Chris@149: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@149: Chris@149: /* Chris@149: Sonic Visualiser Chris@149: An audio file viewer and annotation editor. Chris@149: Centre for Digital Music, Queen Mary, University of London. Chris@149: This file copyright 2006 Chris Cannam. Chris@149: Chris@149: This program is free software; you can redistribute it and/or Chris@149: modify it under the terms of the GNU General Public License as Chris@149: published by the Free Software Foundation; either version 2 of the Chris@149: License, or (at your option) any later version. See the file Chris@149: COPYING included with this distribution for more information. Chris@149: */ Chris@149: Chris@149: #ifndef _RECENT_FILES_H_ Chris@149: #define _RECENT_FILES_H_ Chris@149: Chris@149: #include Chris@149: #include Chris@149: #include Chris@149: #include Chris@149: Chris@166: /** Chris@166: * RecentFiles manages a list of the names of recently-used objects, Chris@166: * saving and restoring that list via QSettings. The names do not Chris@166: * actually have to refer to files. Chris@166: */ Chris@166: Chris@149: class RecentFiles : public QObject Chris@149: { Chris@149: Q_OBJECT Chris@149: Chris@149: public: Chris@166: /** Chris@166: * Construct a RecentFiles object that saves and restores in the Chris@166: * given QSettings group and truncates when the given count of Chris@166: * strings is reached. Chris@166: */ Chris@166: RecentFiles(QString settingsGroup = "RecentFiles", size_t maxCount = 10); Chris@149: Chris@149: virtual ~RecentFiles(); Chris@149: Chris@166: QString getSettingsGroup() const { return m_settingsGroup; } Chris@149: Chris@166: int getMaxCount() const { return m_maxCount; } Chris@166: Chris@166: std::vector getRecent() const; Chris@166: Chris@166: /** Chris@166: * Add a name that should be treated as a literal string. Chris@166: */ Chris@166: void add(QString name); Chris@149: Chris@166: /** Chris@209: * Add a name that is known to be either a file path or a URL. If Chris@209: * it looks like a URL, add it literally; otherwise treat it as a Chris@277: * file path and canonicalise it appropriately. Also takes into Chris@277: * account the user preference for whether to include temporary Chris@277: * files in the recent files menu: the file will not be added if Chris@277: * the preference is set and the file appears to be a temporary Chris@277: * one. Chris@166: */ Chris@166: void addFile(QString name); Chris@149: Chris@149: signals: Chris@166: void recentChanged(); Chris@149: Chris@149: protected: Chris@166: QString m_settingsGroup; Chris@166: size_t m_maxCount; Chris@149: Chris@166: std::deque m_names; Chris@149: Chris@166: void read(); Chris@166: void write(); Chris@149: void truncateAndWrite(); Chris@149: }; Chris@149: Chris@149: #endif