← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2307: Save settings periodically

 

------------------------------------------------------------
revno: 2307
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-11-25 19:35:55 +0100
message:
  Save settings periodically
modified:
  changelog.txt
  dcpp/SettingsManager.cpp
  dcpp/SettingsManager.h
  dwt/include/dwt/aspects/AspectTimer.h
  help/settings_expert.html
  win32/Advanced3Page.cpp
  win32/HashProgressDlg.cpp
  win32/HubFrame.cpp
  win32/MainWindow.cpp
  win32/MainWindow.h
  win32/NotepadFrame.cpp
  win32/NotepadFrame.h
  win32/PublicHubsFrame.cpp
  win32/SearchFrame.cpp
  win32/SpyFrame.cpp
  win32/StatsFrame.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2010-11-24 22:14:02 +0000
+++ changelog.txt	2010-11-25 18:35:55 +0000
@@ -37,6 +37,7 @@
 * Update OpenSSL to version 1.0.0b (poy)
 * [L#378829] Make sure our OpenSSL binaries aren't "optimized for MS-DOS" (poy)
 * [L#674545] Add magnet keyword search (thanks flow84)
+* [L#506288] Save settings periodically (poy)
 
 -- 0.770 2010-07-05 --
 * [L#550300] Catch more potential file corruptions (thanks bigmuscle)

=== modified file 'dcpp/SettingsManager.cpp'
--- dcpp/SettingsManager.cpp	2010-11-19 15:11:20 +0000
+++ dcpp/SettingsManager.cpp	2010-11-25 18:35:55 +0000
@@ -89,7 +89,7 @@
 	"BandwidthLimitStart", "BandwidthLimitEnd", "TimeDependentThrottle", "MaxDownloadSpeedRealTime",
 	"MaxUploadSpeedTime", "MaxDownloadSpeedPrimary", "MaxUploadSpeedPrimary",
 	"SlotsAlternateLimiting", "SlotsPrimaryLimiting",
-	"AutoDetectIncomingConnection",
+	"AutoDetectIncomingConnection", "SettingsSaveInterval",
 	"SENTRY",
 	// Int64
 	"TotalUpload", "TotalDownload",
@@ -307,6 +307,7 @@
 	setDefault(BANDWIDTH_LIMIT_END, 1);
 	setDefault(SLOTS_ALTERNATE_LIMITING, 1);
 	setDefault(SLOTS_PRIMARY, 3);
+	setDefault(SETTINGS_SAVE_INTERVAL, 10);
 
 	setSearchTypeDefaults();
 

=== modified file 'dcpp/SettingsManager.h'
--- dcpp/SettingsManager.h	2010-10-24 18:06:17 +0000
+++ dcpp/SettingsManager.h	2010-11-25 18:35:55 +0000
@@ -109,7 +109,7 @@
 		BANDWIDTH_LIMIT_START, BANDWIDTH_LIMIT_END, TIME_DEPENDENT_THROTTLE, MAX_DOWNLOAD_SPEED_ALTERNATE,
 		MAX_UPLOAD_SPEED_ALTERNATE, MAX_DOWNLOAD_SPEED_MAIN, MAX_UPLOAD_SPEED_MAIN,
 		SLOTS_ALTERNATE_LIMITING, SLOTS_PRIMARY,
-		AUTO_DETECT_CONNECTION,
+		AUTO_DETECT_CONNECTION, SETTINGS_SAVE_INTERVAL,
 		INT_LAST };
 
 	enum Int64Setting { INT64_FIRST = INT_LAST + 1,

=== modified file 'dwt/include/dwt/aspects/AspectTimer.h'
--- dwt/include/dwt/aspects/AspectTimer.h	2010-07-10 14:36:48 +0000
+++ dwt/include/dwt/aspects/AspectTimer.h	2010-11-25 18:35:55 +0000
@@ -41,23 +41,19 @@
 	WidgetType& W() { return *static_cast<WidgetType*>(this); }
 	HWND H() { return W().handle(); }
 
-	struct TimerDispatcher {
-		typedef std::function<bool ()> F;
-
-		TimerDispatcher(const F& f_) : f(f_) { }
+	struct TimerDispatcher : Dispatchers::Base<bool ()> {
+		typedef Dispatchers::Base<bool ()> BaseType;
+		TimerDispatcher(const F& f_) : BaseType(f_) { }
 
 		bool operator()(const MSG& msg, LRESULT& ret) const {
 			if(!f()) {
 				/// @todo remove from message map as well...
 				::KillTimer(msg.hwnd, msg.wParam);
 			}
-			return FALSE;
+			return true;
 		}
-
-		F f;
 	};
 
-
 public:
 	/// Creates a timer object.
 	/** The supplied function must have the signature bool foo() <br>
@@ -65,16 +61,19 @@
 	  * If your event handler returns true, it will keep getting called periodically, otherwise
 	  * it will be removed.
 	  */
-	void createTimer(const typename TimerDispatcher::F& f, unsigned int milliSeconds, unsigned int id = 0);
-
+	void setTimer(const typename TimerDispatcher::F& f, unsigned int milliSeconds, unsigned int id = 0);
 };
 
 template< class WidgetType >
-void AspectTimer< WidgetType >::createTimer( const typename TimerDispatcher::F& f,
+void AspectTimer< WidgetType >::setTimer( const typename TimerDispatcher::F& f,
 	unsigned int milliSecond, unsigned int id)
 {
-	::SetTimer( H(), id, static_cast< UINT >( milliSecond ), NULL);
-	W().addCallback(Message( WM_TIMER, id ), TimerDispatcher(f));
+	if(milliSecond) {
+		::SetTimer(H(), id, milliSecond, 0);
+		W().setCallback(Message(WM_TIMER, id), TimerDispatcher(f));
+	} else {
+		::KillTimer(H(), id);
+	}
 }
 
 }

=== modified file 'help/settings_expert.html'
--- help/settings_expert.html	2010-08-23 16:04:27 +0000
+++ help/settings_expert.html	2010-11-25 18:35:55 +0000
@@ -14,6 +14,11 @@
 It is limited by the speed of your disk subsystem, but it can be
 used to make hashing slower and less noticable. A "normal" hash
 speed may be anywhere from 20 to 50 MiB/s.  (no default)</dd>
+  <dt>Write buffer size</dt>
+  <dd cshelp="IDH_SETTINGS_ADVANCED3_BUFFERSIZE">This controls the size of the chunks that DC++ writes to
+disk for downloads. Measured in kibibytes. (default: 16 KiB)</dd>
+  <dt id="autosearchlimit">Auto-search limit</dt>
+  <dd cshelp="IDH_SETTINGS_ADVANCED3_AUTO_SEARCH_LIMIT">This will limit the amount of sources a file can have before it will no longer be auto searched for. For example, if this option is set to 2, if a file has more than or exactly 2 sources, the file will be excluded from the auto-search list.</dd>
   <dt id="minislotsize">Mini slot size</dt>
   <dd cshelp="IDH_SETTINGS_ADVANCED3_MINISLOT_SIZE">This defines the size of the <a href="settings_sharing.html#slots">mini slot</a>. The
 minimum value for this setting is 64 KiB. (default: 64 KiB)</dd>
@@ -24,17 +29,6 @@
 malformed file lists that require large amounts of memory to decode.
 You may need to reduce or increase the value of this setting
 based on personal experience. (default: 512 MiB)</dd>
-  <dt>PID</dt>
-  <dd cshelp="IDH_SETTINGS_ADVANCED3_PRIVATE_ID">This is your unique private ID (PID). This will later with an algorithm be used to identify you on ADC hubs. <b>Do not share this with other users.</b></dd>
-  <dt id="autorefresh">Auto refresh time</dt>
-  <dd cshelp="IDH_SETTINGS_ADVANCED3_AUTO_REFRESH_TIME">This controls the interval at which your shared directories
-are rescanned for new and changed content. This is measured
-in minutes. (default: 60 minutes)</dd>
-  <dt>Write buffer size</dt>
-  <dd cshelp="IDH_SETTINGS_ADVANCED3_BUFFERSIZE">This controls the size of the chunks that DC++ writes to
-disk for downloads. Measured in kibibytes. (default: 16 KiB)</dd>
-  <dt id="autosearchlimit">Auto-search limit</dt>
-  <dd cshelp="IDH_SETTINGS_ADVANCED3_AUTO_SEARCH_LIMIT">This will limit the amount of sources a file can have before it will no longer be auto searched for. For example, if this option is set to 2, if a file has more than or exactly 2 sources, the file will be excluded from the auto-search list.</dd>
   <dt>Bind address</dt>
   <dd cshelp="IDH_SETTINGS_ADVANCED3_BIND_ADDRESS">This setting allows you to bind DC++ to a particular IP address on your
   machine. Most users do not need to change the default value, 0.0.0.0. However, if you have more than one network interface
@@ -43,6 +37,16 @@
   Automatic incoming connection type detection</a> is enabled. If you experience connection problems make sure that this is set
   to default. (default:0.0.0.0)<br/>
   <i>This feature requires a restart to be fully effective.</i></dd>
+  <dt>PID</dt>
+  <dd cshelp="IDH_SETTINGS_ADVANCED3_PRIVATE_ID">This is your unique private ID (PID). This will later with an algorithm be used to identify you on ADC hubs. <b>Do not share this with other users.</b></dd>
+  <dt id="autorefresh">Auto refresh time</dt>
+  <dd cshelp="IDH_SETTINGS_ADVANCED3_AUTO_REFRESH_TIME">This controls the interval at which your shared directories
+are rescanned for new and changed content. This is measured
+in minutes. (default: 60 minutes)</dd>
+  <dt>Settings save interval</dt>
+  <dd cshelp="IDH_SETTINGS_ADVANCED3_SETTINGS_SAVE_INTERVAL">This controls the interval at which
+  your settings are automatically saved; good to prevent losses in case of crashes. This is
+  measured in minutes. (default: 10 minutes)</dd>
   <dt>Socket read buffer</dt>
   <dd cshelp="IDH_SETTINGS_ADVANCED3_SOCKET_IN_BUFFER">The size of the buffer DC++ use to read sockets. Measured
 in bytes. (default: 8192 bytes)</dd>

=== modified file 'win32/Advanced3Page.cpp'
--- win32/Advanced3Page.cpp	2010-02-11 21:44:13 +0000
+++ win32/Advanced3Page.cpp	2010-11-25 18:35:55 +0000
@@ -31,7 +31,7 @@
 {
 	setHelpId(IDH_ADVANCED3PAGE);
 
-	grid = addChild(Grid::Seed(5, 2));
+	grid = addChild(Grid::Seed(6, 2));
 	grid->column(0).mode = GridInfo::FILL;
 	grid->column(1).mode = GridInfo::FILL;
 	grid->setSpacing(10);
@@ -43,8 +43,9 @@
 	addItem(T_("Max filelist size"), SettingsManager::MAX_FILELIST_SIZE, true, IDH_SETTINGS_ADVANCED3_MAX_FILELIST_SIZE, T_("MiB"));
 	addItem(T_("Bind address"), SettingsManager::BIND_ADDRESS, false, IDH_SETTINGS_ADVANCED3_BIND_ADDRESS);
 	addItem(T_("PID"), SettingsManager::PRIVATE_ID, false, IDH_SETTINGS_ADVANCED3_PRIVATE_ID);
+	addItem(T_("Auto refresh time"), SettingsManager::AUTO_REFRESH_TIME, true, IDH_SETTINGS_ADVANCED3_AUTO_REFRESH_TIME, T_("minutes"));
+	addItem(T_("Settings save interval"), SettingsManager::SETTINGS_SAVE_INTERVAL, true, IDH_SETTINGS_ADVANCED3_SETTINGS_SAVE_INTERVAL, T_("minutes"));
 	addItem(T_("Socket read buffer"), SettingsManager::SOCKET_IN_BUFFER, true, IDH_SETTINGS_ADVANCED3_SOCKET_IN_BUFFER, T_("B"));
-	addItem(T_("Auto refresh time"), SettingsManager::AUTO_REFRESH_TIME, true, IDH_SETTINGS_ADVANCED3_AUTO_REFRESH_TIME);
 	addItem(T_("Socket write buffer"), SettingsManager::SOCKET_OUT_BUFFER, true, IDH_SETTINGS_ADVANCED3_SOCKET_OUT_BUFFER, T_("B"));
 
 	PropPage::read(items);

=== modified file 'win32/HashProgressDlg.cpp'
--- win32/HashProgressDlg.cpp	2010-08-27 13:47:33 +0000
+++ win32/HashProgressDlg.cpp	2010-11-25 18:35:55 +0000
@@ -93,7 +93,7 @@
 	updateStats();
 
 	HashManager::getInstance()->setPriority(Thread::NORMAL);
-	createTimer(std::bind(&HashProgressDlg::updateStats, this), 1000);
+	setTimer(std::bind(&HashProgressDlg::updateStats, this), 1000);
 
 	setText(T_("Creating file index..."));
 

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2010-10-31 16:10:56 +0000
+++ win32/HubFrame.cpp	2010-11-25 18:35:55 +0000
@@ -296,7 +296,7 @@
 }
 
 void HubFrame::initSecond() {
-	createTimer(std::bind(&HubFrame::eachSecond, this), 1000);
+	setTimer(std::bind(&HubFrame::eachSecond, this), 1000);
 }
 
 bool HubFrame::eachSecond() {

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2010-11-08 16:48:29 +0000
+++ win32/MainWindow.cpp	2010-11-25 18:35:55 +0000
@@ -69,7 +69,6 @@
 #include <dwt/widgets/ToolBar.h>
 #include <dwt/widgets/Spinner.h>
 #include <dwt/widgets/Notification.h>
-#include <dwt/LibraryLoader.h>
 #include <dwt/util/StringUtils.h>
 
 #ifdef HAVE_HTMLHELP_H
@@ -112,7 +111,6 @@
 	initToolbar();
 	initStatusBar();
 	initTransfers();
-	initSecond();
 	initTray();
 
 	addAccel(FCONTROL, '1', std::bind(&MainWindow::switchToolbar, this));
@@ -135,7 +133,10 @@
 	onActivate(std::bind(&MainWindow::handleActivate, this, _1));
 	onSized(std::bind(&MainWindow::handleSized, this, _1));
 	onHelp(std::bind(&WinUtil::help, _1, _2));
+
 	updateStatus();
+	setTimer([this]() -> bool { updateStatus(); return true; }, 1000, TIMER_STATUS);
+
 	layout();
 
 	QueueManager::getInstance()->addListener(this);
@@ -183,8 +184,8 @@
 		});
 	}
 
-	if(dwt::LibraryLoader::getCommonControlsVersion() < PACK_COMCTL_VERSION(5,80))
-		dwt::MessageBox(this).show(T_("Your version of windows common controls is too old for DC++ to run correctly, and you will most probably experience problems with the user interface. You should download version 5.80 or higher from the DC++ homepage or from Microsoft directly."), _T(APPNAME) _T(" ") _T(VERSIONSTRING), dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONEXCLAMATION);
+	if(SETTING(SETTINGS_SAVE_INTERVAL) > 0)
+		setSaveTimer();
 }
 
 void MainWindow::initWindow() {
@@ -779,6 +780,16 @@
 	return WinUtil::createIcon(id, SETTING(TOOLBAR_SIZE));
 }
 
+void MainWindow::setSaveTimer() {
+	setTimer([this]() -> bool { saveSettings(); return true; }, SETTING(SETTINGS_SAVE_INTERVAL) * 60 * 1000, TIMER_SAVE);
+}
+
+void MainWindow::saveSettings() {
+	saveWindowSettings();
+	QueueManager::getInstance()->saveQueue();
+	SettingsManager::getInstance()->save();
+}
+
 void MainWindow::saveWindowSettings() {
 	{
 		WindowManager* wm = WindowManager::getInstance();
@@ -846,15 +857,6 @@
 	return true;
 }
 
-void MainWindow::initSecond() {
-	createTimer(std::bind(&MainWindow::eachSecond, this), 1000);
-}
-
-bool MainWindow::eachSecond() {
-	updateStatus();
-	return true;
-}
-
 void MainWindow::layout() {
 	dwt::Rectangle r(getClientSize());
 
@@ -955,6 +957,7 @@
 	bool lastSortFavUsersFirst = BOOLSETTING(SORT_FAVUSERS_FIRST);
 	bool lastURLReg = BOOLSETTING(URL_HANDLER);
 	bool lastMagnetReg = BOOLSETTING(MAGNET_REGISTER);
+	int lastSettingsSave = SETTING(SETTINGS_SAVE_INTERVAL);
 
 	if(dlg.run() == IDOK) {
 		SettingsManager::getInstance()->save();
@@ -974,6 +977,9 @@
 			WinUtil::registerMagnetHandler();
 
 		ClientManager::getInstance()->infoUpdated();
+
+		if(SETTING(SETTINGS_SAVE_INTERVAL) != lastSettingsSave)
+			setSaveTimer();
 	}
 }
 
@@ -1205,9 +1211,7 @@
 		c = NULL;
 	}
 
-	saveWindowSettings();
-	QueueManager::getInstance()->saveQueue();
-	SettingsManager::getInstance()->save();
+	saveSettings();
 
 	return 0;
 }

