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

support for hiding in tray

also new setting, autostart in tray
This commit is contained in:
agilob 2014-10-08 15:17:05 +01:00
parent 20f2dac755
commit 1d31244273
No known key found for this signature in database
GPG Key ID: 2CACF3EEF598C663
8 changed files with 70 additions and 12 deletions

View File

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

View File

@ -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;

View File

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

View File

@ -31,6 +31,7 @@ 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())
{
@ -50,6 +51,7 @@ GeneralForm::GeneralForm() :
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();

View File

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

View File

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

View File

@ -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();

View File

@ -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();