diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 40e06dd51..1d332721f 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -44,12 +44,12 @@ QSettings::Status Settings::checkSettings() { return s_instance->status(); } -Settings &Settings::getInstance() { +Settings *Settings::getInstance() { if (s_instance.isNull()) { setupSettings(); } - return *s_instance; + return s_instance; } QVariant Settings::value(const QString §ion, diff --git a/src/core/settings.h b/src/core/settings.h index 368ca013b..6771d304f 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -10,7 +10,7 @@ class Settings : public QSettings { public: // Singleton getter. - static Settings &getInstance(); + static Settings *getInstance(); // Constructor and destructor. Settings(const QString & file_name, Format format, QObject * parent = 0); diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 0244e1382..fa022134c 100644 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -1,23 +1,41 @@ // for testing #include +#include #include "gui/formmain.h" #include "gui/formsettings.h" #include "gui/themefactory.h" +#include "gui/systemtrayicon.h" #include "core/settings.h" +#include "core/defs.h" #include "qtsingleapplication/qtsingleapplication.h" +FormMain *FormMain::m_this; + FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain) { m_ui->setupUi(this); + // Initialize singleton. + m_this = this; + + // Establish connections. createConnections(); + + // testing purposes + SystemTrayIcon *icon = SystemTrayIcon::getInstance(); + icon->setIcon(QIcon(APP_ICON_PATH)); + icon->show(); } FormMain::~FormMain() { delete m_ui; } +FormMain *FormMain::getInstance() { + return m_this; +} + void FormMain::processExecutionMessage(const QString &message) { // TODO: Implement proper reaction when application is launched more than once. qDebug("Received '%s' execution message from another application instance.", diff --git a/src/gui/formmain.h b/src/gui/formmain.h index 1da197ca3..fcc9afe89 100644 --- a/src/gui/formmain.h +++ b/src/gui/formmain.h @@ -13,6 +13,8 @@ class FormMain : public QMainWindow { explicit FormMain(QWidget *parent = 0); ~FormMain(); + static FormMain *getInstance(); + protected: void createConnections(); @@ -33,6 +35,8 @@ class FormMain : public QMainWindow { private: Ui::FormMain *m_ui; + + static FormMain *m_this; }; #endif // FORMMAIN_H diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 6351af10e..77d67aac9 100644 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -1,6 +1,8 @@ #include "gui/formsettings.h" #include "gui/themefactory.h" +#include "gui/systemtrayicon.h" #include "core/settings.h" +#include "core/defs.h" FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) { @@ -27,10 +29,27 @@ void FormSettings::saveSettings() { //saveLanguages(); // Make sure that settings is synced. - Settings::getInstance().checkSettings(); + Settings::getInstance()->checkSettings(); } void FormSettings::loadInterface() { + // Load settings of tray icon. + if (SystemTrayIcon::isSystemTrayAvailable()) { + // načti + m_ui->m_radioTrayOff->setChecked(!Settings::getInstance()->value(APP_CFG_GUI, + "use_tray_icon", + true).toBool()); + m_ui->m_cmbTrayClose->setCurrentIndex(Settings::getInstance()->value(APP_CFG_GUI, + "close_win_action", + 0).toInt()); + } + else { + m_ui->m_radioTrayOff->setText(tr("disable (Tray icon is not available.)")); + m_ui->m_radioTrayOff->setChecked(true); + m_ui->m_grpTray->setDisabled(true); + } + + // Load settings of icon theme. QString current_theme = ThemeFactory::getCurrentIconTheme(); #if defined(Q_OS_LINUX) QString system_theme = ThemeFactory::getSystemIconTheme(); @@ -64,6 +83,17 @@ void FormSettings::loadInterface() { } void FormSettings::saveInterface() { + // Save tray icon. + if (SystemTrayIcon::isSystemTrayAvailable()) { + Settings::getInstance()->setValue(APP_CFG_GUI, "use_tray_icon", + m_ui->m_radioTrayOn->isChecked()); + Settings::getInstance()->setValue(APP_CFG_GUI, "close_win_action", + m_ui->m_cmbTrayClose->currentIndex()); + // TODO: Switch tray icon here (destroy it/create it) and + // if icon is should be destroyed and no main window is visible, + // then show main window and then destroy tray icon. + } + // Save selected icon theme. ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString()); } diff --git a/src/gui/formsettings.ui b/src/gui/formsettings.ui index 7e2f0c0f0..0dc6c5e09 100644 --- a/src/gui/formsettings.ui +++ b/src/gui/formsettings.ui @@ -6,8 +6,8 @@ 0 0 - 586 - 355 + 680 + 414 @@ -23,7 +23,7 @@ - 0 + -1 @@ -35,6 +35,11 @@ User interface + + + Language + + @@ -45,23 +50,30 @@ + + 0 + + + 0 + + + 0 + + + 0 + - - - QFrame::NoFrame + + + QTabWidget::North - - true + + 0 - - - - 0 - 0 - 394 - 290 - - + + + Icons && skins + @@ -76,12 +88,82 @@ + + + + Skin + + + + + + + + + Notifications + + + + + + Tray icon + + + + + + disable + + + + + + + enable + + + true + + + + + + + When main window is closed, then + + + + + + + + minimize it. + + + + + quit the application. + + + + + + + + + + + + Fonts + + + @@ -146,5 +228,69 @@ + + m_radioTrayOff + toggled(bool) + m_lblTrayClose + setDisabled(bool) + + + 370 + 82 + + + 292 + 135 + + + + + m_radioTrayOff + toggled(bool) + m_cmbTrayClose + setDisabled(bool) + + + 370 + 82 + + + 478 + 135 + + + + + m_radioTrayOn + toggled(bool) + m_lblTrayClose + setVisible(bool) + + + 370 + 108 + + + 292 + 135 + + + + + m_radioTrayOn + toggled(bool) + m_cmbTrayClose + setVisible(bool) + + + 370 + 108 + + + 478 + 135 + + + diff --git a/src/gui/systemtrayicon.cpp b/src/gui/systemtrayicon.cpp index 409929aa2..648322357 100644 --- a/src/gui/systemtrayicon.cpp +++ b/src/gui/systemtrayicon.cpp @@ -1,5 +1,34 @@ #include "gui/systemtrayicon.h" +#include "gui/formmain.h" +#include "core/settings.h" +#include "core/defs.h" +QPointer SystemTrayIcon::m_trayIcon; + SystemTrayIcon::SystemTrayIcon(QObject *parent) : QSystemTrayIcon(parent) { + qDebug("Creating SystemTrayIcon instance."); } + +SystemTrayIcon::~SystemTrayIcon() { + qDebug("Destroying SystemTrayIcon instance."); +} + +bool SystemTrayIcon::isSystemTrayAvailable() { + return QSystemTrayIcon::isSystemTrayAvailable() && QSystemTrayIcon::supportsMessages(); +} + +bool SystemTrayIcon::isSystemTrayActivated() { + return SystemTrayIcon::isSystemTrayAvailable() && Settings::getInstance()->value(APP_CFG_GUI, + "use_tray_icon", + true).toBool(); +} + +SystemTrayIcon *SystemTrayIcon::getInstance() { + if (m_trayIcon.isNull()) { + m_trayIcon = new SystemTrayIcon(FormMain::getInstance()); + } + + return m_trayIcon; +} + diff --git a/src/gui/systemtrayicon.h b/src/gui/systemtrayicon.h index d070c308d..d0096e398 100644 --- a/src/gui/systemtrayicon.h +++ b/src/gui/systemtrayicon.h @@ -2,17 +2,34 @@ #define SYSTEMTRAYICON_H #include +#include class SystemTrayIcon : public QSystemTrayIcon { Q_OBJECT public: explicit SystemTrayIcon(QObject *parent = 0); + ~SystemTrayIcon(); + + // Returns true if tray icon CAN be constructed on this machine. + static bool isSystemTrayAvailable(); + + // Returns true if tray icon CAN be costructed and IS enabled in + // application settings. + static bool isSystemTrayActivated(); + + // Creates new tray icon if necessary and returns it. + // WARNING: Use this in cooperation with SystemTrayIcon::isSystemTrayActivated(). + static SystemTrayIcon *getInstance(); + // TODO: Implement method for manual clearing of the tray icon. Creating of tray icon + // handled by getInstance(). signals: public slots: - + + private: + static QPointer m_trayIcon; }; #endif // SYSTEMTRAYICON_H diff --git a/src/gui/themefactory.cpp b/src/gui/themefactory.cpp index 62b6c04c9..f9eb95b75 100644 --- a/src/gui/themefactory.cpp +++ b/src/gui/themefactory.cpp @@ -62,16 +62,16 @@ QString ThemeFactory::getSystemIconTheme() { } QString ThemeFactory::getCurrentIconTheme() { - QString current_theme_name = Settings::getInstance().value(APP_CFG_GUI, - "icon_theme", - getSystemIconTheme()).toString(); + QString current_theme_name = Settings::getInstance()->value(APP_CFG_GUI, + "icon_theme", + getSystemIconTheme()).toString(); return current_theme_name; } void ThemeFactory::setCurrentIconTheme(const QString &theme_name) { - Settings::getInstance().setValue(APP_CFG_GUI, - "icon_theme", - theme_name); + Settings::getInstance()->setValue(APP_CFG_GUI, + "icon_theme", + theme_name); loadCurrentIconTheme(); } diff --git a/src/main.cpp b/src/main.cpp index 847e12e0c..716584723 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,13 +65,12 @@ int main(int argc, char *argv[]) { QtSingleApplication::setOrganizationName(APP_AUTHORS); QtSingleApplication::setOrganizationDomain(APP_URL); QtSingleApplication::setWindowIcon(QIcon(APP_INFO_PATH)); - qDebug("%s", qPrintable(APP_ICON_PATH)); // Instantiate main application window. FormMain window; - if (Settings::getInstance().value(APP_CFG_GEN, "first_start", true).toBool()) { - Settings::getInstance().setValue(APP_CFG_GEN, "first_start", false); + if (Settings::getInstance()->value(APP_CFG_GEN, "first_start", true).toBool()) { + Settings::getInstance()->setValue(APP_CFG_GEN, "first_start", false); FormWelcome(&window).exec(); }