move appindicator support to an optional binary pamac-tray-appindicator
This commit is contained in:
parent
9f3127615f
commit
6b1bf5cb40
7
Makefile
7
Makefile
@ -7,9 +7,12 @@ datadir := $(prefix)/share
|
||||
localedir := $(datadir)/locale
|
||||
sysconfdir ?= /etc
|
||||
|
||||
use_appindicator ?= false
|
||||
|
||||
all:
|
||||
cd resources && make resources
|
||||
cd src && make binaries
|
||||
[ $(use_appindicator) = true ] && cd src && make pamac-tray-appindicator || echo no appindicator support
|
||||
cd po && make gettext
|
||||
|
||||
clean:
|
||||
@ -27,11 +30,13 @@ install:
|
||||
install -Dm755 src/libpamac.so $(libdir)/libpamac.so
|
||||
install -Dm744 src/pamac-daemon $(bindir)/pamac-daemon
|
||||
install -Dm755 src/pamac-tray $(bindir)/pamac-tray
|
||||
[ -e src/pamac-tray-appindicator ] && install -Dm755 src/pamac-tray-appindicator $(bindir)/pamac-tray-appindicator || echo > /dev/null
|
||||
install -Dm755 src/pamac-manager $(bindir)/pamac-manager
|
||||
install -Dm755 src/pamac-updater $(bindir)/pamac-updater
|
||||
install -Dm755 src/pamac-install $(bindir)/pamac-install
|
||||
install -Dm755 src/pamac-refresh $(bindir)/pamac-refresh
|
||||
install -Dm644 data/applications/pamac-tray.desktop $(sysconfdir)/xdg/autostart/pamac-tray.desktop
|
||||
[ -e src/pamac-tray-appindicator ] && install -Dm644 data/applications/pamac-tray-appindicator.desktop $(sysconfdir)/xdg/autostart/pamac-tray-appindicator.desktop || echo > /dev/null
|
||||
install -Dm644 data/applications/pamac-manager.desktop $(datadir)/applications/pamac-manager.desktop
|
||||
install -Dm644 data/applications/pamac-updater.desktop $(datadir)/applications/pamac-updater.desktop
|
||||
install -Dm644 data/applications/pamac-install.desktop $(datadir)/applications/pamac-install.desktop
|
||||
@ -61,11 +66,13 @@ uninstall:
|
||||
rm -f $(libdir)/libpamac.so
|
||||
rm -f $(bindir)/pamac-daemon
|
||||
rm -f $(bindir)/pamac-tray
|
||||
rm -f $(bindir)/pamac-tray-appindicator
|
||||
rm -f $(bindir)/pamac-manager
|
||||
rm -f $(bindir)/pamac-updater
|
||||
rm -f $(bindir)/pamac-install
|
||||
rm -f $(bindir)/pamac-refresh
|
||||
rm -f $(sysconfdir)/xdg/autostart/pamac-tray.desktop
|
||||
rm -f $(sysconfdir)/xdg/autostart/pamac-tray-appindicator.desktop
|
||||
rm -f $(datadir)/applications/pamac-manager.desktop
|
||||
rm -f $(datadir)/applications/pamac-updater.desktop
|
||||
rm -f $(datadir)/applications/pamac-install.desktop
|
||||
|
8
data/applications/pamac-tray-appindicator.desktop
Normal file
8
data/applications/pamac-tray-appindicator.desktop
Normal file
@ -0,0 +1,8 @@
|
||||
[Desktop Entry]
|
||||
Name=Update Notifier
|
||||
Icon=update-notifier
|
||||
Exec=pamac-tray-appindicator
|
||||
Terminal=false
|
||||
Type=Application
|
||||
StartupNotify=true
|
||||
OnlyShowIn=KDE;
|
@ -5,3 +5,4 @@ Exec=pamac-tray
|
||||
Terminal=false
|
||||
Type=Application
|
||||
StartupNotify=true
|
||||
NotShowIn=KDE;
|
||||
|
14
src/Makefile
14
src/Makefile
@ -45,7 +45,7 @@ INSTALLER_GRESOURCE_FILE = ../resources/pamac.installer.gresource.xml
|
||||
binaries: pamac-refresh pamac-daemon pamac-tray pamac-updater pamac-manager pamac-install
|
||||
|
||||
clean:
|
||||
rm -f *.c pamac.h pamac.vapi libpamac.so pamac-refresh pamac-daemon pamac-tray pamac-updater pamac-manager pamac-install
|
||||
rm -f *.c pamac.h pamac.vapi libpamac.so pamac-refresh pamac-daemon pamac-tray pamac-tray-appindicator pamac-updater pamac-manager pamac-install
|
||||
|
||||
pamac-refresh: pamac_config.vala refresh.vala
|
||||
valac -o pamac-refresh \
|
||||
@ -55,13 +55,23 @@ pamac-refresh: pamac_config.vala refresh.vala
|
||||
pamac_config.vala \
|
||||
refresh.vala
|
||||
|
||||
pamac-tray: $(COMMON_SOURCES) alpm_config.vala tray.vala
|
||||
pamac-tray: $(COMMON_SOURCES) alpm_config.vala tray.vala tray-gtk.vala
|
||||
valac -o pamac-tray \
|
||||
$(COMMON_VALA_FLAGS) \
|
||||
--pkg=gtk+-3.0 \
|
||||
--pkg=libnotify \
|
||||
$(COMMON_SOURCES) \
|
||||
tray-gtk.vala \
|
||||
tray.vala
|
||||
|
||||
pamac-tray-appindicator: $(COMMON_SOURCES) alpm_config.vala tray.vala tray-appindicator.vala
|
||||
valac -o pamac-tray-appindicator \
|
||||
$(COMMON_VALA_FLAGS) \
|
||||
--pkg=gtk+-3.0 \
|
||||
--pkg=appindicator3-0.1 \
|
||||
--pkg=libnotify \
|
||||
$(COMMON_SOURCES) \
|
||||
tray-appindicator.vala \
|
||||
tray.vala
|
||||
|
||||
pamac-daemon: ../vapi/libalpm.vapi ../vapi/polkit-gobject-1.vapi ../vapi/libcurl.vapi alpm_config.vala $(COMMON_SOURCES) package.vala aur.vala mirrors_config.vala daemon.vala
|
||||
|
BIN
src/pamac-tray-appindicator
Executable file
BIN
src/pamac-tray-appindicator
Executable file
Binary file not shown.
63
src/tray-appindicator.vala
Normal file
63
src/tray-appindicator.vala
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* pamac-vala
|
||||
*
|
||||
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
|
||||
*
|
||||
* 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 get of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Pamac {
|
||||
|
||||
class IndicatorTrayIcon: TrayIcon {
|
||||
AppIndicator.Indicator indicator_status_icon;
|
||||
|
||||
public override void init_status_icon () {
|
||||
indicator_status_icon = new AppIndicator.Indicator ("Update Manager", noupdate_icon_name, AppIndicator.IndicatorCategory.APPLICATION_STATUS);
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||
// add a item without label to not show it in menu
|
||||
// this allow left click action
|
||||
var item = new Gtk.MenuItem ();
|
||||
item.visible = true;
|
||||
item.activate.connect (left_clicked);
|
||||
menu.append (item);
|
||||
indicator_status_icon.set_menu (menu);
|
||||
indicator_status_icon.set_secondary_activate_target (item);
|
||||
}
|
||||
|
||||
public override void set_tooltip (string info) {
|
||||
indicator_status_icon.set_title (info);
|
||||
}
|
||||
|
||||
public override void set_icon (string icon) {
|
||||
indicator_status_icon.set_icon_full (icon, icon);
|
||||
}
|
||||
|
||||
public override string get_icon () {
|
||||
return indicator_status_icon.get_icon ();
|
||||
}
|
||||
|
||||
public override void set_icon_visible (bool visible) {
|
||||
if (visible) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
} else {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (string[] args) {
|
||||
var tray_icon = new Pamac.IndicatorTrayIcon();
|
||||
return tray_icon.run (args);
|
||||
}
|
62
src/tray-gtk.vala
Normal file
62
src/tray-gtk.vala
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* pamac-vala
|
||||
*
|
||||
* Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
|
||||
*
|
||||
* 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 get of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Pamac {
|
||||
|
||||
class GtkTrayIcon: TrayIcon {
|
||||
Gtk.StatusIcon status_icon;
|
||||
|
||||
public override void init_status_icon () {
|
||||
status_icon = new Gtk.StatusIcon ();
|
||||
status_icon.visible = false;
|
||||
status_icon.activate.connect (left_clicked);
|
||||
status_icon.popup_menu.connect (menu_popup);
|
||||
}
|
||||
|
||||
// Show popup menu on right button
|
||||
void menu_popup (uint button, uint time) {
|
||||
menu.popup (null, null, null, button, time);
|
||||
}
|
||||
|
||||
public override void set_tooltip (string info) {
|
||||
status_icon.set_tooltip_markup (info);
|
||||
}
|
||||
|
||||
public override void set_icon (string icon) {
|
||||
status_icon.set_from_icon_name (icon);
|
||||
}
|
||||
|
||||
public override string get_icon () {
|
||||
return status_icon.get_icon_name ();
|
||||
}
|
||||
|
||||
public override void set_icon_visible (bool visible) {
|
||||
if (visible) {
|
||||
status_icon.visible = true;
|
||||
} else {
|
||||
status_icon.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (string[] args) {
|
||||
var tray_icon = new Pamac.GtkTrayIcon();
|
||||
return tray_icon.run (args);
|
||||
}
|
111
src/tray.vala
111
src/tray.vala
@ -39,24 +39,21 @@ namespace Pamac {
|
||||
public signal void write_alpm_config_finished (bool checkspace);
|
||||
}
|
||||
|
||||
class TrayIcon: Gtk.Application {
|
||||
public abstract class TrayIcon: Gtk.Application {
|
||||
Notify.Notification notification;
|
||||
//~ Notification notification;
|
||||
Daemon daemon;
|
||||
bool extern_lock;
|
||||
uint refresh_timeout_id;
|
||||
Gtk.StatusIcon status_icon;
|
||||
AppIndicator.Indicator indicator_status_icon;
|
||||
Gtk.Menu menu;
|
||||
public Gtk.Menu menu;
|
||||
GLib.File lockfile;
|
||||
bool use_indicator;
|
||||
|
||||
public TrayIcon () {
|
||||
application_id = "org.manjaro.pamac.tray";
|
||||
flags = ApplicationFlags.FLAGS_NONE;
|
||||
use_indicator = Environment.get_variable ("XDG_CURRENT_DESKTOP") == "KDE";
|
||||
}
|
||||
|
||||
public abstract void init_status_icon ();
|
||||
|
||||
void start_daemon () {
|
||||
try {
|
||||
daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac");
|
||||
@ -91,29 +88,11 @@ namespace Pamac {
|
||||
item = new Gtk.MenuItem.with_mnemonic (_("_Quit"));
|
||||
item.activate.connect (this.release);
|
||||
menu.append (item);
|
||||
if (use_indicator) {
|
||||
// add a item without label to not show it in menu
|
||||
// this allow left click action
|
||||
item = new Gtk.MenuItem ();
|
||||
item.activate.connect (left_clicked);
|
||||
menu.append (item);
|
||||
indicator_status_icon.set_menu (menu);
|
||||
indicator_status_icon.set_secondary_activate_target (item);
|
||||
}
|
||||
menu.show_all ();
|
||||
}
|
||||
|
||||
// Show popup menu on right button
|
||||
void menu_popup (uint button, uint time) {
|
||||
menu.popup (null, null, null, button, time);
|
||||
}
|
||||
|
||||
void left_clicked () {
|
||||
if (use_indicator) {
|
||||
if (indicator_status_icon.get_icon () == "pamac-tray-update") {
|
||||
execute_updater ();
|
||||
}
|
||||
} else if (status_icon.icon_name == "pamac-tray-update") {
|
||||
public void left_clicked () {
|
||||
if (get_icon () == "pamac-tray-update") {
|
||||
execute_updater ();
|
||||
}
|
||||
}
|
||||
@ -134,14 +113,13 @@ namespace Pamac {
|
||||
}
|
||||
}
|
||||
|
||||
public void update_icon (string icon, string info) {
|
||||
if (use_indicator) {
|
||||
indicator_status_icon.set_icon_full (icon, icon);
|
||||
} else {
|
||||
status_icon.set_from_icon_name (icon);
|
||||
status_icon.set_tooltip_markup (info);
|
||||
}
|
||||
}
|
||||
public abstract void set_tooltip (string info);
|
||||
|
||||
public abstract void set_icon (string icon);
|
||||
|
||||
public abstract string get_icon ();
|
||||
|
||||
public abstract void set_icon_visible (bool visible);
|
||||
|
||||
bool start_refresh () {
|
||||
// if pamac is not running start refresh else just check updates
|
||||
@ -160,11 +138,7 @@ namespace Pamac {
|
||||
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period) {
|
||||
launch_refresh_timeout (refresh_period);
|
||||
if (refresh_period == 0) {
|
||||
if (use_indicator) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||
} else {
|
||||
status_icon.visible = false;
|
||||
}
|
||||
set_icon_visible (false);
|
||||
} else {
|
||||
check_updates ();
|
||||
}
|
||||
@ -177,30 +151,16 @@ namespace Pamac {
|
||||
void on_get_updates_finished (Updates updates) {
|
||||
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
|
||||
if (updates_nb == 0) {
|
||||
update_icon (noupdate_icon_name, noupdate_info);
|
||||
set_icon (noupdate_icon_name);
|
||||
set_tooltip (noupdate_info);
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
if (pamac_config.no_update_hide_icon) {
|
||||
if (use_indicator) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||
} else {
|
||||
status_icon.visible = false;
|
||||
}
|
||||
} else {
|
||||
if (use_indicator) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
} else {
|
||||
status_icon.visible = true;
|
||||
}
|
||||
}
|
||||
set_icon_visible (!pamac_config.no_update_hide_icon);
|
||||
close_notification();
|
||||
} else {
|
||||
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
|
||||
this.update_icon (update_icon_name, info);
|
||||
if (use_indicator) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
} else {
|
||||
status_icon.visible = true;
|
||||
}
|
||||
set_icon (update_icon_name);
|
||||
set_tooltip (info);
|
||||
set_icon_visible (true);
|
||||
if (check_pamac_running ()) {
|
||||
update_notification (info);
|
||||
} else {
|
||||
@ -223,17 +183,6 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
void show_notification (string info) {
|
||||
//~ notification = new Notification (_("Update Manager"));
|
||||
//~ notification.set_body (info);
|
||||
//~ Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
|
||||
//~ Gdk.Pixbuf icon = icon_theme.load_icon ("system-software-update", 32, 0);
|
||||
//~ notification.set_icon (icon);
|
||||
//~ var action = new SimpleAction ("update", null);
|
||||
//~ action.activate.connect (execute_updater);
|
||||
//~ this.add_action (action);
|
||||
//~ notification.add_button (_("Show available updates"), "app.update");
|
||||
//~ notification.set_default_action ("app.update");
|
||||
//~ this.send_notification (_("Update Manager"), notification);
|
||||
try {
|
||||
close_notification();
|
||||
notification = new Notify.Notification (_("Update Manager"), info, "system-software-update");
|
||||
@ -347,22 +296,8 @@ namespace Pamac {
|
||||
extern_lock = false;
|
||||
refresh_timeout_id = 0;
|
||||
|
||||
if (use_indicator) {
|
||||
indicator_status_icon = new AppIndicator.Indicator ("Update Manager", noupdate_icon_name, AppIndicator.IndicatorCategory.APPLICATION_STATUS);
|
||||
indicator_status_icon.set_title (_("Update Manager"));
|
||||
if (pamac_config.no_update_hide_icon) {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||
} else {
|
||||
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
}
|
||||
} else {
|
||||
status_icon = new Gtk.StatusIcon ();
|
||||
status_icon.visible = !(pamac_config.no_update_hide_icon);
|
||||
status_icon.activate.connect (left_clicked);
|
||||
status_icon.popup_menu.connect (menu_popup);
|
||||
}
|
||||
update_icon (noupdate_icon_name, noupdate_info);
|
||||
create_menu ();
|
||||
init_status_icon ();
|
||||
|
||||
Notify.init (_("Update Manager"));
|
||||
|
||||
@ -385,9 +320,5 @@ namespace Pamac {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
static int main (string[] args) {
|
||||
var tray_icon = new TrayIcon();
|
||||
return tray_icon.run (args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user