Mercurial > hg > svcore
comparison base/RecentFiles.cpp @ 166:702fc936e6a6
* Pull transforms out of Layer menu (again) and into a separate Transforms
menu
* Add Recent Transforms submenu
* Add effects and generators to the transforms menu (not yet implemented)
as well as analysis plugins and data-from-effects (control output ports)
* Add a nice dictionary-volume-style alphabetic subdivision of plugin names
in plugins By Name menus
author | Chris Cannam |
---|---|
date | Fri, 22 Sep 2006 16:12:23 +0000 |
parents | 059b0322009c |
children | d5052b5fea9c |
comparison
equal
deleted
inserted
replaced
165:5ae5885d6ce3 | 166:702fc936e6a6 |
---|---|
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 | 17 |
18 #include "Preferences.h" | |
19 | |
20 #include <QFileInfo> | 18 #include <QFileInfo> |
21 #include <QSettings> | 19 #include <QSettings> |
22 | 20 |
23 RecentFiles * | 21 RecentFiles::RecentFiles(QString settingsGroup, size_t maxCount) : |
24 RecentFiles::m_instance = 0; | 22 m_settingsGroup(settingsGroup), |
25 | 23 m_maxCount(maxCount) |
26 RecentFiles * | |
27 RecentFiles::getInstance(int maxFileCount) | |
28 { | 24 { |
29 if (!m_instance) { | 25 read(); |
30 m_instance = new RecentFiles(maxFileCount); | |
31 } | |
32 return m_instance; | |
33 } | |
34 | |
35 RecentFiles::RecentFiles(int maxFileCount) : | |
36 m_maxFileCount(maxFileCount) | |
37 { | |
38 readFiles(); | |
39 } | 26 } |
40 | 27 |
41 RecentFiles::~RecentFiles() | 28 RecentFiles::~RecentFiles() |
42 { | 29 { |
43 // nothing | 30 // nothing |
44 } | 31 } |
45 | 32 |
46 void | 33 void |
47 RecentFiles::readFiles() | 34 RecentFiles::read() |
48 { | 35 { |
49 m_files.clear(); | 36 m_names.clear(); |
50 QSettings settings; | 37 QSettings settings; |
51 settings.beginGroup("RecentFiles"); | 38 settings.beginGroup(m_settingsGroup); |
52 | 39 |
53 for (unsigned int i = 0; i < 100; ++i) { | 40 for (size_t i = 0; i < 100; ++i) { |
54 QString key = QString("recent-file-%1").arg(i); | 41 QString key = QString("recent-%1").arg(i); |
55 QString filename = settings.value(key, "").toString(); | 42 QString name = settings.value(key, "").toString(); |
56 if (filename == "") break; | 43 if (name == "") break; |
57 if (i < m_maxFileCount) m_files.push_back(filename); | 44 if (i < m_maxCount) m_names.push_back(name); |
58 else settings.setValue(key, ""); | 45 else settings.setValue(key, ""); |
59 } | 46 } |
60 | 47 |
61 settings.endGroup(); | 48 settings.endGroup(); |
62 } | 49 } |
63 | 50 |
64 void | 51 void |
65 RecentFiles::writeFiles() | 52 RecentFiles::write() |
66 { | 53 { |
67 QSettings settings; | 54 QSettings settings; |
68 settings.beginGroup("RecentFiles"); | 55 settings.beginGroup(m_settingsGroup); |
69 | 56 |
70 for (unsigned int i = 0; i < m_maxFileCount; ++i) { | 57 for (size_t i = 0; i < m_maxCount; ++i) { |
71 QString key = QString("recent-file-%1").arg(i); | 58 QString key = QString("recent-%1").arg(i); |
72 QString filename = ""; | 59 QString name = ""; |
73 if (i < m_files.size()) filename = m_files[i]; | 60 if (i < m_names.size()) name = m_names[i]; |
74 settings.setValue(key, filename); | 61 settings.setValue(key, name); |
75 } | 62 } |
76 | 63 |
77 settings.endGroup(); | 64 settings.endGroup(); |
78 } | 65 } |
79 | 66 |
80 void | 67 void |
81 RecentFiles::truncateAndWrite() | 68 RecentFiles::truncateAndWrite() |
82 { | 69 { |
83 while (m_files.size() > m_maxFileCount) { | 70 while (m_names.size() > m_maxCount) { |
84 m_files.pop_back(); | 71 m_names.pop_back(); |
85 } | 72 } |
86 writeFiles(); | 73 write(); |
87 } | 74 } |
88 | 75 |
89 std::vector<QString> | 76 std::vector<QString> |
90 RecentFiles::getRecentFiles() const | 77 RecentFiles::getRecent() const |
91 { | 78 { |
92 std::vector<QString> files; | 79 std::vector<QString> names; |
93 for (unsigned int i = 0; i < m_maxFileCount; ++i) { | 80 for (size_t i = 0; i < m_maxCount; ++i) { |
94 if (i < m_files.size()) { | 81 if (i < m_names.size()) { |
95 files.push_back(m_files[i]); | 82 names.push_back(m_names[i]); |
96 } | 83 } |
97 } | 84 } |
98 return files; | 85 return names; |
99 } | 86 } |
100 | 87 |
101 void | 88 void |
102 RecentFiles::addFile(QString filename) | 89 RecentFiles::add(QString name) |
103 { | 90 { |
104 filename = QFileInfo(filename).absoluteFilePath(); | |
105 | |
106 bool have = false; | 91 bool have = false; |
107 for (unsigned int i = 0; i < m_files.size(); ++i) { | 92 for (size_t i = 0; i < m_names.size(); ++i) { |
108 if (m_files[i] == filename) { | 93 if (m_names[i] == name) { |
109 have = true; | 94 have = true; |
110 break; | 95 break; |
111 } | 96 } |
112 } | 97 } |
113 | 98 |
114 if (!have) { | 99 if (!have) { |
115 m_files.push_front(filename); | 100 m_names.push_front(name); |
116 } else { | 101 } else { |
117 std::deque<QString> newfiles; | 102 std::deque<QString> newnames; |
118 newfiles.push_back(filename); | 103 newnames.push_back(name); |
119 for (unsigned int i = 0; i < m_files.size(); ++i) { | 104 for (size_t i = 0; i < m_names.size(); ++i) { |
120 if (m_files[i] == filename) continue; | 105 if (m_names[i] == name) continue; |
121 newfiles.push_back(m_files[i]); | 106 newnames.push_back(m_names[i]); |
122 } | 107 } |
123 } | 108 } |
124 | 109 |
125 truncateAndWrite(); | 110 truncateAndWrite(); |
126 emit recentFilesChanged(); | 111 emit recentChanged(); |
112 } | |
113 | |
114 void | |
115 RecentFiles::addFile(QString name) | |
116 { | |
117 add(QFileInfo(name).absoluteFilePath()); | |
127 } | 118 } |
128 | 119 |
129 | 120 |