X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=vv%2FvvUtils.cxx;h=3ef9cc606b2d6d7a87a6ee97b2699ce01056aadf;hb=497f4e3a54a75a1dce99ad4a94a3aaa1ea904323;hp=d4d8b2c5ddc9ae114c1f68a4abec37834b1ab404;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git
diff --git a/vv/vvUtils.cxx b/vv/vvUtils.cxx
index d4d8b2c..3ef9cc6 100644
--- a/vv/vvUtils.cxx
+++ b/vv/vvUtils.cxx
@@ -1,65 +1,72 @@
/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Program: vv
- Language: C++
- Author : Joel Schaerer (joel.schaerer@insa-lyon.fr)
+ 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
-Copyright (C) 2008
-Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
-CREATIS-LRMN 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.
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
+ It is distributed under dual licence
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-
-=========================================================================*/
-
-#include
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#include
#include
#include
-
#include "clitkCommon.h"
#include "vvUtils.h"
const std::string vv_user_file=".vv_settings.txt";
+const std::string recentFileList="recentFiles";
typedef std::list FileListType;
+QString getVVSettingsPath(){
+ return QDir::homePath()+QString::fromStdString("/"+vv_user_file);
+}
+
+QSettings::Format getSettingsOptionFormat(){
+ return QSettings::IniFormat;
+}
+
///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;
+ QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
+ FileListType result;
+ settings.beginGroup(QString::fromStdString(recentFileList));
+ QStringList keys = settings.childKeys();
+ for(int i=0; i= 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();
+ QSettings settings(getVVSettingsPath(), getSettingsOptionFormat());
+ 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);
+
+ 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();
}
+