forked from blue/squawk
First tray attempt, seems to be working
This commit is contained in:
parent
7192286aeb
commit
7e9eed2075
13 changed files with 201 additions and 7 deletions
|
@ -27,8 +27,14 @@ Application::Application(Core::Squawk* p_core):
|
|||
dialogueQueue(roster),
|
||||
nowQuitting(false),
|
||||
destroyingSquawk(false),
|
||||
storage()
|
||||
storage(),
|
||||
trayIcon(nullptr),
|
||||
actionQuit(Shared::icon("application-exit"), tr("Quit")),
|
||||
actionToggle(tr("Minimize to tray"))
|
||||
{
|
||||
connect(&actionQuit, &QAction::triggered, this, &Application::quit);
|
||||
connect(&actionToggle, &QAction::triggered, this, &Application::toggleSquawk);
|
||||
|
||||
connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify);
|
||||
connect(&roster, &Models::Roster::unreadMessagesCountChanged, this, &Application::unreadMessagesCountChanged);
|
||||
|
||||
|
@ -130,6 +136,12 @@ void Application::quit()
|
|||
if (squawk != nullptr) {
|
||||
squawk->close();
|
||||
}
|
||||
|
||||
if (trayIcon != nullptr) {
|
||||
trayIcon->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
|
||||
if (!destroyingSquawk) {
|
||||
checkForTheLastWindow();
|
||||
}
|
||||
|
@ -155,6 +167,8 @@ void Application::createMainWindow()
|
|||
connect(squawk, &Squawk::openedConversation, this, &Application::onSquawkOpenedConversation);
|
||||
connect(squawk, &Squawk::openConversation, this, &Application::openConversation);
|
||||
connect(squawk, &Squawk::changeState, this, &Application::setState);
|
||||
connect(squawk, &Squawk::changeTray, this, &Application::onChangeTray);
|
||||
connect(squawk, &Squawk::quit, this, &Application::quit);
|
||||
connect(squawk, &Squawk::closing, this, &Application::onSquawkClosing);
|
||||
|
||||
connect(squawk, &Squawk::modifyAccountRequest, core, &Core::Squawk::modifyAccountRequest);
|
||||
|
@ -194,8 +208,15 @@ void Application::onSquawkClosing()
|
|||
squawk->deleteLater();
|
||||
squawk = nullptr;
|
||||
|
||||
//for now
|
||||
quit();
|
||||
QSettings settings;
|
||||
if (!nowQuitting && QSystemTrayIcon::isSystemTrayAvailable() && settings.value("tray", false).toBool()) {
|
||||
if (settings.value("hideTray", false).toBool()) {
|
||||
createTrayIcon();
|
||||
}
|
||||
actionToggle.setText(tr("Show Squawk"));
|
||||
} else {
|
||||
quit();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onSquawkDestroyed() {
|
||||
|
@ -205,6 +226,71 @@ void Application::onSquawkDestroyed() {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::onChangeTray(bool enabled, bool hide)
|
||||
{
|
||||
if (enabled) {
|
||||
if (trayIcon == nullptr) {
|
||||
if (!hide || squawk == nullptr) {
|
||||
createTrayIcon();
|
||||
}
|
||||
} else {
|
||||
if (hide && squawk != nullptr) {
|
||||
trayIcon->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
}
|
||||
} else if (trayIcon == nullptr) {
|
||||
trayIcon->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::createTrayIcon()
|
||||
{
|
||||
trayIcon = new QSystemTrayIcon();
|
||||
|
||||
QMenu* trayIconMenu = new QMenu();
|
||||
trayIconMenu->addAction(&actionToggle);
|
||||
trayIconMenu->addAction(&actionQuit);
|
||||
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
trayIcon->setIcon(QApplication::windowIcon().pixmap(32, 32));
|
||||
trayIcon->setToolTip(QApplication::applicationDisplayName());
|
||||
|
||||
connect(trayIcon, &QSystemTrayIcon::activated, this, &Application::trayClicked);
|
||||
connect(trayIcon, &QSystemTrayIcon::destroyed, trayIconMenu, &QMenu::deleteLater);
|
||||
|
||||
trayIcon->show();
|
||||
}
|
||||
|
||||
void Application::trayClicked(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
case QSystemTrayIcon::Trigger:
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
toggleSquawk();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::toggleSquawk()
|
||||
{
|
||||
QSettings settings;
|
||||
if (squawk == nullptr) {
|
||||
createMainWindow();
|
||||
if (settings.value("hideTray", false).toBool()) {
|
||||
trayIcon->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
|
||||
actionToggle.setText(tr("Minimize to tray"));
|
||||
} else {
|
||||
squawk->close();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::notify(const QString& account, const Shared::Message& msg)
|
||||
{
|
||||
|
@ -345,6 +431,10 @@ void Application::readSettings()
|
|||
|
||||
setState(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
createMainWindow();
|
||||
|
||||
if (settings.value("tray", false).toBool() && !settings.value("hideTray", false).toBool()) {
|
||||
createTrayIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::writeSettings()
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
#include "dialogqueue.h"
|
||||
#include "core/squawk.h"
|
||||
|
@ -91,13 +94,16 @@ private slots:
|
|||
void onSquawkDestroyed();
|
||||
void onNotificationClosed(quint32 id, quint32 reason);
|
||||
void onNotificationInvoked(quint32 id, const QString& action);
|
||||
|
||||
void onChangeTray(bool enabled, bool hide);
|
||||
void trayClicked(QSystemTrayIcon::ActivationReason reason);
|
||||
void toggleSquawk();
|
||||
|
||||
private:
|
||||
void createMainWindow();
|
||||
void subscribeConversation(Conversation* conv);
|
||||
void checkForTheLastWindow();
|
||||
void focusConversation(const Models::Roster::ElId& id, const QString& resource = "", const QString& messageId = "");
|
||||
void createTrayIcon();
|
||||
|
||||
private:
|
||||
typedef std::map<Models::Roster::ElId, Conversation*> Conversations;
|
||||
|
@ -113,6 +119,9 @@ private:
|
|||
bool nowQuitting;
|
||||
bool destroyingSquawk;
|
||||
Notifications storage;
|
||||
QSystemTrayIcon* trayIcon;
|
||||
QAction actionQuit;
|
||||
QAction actionToggle;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue