annotate src/recentfiles.h @ 721:744933aba33a

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