diff options
author | Christian Klinger | 2016-09-26 14:33:01 +0200 |
---|---|---|
committer | Christian Klinger | 2016-09-26 14:58:16 +0200 |
commit | aacb7592d27583b27e3ad5d2ff3fc7561658e358 (patch) | |
tree | c9646fcecb6a7626a461ee618a34e498814c285e /src/client/clientapp | |
parent | added the --config=FILE parameter and got rid of the SETTINGS macro. (diff) | |
download | pvs2-aacb7592d27583b27e3ad5d2ff3fc7561658e358.tar.gz pvs2-aacb7592d27583b27e3ad5d2ff3fc7561658e358.tar.xz pvs2-aacb7592d27583b27e3ad5d2ff3fc7561658e358.zip |
clients in exam-mode no longer send a screenshot. Also some refactoring.
Diffstat (limited to 'src/client/clientapp')
-rw-r--r-- | src/client/clientapp/clientapp.cpp | 68 | ||||
-rw-r--r-- | src/client/clientapp/clientapp.h | 38 |
2 files changed, 106 insertions, 0 deletions
diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp new file mode 100644 index 0000000..3d2dba1 --- /dev/null +++ b/src/client/clientapp/clientapp.cpp @@ -0,0 +1,68 @@ +#include "clientapp.h" + +ClientApp::ClientApp(int& argc, char** argv) : QApplication(argc, argv), _connectionMode(ConnectionMode::None) { + /* some values */ + setOrganizationName("openslx"); + setOrganizationDomain("openslx.org"); + setApplicationName("pvsclient"); + + parseParameters(); + initConfiguration(); + + + /* TODO: Move the connection handling to ClientApp */ + if (_connectionMode == ConnectionMode::Auto) { + _toolbar = new Toolbar(true); // auto connect client without session ID. + } else if (_connectionMode == ConnectionMode::Session) { + _toolbar = new Toolbar(_sessionName.toUtf8()); // connect client with given session ID. + } else { + _toolbar = new Toolbar(); // create normal client. + } + _toolbar->setVisible(!_examMode); + + /* set translator */ + /* use system locale as language to translate gui */ + QTranslator translator; + translator.load(":pvsclient"); + installTranslator(&translator); + +}; + +/* parse arguments */ +void ClientApp::parseParameters() { + for (QString a : arguments()) { + if (a == "--exam-mode") { + _examMode = true; + } else if (a == "--auto") { + _connectionMode = ConnectionMode::Auto; + } else if (a.startsWith("--session=")) { + _connectionMode = ConnectionMode::Session; + _sessionName = a.replace("--session=", ""); + } + } +} +void ClientApp::initConfiguration() { + /* configuration */ + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); + do { + // Make sure settings directory exists + USER_SETTINGS(settings); + QFileInfo fi(settings.fileName()); + QDir path(fi.path()); + qDebug() << "User settings are in:" << settings.fileName(); + if (!path.exists()) + path.mkpath(path.absolutePath()); + // Now check if settings file exists. If not, copy system default (if available) + if (!fi.exists()) + { + SYSTEM_SETTINGS(sys); + qDebug() << "System settings are in:" << sys.fileName(); + QFileInfo sysfi(sys.fileName()); + if (sysfi.exists()) + { + if (!QFile::copy(sys.fileName(), settings.fileName())) + qDebug() << "Copying default settings from " << sys.fileName() << " to " << settings.fileName() << " failed."; + } + } + } while (false); +} diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h new file mode 100644 index 0000000..5571cb0 --- /dev/null +++ b/src/client/clientapp/clientapp.h @@ -0,0 +1,38 @@ +#include<QApplication> +#include "../toolbar/toolbar.h" +#include "../util/util.h" + + +/* define a macro `clientApp` that can be used anywhere in the program and returns a reference to the current ClientApp instance */ +#if defined(clientApp) +#undef clientApp +#endif +#define clientApp (static_cast<ClientApp*>(QCoreApplication::instance())) + +/* this class is supposed to (after complete refactoring) to encapsulate all + * state of the application. At the moment, the state is distributed within + * several widgets. With this class information access will also be easier as + * it is possible to access the current ClientApp instance from anywhere with + * the clientApp macro (like qApp) macro */ +class ClientApp : public QApplication { + + Q_OBJECT + + public: + enum ConnectionMode { None, Auto, Session }; + + private: + bool _examMode; + ConnectionMode _connectionMode; /* way of automatically connection to a session on startup*/ + QString _sessionName; /* only set when _connectionMode == Session */ + Toolbar* _toolbar; + + void initConfiguration(); + void parseParameters(); + + public: + + ClientApp(int& argc, char** argv); + + bool isExamMode() const { return _examMode; }; +}; |