libquentier  0.5.0
The library for rich desktop clients of Evernote service
EventLoopWithExitStatus.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_EVENT_LOOP_WITH_EXIT_STATUS_H
20 #define LIB_QUENTIER_UTILITY_EVENT_LOOP_WITH_EXIT_STATUS_H
21 
22 #include <quentier/types/ErrorString.h>
23 #include <quentier/utility/Linkage.h>
24 #include <quentier/utility/Macros.h>
25 
26 #include <QEventLoop>
27 
28 QT_FORWARD_DECLARE_CLASS(QDebug)
29 QT_FORWARD_DECLARE_CLASS(QTextStream)
30 
31 namespace quentier {
32 
33 class QUENTIER_EXPORT EventLoopWithExitStatus : public QEventLoop
34 {
35  Q_OBJECT
36 public:
37  explicit EventLoopWithExitStatus(QObject * parent = nullptr);
38 
39  enum class ExitStatus
40  {
41  Success,
42  Failure,
43  Timeout
44  };
45 
46  friend QDebug & operator<<(QDebug & dbg, const ExitStatus status);
47 
48  friend QTextStream & operator<<(
49  QTextStream & strm, const ExitStatus status);
50 
51  ExitStatus exitStatus() const;
52  const ErrorString & errorDescription() const;
53 
54 public Q_SLOTS:
55  void exitAsSuccess();
56  void exitAsFailure();
57  void exitAsFailureWithError(QString errorDescription);
58  void exitAsFailureWithErrorString(ErrorString errorDescription);
59  void exitAsTimeout();
60 
61 private:
62  ExitStatus m_exitStatus;
63  ErrorString m_errorDescription;
64 };
65 
66 } // namespace quentier
67 
68 #endif // LIB_QUENTIER_UTILITY_EVENT_LOOP_WITH_EXIT_STATUS_H
quentier::ErrorString
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:43
quentier::EventLoopWithExitStatus
Definition: EventLoopWithExitStatus.h:33