Refactorings.

This commit is contained in:
Martin Rotter 2014-07-26 18:48:41 +02:00
parent c46529bc97
commit 7aa22a5fd5
14 changed files with 197 additions and 161 deletions

View File

@ -17,10 +17,62 @@
#include "application.h"
#include "miscellaneous/systemfactory.h"
#include "gui/formmain.h"
#include "gui/feedsview.h"
#include "gui/feedmessageviewer.h"
#include "gui/messagebox.h"
Application::Application(const QString &id, int &argc, char **argv)
: QtSingleApplication(id, argc, argv), m_settings(NULL) {
: QtSingleApplication(id, argc, argv), m_closeLock(NULL), m_mainForm(NULL), m_trayIcon(NULL), m_settings(NULL) {
}
Application::~Application() {
delete m_closeLock;
}
SystemTrayIcon *Application::trayIcon() {
if (m_trayIcon == NULL) {
m_trayIcon = new SystemTrayIcon(APP_ICON_PATH,
APP_ICON_PLAIN_PATH,
m_mainForm);
m_trayIcon->setToolTip(APP_LONG_NAME);
}
return m_trayIcon;
}
void Application::showTrayIcon() {
trayIcon()->show();
if (m_mainForm != NULL) {
m_mainForm->tabWidget()->feedMessageViewer()->feedsView()->notifyWithCounts();
}
}
void Application::deleteTrayIcon() {
if (m_trayIcon != NULL) {
qDebug("Disabling tray icon and raising main application window.");
m_mainForm->display();
delete m_trayIcon;
m_trayIcon = NULL;
// Make sure that application quits when last window is closed.
setQuitOnLastWindowClosed(true);
}
}
void Application::showGuiMessage(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon message_type,
QWidget* parent, int duration) {
if (SystemTrayIcon::isSystemTrayActivated()) {
trayIcon()->showMessage(title, message, message_type, duration);
}
else {
// TODO: Tray icon or OSD is not available, display simple text box.
MessageBox::show(parent, (QMessageBox::Icon) message_type,
title, message);
}
}

View File

@ -20,7 +20,11 @@
#include "qtsingleapplication/qtsingleapplication.h"
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "gui/systemtrayicon.h"
#include <QMutex>
#if defined(qApp)
#undef qApp
@ -29,6 +33,7 @@
// Define new qApp macro. Yeaaaaah.
#define qApp (Application::instance())
class FormMain;
// TODO: presunout nektery veci sem, settings atp
class Application : public QtSingleApplication {
@ -47,12 +52,57 @@ class Application : public QtSingleApplication {
return m_settings;
}
// Access to application-wide close lock.
inline QMutex *closeLock() {
if (m_closeLock == NULL) {
m_closeLock = new QMutex();
}
return m_closeLock;
}
inline FormMain *mainForm() {
return m_mainForm;
}
void setMainForm(FormMain *main_form) {
m_mainForm = main_form;
}
// Access to application tray icon. Always use this in cooperation with
// SystemTrayIcon::isSystemTrayActivated().
SystemTrayIcon *trayIcon();
void showTrayIcon();
void deleteTrayIcon();
// Displays given simple message in tray icon bubble or OSD
// or in message box if tray icon is disabled.
void showGuiMessage(const QString &title, const QString &message,
QSystemTrayIcon::MessageIcon message_type,
QWidget *parent = NULL,
int duration = TRAY_ICON_BUBBLE_TIMEOUT);
// Returns pointer to "GOD" application singleton.
inline static Application *instance() {
return static_cast<Application*>(QCoreApplication::instance());
}
private:
// This read-write lock is used by application on its close.
// Application locks this lock for WRITING.
// This means that if application locks that lock, then
// no other transaction-critical action can acquire lock
// for reading and won't be executed, so no critical action
// will be running when application quits
//
// EACH critical action locks this lock for READING.
// Several actions can lock this lock for reading.
// But of user decides to close the application (in other words,
// tries to lock the lock for writing), then no other
// action will be allowed to lock for reading.
QMutex *m_closeLock;
FormMain *m_mainForm;
SystemTrayIcon *m_trayIcon;
Settings *m_settings;
};

View File

@ -157,7 +157,7 @@ void FeedMessageViewer::updateTrayIconStatus(int unread_messages,
Q_UNUSED(total_messages)
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->setNumber(unread_messages);
qApp->trayIcon()->setNumber(unread_messages);
}
}
@ -178,7 +178,7 @@ void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed,
void FeedMessageViewer::onFeedUpdatesFinished() {
// Updates of some feeds finished, unlock the lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
// And also hide progress bar.
FormMain::instance()->statusBar()->clearProgress();
@ -384,14 +384,14 @@ void FeedMessageViewer::initializeViews() {
void FeedMessageViewer::vacuumDatabase() {
bool is_tray_activated = SystemTrayIcon::isSystemTrayActivated();
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (is_tray_activated) {
SystemTrayIcon::instance()->showMessage(tr("Cannot defragment database"),
tr("Database cannot be defragmented because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot defragment database"),
tr("Database cannot be defragmented because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -405,24 +405,16 @@ void FeedMessageViewer::vacuumDatabase() {
}
if (DatabaseFactory::instance()->vacuumDatabase()) {
if (is_tray_activated) {
SystemTrayIcon::instance()->showMessage(tr("Database defragmented"),
tr("Database was successfully defragmented."),
QSystemTrayIcon::Information);
}
else {
MessageBox::show(this,
QMessageBox::Information,
tr("Database defragmented"),
tr("Database was successfully defragmented."));
}
qApp->showGuiMessage(tr("Database defragmented"),
tr("Database was successfully defragmented."),
QSystemTrayIcon::Information);
}
else {
if (is_tray_activated) {
SystemTrayIcon::instance()->showMessage(tr("Database was not defragmented"),
tr("Database was not defragmented. This database backend does not support it or it cannot be defragmented now."),
QSystemTrayIcon::Warning,
TRAY_ICON_BUBBLE_TIMEOUT);
qApp->trayIcon()->showMessage(tr("Database was not defragmented"),
tr("Database was not defragmented. This database backend does not support it or it cannot be defragmented now."),
QSystemTrayIcon::Warning,
TRAY_ICON_BUBBLE_TIMEOUT);
}
else {
MessageBox::show(this,
@ -432,7 +424,7 @@ void FeedMessageViewer::vacuumDatabase() {
}
}
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FeedMessageViewer::refreshVisualProperties() {

View File

@ -140,14 +140,14 @@ void FeedsView::loadExpandedStates() {
}
void FeedsView::updateAllFeeds() {
if (SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (qApp->closeLock()->tryLock()) {
emit feedsUpdateRequested(allFeeds());
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot update all items"),
tr("You cannot update all items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot update all items"),
tr("You cannot update all items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -166,14 +166,14 @@ void FeedsView::updateAllFeedsOnStartup() {
}
void FeedsView::updateSelectedFeeds() {
if (SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (qApp->closeLock()->tryLock()) {
emit feedsUpdateRequested(selectedFeeds());
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot update selected items"),
tr("You cannot update selected items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot update selected items"),
tr("You cannot update selected items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -185,7 +185,7 @@ void FeedsView::updateSelectedFeeds() {
}
void FeedsView::executeNextAutoUpdate() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
qDebug("Delaying scheduled feed auto-updates for one minute "
"due to another running update.");
@ -212,17 +212,17 @@ void FeedsView::executeNextAutoUpdate() {
if (feeds_for_update.isEmpty()) {
// No feeds are scheduled for update now, unlock the master lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
else {
// Request update for given feeds.
emit feedsUpdateRequested(feeds_for_update);
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Scheduled update started"),
//: RSS Guard is performing updates right now.
tr("%1 is performing scheduled update of some feeds.").arg(APP_NAME),
QSystemTrayIcon::Information);
qApp->trayIcon()->showMessage(tr("Scheduled update started"),
//: RSS Guard is performing updates right now.
tr("%1 is performing scheduled update of some feeds.").arg(APP_NAME),
QSystemTrayIcon::Information);
}
}
}
@ -250,14 +250,14 @@ void FeedsView::clearAllFeeds() {
}
void FeedsView::addNewCategory() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot add standard category"),
tr("You cannot add new standard category now because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot add standard category"),
tr("You cannot add new standard category now because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -277,7 +277,7 @@ void FeedsView::addNewCategory() {
delete form_pointer.data();
// Changes are done, unlock the update master lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FeedsView::editCategory(FeedsModelCategory *category) {
@ -289,14 +289,14 @@ void FeedsView::editCategory(FeedsModelCategory *category) {
}
void FeedsView::addNewFeed() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -316,7 +316,7 @@ void FeedsView::addNewFeed() {
delete form_pointer.data();
// Changes are done, unlock the update master lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FeedsView::editFeed(FeedsModelFeed *feed) {
@ -328,15 +328,15 @@ void FeedsView::editFeed(FeedsModelFeed *feed) {
}
void FeedsView::editSelectedItem() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
//: Warning messagebox title when selected item cannot be edited.
SystemTrayIcon::instance()->showMessage(tr("Cannot edit item"),
tr("Selected item cannot be edited because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot edit item"),
tr("Selected item cannot be edited because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -374,18 +374,18 @@ void FeedsView::editSelectedItem() {
}
// Changes are done, unlock the update master lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FeedsView::deleteSelectedItem() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -403,7 +403,7 @@ void FeedsView::deleteSelectedItem() {
if (!current_index.isValid()) {
// Changes are done, unlock the update master lock and exit.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
return;
}
@ -412,9 +412,9 @@ void FeedsView::deleteSelectedItem() {
selection_model->select(current_index, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
}
@ -430,7 +430,7 @@ void FeedsView::deleteSelectedItem() {
}
// Changes are done, unlock the update master lock.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FeedsView::markSelectedFeedsReadStatus(int read) {

View File

@ -119,7 +119,7 @@ void FormCategoryDetails::apply() {
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot add category"),
qApp->trayIcon()->showMessage(tr("Cannot add category"),
tr("Category was not added due to error."),
QSystemTrayIcon::Critical);
}
@ -137,7 +137,7 @@ void FormCategoryDetails::apply() {
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot edit category"),
qApp->trayIcon()->showMessage(tr("Cannot edit category"),
tr("Category was not edited due to error."),
QSystemTrayIcon::Critical);
}

View File

@ -227,9 +227,9 @@ void FormFeedDetails::apply() {
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot add feed"),
tr("Feed was not added due to error."),
QSystemTrayIcon::Critical);
qApp->trayIcon()->showMessage(tr("Cannot add feed"),
tr("Feed was not added due to error."),
QSystemTrayIcon::Critical);
}
else {
MessageBox::show(this,
@ -246,9 +246,9 @@ void FormFeedDetails::apply() {
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot edit feed"),
tr("Feed was not edited due to error."),
QSystemTrayIcon::Critical);
qApp->trayIcon()->showMessage(tr("Cannot edit feed"),
tr("Feed was not edited due to error."),
QSystemTrayIcon::Critical);
}
else {
MessageBox::show(this,
@ -447,7 +447,7 @@ void FormFeedDetails::initialize() {
}
void FormFeedDetails::loadCategories(const QList<FeedsModelCategory*> categories,
FeedsModelRootItem *root_item) {
FeedsModelRootItem *root_item) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));

View File

@ -165,10 +165,10 @@ void FormMain::processExecutionMessage(const QString &message) {
if (message == APP_IS_RUNNING) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(APP_NAME,
tr("Application is already running."),
QSystemTrayIcon::Information,
TRAY_ICON_BUBBLE_TIMEOUT);
qApp->trayIcon()->showMessage(APP_NAME,
tr("Application is already running."),
QSystemTrayIcon::Information,
TRAY_ICON_BUBBLE_TIMEOUT);
}
display();
@ -240,7 +240,7 @@ void FormMain::onSaveState(QSessionManager &manager) {
void FormMain::onAboutToQuit() {
// Make sure that we obtain close lock
// BEFORE even trying to quit the application.
bool locked_safely = SystemFactory::instance()->applicationCloseLock()->tryLock(CLOSE_LOCK_TIMEOUT);
bool locked_safely = qApp->closeLock()->tryLock(CLOSE_LOCK_TIMEOUT);
qApp->processEvents();
@ -260,7 +260,7 @@ void FormMain::onAboutToQuit() {
qDebug("Close lock was obtained safely.");
// We locked the lock to exit peacefully, unlock it to avoid warnings.
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
else {
// Request for write lock timed-out. This means
@ -474,11 +474,11 @@ void FormMain::showAbout() {
}
void FormMain::showUpdates() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
if (!qApp->closeLock()->tryLock()) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot check for updates"),
tr("You cannot check for updates because feed update is ongoing."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot check for updates"),
tr("You cannot check for updates because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -494,15 +494,15 @@ void FormMain::showUpdates() {
form_update.data()->exec();
delete form_update.data();
SystemFactory::instance()->applicationCloseLock()->unlock();
qApp->closeLock()->unlock();
}
void FormMain::reportABug() {
if (!WebFactory::instance()->openUrlInExternalBrowser(APP_URL_ISSUES_NEW)) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot open external browser"),
tr("Cannot open external browser. Navigate to application website manually."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,

View File

@ -294,10 +294,10 @@ void FormSettings::promptForRestart() {
if (question_result == QMessageBox::Yes) {
if (!QProcess::startDetached(qApp->applicationFilePath())) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Problem with application restart"),
tr("Application couldn't be restarted. "
"Please, restart it manually for changes to take effect."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Problem with application restart"),
tr("Application couldn't be restarted. "
"Please, restart it manually for changes to take effect."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -800,12 +800,10 @@ void FormSettings::saveInterface() {
m_ui->m_radioTrayOn->isChecked());
if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
SystemTrayIcon::instance()->show();
FormMain::instance()->tabWidget()->feedMessageViewer()->feedsView()->notifyWithCounts();
qApp->showTrayIcon();
}
else {
FormMain::instance()->display();
SystemTrayIcon::deleteInstance();
qApp->deleteTrayIcon();
}
}

View File

@ -209,9 +209,9 @@ void FormUpdate::startUpdate() {
qDebug("External updater was not launched due to error.");
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot update application"),
tr("Cannot launch external updater. Update application manually."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot update application"),
tr("Cannot launch external updater. Update application manually."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
@ -244,10 +244,10 @@ void FormUpdate::startUpdate() {
// Self-update and package are not available.
if (!WebFactory::instance()->openUrlInExternalBrowser(url_file)) {
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(tr("Cannot update application"),
tr("Cannot navigate to installation file. Check new installation downloads "
"manually on project website."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(tr("Cannot update application"),
tr("Cannot navigate to installation file. Check new installation downloads "
"manually on project website."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,

View File

@ -39,16 +39,14 @@ bool TrayIconMenu::event(QEvent *event) {
if (Application::activeModalWidget() != NULL &&
event->type() == QEvent::Show) {
QTimer::singleShot(0, this, SLOT(hide()));
SystemTrayIcon::instance()->showMessage(APP_LONG_NAME,
tr("Close opened modal dialogs first."),
QSystemTrayIcon::Warning);
qApp->trayIcon()->showMessage(APP_LONG_NAME,
tr("Close opened modal dialogs first."),
QSystemTrayIcon::Warning);
}
return QMenu::event(event);
}
#endif
QPointer<SystemTrayIcon> SystemTrayIcon::s_trayIcon;
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
const QString &plain_icon,
FormMain *parent)
@ -96,28 +94,6 @@ bool SystemTrayIcon::isSystemTrayActivated() {
true).toBool();
}
SystemTrayIcon *SystemTrayIcon::instance() {
if (s_trayIcon.isNull()) {
s_trayIcon = new SystemTrayIcon(APP_ICON_PATH,
APP_ICON_PLAIN_PATH,
FormMain::instance());
}
return s_trayIcon;
}
void SystemTrayIcon::deleteInstance() {
if (!s_trayIcon.isNull()) {
qDebug("Disabling tray icon and raising main application window.");
static_cast<FormMain*>((*s_trayIcon).parent())->display();
delete s_trayIcon.data();
s_trayIcon = NULL;
// Make sure that application quits when last window is closed.
qApp->setQuitOnLastWindowClosed(true);
}
}
void SystemTrayIcon::showPrivate() {
// Make sure that application does not exit some window (for example
// the settings window) gets closed. Behavior for main window
@ -129,7 +105,7 @@ void SystemTrayIcon::showPrivate() {
qDebug("Tray icon displayed.");
}
void SystemTrayIcon::show() {
void SystemTrayIcon::show() {
#if defined(Q_OS_WIN)
// Show immediately.
qDebug("Showing tray icon immediately.");

View File

@ -58,15 +58,8 @@ class SystemTrayIcon : public QSystemTrayIcon {
// application settings.
static bool isSystemTrayActivated();
// Creates new tray icon if necessary and returns it.
// WARNING: Use this in cooperation with SystemTrayIcon::isSystemTrayActivated().
static SystemTrayIcon *instance();
// Sets the number to be visible in the tray icon, number <= 0 removes it.
void setNumber(int number = -1);
// Explicitle clears SystemTrayIcon instance from the memory.
static void deleteInstance();
public slots:
void show();
@ -79,8 +72,6 @@ class SystemTrayIcon : public QSystemTrayIcon {
QIcon m_normalIcon;
QPixmap m_plainPixmap;
QFont m_font;
static QPointer<SystemTrayIcon> s_trayIcon;
};
#endif // SYSTEMTRAYICON_H

View File

@ -96,6 +96,7 @@ int main(int argc, char *argv[]) {
// Instantiate main application window.
FormMain main_window;
application.setMainForm(&main_window);
// Set correct information for main window.
main_window.setWindowTitle(APP_LONG_NAME);
@ -117,8 +118,7 @@ int main(int argc, char *argv[]) {
// Display tray icon if it is enabled and available.
if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->show();
main_window.tabWidget()->feedMessageViewer()->feedsView()->notifyWithCounts();
qApp->showTrayIcon();
}
// Setup single-instance behavior.

View File

@ -35,13 +35,10 @@
QPointer<SystemFactory> SystemFactory::s_instance;
SystemFactory::SystemFactory(QObject *parent) : QObject(parent) {
m_applicationCloseLock = new QMutex();
}
SystemFactory::~SystemFactory() {
qDebug("Destroying SystemFactory instance.");
delete m_applicationCloseLock;
}

View File

@ -21,7 +21,6 @@
#include <QObject>
#include <QPointer>
#include <QMutex>
#include <QMetaType>
#include <QHash>
#include <QPair>
@ -94,29 +93,10 @@ class SystemFactory : public QObject {
// Tries to download list with new updates.
QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates();
// Access to application-wide close lock.
inline QMutex *applicationCloseLock() const {
return m_applicationCloseLock;
}
// Singleton getter.
static SystemFactory *instance();
private:
// This read-write lock is used by application on its close.
// Application locks this lock for WRITING.
// This means that if application locks that lock, then
// no other transaction-critical action can acquire lock
// for reading and won't be executed, so no critical action
// will be running when application quits
//
// EACH critical action locks this lock for READING.
// Several actions can lock this lock for reading.
// But of user decides to close the application (in other words,
// tries to lock the lock for writing), then no other
// action will be allowed to lock for reading.
QMutex *m_applicationCloseLock;
static QPointer<SystemFactory> s_instance;
};