Skip to content
Snippets Groups Projects
Commit fb438251 authored by gyan000's avatar gyan000
Browse files

GH-2 - implement dbus service to share file(s) to device from Files.

* now can send one or multiple files with context menu from Files.
* if device is not connected, it does not appears anymore in dock's 
quicklist neither in File's context menu.
parent 29b3212e
No related branches found
No related tags found
No related merge requests found
dbus-send --print-reply --dest=com.github.gyan000.eos-connect \
/com/github/gyan000/eosconnect/share \
com.github.gyan000.eosconnect.Share.Files \
string:'fffefc6422d1dda0' \
string:'/home/gyan000e/send-to.jpeg /home/gyan000e/k-yuko-contacts.csv'
dbus-send --dest=org.freedesktop.ExampleName \
/org/freedesktop/sample/object/name \
org.freedesktop.ExampleInterface.ExampleMethod \
int32:47 string:'hello world' double:65.32 \
array:string:"1st item","next item","last item" \
dict:string:int32:"one",1,"two",2,"three",3 \
variant:int32:-8 \
objpath:/org/freedesktop/sample/object/name
[Contractor Entry]
Name=Send to {DEVICE_NAME}
Description=Send this file to {DEVICE_NAME}
MimeType=!inode;
Exec=dbus-send
...@@ -38,15 +38,24 @@ namespace EOSConnect { ...@@ -38,15 +38,24 @@ namespace EOSConnect {
debug ("Creating contract : %s", contract_file); debug ("Creating contract : %s", contract_file);
File file = File.new_for_path (contract_file); File file = File.new_for_path (contract_file);
if (file.query_exists () == true) {
file.delete ();
}
try { try {
FileOutputStream os = file.create (FileCreateFlags.PRIVATE); FileOutputStream os = file.create (FileCreateFlags.PRIVATE);
string str_name="Name=Send to " + device.custom_name + "\n"; string str_name="Name=Send to " + device.custom_name + "\n";
string str_desc="Description=Send this file to " + device.custom_name + "\n"; string str_desc="Description=Send this file to " + device.custom_name + "\n";
// TOCHEK find out why without --print-reply it's not working.
string str_command ="Exec=dbus-send --print-reply --dest=com.github.gyan000.eos-connect ";
str_command += "/com/github/gyan000/eosconnect/share ";
str_command += "com.github.gyan000.eosconnect.Share.Files ";
str_command += "string:'" + device.id + "' string:'%F'\n";
os.write ("[Contractor Entry]\n".data); os.write ("[Contractor Entry]\n".data);
os.write (str_name.data); os.write (str_name.data);
os.write (str_desc.data); os.write (str_desc.data);
os.write ("MimeType=!inode;\n".data); os.write ("MimeType=!inode;\n".data);
os.write ("Exec=dbus-send\n".data); os.write (str_command.data);
} catch (Error e) { } catch (Error e) {
warning ("Unable to create contract file: %s\n", e.message); warning ("Unable to create contract file: %s\n", e.message);
} }
......
...@@ -160,20 +160,27 @@ namespace EOSConnect { ...@@ -160,20 +160,27 @@ namespace EOSConnect {
foreach (var device_entry in devices_map.entries) { foreach (var device_entry in devices_map.entries) {
bool to_add = true; bool to_add = true;
bool to_remove = false;
if (device_entry.value.is_paired == false) { if (device_entry.value.is_paired == false || device_entry.value.is_active == false) {
to_add = false; to_remove = true;
} }
foreach (var device_menuitem in launcher_entry.quicklist.get_children ()) { foreach (var device_menuitem in launcher_entry.quicklist.get_children ()) {
if (((DeviceMenuitem)device_menuitem).id == device_entry.value.device_num) { if (((DeviceMenuitem)device_menuitem).id == device_entry.value.device_num) {
((DeviceMenuitem)device_menuitem).update_ui (); ((DeviceMenuitem)device_menuitem).update_ui ();
to_add = false; to_add = false;
if (to_remove == true) {
launcher_entry.quicklist.child_delete (device_menuitem);
Contractor.destroy_contract (device_entry.value);
}
} }
} }
if (to_add == true) { if (to_add == true && to_remove == false) {
launcher_entry.quicklist.child_append ( launcher_entry.quicklist.child_append (
new DeviceMenuitem.with_device (device_entry.value, main_window)); new DeviceMenuitem.with_device (device_entry.value, main_window));
} }
......
...@@ -47,7 +47,7 @@ namespace EOSConnect.Plugin { ...@@ -47,7 +47,7 @@ namespace EOSConnect.Plugin {
} }
} }
public void send_files (Device device) { public void select_files (Device device) {
Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ( Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
"Select your favorite file", parent_window, Gtk.FileChooserAction.OPEN, "Select your favorite file", parent_window, Gtk.FileChooserAction.OPEN,
"_Cancel", Gtk.ResponseType.CANCEL, "_Cancel", Gtk.ResponseType.CANCEL,
...@@ -57,7 +57,14 @@ namespace EOSConnect.Plugin { ...@@ -57,7 +57,14 @@ namespace EOSConnect.Plugin {
if (chooser.run () == Gtk.ResponseType.ACCEPT) { if (chooser.run () == Gtk.ResponseType.ACCEPT) {
SList<string> uris = chooser.get_uris (); send_files (device, chooser.get_uris ());
}
chooser.close ();
}
public void send_files (Device device, SList<string> uris) {
ShareFileInfoProgress file_info_progress = new ShareFileInfoProgress (uris, parent_window); ShareFileInfoProgress file_info_progress = new ShareFileInfoProgress (uris, parent_window);
file_info_progress.show_all (); file_info_progress.show_all ();
...@@ -79,8 +86,5 @@ namespace EOSConnect.Plugin { ...@@ -79,8 +86,5 @@ namespace EOSConnect.Plugin {
} }
} }
} }
chooser.close ();
}
} }
} }
...@@ -102,7 +102,7 @@ namespace EOSConnect.Widgets { ...@@ -102,7 +102,7 @@ namespace EOSConnect.Widgets {
if (sub_menu_item_share == null) { if (sub_menu_item_share == null) {
sub_menu_item_share = new Dbusmenu.Menuitem.with_id (id + SUB_MENU_SHARE_ID); sub_menu_item_share = new Dbusmenu.Menuitem.with_id (id + SUB_MENU_SHARE_ID);
sub_menu_item_share.item_activated.connect (() => { sub_menu_item_share.item_activated.connect (() => {
((Share)device.get_plugin (ShareHandler.SHARE_PKT)).send_files (device); ((Share)device.get_plugin (ShareHandler.SHARE_PKT)).select_files (device);
}); });
child_append (sub_menu_item_share); child_append (sub_menu_item_share);
EOSConnect.Contractor.create_contract (device); EOSConnect.Contractor.create_contract (device);
......
...@@ -91,6 +91,12 @@ namespace MConnect { ...@@ -91,6 +91,12 @@ namespace MConnect {
discovery.listen (); discovery.listen ();
Bus.own_name (BusType.SESSION, "com.github.gyan000.eos-connect", BusNameOwnerFlags.NONE,
on_bus_aquired,
() => {},
() => stderr.printf ("Could not aquire name\n"));
loop.run (); loop.run ();
} catch (Error e) { } catch (Error e) {
warning ("Error: %s\n", e.message); warning ("Error: %s\n", e.message);
...@@ -99,6 +105,15 @@ namespace MConnect { ...@@ -99,6 +105,15 @@ namespace MConnect {
return 0; return 0;
} }
public void on_bus_aquired (DBusConnection conn) {
try {
// Share service.
conn.register_object ("/com/github/gyan000/eosconnect/share", new ShareHandlerProxy ());
} catch (IOError e) {
warning ("Could not register service.\n");
}
}
public void shutdown () { public void shutdown () {
Process.exit (0); Process.exit (0);
} }
......
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* gyan000 <gyan000 (at] ijaz.fr>
*/
using EOSConnect.Plugin;
using Gee;
using MConnect;
[DBus (name = "com.github.gyan000.eosconnect.Share")]
class ShareHandlerProxy : Object {
// private HashMap<string, Device> devices_map;
//
// public ShareHandlerProxy (HashMap<string, Device> devices_map) {
// this.devices_map = devices_map;
// }
public void files (string device_id, string pathnames) throws IOError {
bool device_available = false;
foreach (var entry in Core.instance ().devices_map.entries) {
if (entry.value.id == device_id &&
entry.value.is_active == true) {
SList<string> files_to_send = new SList<string> ();
debug ("Device ID: %s (%s)", device_id, entry.value.custom_name);
foreach (unowned string pathname in pathnames.split (" ")) {
files_to_send.append (File.new_for_path (pathname).get_uri ());
}
((Share)entry.value.get_plugin (ShareHandler.SHARE_PKT)).send_files (entry.value, files_to_send);
}
}
}
}
[DBus (name = "com.github.gyan000.eosconnect.ShareError")]
public errordomain ShareError {
SOME_ERROR
}
...@@ -65,6 +65,7 @@ all_files = files( ...@@ -65,6 +65,7 @@ all_files = files(
'MConnect/PacketHandlers.vala', 'MConnect/PacketHandlers.vala',
'MConnect/PingHandler.vala', 'MConnect/PingHandler.vala',
'MConnect/ShareHandler.vala', 'MConnect/ShareHandler.vala',
'MConnect/ShareHandlerProxy.vala',
'MConnect/TelephonyHandler.vala', 'MConnect/TelephonyHandler.vala',
'MConnect/TransferInterface.vala', 'MConnect/TransferInterface.vala',
'MConnect/TransferManager.vala', 'MConnect/TransferManager.vala',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment