Browse Source

share: refactor, split file/url/text sharing, use Utils.find_urls()

bboozzoo/self-announce
Maciek Borzecki 7 years ago
parent
commit
11dfd71035
1 changed files with 33 additions and 15 deletions
  1. +33
    -15
      src/mconnect/share.vala

+ 33
- 15
src/mconnect/share.vala View File

@ -67,26 +67,44 @@ class ShareHandler : Object, PacketHandlerInterface {
}
if (pkt.body.has_member("filename")) {
if (pkt.payload == null) {
warning("missing payload info");
return;
}
this.handle_file(dev, pkt);
} else if (pkt.body.has_member("url")) {
this.handle_url(dev, pkt);
} else if (pkt.body.has_member("text")) {
this.handle_text(dev, pkt);
}
}
string name = pkt.body.get_string_member("filename");
debug("file: %s size: %s", name, format_size(pkt.payload.size));
private void handle_file(Device dev, Packet pkt) {
if (pkt.payload == null) {
warning("missing payload info");
return;
}
var t = new DownloadTransfer(
dev,
new InetSocketAddress(dev.host,
(uint16) pkt.payload.port),
pkt.payload.size,
make_downloads_path(name));
string name = pkt.body.get_string_member("filename");
debug("file: %s size: %s", name, format_size(pkt.payload.size));
t.start_async.begin();
} else if (pkt.body.has_member("url")) {
var url = pkt.body.get_string_member("url");
var t = new DownloadTransfer(
dev,
new InetSocketAddress(dev.host,
(uint16) pkt.payload.port),
pkt.payload.size,
make_downloads_path(name));
t.start_async.begin();
}
private void handle_url(Device dev, Packet pkt) {
var url_msg = pkt.body.get_string_member("url");
var urls = Utils.find_urls(url_msg);
if (urls.length > 0) {
var url = urls[0];
debug("got URL: %s, launching...", url);
AppInfo.launch_default_for_uri(url, null);
}
}
private void handle_text(Device dev, Packet pkt) {
}
}

Loading…
Cancel
Save