comparison base/RecentFiles.cpp @ 156:059b0322009c

* Replace all uses of ConfigFile with QSettings
author Chris Cannam
date Thu, 03 Aug 2006 16:04:00 +0000
parents 4b2ea82fd0ed
children 702fc936e6a6
comparison
equal deleted inserted replaced
155:ae9be6b6b522 156:059b0322009c
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "RecentFiles.h" 16 #include "RecentFiles.h"
17 #include "ConfigFile.h"
18 17
19 #include "Preferences.h" 18 #include "Preferences.h"
20 19
21 #include <QFileInfo> 20 #include <QFileInfo>
21 #include <QSettings>
22 22
23 RecentFiles * 23 RecentFiles *
24 RecentFiles::m_instance = 0; 24 RecentFiles::m_instance = 0;
25 25
26 RecentFiles * 26 RecentFiles *
45 45
46 void 46 void
47 RecentFiles::readFiles() 47 RecentFiles::readFiles()
48 { 48 {
49 m_files.clear(); 49 m_files.clear();
50 ConfigFile *cf = Preferences::getInstance()->getConfigFile(); 50 QSettings settings;
51 settings.beginGroup("RecentFiles");
52
51 for (unsigned int i = 0; i < 100; ++i) { 53 for (unsigned int i = 0; i < 100; ++i) {
52 QString key = QString("recent-file-%1").arg(i); 54 QString key = QString("recent-file-%1").arg(i);
53 QString filename = cf->get(key); 55 QString filename = settings.value(key, "").toString();
54 if (filename == "") break; 56 if (filename == "") break;
55 if (i < m_maxFileCount) m_files.push_back(filename); 57 if (i < m_maxFileCount) m_files.push_back(filename);
56 else cf->set(key, ""); 58 else settings.setValue(key, "");
57 } 59 }
58 cf->commit(); 60
61 settings.endGroup();
59 } 62 }
60 63
61 void 64 void
62 RecentFiles::writeFiles() 65 RecentFiles::writeFiles()
63 { 66 {
64 ConfigFile *cf = Preferences::getInstance()->getConfigFile(); 67 QSettings settings;
68 settings.beginGroup("RecentFiles");
69
65 for (unsigned int i = 0; i < m_maxFileCount; ++i) { 70 for (unsigned int i = 0; i < m_maxFileCount; ++i) {
66 QString key = QString("recent-file-%1").arg(i); 71 QString key = QString("recent-file-%1").arg(i);
67 QString filename = ""; 72 QString filename = "";
68 if (i < m_files.size()) filename = m_files[i]; 73 if (i < m_files.size()) filename = m_files[i];
69 cf->set(key, filename); 74 settings.setValue(key, filename);
70 } 75 }
71 cf->commit(); 76
77 settings.endGroup();
72 } 78 }
73 79
74 void 80 void
75 RecentFiles::truncateAndWrite() 81 RecentFiles::truncateAndWrite()
76 { 82 {