llfloatergroupinfo.cpp

Go to the documentation of this file.
00001 
00034 #include "llviewerprecompiledheaders.h"
00035 
00036 #include "llfloatergroupinfo.h"
00037 
00038 #include "llagent.h"
00039 #include "llcommandhandler.h"
00040 #include "llcommandhandler.h"
00041 #include "llpanelgroup.h"
00042 #include "llviewermessage.h" // for inventory_offer_callback
00043 //#include "llviewerwindow.h"
00044 
00045 #include "llcachename.h"
00046 
00047 const char FLOATER_TITLE[] = "Group Information";
00048 const LLRect FGI_RECT(0, 530, 420, 0);
00049 
00050 //
00051 // Globals
00052 //
00053 std::map<LLUUID, LLFloaterGroupInfo*> LLFloaterGroupInfo::sInstances;
00054 
00055 class LLGroupHandler : public LLCommandHandler
00056 {
00057 public:
00058         // don't allow from external browsers
00059         LLGroupHandler() : LLCommandHandler("group", false) { }
00060         bool handle(const LLSD& tokens, const LLSD& queryMap)
00061         {
00062                 if (tokens.size() < 2)
00063                 {
00064                         return false;
00065                 }
00066 
00067                 LLUUID group_id;
00068                 if (!group_id.set(tokens[0], FALSE))
00069                 {
00070                         return false;
00071                 }
00072 
00073                 if (tokens[1].asString() == "about")
00074                 {
00075                         LLFloaterGroupInfo::showFromUUID(group_id);
00076                         return true;
00077                 }
00078                 return false;
00079         }
00080 };
00081 LLGroupHandler gGroupHandler;
00082 
00083 //-----------------------------------------------------------------------------
00084 // Implementation
00085 //-----------------------------------------------------------------------------
00086 LLFloaterGroupInfo::LLFloaterGroupInfo(const std::string& name, const LLRect &rect, const std::string& title, const LLUUID& group_id, const std::string& tab_name)
00087 :       LLFloater(name, rect, title),
00088         mGroupID( group_id )
00089 {
00090         // Construct the filename of the group panel xml definition file.
00091         mPanelGroupp = new LLPanelGroup("panel_group.xml",
00092                                                                         "PanelGroup",
00093                                                                         group_id,
00094                                                                         tab_name);
00095         addChild(mPanelGroupp);
00096 }
00097 
00098 // virtual
00099 LLFloaterGroupInfo::~LLFloaterGroupInfo()
00100 {
00101         sInstances.erase(mGroupID);
00102 }
00103 
00104 BOOL LLFloaterGroupInfo::canClose()
00105 {
00106         // Ask the panel if it is ok to close.
00107         if ( mPanelGroupp )
00108         {
00109                 return mPanelGroupp->canClose();
00110         }
00111         return TRUE;
00112 }
00113 
00114 void LLFloaterGroupInfo::selectTabByName(std::string tab_name)
00115 {
00116         mPanelGroupp->selectTab(tab_name);
00117 }
00118 
00119 // static
00120 void LLFloaterGroupInfo::showMyGroupInfo(void *)
00121 {
00122         showFromUUID( gAgent.getGroupID() );
00123 }
00124 
00125 // static
00126 void LLFloaterGroupInfo::showCreateGroup(void *)
00127 {
00128         showFromUUID(LLUUID::null, "general_tab");
00129 }
00130 
00131 // static
00132 void LLFloaterGroupInfo::closeGroup(const LLUUID& group_id)
00133 {
00134         LLFloaterGroupInfo *fgi = get_if_there(sInstances, group_id, (LLFloaterGroupInfo*)NULL);
00135         if (fgi)
00136         {
00137                 if (fgi->mPanelGroupp)
00138                 {
00139                         fgi->mPanelGroupp->close();
00140                 }
00141         }
00142 }
00143 
00144 // static
00145 void LLFloaterGroupInfo::closeCreateGroup()
00146 {
00147         closeGroup(LLUUID::null);
00148 }
00149 
00150 // static 
00151 void LLFloaterGroupInfo::refreshGroup(const LLUUID& group_id)
00152 {
00153         LLFloaterGroupInfo *fgi = get_if_there(sInstances, group_id, (LLFloaterGroupInfo*)NULL);
00154         if (fgi)
00155         {
00156                 if (fgi->mPanelGroupp)
00157                 {
00158                         fgi->mPanelGroupp->refreshData();
00159                 }
00160         }
00161 }
00162 
00163 // static
00164 void LLFloaterGroupInfo::callbackLoadGroupName(const LLUUID& id, const char* first, const char* last, BOOL is_group, void* data)
00165 {
00166         LLFloaterGroupInfo *fgi = get_if_there(sInstances, id, (LLFloaterGroupInfo*)NULL);
00167 
00168         if (fgi)
00169         {
00170                 // Build a new title including the group name.
00171                 std::ostringstream title;
00172                 title << first << " - " << FLOATER_TITLE;
00173                 fgi->setTitle(title.str());
00174         }
00175 }
00176 
00177 // static
00178 void LLFloaterGroupInfo::showFromUUID(const LLUUID& group_id,
00179                                                                           const std::string& tab_name)
00180 {
00181         // If we don't have a floater for this group, create one.
00182         LLFloaterGroupInfo *fgi = get_if_there(sInstances, group_id, (LLFloaterGroupInfo*)NULL);
00183         if (!fgi)
00184         {
00185                 fgi = new LLFloaterGroupInfo("groupinfo",
00186                                                                          FGI_RECT,
00187                                                                          FLOATER_TITLE,
00188                                                                          group_id,
00189                                                                          tab_name);
00190 
00191                 sInstances[group_id] = fgi;
00192 
00193                 if (group_id.notNull())
00194                 {
00195                         // Look up the group name.
00196                         // The callback will insert it into the title.
00197                         const BOOL is_group = TRUE;
00198                         gCacheName->get(group_id, is_group, callbackLoadGroupName, NULL);
00199                 }
00200         }
00201 
00202         fgi->selectTabByName(tab_name);
00203         
00204         fgi->center();
00205         fgi->open();    /*Flawfinder: ignore*/
00206 }
00207 
00208 // static 
00209 void LLFloaterGroupInfo::showNotice(const char* subject,
00210                                                         const char* message,
00211                                                         const LLUUID& group_id,
00212                                                         const bool& has_inventory,
00213                                                         const char* inventory_name,
00214                                                         LLOfferInfo* inventory_offer)
00215 {
00216         llinfos << "LLFloaterGroupInfo::showNotice : " << subject << llendl;
00217 
00218         if (group_id.isNull())
00219         {
00220                 // We need to clean up that inventory offer.
00221                 if (inventory_offer)
00222                 {
00223                         inventory_offer_callback( IOR_DECLINE , inventory_offer); 
00224                 }
00225                 return;
00226         }
00227 
00228         // If we don't have a floater for this group, drop this packet on the floor.
00229         LLFloaterGroupInfo *fgi = get_if_there(sInstances, group_id, (LLFloaterGroupInfo*)NULL);
00230         if (!fgi)
00231         {
00232                 // We need to clean up that inventory offer.
00233                 if (inventory_offer)
00234                 {
00235                         inventory_offer_callback( IOR_DECLINE , inventory_offer); 
00236                 }
00237                 return;
00238         }
00239         
00240         fgi->mPanelGroupp->showNotice(subject,message,has_inventory,inventory_name,inventory_offer);
00241 }

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