1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #409 from agilob/trayicon

support for hiding in tray
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-10 21:01:01 +02:00
commit f8057c8046
8 changed files with 70 additions and 12 deletions

View File

@ -19,6 +19,7 @@
#include <QApplication> #include <QApplication>
#include <QFontDatabase> #include <QFontDatabase>
#include <QTranslator> #include <QTranslator>
#include <QSystemTrayIcon>
#include <QDebug> #include <QDebug>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -47,7 +48,24 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont("://DejaVuSans.ttf"); QFontDatabase::addApplicationFont("://DejaVuSans.ttf");
Widget* w = Widget::getInstance(); 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(); int errorcode = a.exec();

View File

@ -110,6 +110,7 @@ void Settings::load()
enableIPv6 = s.value("enableIPv6", true).toBool(); enableIPv6 = s.value("enableIPv6", true).toBool();
useTranslations = s.value("useTranslations", true).toBool(); useTranslations = s.value("useTranslations", true).toBool();
makeToxPortable = s.value("makeToxPortable", false).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool();
autostartInTray = s.value("autostartInTray", false).toBool();
forceTCP = s.value("forceTCP", false).toBool(); forceTCP = s.value("forceTCP", false).toBool();
useProxy = s.value("useProxy", false).toBool(); useProxy = s.value("useProxy", false).toBool();
proxyAddr = s.value("proxyAddr", "").toString(); proxyAddr = s.value("proxyAddr", "").toString();
@ -213,6 +214,7 @@ void Settings::save(QString path)
s.setValue("enableIPv6", enableIPv6); s.setValue("enableIPv6", enableIPv6);
s.setValue("useTranslations",useTranslations); s.setValue("useTranslations",useTranslations);
s.setValue("makeToxPortable",makeToxPortable); s.setValue("makeToxPortable",makeToxPortable);
s.setValue("autostartInTray",autostartInTray);
s.setValue("useProxy", useProxy); s.setValue("useProxy", useProxy);
s.setValue("forceTCP", forceTCP); s.setValue("forceTCP", forceTCP);
s.setValue("proxyAddr", proxyAddr); s.setValue("proxyAddr", proxyAddr);
@ -349,6 +351,16 @@ void Settings::setMakeToxPortable(bool newValue)
save(); save();
} }
bool Settings::getAutostartInTray() const
{
return autostartInTray;
}
void Settings::setAutostartInTray(bool newValue)
{
autostartInTray = newValue;
}
bool Settings::getUseTranslations() const bool Settings::getUseTranslations() const
{ {
return useTranslations; return useTranslations;

View File

@ -49,6 +49,9 @@ public:
bool getMakeToxPortable() const; bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue); void setMakeToxPortable(bool newValue);
bool getAutostartInTray() const;
void setAutostartInTray(bool newValue);
bool getUseTranslations() const; bool getUseTranslations() const;
void setUseTranslations(bool newValue); void setUseTranslations(bool newValue);
@ -165,6 +168,7 @@ private:
bool enableIPv6; bool enableIPv6;
bool useTranslations; bool useTranslations;
static bool makeToxPortable; static bool makeToxPortable;
bool autostartInTray;
bool forceTCP; bool forceTCP;

View File

@ -31,6 +31,7 @@ GeneralForm::GeneralForm() :
bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6()); bodyUI->cbEnableIPv6->setChecked(Settings::getInstance().getEnableIPv6());
bodyUI->cbUseTranslations->setChecked(Settings::getInstance().getUseTranslations()); bodyUI->cbUseTranslations->setChecked(Settings::getInstance().getUseTranslations());
bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
bodyUI->startInTray->setChecked(Settings::getInstance().getAutostartInTray());
for (auto entry : SmileyPack::listSmileyPacks()) for (auto entry : SmileyPack::listSmileyPacks())
{ {
@ -50,6 +51,7 @@ GeneralForm::GeneralForm() :
connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated); connect(bodyUI->cbEnableIPv6, &QCheckBox::stateChanged, this, &GeneralForm::onEnableIPv6Updated);
connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated); connect(bodyUI->cbUseTranslations, &QCheckBox::stateChanged, this, &GeneralForm::onUseTranslationUpdated);
connect(bodyUI->cbMakeToxPortable, &QCheckBox::stateChanged, this, &GeneralForm::onMakeToxPortableUpdated); 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))); connect(bodyUI->smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int)));
// new syntax can't handle overloaded signals... (at least not in a pretty way) // new syntax can't handle overloaded signals... (at least not in a pretty way)
connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated); connect(bodyUI->cbUDPDisabled, &QCheckBox::stateChanged, this, &GeneralForm::onUDPUpdated);
@ -78,6 +80,11 @@ void GeneralForm::onMakeToxPortableUpdated()
Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked()); Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
} }
void GeneralForm::onSetAutostartInTray()
{
Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked());
}
void GeneralForm::onSmileyBrowserIndexChanged(int index) void GeneralForm::onSmileyBrowserIndexChanged(int index)
{ {
QString filename = bodyUI->smileyPackBrowser->itemData(index).toString(); QString filename = bodyUI->smileyPackBrowser->itemData(index).toString();

View File

@ -36,6 +36,7 @@ private slots:
void onEnableIPv6Updated(); void onEnableIPv6Updated();
void onUseTranslationUpdated(); void onUseTranslationUpdated();
void onMakeToxPortableUpdated(); void onMakeToxPortableUpdated();
void onSetAutostartInTray();
void onSmileyBrowserIndexChanged(int index); void onSmileyBrowserIndexChanged(int index);
void onUDPUpdated(); void onUDPUpdated();
void onProxyAddrEdited(); void onProxyAddrEdited();

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>527</width> <width>527</width>
<height>367</height> <height>369</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -46,6 +46,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="startInTray">
<property name="text">
<string>Start in tray</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -344,6 +344,14 @@ void Widget::onTransferClicked()
activeChatroomWidget = nullptr; activeChatroomWidget = nullptr;
} }
void Widget::onIconClick()
{
if(this->isHidden() == true)
this->show();
else
this->hide();
}
void Widget::onSettingsClicked() void Widget::onSettingsClicked()
{ {
hideMainForms(); hideMainForms();

View File

@ -105,6 +105,7 @@ private slots:
void onMessageSendResult(int friendId, const QString& message, int messageId); void onMessageSendResult(int friendId, const QString& message, int messageId);
void onGroupSendResult(int groupId, const QString& message, int result); void onGroupSendResult(int groupId, const QString& message, int result);
void playRingtone(); void playRingtone();
void onIconClick();
private: private:
void hideMainForms(); void hideMainForms();