RecentFiles.h
Go to the documentation of this file.
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 SV_RECENT_FILES_H
17 #define SV_RECENT_FILES_H
18 
19 #include <QObject>
20 #include <QString>
21 #include <QMutex>
22 #include <vector>
23 #include <deque>
24 
36 class RecentFiles : public QObject
37 {
38  Q_OBJECT
39 
40 public:
46  RecentFiles(QString settingsGroup = "RecentFiles",
47  int maxCount = 10);
48 
49  virtual ~RecentFiles();
50 
54  QString getSettingsGroup() const {
55  return m_settingsGroup;
56  }
57 
61  int getMaxCount() const {
62  return m_maxCount;
63  }
64 
68  std::vector<QString> getRecentIdentifiers() const;
69 
75  std::vector<QString> getRecent() const {
76  return getRecentIdentifiers();
77  }
78 
83  std::vector<std::pair<QString, QString>> getRecentEntries() const;
84 
92  void add(QString identifier, QString label = "");
93 
107  void addFile(QString filepath, QString label = "");
108 
109 signals:
110  void recentChanged();
111 
112 private:
113  mutable QMutex m_mutex;
114 
115  const QString m_settingsGroup;
116  const int m_maxCount;
117 
118  std::deque<std::pair<QString, QString>> m_entries; // identifier, label
119 
120  void read();
121  void write();
122  void truncateAndWrite();
123 };
124 
125 #endif
void recentChanged()
std::vector< std::pair< QString, QString > > getRecentEntries() const
Return the list of recent identifiers, with labels.
const int m_maxCount
Definition: RecentFiles.h:116
std::vector< QString > getRecent() const
Return the list of recent identifiers, without labels.
Definition: RecentFiles.h:75
QMutex m_mutex
Definition: RecentFiles.h:113
void add(QString identifier, QString label="")
Add a literal identifier, optionally with a label.
virtual ~RecentFiles()
Definition: RecentFiles.cpp:32
void addFile(QString filepath, QString label="")
Add a name that is known to be either a file path or a URL, optionally with a label.
void write()
Definition: RecentFiles.cpp:66
const QString m_settingsGroup
Definition: RecentFiles.h:115
QString getSettingsGroup() const
Return the settingsGroup as passed to the constructor.
Definition: RecentFiles.h:54
std::deque< std::pair< QString, QString > > m_entries
Definition: RecentFiles.h:118
std::vector< QString > getRecentIdentifiers() const
Return the list of recent identifiers, without labels.
RecentFiles manages a list of recently-used identifier strings, saving and restoring that list via QS...
Definition: RecentFiles.h:36
void truncateAndWrite()
Definition: RecentFiles.cpp:90
int getMaxCount() const
Return the maxCount as passed to the constructor.
Definition: RecentFiles.h:61
RecentFiles(QString settingsGroup="RecentFiles", int maxCount=10)
Construct a RecentFiles object that saves and restores in the given QSettings group and truncates whe...
Definition: RecentFiles.cpp:25