1 //**********************************************************************************
2 //EncryptPad Copyright 2016 Evgeny Pokhilko
3 //<http://www.evpo.net/encryptpad>
4 //
5 //This file is part of EncryptPad
6 //
7 //EncryptPad is free software: you can redistribute it and/or modify
8 //it under the terms of the GNU General Public License as published by
9 //the Free Software Foundation, either version 2 of the License, or
10 //(at your option) any later version.
11 //
12 //EncryptPad is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //GNU General Public License for more details.
16 //
17 //You should have received a copy of the GNU General Public License
18 //along with EncryptPad.  If not, see <http://www.gnu.org/licenses/>.
19 //**********************************************************************************
20 #ifndef RECENT_FILES_SERVICE_H
21 #define RECENT_FILES_SERVICE_H
22 
23 #include "assert.h"
24 #include <QMenu>
25 #include <QAction>
26 #include <QStringList>
27 #include <QFileInfo>
28 #include <QWidget>
29 #include <QObject>
30 #include <QDebug>
31 #include <QSignalMapper>
32 
33 class RecentFilesService
34         : public QObject
35 {
36     Q_OBJECT
37 private:
38     QWidget *parent_;
39     QMenu *menu_;
40     int begin_index_;
41     QAction *end_;
42     int max_files_;
43     int file_count_;
44 
45     QAction *CreateAction(const QString &name, const QString &path);
46     void RemoveAction(QAction *action);
47 signals:
48     void FileSelected(const QString &path);
49 public:
50     RecentFilesService(QWidget *parent);
51     virtual ~RecentFilesService();
52 
53     // begin - separator before recent files, end - next menu item after recent files separator
54     void Init(QMenu *menu, QAction *begin, QAction *end);
55     void Serialize(QStringList &list);
56     void Deserialize(const QStringList &list, int max_files);
57     void PushFile(const QString &file_path);
58     void SetMaxFiles(int max_files);
59     int GetMaxFiles() const;
60     void TriggerFileSelected(QString path);
61 };
62 
63 #endif // RECENT_FILES_SERVICE_H
64