]> Creatis software - clitk.git/commitdiff
- version of vv in vvCommon.h
authorMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 12:55:52 +0000 (14:55 +0200)
committerMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 12:55:52 +0000 (14:55 +0200)
- register form being launched at every application launch
- calling a local server if the user agrees to send the register form
- writing qtSettings instead of a plain file. if a non QtSettings saved file is present at the same location, it is written over.

vv/CMakeLists.txt
vv/qt_ui/vvRegisterForm.ui [new file with mode: 0644]
vv/vvCommon.h.in [new file with mode: 0644]
vv/vvMainWindow.cxx
vv/vvRegisterForm.cxx [new file with mode: 0644]
vv/vvRegisterForm.h [new file with mode: 0644]
vv/vvUtils.cxx

index ca6152b39b91137024b6170d8cc69745c4bd1cb3..25cac3d36ebeac45f3a0835482c0596514b91fa0 100644 (file)
@@ -7,6 +7,7 @@ if(COMMAND cmake_policy)
 endif(COMMAND cmake_policy)
 #=========================================================
 
+
 #=========================================================
 #List of vv tools to compile
 SET(vv_TOOLS
@@ -62,6 +63,7 @@ SET(vv_COMMON_WITH_UI
   vvToolSimpleInputSelectorWidget
   vvToolInputSelectorWidget
   vvToolStructureSetManager
+  vvRegisterForm
 )
 
 # All others sources
@@ -113,10 +115,12 @@ QT4_WRAP_CPP(vv_SRCS
   vvStructureSetActor.h
   vvROIActor.h
   vvToolCreatorBase.h
+  vvRegisterForm.h
   )
 
 QT4_WRAP_UI(vv_UI_CXX 
   qt_ui/vvHelpDialog.ui 
+  qt_ui/vvRegisterForm.ui 
   qt_ui/vvDocumentation.ui 
   qt_ui/vvDicomSeriesSelector.ui 
   qt_ui/vvDummyWindow.ui #For testing
@@ -256,3 +260,9 @@ ELSE(WIN32)
 ENDIF(WIN32)
 INCLUDE(CPack)
 #=========================================================
+#=========================================================
+configure_file (
+ vvCommon.h.in
+ vvCommon.h
+)
+#=========================================================
\ No newline at end of file
diff --git a/vv/qt_ui/vvRegisterForm.ui b/vv/qt_ui/vvRegisterForm.ui
new file mode 100644 (file)
index 0000000..59f7764
--- /dev/null
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>vvRegisterForm</class>
+ <widget class="QDialog" name="vvRegisterForm">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>389</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QDialogButtonBox" name="buttonBox">
+   <property name="geometry">
+    <rect>
+     <x>40</x>
+     <y>260</y>
+     <width>341</width>
+     <height>32</height>
+    </rect>
+   </property>
+   <property name="orientation">
+    <enum>Qt::Horizontal</enum>
+   </property>
+   <property name="standardButtons">
+    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="firstName">
+   <property name="geometry">
+    <rect>
+     <x>160</x>
+     <y>120</y>
+     <width>201</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>120</y>
+     <width>61</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>First name</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>140</y>
+     <width>61</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Last name</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lastName">
+   <property name="geometry">
+    <rect>
+     <x>160</x>
+     <y>140</y>
+     <width>201</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="email">
+   <property name="geometry">
+    <rect>
+     <x>160</x>
+     <y>160</y>
+     <width>201</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="group">
+   <property name="geometry">
+    <rect>
+     <x>160</x>
+     <y>180</y>
+     <width>201</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>160</y>
+     <width>61</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Email</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_4">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>180</y>
+     <width>61</width>
+     <height>20</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Institute</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>vvRegisterForm</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>vvRegisterForm</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/vv/vvCommon.h.in b/vv/vvCommon.h.in
new file mode 100644 (file)
index 0000000..7ad04e6
--- /dev/null
@@ -0,0 +1,2 @@
+#define VV_VERSION "v@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@"
+                              
\ No newline at end of file
index 18020b1cc3cb8b61b6d60ac4893bdc2845ea6156..3a11afe6f176917ae6dc5d566b262268958eea2e 100644 (file)
 #include <QInputDialog>
 #include <QTimer>
 #include "QTreePushButton.h"
+#include <QUrl>
 
 // VV include
 #include "vvMainWindow.h"
 #include "vvHelpDialog.h"
+#include "vvRegisterForm.h"
 #include "vvDocumentation.h"
 #include "vvProgressDialog.h"
 #include "vvQDicomSeriesSelector.h"
@@ -331,6 +333,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage()));
   timerMemory->start(2000);
   
