Merge pull request #1866 from ZeldaZach/fix_1860

Prevent trayIcon Null Crash
This commit is contained in:
ctrlaltca 2016-03-18 21:03:54 +01:00
commit 535e19f8b8
2 changed files with 12 additions and 5 deletions

View file

@ -5,6 +5,7 @@
#include <QAction> #include <QAction>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QApplication> #include <QApplication>
#include <QDebug>
#include "tab_message.h" #include "tab_message.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "chatview.h" #include "chatview.h"
@ -131,10 +132,16 @@ bool TabMessage::shouldShowSystemPopup(const Event_UserMessage &event) {
} }
void TabMessage::showSystemPopup(const Event_UserMessage &event) { void TabMessage::showSystemPopup(const Event_UserMessage &event) {
if (trayIcon) {
disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0); disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0);
trayIcon->showMessage(tr("Private message from ") + otherUserInfo->name().c_str(), event.message().c_str()); trayIcon->showMessage(tr("Private message from ") + otherUserInfo->name().c_str(), event.message().c_str());
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
} }
else
{
qDebug() << "Error: trayIcon is NULL. TabMessage::showSystemPopup failed";
}
}
void TabMessage::messageClicked() { void TabMessage::messageClicked() {
tabSupervisor->setCurrentIndex(tabSupervisor->indexOf(this)); tabSupervisor->setCurrentIndex(tabSupervisor->indexOf(this));

View file

@ -160,8 +160,8 @@ void TabRoom::focusTab() {
} }
void TabRoom::actShowMentionPopup(QString &sender) { void TabRoom::actShowMentionPopup(QString &sender) {
if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this) if (trayIcon && (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this) || QApplication::activeWindow() == 0
|| QApplication::activeWindow() == 0 || QApplication::focusWidget() == 0) { || QApplication::focusWidget() == 0)) {
disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0); disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0);
trayIcon->showMessage(sender + tr(" mentioned you."), tr("Click to view")); trayIcon->showMessage(sender + tr(" mentioned you."), tr("Click to view"));
connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked())); connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked()));