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 
135  bool isLocalStorageVersionTooHigh(ErrorString & errorDescription);
136 
152  bool localStorageRequiresUpgrade(ErrorString & errorDescription);
153 
162  bool upgradeLocalStorage(ErrorString & errorDescription);
163 
171  qint32 localStorageVersion(ErrorString & errorDescription);
172 
179  qint32 highestSupportedLocalStorageVersion() const;
180 
186  int userCount(ErrorString & errorDescription) const;
187 
198  bool addUser(const User & user, ErrorString & errorDescription);
199 
210  bool updateUser(const User & user, ErrorString & errorDescription);
211 
220  bool findUser(User & user, ErrorString & errorDescription) const;
221 
228  bool deleteUser(const User & user, ErrorString & errorDescription);
229 
236  bool expungeUser(const User & user, ErrorString & errorDescription);
237 
243  int notebookCount(ErrorString & errorDescription) const;
244 
257  bool addNotebook(Notebook & notebook, ErrorString & errorDescription);
258 
273  bool updateNotebook(Notebook & notebook, ErrorString & errorDescription);
274 
298  bool findNotebook(Notebook & notebook, ErrorString & errorDescription) const;
299 
306  bool findDefaultNotebook(Notebook & notebook, ErrorString & errorDescription) const;
307 
314  bool findLastUsedNotebook(Notebook & notebook, ErrorString & errorDescription) const;
315 
323  bool findDefaultOrLastUsedNotebook(Notebook & notebook, ErrorString & errorDescription) const;
324 
330  {
331  enum type
332  {
333  Ascending = 0,
334  Descending
335  };
336  };
337 
343  {
344  enum type
345  {
346  ByUpdateSequenceNumber = 0,
347  ByNotebookName,
348  ByCreationTimestamp,
349  ByModificationTimestamp,
350  NoOrder
351  };
352  };
353 
370  QList<Notebook> listAllNotebooks(ErrorString & errorDescription, const size_t limit = 0,
371  const size_t offset = 0, const ListNotebooksOrder::type order = ListNotebooksOrder::NoOrder,
372  const OrderDirection::type orderDirection = OrderDirection::Ascending,
373  const QString & linkedNotebookGuid = QString()) const;
374 
392  QList<Notebook> listNotebooks(const ListObjectsOptions flag, ErrorString & errorDescription,
393  const size_t limit = 0, const size_t offset = 0,
394  const ListNotebooksOrder::type order = ListNotebooksOrder::NoOrder,
395  const OrderDirection::type orderDirection = OrderDirection::Ascending,
396  const QString & linkedNotebookGuid = QString()) const;
397 
405  QList<SharedNotebook> listAllSharedNotebooks(ErrorString & errorDescription) const;
406 
417  QList<SharedNotebook> listSharedNotebooksPerNotebookGuid(const QString & notebookGuid,
418  ErrorString & errorDescription) const;
419 
434  bool expungeNotebook(Notebook & notebook, ErrorString & errorDescription);
435 
441  int linkedNotebookCount(ErrorString & errorDescription) const;
442 
452  bool addLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
453 
461  bool updateLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
462 
473  bool findLinkedNotebook(LinkedNotebook & linkedNotebook, ErrorString & errorDescription) const;
474 
480  {
481  enum type
482  {
483  ByUpdateSequenceNumber = 0,
484  ByShareName,
485  ByUsername,
486  NoOrder
487  };
488  };
489 
502  QList<LinkedNotebook> listAllLinkedNotebooks(ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
503  const ListLinkedNotebooksOrder::type order = ListLinkedNotebooksOrder::NoOrder,
504  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
505 
520  QList<LinkedNotebook> listLinkedNotebooks(const ListObjectsOptions flag, ErrorString & errorDescription,
521  const size_t limit = 0, const size_t offset = 0,
522  const ListLinkedNotebooksOrder::type order = ListLinkedNotebooksOrder::NoOrder,
523  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
524 
535  bool expungeLinkedNotebook(const LinkedNotebook & linkedNotebook, ErrorString & errorDescription);
536 
542  int noteCount(ErrorString & errorDescription) const;
543 
551  int noteCountPerNotebook(const Notebook & notebook, ErrorString & errorDescription) const;
552 
560  int noteCountPerTag(const Tag & tag, ErrorString & errorDescription) const;
561 
569  bool noteCountsPerAllTags(QHash<QString, int> & noteCountsPerTagLocalUid, ErrorString & errorDescription) const;
570 
580  bool addNote(Note & note, ErrorString & errorDescription);
581 
603  bool updateNote(Note & note, const bool updateResources,
604  const bool updateTags, ErrorString & errorDescription);
605 
618  bool findNote(Note & note, ErrorString & errorDescription,
619  const bool withResourceBinaryData = true) const;
620 
626  {
627  enum type
628  {
629  ByUpdateSequenceNumber = 0,
630  ByTitle,
631  ByCreationTimestamp,
632  ByModificationTimestamp,
633  ByDeletionTimestamp,
634  ByAuthor,
635  BySource,
636  BySourceApplication,
637  ByReminderTime,
638  ByPlaceName,
639  NoOrder
640  };
641  };
642 
662  QList<Note> listNotesPerNotebook(const Notebook & notebook, ErrorString & errorDescription,
663  const bool withResourceBinaryData = true,
664  const ListObjectsOptions & flag = ListAll,
665  const size_t limit = 0, const size_t offset = 0,
666  const ListNotesOrder::type & order = ListNotesOrder::NoOrder,
667  const OrderDirection::type & orderDirection = OrderDirection::Ascending) const;
668 
687  QList<Note> listNotesPerTag(const Tag & tag, ErrorString & errorDescription,
688  const bool withResourceBinaryData,
689  const LocalStorageManager::ListObjectsOptions & flag,
690  const size_t limit, const size_t offset,
691  const LocalStorageManager::ListNotesOrder::type & order,
692  const LocalStorageManager::OrderDirection::type & orderDirection) const;
693 
715  QList<Note> listNotes(const ListObjectsOptions flag, ErrorString & errorDescription,
716  const bool withResourceBinaryData = true, const size_t limit = 0,
717  const size_t offset = 0, const ListNotesOrder::type order = ListNotesOrder::NoOrder,
718  const OrderDirection::type orderDirection = OrderDirection::Ascending,
719  const QString & linkedNotebookGuid = QString()) const;
720 
727  QStringList findNoteLocalUidsWithSearchQuery(const NoteSearchQuery & noteSearchQuery,
728  ErrorString & errorDescription) const;
729 
743  NoteList findNotesWithSearchQuery(const NoteSearchQuery & noteSearchQuery,
744  ErrorString & errorDescription,
745  const bool withResourceBinaryData = true) const;
746 
758  bool expungeNote(Note & note, ErrorString & errorDescription);
759 
765  int tagCount(ErrorString & errorDescription) const;
766 
776  bool addTag(Tag & tag, ErrorString & errorDescription);
777 
791  bool updateTag(Tag & tag, ErrorString & errorDescription);
792 
813  bool findTag(Tag & tag, ErrorString & errorDescription) const;
814 
816  {
817  enum type
818  {
819  ByUpdateSequenceNumber,
820  ByName,
821  NoOrder
822  };
823  };
824 
841  QList<Tag> listAllTagsPerNote(const Note & note, ErrorString & errorDescription,
842  const ListObjectsOptions & flag = ListAll,
843  const size_t limit = 0, const size_t offset = 0,
844  const ListTagsOrder::type & order = ListTagsOrder::NoOrder,
845  const OrderDirection::type & orderDirection = OrderDirection::Ascending) const;
846 
863  QList<Tag> listAllTags(ErrorString & errorDescription, const size_t limit = 0,
864  const size_t offset = 0, const ListTagsOrder::type order = ListTagsOrder::NoOrder,
865  const OrderDirection::type orderDirection = OrderDirection::Ascending,
866  const QString & linkedNotebookGuid = QString()) const;
867 
884  QList<Tag> listTags(const ListObjectsOptions flag, ErrorString & errorDescription,
885  const size_t limit = 0, const size_t offset = 0,
886  const ListTagsOrder::type & order = ListTagsOrder::NoOrder,
887  const OrderDirection::type orderDirection = OrderDirection::Ascending,
888  const QString & linkedNotebookGuid = QString()) const;
889 
903  bool expungeTag(Tag & tag, QStringList & expungedChildTagLocalUids, ErrorString & errorDescription);
904 
911  bool expungeNotelessTagsFromLinkedNotebooks(ErrorString & errorDescription);
912 
919  int enResourceCount(ErrorString & errorDescription) const;
920 
929  bool addEnResource(Resource & resource, ErrorString & errorDescription);
930 
944  bool updateEnResource(Resource & resource, ErrorString & errorDescription);
945 
957  bool findEnResource(Resource & resource, ErrorString & errorDescription, const bool withBinaryData = true) const;
958 
959  // NOTE: there is no 'deleteEnResource' method for a reason: resources are deleted automatically
960  // in remote storage so there's no need to mark some resource as deleted for the synchronization procedure.
961 
970  bool expungeEnResource(Resource & resource, ErrorString & errorDescription);
971 
977  int savedSearchCount(ErrorString & errorDescription) const;
978 
988  bool addSavedSearch(SavedSearch & search, ErrorString & errorDescription);
989 
1003  bool updateSavedSearch(SavedSearch & search, ErrorString & errorDescription);
1004 
1013  bool findSavedSearch(SavedSearch & search, ErrorString & errorDescription) const;
1014 
1020  {
1021  enum type
1022  {
1023  ByUpdateSequenceNumber = 0,
1024  ByName,
1025  ByFormat,
1026  NoOrder
1027  };
1028  };
1029 
1042  QList<SavedSearch> listAllSavedSearches(ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
1043  const ListSavedSearchesOrder::type order = ListSavedSearchesOrder::NoOrder,
1044  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
1045 
1060  QList<SavedSearch> listSavedSearches(const ListObjectsOptions flag, ErrorString & errorDescription, const size_t limit = 0, const size_t offset = 0,
1061  const ListSavedSearchesOrder::type order = ListSavedSearchesOrder::NoOrder,
1062  const OrderDirection::type orderDirection = OrderDirection::Ascending) const;
1063 
1064  // NOTE: there is no 'deleteSearch' method for a reason: saved searches are deleted automatically
1065  // in remote storage so there's no need to mark some saved search as deleted for synchronization procedure.
1066 
1075  bool expungeSavedSearch(SavedSearch & search, ErrorString & errorDescription);
1076 
1086  qint32 accountHighUsn(const QString & linkedNotebookGuid, ErrorString & errorDescription);
1087 
1088 private:
1089  LocalStorageManager() Q_DECL_EQ_DELETE;
1090  Q_DISABLE_COPY(LocalStorageManager)
1091 
1092  QScopedPointer<LocalStorageManagerPrivate> d_ptr;
1093  Q_DECLARE_PRIVATE(LocalStorageManager)
1094 };
1095 
1096 Q_DECLARE_OPERATORS_FOR_FLAGS(LocalStorageManager::ListObjectsOptions)
1097 
1098 } // namespace quentier
1099 
1100 #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:815
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:329
Definition: Resource.h:29
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:1019
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:625
Definition: NoteSearchQuery.h:29
The ListLinkedNotebooksOrder struct is a C++98-style scoped enum which allows to specify ordering of ...
Definition: LocalStorageManager.h:479
The ListNotebooksOrder struct is a C++98 style scoped enum which allows to specify the ordering of th...
Definition: LocalStorageManager.h:342
Definition: LocalStorageManager.h:49
Definition: SavedSearch.h:36