From 5e6c2a27334930a55c4586751d9b2f680e808c4b Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Thu, 28 Apr 2011 19:51:05 +0200 Subject: theme support, move directboot option from no parameter to --file / -f --- src/command_line_options.cpp | 48 ++++++++++++++++++++++---------------------- src/dialog.cpp | 38 +++++++++++++++++++++++++++++++++++ src/dialog.h | 1 + src/globals.cpp | 2 +- src/globals.h | 2 ++ src/main.cpp | 14 ++++++++++++- 6 files changed, 79 insertions(+), 26 deletions(-) diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 1bc6c4a..712f8a5 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -1,33 +1,37 @@ #include "command_line_options.h" #include +#include CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { // parse command line arguments - for (;;) { - static const struct option longOptions[] = { - {"config", required_argument, NULL, 'c'}, - {"default", required_argument, NULL, 'd'}, - {"pool", required_argument, NULL, 'P'}, - {"path", required_argument, NULL, 'p'}, - {"xpath", required_argument, NULL, 'x'}, - {"size", required_argument, NULL, 's'}, - {"pvs", no_argument, NULL, 'b'}, - {"debug", no_argument, NULL, 'D'}, - {"version", no_argument, NULL, 'v'}, - {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0} - }; + static const struct option longOptions[] = { + {"config", required_argument, NULL, 'c'}, + {"default", required_argument, NULL, 'd'}, + {"pool", required_argument, NULL, 'P'}, + {"path", required_argument, NULL, 'p'}, + {"xpath", required_argument, NULL, 'x'}, + {"size", required_argument, NULL, 's'}, + {"theme", required_argument, NULL, 't'}, + {"pvs", no_argument, NULL, 'b'}, + {"debug", no_argument, NULL, 'D'}, + {"version", no_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0} + }; - int opt = getopt_long(argc, argv, "c:d:P:p:x:s:w:vhbD", longOptions, NULL); - if (opt == -1) break; + int c; - switch (opt) { + while ((c = getopt_long(argc, argv, "c:d:f:P:p:x:s:t:w:vhbD", longOptions, NULL)) != -1) { + switch (c) { case 'c': options.insert("config", optarg); break; case 'd': options.insert("default", optarg); break; + case 'f': + options.insert("file", optarg); + break; case 'D': options.insert("debugMode", "debugMode"); break; @@ -43,6 +47,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { case 's': options.insert("size", optarg); break; + case 't': + options.insert("theme", optarg); + break; case 'b': options.insert("pvs", "pvs"); break; @@ -56,12 +63,5 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { default: options.insert("error", "error"); } - - if (optind == argc - 1) { - options.insert("file", argv[optind]); - } else if (optind < argc - 1) { - options.insert("error", "error"); - } } } - diff --git a/src/dialog.cpp b/src/dialog.cpp index 98a60e8..342da87 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -2,10 +2,13 @@ #include #include +#include +#include #include "ui_dialog.h" #include "save_restore_session.h" #include "sessiontreeitem.h" +#include "globals.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { @@ -165,3 +168,38 @@ void Dialog::showSettingsPVS() { readPVSSettings(); ui->PVSOptionsGroupBox->show(); } + +void Dialog::setTheme() { + QString label_l_style, label_r_style; + QString backgroundColor, imageLeft, imageRight; + QString themePathBase, themePathIni, themePathImgLeft, themePathImgRight; + + if (theme.isEmpty()) return; + + themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); + themePathIni = QString("%1%2.ini").arg(themePathBase).arg(theme); + + if (!QFile::exists(themePathIni)) return; + + + QSettings themeSettings(themePathIni, QSettings::IniFormat); + backgroundColor = themeSettings.value("background-color").toString(); + imageLeft = themeSettings.value("image-left").toString(); + imageRight = themeSettings.value("image-right").toString(); + + themePathImgLeft = QString("%1%2").arg(themePathBase).arg(imageLeft); + themePathImgRight = QString("%1%2").arg(themePathBase).arg(imageRight); + + QRegExp re; + + ui->label_l->setPixmap(QPixmap(themePathImgLeft)); + ui->label_r->setPixmap(QPixmap(themePathImgRight)); + label_l_style = ui->label_l->styleSheet(); + label_r_style = ui->label_r->styleSheet(); + backgroundColor.prepend("\\1").append("\\2"); + label_l_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); + label_r_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); + //qDebug() << label_r_style << label_l_style; + ui->label_l->setStyleSheet(label_l_style); + ui->label_r->setStyleSheet(label_r_style); +} diff --git a/src/dialog.h b/src/dialog.h index 86896c7..805ed08 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -21,6 +21,7 @@ class Dialog : public QDialog { void selectSession(const QString& name); void selectPreviousSession(); void showSettingsPVS(); + void setTheme(); protected: void changeEvent(QEvent *e); diff --git a/src/globals.cpp b/src/globals.cpp index cc931f9..b580bbe 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -21,4 +21,4 @@ const QString previousSessionFile(userPath + "/vmchooser_prev_session"); bool debugMode = false; QString pool; - +QString theme; diff --git a/src/globals.h b/src/globals.h index 7849d2d..0a40059 100644 --- a/src/globals.h +++ b/src/globals.h @@ -7,6 +7,7 @@ #define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin" #define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser" #define VMCHOOSER_VMPATH "/var/lib/virt" +#define VMCHOOSER_THEME_BASE "/usr/local/share/vmchooser/themes" #define VMCHOOSER_X_SESSIONS_PATH "/usr/share/xsessions" @@ -33,5 +34,6 @@ extern const QString userConfFile; extern const QString previousSessionFile; extern QString pool; +extern QString theme; #endif diff --git a/src/main.cpp b/src/main.cpp index 7b90ee5..6af6cbc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -33,12 +34,14 @@ int main(int argc, char *argv[]) { std::string usage(a.translate( "Console", - "Usage: vmchooser [ OPTIONS | FILE ]\n\n" + "Usage: vmchooser [ OPTIONS ]\n\n" " -d, --default name of default session\n" + " -f, --file direct boot FILE" " -P, --pool name of the environment\n" " -p, --path path to vmware .xml files\n" " -x, --xpath path of X Session .desktop files\n" " -s, --size window size x\n" + " -t, --theme theme\n" " -b, --pvs show pvs options\n" " -D, --debug print debug information\n" " -v, --version print version and exit\n" @@ -162,6 +165,12 @@ int main(int argc, char *argv[]) { pool = settings.value("vmchooser_env").toString(); } + if (cmdOptions.contains("theme")) { + theme = cmdOptions.value("theme"); + } else if (settings.contains("theme")) { + theme = settings.value("theme").toString(); + } + if (cmdOptions.contains("debugMode")) { debugMode = true; } @@ -171,6 +180,9 @@ int main(int argc, char *argv[]) { QList vsessions(VSession::readXmlDir(vSessionPath)); Dialog w; + + w.setTheme(); + w.setWindowFlags(Qt::FramelessWindowHint); if (cmdOptions.contains("pvs")) w.showSettingsPVS(); -- cgit v1.2.3-55-g7522