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

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