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