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

* create user contract file by device.

* delete cotnract files when application close.
parent 8700d8dd
Branches no_submodule
No related tags found
No related merge requests found
[Contractor Entry]
Name=Send to {DEVICE_NAME}
Description=Send this file to {DEVICE_NAME}
MimeType=!inode;
Exec=dbus-send
/**
* 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 MConnect;
namespace EOSConnect {
public class Contractor {
public static string get_contract_dir () {
return Path.build_filename (Environment.get_home_dir (), ".local", "share", "contractor");
}
public static string create_if_not_exists_contract_dir () {
if (File.new_for_path(Contractor.get_contract_dir ()).query_exists () == false) {
DirUtils.create (Contractor.get_contract_dir (), 0700);
}
return Contractor.get_contract_dir ();
}
public static void create_contract(Device device) {
var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract");
debug ("Creating contract : %s", contract_file);
File file = File.new_for_path (contract_file);
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";
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);
} catch (Error e) {
warning ("Unable to create contract file: %s\n", e.message);
}
}
public static void destroy_contract(Device device) {
var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract");
File file = File.new_for_path (contract_file);
if (file.query_exists ()) {
debug ("Deleting contract : %s", contract_file);
file.delete ();
}
}
}
}
......@@ -65,6 +65,9 @@ namespace EOSConnect {
main_window.delete_event.connect ((event) => {
// When from launcher menu is clicked.
if (event.send_event == (int8)0) {
foreach (var device_entry in devices_map.entries) {
Contractor.destroy_contract (device_entry.value);
}
main_window.destroy ();
} else { // When close button from the main window is clicked.
main_window.iconify ();
......@@ -107,6 +110,8 @@ namespace EOSConnect {
error ("Cannot run without thread support.\n");
}
message ("Report any issues/bugs you might find to https://github.com/gyan000/EOSConnect/issues");
var application = new App ();
return application.run (args);
}
......
......@@ -46,7 +46,6 @@ namespace EOSConnect {
set_default_size (900, 600);
set_size_request (750, 500);
}
construct {
var theme_button = new Gtk.Button.from_icon_name ("object-inverse");
......
......@@ -105,6 +105,7 @@ namespace EOSConnect.Widgets {
((Share)device.get_plugin (ShareHandler.SHARE_PKT)).send_files (device);
});
child_append (sub_menu_item_share);
EOSConnect.Contractor.create_contract (device);
}
sub_menu_item_share.property_set (Dbusmenu.MENUITEM_PROP_ICON_NAME, "send-to");
......@@ -113,6 +114,7 @@ namespace EOSConnect.Widgets {
if (sub_menu_item_share != null) {
child_delete (sub_menu_item_share);
sub_menu_item_share = null;
EOSConnect.Contractor.destroy_contract (device);
}
}
}
......
......@@ -2,6 +2,7 @@ all_files = files(
'EOSConnect/Config.vala',
'EOSConnect/Contact.vala',
'EOSConnect/ContactsInterface.vala',
'EOSConnect/Contractor.vala',
'EOSConnect/EContacts.vala',
'EOSConnect/EOSConnect.vala',
'EOSConnect/DebugToolbar.vala',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment