00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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());
00063 insertChild(-1, "AvatarList_label", &label);
00064
00065
00066 list = site->createMetaObject<SelectList>("AvatarList");
00067 list->initialize();
00068 list->setMultiple(true);
00069
00070 list->setProportion(3);
00071 insertChild(-1, "list", &list);
00072
00073
00074 if(usePrivMsg && &yourAvatar && &display)
00075 CREATE_BUTTON(PrivMsgButton, this, site, this);
00076
00077
00078 if(&display)
00079 CREATE_BUTTON(UserInfoButton, this, site, this);
00080
00081
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
00101 world->addChildListener(this);
00102 }
00103
00104
00105
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
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
00160 void AvatarList::notifyObjectExcise(RefCounted* obj) {
00161
00162
00163 }
00164
00165
00166
00167 void AvatarList::UserInfoButton::push(const string& userid) {
00168
00169
00170
00171
00172
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
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