From ea2cc3e0dedc262b0ff760495c7de44092963b58 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Fri, 13 May 2011 23:50:56 +0200 Subject: [PATCH] Make FilePicker context sensitive default paths persistent over logins. Also, make newview/statemachine a separate project. --- indra/CMakeLists.txt | 1 + indra/cmake/AIStateMachine.cmake | 4 ++ indra/llcommon/llstl.h | 1 + indra/llplugin/llpluginclassmedia.h | 7 +- indra/newview/CMakeLists.txt | 15 +---- indra/newview/llappviewer.cpp | 4 ++ indra/newview/llstartup.cpp | 7 ++ indra/newview/llviewercontrol.cpp | 10 +++ indra/newview/llviewercontrol.h | 7 +- indra/newview/llviewerpluginmanager.cpp | 10 +++ indra/newview/llviewerpluginmanager.h | 11 ++- indra/newview/statemachine/CMakeLists.txt | 41 ++++++++++++ indra/newview/statemachine/aifilepicker.cpp | 67 +++++++++++++++++-- indra/newview/statemachine/aifilepicker.h | 7 +- indra/newview/statemachine/aistatemachine.cpp | 9 +-- indra/newview/statemachine/aistatemachine.h | 1 + 16 files changed, 168 insertions(+), 34 deletions(-) create mode 100644 indra/cmake/AIStateMachine.cmake create mode 100644 indra/newview/statemachine/CMakeLists.txt diff --git a/indra/CMakeLists.txt b/indra/CMakeLists.txt index 55e2c1e87..c0e8dc408 100644 --- a/indra/CMakeLists.txt +++ b/indra/CMakeLists.txt @@ -106,6 +106,7 @@ if (VIEWER) add_dependencies(viewer solaris-crash-logger) endif (LINUX) + add_subdirectory(${VIEWER_PREFIX}newview/statemachine) add_subdirectory(${VIEWER_PREFIX}newview) add_dependencies(viewer secondlife-bin) endif (VIEWER) diff --git a/indra/cmake/AIStateMachine.cmake b/indra/cmake/AIStateMachine.cmake new file mode 100644 index 000000000..c1bda40c4 --- /dev/null +++ b/indra/cmake/AIStateMachine.cmake @@ -0,0 +1,4 @@ +# -*- cmake -*- + +set(AISTATEMACHINE_INCLUDE_DIRS statemachine) +set(AISTATEMACHINE_LIBRARIES statemachine) diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h index 788617953..18842f276 100644 --- a/indra/llcommon/llstl.h +++ b/indra/llcommon/llstl.h @@ -39,6 +39,7 @@ #include #include #include +#include "stdtypes.h" // llcommon/stdtypes.h, needed for S32 and U32. // Use to compare the first element only of a pair // e.g. typedef std::set, compare_pair > some_pair_set_t; diff --git a/indra/llplugin/llpluginclassmedia.h b/indra/llplugin/llpluginclassmedia.h index 1996c6588..2882de180 100644 --- a/indra/llplugin/llpluginclassmedia.h +++ b/indra/llplugin/llpluginclassmedia.h @@ -37,7 +37,6 @@ #define LL_LLPLUGINCLASSMEDIA_H #include "llpluginclassbasic.h" -#include "llgltypes.h" #include "llrect.h" #include "v4color.h" @@ -232,9 +231,9 @@ protected: bool mTextureParamsReceived; // the mRequestedTexture* fields are only valid when this is true S32 mRequestedTextureDepth; - LLGLenum mRequestedTextureInternalFormat; - LLGLenum mRequestedTextureFormat; - LLGLenum mRequestedTextureType; + U32 mRequestedTextureInternalFormat; + U32 mRequestedTextureFormat; + U32 mRequestedTextureType; bool mRequestedTextureSwapBytes; bool mRequestedTextureCoordsOpenGL; diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 340989a05..2b4a4ca31 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -22,6 +22,7 @@ include(LLInventory) include(LLMath) include(LLMessage) include(LLPlugin) +include(AIStateMachine) include(LLPrimitive) include(LLRender) include(LLUI) @@ -43,6 +44,7 @@ if (WINDOWS) endif (WINDOWS) include_directories( + ${CMAKE_SOURCE_DIR}/newview ${DBUSGLIB_INCLUDE_DIRS} ${HUNSPELL_INCLUDE_DIR} ${ELFIO_INCLUDE_DIR} @@ -1006,18 +1008,6 @@ set(viewer_HEADER_FILES source_group("CMake Rules" FILES ViewerInstall.cmake) -set(statemachine_SOURCE_FILES - statemachine/aistatemachine.cpp - statemachine/aifilepicker.cpp - ) -set(statemachine_HEADER_FILES - statemachine/aistatemachine.h - statemachine/aifilepicker.h - statemachine/aidirpicker.h - ) -list(APPEND viewer_SOURCE_FILES ${statemachine_SOURCE_FILES}) -list(APPEND viewer_HEADER_FILES ${statemachine_HEADER_FILES}) - if (DARWIN) LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp) @@ -1434,6 +1424,7 @@ target_link_libraries(${VIEWER_BINARY_NAME} ${LLINVENTORY_LIBRARIES} ${LLMESSAGE_LIBRARIES} ${LLPLUGIN_LIBRARIES} + ${AISTATEMACHINE_LIBRARIES} ${LLPRIMITIVE_LIBRARIES} ${LLRENDER_LIBRARIES} ${FREETYPE_LIBRARIES} diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 420a9ae67..a2a4ed386 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -72,6 +72,7 @@ #include "llmutelist.h" #include "llurldispatcher.h" #include "llurlhistory.h" +#include "statemachine/aifilepicker.h" #include "llfirstuse.h" #include "llrender.h" #include "llfont.h" @@ -1353,6 +1354,9 @@ bool LLAppViewer::cleanup() // Save URL history file LLURLHistory::saveFile("url_history.xml"); + // Save file- and dirpicker {context, default paths} map. + AIFilePicker::saveFile("filepicker_contexts.xml"); + // save mute list. gMuteList used to also be deleted here too. LLMuteList::getInstance()->cache(gAgent.getID()); diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index e08bc301a..07c8de068 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -54,6 +54,7 @@ #include "hippogridmanager.h" #include "hippolimits.h" #include "floaterao.h" +#include "statemachine/aifilepicker.h" #include "llares.h" #include "llcachename.h" @@ -636,6 +637,12 @@ bool idle_startup() LLStartUp::handleSocksProxy(false); + //------------------------------------------------- + // Load file- and dirpicker {context, default path} map. + //------------------------------------------------- + + AIFilePicker::loadFile("filepicker_contexts.xml"); + //------------------------------------------------- // Init audio, which may be needed for prefs dialog // or audio cues in connection UI. diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp index de65b97af..c5889106f 100644 --- a/indra/newview/llviewercontrol.cpp +++ b/indra/newview/llviewercontrol.cpp @@ -810,6 +810,16 @@ template <> eControlType get_control_type(const LLSD& in, LLSD& out) return TYPE_LLSD; } +void onCommitControlSetting_gSavedSettings(LLUICtrl* ctrl, void* name) +{ + gSavedSettings.setValue((const char*)name,ctrl->getValue()); +} + +void onCommitControlSetting_gSavedPerAccountSettings(LLUICtrl* ctrl, void* name) +{ + gSavedPerAccountSettings.setValue((const char*)name,ctrl->getValue()); +} + #if TEST_CACHED_CONTROL #define DECL_LLCC(T, V) static LLCachedControl mySetting_##T("TestCachedControl"#T, V) diff --git a/indra/newview/llviewercontrol.h b/indra/newview/llviewercontrol.h index 8835146ad..f22f96f27 100644 --- a/indra/newview/llviewercontrol.h +++ b/indra/newview/llviewercontrol.h @@ -35,9 +35,10 @@ #include #include "llcontrol.h" -#include "lluictrl.h" #include "aithreadsafe.h" +class LLUICtrl; + // Enabled this definition to compile a 'hacked' viewer that // allows a hacked godmode to be toggled on and off. #define TOGGLE_HACKED_GODLIKE_VIEWER @@ -75,8 +76,8 @@ bool handleCloudSettingsChanged(const LLSD& newvalue); //A template would be a little awkward to use here.. so.. a preprocessor macro. Alas. onCommitControlSetting(gSavedSettings) etc. -inline void onCommitControlSetting_gSavedSettings(LLUICtrl* ctrl, void* name) {gSavedSettings.setValue((const char*)name,ctrl->getValue());} -inline void onCommitControlSetting_gSavedPerAccountSettings(LLUICtrl* ctrl, void* name) {gSavedPerAccountSettings.setValue((const char*)name,ctrl->getValue());} +void onCommitControlSetting_gSavedSettings(LLUICtrl* ctrl, void* name); +void onCommitControlSetting_gSavedPerAccountSettings(LLUICtrl* ctrl, void* name); #define onCommitControlSetting(controlgroup) onCommitControlSetting_##controlgroup //#define TEST_CACHED_CONTROL 1 diff --git a/indra/newview/llviewerpluginmanager.cpp b/indra/newview/llviewerpluginmanager.cpp index 58ee33585..fdd48736e 100644 --- a/indra/newview/llviewerpluginmanager.cpp +++ b/indra/newview/llviewerpluginmanager.cpp @@ -32,6 +32,7 @@ #include "llviewerprecompiledheaders.h" #include "llviewerpluginmanager.h" +#include "llnotifications.h" void LLViewerPluginManager::destroyPlugin() { @@ -54,3 +55,12 @@ void LLViewerPluginManager::update() return; } } + +void LLViewerPluginManager::send_plugin_failure_warning(std::string const& plugin_basename) +{ + LL_WARNS("Plugin") << "plugin intialization failed for plugin: " << plugin_basename << LL_ENDL; + LLSD args; + args["MIME_TYPE"] = plugin_basename; // FIXME: Use different notification. + LLNotifications::instance().add("NoPlugin", args); +} + diff --git a/indra/newview/llviewerpluginmanager.h b/indra/newview/llviewerpluginmanager.h index b56d11eee..6525a5403 100644 --- a/indra/newview/llviewerpluginmanager.h +++ b/indra/newview/llviewerpluginmanager.h @@ -39,7 +39,6 @@ #include "lldir.h" #include "llfile.h" #include "llviewercontrol.h" -#include "llnotifications.h" #include "llpluginclassbasic.h" class LLViewerPluginManager : public LLRefCount @@ -65,6 +64,10 @@ public: // Return pointer to plugin. LLPluginClassBasic* getPlugin(void) const { return mPluginBase; } +private: + // Called from createPlugin. + void send_plugin_failure_warning(std::string const& plugin_basename); + protected: LLPluginClassBasic* mPluginBase; //!< Pointer to the base class of the underlaying plugin. }; @@ -104,11 +107,7 @@ LLPluginClassBasic* LLViewerPluginManager::createPlugin(T* user_data) if (mPluginBase) return mPluginBase; - LL_WARNS("Plugin") << "plugin intialization failed for plugin: " << PLUGIN_TYPE::plugin_basename() << LL_ENDL; - LLSD args; - args["MIME_TYPE"] = PLUGIN_TYPE::plugin_basename(); // FIXME: Use different notification. - LLNotifications::instance().add("NoPlugin", args); - + send_plugin_failure_warning(PLUGIN_TYPE::plugin_basename()); return NULL; } diff --git a/indra/newview/statemachine/CMakeLists.txt b/indra/newview/statemachine/CMakeLists.txt new file mode 100644 index 000000000..a7738290a --- /dev/null +++ b/indra/newview/statemachine/CMakeLists.txt @@ -0,0 +1,41 @@ +# -*- cmake -*- + +project(statemachine) + +include(00-Common) +include(LLCommon) +include(LLPlugin) +include(LLMessage) # This is needed by LLPlugin. +include(LLMath) +include(LLVFS) +include(LLXML) + +include_directories( + ${CMAKE_SOURCE_DIR}/newview + ${LLCOMMON_INCLUDE_DIRS} + ${LLPLUGIN_INCLUDE_DIRS} + ${LLMESSAGE_INCLUDE_DIRS} + ${LLMATH_INCLUDE_DIRS} + ${LLVFS_INCLUDE_DIRS} + ${LLXML_INCLUDE_DIRS} + ) + +set(statemachine_SOURCE_FILES + aistatemachine.cpp + aifilepicker.cpp + ) + +set(statemachine_HEADER_FILES + CMakeLists.txt + aistatemachine.h + aifilepicker.h + aidirpicker.h + ) + +set_source_files_properties(${statemachine_HEADER_FILES} + PROPERTIES HEADER_FILE_ONLY TRUE) + +list(APPEND statemachine_SOURCE_FILES ${statemachine_HEADER_FILES}) + +add_library (statemachine ${statemachine_SOURCE_FILES}) +add_dependencies(statemachine prepare) diff --git a/indra/newview/statemachine/aifilepicker.cpp b/indra/newview/statemachine/aifilepicker.cpp index f8da4da86..29f83c782 100644 --- a/indra/newview/statemachine/aifilepicker.cpp +++ b/indra/newview/statemachine/aifilepicker.cpp @@ -28,14 +28,14 @@ * Initial version, written by Aleric Inglewood @ SL */ -#include "../llviewerprecompiledheaders.h" -#include "../llviewermedia.h" -#include "../lltrans.h" +#include "linden_common.h" +#include "lltrans.h" #include "llpluginclassmedia.h" #include "llpluginmessageclasses.h" +#include "llsdserialize.h" #include "aifilepicker.h" #if LL_WINDOWS -#include "../llviewerwindow.h" +#include "llviewerwindow.h" #endif #if LL_GTK && LL_X11 #include "llwindowsdl.h" @@ -456,3 +456,62 @@ std::string AIFilePicker::getFolder(void) const return gDirUtilp->getDirName(getFilename()); } +// static +bool AIFilePicker::loadFile(std::string const& filename) +{ + LLSD data; + std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename); + llifstream file(filepath); + if (file.is_open()) + { + llinfos << "Loading filepicker context file at \"" << filepath << "\"." << llendl; + LLSDSerialize::fromXML(data, file); + } + + if (!data.isMap()) + { + llinfos << "File missing, ill-formed, or simply undefined; not changing the file (" << filepath << ")." << llendl; + return false; + } + + AIAccess wContextMap(sContextMap); + + for (LLSD::map_const_iterator iter = data.beginMap(); iter != data.endMap(); ++iter) + { + wContextMap->insert(context_map_type::value_type(iter->first, iter->second.asString())); + } + + return true; +} + +// static +bool AIFilePicker::saveFile(std::string const& filename) +{ + AIAccess wContextMap(sContextMap); + if (wContextMap->empty()) + return false; + + LLSD context; + + for (context_map_type::iterator iter = wContextMap->begin(); iter != wContextMap->end(); ++iter) + { + context[iter->first] = iter->second; + } + + std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename); + llofstream file; + file.open(filepath.c_str()); + if (!file.is_open()) + { + llwarns << "Unable to open filepicker context file for save: \"" << filepath << "\"." << llendl; + return false; + } + + LLSDSerialize::toPrettyXML(context, file); + + file.close(); + llinfos << "Saved default paths to \"" << filepath << "\"." << llendl; + + return true; +} + diff --git a/indra/newview/statemachine/aifilepicker.h b/indra/newview/statemachine/aifilepicker.h index 91a7bc819..ee2013306 100644 --- a/indra/newview/statemachine/aifilepicker.h +++ b/indra/newview/statemachine/aifilepicker.h @@ -33,7 +33,7 @@ #include "aistatemachine.h" #include "llpluginclassmedia.h" -#include "../llviewermedia.h" +#include "llviewerpluginmanager.h" #include enum ELoadFilter @@ -165,6 +165,11 @@ public: std::string getFolder(void) const; std::vector const& getFilenames(void) const { return mFilenames; } + // Load the sContextMap from disk. + static bool loadFile(std::string const& filename); + // Save the sContextMap to disk. + static bool saveFile(std::string const& filename); + private: friend class AIPluginFilePicker; diff --git a/indra/newview/statemachine/aistatemachine.cpp b/indra/newview/statemachine/aistatemachine.cpp index ce1a4149e..2136d0eb4 100644 --- a/indra/newview/statemachine/aistatemachine.cpp +++ b/indra/newview/statemachine/aistatemachine.cpp @@ -28,17 +28,18 @@ * Initial version, written by Aleric Inglewood @ SL */ -#include "../llviewerprecompiledheaders.h" +#include "linden_common.h" #include -#include "../llcallbacklist.h" -#include "../llviewercontrol.h" - +#include "llcallbacklist.h" +#include "llcontrol.h" #include "llfasttimer.h" #include "aithreadsafe.h" #include "aistatemachine.h" +extern LLControlGroup gSavedSettings; + // Local variables. namespace { struct QueueElementComp; diff --git a/indra/newview/statemachine/aistatemachine.h b/indra/newview/statemachine/aistatemachine.h index 4b25b957d..fe3010d14 100644 --- a/indra/newview/statemachine/aistatemachine.h +++ b/indra/newview/statemachine/aistatemachine.h @@ -33,6 +33,7 @@ #include "aithreadsafe.h" #include "llfasttimer.h" +#include //! // A AIStateMachine is a base class that allows derived classes to