comparison base/RecentFiles.h @ 0:fc9323a41f5a

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