summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2017-03-04 17:37:16 +0100
committerFrédéric Buclin <LpSolit@gmail.com>2017-03-04 17:37:16 +0100
commitc6bf85bfde585dc1226f9daaa3748939dd40d1b8 (patch)
treefad85b200cfa88f8bd2c75c16f295496f1e0c93a
parent2f868df9f35ab4658451bd6eadac5682f796b21f (diff)
downloadmgaonline-c6bf85bfde585dc1226f9daaa3748939dd40d1b8.tar
mgaonline-c6bf85bfde585dc1226f9daaa3748939dd40d1b8.tar.gz
mgaonline-c6bf85bfde585dc1226f9daaa3748939dd40d1b8.tar.bz2
mgaonline-c6bf85bfde585dc1226f9daaa3748939dd40d1b8.tar.xz
mgaonline-c6bf85bfde585dc1226f9daaa3748939dd40d1b8.zip
Hybrid support for both SNI (for Plasma) and GtkStatusIcon
-rwxr-xr-xmgaapplet52
1 files changed, 37 insertions, 15 deletions
diff --git a/mgaapplet b/mgaapplet
index 991ac77f..cfd44340 100755
--- a/mgaapplet
+++ b/mgaapplet
@@ -175,13 +175,27 @@ my %actions = (
'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade },
);
-my $icon = StatusNotifier::Notifier->new_from_icon_name('mgaapplet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'mgaonline');
-$icon->set_title('mgaapplet');
-$icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
-$icon->register;
-$icon->signal_connect(context_menu => sub {
- $menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu;
- });
+my ($icon, $is_plasma);
+# Plasma supports SNI natively. Other DE do not. In that case, we fall back to
+# the deprecated GtkStatusIcon.
+if ($ENV{DESKTOP_SESSION} =~ /plasma$/i) {
+ $is_plasma = 1;
+ $icon = StatusNotifier::Notifier->new_from_icon_name('mgaapplet', 'STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS', 'mgaonline');
+ $icon->set_title('mgaapplet');
+ $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
+ $icon->register;
+ $icon->signal_connect(context_menu => sub {
+ $menu->popup(undef, undef, undef, undef, 0, Gtk3::get_current_event_time()) if $menu;
+ });
+}
+else {
+ $icon = Gtk3::StatusIcon->new;
+ $icon->signal_connect(popup_menu => sub {
+ my ($_icon, $button, $time) = @_;
+ $menu->popup(undef, undef, undef, undef, $button, $time) if $menu;
+ });
+}
+
$icon->signal_connect(activate => sub {
my %click_actions = (
no_update_medium => \&add_media,
@@ -197,7 +211,7 @@ $icon->signal_connect(activate => sub {
}
$click_actions{$action}->() if ref $click_actions{$action};
- });
+ });
foreach my $opt (@ARGV) {
if (member($opt, qw(--force -f))) { setAutoStart('TRUE') }
if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) {
@@ -491,7 +505,7 @@ sub no_more_supported() {
if ($choice eq 'upgrade') {
really_confirm_upgrade() and real_upgrade();
} elsif ($choice eq 'nothing') {
- $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE');
+ $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE') : $icon->set_visible(0);
}
undef $no_more_supported_wip;
}
@@ -664,17 +678,25 @@ sub setState {
state $previous_state;
my @arr = @{$state{$state}{menu}};
my $icon_name = 'mgaonline-' . $state{$state}{colour}[0];
- $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_name);
- $icon->set_tooltip($icon_name, 'mgaapplet', formatAlaTeX(translate($state{$state}{tt}[0])));
- my @invisible_states = qw(delayed okay disconnected locked);
+ if ($is_plasma) {
+ $icon->set_from_icon_name('STATUS_NOTIFIER_ICON', $icon_name);
+ $icon->set_tooltip($icon_name, 'mgaapplet', formatAlaTeX(translate($state{$state}{tt}[0])));
+ }
+ else {
+ $icon_name = "/usr/share/icons/hicolor/scalable/actions/${icon_name}.svg";
+ $icon->set_from_pixbuf(gtkcreate_pixbuf($icon_name));
+ $icon->set_tooltip_text(formatAlaTeX(translate($state{$state}{tt}[0])));
+ }
+ my @invisible_states = qw(delayed okay disconnected locked);
# do not show icon while checking if previously hidden:
if (member($state, @invisible_states)
- or $state eq 'busy' && member($previous_state, @invisible_states)) {
- $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE');
+ or $state eq 'busy' && member($previous_state, @invisible_states))
+ {
+ $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_PASSIVE') : $icon->set_visible(0);
}
else {
- $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE');
+ $is_plasma ? $icon->set_status('STATUS_NOTIFIER_STATUS_ACTIVE') : $icon->set_visible(1);
}
$previous_state = $state;