Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Address deprecation & error handling compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcinnz committed Mar 31, 2020
1 parent 119a949 commit 26694d8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 54 deletions.
22 changes: 11 additions & 11 deletions src/BrowserWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,18 @@ public class Odysseus.BrowserWindow : Gtk.ApplicationWindow {
var back = tools.build_tool_item("go-previous", _("Go to previously viewed page"),
Gdk.Key.comma, () => web.go_back(), (menu) => {
web.get_back_forward_list().get_back_list().@foreach((item) => {
var opt = menu.add(item.get_title(), () => web.go_to_back_forward_list_item(item));
favicon_for_menuitem.begin(opt, item);
/*var opt =*/ menu.add(item.get_title(), () => web.go_to_back_forward_list_item(item));
// FIXME, I'll miss having favicons here. But deprecated APIs I can't be bothered to replace...
//favicon_for_menuitem.begin(opt, item);
});
}, Gdk.ModifierType.CONTROL_MASK, true);
tabs.bind_property("can-go-back", back, "sensitive", BindingFlags.SYNC_CREATE);
var forward = tools.build_tool_item("go-next", _("Go to next viewed page"),
Gdk.Key.period, () => web.go_forward(), (menu) => {
web.get_back_forward_list().get_forward_list().@foreach((item) => {
var opt = menu.add(item.get_title(), () => web.go_to_back_forward_list_item(item));
favicon_for_menuitem.begin(opt, item);
/*var opt =*/ menu.add(item.get_title(), () => web.go_to_back_forward_list_item(item));
// FIXME, I'll miss having favicons here. But deprecated APIs I can't be bothered to replace...
//favicon_for_menuitem.begin(opt, item);
});
}, Gdk.ModifierType.CONTROL_MASK, true);
tabs.bind_property("can-go-forward", forward, "sensitive", BindingFlags.SYNC_CREATE);
Expand Down Expand Up @@ -182,10 +184,8 @@ public class Odysseus.BrowserWindow : Gtk.ApplicationWindow {
menu.add(_("_Print"), () => new WebKit.PrintOperation(web).run_dialog(this), Gdk.Key.P);
menu.separate();
menu.add(_("Show Downloads"), () => downloads.set_reveal_child(true), Gdk.Key.D);
var help = "https://odysseus.adrian.geek.nz/guide.html";
menu.add(_("Help"), () => new_tab(help), Gdk.Key.question);
var about_link = "appstream://com.github.alcinnz.odysseus";
menu.add(_("About Odysseus"), () => Granite.Services.System.open_uri(about_link));
menu.add(_("Help"), () => new_tab("https://odysseus.adrian.geek.nz/guide.html"), Gdk.Key.question);
menu.add(_("About Odysseus"), () => new_tab("appstream://com.github.alcinnz.odysseus"));
});

tools.shortcut(Gdk.Key.T, () => new_tab());
Expand Down Expand Up @@ -214,7 +214,7 @@ public class Odysseus.BrowserWindow : Gtk.ApplicationWindow {
return ret;
}

