libquentier  0.4.0
The library for rich desktop clients of Evernote service
Utility.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_UTILITY_UTILITY_H
20 #define LIB_QUENTIER_UTILITY_UTILITY_H
21 
22 #include <quentier/utility/Linkage.h>
23 #include <QtGlobal>
24 
25 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
26 #include <qt5qevercloud/QEverCloud.h>
27 #else
28 #include <qt4qevercloud/QEverCloud.h>
29 #endif
30 
31 #include <QString>
32 #include <QUrl>
33 #include <QStyle>
34 #include <QFileDialog>
35 #include <QFlags>
36 
37 #include <cstdint>
38 
42 #define SEC_TO_MSEC(sec) (sec * 1000)
43 
44 namespace quentier {
45 
50 void QUENTIER_EXPORT initializeLibquentier();
51 
58 template <class T>
59 bool checkGuid(const T & guid)
60 {
61  qint32 guidSize = static_cast<qint32>(guid.size());
62 
63  if (guidSize < qevercloud::EDAM_GUID_LEN_MIN) {
64  return false;
65  }
66 
67  if (guidSize > qevercloud::EDAM_GUID_LEN_MAX) {
68  return false;
69  }
70 
71  return true;
72 }
73 
80 bool QUENTIER_EXPORT checkUpdateSequenceNumber(const int32_t updateSequenceNumber);
81 
85 class QUENTIER_EXPORT DateTimePrint
86 {
87 public:
91  enum Option {
95  IncludeNumericTimestamp = 1 << 1,
99  IncludeMilliseconds = 1 << 2,
104  IncludeTimezone = 1 << 3
105  };
106  Q_DECLARE_FLAGS(Options, Option)
107 };
108 
109 Q_DECLARE_OPERATORS_FOR_FLAGS(DateTimePrint::Options)
110 
111 
121 const QString QUENTIER_EXPORT printableDateTimeFromTimestamp(const qint64 timestamp,
122  DateTimePrint::Options options =
123  DateTimePrint::Options(DateTimePrint::IncludeNumericTimestamp |
126  const char * customFormat = Q_NULLPTR);
127 
133 QUENTIER_EXPORT QStyle * applicationStyle();
134 
142 const QString QUENTIER_EXPORT humanReadableSize(const quint64 bytes);
143 
147 const QString QUENTIER_EXPORT getExistingFolderDialog(QWidget * parent, const QString & title,
148  const QString & initialFolder,
149  QFileDialog::Options options = QFileDialog::ShowDirsOnly);
150 
159 const QString QUENTIER_EXPORT relativePathFromAbsolutePath(const QString & absolutePath,
160  const QString & relativePathRootFolderPath);
161 
166 const QString QUENTIER_EXPORT getCurrentUserName();
167 
172 const QString QUENTIER_EXPORT getCurrentUserFullName();
173 
177 void QUENTIER_EXPORT openUrl(const QUrl & url);
178 
186 bool QUENTIER_EXPORT removeFile(const QString & filePath);
187 
195 bool QUENTIER_EXPORT removeDir(const QString & dirPath);
196 
197 } // namespace quentier
198 
199 #endif // LIB_QUENTIER_UTILITY_UTILITY_H
The DateTimePrint class simply wraps the enum containing datetime printing options.
Definition: Utility.h:85
Option
Definition: Utility.h:91