Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
Removes application indicator. #522
Browse files Browse the repository at this point in the history
Qt has fixed System Tray for awhile. For users who use old Linux
distributions, they should consider upgrading, or using AppImage
  • Loading branch information
librehat committed Oct 7, 2017
1 parent fc2e935 commit 5917de3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 122 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ addons:
- libbotan1.10-dev
- libqrencode-dev
- libzbar-dev
- libappindicator-dev

env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -36,13 +36,6 @@ find_library(ZBAR_LIBRARY_VAR
NAMES ${ZBAR_LIBRARIES}
HINTS ${ZBAR_LIBRARY_DIRS} ${ZBAR_LIBDIR})

if(UNIX AND NOT APPLE)
pkg_check_modules(APPINDICATOR REQUIRED appindicator-0.1)
find_library(APPINDICATOR_LIBRARY_VAR
NAMES ${APPINDICATOR_LIBRARIES}
HINTS ${APPINDICATOR_LIBRARY_DIRS} ${APPINDICATOR_LIBDIR})
endif()

if(WIN32 OR APPLE)
add_definitions(-DFD_SETSIZE=1024)
endif()
Expand Down
5 changes: 2 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ Build-Depends: debhelper (>= 9),
cmake (>= 3.1.0) | cmake3 (>= 3.1.0),
qtbase5-dev,
libqrencode-dev,
libqtshadowsocks-dev (>= 1.10.0),
libqtshadowsocks-dev (>= 2.0.0),
libzbar-dev,
libappindicator-dev,
libbotan1.10-dev
Standards-Version: 3.9.6
Homepage: https://github.com/librehat/shadowsocks-qt5
Expand All @@ -19,7 +18,7 @@ Vcs-Browser: https://github.com/librehat/shadowsocks-qt5
Package: shadowsocks-qt5
Architecture: any
Depends: ${shlibs:Depends},
libqtshadowsocks (>= 1.10.0)
libqtshadowsocks (>= 2.0.0)
Description: A cross-platform shadowsocks GUI client
Shadowsocks-Qt5 is a native and cross-platform shadowsocks GUI client
with advanced features.
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ target_include_directories(${APP_NAME}
PRIVATE ${ZBAR_INCLUDE_DIRS})

if (UNIX AND NOT APPLE)
target_link_libraries(${APP_NAME}
PRIVATE Qt5::DBus
PRIVATE ${APPINDICATOR_LIBRARY_VAR})
target_include_directories(${APP_NAME} PRIVATE ${APPINDICATOR_INCLUDE_DIRS})
target_link_libraries(${APP_NAME} PRIVATE Qt5::DBus)
endif()

install(TARGETS ${APP_NAME}
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MainWindow::MainWindow(ConfigHelper *confHelper, QWidget *parent) :
(configHelper->getToolbarStyle()));
setupActionIcon();

notifier = new StatusNotifier(this, configHelper->isHideWindowOnStartup(), this);
//notifier = new StatusNotifier(this, configHelper->isHideWindowOnStartup(), this);

connect(configHelper, &ConfigHelper::toolbarStyleChanged,
ui->toolBar, &QToolBar::setToolButtonStyle);
Expand Down
82 changes: 2 additions & 80 deletions src/statusnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,7 @@ StatusNotifier::StatusNotifier(MainWindow *w, bool startHiden, QObject *parent)
systrayMenu.addAction(minimiseRestoreAction);
systrayMenu.addAction(QIcon::fromTheme("application-exit", QIcon::fromTheme("exit")), tr("Quit"), qApp, SLOT(quit()));
systray.setContextMenu(&systrayMenu);

#ifdef USE_APP_INDICATOR
QString de(getenv("XDG_CURRENT_DESKTOP"));
useAppIndicator = appIndicatorDE.contains(de, Qt::CaseInsensitive);
if (useAppIndicator) {
createAppIndicator(startHiden);
} else {
#endif
systray.show();
#ifdef USE_APP_INDICATOR
}
#endif
}

StatusNotifier::~StatusNotifier()
{
#ifdef Q_OS_WIN
systray.hide();
#endif
}

