Cutelyst  1.5.0
application.h
1 /*
2  * Copyright (C) 2013-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CUTELYST_APPLICATION_H
21 #define CUTELYST_APPLICATION_H
22 
23 #include <QtCore/qobject.h>
24 #include <QtCore/qvariant.h>
25 #include <QtCore/qlocale.h>
26 
27 #include <Cutelyst/cutelyst_global.h>
28 
29 class QTranslator;
30 
31 namespace Cutelyst {
32 
33 #define CUTELYST_APPLICATION(x) \
34  Q_PLUGIN_METADATA(x) \
35  Q_INTERFACES(Cutelyst::Application)
36 
37 class Context;
38 class Controller;
39 class Component;
40 class View;
41 class Dispatcher;
42 class DispatchType;
43 class Request;
44 class Response;
45 class Engine;
46 class Plugin;
47 class Headers;
48 class ApplicationPrivate;
49 
55 class CUTELYST_LIBRARY Application : public QObject
56 {
57  Q_OBJECT
58  Q_DECLARE_PRIVATE(Application)
59 public:
74  explicit Application(QObject *parent = nullptr);
75  virtual ~Application();
76 
82  QVector<Controller *> controllers() const;
83 
87  View *view(const QString &name = QString()) const;
88 
92  QVariant config(const QString &key, const QVariant &defaultValue = QVariant()) const;
93 
97  Dispatcher *dispatcher() const;
98 
104  QVector<DispatchType *> dispatchers() const;
105 
110  QVariantMap config() const;
111 
115  QString pathTo(const QStringList &path) const;
116 
120  bool inited() const;
121 
125  Engine *engine() const;
126 
131  Component *createComponentPlugin(const QString &name, QObject *parent = nullptr);
132 
136  static const char *cutelystVersion();
137 
164  void addTranslator(const QLocale &locale, QTranslator *translator);
165 
175  void addTranslator(const QString &locale, QTranslator *translator);
176 
184  void addTranslators(const QLocale &locale, const QVector<QTranslator *> &translators);
185 
197  QString translate(const QLocale &locale, const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1) const;
198 
199 protected:
213  virtual bool init();
214 
232  virtual bool postFork();
233 
239  Headers &defaultHeaders();
240 
248  bool registerPlugin(Plugin *plugin);
249 
260  bool registerController(Controller *controller);
261 
269  bool registerView(View *view);
270 
275  bool registerDispatcher(DispatchType *dispatcher);
276 
277 Q_SIGNALS:
287  void beforePrepareAction(Context *c, bool *skipMethod);
288 
293  void beforeDispatch(Context *c);
294 
299  void afterDispatch(Context *c);
300 
305  void preForked(Application *app);
306 
310  void postForked(Application *app);
311 
312 protected:
319  void setConfig(const QString &key, const QVariant &value);
320 
321  friend class Engine;
322  bool setup(Engine *engine);
323  void handleRequest(Request *req);
324  bool enginePostFork();
325 
326  ApplicationPrivate *d_ptr;
327 };
328 
329 }
330 
331 #define CutelystApplicationInterface_iid "org.cutelyst.CutelystApplicationInterface"
332 
333 Q_DECLARE_INTERFACE(Cutelyst::Application, CutelystApplicationInterface_iid)
334 
335 #endif // CUTELYST_APPLICATION_H
The Cutelyst Component base class.
Definition: component.h:40
The Cutelyst Context.
Definition: context.h:52
Cutelyst Controller base class
Definition: controller.h:104
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:55
The Cutelyst Dispatcher.
Definition: dispatcher.h:41