Skip to content

Commit

Permalink
Merge pull request #682 from ilya-fedin/statusnotifieritem
Browse files Browse the repository at this point in the history
Add menu and system icon to the tray icon
  • Loading branch information
KitsuneRal authored Jul 12, 2020
2 parents 3742615 + 8273195 commit 5671a95
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
29 changes: 29 additions & 0 deletions client/linuxutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2017 Elvis Angelaccio <[email protected]>
* Copyright (C) 2020 The Quotient project
*
* 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 (at your option) any later version.
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QtCore/QFileInfo>

inline bool inFlatpak() {
return QFileInfo::exists("/.flatpak-info");
}

inline QString appIconName() {
return inFlatpak() ? "com.github.quaternion" : "quaternion";
}
4 changes: 3 additions & 1 deletion client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "networkconfigdialog.h"
#include "roomdialogs.h"
#include "systemtrayicon.h"
#include "linuxutils.h"

#include <csapi/joining.h>
#include <connection.h>
Expand Down Expand Up @@ -80,7 +81,7 @@ MainWindow::MainWindow()
connect(nam, &QNetworkAccessManager::sslErrors,
this, &MainWindow::sslErrors);

setWindowIcon(QIcon(":/icon.png"));
setWindowIcon(QIcon::fromTheme(appIconName(), QIcon(":/icon.png")));

roomListDock = new RoomListDock(this);
addDockWidget(Qt::LeftDockWidgetArea, roomListDock);
Expand All @@ -102,6 +103,7 @@ MainWindow::MainWindow()
chatRoomWidget, &ChatRoomWidget::insertMention);

createMenu();
createWinId();
systemTrayIcon = new SystemTrayIcon(this);
systemTrayIcon->show();

Expand Down
15 changes: 14 additions & 1 deletion client/systemtrayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,30 @@

#include "systemtrayicon.h"

#include <QtGui/QWindow>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMenu>

#include "mainwindow.h"
#include "quaternionroom.h"
#include "linuxutils.h"
#include <settings.h>
#include <qt_connection_util.h>

SystemTrayIcon::SystemTrayIcon(MainWindow* parent)
: QSystemTrayIcon(parent)
, m_parent(parent)
{
setIcon(QIcon(":/icon.png"));
auto contextMenu = new QMenu(parent);
auto showHideAction = contextMenu->addAction(tr("Hide"), this, &SystemTrayIcon::showHide);
contextMenu->addAction(tr("Quit"), QApplication::quit);
connect(m_parent->windowHandle(), &QWindow::visibleChanged, [showHideAction](bool visible) {
showHideAction->setText(visible ? tr("Hide") : tr("Show"));
});

setIcon(QIcon::fromTheme(appIconName(), QIcon(":/icon.png")));
setToolTip("Quaternion");
setContextMenu(contextMenu);
connect( this, &SystemTrayIcon::activated, this, &SystemTrayIcon::systemTrayIconAction);
}

Expand Down

0 comments on commit 5671a95

Please sign in to comment.