MagicSmoke  $VERSION$
msinterface.h
Go to the documentation of this file.
1 //
2 // C++ Interface: msinterface
3 //
4 // Description:
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009-2011
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_MSINTERFACE_H
14 #define MAGICSMOKE_MSINTERFACE_H
15 
16 #include "MInterface"
17 
18 #define req (MSInterface::instance())
19 
20 #ifndef MSIFACE_EXPORT
21 #define MSIFACE_EXPORT Q_DECL_IMPORT
22 #endif
23 
24 
25 class MSslExceptions;
26 class MTemplateStore;
27 
30 {
31  Q_OBJECT
32  Q_PROPERTY(QString currentUser READ currentUser)
33  Q_PROPERTY(QString hostName READ hostName)
34  Q_PROPERTY(QString dataDir READ dataDir)
35  Q_PROPERTY(QString settingsGroup READ settingsGroup)
36  Q_PROPERTY(QString sessionId READ sessionId)
37  Q_PROPERTY(QString profileId READ profileId)
38  public:
40  MSInterface(QString);
42  ~MSInterface();
43 
45  static MSInterface* instance(){return qobject_cast<MSInterface*>(MInterface::instance());}
46 
48  Q_INVOKABLE QString currentUser()const{return m_uname;}
49 
51  Q_INVOKABLE QString hostName()const{return m_host;}
52 
54  Q_INVOKABLE bool hasRole(QString s)const{return userroles.contains(s);}
55 
57  Q_INVOKABLE bool hasRight(Right)const;
58 
60  Q_INVOKABLE bool hasFlag(QString f)const{return userflags.contains(f);}
61 
63  Q_INVOKABLE bool checkFlags(const QStringList&)const;
64 
66  Q_INVOKABLE bool checkFlags(const QString&s)const{return checkFlags(s.split(" "));}
67 
69  Q_INVOKABLE QString dataDir()const;
71  Q_INVOKABLE QString settingsGroup()const;
73  Q_INVOKABLE QString configSettingsGroup()const;
74 
76  bool checkServer();
77 
79  Q_INVOKABLE QString sessionId()const{return m_sessid;}
80 
82  virtual QMap<QString,QString> headers(QString)const;
83 
85  void initialize();
86 
88  Q_INVOKABLE MTemplateStore* templateStore(){return temp;}
89 
91  QString profileId()const{return profileid;}
92 
94  QString profileName()const;
95 
97  QList<Right> allRights()const{return userrights;}
98 
100  QStringList allRoles()const{return userroles;}
101 
103  QStringList allFlags()const{return userflags;}
104 
106  QUrl parentUrl()const;
107 
109  bool autoLogout()const{return autologout;}
110 
112  void setAutoLogout(bool a){autologout=a;}
113 
115  static QString appDataDir();
116 
118  static void setAppDataDir(QString);
119 
124  static QString resolveDir(const QString&dir);
125 
127  QString statusBarText()const{return m_statusbartext;}
128 
129  public slots:
131  bool login(QString username,QString passwd);
133  bool loginSession(QString username,QString sessionid);
135  void logout();
137  bool relogin();
139  void setSessionId(QString sid){m_sessid=sid;}
141  virtual void sslErrors(QNetworkReply *,const QList<QSslError>&);
143  void updateTemplates();
144 
145  signals:
147  void needRelogin();
148  private:
149  QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey,m_statusbartext;
150  mutable QList<Right>userrights;
151  mutable QStringList userroles,userflags;
152  QByteArray servertranslation;
153  MSslExceptions*sslexcept=nullptr;
154  bool didsslerror=false,autologout=false;
155  MTemplateStore *temp=nullptr;
156 };
157 
158 
159 #endif
Q_INVOKABLE QString sessionId() const
returns the current session ID
Definition: msinterface.h:79
Q_INVOKABLE bool checkFlags(const QString &s) const
checks the space separeted flags in the string and returns true if all of them match ...
Definition: msinterface.h:66
static MSInterface * instance()
returns the singleton instance of the interface
Definition: msinterface.h:45
bool autoLogout() const
returns whether this instance automatically logs out on closure
Definition: msinterface.h:109
void setAutoLogout(bool a)
sets whether this instance automatically logs out on closure
Definition: msinterface.h:112
Helper class: stores and compares SSL-Exceptions.
Definition: sslexception.h:31
Q_INVOKABLE QString currentUser() const
returns the name of the current user
Definition: msinterface.h:48
this class implements the storage end of the template subsystem, its only instance exists in the webr...
Definition: templates.h:149
QString statusBarText() const
returns the status bar text
Definition: msinterface.h:127
Q_INVOKABLE bool hasFlag(QString f) const
returns whether the user has a particular flag
Definition: msinterface.h:60
MagicSmoke interface class.
Definition: srcMInterface.h:212
static QString dataDir
Definition: msinterface.cpp:36
Q_INVOKABLE bool hasRole(QString s) const
returns whether the user is part of this role
Definition: msinterface.h:54
Q_INVOKABLE QString hostName() const
returns the name used for the host in this session
Definition: msinterface.h:51
QString profileId() const
returns the profile ID of this session
Definition: msinterface.h:91
static MInterface * instance(QString name="MagicSmoke")
convenience override: returns a pointer to an instance with the given name if it is of the correct ty...
Definition: srcMInterface.h:218
QStringList allRoles() const
return all roles of the current user
Definition: msinterface.h:100
QList< Right > allRights() const
return all rights of the current user
Definition: msinterface.h:97
the MagicSmoke specific interface class - enhances the basic interface by some functionality needed i...
Definition: msinterface.h:29
QStringList allFlags() const
return all flags of the current user
Definition: msinterface.h:103
#define MSIFACE_EXPORT
Definition: msinterface.h:21
Q_INVOKABLE MTemplateStore * templateStore()
returns a pointer to the template storage engine
Definition: msinterface.h:88
void setSessionId(QString sid)
sets the session id to be transmitted
Definition: msinterface.h:139