Skip to content
Browse files

UI improvements for downloads

  • Loading branch information...
1 parent be22c56 commit 03c437d66b672df3281805a5eac7ced9ce15d66f @Waldteufel committed
Showing with 47 additions and 6 deletions.
  1. +47 −6 browser.vala
View
53 browser.vala
@@ -160,7 +160,8 @@ class BrowserWindow : Gtk.Window {
protected override void enter() {
browser.cmdentry.editable = false;
browser.statusbar.hide();
- browser.cmdentry.show();
+ browser.cmdentry.text = browser.get_current_uri();
+ browser.cmdentry.show();
}
public override bool key_pressed(Gdk.ModifierType modif, uint key) {
@@ -172,6 +173,47 @@ class BrowserWindow : Gtk.Window {
}
}
+ class DownloadMode : Mode {
+ public WebKit.Download download { get; construct; }
+ public DownloadMode(BrowserWindow browser, WebKit.Download dl) {
+ Object(browser: browser, download: dl);
+ }
+
+ protected override void enter() {
+ browser.cmdentry.editable = false;
+ browser.statusbar.hide();
+ browser.cmdentry.show();
+
+ download.notify["progress"].connect(this.update_progress);
+ download.error.connect(this.handle_error);
+ }
+
+ private bool handle_error(int code, int detail, string reason) {
+ var dialog = new Gtk.MessageDialog(browser, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "%s", reason);
+ dialog.title = "Download";
+ dialog.run();
+ browser.mode = new InteractMode(browser);
+ return false;
+ }
+
+ private void update_progress() {
+ browser.cmdentry.text = download.get_uri();
+ browser.cmdentry.set_progress_fraction(download.progress);
+
+ if (download.progress == 1)
+ browser.mode = new InteractMode(browser);
+ }
+
+ public override bool key_pressed(Gdk.ModifierType modif, uint key) {
+ if (modif == 0 && key == 0xff1b) {
+ download.cancel();
+ browser.mode = new InteractMode(browser);
+ return true;
+ }
+ return base.key_pressed(modif, key);
+ }
+ }
+
class CommandMode : NonLoadMode {
public CommandMode(BrowserWindow browser) {
Object(browser: browser);
@@ -350,10 +392,8 @@ class BrowserWindow : Gtk.Window {
}
private void load_status_changed() {
- show_uri_and_title();
-
- if (mode is LoadMode)
- cmdentry.text = get_current_uri();
+ if (mode is DownloadMode)
+ return;
switch (web.load_status) {
case WebKit.LoadStatus.PROVISIONAL:
@@ -376,8 +416,9 @@ class BrowserWindow : Gtk.Window {
var dialog = new Gtk.MessageDialog(this, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, "%s", filename);
dialog.title = "Download?";
if (dialog.run() == Gtk.ResponseType.YES) {
- download.set_destination_uri("file://" + Path.build_filename("/tmp", filename));
dialog.destroy();
+ download.set_destination_uri("file://" + Path.build_filename("/tmp", filename));
+ mode = new DownloadMode(this, download);
return true;
} else {
dialog.destroy();

0 comments on commit 03c437d

Please sign in to comment.
Something went wrong with that request. Please try again.