From 879d15903608b26f6b10f499d150bb72a65fa966 Mon Sep 17 00:00:00 2001 From: Monroe Linden Date: Mon, 9 Aug 2010 17:40:17 -0700 Subject: Limit the number of media browser windows the viewer will open at once. The limit is controlled by the debug setting MediaBrowserWindowLimit. When opening a new window would take us over the limit, the least recently opened window will be closed first. --- indra/newview/app_settings/settings.xml | 11 +++++++++++ indra/newview/llfloatermediabrowser.cpp | 26 +++++++++++++++++++++++++- indra/newview/llfloatermediabrowser.h | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 4c52fb015f..3326319e2d 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -6425,6 +6425,17 @@ Value 1.0 + MediaBrowserWindowLimit + + Comment + Maximum number of media brower windows that can be open at once (0 for no limit) + Persist + 1 + Type + S32 + Value + 5 + MediaRollOffRate Comment diff --git a/indra/newview/llfloatermediabrowser.cpp b/indra/newview/llfloatermediabrowser.cpp index 268a0e0b93..2fc5bd72de 100644 --- a/indra/newview/llfloatermediabrowser.cpp +++ b/indra/newview/llfloatermediabrowser.cpp @@ -76,8 +76,32 @@ void LLFloaterMediaBrowser::create(const std::string &url, const std::string& ta tag = id.asString(); } - // TODO: Figure out whether we need to close an existing instance and/or warn the user about the number of instances they have open + S32 browser_window_limit = gSavedSettings.getS32("MediaBrowserWindowLimit"); + if(LLFloaterReg::findInstance("media_browser", tag) != NULL) + { + // There's already a media browser for this tag, so we won't be opening a new window. + } + else if(browser_window_limit != 0) + { + // showInstance will open a new window. Figure out how many media browsers are already open, + // and close the least recently opened one if this will put us over the limit. + + LLFloaterReg::const_instance_list_t &instances = LLFloaterReg::getFloaterList("media_browser"); + lldebugs << "total instance count is " << instances.size() << llendl; + + for(LLFloaterReg::const_instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); iter++) + { + lldebugs << " " << (*iter)->getKey() << llendl; + } + + if(instances.size() >= browser_window_limit) + { + // Destroy the least recently opened instance + (*instances.begin())->closeFloater(); + } + } + LLFloaterMediaBrowser *browser = dynamic_cast (LLFloaterReg::showInstance("media_browser", tag)); llassert(browser); if(browser) diff --git a/indra/newview/llfloatermediabrowser.h b/indra/newview/llfloatermediabrowser.h index 1645ed4613..4255d814c0 100644 --- a/indra/newview/llfloatermediabrowser.h +++ b/indra/newview/llfloatermediabrowser.h @@ -45,6 +45,7 @@ class LLFloaterMediaBrowser : public LLViewerMediaObserver { public: + LOG_CLASS(LLFloaterMediaBrowser); LLFloaterMediaBrowser(const LLSD& key); static void create(const std::string &url, const std::string& target); -- cgit v1.2.3