From e6882176d2e0e6728a1a0ffe7e1d327b3c88c4df Mon Sep 17 00:00:00 2001 From: Cinders Date: Thu, 25 Jul 2013 17:00:45 -0600 Subject: [PATCH] Make the settings backup panel a proper preferences panel and register it as such --- indra/newview/llfloaterpreference.cpp | 72 ++++++++++++++++----------- indra/newview/llfloaterpreference.h | 39 ++++++++++----- 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index c4065f9629..1e20fc7bf8 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -480,14 +480,6 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key) mCommitCallbackRegistrar.add("Pref.ClickActionChange", boost::bind(&LLFloaterPreference::onClickActionChange, this)); - // Backup settings - mCommitCallbackRegistrar.add("Pref.SetBackupSettingsPath", boost::bind(&LLFloaterPreference::onClickSetBackupSettingsPath, this)); - mCommitCallbackRegistrar.add("Pref.BackupSettings", boost::bind(&LLFloaterPreference::onClickBackupSettings, this)); - mCommitCallbackRegistrar.add("Pref.RestoreSettings", boost::bind(&LLFloaterPreference::onClickRestoreSettings, this)); - mCommitCallbackRegistrar.add("Pref.BackupSelectAll", boost::bind(&LLFloaterPreference::onClickSelectAll, this)); - mCommitCallbackRegistrar.add("Pref.BackupDeselectAll", boost::bind(&LLFloaterPreference::onClickDeselectAll, this)); - // - gSavedSettings.getControl("NameTagShowUsernames")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged, _2)); gSavedSettings.getControl("NameTagShowFriends")->getCommitSignal()->connect(boost::bind(&handleNameTagOptionChanged, _2)); // @@ -669,12 +661,6 @@ BOOL LLFloaterPreference::postBuild() // Show email address in preferences (FIRE-1071) getChild("send_im_to_email")->setLabelArg("[EMAIL]", getString("LoginToChange")); - // Backup Settings - // Apparently, line editors don't update with their settings controls, so do that manually here - std::string dir_name=gSavedSettings.getString("SettingsBackupPath"); - getChild("settings_backup_path")->setValue(dir_name); - // - // Load the list of font settings populateFontSelectionCombo(); // @@ -1098,7 +1084,7 @@ void LLFloaterPreference::onBtnOK() if(mGotPersonalInfo) { gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE); - } + } } else { @@ -3260,16 +3246,38 @@ S32 copy_prefs_file(const std::string& from, const std::string& to) const S32 COPY_BUFFER_SIZE = 16384; U8 buffer[COPY_BUFFER_SIZE]; while(((read = fread(buffer, 1, sizeof(buffer), in)) > 0) - && (fwrite(buffer, 1, read, out) == (U32)read)); /* Flawfinder : ignore */ + && (fwrite(buffer, 1, read, out) == (U32)read)); /* Flawfinder : ignore */ if(ferror(in) || ferror(out)) rv = -2; - + if(in) fclose(in); if(out) fclose(out); - + return rv; } -void LLFloaterPreference::onClickSetBackupSettingsPath() +static LLRegisterPanelClassWrapper t_pref_backup("panel_preference_backup"); + +FSPanelPreferenceBackup::FSPanelPreferenceBackup() : LLPanelPreference() +{ + mCommitCallbackRegistrar.add("Pref.SetBackupSettingsPath", boost::bind(&FSPanelPreferenceBackup::onClickSetBackupSettingsPath, this)); + mCommitCallbackRegistrar.add("Pref.BackupSettings", boost::bind(&FSPanelPreferenceBackup::onClickBackupSettings, this)); + mCommitCallbackRegistrar.add("Pref.RestoreSettings", boost::bind(&FSPanelPreferenceBackup::onClickRestoreSettings, this)); + mCommitCallbackRegistrar.add("Pref.BackupSelectAll", boost::bind(&FSPanelPreferenceBackup::onClickSelectAll, this)); + mCommitCallbackRegistrar.add("Pref.BackupDeselectAll", boost::bind(&FSPanelPreferenceBackup::onClickDeselectAll, this)); +} + +BOOL FSPanelPreferenceBackup::postBuild() +{ + // Backup Settings + // Apparently, line editors don't update with their settings controls, so do that manually here + std::string dir_name=gSavedSettings.getString("SettingsBackupPath"); + getChild("settings_backup_path")->setValue(dir_name); + // + + return LLPanelPreference::postBuild(); +} + +void FSPanelPreferenceBackup::onClickSetBackupSettingsPath() { std::string dir_name=gSavedSettings.getString("SettingsBackupPath"); LLDirPicker& picker=LLDirPicker::instance(); @@ -3284,7 +3292,7 @@ void LLFloaterPreference::onClickSetBackupSettingsPath() getChild("settings_backup_path")->setValue(dir_name); } -void LLFloaterPreference::onClickBackupSettings() +void FSPanelPreferenceBackup::onClickBackupSettings() { llwarns << "entered" << llendl; // Get settings backup path @@ -3472,13 +3480,13 @@ void LLFloaterPreference::onClickBackupSettings() LLNotificationsUtil::add("BackupFinished"); } -void LLFloaterPreference::onClickRestoreSettings() +void FSPanelPreferenceBackup::onClickRestoreSettings() { // ask the user if they really want to restore and restart - LLNotificationsUtil::add("SettingsRestoreNeedsLogout",LLSD(),LLSD(),boost::bind(&LLFloaterPreference::doRestoreSettings,this,_1,_2)); + LLNotificationsUtil::add("SettingsRestoreNeedsLogout",LLSD(),LLSD(),boost::bind(&FSPanelPreferenceBackup::doRestoreSettings,this,_1,_2)); } -void LLFloaterPreference:: doRestoreSettings(const LLSD& notification,const LLSD& response) +void FSPanelPreferenceBackup:: doRestoreSettings(const LLSD& notification,const LLSD& response) { llwarns << "entered" << llendl; // Check the user's answer about restore and restart @@ -3521,7 +3529,11 @@ void LLFloaterPreference:: doRestoreSettings(const LLSD& notification,const LLSD } // Close the window so the restored settings can't be destroyed by the user - onBtnOK(); + LLFloaterPreference* instance = LLFloaterReg::findTypedInstance("preferences"); + if (instance) + { + instance->onBtnOK(); + } if(gSavedSettings.getBOOL("RestoreGlobalSettings")) { @@ -3661,11 +3673,11 @@ void LLFloaterPreference:: doRestoreSettings(const LLSD& notification,const LLSD } } // Tell the user we have finished restoring settings and the viewer must shut down - LLNotificationsUtil::add("RestoreFinished",LLSD(),LLSD(),boost::bind(&LLFloaterPreference::onQuitConfirmed,this,_1,_2)); + LLNotificationsUtil::add("RestoreFinished",LLSD(),LLSD(),boost::bind(&FSPanelPreferenceBackup::onQuitConfirmed,this,_1,_2)); } // User confirmed the shutdown and we proceed -void LLFloaterPreference::onQuitConfirmed(const LLSD& notification,const LLSD& response) +void FSPanelPreferenceBackup::onQuitConfirmed(const LLSD& notification,const LLSD& response) { // Make sure the viewer will not save any settings on exit, so our copied files will survive LLAppViewer::instance()->setSaveSettingsOnExit(FALSE); @@ -3674,17 +3686,17 @@ void LLFloaterPreference::onQuitConfirmed(const LLSD& notification,const LLSD& r LLAppViewer::instance()->requestQuit(); } -void LLFloaterPreference::onClickSelectAll() +void FSPanelPreferenceBackup::onClickSelectAll() { doSelect(TRUE); } -void LLFloaterPreference::onClickDeselectAll() +void FSPanelPreferenceBackup::onClickDeselectAll() { doSelect(FALSE); } -void LLFloaterPreference::doSelect(BOOL all) +void FSPanelPreferenceBackup::doSelect(BOOL all) { // Get scroll list control that holds the list of global files LLScrollListCtrl* globalScrollList=getChild("restore_global_files_list"); @@ -3698,7 +3710,7 @@ void LLFloaterPreference::doSelect(BOOL all) applySelection(globalFoldersScrollList,all); } -void LLFloaterPreference::applySelection(LLScrollListCtrl* control,BOOL all) +void FSPanelPreferenceBackup::applySelection(LLScrollListCtrl* control,BOOL all) { // Pull out all data std::vector itemList=control->getAllData(); diff --git a/indra/newview/llfloaterpreference.h b/indra/newview/llfloaterpreference.h index 23e1d98e77..8eced39999 100755 --- a/indra/newview/llfloaterpreference.h +++ b/indra/newview/llfloaterpreference.h @@ -93,8 +93,11 @@ public: void selectPrivacyPanel(); void selectChatPanel(); -protected: +// Make onBtnOk() public for settings backup panel +//protected: void onBtnOK(); +protected: +// void onBtnCancel(); void onBtnApply(); @@ -211,18 +214,6 @@ public: static void refreshSkin(void* data); void selectPanel(const LLSD& name); - // Backup settings - void onClickSetBackupSettingsPath(); - void onClickSelectAll(); - void onClickDeselectAll(); - void onClickBackupSettings(); - void onClickRestoreSettings(); - - void doSelect(BOOL all); // calls applySelection for each list - void applySelection(LLScrollListCtrl* control,BOOL all); // selects or deselects all items in a scroll list - void doRestoreSettings(const LLSD& notification,const LLSD& response); // callback for restore dialog - void onQuitConfirmed(const LLSD& notification,const LLSD& response); // callback for finished restore dialog -// private: void onDeleteTranscripts(); @@ -346,6 +337,28 @@ public: }; // [/SL:KB] +// Settings Backup +class FSPanelPreferenceBackup : public LLPanelPreference +{ +public: + FSPanelPreferenceBackup(); + /*virtual*/ BOOL postBuild(); + +protected: + // Backup settings + void onClickSetBackupSettingsPath(); + void onClickSelectAll(); + void onClickDeselectAll(); + void onClickBackupSettings(); + void onClickRestoreSettings(); + + void doSelect(BOOL all); // calls applySelection for each list + void applySelection(LLScrollListCtrl* control,BOOL all); // selects or deselects all items in a scroll list + void doRestoreSettings(const LLSD& notification,const LLSD& response); // callback for restore dialog + void onQuitConfirmed(const LLSD& notification,const LLSD& response); // callback for finished restore dialog + // +}; + #ifdef OPENSIM // // class LLPanelPreferenceOpensim : public LLPanelPreference