Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/applibs/chatgui/avatarlist.cc

Go to the documentation of this file.
00001 /*  $Id: avatarlist.cc,v 1.14 2003/07/23 00:16:48 reed Exp $
00002 
00003     Copyright (C) 2003 Reed Hedges
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #include <vos/corelibs/vos/vos.hh>
00021 #include <vos/metaobjects/misc/avatar.hh>
00022 #include <vos/metaobjects/misc/talkative.hh>
00023 #include <vos/gui/gui/gui.hh>
00024 #include "avatarlist.hh"
00025 #include "privmsg.hh"
00026 
00027 
00028 #define CREATE_BUTTON(CLASS, PARENT, SITE, DATA) { \
00029     LocalSite::addLocalObjectExtension(typeid(CLASS).name(), &CLASS::new_##CLASS); \
00030     vRef<MetaObject> o = (SITE)->createMetaObject(#CLASS, typeid(CLASS).name(), 0); \
00031     vRef<CLASS> b = meta_cast<CLASS*>(&o); \
00032     assert(&b); \
00033     b->initialize(&NoPropertyAccessControl::static_); \
00034     b->setup(DATA); \
00035     (PARENT)->insertChild(-1, #CLASS, &o); \
00036 }
00037 
00038 using namespace VOSGUI;
00039 using namespace VOSChatGUI;
00040 
00041 AvatarList::AvatarList(MetaObject* s) : LocalContainer(s), Container(s),
00042     LocalWidget(s), Widget(s), MetaObject(s) {
00043 }
00044 
00045 
00046 void AvatarList::enablePrivMsg(bool q) {
00047     usePrivMsg = q;
00048 }
00049 
00050 void AvatarList::setup(Vobject* w, Vobject* disp, Avatar* yourAv) {
00051     world = w;
00052     display = disp;
00053     display->acquire();
00054     yourAvatar = yourAv;
00055     site = LocalSite::getDefaultPeer();
00056 
00057     setLabel(string("Avatars in ") + world->getURL().getString() );
00058     setLayout("vertical");
00059 
00060     vRef<Label> label = site->createMetaObject<Label>("AvatarList_label");
00061     label->initialize();
00062     label->setLabel(getLabel());    // copy the value not the object so that apps can change the window titiel
00063     insertChild(-1, "AvatarList_label", &label);
00064 
00065     /* The list */
00066     list = site->createMetaObject<SelectList>("AvatarList");
00067     list->initialize();
00068     list->setMultiple(true);
00069     //list->setAlignment("expand");
00070     list->setProportion(3);
00071     insertChild(-1, "list", &list);
00072 
00073     /* Send private message */
00074     if(usePrivMsg && &yourAvatar && &display)
00075         CREATE_BUTTON(PrivMsgButton, this, site, this);
00076 
00077     /* A "more info" button */
00078     if(&display)
00079         CREATE_BUTTON(UserInfoButton, this, site, this);
00080 
00081     /* Edit your info */
00082     if(&yourAvatar && &display)
00083         CREATE_BUTTON(EditYourInfoButton, this, site, this);
00084 
00085 
00086     if(&yourAvatar) {
00087         vRef<SelectValue> sel = site->createMetaObject<SelectValue>();
00088         sel->setPropertyAccessControl(&NoPropertyAccessControl::static_);
00089         sel->setTargetObj(yourAvatar->getPresenceObj());
00090         sel->initialize();
00091         sel->add("Available", "chat");
00092         sel->add("Away", "away");
00093         sel->add("Extended Away", "xa");
00094         sel->add("Busy", "dnd");
00095         sel->setPopup();
00096         sel->setLabel("Your Status:");
00097         insertChild(-1, "setYourStatus", &sel); 
00098     }
00099 
00100     // XXX TODO: do a search that includes children (recurse down objects)
00101     world->addChildListener(this);
00102 }
00103 
00104 
00105 /* Destructor */
00106 AvatarList::~AvatarList() {
00107     if(&world) {
00108         world->removeChildListener(this);
00109         world->release();
00110     }
00111 }
00112 
00113 
00114 MetaObject* AvatarList::create(MetaObject* s, const string& type) {
00115     return new AvatarList(s);
00116 }
00117 
00118 void AvatarList::registerExtenders() {
00119     LocalSite::addLocalObjectExtension(typeid(AvatarList).name(), &AvatarList::create);
00120 }
00121 
00122 void AvatarList::registerOtherExtenders() {
00123     PrivMsg::registerExtenders();
00124 }
00125 
00126 
00127 void AvatarList::notifyChildInserted(VobjectEvent& ev) {
00128     try {
00129         Avatar* av = meta_cast<Avatar*>(ev.getNewChild());
00130         if(!av) return;
00131         assert(&list);
00132         LOG("AvatarList", 2, "Adding " << av->getURL().getString() << " to list.");
00133         list->add(av);
00134     } catch(bad_cast) {
00135     } catch(exception& e) {
00136         LOG("AvatarList", 2, "error checking new object for \"avatar\" type: " << e.what());
00137     }
00138 }
00139 
00140 
00141 void AvatarList::notifyChildReplaced(VobjectEvent& ev) {
00142     notifyChildRemoved(ev);
00143     notifyChildInserted(ev);
00144 }
00145 
00146 /* Child removed callback */
00147 void AvatarList::notifyChildRemoved(VobjectEvent& ev) {
00148     try {
00149         Avatar* av = meta_cast<Avatar*>(ev.getOldChild());
00150         if(!av) return;
00151         LOG("AvatarList", 2, "Removing " << av->getURL().getString() << " from list.");
00152         list->remove(av);
00153     } catch(exception& e) {
00154         LOG("AvatarList", 2, "Notice: Exception handling ChildRemoved: " << e.what() << ". Continuing...");
00155     }
00156 }
00157 
00158 
00159 /* Child excised callback */
00160 void AvatarList::notifyObjectExcise(RefCounted* obj) {
00161     //?
00162     // TODO
00163 }
00164 
00165 
00166 
00167 void AvatarList::UserInfoButton::push(const string& userid) {
00168     /* TODO: When we have scrolled windows, put them all in a scrolled
00169         window vertically.
00170     vRef<Container> infoWin = CREATEOBJ(site, "UserInfoWindow", Container);
00171     infoWin->initialize();
00172     infoWin->setLabel("User Info");
00173     */
00174     LOG("AvatarList", 2, "Pushed UserInfo button.");
00175 
00176     const Vobject::ChildList& c = data->list->selectedObjectList()->getChildren(); 
00177     for(Vobject::ChildList::const_iterator i = c.begin(); i != c.end(); i++) {
00178         Avatar* av = meta_cast<Avatar*>((*i)->child);
00179         if(!av) 
00180             continue;
00181         LOG("AvatarList", 2, "User Info: found " << av->getURL().getString());
00182 
00183         vRef<Container> subwin = data->site->createMetaObject<Container>("UserInfoSubWindow");
00184         subwin->initialize();
00185         subwin->setBorder(true);
00186         subwin->setLabelObj(av->getNickObj());
00187 
00188         try {
00189             vRef<Label> fullname = data->site->createMetaObject<Label>("UserInfo_Fullname");
00190             fullname->initialize();
00191             fullname->setLabelObj(av->getFullnameObj());
00192             subwin->insertChild(-1, "fullname", &fullname); 
00193         } catch(...) {
00194         }
00195 
00196         try {
00197             vRef<Label> xinfo = data->site->createMetaObject<Label>("UserInfo_ExtraInfo");
00198             xinfo->initialize();
00199             xinfo->setLabelObj(av->getInfoObj());
00200             subwin->insertChild(-1, "extraInfo", &xinfo); 
00201         } catch(...) {
00202         }
00203 
00204         data->display->insertChild(-1, "user", &subwin);
00205     }
00206     //data->display->insertChild(-1, "AvatarList_UserInfoWindow", *infoWin);
00207 }      
00208 
00209 void AvatarList::PrivMsgButton::push(const string& userid) {
00210     LocalTalkative* sender = meta_cast<LocalTalkative*>(&data->yourAvatar);
00211     if(!sender) {
00212         LOG("AvatarList", 2, "Your avatar is not Talkative or is not local. Can't send messages."); 
00213         return;
00214     }
00215     vRef<PrivMsg> privmsg = data->site->createMetaObject<PrivMsg>("PrivMsgWindow");
00216     if(&privmsg) {
00217         assert(&privmsg);
00218         const Vobject::ChildList& c = data->list->selectedObjectList()->getChildren(); 
00219         if(c.size() < 1) 
00220             return;
00221         Talkative* t = meta_cast<Talkative*>(c[0]->child);
00222         if(!t) {
00223             LOG("AvatarList", 0, "Error: selected object is not talkative! Can't send messages.");
00224             return;
00225         }
00226         privmsg->setup(sender, t);
00227         data->display->insertChild(-1, "AvatarList_PrivMsg", &privmsg);
00228     } else {
00229         LOG("AvatarList", 0, "Internal Error creating private message window: did you register the VOSChatGUI::PrivMsg Metaobject extenders?");
00230     }
00231 }
00232     
00233     
00234 
00235 void AvatarList::EditYourInfoButton::push(const string&) {
00236     vRef<Container> win = data->site->createMetaObject<Container>("EditYourInfoWindow");
00237     Avatar* av = &(data->yourAvatar);
00238     win->initialize();
00239     win->setLabel("Edit Your Info");
00240 
00241     vRef<Input> nick = data->site->createMetaObject<Input>("EditYourInfo_NickField");
00242     nick->initialize();
00243     nick->setProportion(1);
00244     nick->setLabel("Nickname");
00245     nick->setTargetObj(av->getNickObj());
00246     win->insertChild(-1, "NickField", &nick);
00247 
00248     try {
00249         vRef<Input> fullname = data->site->createMetaObject<Input>("EditYourInfo_FullNameField");
00250         fullname->initialize();
00251         fullname->setProportion(1);
00252         fullname->setLabel("Real Name");
00253         fullname->setTargetObj(av->getFullnameObj());
00254         win->insertChild(-1, "FullnameField", &fullname);
00255     } catch(...) {
00256         LOG("avatarlist", 1, "Warning: can't include field for fullname.");
00257         vRef<Label> fullname = data->site->createMetaObject<Label>("EditYourInfo_FullNameField");
00258         fullname->initialize();
00259         fullname->setProportion(1);
00260         fullname->setLabel("(Real name not available)");
00261         win->insertChild(-1, "FullnameField", &fullname);
00262     }
00263 
00264     try {
00265         vRef<Input> info = data->site->createMetaObject<Input>("EditYourInfo_XInfoField");
00266         info->initialize();
00267         info->setProportion(3);
00268         info->setLabel("Extra Info");
00269         info->setMultiline(true);
00270         info->setTargetObj(av->getInfoObj());
00271         win->insertChild(-1, "XInfoField", &info);
00272     } catch(...) {
00273         LOG("avatasrlist", 1, "Warning: can't include field for extra info.");
00274         vRef<Label> info = data->site->createMetaObject<Label>("EditYourInfo_XInfoField");
00275         info->initialize();
00276         info->setProportion(3);
00277         info->setLabel("(Extra info not available)");
00278         win->insertChild(-1, "XInfoField", &info);
00279     }
00280 
00281     data->display->insertChild(-1, "AvatarList_EditYourInfo", &win);
00282 }
00283     

Generated on Tue Aug 12 03:55:37 2003 for Interreality Project - VOS by doxygen 1.3.2