]> Creatis software - clitk.git/blob - vv/vvUtils.cxx
361c7809f4fc22867c08b6771cd81f14af45549b
[clitk.git] / vv / vvUtils.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #include <sstream>
19 #include <algorithm>
20 #include <QDir>
21 #include <QSettings>
22 #include "clitkCommon.h"
23 #include "vvUtils.h"
24
25 const std::string vv_user_file=".vv_settings.txt";
26 typedef std::list<std::string> FileListType;
27
28 static QSettings settings(QDir::homePath()+QString::fromStdString("/"+vv_user_file), QSettings::NativeFormat);
29 ///Returns the last images opened by the user
30 FileListType GetRecentlyOpenedImages()
31 {
32   FileListType result;
33   settings.beginGroup("recentFiles");
34     QStringList keys = settings.childKeys();
35     for(int i=0; i<keys.size(); i++){
36       std::string value=settings.value(QString::fromStdString (keys[i].toStdString())).toString().toStdString();
37       result.push_back(value);
38     }
39   settings.endGroup();
40   return result;
41 }
42
43 ///Adds an image to the list of recently opened images
44 void AddToRecentlyOpenedImages(std::string filename)
45 {
46   FileListType file_list = GetRecentlyOpenedImages();
47   
48   FileListType::iterator i = std::find(file_list.begin(),file_list.end(),filename);
49   if (i != file_list.end()) // avoid dupes
50     file_list.erase(i);
51   while (file_list.size() >= 6) //keep list to a reasonable size
52     file_list.pop_back();
53   file_list.push_front(filename);
54   
55   settings.beginGroup("recentFiles");
56   int index=0;
57   for (FileListType::iterator j = file_list.begin() ; j != file_list.end() ; j++){
58     QString s=QString(index++);
59     settings.setValue(s, QString::fromStdString ( *j ));
60   }
61   settings.endGroup();
62 }