Update many things, testing of tray icon behaviour.

This commit is contained in:
Martin Rotter 2013-06-17 20:17:13 +02:00
parent d5110d86ee
commit cc18e95701
10 changed files with 274 additions and 31 deletions

View File

@ -44,12 +44,12 @@ QSettings::Status Settings::checkSettings() {
return s_instance->status(); return s_instance->status();
} }
Settings &Settings::getInstance() { Settings *Settings::getInstance() {
if (s_instance.isNull()) { if (s_instance.isNull()) {
setupSettings(); setupSettings();
} }
return *s_instance; return s_instance;
} }
QVariant Settings::value(const QString &section, QVariant Settings::value(const QString &section,

View File

@ -10,7 +10,7 @@ class Settings : public QSettings {
public: public:
// Singleton getter. // Singleton getter.
static Settings &getInstance(); static Settings *getInstance();
// Constructor and destructor. // Constructor and destructor.
Settings(const QString & file_name, Format format, QObject * parent = 0); Settings(const QString & file_name, Format format, QObject * parent = 0);

View File

@ -1,23 +1,41 @@
// for testing // for testing
#include <QMessageBox> #include <QMessageBox>
#include <QProcess>
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/formsettings.h" #include "gui/formsettings.h"
#include "gui/themefactory.h" #include "gui/themefactory.h"
#include "gui/systemtrayicon.h"
#include "core/settings.h" #include "core/settings.h"
#include "core/defs.h"
#include "qtsingleapplication/qtsingleapplication.h" #include "qtsingleapplication/qtsingleapplication.h"
FormMain *FormMain::m_this;
FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain) { FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain) {
m_ui->setupUi(this); m_ui->setupUi(this);
// Initialize singleton.
m_this = this;
// Establish connections.
createConnections(); createConnections();
// testing purposes
SystemTrayIcon *icon = SystemTrayIcon::getInstance();
icon->setIcon(QIcon(APP_ICON_PATH));
icon->show();
} }
FormMain::~FormMain() { FormMain::~FormMain() {
delete m_ui; delete m_ui;
} }
FormMain *FormMain::getInstance() {
return m_this;
}
void FormMain::processExecutionMessage(const QString &message) { void FormMain::processExecutionMessage(const QString &message) {
// TODO: Implement proper reaction when application is launched more than once. // TODO: Implement proper reaction when application is launched more than once.
qDebug("Received '%s' execution message from another application instance.", qDebug("Received '%s' execution message from another application instance.",

View File

@ -13,6 +13,8 @@ class FormMain : public QMainWindow {
explicit FormMain(QWidget *parent = 0); explicit FormMain(QWidget *parent = 0);
~FormMain(); ~FormMain();
static FormMain *getInstance();
protected: protected:
void createConnections(); void createConnections();
@ -33,6 +35,8 @@ class FormMain : public QMainWindow {
private: private:
Ui::FormMain *m_ui; Ui::FormMain *m_ui;
static FormMain *m_this;
}; };
#endif // FORMMAIN_H #endif // FORMMAIN_H

View File

@ -1,6 +1,8 @@
#include "gui/formsettings.h" #include "gui/formsettings.h"
#include "gui/themefactory.h" #include "gui/themefactory.h"
#include "gui/systemtrayicon.h"
#include "core/settings.h" #include "core/settings.h"
#include "core/defs.h"
FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) { FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormSettings) {
@ -27,10 +29,27 @@ void FormSettings::saveSettings() {
//saveLanguages(); //saveLanguages();
// Make sure that settings is synced. // Make sure that settings is synced.
Settings::getInstance().checkSettings(); Settings::getInstance()->checkSettings();
} }
void FormSettings::loadInterface() { 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(); QString current_theme = ThemeFactory::getCurrentIconTheme();
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
QString system_theme = ThemeFactory::getSystemIconTheme(); QString system_theme = ThemeFactory::getSystemIconTheme();
@ -64,6 +83,17 @@ void FormSettings::loadInterface() {
} }
void FormSettings::saveInterface() { 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. // Save selected icon theme.
ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString()); ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString());
} }

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>586</width> <width>680</width>
<height>355</height> <height>414</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -23,7 +23,7 @@
</size> </size>
</property> </property>
<property name="currentRow"> <property name="currentRow">
<number>0</number> <number>-1</number>
</property> </property>
<item> <item>
<property name="text"> <property name="text">
@ -35,6 +35,11 @@
<string>User interface</string> <string>User interface</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>Language</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
@ -45,23 +50,30 @@
<widget class="QWidget" name="m_pageGeneral"/> <widget class="QWidget" name="m_pageGeneral"/>
<widget class="QWidget" name="m_pageUi"> <widget class="QWidget" name="m_pageUi">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QScrollArea" name="m_scrollUi"> <widget class="QTabWidget" name="m_tabUi">
<property name="frameShape"> <property name="tabPosition">
<enum>QFrame::NoFrame</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="widgetResizable"> <property name="currentIndex">
<bool>true</bool> <number>0</number>
</property> </property>
<widget class="QWidget" name="m_scrollUiContents"> <widget class="QWidget" name="m_tabIconSkin">
<property name="geometry"> <attribute name="title">
<rect> <string>Icons &amp;&amp; skins</string>
<x>0</x> </attribute>
<y>0</y>
<width>394</width>
<height>290</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="m_lblIconTheme"> <widget class="QLabel" name="m_lblIconTheme">
@ -76,12 +88,82 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="m_cmbIconTheme"/> <widget class="QComboBox" name="m_cmbIconTheme"/>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="m_lblSkin">
<property name="text">
<string>Skin</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_cmbSkin"/>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Notifications</string>
</attribute>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="m_grpTray">
<property name="title">
<string>Tray icon</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="m_radioTrayOff">
<property name="text">
<string>disable</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="m_radioTrayOn">
<property name="text">
<string>enable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_lblTrayClose">
<property name="text">
<string>When main window is closed, then</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_cmbTrayClose">
<item>
<property name="text">
<string>minimize it.</string>
</property>
</item>
<item>
<property name="text">
<string>quit the application.</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabFonts">
<attribute name="title">
<string>Fonts</string>
</attribute>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="m_pageLanguage"/>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
@ -146,5 +228,69 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>m_radioTrayOff</sender>
<signal>toggled(bool)</signal>
<receiver>m_lblTrayClose</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>370</x>
<y>82</y>
</hint>
<hint type="destinationlabel">
<x>292</x>
<y>135</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOff</sender>
<signal>toggled(bool)</signal>
<receiver>m_cmbTrayClose</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>370</x>
<y>82</y>
</hint>
<hint type="destinationlabel">
<x>478</x>
<y>135</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_lblTrayClose</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>370</x>
<y>108</y>
</hint>
<hint type="destinationlabel">
<x>292</x>
<y>135</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_cmbTrayClose</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>370</x>
<y>108</y>
</hint>
<hint type="destinationlabel">
<x>478</x>
<y>135</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View File

@ -1,5 +1,34 @@
#include "gui/systemtrayicon.h" #include "gui/systemtrayicon.h"
#include "gui/formmain.h"
#include "core/settings.h"
#include "core/defs.h"
QPointer<SystemTrayIcon> SystemTrayIcon::m_trayIcon;
SystemTrayIcon::SystemTrayIcon(QObject *parent) : QSystemTrayIcon(parent) { 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;
}

View File

@ -2,17 +2,34 @@
#define SYSTEMTRAYICON_H #define SYSTEMTRAYICON_H
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QPointer>
class SystemTrayIcon : public QSystemTrayIcon { class SystemTrayIcon : public QSystemTrayIcon {
Q_OBJECT Q_OBJECT
public: public:
explicit SystemTrayIcon(QObject *parent = 0); 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: signals:
public slots: public slots:
private:
static QPointer<SystemTrayIcon> m_trayIcon;
}; };
#endif // SYSTEMTRAYICON_H #endif // SYSTEMTRAYICON_H

View File

@ -62,16 +62,16 @@ QString ThemeFactory::getSystemIconTheme() {
} }
QString ThemeFactory::getCurrentIconTheme() { QString ThemeFactory::getCurrentIconTheme() {
QString current_theme_name = Settings::getInstance().value(APP_CFG_GUI, QString current_theme_name = Settings::getInstance()->value(APP_CFG_GUI,
"icon_theme", "icon_theme",
getSystemIconTheme()).toString(); getSystemIconTheme()).toString();
return current_theme_name; return current_theme_name;
} }
void ThemeFactory::setCurrentIconTheme(const QString &theme_name) { void ThemeFactory::setCurrentIconTheme(const QString &theme_name) {
Settings::getInstance().setValue(APP_CFG_GUI, Settings::getInstance()->setValue(APP_CFG_GUI,
"icon_theme", "icon_theme",
theme_name); theme_name);
loadCurrentIconTheme(); loadCurrentIconTheme();
} }

View File

@ -65,13 +65,12 @@ int main(int argc, char *argv[]) {
QtSingleApplication::setOrganizationName(APP_AUTHORS); QtSingleApplication::setOrganizationName(APP_AUTHORS);
QtSingleApplication::setOrganizationDomain(APP_URL); QtSingleApplication::setOrganizationDomain(APP_URL);
QtSingleApplication::setWindowIcon(QIcon(APP_INFO_PATH)); QtSingleApplication::setWindowIcon(QIcon(APP_INFO_PATH));
qDebug("%s", qPrintable(APP_ICON_PATH));
// Instantiate main application window. // Instantiate main application window.
FormMain window; FormMain window;
if (Settings::getInstance().value(APP_CFG_GEN, "first_start", true).toBool()) { if (Settings::getInstance()->value(APP_CFG_GEN, "first_start", true).toBool()) {
Settings::getInstance().setValue(APP_CFG_GEN, "first_start", false); Settings::getInstance()->setValue(APP_CFG_GEN, "first_start", false);
FormWelcome(&window).exec(); FormWelcome(&window).exec();
} }