]> Creatis software - clitk.git/commitdiff
factorising parameters for QSettings
authorMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 15:00:52 +0000 (17:00 +0200)
committerMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 15:00:52 +0000 (17:00 +0200)
we propose the popup only if it is a new version

vv/vvMainWindow.cxx
vv/vvRegisterForm.cxx
vv/vvUtils.cxx
vv/vvUtils.h

index df3b67570cae733ca809e938c417f46be75b2e2e..7075b2c63544bd92760eaa4de2a5a57eb490d22a 100644 (file)
@@ -328,7 +328,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   
   
   vvRegisterForm* registerForm = new vvRegisterForm(QUrl("http://localhost/vvregister/write.php"));
-  registerForm->show();
+  if(registerForm->canPush()){
+      registerForm->show();
+      registerForm->acquitPushed();//too bad if there is not internet connection anymore.
+  }
   
 }
 //------------------------------------------------------------------------------
index 39037967e861654997ecf41152004b3694da7a20..430ba5fd4330c47824727509a10524307d2e0ad2 100644 (file)
 
 #include "vvRegisterForm.h"
 #include <QNetworkRequest>
+#include <QSettings>
+#include <QDir>
 #include <iostream>
 #include "common/globals.h"
 #include "vvCommon.h"
+#include "vvUtils.h"
 
 vvRegisterForm::vvRegisterForm(QUrl url):url(url) { 
   manager = new QNetworkAccessManager(this);
@@ -29,7 +32,6 @@ vvRegisterForm::vvRegisterForm(QUrl url):url(url) {
 }
 
 void vvRegisterForm::sendData(){
- if(canPush()){
   QUrl url2(url);
   url2.addQueryItem("name", firstName->text().toUtf8());
   url2.addQueryItem("lastName", lastName->text().toUtf8());
@@ -37,17 +39,17 @@ void vvRegisterForm::sendData(){
   url2.addQueryItem("group", group->text().toUtf8());
   url2.addQueryItem("os", QString::fromUtf8(OS_NAME));
   url2.addQueryItem("vvVersion", QString::fromUtf8(VV_VERSION));
-  manager->get(QNetworkRequest(url2));//make pushed in callback?
-  acquitPushed();
- }
+  manager->get(QNetworkRequest(url2));
 }
 void vvRegisterForm::accept(){
- sendData();
- QDialog::accept();
 sendData();
 QDialog::accept();
 }
 bool vvRegisterForm::canPush(){
- return true; 
+  QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
+  return settings.value("vvVersion").toString().toStdString()<VV_VERSION;
 }
 void vvRegisterForm::acquitPushed(){
-  
+  QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
+  settings.setValue("vvVersion", VV_VERSION);
 }
\ No newline at end of file
index 361c7809f4fc22867c08b6771cd81f14af45549b..e9920479ec0e2e62722bec6fbaa4aaf223972ae8 100644 (file)
 #include <sstream>
 #include <algorithm>
 #include <QDir>
-#include <QSettings>
 #include "clitkCommon.h"
 #include "vvUtils.h"
 
 const std::string vv_user_file=".vv_settings.txt";
+const std::string recentFileList="recentFiles";
 typedef std::list<std::string> FileListType;
 
-static QSettings settings(QDir::homePath()+QString::fromStdString("/"+vv_user_file), QSettings::NativeFormat);
+QString getVVSettingsPath(){
+  return QDir::homePath()+QString::fromStdString("/"+vv_user_file);
+}
+
+QSettings::Format getSettingsOptionFormat(){
+  return QSettings::NativeFormat;
+}
+
 ///Returns the last images opened by the user
 FileListType GetRecentlyOpenedImages()
 {
+  QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
   FileListType result;
-  settings.beginGroup("recentFiles");
+  settings.beginGroup(QString::fromStdString(recentFileList));
     QStringList keys = settings.childKeys();
     for(int i=0; i<keys.size(); i++){
       std::string value=settings.value(QString::fromStdString (keys[i].toStdString())).toString().toStdString();
@@ -43,6 +51,7 @@ FileListType GetRecentlyOpenedImages()
 ///Adds an image to the list of recently opened images
 void AddToRecentlyOpenedImages(std::string filename)
 {
+  QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
   FileListType file_list = GetRecentlyOpenedImages();
   
   FileListType::iterator i = std::find(file_list.begin(),file_list.end(),filename);
@@ -52,11 +61,12 @@ void AddToRecentlyOpenedImages(std::string filename)
     file_list.pop_back();
   file_list.push_front(filename);
   
-  settings.beginGroup("recentFiles");
-  int index=0;
-  for (FileListType::iterator j = file_list.begin() ; j != file_list.end() ; j++){
-    QString s=QString(index++);
-    settings.setValue(s, QString::fromStdString ( *j ));
-  }
+  settings.beginGroup(QString::fromStdString(recentFileList));
+    int index=0;
+    for (FileListType::iterator j = file_list.begin() ; j != file_list.end() ; j++){
+      QString s=QString(index++);
+      settings.setValue(s, QString::fromStdString ( *j ));
+    }
   settings.endGroup();
 }
+
index f8631dd8f09af720b639f25ad2a970d60f4ff1c6..5854b5b6141c6e6221acf7d4ddf4faf1b4d7a908 100644 (file)
@@ -19,6 +19,7 @@
 #define vvXXX_h
 #include <list>
 #include <string>
+#include <QSettings>
 
 ///Returns the last images opened by the user
 std::list<std::string> GetRecentlyOpenedImages();
@@ -26,4 +27,10 @@ std::list<std::string> GetRecentlyOpenedImages();
 ///Adds an image to the list of recently opened images
 void AddToRecentlyOpenedImages(std::string filename);
 
+///path to user settings
+QString getVVSettingsPath();
+
+///by default nativeFormat
+QSettings::Format getSettingsOptionFormat();
+
 #endif