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

GH-2 - delete contract files at startup.

And some cleanup.
parent 9312067d
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
...@@ -33,7 +33,24 @@ namespace EOSConnect { ...@@ -33,7 +33,24 @@ namespace EOSConnect {
return Contractor.get_contract_dir (); return Contractor.get_contract_dir ();
} }
public async static void clean_contractor_directory () {
try {
File directory = File.new_for_path (get_contract_dir ());
FileEnumerator enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
FileInfo file_info, iterated_file_info;
File iterated_file;
while ((file_info = enumerator.next_file ()) != null) {
enumerator.iterate (out iterated_file_info, out iterated_file);
debug ("Deleting %s", iterated_file_info.get_name ());
iterated_file.delete ();
}
} catch (Error e) {
warning ("Error: %s\n", e.message);
}
}
public static void create_contract(Device device) { public static void create_contract(Device device) {
try {
var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract"); var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract");
debug ("Creating contract : %s", contract_file); debug ("Creating contract : %s", contract_file);
...@@ -42,7 +59,7 @@ namespace EOSConnect { ...@@ -42,7 +59,7 @@ namespace EOSConnect {
file.delete (); file.delete ();
} }
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";
...@@ -57,17 +74,21 @@ namespace EOSConnect { ...@@ -57,17 +74,21 @@ namespace EOSConnect {
os.write ("MimeType=!inode;\n".data); os.write ("MimeType=!inode;\n".data);
os.write (str_command.data); os.write (str_command.data);
} catch (Error e) { } catch (Error e) {
warning ("Unable to create contract file: %s\n", e.message); warning ("Error: %s\n", e.message);
} }
} }
public static void destroy_contract(Device device) { public static void destroy_contract(Device device) {
try {
var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract"); var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract");
File file = File.new_for_path (contract_file); File file = File.new_for_path (contract_file);
if (file.query_exists ()) { if (file.query_exists ()) {
debug ("Deleting contract : %s", contract_file); debug ("Deleting contract : %s", contract_file);
file.delete (); file.delete ();
} }
} catch (Error e) {
warning ("Error: %s\n", e.message);
}
} }
} }
} }
...@@ -50,6 +50,7 @@ namespace EOSConnect { ...@@ -50,6 +50,7 @@ namespace EOSConnect {
public override void activate () public override void activate ()
{ {
Contractor.clean_contractor_directory.begin ();
MConnectThread mconnect_thread = new MConnectThread (this, devices_map, main_settings); MConnectThread mconnect_thread = new MConnectThread (this, devices_map, main_settings);
launcher_entry = LauncherEntry.get_for_desktop_id (GSETTINGS_SCHEMA_ID + ".desktop"); launcher_entry = LauncherEntry.get_for_desktop_id (GSETTINGS_SCHEMA_ID + ".desktop");
......
...@@ -43,8 +43,6 @@ namespace EOSConnect.Plugin.Popover { ...@@ -43,8 +43,6 @@ namespace EOSConnect.Plugin.Popover {
var file_chooser = new Gtk.FileChooserButton (_("Select default download directory"), var file_chooser = new Gtk.FileChooserButton (_("Select default download directory"),
Gtk.FileChooserAction.SELECT_FOLDER); Gtk.FileChooserAction.SELECT_FOLDER);
file_chooser.margin_right = 10;
var directory = device.settings.get_string ("kdeconnect-share-directory"); var directory = device.settings.get_string ("kdeconnect-share-directory");
if (directory.length > 5) { if (directory.length > 5) {
file_chooser.set_uri (directory); file_chooser.set_uri (directory);
......
...@@ -176,28 +176,28 @@ namespace MConnect { ...@@ -176,28 +176,28 @@ namespace MConnect {
} }
private void on_local_notification_closed (Notification notification) { private void on_local_notification_closed (Notification notification) {
try { //try {
print ("\n>>%S\n", notification.id); // print ("\n>>%S\n", notification.id);
// var notification = new Notification.from_message (message, id); // // var notification = new Notification.from_message (message, id);
// Core.instance ().application.withdraw_notification (notification_id); // // Core.instance ().application.withdraw_notification (notification_id);
// if (!notification.get_is_valid () || notification.app_name in Notification.EXCEPTIONS) { // // if (!notification.get_is_valid () || notification.app_name in Notification.EXCEPTIONS) {
// return; // // return;
// } // // }
// // //
// foreach (Device device in Core.instance ().devices_map.values) { // // foreach (Device device in Core.instance ().devices_map.values) {
// if (device.has_capability_handler (NotificationHandler.NOTIFICATION)) { // // if (device.has_capability_handler (NotificationHandler.NOTIFICATION)) {
// NotificationHandler notification_handler = (NotificationHandler)device.get_path_capability_handler( // // NotificationHandler notification_handler = (NotificationHandler)device.get_path_capability_handler(
// NotificationHandler.NOTIFICATION); // // NotificationHandler.NOTIFICATION);
// // //
// notification_handler.send_notification (device, message, id); // // notification_handler.send_notification (device, message, id);
// // }
// // }
//} catch (Error e) {
// warning ("Error: %s", e.message);
//} //}
// }
} catch (Error e) {
warning ("Error: %s", e.message);
}
} }
/** /**
......
...@@ -77,7 +77,8 @@ namespace MConnect { ...@@ -77,7 +77,8 @@ namespace MConnect {
Utils.TlsConnectionMode.CLIENT); Utils.TlsConnectionMode.CLIENT);
debug ("Attempt TLS handshake."); debug ("Attempt TLS handshake.");
var tls_res = yield this.tls_connection.handshake_async (); //var tls_res = yield this.tls_connection.handshake_async ();
yield this.tls_connection.handshake_async ();
debug ("TLS handshake complete."); debug ("TLS handshake complete.");
} catch (Error e) { } catch (Error e) {
......
...@@ -121,7 +121,7 @@ namespace MConnect { ...@@ -121,7 +121,7 @@ namespace MConnect {
return message; return message;
} }
uint32 id = child.get_uint32 (); //uint32 id = child.get_uint32 ();
Idle.add (() => { Idle.add (() => {
return false; return false;
}); });
......
...@@ -40,6 +40,7 @@ namespace MConnect { ...@@ -40,6 +40,7 @@ namespace MConnect {
public uint64 size; public uint64 size;
public uint port; public uint port;
} }
public string pkt_type { public string pkt_type {
get; private set; default = ""; get; private set; default = "";
} }
...@@ -49,9 +50,7 @@ namespace MConnect { ...@@ -49,9 +50,7 @@ namespace MConnect {
public Json.Object body { public Json.Object body {
get; private set; default = null; get; private set; default = null;
} }
public Packet.Payload ? payload { public Packet.Payload ? payload;
get; set; default = null;
}
public Packet (string type, Json.Object body, int64 id = 0) { public Packet (string type, Json.Object body, int64 id = 0) {
this.pkt_type = type; this.pkt_type = type;
......
...@@ -30,9 +30,7 @@ class ShareHandlerProxy : Object { ...@@ -30,9 +30,7 @@ class ShareHandlerProxy : Object {
// } // }
public void files (string device_id, string pathnames) throws IOError { public void files (string device_id, string pathnames) throws IOError {
try {
bool device_available = false;
foreach (var entry in Core.instance ().devices_map.entries) { foreach (var entry in Core.instance ().devices_map.entries) {
if (entry.value.id == device_id && if (entry.value.id == device_id &&
...@@ -47,6 +45,9 @@ class ShareHandlerProxy : Object { ...@@ -47,6 +45,9 @@ class ShareHandlerProxy : Object {
((Share)entry.value.get_plugin (ShareHandler.SHARE_PKT)).send_files (entry.value, files_to_send); ((Share)entry.value.get_plugin (ShareHandler.SHARE_PKT)).send_files (entry.value, files_to_send);
} }
} }
} catch (Error e) {
warning ("Error: %s", e.message);
}
} }
} }
......
...@@ -158,22 +158,22 @@ namespace MConnect { ...@@ -158,22 +158,22 @@ namespace MConnect {
// } // }
} }
public void handle_sms_notification (Device device, Packet pkt) { //public void handle_sms_notification (Device device, Packet pkt) {
debug ("Handling missed SMS from notifiation."); // debug ("Handling missed SMS from notifiation.");
// TOCHECK There's' a "time" field, but, does not seems to be a unix timestamp. And no mention in kdeconnect. // // TOCHECK There's' a "time" field, but, does not seems to be a unix timestamp. And no mention in kdeconnect.
//DateTime glop = new DateTime.from_unix_local (pkt.body.get_string_member ("time").to_int()); // //DateTime glop = new DateTime.from_unix_local (pkt.body.get_string_member ("time").to_int());
//print (">> %s -> %s", pkt.body.get_string_member ("time").to_string (), glop.to_string ()); // //print (">> %s -> %s", pkt.body.get_string_member ("time").to_string (), glop.to_string ());
//return; // //return;
SMSStore.instance ().handle_missed_sms ( // SMSStore.instance ().handle_missed_sms (
device, // device,
new SMS ( // new SMS (
pkt.body.get_string_member ("text"), // pkt.body.get_string_member ("text"),
SMS.FROM_CONTACT, // SMS.FROM_CONTACT,
SMS.FROM_TYPE_NOTIFICATION, // SMS.FROM_TYPE_NOTIFICATION,
new DateTime.now_utc () // new DateTime.now_utc ()
), // ),
pkt.body.get_string_member ("title")); // pkt.body.get_string_member ("title"));
} //}
/** /**
* make_sms_packet: * make_sms_packet:
......
...@@ -102,7 +102,8 @@ namespace MConnect { ...@@ -102,7 +102,8 @@ namespace MConnect {
Utils.TlsConnectionMode.SERVER); Utils.TlsConnectionMode.SERVER);
debug ("Attempt TLS handshake."); debug ("Attempt TLS handshake.");
var tls_res = yield tls_connection.handshake_async (); //var tls_res = yield tls_connection.handshake_async ();
yield tls_connection.handshake_async ();
debug ("TLS handshake complete."); debug ("TLS handshake complete.");
} catch (Error e) { } catch (Error e) {
var error = "TLS handshake failed: %s".printf (e.message); var error = "TLS handshake failed: %s".printf (e.message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment