comparison recentfiles.h @ 63:2340b00561d2

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