const QStringList StatusNotifier::appIndicatorDE = QStringList()
<< "Unity"
<< "XFCE"
<< "Pantheon"
<< "LXDE"
<< "MATE"
<< "X-Cinnamon";

#ifdef USE_APP_INDICATOR
void onAppIndicatorActivated(GtkMenuItem *, gpointer data)
{
MainWindow *window = reinterpret_cast<MainWindow *>(data);
if (!window->isVisible() || window->isMinimized()) {
window->showNormal();
window->activateWindow();
window->raise();
} else {
window->hide();
}
}

void onQuit(GtkMenu *, gpointer data)
{
reinterpret_cast<QApplication *>(data)->quit();
}

void StatusNotifier::createAppIndicator(bool startHiden)
{
AppIndicator *indicator = app_indicator_new("Shadowsocks-Qt5", "shadowsocks-qt5", APP_INDICATOR_CATEGORY_OTHER);
GtkWidget *menu = gtk_menu_new();

minimiseRestoreGtkItem = gtk_menu_item_new_with_label(
tr(startHiden ? "Restore" : "Minimise").toLocal8Bit().constData());
gtk_menu_shell_append(GTK_MENU_SHELL(menu), minimiseRestoreGtkItem);
g_signal_connect(minimiseRestoreGtkItem, "activate", G_CALLBACK(onAppIndicatorActivated), window);
gtk_widget_show(minimiseRestoreGtkItem);

GtkWidget *exitItem = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), exitItem);
g_signal_connect(exitItem, "activate", G_CALLBACK(onQuit), qApp);
gtk_widget_show(exitItem);

app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_menu(indicator, GTK_MENU(menu));
}
#endif

bool StatusNotifier::isUsingAppIndicator() const
{
return useAppIndicator;
systray.show();
}

void StatusNotifier::activate()
Expand Down Expand Up @@ -123,13 +53,5 @@ void StatusNotifier::showNotification(const QString &msg)

void StatusNotifier::onWindowVisibleChanged(bool visible)
{
#ifdef USE_APP_INDICATOR
if (useAppIndicator) {
gtk_menu_item_set_label(reinterpret_cast<GtkMenuItem *>(minimiseRestoreGtkItem), QObject::tr(visible ? "Minimise" : "Restore").toLocal8Bit().constData());
} else {
#endif
minimiseRestoreAction->setText(visible ? tr("Minimise") : tr("Restore"));
#ifdef USE_APP_INDICATOR
}
#endif
minimiseRestoreAction->setText(visible ? tr("Minimise") : tr("Restore"));
}
27 changes: 2 additions & 25 deletions src/statusnotifier.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Symeon Huang <[email protected]>
* Copyright (C) 2015-2017 Symeon Huang <[email protected]>
*
* shadowsocks-qt5 is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
Expand All @@ -24,47 +24,24 @@
#include <QMenu>
#include <QStringList>

#ifdef USE_APP_INDICATOR
#undef signals
extern "C"
{
#include <libappindicator/app-indicator.h>
#include <gtk/gtk.h>
}
#define signals public
#endif

class MainWindow;

class StatusNotifier : public QObject
{
Q_OBJECT
public:
explicit StatusNotifier(MainWindow *w, bool startHiden, QObject *parent = 0);
~StatusNotifier();

bool isUsingAppIndicator() const;
StatusNotifier(MainWindow *w, bool startHiden, QObject *parent = 0);

public slots:
void activate();
void showNotification(const QString &);
void onWindowVisibleChanged(bool visible);

private:
#ifdef USE_APP_INDICATOR
GtkWidget *minimiseRestoreGtkItem;
void createAppIndicator(bool startHiden);
#endif

QMenu systrayMenu;
QAction *minimiseRestoreAction;
QSystemTrayIcon systray;
MainWindow *window;

bool useAppIndicator;

//desktop environments that need application indicator
static const QStringList appIndicatorDE;
};

#endif // STATUSNOTIFIER_H

0 comments on commit 5917de3

Please sign in to comment.