=== modified file 'win32/MainWindow.h'
--- win32/MainWindow.h	2010-11-08 16:27:16 +0000
+++ win32/MainWindow.h	2010-11-25 18:35:55 +0000
@@ -102,6 +102,11 @@
 		tstring community;
 	} links;
 
+	enum {
+		TIMER_STATUS,
+		TIMER_SAVE
+	};
+
 	WidgetHPanedPtr paned;
 	MenuPtr mainMenu;
 	MenuPtr viewMenu;
@@ -135,7 +140,6 @@
 	void initStatusBar();
 	void initTabs();
 	void initTransfers();
-	void initSecond();
 	void initTray();
 
 	// User actions
@@ -182,9 +186,10 @@
 
 	void layout();
 	void layoutSlotsSpin();
-	bool eachSecond();
 	void updateStatus();
 	void showPortsError(const string& port);
+	void setSaveTimer();
+	void saveSettings();
 	void saveWindowSettings();
 	void parseCommandLine(const tstring& line);
 	bool chooseFavHubGroup(const tstring& title, tstring& group);

=== modified file 'win32/NotepadFrame.cpp'
--- win32/NotepadFrame.cpp	2010-03-26 17:15:26 +0000
+++ win32/NotepadFrame.cpp	2010-11-25 18:35:55 +0000
@@ -48,16 +48,30 @@
 	}
 
 	pad->setModify(false);
