comparison src/recentfiles.h @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents recentfiles.h@8fd71f570884
children 533519ebc0cb
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
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) 2011 Chris Cannam
9 Copyright (c) 2011 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 preference for whether to include temporary files
63 * in the recent files menu: the file will not be added if the
64 * preference is set and the file appears to be a temporary one.
65 */
66 void addFile(QString name);
67
68 signals:
69 void recentChanged();
70
71 protected:
72 QString m_settingsGroup;
73 size_t m_maxCount;
74 bool m_ignoreTemporaries;
75
76 std::deque<QString> m_names;
77
78 void read();
79 void write();
80 void truncateAndWrite();
81 };
82
83 #endif