+  
+  vvRegisterForm* registerForm = new vvRegisterForm(QUrl("http://localhost/vvregister/write.php"));
+  registerForm->show();
+  
 }
 //------------------------------------------------------------------------------
 
diff --git a/vv/vvRegisterForm.cxx b/vv/vvRegisterForm.cxx
new file mode 100644 (file)
index 0000000..3903796
--- /dev/null
@@ -0,0 +1,53 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#include <QApplication>
+
+#include "vvRegisterForm.h"
+#include <QNetworkRequest>
+#include <iostream>
+#include "common/globals.h"
+#include "vvCommon.h"
+
+vvRegisterForm::vvRegisterForm(QUrl url):url(url) { 
+  manager = new QNetworkAccessManager(this);
+  setupUi(this);
+}
+
+void vvRegisterForm::sendData(){
+ if(canPush()){
+  QUrl url2(url);
+  url2.addQueryItem("name", firstName->text().toUtf8());
+  url2.addQueryItem("lastName", lastName->text().toUtf8());
+  url2.addQueryItem("email", email->text().toUtf8());
+  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();
+ }
+}
+void vvRegisterForm::accept(){
+ sendData();
+ QDialog::accept();
+}
+bool vvRegisterForm::canPush(){
+ return true; 
+}
+void vvRegisterForm::acquitPushed(){
+  
+}
\ No newline at end of file
diff --git a/vv/vvRegisterForm.h b/vv/vvRegisterForm.h
new file mode 100644 (file)
index 0000000..10c5770
--- /dev/null
@@ -0,0 +1,42 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to: 
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef vvRegisterForm_h
+#define vvRegisterForm_h
+
+#include "ui_vvRegisterForm.h"
+#include <QUrl>
+#include <QNetworkAccessManager>
+class vvRegisterForm : public QDialog, private Ui::vvRegisterForm
+{
+    Q_OBJECT
+
+public:
+    vvRegisterForm(QUrl url);
+    void sendData();
+    ~vvRegisterForm() {}
+    //return true only if first time
+    virtual bool canPush();
+    virtual void acquitPushed();
+public slots:
+  virtual void accept();
+protected:
+  QUrl url;
+  QNetworkAccessManager* manager;
+};
+
+#endif
index 441b4b3731970f44b92e8a7a013b6f5219ebf3d8..361c7809f4fc22867c08b6771cd81f14af45549b 100644 (file)
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
 ===========================================================================**/
-#include <fstream>
+#include <sstream>
 #include <algorithm>
 #include <QDir>
-
+#include <QSettings>
 #include "clitkCommon.h"
 #include "vvUtils.h"
 
 const std::string vv_user_file=".vv_settings.txt";
 typedef std::list<std::string> FileListType;
 
+static QSettings settings(QDir::homePath()+QString::fromStdString("/"+vv_user_file), QSettings::NativeFormat);
 ///Returns the last images opened by the user
 FileListType GetRecentlyOpenedImages()
 {
-  std::ifstream in((QDir::homePath().toStdString() + "/" + vv_user_file).c_str());
-  std::string current_file;
   FileListType result;
-  in >> current_file;
-  while (in.good()) {
-    result.push_back(current_file);
-    in >> current_file;
-  }
-  in.close();
+  settings.beginGroup("recentFiles");
+    QStringList keys = settings.childKeys();
+    for(int i=0; i<keys.size(); i++){
+      std::string value=settings.value(QString::fromStdString (keys[i].toStdString())).toString().toStdString();
+      result.push_back(value);
+    }
+  settings.endGroup();
   return result;
 }
 
@@ -44,14 +44,19 @@ FileListType GetRecentlyOpenedImages()
 void AddToRecentlyOpenedImages(std::string filename)
 {
   FileListType file_list = GetRecentlyOpenedImages();
+  
   FileListType::iterator i = std::find(file_list.begin(),file_list.end(),filename);
   if (i != file_list.end()) // avoid dupes
     file_list.erase(i);
   while (file_list.size() >= 6) //keep list to a reasonable size
     file_list.pop_back();
   file_list.push_front(filename);
-  std::ofstream out((QDir::homePath().toStdString() + "/" + vv_user_file).c_str(),std::ios_base::out | std::ios_base::trunc);
-  for (FileListType::iterator j = file_list.begin() ; j != file_list.end() ; j++)
-    out << (*j) << std::endl;
-  out.close();
+  
+  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.endGroup();
 }