+	SettingsManager::getInstance()->addListener(this);
 
 	layout();
 	activate();
 }
 
 NotepadFrame::~NotepadFrame() {
-
 }
 
 bool NotepadFrame::preClosing() {
+	SettingsManager::getInstance()->removeListener(this);
+	save();
+	return true;
+}
+
+void NotepadFrame::layout() {
+	dwt::Rectangle r(dwt::Point(0, 0), getClientSize());
+
+	status->layout(r);
+
+	pad->layout(r);
+}
+
+void NotepadFrame::save() {
 	if(pad->getModify()) {
 		try {
 			dcdebug("Writing notepad contents\n");
@@ -67,13 +81,8 @@
 			///@todo Notify user
 		}
 	}
-	return true;
 }
 
-void NotepadFrame::layout() {
-	dwt::Rectangle r(dwt::Point(0, 0), getClientSize());
-
-	status->layout(r);
-
-	pad->layout(r);
+void NotepadFrame::on(SettingsManagerListener::Save, SimpleXML&) throw() {
+	callAsync([this] { save(); });
 }

=== modified file 'win32/NotepadFrame.h'
--- win32/NotepadFrame.h	2010-02-11 21:44:13 +0000
+++ win32/NotepadFrame.h	2010-11-25 18:35:55 +0000
@@ -23,7 +23,8 @@
 #include "resource.h"
 
 class NotepadFrame :
-	public StaticFrame<NotepadFrame>
+	public StaticFrame<NotepadFrame>,
+	private SettingsManagerListener
 {
 	typedef StaticFrame<NotepadFrame> BaseType;
 public:
@@ -47,6 +48,9 @@
 
 private:
 	TextBoxPtr pad;
+
+	void save();
+	virtual void on(SettingsManagerListener::Save, SimpleXML&) throw();
 };
 
 #endif

=== modified file 'win32/PublicHubsFrame.cpp'
--- win32/PublicHubsFrame.cpp	2010-10-01 14:24:13 +0000
+++ win32/PublicHubsFrame.cpp	2010-11-25 18:35:55 +0000
@@ -447,6 +447,7 @@
 void PublicHubsFrame::handleConfigure() {
 	HubListsDlg dlg(this);
 	if(dlg.run() == IDOK) {
+		SettingsManager::getInstance()->save();
 		updateDropDown();
 	}
 }

=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp	2010-11-19 15:11:20 +0000
+++ win32/SearchFrame.cpp	2010-11-25 18:35:55 +0000
@@ -1008,7 +1008,7 @@
 }
 
 void SearchFrame::initSecond() {
-	createTimer(std::bind(&SearchFrame::eachSecond, this), 1000);
+	setTimer(std::bind(&SearchFrame::eachSecond, this), 1000);
 }
 
 bool SearchFrame::eachSecond() {

=== modified file 'win32/SpyFrame.cpp'
--- win32/SpyFrame.cpp	2010-07-10 14:36:48 +0000
+++ win32/SpyFrame.cpp	2010-11-25 18:35:55 +0000
@@ -102,7 +102,7 @@
 }
 
 void SpyFrame::initSecond() {
-	createTimer(std::bind(&SpyFrame::eachSecond, this), 1000);
+	setTimer(std::bind(&SpyFrame::eachSecond, this), 1000);
 }
 
 bool SpyFrame::eachSecond() {

=== modified file 'win32/StatsFrame.cpp'
--- win32/StatsFrame.cpp	2010-10-29 15:30:05 +0000
+++ win32/StatsFrame.cpp	2010-11-25 18:35:55 +0000
@@ -55,7 +55,7 @@
 	layout();
 	activate();
 
-	createTimer(std::bind(&StatsFrame::eachSecond, this), 1000);
+	setTimer(std::bind(&StatsFrame::eachSecond, this), 1000);
 }
 
 StatsFrame::~StatsFrame() {