diff --git a/data/dbus-send.sh b/data/dbus-send.sh new file mode 100644 index 0000000000000000000000000000000000000000..564ae296260742f38f772fcd7565d6b37ea48a6d --- /dev/null +++ b/data/dbus-send.sh @@ -0,0 +1,19 @@ +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 diff --git a/data/send-to.contract b/data/send-to.contract deleted file mode 100644 index eb70e9a494ddf04f930cef61812dc8f85db59442..0000000000000000000000000000000000000000 --- a/data/send-to.contract +++ /dev/null @@ -1,5 +0,0 @@ -[Contractor Entry] -Name=Send to {DEVICE_NAME} -Description=Send this file to {DEVICE_NAME} -MimeType=!inode; -Exec=dbus-send diff --git a/src/EOSConnect/Contractor.vala b/src/EOSConnect/Contractor.vala index 4dbc0c8e2245e487df0f8941969e5ffe513a4291..cc0d340fdd3abf193bd250251649313d0447c90e 100644 --- a/src/EOSConnect/Contractor.vala +++ b/src/EOSConnect/Contractor.vala @@ -38,15 +38,24 @@ namespace EOSConnect { debug ("Creating contract : %s", contract_file); File file = File.new_for_path (contract_file); + if (file.query_exists () == true) { + file.delete (); + } + try { FileOutputStream os = file.create (FileCreateFlags.PRIVATE); string str_name="Name=Send 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 (str_name.data); os.write (str_desc.data); os.write ("MimeType=!inode;\n".data); - os.write ("Exec=dbus-send\n".data); + os.write (str_command.data); } catch (Error e) { warning ("Unable to create contract file: %s\n", e.message); } diff --git a/src/EOSConnect/EOSConnect.vala b/src/EOSConnect/EOSConnect.vala index 92e783da1da985600c56747c5bd22b92fb85f875..8500ac618252ffa2f9bb6509602a372edd8e3e6b 100644 --- a/src/EOSConnect/EOSConnect.vala +++ b/src/EOSConnect/EOSConnect.vala @@ -160,20 +160,27 @@ namespace EOSConnect { foreach (var device_entry in devices_map.entries) { bool to_add = true; + bool to_remove = false; - if (device_entry.value.is_paired == false) { - to_add = false; + if (device_entry.value.is_paired == false || device_entry.value.is_active == false) { + to_remove = true; } + foreach (var device_menuitem in launcher_entry.quicklist.get_children ()) { if (((DeviceMenuitem)device_menuitem).id == device_entry.value.device_num) { ((DeviceMenuitem)device_menuitem).update_ui (); 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 ( new DeviceMenuitem.with_device (device_entry.value, main_window)); } diff --git a/src/EOSConnect/Plugin/Share.vala b/src/EOSConnect/Plugin/Share.vala index 60fc2731fc90b2b185952ae56642a06c6fb95269..98a8135750284683d513ac8c77f47c431e6dee22 100644 --- a/src/EOSConnect/Plugin/Share.vala +++ b/src/EOSConnect/Plugin/Share.vala @@ -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 ( "Select your favorite file", parent_window, Gtk.FileChooserAction.OPEN, "_Cancel", Gtk.ResponseType.CANCEL, @@ -57,30 +57,34 @@ namespace EOSConnect.Plugin { if (chooser.run () == Gtk.ResponseType.ACCEPT) { - SList uris = chooser.get_uris (); - ShareFileInfoProgress file_info_progress = new ShareFileInfoProgress (uris, parent_window); - file_info_progress.show_all (); - - int current_file_num = 0; - foreach (unowned string uri in uris) { - try { - UploadTransfer upload_transfer; - - ((ShareHandler)device.get_path_capability_handler (ShareHandler.SHARE)) - .share_file (device, uri, ++current_file_num, out upload_transfer); - - // TOCHECK - potential memory leak here ? - upload_transfer.progress.connect ((progress_percentage, file_num, file_uri) => { - file_info_progress.update_progress (--file_num, progress_percentage); - }); - } catch (Error e) { - file_info_progress.destroy (); - warning ("Error: %s", e.message); - } - } + send_files (device, chooser.get_uris ()); } chooser.close (); } + + public void send_files (Device device, SList uris) { + + ShareFileInfoProgress file_info_progress = new ShareFileInfoProgress (uris, parent_window); + file_info_progress.show_all (); + + int current_file_num = 0; + foreach (unowned string uri in uris) { + try { + UploadTransfer upload_transfer; + + ((ShareHandler)device.get_path_capability_handler (ShareHandler.SHARE)) + .share_file (device, uri, ++current_file_num, out upload_transfer); + + // TOCHECK - potential memory leak here ? + upload_transfer.progress.connect ((progress_percentage, file_num, file_uri) => { + file_info_progress.update_progress (--file_num, progress_percentage); + }); + } catch (Error e) { + file_info_progress.destroy (); + warning ("Error: %s", e.message); + } + } + } } } diff --git a/src/EOSConnect/Widgets/DeviceMenuitem.vala b/src/EOSConnect/Widgets/DeviceMenuitem.vala index bca57a87040fff930b6a9c86d8e6ff137d797a14..dc181e8b9b07724c726818a5d4619953785543e0 100644 --- a/src/EOSConnect/Widgets/DeviceMenuitem.vala +++ b/src/EOSConnect/Widgets/DeviceMenuitem.vala @@ -102,7 +102,7 @@ namespace EOSConnect.Widgets { if (sub_menu_item_share == null) { sub_menu_item_share = new Dbusmenu.Menuitem.with_id (id + SUB_MENU_SHARE_ID); 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); EOSConnect.Contractor.create_contract (device); diff --git a/src/MConnect/MConnectThread.vala b/src/MConnect/MConnectThread.vala index fa2c3a539b130c8614f8f0d4d82bfa4b479a7375..6c549218ddb353624f74cdfffbe2b7a11373d533 100644 --- a/src/MConnect/MConnectThread.vala +++ b/src/MConnect/MConnectThread.vala @@ -91,6 +91,12 @@ namespace MConnect { 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 (); } catch (Error e) { warning ("Error: %s\n", e.message); @@ -99,6 +105,15 @@ namespace MConnect { 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 () { Process.exit (0); } diff --git a/src/MConnect/ShareHandlerProxy.vala b/src/MConnect/ShareHandlerProxy.vala new file mode 100644 index 0000000000000000000000000000000000000000..09f3aace879a5674b0e8c9ad6fd3099b766ebcb7 --- /dev/null +++ b/src/MConnect/ShareHandlerProxy.vala @@ -0,0 +1,56 @@ +/** + * 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 + */ + +using EOSConnect.Plugin; +using Gee; +using MConnect; + +[DBus (name = "com.github.gyan000.eosconnect.Share")] +class ShareHandlerProxy : Object { + + // private HashMap devices_map; + // + // public ShareHandlerProxy (HashMap 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 files_to_send = new SList (); + + 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 +} diff --git a/src/meson.build b/src/meson.build index 2b85038843b330122d1cb44e304d62fa4c77ceb6..466b4e77892d043983e148fb044eec18179115c3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -65,6 +65,7 @@ all_files = files( 'MConnect/PacketHandlers.vala', 'MConnect/PingHandler.vala', 'MConnect/ShareHandler.vala', + 'MConnect/ShareHandlerProxy.vala', 'MConnect/TelephonyHandler.vala', 'MConnect/TransferInterface.vala', 'MConnect/TransferManager.vala',