Chris@149
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@149
|
2
|
Chris@149
|
3 /*
|
Chris@149
|
4 Sonic Visualiser
|
Chris@149
|
5 An audio file viewer and annotation editor.
|
Chris@149
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@149
|
7 This file copyright 2006 Chris Cannam.
|
Chris@149
|
8
|
Chris@149
|
9 This program is free software; you can redistribute it and/or
|
Chris@149
|
10 modify it under the terms of the GNU General Public License as
|
Chris@149
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@149
|
12 License, or (at your option) any later version. See the file
|
Chris@149
|
13 COPYING included with this distribution for more information.
|
Chris@149
|
14 */
|
Chris@149
|
15
|
Chris@149
|
16 #ifndef _RECENT_FILES_H_
|
Chris@149
|
17 #define _RECENT_FILES_H_
|
Chris@149
|
18
|
Chris@149
|
19 #include <QObject>
|
Chris@149
|
20 #include <QString>
|
Chris@149
|
21 #include <vector>
|
Chris@149
|
22 #include <deque>
|
Chris@149
|
23
|
Chris@166
|
24 /**
|
Chris@166
|
25 * RecentFiles manages a list of the names of recently-used objects,
|
Chris@166
|
26 * saving and restoring that list via QSettings. The names do not
|
Chris@166
|
27 * actually have to refer to files.
|
Chris@166
|
28 */
|
Chris@166
|
29
|
Chris@149
|
30 class RecentFiles : public QObject
|
Chris@149
|
31 {
|
Chris@149
|
32 Q_OBJECT
|
Chris@149
|
33
|
Chris@149
|
34 public:
|
Chris@166
|
35 /**
|
Chris@166
|
36 * Construct a RecentFiles object that saves and restores in the
|
Chris@166
|
37 * given QSettings group and truncates when the given count of
|
Chris@166
|
38 * strings is reached.
|
Chris@166
|
39 */
|
Chris@166
|
40 RecentFiles(QString settingsGroup = "RecentFiles", size_t maxCount = 10);
|
Chris@149
|
41
|
Chris@149
|
42 virtual ~RecentFiles();
|
Chris@149
|
43
|
Chris@166
|
44 QString getSettingsGroup() const { return m_settingsGroup; }
|
Chris@149
|
45
|
Chris@166
|
46 int getMaxCount() const { return m_maxCount; }
|
Chris@166
|
47
|
Chris@166
|
48 std::vector<QString> getRecent() const;
|
Chris@166
|
49
|
Chris@166
|
50 /**
|
Chris@166
|
51 * Add a name that should be treated as a literal string.
|
Chris@166
|
52 */
|
Chris@166
|
53 void add(QString name);
|
Chris@149
|
54
|
Chris@166
|
55 /**
|
Chris@209
|
56 * Add a name that is known to be either a file path or a URL. If
|
Chris@209
|
57 * it looks like a URL, add it literally; otherwise treat it as a
|
Chris@277
|
58 * file path and canonicalise it appropriately. Also takes into
|
Chris@277
|
59 * account the user preference for whether to include temporary
|
Chris@277
|
60 * files in the recent files menu: the file will not be added if
|
Chris@277
|
61 * the preference is set and the file appears to be a temporary
|
Chris@277
|
62 * one.
|
Chris@166
|
63 */
|
Chris@166
|
64 void addFile(QString name);
|
Chris@149
|
65
|
Chris@149
|
66 signals:
|
Chris@166
|
67 void recentChanged();
|
Chris@149
|
68
|
Chris@149
|
69 protected:
|
Chris@166
|
70 QString m_settingsGroup;
|
Chris@166
|
71 size_t m_maxCount;
|
Chris@149
|
72
|
Chris@166
|
73 std::deque<QString> m_names;
|
Chris@149
|
74
|
Chris@166
|
75 void read();
|
Chris@166
|
76 void write();
|
Chris@149
|
77 void truncateAndWrite();
|
Chris@149
|
78 };
|
Chris@149
|
79
|
Chris@149
|
80 #endif
|