diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1376099..57dd6f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,7 +73,7 @@ install (TARGETS ${INDICATOR_EXEC} RUNTIME DESTINATION bin)
# contractor binary
set (CONTRACTOR_EXEC "kdeconnect-send")
vala_precompile(VALA_C ${CONTRACTOR_EXEC}
- src/contractor/Contractor.vala
+ src/contractor/KDEConnectSend.vala
src/Device.vala
PACKAGES
gtk+-3.0
diff --git a/data/settings/com.bajoja.indicator-kdeconnect.gschema.xml b/data/settings/com.bajoja.indicator-kdeconnect.gschema.xml
index 95586fa..4ae5c6a 100644
--- a/data/settings/com.bajoja.indicator-kdeconnect.gschema.xml
+++ b/data/settings/com.bajoja.indicator-kdeconnect.gschema.xml
@@ -17,5 +17,13 @@
+
+ false
+ Show directory list
+
+ Show directory list of the device
+
+
+
diff --git a/src/Device.vala b/src/Device.vala
index 07ff89a..d5cd271 100644
--- a/src/Device.vala
+++ b/src/Device.vala
@@ -109,6 +109,12 @@ namespace KDEConnectIndicator {
}
}
+ public bool to_list_dir{
+ get {
+ return this.settings.get_boolean ("list-device-dir");
+ }
+ }
+
public Device (string path) {
message ("device : %s",path);
this.path = path;
@@ -397,15 +403,15 @@ namespace KDEConnectIndicator {
}
}
- public void browse () {
+ public void browse (string open_path="") {
if (!has_plugin ("kdeconnect_sftp"))
return;
if (is_mounted ())
- open_file (mount_point);
+ open_file (open_path.length == 0 ? mount_point : open_path);
else {
mount();
Timeout.add (1000, ()=> { // idle for a few second to let sftp kickin
- open_file (mount_point);
+ open_file (open_path.length == 0 ? mount_point : open_path);
return false;
});
}
@@ -454,25 +460,39 @@ namespace KDEConnectIndicator {
} catch (Error e) {
message (e.message);
}
- return ""; //TODO : maybe return /home/vikoadi/.kde/share/apps/kdeconnect/
+ return "";
}
}
-
- public void mount () {
+
+ public void mount (bool mount_and_wait=false) {
try {
if (!has_plugin ("kdeconnect_sftp"))
return;
- conn.call_sync (
- "org.kde.kdeconnect",
- path+"/sftp",
- "org.kde.kdeconnect.device.sftp",
- "mount",
- null,
- null,
- DBusCallFlags.NONE,
- -1,
- null
- );
+
+ if (mount_and_wait)
+ conn.call_sync (
+ "org.kde.kdeconnect",
+ path+"/sftp",
+ "org.kde.kdeconnect.device.sftp",
+ "mountAndWait",
+ null,
+ null,
+ DBusCallFlags.NONE,
+ -1,
+ null
+ );
+ else
+ conn.call_sync (
+ "org.kde.kdeconnect",
+ path+"/sftp",
+ "org.kde.kdeconnect.device.sftp",
+ "mount",
+ null,
+ null,
+ DBusCallFlags.NONE,
+ -1,
+ null
+ );
} catch (Error e) {
message (e.message);
}
@@ -498,6 +518,40 @@ namespace KDEConnectIndicator {
}
}
+ public HashTable get_directories () {
+ try {
+ var return_variant = conn.call_sync (
+ "org.kde.kdeconnect",
+ path+"/sftp",
+ "org.kde.kdeconnect.device.sftp",
+ "getDirectories",
+ null,
+ null,
+ DBusCallFlags.NONE,
+ -1,
+ null
+ );
+
+ HashTable directories = new HashTable (str_hash, str_equal);
+
+ Variant variant = return_variant.get_child_value (0);
+ VariantIter iter = variant.iterator ();
+
+ Variant? val = null;
+ string? key = null;
+
+ while (iter.next ("{sv}", &key, &val)) {
+ directories.insert (key, val.dup_string ());
+ }
+
+ return directories;
+
+ } catch (Error e) {
+ message (e.message);
+ }
+ return new HashTable (str_hash, str_equal);;
+ }
+
private bool open_file (string path) {
var file = File.new_for_path (path);
try {
diff --git a/src/DeviceIndicator.vala b/src/DeviceIndicator.vala
index 17f2698..47a47ca 100644
--- a/src/DeviceIndicator.vala
+++ b/src/DeviceIndicator.vala
@@ -13,6 +13,7 @@ namespace KDEConnectIndicator {
private Gtk.MenuItem battery_item;
private Gtk.MenuItem status_item;
private Gtk.MenuItem browse_item;
+ private Gtk.Menu browse_submenu;
private Gtk.MenuItem send_item;
private Gtk.MenuItem ring_item;
private Gtk.MenuItem pair_item;
@@ -21,6 +22,8 @@ namespace KDEConnectIndicator {
private Gtk.SeparatorMenuItem separator;
private Gtk.SeparatorMenuItem separator2;
private Gtk.SeparatorMenuItem separator3;
+ private SList browse_items;
+ private Queue path_directories;
public DeviceIndicator (string path) {
this.path = path;
@@ -38,8 +41,33 @@ namespace KDEConnectIndicator {
status_item = new Gtk.MenuItem ();
menu.append (status_item);
menu.append (new Gtk.SeparatorMenuItem ());
+
browse_item = new Gtk.MenuItem.with_label (_("Browse device"));
menu.append (browse_item);
+
+ if (device.to_list_dir) {
+ device.mount(true);
+
+ if (device.get_directories().size () > 0) {
+ browse_submenu = new Gtk.Menu ();
+ browse_item.set_submenu (browse_submenu);
+
+ browse_items = new SList ();
+
+ HashTable directories = device.get_directories();
+ path_directories = new Queue ();
+
+ directories.@foreach ((key, val) => {
+ path_directories.push_tail (key);
+ browse_items.append (new Gtk.MenuItem.with_label (val));
+ });
+
+ browse_items.@foreach ((item) => {
+ browse_submenu.append (item);
+ });
+ }
+ }
+
send_item = new Gtk.MenuItem.with_label (_("Send file(s)"));
menu.append (send_item);
separator = new Gtk.SeparatorMenuItem ();
@@ -59,14 +87,6 @@ namespace KDEConnectIndicator {
menu.show_all ();
- update_visibility ();
- update_name_item ();
- update_battery_item ();
- update_status_item ();
- update_pair_item ();
-
- indicator.set_menu (menu);
-
name_item.activate.connect (() => {
var msg = new Gtk.MessageDialog.with_markup (null,
Gtk.DialogFlags.MODAL,
@@ -105,9 +125,21 @@ namespace KDEConnectIndicator {
}
});
- browse_item.activate.connect (() => {
- device.browse ();
- });
+ if (device.to_list_dir) {
+ if (device.get_directories().size () > 0) {
+ browse_items.@foreach ((item) => {
+ item.activate.connect (() => {
+ device.browse (path_directories.pop_head ());
+ });
+ });
+ }
+ }
+ else {
+ browse_item.activate.connect (() => {
+ device.mount(true);
+ device.browse ();
+ });
+ }
send_item.activate.connect (() => {
var chooser = new Gtk.FileChooserDialog (_("Select file(s)"),
@@ -122,9 +154,9 @@ namespace KDEConnectIndicator {
if (chooser.run () == Gtk.ResponseType.OK) {
SList urls = chooser.get_uris ();
- foreach (var url in urls) {
- device.send_file (url);
- }
+ urls.@foreach ((item) => {
+ device.send_file(item);
+ });
}
chooser.close ();
});
@@ -192,6 +224,14 @@ namespace KDEConnectIndicator {
update_battery_item ();
update_icon_item ();
});
+
+ update_visibility ();
+ update_name_item ();
+ update_battery_item ();
+ update_status_item ();
+ update_pair_item ();
+
+ indicator.set_menu (menu);
}
public void device_visibility_changed (bool visible) {
diff --git a/src/contractor/Contractor.vala b/src/contractor/KDEConnectSend.vala
similarity index 98%
rename from src/contractor/Contractor.vala
rename to src/contractor/KDEConnectSend.vala
index a33fab5..c930500 100755
--- a/src/contractor/Contractor.vala
+++ b/src/contractor/KDEConnectSend.vala
@@ -61,12 +61,8 @@ namespace KDEConnectIndicator{
files.append (file);
}
- if (files.length () == 0){
-
- }
- else{
+ if (files.length () > 0)
activate ();
- }
}
private void create_window (){
@@ -218,7 +214,7 @@ namespace KDEConnectIndicator{
foreach (File file in files){
foreach (int selected in selected_devs){
Device selected_dev = this.device_list.
- nth_data (selected);
+ nth_data (selected);
selected_dev.send_file (file.get_uri ());
}
diff --git a/src/settings/Settings.vala b/src/settings/Settings.vala
index 9836d7c..78a6c4a 100644
--- a/src/settings/Settings.vala
+++ b/src/settings/Settings.vala
@@ -52,9 +52,7 @@ namespace KDEConnectIndicator {
this.stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
this.stack.add_titled(create_visibility_setts (), "visibility", _("Visibility"));
- // Will be Deprecate on 1.0
- //this.stack.add_titled (create_icons_setts (), "icons", _("Icons"));
-
+
this.stack.add_titled (create_sms_setts (), "sms", _("SMS"));
this.stack_switcher = new StackSwitcher ();
@@ -154,62 +152,49 @@ namespace KDEConnectIndicator {
settings.set_boolean ("visibilitiy", switch1.active);
});
-
- ListBox list_box = new ListBox ();
- list_box.set_selection_mode (Gtk.SelectionMode.NONE);
-
Box hbox1 = new Box (Gtk.Orientation.HORIZONTAL, 50);
- ListBoxRow boxrow1 = new ListBoxRow ();
-
- boxrow1.add (hbox1);
-
hbox1.pack_start (label1, true, true, 0);
hbox1.pack_start (switch1, true, true, 0);
- list_box.add (boxrow1);
+ ListBoxRow boxrow1 = new ListBoxRow ();
- Box vbox = new Box (Gtk.Orientation.HORIZONTAL, 0);
- vbox.pack_start (list_box, true, true, 0);
+ boxrow1.add (hbox1);
- return vbox;
- }
-
- /*
- private Box create_icons_setts () {
- Label label1 = new Label (_("Show custom icons for Elementary OS: "));
+ //----------------------------------------------------//
+
+ Label label2 = new Label (_("Show device directories: "));
Switch switch2 = new Switch ();
- switch2.set_active (settings.get_string ("icons")!="");
+ switch2.set_active (settings.get_boolean ("list-device-dir"));
switch2.notify["active"].connect (() => {
- if (switch2.active) {
- settings.set_string ("icons", "-symbolic");
- } else {
- settings.set_string ("icons", "");
- }
+ settings.set_boolean ("list-device-dir", switch2.active);
});
- ListBox list_box = new ListBox ();
- list_box.set_selection_mode (Gtk.SelectionMode.NONE);
+ Box hbox2 = new Box (Gtk.Orientation.HORIZONTAL, 50);
- Box hbox1 = new Box (Gtk.Orientation.HORIZONTAL, 50);
+ hbox2.pack_start (label2, true, true, 0);
+ hbox2.pack_start (switch2, true, true, 0);
- ListBoxRow boxrow1 = new ListBoxRow ();
+ ListBoxRow boxrow2 = new ListBoxRow ();
- boxrow1.add (hbox1);
+ boxrow2.add (hbox2);
+
+ //----------------------------------------------------//
+
+ ListBox list_box = new ListBox ();
+ list_box.set_selection_mode (Gtk.SelectionMode.NONE);
- hbox1.pack_start (label1, true, true, 0);
- hbox1.pack_start (switch2, true, true, 0);
list_box.add (boxrow1);
+ list_box.add (boxrow2);
Box vbox = new Box (Gtk.Orientation.HORIZONTAL, 0);
vbox.pack_start (list_box, true, true, 0);
return vbox;
- }
- */
+ }
private Box create_sms_setts () {
Label label1 = new Label (_("Delete Google Contacts: "));