[1f4adec] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright 2014 S. Razi Alavizadeh |
---|
| 4 | Copyright 2013-2015 Adam Reichold |
---|
| 5 | |
---|
| 6 | This file is part of qpdfview. |
---|
| 7 | |
---|
| 8 | qpdfview is free software: you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation, either version 2 of the License, or |
---|
| 11 | (at your option) any later version. |
---|
| 12 | |
---|
| 13 | qpdfview is distributed in the hope that it will be useful, |
---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | GNU General Public License for more details. |
---|
| 17 | |
---|
| 18 | You should have received a copy of the GNU General Public License |
---|
| 19 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
| 20 | |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #ifndef DATABASE_H |
---|
| 24 | #define DATABASE_H |
---|
| 25 | |
---|
| 26 | #include <QObject> |
---|
| 27 | |
---|
| 28 | #ifdef WITH_SQL |
---|
| 29 | |
---|
| 30 | #include <QSqlDatabase> |
---|
| 31 | |
---|
| 32 | #endif // WITH_SQL |
---|
| 33 | |
---|
| 34 | class QDateTime; |
---|
| 35 | |
---|
| 36 | #include "global.h" |
---|
| 37 | |
---|
| 38 | namespace qpdfview |
---|
| 39 | { |
---|
| 40 | |
---|
| 41 | class DocumentView; |
---|
| 42 | |
---|
| 43 | class Database : public QObject |
---|
| 44 | { |
---|
| 45 | Q_OBJECT |
---|
| 46 | |
---|
| 47 | public: |
---|
| 48 | static Database* instance(); |
---|
| 49 | ~Database(); |
---|
| 50 | |
---|
| 51 | QStringList loadInstanceNames(); |
---|
| 52 | |
---|
| 53 | struct RestoreTab |
---|
| 54 | { |
---|
| 55 | virtual DocumentView* operator()(const QString& absoluteFilePath) const = 0; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | void restoreTabs(const RestoreTab& restoreTab); |
---|
| 59 | void saveTabs(const QList< DocumentView* >& tabs); |
---|
| 60 | void clearTabs(); |
---|
| 61 | |
---|
| 62 | void restoreBookmarks(); |
---|
| 63 | void saveBookmarks(); |
---|
| 64 | void clearBookmarks(); |
---|
| 65 | |
---|
| 66 | void restorePerFileSettings(DocumentView* tab); |
---|
| 67 | void savePerFileSettings(const DocumentView* tab); |
---|
| 68 | |
---|
| 69 | private: |
---|
| 70 | Q_DISABLE_COPY(Database) |
---|
| 71 | |
---|
| 72 | static Database* s_instance; |
---|
| 73 | Database(QObject* parent = 0); |
---|
| 74 | |
---|
| 75 | static QString instanceName(); |
---|
| 76 | |
---|
| 77 | #ifdef WITH_SQL |
---|
| 78 | |
---|
| 79 | bool prepareTabs_v4(); |
---|
| 80 | bool prepareBookmarks_v3(); |
---|
| 81 | bool preparePerFileSettings_v4(); |
---|
| 82 | |
---|
| 83 | void migrateTabs_v3_v4(); |
---|
| 84 | void migrateTabs_v2_v4(); |
---|
| 85 | void migrateTabs_v1_v4(); |
---|
| 86 | void migrateBookmarks_v2_v3(); |
---|
| 87 | void migrateBookmarks_v1_v3(); |
---|
| 88 | void migratePerFileSettings_v3_v4(); |
---|
| 89 | void migratePerFileSettings_v2_v4(); |
---|
| 90 | void migratePerFileSettings_v1_v4(); |
---|
| 91 | |
---|
| 92 | bool prepareTable(const QString& prepare); |
---|
| 93 | void migrateTable(const QString& migrate, const QString& prune, const QString& warning); |
---|
| 94 | |
---|
| 95 | void limitPerFileSettings(); |
---|
| 96 | |
---|
| 97 | QSqlDatabase m_database; |
---|
| 98 | |
---|
| 99 | #endif // WITH_SQL |
---|
| 100 | |
---|
| 101 | }; |
---|
| 102 | |
---|
| 103 | } // qpdfview |
---|
| 104 | |
---|
| 105 | #endif // DATABASE_H |
---|