From 211bed049d7073ea95789eeedc483541f8a85b2c Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Mon, 12 Sep 2016 13:09:15 +0200 Subject: removed USER_SETTINGS etc. (this also changes filename of the crt ans rsa files, but this shouldn't be a problem. (formerly the name of those files depended on the name and location of the ini-files) --- src/server/main.cpp | 23 +++-------------------- src/server/mainwindow/mainwindow.cpp | 32 ++++++-------------------------- src/server/net/certmanager.cpp | 6 ++++-- src/server/util/util.h | 8 +++----- 4 files changed, 16 insertions(+), 53 deletions(-) diff --git a/src/server/main.cpp b/src/server/main.cpp index 71657d8..2e5a32b 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -36,26 +36,9 @@ int main(int argc, char** argv) // Set the global path of the settings QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); - - // 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."; - } - } + SETTINGS(sys); + qDebug() << "System settings are in:" << sys.fileName(); + QFileInfo sysfi(sys.fileName()); // use system locale as language to translate gui diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 8fbba96..bed07f6 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -118,7 +118,7 @@ MainWindow::MainWindow(QWidget* parent) : connect(ui->action_DeleteClient, SIGNAL(triggered()), this, SLOT(onDeleteClient())); /* In exam-mode: disable most features */ - SYSTEM_SETTINGS(conf); + SETTINGS(conf); if (conf.contains("examMode")) { Global::setExam(conf.value("examMode").toBool()); } @@ -351,21 +351,6 @@ bool MainWindow::loadPosition(QSettings& settings, const QString& id, int& x, in return true; } -/***************************************************************************//** - * Save position of given connectionFrame. - * @param cf - */ -void MainWindow::savePosition(ConnectionFrame *cf) -{ - Client *client = cf->client(); - if (client == NULL) - return; - QPoint pos(cf->pos().x() / getTileWidthPx(), cf->pos().y() / getTileHeightPx()); - USER_SETTINGS(settings); - settings.beginGroup("client_position"); - settings.setValue(client->ip(), pos); - settings.endGroup(); -} /***************************************************************************//** * Tells the new client the current situation in class room. @@ -414,7 +399,7 @@ void MainWindow::tryToUseRoomTemplate() { qDebug() << "tryToUseRoomTemplate()"; QMap roomsList; - SYSTEM_SETTINGS(conf); + SETTINGS(conf); if (!conf.contains("rooms")) { qDebug() << "Invalid config file (no rooms are set)!"; return; } QStringList rooms = conf.value("rooms").toStringList(); @@ -731,8 +716,6 @@ void MainWindow::onPlaceFrame(bool activateTrash, ConnectionFrame* connectionFra const QPoint &preferredPixels = connectionFrame->frameGeometry().center(); placeFrameInFreeSlot(connectionFrame, preferredPixels); - /* save in local config to remember position */ - savePosition(connectionFrame); resizeEvent(NULL); } @@ -1296,13 +1279,10 @@ void MainWindow::onClientAuthenticated(Client* client) // Try to load last known position int x, y; bool ok; - USER_SETTINGS(usr); - ok = loadPosition(usr, client->ip(), x, y); - if (!ok) - { - SYSTEM_SETTINGS(sys); - ok = loadPosition(sys, client->ip(), x, y); - } + + SETTINGS(sys); + ok = loadPosition(sys, client->ip(), x, y); + if (x >= _tilesX || y >= _tilesY) ok = false; if (ok) diff --git a/src/server/net/certmanager.cpp b/src/server/net/certmanager.cpp index 5ba81e3..b85966a 100644 --- a/src/server/net/certmanager.cpp +++ b/src/server/net/certmanager.cpp @@ -18,6 +18,8 @@ #include "certmanager.h" #include "../util/util.h" #include +#include +#include #include #include #include @@ -38,8 +40,7 @@ bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &ce cert = _certs[name]; return true; } - USER_SETTINGS(settings); - QString certFile = settings.fileName().append(".").append(name); + QString certFile = QDir::homePath().append("/").append(CERTSTORAGE).append(name); QString keyFile = certFile; keyFile.append(".rsa"); certFile.append(".crt"); @@ -48,6 +49,7 @@ bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &ce { generateFiles(keyFile, certFile); if (!loadFiles(keyFile, certFile, key, cert)) + qDebug() << "error while creating cert and key files\n"; return false; } _certs.insert(name, cert); diff --git a/src/server/util/util.h b/src/server/util/util.h index 98a56b6..dfb70b4 100644 --- a/src/server/util/util.h +++ b/src/server/util/util.h @@ -4,13 +4,11 @@ // Helper for getting a settings object in various places, so if you ever change the organization, location, // file format or anything, you won't have to edit in 100 places. // Use like this: -// USER_SETTINGS(settings) // settings.value("somekey") -#define USER_SETTINGS(name) \ - QSettings name (QSettings::IniFormat, QSettings::UserScope, "openslx/pvs2", "pvs2"); \ - name.setIniCodec("UTF-8"); -#define SYSTEM_SETTINGS(name) \ +#define CERTSTORAGE ".config/openslx/pvs2/" + +#define SETTINGS(name) \ QSettings name (QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2"); \ name.setIniCodec("UTF-8"); -- cgit v1.2.3-55-g7522