| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 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 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 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 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 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 |
|
| 80 |
LibraryRowsList getChildren(int idparent=1); |
| 81 |
|
| 82 |
|
| 83 |
LibraryRowsList getAllBookmarkedFolders(); |
| 84 |
|
| 85 |
int childrenCountInFolder(int id=1); |
| 86 |
|
| 87 |
int historySize(); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
Bookmark copyBookmark(int id, int idparent=1); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
BookmarkFolder copyBookmarkFolder(int id, int idparent=1); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
bool moveData(const LibraryModelData& data, int newParentId); |
| 101 |
bool moveBookmark(int id, int newParentId); |
| 102 |
bool moveBookmarkFolder(int id, int newParentId); |
| 103 |
|
| 104 |
|
| 105 |
bool updateData(const LibraryModelData& data); |
| 106 |
bool updateBookmark(const Bookmark &bookmark); |
| 107 |
bool updateBookmarkFolder(const BookmarkFolder &folder); |
| 108 |
|
| 109 |
|
| 110 |
bool removeBookmark(int id); |
| 111 |
bool removeBookmarkFolder(int id); |
| 112 |
|
| 113 |
|
| 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&); |
| 130 |
LibraryManager& operator=(LibraryManager const&); |
| 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); |
| 139 |
bool removeBookmarkFromFS(int id, const QString &filetype); |
| 140 |
|
| 141 |
void copyChildren(int ofFolderId, int toNewFolderId); |
| 142 |
protected: |
| 143 |
QSqlDatabase mDB; |
| 144 |
QString mErrStr; |
| 145 |
QString mBookmarksDirStr; |
| 146 |
QString mHistoryDirStr; |
| 147 |
|
| 148 |
private: |
| 149 |
static LibraryManager* mInstance; |
| 150 |
}; |
| 151 |
|
| 152 |
#endif |