Merge pull request #2806 from defnax/macos-fixes

Added logo for retroshare-service on macOS
This commit is contained in:
csoler 2023-12-23 18:02:43 +01:00 committed by GitHub
commit 081782c97c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include <QString>
#include <QUrl>
#include <QtDebug>
#include <QMenuBar>
#include <retroshare/rsplugin.h>
#include <retroshare/rsconfig.h>
@ -377,6 +378,10 @@ MainWindow::~MainWindow()
delete sysTrayStatus;
delete trayIcon;
delete trayMenu;
#if defined(Q_OS_DARWIN)
delete menuBar;
delete dockMenu;
#endif
// delete notifyMenu; // already deleted by the deletion of trayMenu
StatisticsWindow::releaseInstance();
@ -651,10 +656,48 @@ void MainWindow::createTrayIcon()
trayIcon->setContextMenu(trayMenu);
trayIcon->setIcon(QIcon(IMAGE_NOONLINE));
#if defined(Q_OS_DARWIN)
createMenuBar();
#endif
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
}
#if defined(Q_OS_DARWIN)
/** Creates a new menubar for macOS */
void MainWindow::createMenuBar()
{
/* Mac users sure like their shortcuts. */
actionMinimize = new QAction(tr("Minimize"),this);
actionMinimize->setShortcutContext(Qt::ApplicationShortcut);
actionMinimize->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
actionMinimize->setShortcutVisibleInContextMenu(true);
connect(actionMinimize,SIGNAL(triggered()),this,SLOT(showMinimized())) ;
menuBar = new QMenuBar(this);
QMenu *fileMenu = menuBar->addMenu("");
fileMenu->addAction(actionMinimize);
dockMenu = new QMenu(this);
dockMenu->setAsDockMenu();
dockMenu->addAction(tr("Open Messages"), this, SLOT(Mess()));
dockMenu->addAction(tr("Bandwidth Graph"), this, SLOT(showBandwidthGraph()));
dockMenu->addAction(tr("Statistics"), this, SLOT(showStatisticsWindow()));
dockMenu->addAction(tr("Options"), this, SLOT(showSettings()));
dockMenu->addAction(tr("Help"), this, SLOT(showHelpDialog()));
dockMenu->addSeparator();
QObject::connect(dockMenu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));
toggleVisibilityAction = dockMenu->addAction(tr("Show/Hide"), this, SLOT(toggleVisibilitycontextmenu()));
dockMenu->addSeparator();
QMenu *statusMenu = dockMenu->addMenu(tr("Status"));
initializeStatusObject(statusMenu, true);
}
#endif
void MainWindow::showBandwidthGraph()
{
if(_bandwidthGraph == NULL)
@ -1220,7 +1263,11 @@ void MainWindow::updateMenu()
void MainWindow::toggleVisibility(QSystemTrayIcon::ActivationReason e)
{
#if defined(Q_OS_DARWIN)
if (e == QSystemTrayIcon::DoubleClick) {
#else
if (e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
#endif
if (isHidden() || isMinimized()) {
show();
if (isMinimized()) {

View File

@ -308,6 +308,10 @@ private:
void initStackedPage();
void addPage(MainPage *page, QActionGroup *grp, QList<QPair<MainPage *, QPair<QAction *, QListWidgetItem *> > > *notify);
void createTrayIcon();
#if defined(Q_OS_DARWIN)
/** Creates a default menubar on Mac */
void createMenuBar();
#endif
void createNotifyIcons();
static MainWindow *_instance;
@ -324,6 +328,13 @@ private:
QString nameAndLocation;
#if defined(Q_OS_DARWIN)
/** The menubar (Mac OS X only). */
QMenuBar *menuBar;
QMenu *dockMenu;
QAction* actionMinimize;
#endif
QSystemTrayIcon *trayIcon;
QMenu *notifyMenu;
QMenu *trayMenu;

Binary file not shown.

View File

@ -70,6 +70,10 @@ macx {
#QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4
LIBS += -lz
#LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan
RC_FILE = $$files($$PWD/logo.icns)
mac_icon.files = $$files($$PWD/logo.icns)
mac_icon.path = Contents/Resources
QMAKE_BUNDLE_DATA += mac_icon
for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a}