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

Commit

Permalink
Clean up warnings to that from 3rd parties.
Browse files Browse the repository at this point in the history
Largely involved moving away from using Gtk.Stock, as that has been deprecated
in favour of icon themes and explicit developer control.
  • Loading branch information
Adrian Cochrane committed Mar 10, 2017
1 parent f65a6f9 commit c81b4a4
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 49 deletions.
30 changes: 18 additions & 12 deletions src/BrowserWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,23 @@ public class Oddysseus.BrowserWindow : Gtk.ApplicationWindow {
private Gtk.Menu create_appmenu() {
var menu = new Gtk.Menu();

var new_window = new Gtk.MenuItem.with_label(_("New Window"));
// TRANSLATORS _ precedes the keyboard shortcut
var new_window = new Gtk.MenuItem.with_label(_("_New Window"));
new_window.activate.connect(() => {
var window = new BrowserWindow(Oddysseus.Application.instance);
window.show_all();
});
menu.add(new_window);

var open = new Gtk.MenuItem.with_label(_("Open..."));
// TRANSLATORS _ precedes the keyboard shortcut
var open = new Gtk.MenuItem.with_label(_("_Open..."));
open.activate.connect(() => {
var chooser = new Gtk.FileChooserDialog(
_("Open Local Webpage"),
this,
Gtk.FileChooserAction.OPEN,
Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
Gtk.Stock.OPEN, Gtk.ResponseType.OK);
_("_Cancel"), Gtk.ResponseType.CANCEL,
_("_Open"), Gtk.ResponseType.OK);
chooser.filter.add_mime_type("text/html");
chooser.filter.add_mime_type("application/xhtml+xml");
chooser.filter.add_pattern("*.html");
Expand All @@ -134,25 +136,27 @@ public class Oddysseus.BrowserWindow : Gtk.ApplicationWindow {
menu.add(open);
open_item = open;

var save = new Gtk.MenuItem.with_label(_("Save..."));
// TRANSLATORS _ precedes the keyboard shortcut
var save = new Gtk.MenuItem.with_label(_("_Save..."));
save.activate.connect(() => {
var chooser = new Gtk.FileChooserDialog(
_("Save Page as"),
this,
Gtk.FileChooserAction.SAVE,
Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
Gtk.Stock.SAVE_AS, Gtk.ResponseType.OK);
_("_Cancel"), Gtk.ResponseType.CANCEL,
_("_Save As"), Gtk.ResponseType.OK);

if (chooser.run() == Gtk.ResponseType.OK) {
web.save_to_file(File.new_for_uri(chooser.get_uri()),
web.save_to_file.begin(File.new_for_uri(chooser.get_uri()),
WebKit.SaveMode.MHTML, null);
}
chooser.destroy();
});
menu.add(save);
save_item = save;

var view_source = new Gtk.MenuItem.with_label(_("View Source"));
// TRANSLATORS _ precedes the keyboard shortcut
var view_source = new Gtk.MenuItem.with_label(_("_View Source"));
view_source.activate.connect(() => {
var tab = new WebTab(tabs, web, "about:blank");
tabs.insert_tab(tab, -1);
Expand All @@ -177,11 +181,13 @@ public class Oddysseus.BrowserWindow : Gtk.ApplicationWindow {

menu.add(new Gtk.SeparatorMenuItem());

var find_in_page = new Gtk.MenuItem.with_label(_("Find In Page..."));
// TRANSLATORS _ precedes the keyboard shortcut
var find_in_page = new Gtk.MenuItem.with_label(_("_Find In Page..."));
find_in_page.activate.connect(find_in_page_cb);
menu.add(find_in_page);

var print = new Gtk.MenuItem.with_label(_("Print..."));
// TRANSLATORS _ precedes the keyboard shortcut
var print = new Gtk.MenuItem.with_label(_("_Print..."));
print.activate.connect(() => {
var printer = new WebKit.PrintOperation(web);
printer.run_dialog(this);
Expand Down Expand Up @@ -454,7 +460,7 @@ public class Oddysseus.BrowserWindow : Gtk.ApplicationWindow {
yield persistFile.write_all_async(url.data,
Priority.DEFAULT,
null, out bytes_written);
} catch (IOError e) {
} catch (Error e) {
// The file should still work reasonably well.
// The separator must be successful written before the url is,
// and if that isn't fully written things should still work.
Expand Down
4 changes: 0 additions & 4 deletions src/Oddysseus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public class Oddysseus.Application : Granite.Application {
}
} catch (Error e) {
warning("Failed to restore tabs: %s", e.message);
} catch (IOError e) {
warning("Failed to restore tabs: %s", e.message);
}
}

Expand Down Expand Up @@ -160,8 +158,6 @@ public class Oddysseus.Application : Granite.Application {
}
} catch (Error e) {
warning("Failed to persist state: %s", e.message);
} catch (IOError e) {
warning("Failed to write window seperator: %s", e.message);
}
}
}
Expand Down
45 changes: 41 additions & 4 deletions src/Services/Prosody/lib.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
/* Standard "tags" and "filters" to use in templates.
Beware that these may differ subtly from Django's implementation. */
namespace Oddysseus.Templating.Std {
private Gee.Map<Bytes, Variable> parse_params(WordIter args) {
private Gee.Map<Bytes, Variable> parse_params(WordIter args)
throws SyntaxError {
var parameters = ByteUtils.create_map<Variable>();
var count = 0;
foreach (var arg in args) {
Expand Down Expand Up @@ -665,14 +666,22 @@ namespace Oddysseus.Templating.Std {

// Parse string
WordIter? endtag;
var bytes = parser.scan_until("endtrans plural", out endtag);
Bytes bytes;
// Ensures source string is a valid template
parser.parse("endtrans plural", out endtag, out bytes);
var text = ByteUtils.to_string(bytes).strip();

// Parse plural
if (ByteUtils.equals_str(endtag.next(), "plural")) {
var pluralb = parser.scan_until("endtrans", out endtag);
Bytes pluralb;
parser.parse("endtrans", out endtag, out pluralb);
var plural = ByteUtils.to_string(pluralb).strip();
// TODO handle plurals

// Assert endtag
if (endtag == null) throw new SyntaxError.UNBALANCED_TAGS(
"{%% trans %%} must be closed with a {%% endtrans %%}");

return new TransTag(parameters, text, plural);
}

// Assert endtag
Expand All @@ -691,6 +700,34 @@ namespace Oddysseus.Templating.Std {
return new WithTag(parameters, inner_parser.parse());
}
}
private class TransTag : Template {
private string text;
private string plural;
private Gee.Map<Bytes,Variable> vars;
public TransTag(Gee.Map<Bytes,Variable> vars, string t, string p) {
this.vars = vars;
this.text = t;
this.plural = p;
}

public override async void exec(Data.Data ctx, Writer output) {
// TODO optimize! by parsing ahead of time
var inner_ctx = new Data.Lazy(vars, ctx);
var n = inner_ctx[ByteUtils.from_string("count")].to_int();
var translated = ngettext(text, plural, n);

try {
var parser = new Parser(ByteUtils.from_string(translated));
var block = parser.parse();
yield block.exec(inner_ctx, output);
} catch (SyntaxError e) {
// TRANSLATORS Feel free to put in a different web address
// for users to report your invalid templates to.
yield output.writes(_("TRANSLATION ERROR! Please report to " +
"https://github.com/alcinnz/Oddysseus/issues"));
}
}
}

private class VerbatimBuilder : TagBuilder, Object {
public Template? build(Parser parser, WordIter args) throws SyntaxError {
Expand Down
7 changes: 4 additions & 3 deletions src/Services/Prosody/loader.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Oddysseus.Templating {
if (!template_cache.has_key(resource)) {
if (cached_keys.size > 5) {
// cap number of templates
var to_free = template_cache.unset(cached_keys[CACHE_SIZE - 1]);
template_cache.unset(cached_keys[CACHE_SIZE - 1]);
cached_keys.remove_at(CACHE_SIZE - 1);
}

Expand Down Expand Up @@ -67,7 +67,8 @@ namespace Oddysseus.Templating {
"Unknown Tag", "Unknown Filter",
"Invalid Arguments for Tag", "Unclosed Block Tag"};
public ErrorData(SyntaxError err, int line_number, int line_offset,
int error_start, int error_end, Bytes source) {
int error_start, int error_end, Bytes source)
throws SyntaxError {
data[ByteUtils.from_string("err-code")] =
new Data.Literal(error_types[err.code]);

Expand All @@ -91,7 +92,7 @@ namespace Oddysseus.Templating {
private class ErrorTagBuilder : Object, TagBuilder {
private ErrorTag tag;
public ErrorTagBuilder(ErrorTag tag) {this.tag = tag;}
public Template? build(Parser parser, WordIter args) {
public Template? build(Parser parser, WordIter args) throws SyntaxError {
args.assert_end();
return tag;
}
Expand Down
8 changes: 1 addition & 7 deletions src/Services/pages.vala
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ namespace Oddysseus.Services {
render_error(request, "NOT-FOUND");
return;
}
Templating.Data.Data data;
try {
data = parse_url_to_prosody(request.get_uri());
} catch (Error e) {
render_error(request, "BAD-REQUEST");
return;
}
Templating.Data.Data data = parse_url_to_prosody(request.get_uri());

var stream = new Templating.InputStreamWriter();
request.finish(stream, -1, mime_type);
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/errors.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Oddysseus.Traits {
}
}

render_alternate_html(web, "errors/" + error, uri);
render_alternate_html.begin(web, "errors/" + error, uri);
try {
var path = "/" + Path.build_path("/",
"io", "github", "alcinnz", "Oddysseus", "oddysseus:",
Expand Down
15 changes: 12 additions & 3 deletions src/Traits/viewsource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ namespace Oddysseus.Traits {
public async void view_source(WebKit.WebView source, WebKit.WebView dest) {
var data = new Source();
data.title = source.title;
data.code = new Bytes(yield source.get_main_resource().get_data(null));
try {
var code = yield source.get_main_resource().get_data(null);
data.code = new Bytes(code);
} catch (Error e) {
return; // Don't go through
}

var url = "source:" + source.get_main_resource().uri;
if (sources == null) sources = new Gee.HashMap<string, Source>();
Expand Down Expand Up @@ -79,8 +84,12 @@ namespace Oddysseus.Traits {
request.finish_error(err);
}
} else if (request.get_uri() == "source:favicon.ico") {
var stream = resources_open_stream("/io/github/alcinnz/Oddysseus/oddysseus:/special/viewsource.ico", 0);
request.finish(stream, -1, "image/x-icon");
try {
var stream = resources_open_stream("/io/github/alcinnz/Oddysseus/oddysseus:/special/viewsource.ico", 0);
request.finish(stream, -1, "image/x-icon");
} catch (Error e) {
request.finish_error(e);
}
} else {
// If we're not viewing alternate HTML under this schema,
// close any tabs that have persisted.
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/AddressBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Oddysseus.AddressBar : Gtk.Entry {
/* While there's more planned here,
at the moment I just need this class to customize sizing */
public override void get_preferred_width(out int min_width, out int nat_width) {
min_width = 20; // Meh
nat_width = 848; // Something large, so it fills this space if possible
}
}
35 changes: 25 additions & 10 deletions src/Widgets/DownloadButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,22 @@ public class Oddysseus.DownloadButton : Oddysseus.ProgressBin {
download.finished.connect(() => {
// Can't set destination after a download's started,
// so do it afterwords
if (destination != "")
if (destination != "") try {
File.new_for_uri(download.destination).move(
File.new_for_uri(destination),
FileCopyFlags.OVERWRITE | FileCopyFlags.BACKUP);
} catch (Error e) {
var dlg = new Gtk.MessageDialog((Gtk.Window) get_toplevel(),
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE,
// TRANSLATORS "%s is replaced with the filepath
// the user specified they wanted their download to be at
_("Error moving download to %s.\nIt has been left in you Downloads folder") + "\n\n%s",
destination, e.message);
dlg.run();
dlg.destroy();
}

update_data();
remaining.label = _("DONE");
Expand Down Expand Up @@ -140,23 +152,26 @@ public class Oddysseus.DownloadButton : Oddysseus.ProgressBin {

private void create_menu() {
menu = new Gtk.Menu();

open_item = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.OPEN, null);

// TRANSLATORS _ precedes shortcut key
open_item = new Gtk.MenuItem.with_mnemonic(_("_Open"));
open_item.activate.connect(() => {
Granite.Services.System.open_uri(download.destination);
});
open_item.sensitive = false;
menu.add(open_item);

var save_item = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.SAVE_AS,
null);
// TRANSLATORS _ precedes shortcut key
var save_item = new Gtk.MenuItem.with_mnemonic(_("_Save As"));
save_item.activate.connect(() => {
var chooser = new Gtk.FileChooserDialog(
_("Save Download to:"),
(Gtk.Window) get_toplevel(),
Gtk.FileChooserAction.SAVE,
Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
Gtk.Stock.SAVE_AS, Gtk.ResponseType.OK);
// TRANSLATORS _ precedes the shortcut key
_("_Cancel"), Gtk.ResponseType.CANCEL,
// TRANSLATORS _ precedes the shortcut key
_("_Save As"), Gtk.ResponseType.OK);
chooser.set_filename(download.destination);

if (chooser.run() == Gtk.ResponseType.OK) {
Expand All @@ -167,9 +182,9 @@ public class Oddysseus.DownloadButton : Oddysseus.ProgressBin {
menu.add(save_item);

menu.add(new Gtk.SeparatorMenuItem());
var cancel_item = new Gtk.ImageMenuItem.from_stock(Gtk.Stock.CANCEL,
null);

// TRANSLATORS _ precedes shortcut key
var cancel_item = new Gtk.MenuItem.with_mnemonic(_("_Cancel"));
cancel_item.activate.connect(() => this.destroy());
menu.add(cancel_item);

Expand Down
6 changes: 1 addition & 5 deletions src/Widgets/ProgressBin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
public class Oddysseus.ProgressBin : Gtk.Bin {
public Cairo.Pattern progressFill {get; set;}
public double progress {get; set;}
private Gdk.Window window; // A clear background to use

public ProgressBin() {
window = new Gdk.Window(null, Gdk.WindowAttr(), 0);
window.set_background({0, green: 0, blue: 0, alpha: 0});

progressFill = new Cairo.Pattern.rgba(0.7, 0.8, 1.0, 0.9);

this.notify.connect((sender, property) => queue_draw());
Expand All @@ -39,7 +35,7 @@ public class Oddysseus.ProgressBin : Gtk.Bin {
// TODO Works, at the moment, on elementary OS without this,
// but needs fixing.
// The goal: set a transparent background before rendering child.
//child_ctx.set_background(window);
//child_ctx.set_background(?);

// Render progress
cr.rectangle(0, 0, width * progress, height);
Expand Down

0 comments on commit c81b4a4

Please sign in to comment.