Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Add Option to show device paths instead of broswe
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajoja committed Nov 10, 2017
1 parent 86add05 commit 8f25e9e
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 73 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions data/settings/com.bajoja.indicator-kdeconnect.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
</description>
</key>

<key name="list-device-dir" type="b">
<default>false</default>
<summary>Show directory list</summary>
<description>
Show directory list of the device
</description>
</key>

</schema>
</schemalist>
88 changes: 71 additions & 17 deletions src/Device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -498,6 +518,40 @@ namespace KDEConnectIndicator {
}
}

public HashTable<string, string> 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<string, string> directories = new HashTable<string, string> (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<string, string> (str_hash, str_equal);;
}

private bool open_file (string path) {
var file = File.new_for_path (path);
try {
Expand Down
68 changes: 54 additions & 14 deletions src/DeviceIndicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,8 @@ namespace KDEConnectIndicator {
private Gtk.SeparatorMenuItem separator;
private Gtk.SeparatorMenuItem separator2;
private Gtk.SeparatorMenuItem separator3;
private SList<Gtk.MenuItem> browse_items;
private Queue<string> path_directories;

public DeviceIndicator (string path) {
this.path = path;
Expand All @@ -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<Gtk.MenuItem> ();

HashTable<string, string> directories = device.get_directories();
path_directories = new Queue<string> ();

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 ();
Expand All @@ -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,
Expand Down Expand Up @@ -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)"),
Expand All @@ -122,9 +154,9 @@ namespace KDEConnectIndicator {
if (chooser.run () == Gtk.ResponseType.OK) {
SList<string> urls = chooser.get_uris ();

foreach (var url in urls) {
device.send_file (url);
}
urls.@foreach ((item) => {
device.send_file(item);
});
}
chooser.close ();
});
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ namespace KDEConnectIndicator{
files.append (file);
}

if (files.length () == 0){

}
else{
if (files.length () > 0)
activate ();
}
}

private void create_window (){
Expand Down Expand Up @@ -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 ());
}
Expand Down
55 changes: 20 additions & 35 deletions src/settings/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -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: "));
Expand Down

0 comments on commit 8f25e9e

Please sign in to comment.