llfloaternewim.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 #include "llfloaternewim.h"
00034 #include "lluictrlfactory.h"
00035 #include "llnamelistctrl.h"
00036 #include "llresmgr.h"
00037 #include "lltabcontainer.h"
00038 #include "llimview.h"
00039 
00040 S32 COL_1_WIDTH = 200;
00041 
00042 static LLString sOnlineDescriptor = "*";
00043 static LLString sNameFormat = "[FIRST] [LAST]";
00044 
00045 LLFloaterNewIM::LLFloaterNewIM()
00046 {
00047         LLUICtrlFactory::getInstance()->buildFloater(this, "floater_new_im.xml");
00048 }
00049 
00050 BOOL LLFloaterNewIM::postBuild()
00051 {
00052         requires<LLButton>("start_btn");
00053         requires<LLButton>("close_btn");
00054         requires<LLNameListCtrl>("user_list");
00055 
00056         if (checkRequirements())
00057         {
00058                 childSetAction("start_btn", &LLFloaterNewIM::onStart, this);
00059                 childSetAction("close_btn", &LLFloaterNewIM::onClickClose, this);
00060                 mSelectionList = getChild<LLNameListCtrl>("user_list");
00061                 if (mSelectionList)
00062                 {
00063                         mSelectionList->setDoubleClickCallback(&LLFloaterNewIM::onStart);
00064                         mSelectionList->setCallbackUserData(this);
00065                 }
00066                 else
00067                 {
00068                         llwarns << "LLUICtrlFactory::getNameListByName() returned NULL for 'user_list'" << llendl;
00069                 }
00070                 sOnlineDescriptor = getString("online_descriptor");
00071                 sNameFormat = getString("name_format");
00072                 setDefaultBtn("start_btn");
00073                 return TRUE;
00074         }       
00075 
00076         return FALSE;
00077 }
00078 
00079 
00080 LLFloaterNewIM::~LLFloaterNewIM()
00081 {
00082         clearAllTargets();
00083 }
00084 
00085 
00086 void LLFloaterNewIM::clearAllTargets()
00087 {
00088         mSelectionList->deleteAllItems();
00089 }
00090 
00091 void LLFloaterNewIM::addSpecial(const LLUUID& uuid, const std::string& name,
00092                                                          void* data, BOOL bold, BOOL online)
00093 {
00094         LLSD row;
00095         row["id"] = uuid;
00096         row["name"] = name;
00097         row["target"] = "SPECIAL";
00098         row["columns"][0]["value"] = name;
00099         row["columns"][0]["width"] = COL_1_WIDTH;
00100         row["columns"][0]["font"] = "SANSSERIF";
00101         row["columns"][0]["font-style"] = bold ? "BOLD" : "NORMAL";
00102         row["columns"][1]["value"] = online ? sOnlineDescriptor : "";
00103         row["columns"][1]["font"] = "SANSSERIF";
00104         row["columns"][1]["font-style"] = "BOLD";
00105         LLScrollListItem* itemp = mSelectionList->addElement(row);
00106         itemp->setUserdata(data);
00107 
00108         if (mSelectionList->getFirstSelectedIndex() == -1)
00109         {
00110                 mSelectionList->selectFirstItem();
00111         }
00112 }
00113 
00114 void LLFloaterNewIM::addGroup(const LLUUID& uuid, void* data, BOOL bold, BOOL online)
00115 {
00116         LLSD row;
00117         row["id"] = uuid;
00118         row["target"] = "GROUP";
00119         row["columns"][0]["value"] = ""; // name will be looked up
00120         row["columns"][0]["width"] = COL_1_WIDTH;
00121         row["columns"][0]["font"] = "SANSSERIF";
00122         row["columns"][0]["font-style"] = bold ? "BOLD" : "NORMAL";
00123         row["columns"][1]["value"] = online ? sOnlineDescriptor : "";
00124         row["columns"][1]["font"] = "SANSSERIF";
00125         row["columns"][1]["font-style"] = "BOLD";
00126         LLScrollListItem* itemp = mSelectionList->addElement(row);
00127         itemp->setUserdata(data);
00128 
00129         if (mSelectionList->getFirstSelectedIndex() == -1)
00130         {
00131                 mSelectionList->selectFirstItem();
00132         }
00133 }
00134 
00135 void LLFloaterNewIM::addAgent(const LLUUID& uuid, void* data, BOOL online)
00136 {
00137         std::string first, last;
00138         gCacheName->getName(uuid, first, last);
00139         LLUIString fullname = sNameFormat;
00140         fullname.setArg("[FIRST]", first);
00141         fullname.setArg("[LAST]", last);
00142 
00143         LLSD row;
00144         row["id"] = uuid;
00145         row["columns"][0]["value"] = fullname;
00146         row["columns"][0]["width"] = COL_1_WIDTH;
00147         row["columns"][0]["font"] = "SANSSERIF";
00148         row["columns"][0]["font-style"] = online ? "BOLD" : "NORMAL";
00149         row["columns"][1]["value"] = online ? sOnlineDescriptor : "";
00150         row["columns"][1]["font"] = "SANSSERIF";
00151         row["columns"][1]["font-style"] = "BOLD";
00152         LLScrollListItem* itemp = mSelectionList->addElement(row);
00153         itemp->setUserdata(data);
00154 
00155         if (mSelectionList->getFirstSelectedIndex() == -1)
00156         {
00157                 mSelectionList->selectFirstItem();
00158         }
00159 }
00160 
00161 BOOL LLFloaterNewIM::isUUIDAvailable(const LLUUID& uuid)
00162 {
00163         std::vector<LLScrollListItem*> data_list = mSelectionList->getAllData();
00164         std::vector<LLScrollListItem*>::iterator data_itor;
00165         for (data_itor = data_list.begin(); data_itor != data_list.end(); ++data_itor)
00166         {
00167                 LLScrollListItem* item = *data_itor;
00168                 if(item->getUUID() == uuid)
00169                 {
00170                         return TRUE;
00171                 }
00172         }
00173         return FALSE;
00174 }
00175 
00176 void LLFloaterNewIM::onStart(void* userdata)
00177 {
00178         LLFloaterNewIM* self = (LLFloaterNewIM*) userdata;
00179 
00180         LLScrollListItem* item = self->mSelectionList->getFirstSelected();
00181         if(item)
00182         {
00183                 const LLScrollListCell* cell = item->getColumn(0);
00184                 LLString name(cell->getValue());
00185 
00186                 // *NOTE: Do a live detrmination of what type of session it
00187                 // should be. If we restrict the new im panel to online users,
00188                 // then we can remove some of this code.
00189                 EInstantMessage type;
00190                 EInstantMessage* t = (EInstantMessage*)item->getUserdata();
00191                 if(t) type = (*t);
00192                 else type = LLIMMgr::defaultIMTypeForAgent(item->getUUID());
00193                 gIMMgr->addSession(name, type, item->getUUID());
00194 
00195                 make_ui_sound("UISndStartIM");
00196         }
00197         else
00198         {
00199                 make_ui_sound("UISndInvalidOp");
00200         }
00201 }
00202 
00203 
00204 // static
00205 void LLFloaterNewIM::onClickClose(void *userdata)
00206 {
00207         gIMMgr->setFloaterOpen(FALSE);
00208 }
00209 
00210 
00211 BOOL LLFloaterNewIM::handleKeyHere(KEY key, MASK mask)
00212 {
00213         BOOL handled = LLFloater::handleKeyHere(key, mask);
00214         if ( KEY_ESCAPE == key )
00215         {
00216                 handled = TRUE;
00217                 // Close talk panel on escape
00218                 gIMMgr->toggle(NULL);
00219         }
00220 
00221         // Might need to call base class here if not handled
00222         return handled;
00223 }
00224 
00225 BOOL LLFloaterNewIM::canClose()
00226 {
00227         if (getHost())
00228         {
00229                 LLMultiFloater* hostp = (LLMultiFloater*)getHost();
00230                 // if we are the only tab in the im view, go ahead and close
00231                 return hostp->getFloaterCount() == 1;
00232         }
00233         return TRUE;
00234 }
00235 
00236 void LLFloaterNewIM::close(bool app_quitting)
00237 {
00238         if (getHost())
00239         {
00240                 LLMultiFloater* hostp = (LLMultiFloater*)getHost();
00241                 hostp->close();
00242         }
00243         else
00244         {
00245                 LLFloater::close(app_quitting);
00246         }
00247 }
00248 
00249 S32 LLFloaterNewIM::getScrollPos()
00250 {
00251         return mSelectionList->getScrollPos();
00252 }
00253 
00254 void LLFloaterNewIM::setScrollPos( S32 pos )
00255 {
00256         mSelectionList->setScrollPos( pos );
00257 }

Generated on Fri May 16 08:33:29 2008 for SecondLife by  doxygen 1.5.5