summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-17 21:31:08 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-17 21:31:08 +0300
commit4cd44430deb5a7efc030839a133fe8510327fc24 (patch)
tree79558ea0608257be85840cfb8289c20080fdc70b
parent2e84ac20fcf6ec69b40e19c4c6c428db04b70d85 (diff)
downloadmv-4cd44430deb5a7efc030839a133fe8510327fc24.tar.gz
mv-4cd44430deb5a7efc030839a133fe8510327fc24.tar.bz2
mv-4cd44430deb5a7efc030839a133fe8510327fc24.tar.xz
mv-4cd44430deb5a7efc030839a133fe8510327fc24.zip
Update servers list once a day.
-rw-r--r--src/gui/serverdialog.cpp15
-rw-r--r--src/gui/serverdialog.h4
-rw-r--r--src/utils/stringutils.cpp14
-rw-r--r--src/utils/stringutils.h2
4 files changed, 34 insertions, 1 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 55eda908e..da61e105b 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -305,7 +305,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
loadServers(true);
- if (mServers.empty())
+ if (needUpdateServers())
downloadServerList();
}
@@ -487,6 +487,8 @@ void ServerDialog::downloadServerList()
mDownload->setFile(mDir + "/" + branding.getStringValue(
"onlineServerFile"));
mDownload->start();
+
+ config.setValue("serverslistupdate", getDateString());
}
void ServerDialog::loadServers(bool addNew)
@@ -742,3 +744,14 @@ void ServerDialog::updateServer(ServerInfo server, int index)
{
saveCustomServers(server, index);
}
+
+bool ServerDialog::needUpdateServers()
+{
+ if (mServers.empty() || config.getStringValue("serverslistupdate")
+ != getDateString())
+ {
+ return true;
+ }
+
+ return false;
+}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index c23fb8776..61620364c 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -138,12 +138,16 @@ class ServerDialog : public Window,
* Called to load a list of available server from an online xml file.
*/
void downloadServerList();
+
void loadServers(bool addNew = true);
void loadCustomServers();
+
void saveCustomServers(const ServerInfo &currentServer = ServerInfo(),
int index = -1);
+ bool needUpdateServers();
+
static int downloadUpdate(void *ptr, DownloadStatus status,
size_t total, size_t remaining);
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 9184ba79d..2be1e5b77 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -609,3 +609,17 @@ bool strStartWith(std::string str1, std::string str2)
return false;
return str1.substr(0, str2.size()) == str2;
}
+
+std::string getDateString()
+{
+ char buffer[80];
+
+ time_t rawtime;
+ struct tm *timeinfo;
+
+ time (&rawtime);
+ timeinfo = localtime(&rawtime);
+
+ strftime(buffer, 79, "%Y-%m-%d", timeinfo);
+ return std::string(buffer);
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 47d495dd0..31ee6d51f 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -206,4 +206,6 @@ std::string &removeProtocol(std::string &url);
bool strStartWith(std::string str, std::string start);
+std::string getDateString();
+
#endif // UTILS_STRINGUTILS_H