Permalink
Browse files

add GMB::DBus::simple_call function and use it

  • Loading branch information...
squentin committed Aug 28, 2015
1 parent 3e82d84 commit b54d9a27b077ace13c140ad78740ad1bae83f772
Showing with 31 additions and 16 deletions.
  1. +5 −7 gmusicbrowser.pl
  2. +21 −0 gmusicbrowser_dbus.pm
  3. +5 −9 plugins/gnome_mmkeys.pm
View
@@ -410,13 +410,11 @@ BEGIN
if (!$running && !$CmdLine{noDBus})
{ eval {require 'gmusicbrowser_dbus.pm'}
|| warn "Error loading gmusicbrowser_dbus.pm :\n$@ => controlling gmusicbrowser through DBus won't be possible.\n\n";
eval
{ my $bus= $GMB::DBus::bus || die;
my $service = $bus->get_service($DBus_id) || die;
my $object = $service->get_object('/org/gmusicbrowser', 'org.gmusicbrowser') || die;
$object->RunCommand($_) for @cmd;
};
$running="using DBus id=$DBus_id" unless $@;
my $object= GMB::DBus::simple_call("$DBus_id org.gmusicbrowser/org/gmusicbrowser");
if ($object)
{ $object->RunCommand($_) for @cmd;
$running="using DBus id=$DBus_id";
}
}
if ($running)
{ warn "Found a running instance ($running)\n";
View
@@ -151,6 +151,27 @@ sub init
0; #called in an idle, return 0 to run only once
}
use Net::DBus::Annotation qw(:call);
sub simple_call #$service_path can be service_and_path separated by space, or the object
{ my ($service_path,$method,$args,$reply)=@_;
my $return= eval
{ my $object;
if (ref $service_path) { $object=$service_path }
else
{ my ($name,$path)= split / +/,$service_path,2;
my $service= $bus->get_service($name);
return $service unless $path;
my $interface= $path=~s#^([^/]+)## ? $1 : undef;
$object = $service->get_object($path,$interface);
}
return $object unless $method;
$reply&&= $reply eq 'async' ? dbus_call_async :
$reply eq 'noreply' ? dbus_call_noreply : undef;
return $object->$method(($reply||()),@$args);
};
return $@ ? undef : $return;
}
sub DBus_mainloop_hack
{ # use Net::DBus internals to connect it to the Glib mainloop, though unlikely, it may break with future version of Net::DBus
use Net::DBus::Reactor;
View
@@ -24,16 +24,12 @@ my %Names=
mate => 'org.mate.SettingsDaemon /org/mate/SettingsDaemon/MediaKeys',
);
my $bus= Net::DBus->find;
my ($service,$object);
my $object;
for my $desktop (qw/gnome mate ognome/)
{ my ($name,$path)= split /\s+/, $Names{$desktop};
eval
{ $service= $bus->get_service($name);
$object = $service->get_object($path);
$object->connect_to_signal(MediaPlayerKeyPressed => \&callback);
};
last if $object && !$@;
{ if ($object= GMB::DBus::simple_call($Names{$desktop}))
{ $object->connect_to_signal(MediaPlayerKeyPressed => \&callback);
last
}
}
die "Can't find the dbus Settings Daemon for gnome or MATE\n" if $@;

0 comments on commit b54d9a2

Please sign in to comment.