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

Merge branch 'pr1244'

This commit is contained in:
tux3 2015-03-04 19:29:49 +01:00
commit 17042c1aff
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 56 additions and 43 deletions

View File

@ -114,46 +114,6 @@ void Widget::init()
statusBusy->setIcon(QIcon(":img/status/dot_busy.png"));
connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
if (QSystemTrayIcon::isSystemTrayAvailable())
{
icon = new SystemTrayIcon;
updateTrayIcon();
trayMenu = new QMenu;
actionQuit = new QAction(tr("&Quit"), this);
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
trayMenu->addAction(statusOnline);
trayMenu->addAction(statusAway);
trayMenu->addAction(statusBusy);
trayMenu->addSeparator();
trayMenu->addAction(actionQuit);
icon->setContextMenu(trayMenu);
connect(icon,
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,
SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
icon->show();
icon->hide();
if (Settings::getInstance().getShowSystemTray())
{
icon->show();
if (Settings::getInstance().getAutostartInTray() == false)
this->show();
}
else
this->show();
}
else
{
qWarning() << "Widget: No system tray detected!";
icon = nullptr;
this->show();
}
ui->statusbar->hide();
ui->menubar->hide();
@ -232,6 +192,7 @@ void Widget::init()
connect(addFriendForm, SIGNAL(friendRequested(QString, QString)), this, SIGNAL(friendRequested(QString, QString)));
connect(timer, &QTimer::timeout, this, &Widget::onUserAwayCheck);
connect(timer, &QTimer::timeout, this, &Widget::onEventIconTick);
connect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
connect(offlineMsgTimer, &QTimer::timeout, this, &Widget::processOfflineMsgs);
addFriendForm->show(*ui);
@ -240,6 +201,8 @@ void Widget::init()
if (Settings::getInstance().getCheckUpdates())
AutoUpdater::checkUpdatesAsyncInteractive();
#endif
if (!Settings::getInstance().getShowSystemTray())
show();
}
void Widget::setTranslation()
@ -281,7 +244,8 @@ Widget::~Widget()
{
qDebug() << "Widget: Deleting Widget";
AutoUpdater::abortUpdates();
icon->hide();
if (icon)
icon->hide();
hideMainForms();
delete settingsWidget;
delete addFriendForm;
@ -1094,6 +1058,52 @@ void Widget::onEventIconTick()
}
}
void Widget::onTryCreateTrayIcon()
{
static int32_t tries = 15;
if (!icon && tries--)
{
if (QSystemTrayIcon::isSystemTrayAvailable())
{
icon = new SystemTrayIcon;
updateTrayIcon();
trayMenu = new QMenu;
actionQuit = new QAction(tr("&Quit"), this);
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
trayMenu->addAction(statusOnline);
trayMenu->addAction(statusAway);
trayMenu->addAction(statusBusy);
trayMenu->addSeparator();
trayMenu->addAction(actionQuit);
icon->setContextMenu(trayMenu);
connect(icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
if (Settings::getInstance().getShowSystemTray())
{
icon->show();
setHidden(Settings::getInstance().getAutostartInTray());
}
else
show();
}
else if (!isVisible())
show();
}
else
{
disconnect(timer, &QTimer::timeout, this, &Widget::onTryCreateTrayIcon);
if (!icon)
{
qWarning() << "Widget: No system tray detected!";
show();
}
}
}
void Widget::setStatusOnline()
{
Nexus::getCore()->setStatus(Status::Online);
@ -1137,8 +1147,10 @@ void Widget::onFriendTypingChanged(int friendId, bool isTyping)
f->getChatForm()->setFriendTyping(isTyping);
}
void Widget::onSetShowSystemTray(bool newValue){
icon->setVisible(newValue);
void Widget::onSetShowSystemTray(bool newValue)
{
if (icon)
icon->setVisible(newValue);
}
void Widget::saveWindowGeometry()

View File

@ -134,6 +134,7 @@ private slots:
void onIconClick(QSystemTrayIcon::ActivationReason);
void onUserAwayCheck();
void onEventIconTick();
void onTryCreateTrayIcon();
void onSetShowSystemTray(bool newValue);
void onSplitterMoved(int pos, int index);
void processOfflineMsgs();