Skip to content

Commit

Permalink
GH-2 - delete contract files at startup.
Browse files Browse the repository at this point in the history
And some cleanup.
  • Loading branch information
gyan000 committed Nov 23, 2018
1 parent 9312067 commit e364d6f
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 91 deletions.
19 changes: 0 additions & 19 deletions data/dbus-send.sh

This file was deleted.

49 changes: 35 additions & 14 deletions src/EOSConnect/Contractor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,33 @@ namespace EOSConnect {
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) {
var contract_file = Path.build_filename (Contractor.create_if_not_exists_contract_dir (), device.id + ".contract");
try {
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);
if (file.query_exists () == true) {
file.delete ();
}

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";
Expand All @@ -57,17 +74,21 @@ namespace EOSConnect {
os.write ("MimeType=!inode;\n".data);
os.write (str_command.data);
} 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) {
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 ();
}
try {
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 ();
}
} catch (Error e) {
warning ("Error: %s\n", e.message);
}
}
}
}
1 change: 1 addition & 0 deletions src/EOSConnect/EOSConnect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace EOSConnect {

public override void activate ()
{
Contractor.clean_contractor_directory.begin ();
MConnectThread mconnect_thread = new MConnectThread (this, devices_map, main_settings);

launcher_entry = LauncherEntry.get_for_desktop_id (GSETTINGS_SCHEMA_ID + ".desktop");
Expand Down
2 changes: 0 additions & 2 deletions src/EOSConnect/Plugin/Popover/ShareSettings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ namespace EOSConnect.Plugin.Popover {

var file_chooser = new Gtk.FileChooserButton (_("Select default download directory"),
Gtk.FileChooserAction.SELECT_FOLDER);
file_chooser.margin_right = 10;

var directory = device.settings.get_string ("kdeconnect-share-directory");
if (directory.length > 5) {
file_chooser.set_uri (directory);
Expand Down
44 changes: 22 additions & 22 deletions src/MConnect/DeviceManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -176,28 +176,28 @@ namespace MConnect {
}

private void on_local_notification_closed (Notification notification) {
try {

print ("\n>>%S\n", notification.id);

// var notification = new Notification.from_message (message, id);
// Core.instance ().application.withdraw_notification (notification_id);

// if (!notification.get_is_valid () || notification.app_name in Notification.EXCEPTIONS) {
// return;
// }
//
// foreach (Device device in Core.instance ().devices_map.values) {
// if (device.has_capability_handler (NotificationHandler.NOTIFICATION)) {
// NotificationHandler notification_handler = (NotificationHandler)device.get_path_capability_handler(
// NotificationHandler.NOTIFICATION);
//
// notification_handler.send_notification (device, message, id);
// }
// }
} catch (Error e) {
warning ("Error: %s", e.message);
}
//try {

// print ("\n>>%S\n", notification.id);

// // var notification = new Notification.from_message (message, id);
// // Core.instance ().application.withdraw_notification (notification_id);

// // if (!notification.get_is_valid () || notification.app_name in Notification.EXCEPTIONS) {
// // return;
// // }
// //
// // foreach (Device device in Core.instance ().devices_map.values) {
// // if (device.has_capability_handler (NotificationHandler.NOTIFICATION)) {
// // NotificationHandler notification_handler = (NotificationHandler)device.get_path_capability_handler(
// // NotificationHandler.NOTIFICATION);
// //
// // notification_handler.send_notification (device, message, id);
// // }
// // }
//} catch (Error e) {
// warning ("Error: %s", e.message);
//}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/MConnect/DownloadTransfer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace MConnect {
Utils.TlsConnectionMode.CLIENT);

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.");
} catch (Error e) {
Expand Down
2 changes: 1 addition & 1 deletion src/MConnect/NotificationMonitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace MConnect {
return message;
}

uint32 id = child.get_uint32 ();
//uint32 id = child.get_uint32 ();
Idle.add (() => {
return false;
});
Expand Down
5 changes: 2 additions & 3 deletions src/MConnect/Packet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace MConnect {
public uint64 size;
public uint port;
}

public string pkt_type {
get; private set; default = "";
}
Expand All @@ -49,9 +50,7 @@ namespace MConnect {
public Json.Object body {
get; private set; default = null;
}
public Packet.Payload ? payload {
get; set; default = null;
}
public Packet.Payload ? payload;

public Packet (string type, Json.Object body, int64 id = 0) {
this.pkt_type = type;
Expand Down
25 changes: 13 additions & 12 deletions src/MConnect/ShareHandlerProxy.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ class ShareHandlerProxy : Object {
// }

public void files (string device_id, string pathnames) throws IOError {
try {
foreach (var entry in Core.instance ().devices_map.entries) {

bool device_available = false;
if (entry.value.id == device_id &&
entry.value.is_active == true) {
SList<string> files_to_send = new SList<string> ();

foreach (var entry in Core.instance ().devices_map.entries) {
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 ());
}

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);
((Share)entry.value.get_plugin (ShareHandler.SHARE_PKT)).send_files (entry.value, files_to_send);
}
}
} catch (Error e) {
warning ("Error: %s", e.message);
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/MConnect/TelephonyHandler.vala
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,22 @@ namespace MConnect {
// }
}

public void handle_sms_notification (Device device, Packet pkt) {
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.
//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 ());
//return;
SMSStore.instance ().handle_missed_sms (
device,
new SMS (
pkt.body.get_string_member ("text"),
SMS.FROM_CONTACT,
SMS.FROM_TYPE_NOTIFICATION,
new DateTime.now_utc ()
),
pkt.body.get_string_member ("title"));
}
//public void handle_sms_notification (Device device, Packet pkt) {
// 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.
// //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 ());
// //return;
// SMSStore.instance ().handle_missed_sms (
// device,
// new SMS (
// pkt.body.get_string_member ("text"),
// SMS.FROM_CONTACT,
// SMS.FROM_TYPE_NOTIFICATION,
// new DateTime.now_utc ()
// ),
// pkt.body.get_string_member ("title"));
//}

/**
* make_sms_packet:
Expand Down
3 changes: 2 additions & 1 deletion src/MConnect/UploadTransfer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ namespace MConnect {
Utils.TlsConnectionMode.SERVER);

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.");
} catch (Error e) {
var error = "TLS handshake failed: %s".printf (e.message);
Expand Down

0 comments on commit e364d6f

Please sign in to comment.