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

View File

@ -1,8 +1,8 @@
/*
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
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;

View File

@ -1,8 +1,8 @@
/*
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
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;

View File

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

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