llfloaternewim.cpp

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

Generated on Thu Jul 1 06:08:35 2010 for Second Life Viewer by  doxygen 1.4.7