libquentier  0.4.0
The library for rich desktop clients of Evernote service
LocalStorageManager.h
1 /*
2  * Copyright 2016 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_LOCAL_STORAGE_LOCAL_STORAGE_MANAGER_H
20 #define LIB_QUENTIER_LOCAL_STORAGE_LOCAL_STORAGE_MANAGER_H
21 
22 #include <quentier/types/Account.h>
23 #include <quentier/local_storage/Lists.h>
24 #include <quentier/local_storage/NoteSearchQuery.h>
25 #include <quentier/utility/Linkage.h>
26 #include <quentier/utility/Macros.h>
27 #include <quentier/types/ErrorString.h>
28 #include <QString>
29 #include <QScopedPointer>
30 #include <QSharedPointer>
31 #include <QHash>
32 #include <cstdint>
33 
34 namespace qevercloud {
35 QT_FORWARD_DECLARE_STRUCT(ResourceAttributes)
36 QT_FORWARD_DECLARE_STRUCT(NoteAttributes)
37 QT_FORWARD_DECLARE_STRUCT(UserAttributes)
38 QT_FORWARD_DECLARE_STRUCT(Accounting)
39 QT_FORWARD_DECLARE_STRUCT(PremiumInfo)
40 QT_FORWARD_DECLARE_STRUCT(BusinessUserInfo)
41 QT_FORWARD_DECLARE_STRUCT(SharedNotebook)
42 QT_FORWARD_DECLARE_STRUCT(NotebookRestrictions)
43 }
44 
45 namespace quentier {
46 
47 QT_FORWARD_DECLARE_CLASS(LocalStorageManagerPrivate)
48 
49 class QUENTIER_EXPORT LocalStorageManager: public QObject
50 {
51  Q_OBJECT
52 public:
63  LocalStorageManager(const Account & account, const bool startFromScratch, const bool overrideLock);
64 
65  virtual ~LocalStorageManager();
66 
67 Q_SIGNALS:
76  void upgradeProgress(double progress);
77 
78 public:
88  ListAll = 0,
89  ListDirty = 1,
90  ListNonDirty = 2,
91  ListElementsWithoutGuid = 4,
92  ListElementsWithGuid = 8,
93  ListLocal = 16,
94  ListNonLocal = 32,
95  ListFavoritedElements = 64,
96  ListNonFavoritedElements = 128
97  };
98  Q_DECLARE_FLAGS(ListObjectsOptions, ListObjectsOption)
99 
100 
117  void switchUser(const Account & account, const bool startFromScratch = false,
118  const bool overrideLock = false);
119 
125  int userCount(ErrorString & errorDescription) const;
126 
137  bool addUser(const User & user, ErrorString & errorDescription);
138 
149  bool updateUser(const User & user, ErrorString & errorDescription);
150 
159  bool findUser(User & user, ErrorString & errorDescription) const;
160 
167  bool deleteUser(const User & user, ErrorString & errorDescription);
168 
175  bool expungeUser(const User & user, ErrorString & errorDescription);
176 
182  int notebookCount(ErrorString & errorDescription) const;
183 
196  bool addNotebook(Notebook & notebook, ErrorString & errorDescription);
197 
212  bool updateNotebook(Notebook & notebook, ErrorString & errorDescription);
213 
237  bool findNotebook(Notebook & notebook, ErrorString & errorDescription) const;
238 
245  bool findDefaultNotebook(Notebook & notebook, ErrorString & errorDescription) const;
246 
253  bool findLastUsedNotebook(Notebook & notebook, ErrorString & errorDescription) const;
254 
262  bool findDefaultOrLastUsedNotebook(Notebook & notebook, ErrorString & errorDescription) const;
263 
269  {
270  enum type
271  {
272  Ascending = 0,
273  Descending
274  };
275  };
276 
282  {
283  enum type
284  {
285  ByUpdateSequenceNumber = 0,
286  ByNotebookName,
287  ByCreationTimestamp,
288  ByModificationTimestamp,
289  NoOrder
290  };
291  };
292 
309  QList<Notebook> listAllNotebooks(ErrorString & errorDescription, const size_t limit = 0,
310  const size_t offset = 0, const ListNotebooksOrder::type order = ListNotebooksOrder::NoOrder,
311  const OrderDirection::type orderDirection = OrderDirection::Ascending,
312  const QString & linkedNotebookGuid = QString()) const;
313 
331  QList<Notebook> listNotebooks(const ListObjectsOptions flag, ErrorString & errorDescription,
332  const size_t limit = 0, const size_t offset = 0,
333  const ListNotebooksOrder::type order = ListNotebooksOrder::NoOrder,
334  const OrderDirection::type orderDirection = OrderDirection::Ascending,
335  const QString & linkedNotebookGuid = QString()) const;
336 
344  QList<SharedNotebook> listAllSharedNotebooks(ErrorString & errorDescription) const;
345 
356  QList<SharedNotebook> listSharedNotebooksPerNotebookGuid(const QString & notebookGuid,
357  ErrorString & errorDescription) const;
358 
373  bool expungeNotebook(Notebook & notebook, ErrorString & errorDescription);
374 
380  int linkedNotebookCount(ErrorString & errorDescription) const;
381 
391  bool addLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
392 
400  bool updateLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
401 
412  bool findLinkedNotebook(LinkedNotebook & linkedNotebook, ErrorString & errorDescription) const;
413 
419  {
420  enum type
421  {
422  ByUpdateSequenceNumber = 0,
423  ByShareName,
424  ByUsername,
425  NoOrder
426  };
427  };
428 
441  QList<LinkedNotebook> listAllLinkedNotebooks(ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
442  const ListLinkedNotebooksOrder::type order = ListLinkedNotebooksOrder::NoOrder,
443  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
444 
459  QList<LinkedNotebook> listLinkedNotebooks(const ListObjectsOptions flag, ErrorString & errorDescription,
460  const size_t limit = 0, const size_t offset = 0,
461  const ListLinkedNotebooksOrder::type order = ListLinkedNotebooksOrder::NoOrder,
462  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
463 
474  bool expungeLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
475 
481  int noteCount(ErrorString & errorDescription) const;
482 
490  int noteCountPerNotebook(const Notebook & notebook, ErrorString & errorDescription) const;
491 
499  int noteCountPerTag(const Tag & tag, ErrorString & errorDescription) const;
500 
508  bool noteCountsPerAllTags(QHash<QString, int> & noteCountsPerTagLocalUid, ErrorString & errorDescription) const;
509 
519  bool addNote(Note & note, ErrorString & errorDescription);
520 
542  bool updateNote(Note & note, const bool updateResources,
543  const bool updateTags, ErrorString & errorDescription);
544 
557  bool findNote(Note & note, ErrorString & errorDescription,
558  const bool withResourceBinaryData = true) const;
559 
565  {
566  enum type
567  {
568  ByUpdateSequenceNumber = 0,
569  ByTitle,
570  ByCreationTimestamp,
571  ByModificationTimestamp,
572  ByDeletionTimestamp,
573  ByAuthor,
574  BySource,
575  BySourceApplication,
576  ByReminderTime,
577  ByPlaceName,
578  NoOrder
579  };
580  };
581 
601  QList<Note> listNotesPerNotebook(const Notebook & notebook, ErrorString & errorDescription,
602  const bool withResourceBinaryData = true,
603  const ListObjectsOptions & flag = ListAll,
604  const size_t limit = 0, const size_t offset = 0,
605  const ListNotesOrder::type & order = ListNotesOrder::NoOrder,
606  const OrderDirection::type & orderDirection = OrderDirection::Ascending) const;
607 
626  QList<Note> listNotesPerTag(const Tag & tag, ErrorString & errorDescription,
627  const bool withResourceBinaryData,
628  const LocalStorageManager::ListObjectsOptions & flag,
629  const size_t limit, const size_t offset,
630  const LocalStorageManager::ListNotesOrder::type & order,
631  const LocalStorageManager::OrderDirection::type & orderDirection) const;
632 
654  QList<Note> listNotes(const ListObjectsOptions flag, ErrorString & errorDescription,
655  const bool withResourceBinaryData = true, const size_t limit = 0,
656  const size_t offset = 0, const ListNotesOrder::type order = ListNotesOrder::NoOrder,
657  const OrderDirection::type orderDirection = OrderDirection::Ascending,
658  const QString & linkedNotebookGuid = QString()) const;
659 
666  QStringList findNoteLocalUidsWithSearchQuery(const NoteSearchQuery & noteSearchQuery,
667  ErrorString & errorDescription) const;
668 
682  NoteList findNotesWithSearchQuery(const NoteSearchQuery & noteSearchQuery,
683  ErrorString & errorDescription,
684  const bool withResourceBinaryData = true) const;
685 
697  bool expungeNote(Note & note, ErrorString & errorDescription);
698 
704  int tagCount(ErrorString & errorDescription) const;
705 
715  bool addTag(Tag & tag, ErrorString & errorDescription);
716 
730  bool updateTag(Tag & tag, ErrorString & errorDescription);
731 
752  bool findTag(Tag & tag, ErrorString & errorDescription) const;
753 
755  {
756  enum type
757  {
758  ByUpdateSequenceNumber,
759  ByName,
760  NoOrder
761  };
762  };
763 
780  QList<Tag> listAllTagsPerNote(const Note & note, ErrorString & errorDescription,
781  const ListObjectsOptions & flag = ListAll,
782  const size_t limit = 0, const size_t offset = 0,
783  const ListTagsOrder::type & order = ListTagsOrder::NoOrder,
784  const OrderDirection::type & orderDirection = OrderDirection::Ascending) const;
785 
802  QList<Tag> listAllTags(ErrorString & errorDescription, const size_t limit = 0,
803  const size_t offset = 0, const ListTagsOrder::type order = ListTagsOrder::NoOrder,
804  const OrderDirection::type orderDirection = OrderDirection::Ascending,
805  const QString & linkedNotebookGuid = QString()) const;
806 
823  QList<Tag> listTags(const ListObjectsOptions flag, ErrorString & errorDescription,
824  const size_t limit = 0, const size_t offset = 0,
825  const ListTagsOrder::type & order = ListTagsOrder::NoOrder,
826  const OrderDirection::type orderDirection = OrderDirection::Ascending,
827  const QString & linkedNotebookGuid = QString()) const;
828 
842  bool expungeTag(Tag & tag, QStringList & expungedChildTagLocalUids, ErrorString & errorDescription);
843 
850  bool expungeNotelessTagsFromLinkedNotebooks(ErrorString & errorDescription);
851 
858  int enResourceCount(ErrorString & errorDescription) const;
859 
868  bool addEnResource(Resource & resource, ErrorString & errorDescription);
869 
883  bool updateEnResource(Resource & resource, ErrorString & errorDescription);
884 
896  bool findEnResource(Resource & resource, ErrorString & errorDescription, const bool withBinaryData = true) const;
897 
898  // NOTE: there is no 'deleteEnResource' method for a reason: resources are deleted automatically
899  // in remote storage so there's no need to mark some resource as deleted for the synchronization procedure.
900 
909  bool expungeEnResource(Resource & resource, ErrorString & errorDescription);
910 
916  int savedSearchCount(ErrorString & errorDescription) const;
917 
927  bool addSavedSearch(SavedSearch & search, ErrorString & errorDescription);
928 
942  bool updateSavedSearch(SavedSearch & search, ErrorString & errorDescription);
943 
952  bool findSavedSearch(SavedSearch & search, ErrorString & errorDescription) const;
953 
959  {
960  enum type
961  {
962  ByUpdateSequenceNumber = 0,
963  ByName,
964  ByFormat,
965  NoOrder
966  };
967  };
968 
981  QList<SavedSearch> listAllSavedSearches(ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
982  const ListSavedSearchesOrder::type order = ListSavedSearchesOrder::NoOrder,
983  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
984 
999  QList<SavedSearch> listSavedSearches(const ListObjectsOptions flag, ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
1000  const ListSavedSearchesOrder::type order = ListSavedSearchesOrder::NoOrder,
1001  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
1002 
1003  // NOTE: there is no 'deleteSearch' method for a reason: saved searches are deleted automatically
1004  // in remote storage so there's no need to mark some saved search as deleted for synchronization procedure.
1005 
1014  bool expungeSavedSearch(SavedSearch & search, ErrorString & errorDescription);
1015 
1025  qint32 accountHighUsn(const QString & linkedNotebookGuid, ErrorString & errorDescription);
1026 
1027 private:
1028  LocalStorageManager() Q_DECL_EQ_DELETE;
1029  Q_DISABLE_COPY(LocalStorageManager)
1030 
1031  QScopedPointer<LocalStorageManagerPrivate> d_ptr;
1032  Q_DECLARE_PRIVATE(LocalStorageManager)
1033 };
1034 
1035 Q_DECLARE_OPERATORS_FOR_FLAGS(LocalStorageManager::ListObjectsOptions)
1036 
1037 } // namespace quentier
1038 
1039 #endif // LIB_QUENTIER_LOCAL_STORAGE_LOCAL_STORAGE_MANAGER_H
ListObjectsOption
The ListObjectsOption enum is the base enum for QFlags which allows to specify the desired local stor...
Definition: LocalStorageManager.h:87
Definition: LocalStorageManager.h:754
Definition: LinkedNotebook.h:36
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:38
The OrderDirection struct is a C++98 style scoped enum which specifies the direction of ordering of t...
Definition: LocalStorageManager.h:268
Definition: Resource.h:29
Definition: DecryptedTextManager.h:25
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:24
The ListSavedSearchesOrder struct is a C++98-style scoped enum which allows to specify the ordering o...
Definition: LocalStorageManager.h:958
Definition: Notebook.h:38
Definition: Tag.h:36
Definition: User.h:37
Definition: Note.h:38
The ListNotesOrder struct is a C++98-style scoped enum which allows to specify the ordering of the re...
Definition: LocalStorageManager.h:564
Definition: NoteSearchQuery.h:29
Definition: LocalStorageManager.h:34
The ListLinkedNotebooksOrder struct is a C++98-style scoped enum which allows to specify ordering of ...
Definition: LocalStorageManager.h:418
The ListNotebooksOrder struct is a C++98 style scoped enum which allows to specify the ordering of th...
Definition: LocalStorageManager.h:281
Definition: LocalStorageManager.h:49
Definition: SavedSearch.h:36