Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
clientapp.cpp
Go to the documentation of this file.
1 #include "clientapp.h"
2 
3 #include "../connectwindow/connectwindow.h"
4 #include "../toolbar/toolbar.h"
5 #include "../net/serverconnection.h"
6 
7 #include <QNetworkInterface>
8 #include <QTranslator>
9 #include <QLibraryInfo>
10 
11 ClientApp::ClientApp(int& argc, char** argv)
12  : QApplication(argc, argv)
13  , _connectionMode(ConnectionMode::None)
14  , _examMode(false)
15  , _connection(nullptr)
16 {
17  /* some values */
18  setOrganizationName("openslx");
19  setOrganizationDomain("openslx.org");
20  setApplicationName("pvsclient");
21  setQuitOnLastWindowClosed(false);
22 
23  /* configuration */
24  QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/");
25 
26  /* parse parameters and keep the unparsed ones */
28 
29  /* set translator */
30  // System strings
31  auto *qtTranslator = new QTranslator(this);
32  if (!qtTranslator->load(QLocale::system(), "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
33  qDebug() << "Could not load system string translations" << QLocale::system() << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
34  } else {
35  installTranslator(qtTranslator);
36  }
37  // App specific
38  auto *translator = new QTranslator(this);
39  if (!translator->load(QLocale::system(), ":/", "l_")) {
40  qDebug() << "Could not load app translations" << QLocale::system();
41  } else {
42  installTranslator(translator);
43  }
44 
45  _connectWindow = new ConnectWindow(nullptr);
47  if (_connectionMode == ConnectionMode::Auto) {
48  _toolbar = new Toolbar(true); // auto connect client without session ID.
49  } else if (_connectionMode == ConnectionMode::Session) {
50  _toolbar = new Toolbar(_sessionName.toUtf8()); // connect client with given session ID.
51  } else {
52  _toolbar = new Toolbar(); // create normal client.
53  }
54  _toolbar->setVisible(!_examMode);
55 
56 }
57 
58 /* parse arguments and return a list with the unused arguments */
60 {
61  QStringList rest;
62  for (const QString &a : QApplication::arguments()) {
63  if (a == "--exam-mode") {
64  _examMode = true;
65  } else if (a == "--auto") {
66  _connectionMode = ConnectionMode::Auto;
67  } else if (a.startsWith("--session=")) {
68  _connectionMode = ConnectionMode::Session;
69  _sessionName = a.mid(10);
70  } else if (a.startsWith("--config=")) {
71  _iniPath = a.mid(9);
72  } else {
73  rest << a;
74  }
75  }
76  return rest;
77 }
78 
79 QStringList ClientApp::arguments()
80 {
81  return _arguments;
82 }
83 
84 QSharedPointer<QSettings> ClientApp::getSettings()
85 {
86  QSharedPointer<QSettings> set;
87  if (_iniPath.isEmpty()) {
88  /* default location (system scope) */
89  set = QSharedPointer<QSettings>(new QSettings(QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2"));
90  } else {
91  /* use _iniPath to find ini file */
92  set = QSharedPointer<QSettings>(new QSettings(_iniPath, QSettings::IniFormat));
93  }
94  set->setIniCodec("UTF-8");
95  return set;
96 }
97 
99 {
102 }
103 
105 {
106  if (connection != nullptr)
107  connection->blockSignals(true);
108  if (_connection == connection) {
109  _connection = nullptr;
110  }
111 }
112 
Class for handling the client connection.
Definition: connectwindow.h:41
ConnectionMode
Definition: clientapp.h:28
QStringList _arguments
Definition: clientapp.h:37
QStringList parseParameters()
Definition: clientapp.cpp:59
ConnectionMode _connectionMode
Definition: clientapp.h:31
virtual QStringList arguments()
Definition: clientapp.cpp:79
ServerConnection * connection() const
Definition: clientapp.h:52
void disconnected(ServerConnection *connection)
bool _examMode
Definition: clientapp.h:32
ServerConnection * _connection
Definition: clientapp.h:36
ClientApp(int &argc, char **argv)
Definition: clientapp.cpp:11
QSharedPointer< QSettings > getSettings()
Definition: clientapp.cpp:84
QString _sessionName
Definition: clientapp.h:33
Toolbar * _toolbar
Definition: clientapp.h:34
void connected(ServerConnection *connection)
void disconnected(ServerConnection *connection)
Definition: clientapp.cpp:104
ConnectWindow * _connectWindow
Definition: clientapp.h:35
void connected(ServerConnection *connection)
Definition: clientapp.cpp:98
QString _iniPath
Definition: clientapp.h:38