Skip to content

Commit

Permalink
isReachable/isPaired as properties, correct icon
Browse files Browse the repository at this point in the history
This change switches is_reachable and is_paired to fetch the properties
instead of trying to call a method.  (not sure if/when this changed in
the dbus interface, but that's how they are presented for me)

This fixes issue vikoadi#31 and (I think) vikoadi#38

This also switches the icon code to use the statusIconName as that seems
to have the correct value.  Also, in DeviceIndicator, no longer append
"-symbolic" as (at least on my system) the icons don't seem to have
that in their names.
  • Loading branch information
nicklan authored and rcristi committed Apr 16, 2016
1 parent 20387af commit 37c2221
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
45 changes: 15 additions & 30 deletions src/Device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace KDEConnectIndicator {
}
public string icon_name {
get {
Variant return_variant=device_proxy.get_cached_property ("iconName");
Variant return_variant=device_proxy.get_cached_property ("statusIconName");
if (return_variant!=null && return_variant.get_string () != "")
return return_variant.get_string ();
return "smartphone"; // default to smartphone as KDC 0.5 doens't have icon name props
Expand Down Expand Up @@ -211,36 +211,21 @@ namespace KDEConnectIndicator {
message (e.message);
}
}
public bool is_paired () {
try {
var return_variant = conn.call_sync (
"org.kde.kdeconnect",
path,
"org.kde.kdeconnect.device",
"isPaired",
null,
null,
DBusCallFlags.NONE,
-1,
null
);
Variant i = return_variant.get_child_value (0);
if (i!=null)
return i.get_boolean ();
} catch (Error e) {
message (e.message);
}
return false;
public bool is_paired {
get {
Variant return_variant=device_proxy.get_cached_property ("isPaired");
if (return_variant!=null)
return return_variant.get_boolean ();
return false; // default to false if something went wrong
}
}
public bool is_reachable () {
try {
Variant return_variant=device_proxy.get_cached_property ("isReachable");
if (return_variant!=null)
return return_variant.get_boolean ();
} catch (Error e) {
message (e.message);
}
return false;
public bool is_reachable {
get {
Variant return_variant=device_proxy.get_cached_property ("isReachable");
if (return_variant!=null)
return return_variant.get_boolean ();
return false; // default to false if something went wrong
}
}
public bool is_charging () {
if (!has_plugin ("kdeconnect_battery"))
Expand Down
18 changes: 9 additions & 9 deletions src/DeviceIndicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace KDEConnectIndicator {

indicator = new AppIndicator.Indicator (
path,
device.icon_name + "-symbolic",
device.icon_name,
AppIndicator.IndicatorCategory.HARDWARE);

name_item = new Gtk.MenuItem ();
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace KDEConnectIndicator {
}

private void update_visibility () {
if (!device.is_reachable ())
if (!device.is_reachable)
indicator.set_status (AppIndicator.IndicatorStatus.PASSIVE);
else
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
Expand All @@ -126,31 +126,31 @@ namespace KDEConnectIndicator {
name_item.label = device.name;
}
private void update_battery_item () {
battery_item.visible = device.is_paired ()
&& device.is_reachable ()
battery_item.visible = device.is_paired
&& device.is_reachable
&& device.has_plugin ("kdeconnect_battery");
this.battery_item.label = "Battery : %d%%".printf(device.battery);
if (device.is_charging ())
this.battery_item.label += " (charging)";
}
private void update_status_item () {

if (device.is_reachable ()) {
if (device.is_paired ())
if (device.is_reachable) {
if (device.is_paired)
this.status_item.label = "Device Reachable and Paired";
else
this.status_item.label = "Device Reachable but Not Paired";
} else {
if (device.is_paired ())
if (device.is_paired)
this.status_item.label = "Device Paired but not Reachable";
else
// is this even posible?
this.status_item.label = "Device Not Reachable and Not Paired";
}
}
private void update_pair_item () {
var paired = device.is_paired ();
var reachable = device.is_reachable ();
var paired = device.is_paired;
var reachable = device.is_reachable;
pair_item.visible = !paired;
unpair_item.visible = paired;

Expand Down
2 changes: 1 addition & 1 deletion src/contractor/Contractor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace KDEConnectIndicator {
var device_list = new SList<Device> ();
foreach (string id in id_list) {
var d = new Device ("/modules/kdeconnect/devices/"+id);
if (d.is_reachable () && d.is_paired ()) {
if (d.is_reachable && d.is_paired) {
device_list.append (d);
Gtk.TreeIter iter;
list_store.append (out iter);
Expand Down

0 comments on commit 37c2221

Please sign in to comment.