libquentier  0.5.0
The library for rich desktop clients of Evernote service
Utility.h
1 /*
2  * Copyright 2016-2020 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_UTILITY_UTILITY_H
20 #define LIB_QUENTIER_UTILITY_UTILITY_H
21 
22 #include <quentier/types/ErrorString.h>
23 #include <quentier/utility/Linkage.h>
24 
25 #include <qt5qevercloud/QEverCloud.h>
26 
27 #include <QByteArray>
28 #include <QFileDialog>
29 #include <QFlags>
30 #include <QString>
31 #include <QStyle>
32 #include <QtGlobal>
33 #include <QUrl>
34 
35 #include <cstdint>
36 
40 #define SEC_TO_MSEC(sec) (sec * 1000)
41 
42 namespace quentier {
43 
48 void QUENTIER_EXPORT initializeLibquentier();
49 
57 template <class T>
58 bool checkGuid(const T & guid)
59 {
60  qint32 guidSize = static_cast<qint32>(guid.size());
61 
62  if (guidSize < qevercloud::EDAM_GUID_LEN_MIN) {
63  return false;
64  }
65 
66  if (guidSize > qevercloud::EDAM_GUID_LEN_MAX) {
67  return false;
68  }
69 
70  return true;
71 }
72 
82 bool QUENTIER_EXPORT checkUpdateSequenceNumber(
83  const int32_t updateSequenceNumber);
84 
89 class QUENTIER_EXPORT DateTimePrint
90 {
91 public:
95  enum Option {
100  IncludeNumericTimestamp = 1 << 1,
104  IncludeMilliseconds = 1 << 2,
110  IncludeTimezone = 1 << 3
111  };
112  Q_DECLARE_FLAGS(Options, Option)
113 };
114 
115 Q_DECLARE_OPERATORS_FOR_FLAGS(DateTimePrint::Options)
116 
117 
134 const QString QUENTIER_EXPORT printableDateTimeFromTimestamp(
135  const qint64 timestamp,
136  DateTimePrint::Options options = DateTimePrint::Options(
140  const char * customFormat = nullptr);
141 
148 QUENTIER_EXPORT QStyle * applicationStyle();
149 
159 const QString QUENTIER_EXPORT humanReadableSize(const quint64 bytes);
160 
165 const QString QUENTIER_EXPORT getExistingFolderDialog(
166  QWidget * parent, const QString & title, const QString & initialFolder,
167  QFileDialog::Options options = QFileDialog::ShowDirsOnly);
168 
183 const QString QUENTIER_EXPORT relativePathFromAbsolutePath(
184  const QString & absolutePath, const QString & relativePathRootFolderPath);
185 
189 const QString QUENTIER_EXPORT getCurrentUserName();
190 
194 const QString QUENTIER_EXPORT getCurrentUserFullName();
195 
199 void QUENTIER_EXPORT openUrl(const QUrl & url);
200 
209 bool QUENTIER_EXPORT removeFile(const QString & filePath);
210 
220 bool QUENTIER_EXPORT removeDir(const QString & dirPath);
221 
233 QByteArray QUENTIER_EXPORT readFileContents(
234  const QString & filePath, ErrorString & errorDescription);
235 
250 bool QUENTIER_EXPORT renameFile(
251  const QString & from, const QString & to, ErrorString & errorDescription);
252 
253 } // namespace quentier
254 
255 #endif // LIB_QUENTIER_UTILITY_UTILITY_H
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:43
Definition: DecryptedTextManager.h:26
The DateTimePrint class simply wraps the enum containing datetime printing options.
Definition: Utility.h:89
Option
Definition: Utility.h:95