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