private async void favicon_for_menuitem(Gtk.ImageMenuItem menuitem,
/*private async void favicon_for_menuitem(Gtk.ImageMenuItem menuitem,
WebKit.BackForwardListItem item) {
menuitem.always_show_image = true;
try {
Expand All @@ -225,8 +225,8 @@ public class Odysseus.BrowserWindow : Gtk.ApplicationWindow {
} catch (Error e) {
warning("Failed to load favicon for '%s':", item.get_uri());
}
}
}*/

public void new_tab(string url = "odysseus:home") {
var tab = new WebTab.with_new_entry(tabs, url);
tabs.insert_tab(tab, -1);
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/autocomplete/imply-http.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace Odysseus.Traits {
var host = query.split("/", 2)[0];
if (host == null) host = query;

var user = host.str("@");
var user = host[0:host.index_of("@")];
if (user != null) has_schema = !(":" in user);
else {
var port = host.rstr(":");
var port = host[host.index_of(":")+1:host.length];
has_schema = false;
foreach (var digit in port.data) {
if ('0' < digit || digit > '9') {
Expand Down
65 changes: 33 additions & 32 deletions src/Traits/download-progress.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,45 @@ namespace Odysseus.Traits {
var appuri = "application://com.github.alcinnz.odysseus.desktop";
var launcher = new LauncherEntry();

var conn = Bus.get_sync(BusType.SESSION);
conn.register_object(@"/com/canonical/unity/launcherentry/$(appuri.hash())", launcher);
try {
var conn = Bus.get_sync(BusType.SESSION);
conn.register_object(@"/com/canonical/unity/launcherentry/$(appuri.hash())", launcher);

dl.received_data.connect(() => {
Idle.add(() => {
var props = new HashTable<string, Variant>(str_hash, str_equal);
dl.received_data.connect(() => {
Idle.add(() => {
var props = new HashTable<string, Variant>(str_hash, str_equal);

var downloads = DownloadSet.get_downloads().downloads;
if (downloads.size == 0) {
props.insert("progress-visible", false);
props.insert("count-visible", false);
launcher.update(appuri, props);
return false;
}
var downloads = DownloadSet.get_downloads().downloads;
if (downloads.size == 0) {
props.insert("progress-visible", false);
launcher.update(appuri, props);
return false;
}

var progress = 1.0;
foreach (var download in downloads)
progress *= download.download.estimated_progress;
var progress = 1.0;
foreach (var download in downloads)
progress *= download.download.estimated_progress;

props.insert("progress-visible", true);
props.insert("progress", progress);
props.insert("count-visible", true);
props.insert("count", (int64) downloads.size);
launcher.update(appuri, props);
props.insert("progress-visible", true);
props.insert("progress", progress);
launcher.update(appuri, props);

return false;
}, Priority.LOW);
});
dl.finished.connect(() => {
if (dl.cancelled) return;
return false;
}, Priority.LOW);
});
dl.finished.connect(() => {
if (dl.cancelled) return;

var notify = new Notification(_("Web Download Completed"));
var response = dl.download.response;
var url = new Soup.URI(response.uri);
notify.set_body(url.path.rstr("/") + "\n" + url.host);
notify.set_icon(dl.icon);
Odysseus.Application.instance.send_notification(null, notify);
});
var notify = new Notification(_("Web Download Completed"));
var response = dl.download.response;
var url = new Soup.URI(response.uri);
notify.set_body(url.path[url.path.last_index_of("/")+1:url.path.length] + "\n" + url.host);
notify.set_icon(dl.icon);
Odysseus.Application.instance.send_notification(null, notify);
});
} catch (IOError e) {
/* Ignore, assuming the desktop doesn't support these indicators. */
}
}

[DBus(name="com.canonical.Unity.LauncherEntry")]
Expand Down
9 changes: 8 additions & 1 deletion src/Traits/status/webfeed.vala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,14 @@ namespace Odysseus.Traits {
button.tooltip_text = _("Subscribe via %s").printf(feedreader.get_name());
add(button);

button.clicked.connect(() => feedreader.launch_uris(links, null));
button.clicked.connect(() => {
try {
feedreader.launch_uris(links, null);
} catch (Error e) {
button.image = new Gtk.Image.from_icon_name("error", Gtk.IconSize.MENU);
warning("Failed to subscribe with %s: %s", feedreader.get_name(), e.message);
}
});
});

if (is_empty) {
Expand Down
15 changes: 11 additions & 4 deletions src/Widgets/DownloadBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ public class Odysseus.DownloadsBar : Gtk.Revealer {
box.add(mainbox);

add_action("folder", _("View all downloads"),
() => Granite.Services.System.open(Download.folder));
add_action("window-close", _("Close downloads bar"), () => set_reveal_child(false));
(button) => {
try {
AppInfo.launch_default_for_uri(Download.folder.get_uri(), null);
} catch (Error e) {
button.image = new Gtk.Image.from_icon_name("error", Gtk.IconSize.MENU);
warning("Failed to open file manager: %s", e.message);
}
});
add_action("window-close", _("Close downloads bar"), (_) => set_reveal_child(false));

reveal_child = false;
notify["child-revealed"].connect((pspec) => {
Expand All @@ -46,10 +53,10 @@ public class Odysseus.DownloadsBar : Gtk.Revealer {
DownloadSet.get_downloads().add.connect((dl) => reveal_child = true);
}

private delegate void Action();
private delegate void Action(Gtk.Button button);
private void add_action(string icon, string help, owned Action action) {
var button = new Gtk.Button.from_icon_name(icon);
button.clicked.connect(() => action());
button.clicked.connect(() => action(button));
button.relief = Gtk.ReliefStyle.NONE;
button.tooltip_text = help;
box.add(button);
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/header/HeaderBarWithMenus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public class Odysseus.Header.HeaderBarWithMenus : Gtk.HeaderBar {
public Gtk.Menu menu = new Gtk.Menu();
public Gtk.AccelGroup? accel_group = null;

public Gtk.ImageMenuItem add(string title, owned Action action, uint key = 0,
public Gtk.MenuItem add(string title, owned Action action, uint key = 0,
Gdk.ModifierType modifier = Gdk.ModifierType.CONTROL_MASK) {
var item = new Gtk.ImageMenuItem.with_mnemonic(title);
var item = new Gtk.MenuItem.with_mnemonic(title);
item.activate.connect(() => {action();});
menu.add(item);

Expand Down
8 changes: 6 additions & 2 deletions src/ext/liberate/Liberate.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ namespace Liberate {
}

static string read_resource (string name) {
var res = GLib.resources_lookup_data (RESOURCES_PATH + name, ResourceLookupFlags.NONE);
return (string)res.get_data ();
try {
var res = GLib.resources_lookup_data (RESOURCES_PATH + name, ResourceLookupFlags.NONE);
return (string)res.get_data ();
} catch (Error e) {
return e.message; // Syntax error, but places the error in a place I can easily check.
}
}

static inline string to_vala_string (global::JS.String js) {
Expand Down

0 comments on commit 26694d8

Please sign in to comment.