mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-05 20:03:31 +01:00
Update many things, testing of tray icon behaviour.
This commit is contained in:
parent
d5110d86ee
commit
cc18e95701
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -1,23 +1,41 @@
|
||||
// for testing
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
#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.",
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>586</width>
|
||||
<height>355</height>
|
||||
<width>680</width>
|
||||
<height>414</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -23,7 +23,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentRow">
|
||||
<number>0</number>
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
@ -35,6 +35,11 @@
|
||||
<string>User interface</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Language</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
@ -45,23 +50,30 @@
|
||||
<widget class="QWidget" name="m_pageGeneral"/>
|
||||
<widget class="QWidget" name="m_pageUi">
|
||||
<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>
|
||||
<widget class="QScrollArea" name="m_scrollUi">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
<widget class="QTabWidget" name="m_tabUi">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_scrollUiContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>394</width>
|
||||
<height>290</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_tabIconSkin">
|
||||
<attribute name="title">
|
||||
<string>Icons && skins</string>
|
||||
</attribute>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="m_lblIconTheme">
|
||||
@ -76,12 +88,82 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="m_cmbIconTheme"/>
|
||||
</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>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_pageLanguage"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
@ -146,5 +228,69 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
</ui>
|
||||
|
@ -1,5 +1,34 @@
|
||||
#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) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,34 @@
|
||||
#define SYSTEMTRAYICON_H
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QPointer>
|
||||
|
||||
|
||||
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<SystemTrayIcon> m_trayIcon;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYICON_H
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user