diff --git a/main.cpp b/main.cpp index e21c1c647..1d447dbf9 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include int main(int argc, char *argv[]) @@ -47,7 +48,24 @@ int main(int argc, char *argv[]) QFontDatabase::addApplicationFont("://DejaVuSans.ttf"); Widget* w = Widget::getInstance(); - w->show(); + if (QSystemTrayIcon::isSystemTrayAvailable() == false) + { + qWarning() << "No system tray detected!"; + w->show(); + } + else + { + QSystemTrayIcon *icon = new QSystemTrayIcon(w); + QObject::connect(icon, + SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + w, + SLOT(onIconClick())); + icon->setIcon(w->windowIcon()); + icon->show(); + if(Settings::getInstance().getAutostartInTray() == false) + w->show(); + } + int errorcode = a.exec(); diff --git a/misc/settings.cpp b/misc/settings.cpp index 545684272..6b1ca0ed0 100644 --- a/misc/settings.cpp +++ b/misc/settings.cpp @@ -1,8 +1,8 @@ /* Copyright (C) 2013 by Maxim Biro - + This file is part of Tox Qt GUI. - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -10,7 +10,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - + See the COPYING file for more details. */ @@ -110,6 +110,7 @@ void Settings::load() enableIPv6 = s.value("enableIPv6", true).toBool(); useTranslations = s.value("useTranslations", true).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool(); + autostartInTray = s.value("autostartInTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); useProxy = s.value("useProxy", false).toBool(); proxyAddr = s.value("proxyAddr", "").toString(); @@ -213,6 +214,7 @@ void Settings::save(QString path) s.setValue("enableIPv6", enableIPv6); s.setValue("useTranslations",useTranslations); s.setValue("makeToxPortable",makeToxPortable); + s.setValue("autostartInTray",autostartInTray); s.setValue("useProxy", useProxy); s.setValue("forceTCP", forceTCP); s.setValue("proxyAddr", proxyAddr); @@ -349,6 +351,16 @@ void Settings::setMakeToxPortable(bool newValue) save(); } +bool Settings::getAutostartInTray() const +{ + return autostartInTray; +} + +void Settings::setAutostartInTray(bool newValue) +{ + autostartInTray = newValue; +} + bool Settings::getUseTranslations() const { return useTranslations; diff --git a/misc/settings.h b/misc/settings.h index 7c43987d6..9278fff8b 100644 --- a/misc/settings.h +++ b/misc/settings.h @@ -1,8 +1,8 @@ /* Copyright (C) 2013 by Maxim Biro - + This file is part of Tox Qt GUI. - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -10,7 +10,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - + See the COPYING file for more details. */ @@ -49,12 +49,15 @@ public: bool getMakeToxPortable() const; void setMakeToxPortable(bool newValue); + bool getAutostartInTray() const; + void setAutostartInTray(bool newValue); + bool getUseTranslations() const; void setUseTranslations(bool newValue); bool getForceTCP() const; void setForceTCP(bool newValue); - + QString getProxyAddr() const; void setProxyAddr(const QString& newValue); @@ -165,7 +168,8 @@ private: bool enableIPv6; bool useTranslations; static bool makeToxPortable; - + bool autostartInTray; + bool forceTCP; bool useProxy; diff --git a/widget/form/settings/generalform.cpp b/widget/form/settings/generalform.cpp index b8138874e..0df370048 100644 --- a/widget/form/settings/generalform.cpp +++ b/widget/form/settings/generalform.cpp @@ -31,13 +31,14 @@ GeneralForm::GeneralForm() : bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6()); bodyUI->cbUseTranslations->setChecked(Settings::getInstance().getUseTranslations()); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); + bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray()); for (auto entry : SmileyPack::listSmileyPacks()) { bodyUI->smileyPackBrowser->addItem(entry.first, entry.second); } bodyUI->smileyPackBrowser->setCurrentIndex(bodyUI->smileyPackBrowser->findData(Settings::getInstance().getSmileyPack())); - + bodyUI->cbUDPDisabled->setChecked(Settings::getInstance().getForceTCP()); bodyUI->proxyAddr->setText(Settings::getInstance().getProxyAddr()); int port = Settings::getInstance().getProxyPort(); @@ -46,10 +47,11 @@ GeneralForm::GeneralForm() : bodyUI->cbUseProxy->setChecked(Settings::getInstance().getUseProxy()); onUseProxyUpdated(); - + connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated); connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated); + connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray); connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int))); // new syntax can't handle overloaded signals... (at least not in a pretty way) connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); @@ -78,6 +80,11 @@ void GeneralForm::onMakeToxPortableUpdated() Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked()); } +void GeneralForm::onSetAutostartInTray() +{ + Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked()); +} + void GeneralForm::onSmileyBrowserIndexChanged(int index) { QString filename = bodyUI->smileyPackBrowser->itemData(index).toString(); diff --git a/widget/form/settings/generalform.h b/widget/form/settings/generalform.h index ddfde9522..224c6ee26 100644 --- a/widget/form/settings/generalform.h +++ b/widget/form/settings/generalform.h @@ -36,6 +36,7 @@ private slots: void onEnableIPv6Updated(); void onUseTranslationUpdated(); void onMakeToxPortableUpdated(); + void onSetAutostartInTray(); void onSmileyBrowserIndexChanged(int index); void onUDPUpdated(); void onProxyAddrEdited(); diff --git a/widget/form/settings/generalsettings.ui b/widget/form/settings/generalsettings.ui index 653f15204..e0ffb3ab4 100644 --- a/widget/form/settings/generalsettings.ui +++ b/widget/form/settings/generalsettings.ui @@ -7,7 +7,7 @@ 0 0 527 - 367 + 369 @@ -46,6 +46,13 @@ + + + + Start in tray + + + diff --git a/widget/widget.cpp b/widget/widget.cpp index 708c23fd4..189b43f40 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -344,6 +344,14 @@ void Widget::onTransferClicked() activeChatroomWidget = nullptr; } +void Widget::onIconClick() +{ + if(this->isHidden() == true) + this->show(); + else + this->hide(); +} + void Widget::onSettingsClicked() { hideMainForms(); diff --git a/widget/widget.h b/widget/widget.h index b7abc60fa..a973ca818 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -105,6 +105,7 @@ private slots: void onMessageSendResult(int friendId, const QString& message, int messageId); void onGroupSendResult(int groupId, const QString& message, int result); void playRingtone(); + void onIconClick(); private: void hideMainForms();