Debian Codegraph @

include/Library/Library.h

raw symbols SCIP
1 /*
2 * Copyright 2014 Mihai Niculescu <[email protected]>
3 *
4 * This file is part of EqualX Project (https://launchpad.net/equalx/)
5 *
6 * EqualX is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * EqualX is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef LIBRARY_H
21 #define LIBRARY_H
22
23 #include <QObject>
24 #include <QSqlDatabase>
25
26 #include "LibraryData.h"
27
28 class LibraryManager : public QObject
29 {
30 Q_OBJECT
31 public:
32 enum SEARCH_MODE{
33 SEARCH_BY_TITLE_DESCRIPTION,
34 SEARCH_BY_TITLE,
35 SEARCH_BY_DESCRIPTION,
36 SEARCH_BY_CONTENT
37 };
38
39 static LibraryManager* Instance();
40
41 QString errorStr() const {return mErrStr;}
42
43 /* Add an equation with 'title' and 'description' in bookmarks
44 * which its parent is specified by 'parentId'. If successful,
45 * it copies the file 'file' to the folder which is represented
46 * in the database by 'parentId'. If 'parentId'= 1, then its
47 * parent is the root node.
48 *
49 * If everything went well, it returns the id of the equation in DB.
50 * If not it returns -1;
51 */
52 int addBookmark(const QString& title, const QString& description, const QString& file, int parentId=1);
53 int addBookmark(const Bookmark& bookmark, int parentId=1);
54 /* Add a folder to bookmarks in database. If successful, create
55 * a subfolder to the folder which has id. If 'parentId'= 1, then its
56 * parent is the root node.
57 *
58 * If everything went well it returns the id of the folder in DB
59 * If not it returns -1;
60 */
61 int addBookmarkFolder(const QString& name, const QString& description=QString(""), int parentId=1);
62 int addBookmarkFolder(const BookmarkFolder& folder, int parentId=1);
63
64 /* Add an equation specified by 'title' and 'file' in history. If successful,
65 * it copies the file 'file' to history folder.
66 *
67 * If everything went well, it returns the id of the equation in history.
68 * If not it returns -1;
69 */
70 int addHistoryItem(const QString& title, const QString& file);
71
72 LibraryRowsList getAllHistory();
73 const HistoryRow getHistoryRow(int id);
74
75
76 Bookmark getBookmark(int id);
77 BookmarkFolder getBookmarkFolder(int id);
78
79 // returns a list with all children (all bookmarks and subfolders) contained in parent folder
80 LibraryRowsList getChildren(int idparent=1);
81
82 // returns a list with all folders in bookmarks
83 LibraryRowsList getAllBookmarkedFolders();
84
85 int childrenCountInFolder(int id=1); // returns the direct number of children of folder (subfolders+bookmarks)
86
87 int historySize(); // returns the number of items in history
88
89 // copy bookmark with id 'id' to folder with id 'idparent'
90 // returns the new copied bookmark
91 Bookmark copyBookmark(int id, int idparent=1);
92
93 // copy folder (including all subnodes) with 'id' to folder 'idparent'
94 // returns the new copied folder
95 BookmarkFolder copyBookmarkFolder(int id, int idparent=1);
96
97 /* Move Actions */
98 // these will emit 2 bookmarkFolderChanged() signals:
99 // one for the old folder, second for the new folder
100 bool moveData(const LibraryModelData& data, int newParentId);
101 bool moveBookmark(int id, int newParentId);
102 bool moveBookmarkFolder(int id, int newParentId);
103
104 /* Update fields (no reparenting) */
105 bool updateData(const LibraryModelData& data);
106 bool updateBookmark(const Bookmark &bookmark);
107 bool updateBookmarkFolder(const BookmarkFolder &folder);
108
109 /* Remove Actions */
110 bool removeBookmark(int id);
111 bool removeBookmarkFolder(int id);
112
113 // returns the absolute path to the root library directory
114 QString path() const;
115
116 LibraryRowsList searchBookmarks(QString searchText, SEARCH_MODE searchType=SEARCH_BY_TITLE_DESCRIPTION);
117 public slots:
118 bool clearHistory();
119
120 signals:
121 void bookmarkAdded(const Bookmark &);
122 void bookmarksChanged();
123 void bookmarkFolderChanged(const QString& dirPath);
124 void historyChanged();
125 void historyChanged(const HistoryRow &);
126
127 private:
128 explicit LibraryManager(QObject *parent = 0);
129 LibraryManager(LibraryManager const&); // copy constructor not implemented
130 LibraryManager& operator=(LibraryManager const&); // assignment operator not implemented
131 virtual ~LibraryManager();
132
133 bool setup();
134 bool createLibrary(const QString& path);
135 bool createDatabaseTablesFromFile(const QString& sqlFile);
136
137 int lastId(const QString& tableName);
138 bool removeSystemDir(const QString& dirName); // removes a system directory recursively
139 bool removeBookmarkFromFS(int id, const QString &filetype);
140
141 void copyChildren(int ofFolderId, int toNewFolderId);
142 protected:
143 QSqlDatabase mDB;
144 QString mErrStr; // error string
145 QString mBookmarksDirStr; // absolute path to the library dir
146 QString mHistoryDirStr; // absolute path to history dir
147
148 private:
149 static LibraryManager* mInstance;
150 };
151
152 #endif // LIBRARY_H