From 7c41b228818ae7ade695063cb004ee53a0f2e5ec Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 10 Sep 2017 21:18:06 +0200 Subject: [PATCH 01/31] show app icon in desktop notification --- src/WebWindow.vala | 36 +++++------------------------------- src/Widgets/WebApp.vala | 9 ++++++--- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index ff676fe..3d3f50d 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -66,31 +66,6 @@ namespace Webpin { }); headerbar.pack_start (stay_open); - var mute_notifications = new Gtk.ToggleButton (); - mute_notifications.active = desktop_file.mute_notifications; - if (mute_notifications.active) { - mute_notifications.image = new Gtk.Image.from_icon_name ("notification-disabled-symbolic", Gtk.IconSize.MENU); - mute_notifications.tooltip_text = _("Unmute notifications"); - } else { - mute_notifications.image = new Gtk.Image.from_icon_name ("notification-symbolic", Gtk.IconSize.MENU); - mute_notifications.tooltip_text = _("Mute notifications"); - } - mute_notifications.toggled.connect (() => { - desktop_file.edit_propertie ("WebpinMuteNotifications", mute_notifications.active.to_string ()); - desktop_file.save_to_file (); - if (mute_notifications.active) { - mute_notifications.image = new Gtk.Image.from_icon_name ("notification-disabled-symbolic", Gtk.IconSize.MENU); - mute_notifications.tooltip_text = _("Unmute notifications"); - } else { - mute_notifications.image = new Gtk.Image.from_icon_name ("notification-symbolic", Gtk.IconSize.MENU); - mute_notifications.tooltip_text = _("Mute notifications"); - desktop_notification.set_title (desktop_file.name); - desktop_notification.set_body (_("Desktop notifications are enabled")); - WebpinApp.instance.send_notification (null, desktop_notification); - } - }); - headerbar.pack_start (mute_notifications); - this.set_titlebar (headerbar); var width = desktop_file.info.get_string ("WebpinWindowWidth"); @@ -129,12 +104,11 @@ namespace Webpin { } }); - web_app.desktop_notification.connect ((title, body) => { - if (!desktop_file.mute_notifications) { - desktop_notification.set_title (title); - desktop_notification.set_body (body); - WebpinApp.instance.send_notification (null, desktop_notification); - } + web_app.desktop_notification.connect ((title, body, icon) => { + desktop_notification.set_title (title); + desktop_notification.set_body (body); + desktop_notification.set_icon (icon); + WebpinApp.instance.send_notification (null, desktop_notification); }); web_app.request_begin.connect (() => { diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index e128e18..b8eaa00 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -37,11 +37,12 @@ namespace Webpin { private WebKit.CookieManager cookie_manager; private Gtk.Box container; Granite.Widgets.Toast app_notification; + GLib.Icon icon_for_notification; public signal void external_request (WebKit.NavigationAction action); public signal void request_begin (); public signal void request_finished (); - public signal void desktop_notification (string title, string body); + public signal void desktop_notification (string title, string body, GLib.Icon icon); public WebApp (string app_url) { @@ -106,6 +107,7 @@ namespace Webpin { if (icon_file.query_exists ()) { try { icon = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (file.icon, 48, 48, true)); + icon_for_notification = GLib.Icon.new_for_string (file.icon); } catch (Error e) { warning (e.message); @@ -113,6 +115,7 @@ namespace Webpin { } } else { icon = new Gtk.Image.from_icon_name (file.icon, Gtk.IconSize.DIALOG); + icon_for_notification = new GLib.ThemedIcon (file.icon); } container.pack_start(icon, true, true, 0); @@ -134,8 +137,8 @@ namespace Webpin { }); app_view.show_notification.connect ((notification) => { - desktop_notification (notification.title, notification.body); - return false; + desktop_notification (notification.title, notification.body, icon_for_notification); + return true; }); app_view.permission_request.connect ((permission) => { From 0acf8f77bab1660edab51fcb512969b9a262d52c Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 10 Sep 2017 22:51:20 +0200 Subject: [PATCH 02/31] open webapp by clicking desktop notification --- src/Application.vala | 20 ++++++++++++++++---- src/Objects/DesktopFile.vala | 9 ++++++--- src/WebWindow.vala | 6 ++---- src/Widgets/WebApp.vala | 1 - 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index f062c23..81b0976 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -48,6 +48,15 @@ namespace Webpin { app_launcher = application_id + ".desktop"; flags |= GLib.ApplicationFlags.HANDLES_OPEN; app_list = new GLib.List (); + + var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING); + add_action (open_web_app); + open_web_app.activate.connect ((parameter) => { + if (parameter != null) { + debug ("start web app over action: '%s'", parameter.get_string ()); + start_webapp (parameter.get_string ()); + } + }); } public Gtk.Window mainwindow; @@ -64,24 +73,27 @@ namespace Webpin { } public override void open (File[] files, string hint) { - debug (files [0].get_uri ()); + debug ("%s", files [0].get_uri ()); start_webapp (files [0].get_uri ()); } - + public void start_webapp (string url) { foreach (var item in app_list) { + debug ("running webapp: %s", item.desktop_file.url); if (item.desktop_file.url == url) { + debug ("open runing app: %s", url); item.present (); return; } } + debug ("create a new web app: %s", url); var app_info = Webpin.DesktopFile.get_app_by_url (url); var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info); - var app = new WebWindow(desktop_file); + var app = new WebWindow (desktop_file); + app_list.append (app); app.destroy.connect (() => { app_list.remove (app); }); app.set_application (this); - app_list.append (app); } } } diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 1db111c..2cb93bd 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -180,10 +180,13 @@ namespace Webpin { var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); - var exec = desktop_app.get_string ("Exec").replace ("%%", "%"); + var exec = desktop_app.get_string ("Exec"); - if (exec != null && exec.contains (url)) { - return desktop_app; + if (exec != null) { + exec = exec.replace ("%%", "%"); + if (exec.contains (url)) { + return desktop_app; + } } } return null; diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 3d3f50d..fcb0b08 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -37,7 +37,6 @@ namespace Webpin { Gtk.Spinner spinner; public DesktopFile desktop_file { get; private set; } - private Notification desktop_notification; public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; @@ -46,8 +45,6 @@ namespace Webpin { set_wmclass (desktop_file.url, desktop_file.url); web_app = new WebApp (desktop_file.url); - desktop_notification = new Notification (""); - var headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; headerbar.show_close_button = true; @@ -105,9 +102,10 @@ namespace Webpin { }); web_app.desktop_notification.connect ((title, body, icon) => { - desktop_notification.set_title (title); + var desktop_notification = new Notification (title); desktop_notification.set_body (body); desktop_notification.set_icon (icon); + desktop_notification.add_button_with_target_value (_("Open %s").printf (desktop_file.name), "app.open-web-app", new GLib.Variant.string (desktop_file.url)); WebpinApp.instance.send_notification (null, desktop_notification); }); diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index b8eaa00..45adb15 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -108,7 +108,6 @@ namespace Webpin { try { icon = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (file.icon, 48, 48, true)); icon_for_notification = GLib.Icon.new_for_string (file.icon); - } catch (Error e) { warning (e.message); icon = new Gtk.Image.from_icon_name ("artemanufrij.webpin", Gtk.IconSize.DIALOG); From e0068616430c3d8a8f78e3067746c5c72ff85349 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 15 Oct 2017 19:16:01 +0200 Subject: [PATCH 03/31] open app on single click --- src/Widgets/ApplicationsView.vala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Widgets/ApplicationsView.vala b/src/Widgets/ApplicationsView.vala index 45d1639..595c040 100644 --- a/src/Widgets/ApplicationsView.vala +++ b/src/Widgets/ApplicationsView.vala @@ -48,10 +48,9 @@ namespace Webpin { icon_view.valign = Gtk.Align.START; icon_view.vexpand = false; icon_view.homogeneous = true; - icon_view.column_spacing = 15; - icon_view.row_spacing = 15; - icon_view.margin = 15; - icon_view.activate_on_single_click = false; + icon_view.column_spacing = 24; + icon_view.row_spacing = 24; + icon_view.margin = 24; icon_view.child_activated.connect ((child) => { if ((child as Gtk.FlowBoxChild).get_child () is ApplicationIcon) { var app_icon = (child as Gtk.FlowBoxChild).get_child () as ApplicationIcon; From f181c85602476f63946f00af58219eda2534906f Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 15 Oct 2017 19:26:23 +0200 Subject: [PATCH 04/31] new option copy current uri into clipboard --- src/WebWindow.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index fcb0b08..116ade8 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -49,6 +49,13 @@ namespace Webpin { headerbar.title = desktop_file.name; headerbar.show_close_button = true; + var copy_url = new Gtk.Button.from_icon_name ("edit-copy-symbolic", Gtk.IconSize.MENU); + copy_url.tooltip_text = _("Copy URI into clipboard"); + copy_url.clicked.connect (() => { + Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (web_app.app_view.uri, -1); + }); + headerbar.pack_end (copy_url); + spinner = new Gtk.Spinner (); spinner.set_size_request (16, 16); headerbar.pack_end (spinner); From 36a5b2fabcf8df2dcf063bddee9b6ac6ca4a4bfc Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 15 Oct 2017 19:26:56 +0200 Subject: [PATCH 05/31] updated po/pot content --- po/com.github.artemanufrij.webpin.pot | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/po/com.github.artemanufrij.webpin.pot b/po/com.github.artemanufrij.webpin.pot index 87eccd7..3e88a39 100644 --- a/po/com.github.artemanufrij.webpin.pot +++ b/po/com.github.artemanufrij.webpin.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-09 21:07+0400\n" +"POT-Creation-Date: 2017-10-15 19:26+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,24 +17,20 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ../src/WebWindow.vala:61 ../src/Widgets/Assistant.vala:118 +#: ../src/Dialogs/InfoDialog.vala:44 +msgid "Accept" +msgstr "" + +#: ../src/WebWindow.vala:53 +msgid "Copy URI into clipboard" +msgstr "" + +#: ../src/WebWindow.vala:65 ../src/Widgets/Assistant.vala:118 msgid "Run in background when closed" msgstr "" -#: ../src/WebWindow.vala:73 ../src/WebWindow.vala:83 -msgid "Unmute notifications" -msgstr "" - -#: ../src/WebWindow.vala:76 ../src/WebWindow.vala:86 -msgid "Mute notifications" -msgstr "" - -#: ../src/WebWindow.vala:88 -msgid "Desktop notifications are enabled" -msgstr "" - -#: ../src/Dialogs/InfoDialog.vala:44 -msgid "Accept" +#: ../src/WebWindow.vala:115 +msgid "Open %s" msgstr "" #: ../src/MainWindow.vala:56 @@ -61,6 +57,10 @@ msgstr "" msgid "Create a new web app with Webpin" msgstr "" +#: ../src/Widgets/WebApp.vala:94 +msgid "Open request in an external application…" +msgstr "" + #: ../src/Widgets/Assistant.vala:74 msgid "Create a new web app" msgstr "" @@ -124,7 +124,3 @@ msgstr "" #: ../src/Widgets/ApplicationIcon.vala:147 msgid "Edit Webapp Properties" msgstr "" - -#: ../src/Widgets/WebApp.vala:93 -msgid "Open request in an external application…" -msgstr "" From 05f16ebc7206636ccd1a38b277d43a68b97d11fd Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 15 Oct 2017 19:45:04 +0200 Subject: [PATCH 06/31] changed icon --- src/WebWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 116ade8..d55e11a 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -49,7 +49,7 @@ namespace Webpin { headerbar.title = desktop_file.name; headerbar.show_close_button = true; - var copy_url = new Gtk.Button.from_icon_name ("edit-copy-symbolic", Gtk.IconSize.MENU); + var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); copy_url.tooltip_text = _("Copy URI into clipboard"); copy_url.clicked.connect (() => { Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (web_app.app_view.uri, -1); From 717b5628851badead6b01ed343644402c6cbf735 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 15 Oct 2017 19:51:28 +0200 Subject: [PATCH 07/31] changed appdata --- data/com.github.artemanufrij.webpin.appdata.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index a59dcf8..a1a6c75 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -31,4 +31,18 @@ https://raw.githubusercontent.com/artemanufrij/webpin/master/Screenshot_new_app.png + + + +

New:

+
    +
  • Copy current URI into clipboard
  • +
+

Fix:

+
    +
  • Open WebApp on single click instead double click
  • +
+
+
+
From cd8f2ecec36bbf1578989a686c5f8e7ef63739ea Mon Sep 17 00:00:00 2001 From: welaq Date: Wed, 18 Oct 2017 22:56:01 +0300 Subject: [PATCH 08/31] Update lt.po --- po/lt.po | 153 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/po/lt.po b/po/lt.po index f747281..1a42661 100644 --- a/po/lt.po +++ b/po/lt.po @@ -7,88 +7,33 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-08-28 22:31+0300\n" -"PO-Revision-Date: 2017-08-28 22:39+0300\n" +"POT-Creation-Date: 2017-10-18 22:53+0300\n" +"PO-Revision-Date: 2017-10-18 22:55+0300\n" +"Last-Translator: Moo\n" "Language-Team: \n" +"Language: lt\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 1.8.7.1\n" -"Last-Translator: Moo\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);\n" -"Language: lt\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n" +"%100<10 || n%100>=20) ? 1 : 2);\n" #: ../src/Dialogs/InfoDialog.vala:44 msgid "Accept" msgstr "Priimti" -#: ../src/Widgets/ApplicationIcon.vala:142 -msgid "Delete Webapp" -msgstr "Ištrinti saityno programą" +#: ../src/WebWindow.vala:53 +msgid "Copy URI into clipboard" +msgstr "Kopijuoti URI į iškarpinę" -#: ../src/Widgets/ApplicationIcon.vala:147 -msgid "Edit Webapp Properties" -msgstr "Taisyti saityno programos savybes" +#: ../src/WebWindow.vala:65 ../src/Widgets/Assistant.vala:118 +msgid "Run in background when closed" +msgstr "Užvėrus, palikti veikti fone" -#: ../src/Widgets/Assistant.vala:73 -msgid "Create a new web app" -msgstr "Sukurti naują saityno programą" - -#: ../src/Widgets/Assistant.vala:81 -msgid "Application name" -msgstr "Programos pavadinimas" - -#: ../src/Widgets/Assistant.vala:84 -msgid "http://myapp.domain" -msgstr "http://manoprograma.sritis" - -#: ../src/Widgets/Assistant.vala:94 -msgid "theme icon name" -msgstr "temos piktogramos pavadinimas" - -#: ../src/Widgets/Assistant.vala:96 -msgid "or" -msgstr "arba" - -#: ../src/Widgets/Assistant.vala:97 -msgid "Set from file..." -msgstr "Nustatyti iš failo..." - -#: ../src/Widgets/Assistant.vala:113 -msgid "Save cookies" -msgstr "Įrašyti slapukus" - -#: ../src/Widgets/Assistant.vala:115 -msgid "Save login information" -msgstr "Įrašyti prisijungimo informaciją" - -#: ../src/Widgets/Assistant.vala:138 -msgid "Save app" -msgstr "Įrašyti programą" - -#: ../src/Widgets/Assistant.vala:160 -msgid "url must start with http:// or https://" -msgstr "url privalo prasidėti http:// arba https://" - -#: ../src/Widgets/Assistant.vala:173 -msgid "App already exist" -msgstr "Programa jau yra" - -#: ../src/Widgets/Assistant.vala:226 -msgid "Images" -msgstr "Paveikslai" - -#: ../src/Widgets/Assistant.vala:238 -msgid "Cancel" -msgstr "Atsisakyti" - -#: ../src/Widgets/Assistant.vala:239 -msgid "Open" -msgstr "Atverti" - -#: ../src/Widgets/WebApp.vala:93 -msgid "Open request in an external application…" -msgstr "Užklausa atveriama išorinėje programoje…" +#: ../src/WebWindow.vala:115 +msgid "Open %s" +msgstr "Atverti %s" #: ../src/MainWindow.vala:56 msgid "Applications" @@ -113,3 +58,71 @@ msgstr "Sukurti programą" #: ../src/MainWindow.vala:66 msgid "Create a new web app with Webpin" msgstr "Sukurkite naują saityno programą, naudodami Webpin" + +#: ../src/Widgets/WebApp.vala:94 +msgid "Open request in an external application…" +msgstr "Užklausa atveriama išorinėje programoje…" + +#: ../src/Widgets/Assistant.vala:74 +msgid "Create a new web app" +msgstr "Sukurti naują saityno programą" + +#: ../src/Widgets/Assistant.vala:82 +msgid "Application name" +msgstr "Programos pavadinimas" + +#: ../src/Widgets/Assistant.vala:85 +msgid "http://myapp.domain" +msgstr "http://manoprograma.sritis" + +#: ../src/Widgets/Assistant.vala:95 +msgid "theme icon name" +msgstr "temos piktogramos pavadinimas" + +#: ../src/Widgets/Assistant.vala:97 +msgid "or" +msgstr "arba" + +#: ../src/Widgets/Assistant.vala:98 +msgid "Set from file..." +msgstr "Nustatyti iš failo..." + +#: ../src/Widgets/Assistant.vala:114 +msgid "Save cookies" +msgstr "Įrašyti slapukus" + +#: ../src/Widgets/Assistant.vala:116 +msgid "Save login information" +msgstr "Įrašyti prisijungimo informaciją" + +#: ../src/Widgets/Assistant.vala:141 +msgid "Save app" +msgstr "Įrašyti programą" + +#: ../src/Widgets/Assistant.vala:163 +msgid "url must start with http:// or https://" +msgstr "url privalo prasidėti http:// arba https://" + +#: ../src/Widgets/Assistant.vala:176 +msgid "App already exist" +msgstr "Programa jau yra" + +#: ../src/Widgets/Assistant.vala:229 +msgid "Images" +msgstr "Paveikslai" + +#: ../src/Widgets/Assistant.vala:241 +msgid "Cancel" +msgstr "Atsisakyti" + +#: ../src/Widgets/Assistant.vala:242 +msgid "Open" +msgstr "Atverti" + +#: ../src/Widgets/ApplicationIcon.vala:142 +msgid "Delete Webapp" +msgstr "Ištrinti saityno programą" + +#: ../src/Widgets/ApplicationIcon.vala:147 +msgid "Edit Webapp Properties" +msgstr "Taisyti saityno programos savybes" From 41375f154c90ea727521e716d46afd1c0374ab8d Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Wed, 8 Nov 2017 23:13:17 +0100 Subject: [PATCH 09/31] prefer for #43 and #45 --- src/Application.vala | 31 ++++++++++------------ src/Objects/DesktopFile.vala | 22 ++++++++++++++++ src/WebWindow.vala | 3 +++ src/Widgets/Assistant.vala | 50 +++++++++++++++++++++--------------- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 81b0976..5bc25aa 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -31,8 +31,6 @@ namespace Webpin { static WebpinApp _instance = null; - public GLib.List app_list; - public static WebpinApp instance { get { if (_instance == null) @@ -47,7 +45,6 @@ namespace Webpin { application_id = "com.github.artemanufrij.webpin"; app_launcher = application_id + ".desktop"; flags |= GLib.ApplicationFlags.HANDLES_OPEN; - app_list = new GLib.List (); var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING); add_action (open_web_app); @@ -64,6 +61,7 @@ namespace Webpin { protected override void activate () { if (mainwindow != null) { mainwindow.present (); + return; } @@ -73,32 +71,31 @@ namespace Webpin { } public override void open (File[] files, string hint) { - debug ("%s", files [0].get_uri ()); start_webapp (files [0].get_uri ()); } public void start_webapp (string url) { - foreach (var item in app_list) { - debug ("running webapp: %s", item.desktop_file.url); - if (item.desktop_file.url == url) { - debug ("open runing app: %s", url); - item.present (); - return; - } + if (mainwindow != null ) { + mainwindow.present (); + return; } - - debug ("create a new web app: %s", url); var app_info = Webpin.DesktopFile.get_app_by_url (url); var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info); - var app = new WebWindow (desktop_file); - app_list.append (app); - app.destroy.connect (() => { app_list.remove (app); }); - app.set_application (this); + mainwindow = new WebWindow (desktop_file); + mainwindow.set_application (this); } } } static int main (string[] args) { Gtk.init (ref args); var app = Webpin.WebpinApp.instance; + if (args.length > 1) { + var checksum = new GLib.Checksum (GLib.ChecksumType.MD5); + checksum.update (args[1].data, args[1].length); + var id = "a" + checksum.get_string ().substring (0, 5) + "a.artemanufrij.webpin"; + app.application_id = id; + } else { + app.application_id = "com.github.artemanufrij.webpin"; + } return app.run (args); } diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 2cb93bd..f767938 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -63,6 +63,26 @@ namespace Webpin { } } + public Gdk.RGBA? color { + get { + Gdk.RGBA return_value = {0, 0, 0, 255}; + this.file = new GLib.KeyFile(); + try { + file.load_from_file (info.filename, KeyFileFlags.NONE); + var property = file.get_string ("Desktop Entry", "WebpinPrimaryColor"); + if (property == "" || !return_value.parse (property)) { + return null; + } + } catch (Error e) { + warning (e.message); + return null; + } + return return_value; + } set { + edit_propertie ("WebpinPrimaryColor", value.to_string ()); + } + } + public bool mute_notifications { get { this.file = new GLib.KeyFile(); @@ -114,6 +134,8 @@ namespace Webpin { } } + + public bool edit_propertie (string propertie, string val) { bool return_value = false; try { diff --git a/src/WebWindow.vala b/src/WebWindow.vala index fcb0b08..75ed71c 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -41,6 +41,9 @@ namespace Webpin { public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; this.events |= Gdk.EventMask.STRUCTURE_MASK; + if (desktop_file.color != null) { + Granite.Widgets.Utils.set_color_primary (this, desktop_file.color); + } set_wmclass (desktop_file.url, desktop_file.url); web_app = new WebApp (desktop_file.url); diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index 7be9ec8..e917830 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -34,19 +34,20 @@ namespace Webpin { public signal void application_created (GLib.DesktopAppInfo? new_file); public signal void application_edited (GLib.DesktopAppInfo? new_file); - private Gtk.Label message; - private Gtk.Button icon_button; - private Gtk.Entry app_name_entry; - private Gtk.Entry app_url_entry; - private Gtk.Entry icon_name_entry; - private Gtk.CheckButton save_cookies_check; - private Gtk.CheckButton save_password_check; - private Gtk.CheckButton stay_open_when_closed; - private Gtk.Popover icon_selector_popover; - private Gtk.FileChooserDialog file_chooser; - private Gtk.Button accept_button; - private GLib.Regex protocol_regex; - private Gee.HashMap apps; + Gtk.Label message; + Gtk.Button icon_button; + Gtk.Entry app_name_entry; + Gtk.Entry app_url_entry; + Gtk.Entry icon_name_entry; + Gtk.CheckButton save_cookies_check; + Gtk.CheckButton save_password_check; + Gtk.CheckButton stay_open_when_closed; + Gtk.Popover icon_selector_popover; + Gtk.FileChooserDialog file_chooser; + Gtk.Button accept_button; + Gtk.ColorButton primary_color_button; + GLib.Regex protocol_regex; + Gee.HashMap apps; private string default_app_icon = "artemanufrij.webpin"; @@ -107,6 +108,9 @@ namespace Webpin { icon_selector_popover.add (popover_box); + primary_color_button = new Gtk.ColorButton.with_rgba ({ 222, 222, 222, 255 }); + primary_color_button.use_alpha = false; + //TODO: categories //combobox @@ -128,6 +132,7 @@ namespace Webpin { var app_info_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5); app_info_box.pack_start (icon_button, false, false, 3); app_info_box.pack_start (app_input_box, false, false, 3); + app_info_box.pack_start (primary_color_button, false, false, 3); app_info_box.halign = Gtk.Align.CENTER; //app options @@ -204,17 +209,17 @@ namespace Webpin { try { pix = new Gdk.Pixbuf.from_file_at_size (icon, 48, 48); app_icon_valid = true; - } catch (GLib.Error error) { + } catch (GLib.Error error) { app_icon_valid = false; try { Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default (); pix = icon_theme.load_icon ("image-missing", 48, Gtk.IconLookupFlags.FORCE_SIZE); } catch (GLib.Error err) { - warning ("Getting selection-checked icon from theme failed"); + warning ("Getting selection-checked icon from theme failed"); } - } finally { - if (pix != null) - icon_button.set_image (new Gtk.Image.from_pixbuf (pix)); + } + if (pix != null) { + icon_button.set_image (new Gtk.Image.from_pixbuf (pix)); } } else { icon_button.set_image (new Gtk.Image.from_icon_name (icon, Gtk.IconSize.DIALOG) ); @@ -247,16 +252,15 @@ namespace Webpin { preview.valign = Gtk.Align.START; file_chooser.update_preview.connect ( ()=> { - string filename = file_chooser.get_preview_filename(); Gdk.Pixbuf pix = null; if (filename != null) { try { pix = new Gdk.Pixbuf.from_file_at_size (filename, 128, 128); - } catch (GLib.Error error) { + } catch (GLib.Error error) { warning ("There was a problem loading preview."); - } + } } if (pix != null){ @@ -309,6 +313,7 @@ namespace Webpin { if (app_icon_valid && app_name_valid && app_url_valid) { var desktop_file = new DesktopFile (name, url, icon, stay_open); + desktop_file.color = primary_color_button.rgba; switch (mode) { case assistant_mode.new_app: application_created (desktop_file.save_to_file ()); @@ -327,6 +332,9 @@ namespace Webpin { app_url_entry.text = desktop_file.url.replace ("%%", "%"); icon_name_entry.text = desktop_file.icon; stay_open_when_closed.active = desktop_file.hide_on_close; + if (desktop_file.color != null) { + primary_color_button.set_rgba (desktop_file.color); + } update_app_icon (); } } From f0ecf5e173358359d81f211233738e5388b97dd7 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Wed, 8 Nov 2017 23:40:54 +0100 Subject: [PATCH 10/31] small fixes --- src/Application.vala | 4 ---- src/Objects/DesktopFile.vala | 4 +++- src/Widgets/Assistant.vala | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 5bc25aa..1a2023a 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -42,7 +42,6 @@ namespace Webpin { construct { program_name = "Webpin"; exec_name = "com.github.artemanufrij.webpin"; - application_id = "com.github.artemanufrij.webpin"; app_launcher = application_id + ".desktop"; flags |= GLib.ApplicationFlags.HANDLES_OPEN; @@ -61,12 +60,9 @@ namespace Webpin { protected override void activate () { if (mainwindow != null) { mainwindow.present (); - return; } - mainwindow = new MainWindow (); - mainwindow.destroy.connect (() => { mainwindow = null; }); mainwindow.set_application(this); } diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index f767938..0f2e119 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -79,7 +79,9 @@ namespace Webpin { } return return_value; } set { - edit_propertie ("WebpinPrimaryColor", value.to_string ()); + if (value != null) { + edit_propertie ("WebpinPrimaryColor", value.to_string ()); + } } } diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index e917830..c05317f 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -313,7 +313,6 @@ namespace Webpin { if (app_icon_valid && app_name_valid && app_url_valid) { var desktop_file = new DesktopFile (name, url, icon, stay_open); - desktop_file.color = primary_color_button.rgba; switch (mode) { case assistant_mode.new_app: application_created (desktop_file.save_to_file ()); @@ -322,6 +321,7 @@ namespace Webpin { application_edited (desktop_file.save_to_file ()); break; } + desktop_file.color = primary_color_button.rgba; } } @@ -334,6 +334,8 @@ namespace Webpin { stay_open_when_closed.active = desktop_file.hide_on_close; if (desktop_file.color != null) { primary_color_button.set_rgba (desktop_file.color); + } else { + primary_color_button.set_rgba ({ 222, 222, 222, 255 }); } update_app_icon (); } From e37362bd5a0c94da4db7b58f79fc34c2e826271e Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Thu, 9 Nov 2017 20:09:10 +0100 Subject: [PATCH 11/31] switch to dark theme for dark colors --- src/WebWindow.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index c78fb53..1ecf628 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -42,6 +42,10 @@ namespace Webpin { this.desktop_file = desktop_file; this.events |= Gdk.EventMask.STRUCTURE_MASK; if (desktop_file.color != null) { + var mid = desktop_file.color.red + desktop_file.color.blue + desktop_file.color.green; + if (mid / 3 < 0.3) { + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; + } Granite.Widgets.Utils.set_color_primary (this, desktop_file.color); } From 32d31f52d87635e2c3be38f8e3681b8ffdd531cb Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Fri, 10 Nov 2017 18:10:13 +0100 Subject: [PATCH 12/31] appdata.xml --- .../com.github.artemanufrij.webpin.appdata.xml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index a1a6c75..648d940 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -7,7 +7,7 @@ Webpin A simple app to pin websites on the desktop -

Pin your any favorite website on Applications Menu or Plank like a regular desktop app

+

Create your own WebApps. Pin your any favorite website on Applications Menu or Plank like a regular desktop app.

Utility @@ -32,6 +32,22 @@ + + +

New:

+
    +
  • Set custom color for headerbar
  • +
+

Fix:

+
    +
  • Open application on clicking desktop notification
  • +
+

Translation:

+
    +
  • Lithuanian (by welaq)
  • +
+
+

New:

From 5346864d95b7f9eaf36c762584730a31d41751df Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 12 Nov 2017 12:04:04 +0100 Subject: [PATCH 13/31] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 78758be..f430506 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,6 @@ Webpin is a fork of Webby created by Erasmo Marín Pin your any favourite website on Applications Menu or Plank like a regular desktop app ![Apps](Apps.png) + +## Donations +If you liked _Webpin_, and would like to support it's development of this app and more, consider [buying me a coffee](https://www.paypal.me/ArtemAnufrij) :) From 262a807f3ce3fd3e9fc6c813cc0f94f3047ac345 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 12 Nov 2017 12:32:36 +0100 Subject: [PATCH 14/31] fix setting custom colors --- src/Objects/DesktopFile.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 0f2e119..99ae289 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -80,7 +80,8 @@ namespace Webpin { return return_value; } set { if (value != null) { - edit_propertie ("WebpinPrimaryColor", value.to_string ()); + var color = "#%02x%02x%02x".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); + edit_propertie ("WebpinPrimaryColor", color); } } } From 9eaf20aec0ddd601e35b4850322d4d44b1122698 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 12 Nov 2017 12:34:04 +0100 Subject: [PATCH 15/31] appdata.xml --- data/com.github.artemanufrij.webpin.appdata.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index 648d940..554d8df 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

Fix:

+
    +
  • Set custom color for headerbar
  • +
+
+

New:

From 0d3553fbe8c09afa4970d0daaa10dba25ada0c4e Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Thu, 16 Nov 2017 21:54:36 +0100 Subject: [PATCH 16/31] appdata.xml --- data/com.github.artemanufrij.webpin.appdata.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index 554d8df..b1a38e9 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

Fix:

+
    +
  • Set custom color for headerbar
  • +
+
+

Fix:

From 960f5467b300a960853cef9658dfe1e692288563 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sat, 18 Nov 2017 22:31:28 +0100 Subject: [PATCH 17/31] fixed icon name --- data/com.github.artemanufrij.webpin.appdata.xml | 8 ++++++++ data/com.github.artemanufrij.webpin.desktop | 2 +- ...frij.webpin.svg => com.github.artemanufrij.webpin.svg} | 0 ...frij.webpin.svg => com.github.artemanufrij.webpin.svg} | 0 ...frij.webpin.svg => com.github.artemanufrij.webpin.svg} | 0 5 files changed, 9 insertions(+), 1 deletion(-) rename data/icons/32/{artemanufrij.webpin.svg => com.github.artemanufrij.webpin.svg} (100%) rename data/icons/48/{artemanufrij.webpin.svg => com.github.artemanufrij.webpin.svg} (100%) rename data/icons/{artemanufrij.webpin.svg => com.github.artemanufrij.webpin.svg} (100%) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index b1a38e9..f3bf6df 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

Fix:

+
    +
  • Desktop icon name
  • +
+
+

Fix:

diff --git a/data/com.github.artemanufrij.webpin.desktop b/data/com.github.artemanufrij.webpin.desktop index 76c3f9b..3bde0e9 100644 --- a/data/com.github.artemanufrij.webpin.desktop +++ b/data/com.github.artemanufrij.webpin.desktop @@ -5,7 +5,7 @@ Comment=Pin your websites on your desktop Comment[lt]=Prisegti interneto svetaines savo darbalaukyje Keywords=internet;webapp; Exec=com.github.artemanufrij.webpin %u -Icon=artemanufrij.webpin +Icon=com.github.artemanufrij.webpin Terminal=false Type=Application Categories=Network;GNOME;GTK; diff --git a/data/icons/32/artemanufrij.webpin.svg b/data/icons/32/com.github.artemanufrij.webpin.svg similarity index 100% rename from data/icons/32/artemanufrij.webpin.svg rename to data/icons/32/com.github.artemanufrij.webpin.svg diff --git a/data/icons/48/artemanufrij.webpin.svg b/data/icons/48/com.github.artemanufrij.webpin.svg similarity index 100% rename from data/icons/48/artemanufrij.webpin.svg rename to data/icons/48/com.github.artemanufrij.webpin.svg diff --git a/data/icons/artemanufrij.webpin.svg b/data/icons/com.github.artemanufrij.webpin.svg similarity index 100% rename from data/icons/artemanufrij.webpin.svg rename to data/icons/com.github.artemanufrij.webpin.svg From b5ff5d1c4f4dad4aaef782d1b7700d67477a8bc4 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sat, 18 Nov 2017 22:37:23 +0100 Subject: [PATCH 18/31] fixed CMakeList.txt --- data/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 33f3fdc..b91ec4e 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,8 +1,8 @@ install (FILES com.github.artemanufrij.webpin.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications) install (FILES com.github.artemanufrij.webpin.appdata.xml DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/metainfo) -install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/) -install (FILES icons/32/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/32x32/apps/) -install (FILES icons/48/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps/) -install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/64x64/apps/) -install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/128x128/apps/) +install (FILES icons/com.github.artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/) +install (FILES icons/32/com.github.artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/32x32/apps/) +install (FILES icons/48/com.github.artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps/) +install (FILES icons/com.github.artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/64x64/apps/) +install (FILES icons/com.github.artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/128x128/apps/) From 3d1dbda54502c6bab8d4529b05689549987c9259 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sat, 18 Nov 2017 23:34:21 +0100 Subject: [PATCH 19/31] changed default icon --- src/Widgets/Assistant.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index c05317f..b180de0 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -49,7 +49,7 @@ namespace Webpin { GLib.Regex protocol_regex; Gee.HashMap apps; - private string default_app_icon = "artemanufrij.webpin"; + private string default_app_icon = "com.github.artemanufrij.webpin"; private bool app_name_valid = false; private bool app_url_valid = false; From f7b4eeb2d807443ed75b0e69cb7897b271c30d47 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 19 Nov 2017 00:26:09 +0100 Subject: [PATCH 20/31] fixed custom color --- data/com.github.artemanufrij.webpin.appdata.xml | 8 ++++++++ debian/changelog | 6 ++++++ debian/changelog~ | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 debian/changelog~ diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index f3bf6df..7fff5df 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

Fix:

+
    +
  • Set custom color
  • +
+
+

Fix:

diff --git a/debian/changelog b/debian/changelog index 4dcf9ad..5f47cfc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +com.github.artemanufrij.webpin (0.2.1) xenial; urgency=low + + * Fixed custom color. + + -- Artem Anufrij Sun, 19 Nov 2017 04:53:39 +0100 + com.github.artemanufrij.webpin (0.1.3) xenial; urgency=low * Initial Release. diff --git a/debian/changelog~ b/debian/changelog~ new file mode 100644 index 0000000..4dcf9ad --- /dev/null +++ b/debian/changelog~ @@ -0,0 +1,5 @@ +com.github.artemanufrij.webpin (0.1.3) xenial; urgency=low + + * Initial Release. + + -- Artem Anufrij Mon, 31 Jul 2017 04:53:39 +0100 From 58674f1217ee807a860faaa05fdb633934a1331c Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 19 Nov 2017 00:49:02 +0100 Subject: [PATCH 21/31] fixed .desktop properties --- ...com.github.artemanufrij.webpin.appdata.xml | 8 +++++++ debian/changelog~ | 5 ---- src/Objects/DesktopFile.vala | 21 ++++------------ src/WebWindow.vala | 24 +++++++++---------- src/Widgets/WebApp.vala | 2 +- 5 files changed, 25 insertions(+), 35 deletions(-) delete mode 100644 debian/changelog~ diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index 7fff5df..d7218e3 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

Fix:

+
    +
  • Custom settings in .desktop
  • +
+
+

Fix:

diff --git a/debian/changelog~ b/debian/changelog~ deleted file mode 100644 index 4dcf9ad..0000000 --- a/debian/changelog~ +++ /dev/null @@ -1,5 +0,0 @@ -com.github.artemanufrij.webpin (0.1.3) xenial; urgency=low - - * Initial Release. - - -- Artem Anufrij Mon, 31 Jul 2017 04:53:39 +0100 diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 99ae289..2d3f129 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -55,7 +55,7 @@ namespace Webpin { this.file = new GLib.KeyFile(); try { file.load_from_file (info.filename, KeyFileFlags.NONE); - return file.get_string ("Desktop Entry", "WebpinStayOpen") == "true"; + return file.get_string ("Desktop Entry", "X-Webpin-StayOpen") == "true"; } catch (Error e) { warning (e.message); } @@ -69,7 +69,7 @@ namespace Webpin { this.file = new GLib.KeyFile(); try { file.load_from_file (info.filename, KeyFileFlags.NONE); - var property = file.get_string ("Desktop Entry", "WebpinPrimaryColor"); + var property = file.get_string ("Desktop Entry", "X-Webpin-PrimaryColor"); if (property == "" || !return_value.parse (property)) { return null; } @@ -81,24 +81,11 @@ namespace Webpin { } set { if (value != null) { var color = "#%02x%02x%02x".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); - edit_propertie ("WebpinPrimaryColor", color); + edit_propertie ("X-Webpin-PrimaryColor", color); } } } - public bool mute_notifications { - get { - this.file = new GLib.KeyFile(); - try { - file.load_from_file (info.filename, KeyFileFlags.NONE); - return file.get_string ("Desktop Entry", "WebpinMuteNotifications") == "true"; - } catch (Error e) { - warning (e.message); - } - return false; - } - } - public DesktopFile (string name, string url, string icon, bool stay_open) { this.name = name; this.url = url.replace ("%", "%%"); @@ -117,7 +104,7 @@ namespace Webpin { file.set_string ("Desktop Entry", "Exec", "com.github.artemanufrij.webpin " + url); file.set_string ("Desktop Entry", "Icon", icon); file.set_string ("Desktop Entry", "StartupWMClass", url); - file.set_string ("Desktop Entry", "WebpinStayOpen", stay_open.to_string ()); + file.set_string ("Desktop Entry", "X-Webpin-StayOpen", stay_open.to_string ()); } public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) { diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 1ecf628..3688ae4 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -72,17 +72,17 @@ namespace Webpin { stay_open.tooltip_text = _("Run in background when closed"); stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); stay_open.toggled.connect (() => { - desktop_file.edit_propertie ("WebpinStayOpen", stay_open.active.to_string ()); + desktop_file.edit_propertie ("X-Webpin-StayOpen", stay_open.active.to_string ()); desktop_file.save_to_file (); }); headerbar.pack_start (stay_open); this.set_titlebar (headerbar); - var width = desktop_file.info.get_string ("WebpinWindowWidth"); - var height = desktop_file.info.get_string ("WebpinWindowHeight"); - var state = desktop_file.info.get_string ("WebpinWindowMaximized"); - var zoom = desktop_file.info.get_string ("WebpinWindowZoom"); + var width = desktop_file.info.get_string ("X-Webpin-WindowWidth"); + var height = desktop_file.info.get_string ("X-Webpin-WindowHeight"); + var state = desktop_file.info.get_string ("X-Webpin-WindowMaximized"); + var zoom = desktop_file.info.get_string ("X-Webpin-WindowZoom"); if (width != null && height != null) { set_default_size (int.parse(width), int.parse(height)); @@ -159,11 +159,11 @@ namespace Webpin { var file = web_app.get_desktop_file(); if (is_maximized) { - file.edit_propertie ("WebpinWindowMaximized", "max"); + file.edit_propertie ("X-Webpin-WindowMaximized", "max"); } else { - file.edit_propertie ("WebpinWindowWidth", width.to_string()); - file.edit_propertie ("WebpinWindowHeight", height.to_string()); - file.edit_propertie ("WebpinWindowMaximized", "norm"); + file.edit_propertie ("X-Webpin-WindowWidth", width.to_string()); + file.edit_propertie ("X-Webpin-WindowHeight", height.to_string()); + file.edit_propertie ("X-Webpin-WindowMaximized", "norm"); } } @@ -180,7 +180,7 @@ namespace Webpin { case Gdk.Key.plus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { web_app.app_view.zoom_level += 0.1; - web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ()); + web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); } else { handled = false; } @@ -189,7 +189,7 @@ namespace Webpin { case Gdk.Key.minus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { web_app.app_view.zoom_level -= 0.1; - web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ()); + web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); } else { handled = false; } @@ -198,7 +198,7 @@ namespace Webpin { case Gdk.Key.@0: if (Gdk.ModifierType.CONTROL_MASK in event.state) { web_app.app_view.zoom_level = 1; - web_app.get_desktop_file().edit_propertie ("WebpinWindowZoom", web_app.app_view.zoom_level.to_string ()); + web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); } else { handled = false; } diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index 45adb15..f277b74 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -110,7 +110,7 @@ namespace Webpin { icon_for_notification = GLib.Icon.new_for_string (file.icon); } catch (Error e) { warning (e.message); - icon = new Gtk.Image.from_icon_name ("artemanufrij.webpin", Gtk.IconSize.DIALOG); + icon = new Gtk.Image.from_icon_name ("com.github.artemanufrij.webpin", Gtk.IconSize.DIALOG); } } else { icon = new Gtk.Image.from_icon_name (file.icon, Gtk.IconSize.DIALOG); From 906ff061408ad1ed24abdd4349e8ea50c705c0bb Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 19 Nov 2017 01:34:39 +0100 Subject: [PATCH 22/31] improved color check --- src/WebWindow.vala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 3688ae4..313c813 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -41,12 +41,14 @@ namespace Webpin { public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; this.events |= Gdk.EventMask.STRUCTURE_MASK; - if (desktop_file.color != null) { - var mid = desktop_file.color.red + desktop_file.color.blue + desktop_file.color.green; + + var color = desktop_file.color; + if (color != null) { + var mid = color.red + color.blue + color.green; if (mid / 3 < 0.3) { Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; } - Granite.Widgets.Utils.set_color_primary (this, desktop_file.color); + Granite.Widgets.Utils.set_color_primary (this, color); } set_wmclass (desktop_file.url, desktop_file.url); From d7c7557ece1931c016e448de9ebab64cc84bd271 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 19 Nov 2017 12:28:44 +0100 Subject: [PATCH 23/31] fix custom color --- ...com.github.artemanufrij.webpin.appdata.xml | 10 ++++++- src/Objects/DesktopFile.vala | 27 +++++++++++-------- src/WebWindow.vala | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index d7218e3..a7b87f0 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,7 +32,15 @@ - + + +

Fix:

+
    +
  • Custom settings in .desktop
  • +
+
+
+

Fix:

    diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 2d3f129..091c941 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -63,24 +63,29 @@ namespace Webpin { } } + Gdk.RGBA? _color; public Gdk.RGBA? color { get { - Gdk.RGBA return_value = {0, 0, 0, 255}; - this.file = new GLib.KeyFile(); - try { - file.load_from_file (info.filename, KeyFileFlags.NONE); - var property = file.get_string ("Desktop Entry", "X-Webpin-PrimaryColor"); - if (property == "" || !return_value.parse (property)) { + if (_color == null) { + Gdk.RGBA return_value = {0, 0, 0, 0}; + this.file = new GLib.KeyFile(); + try { + file.load_from_file (info.filename, KeyFileFlags.NONE); + var property = file.get_string ("Desktop Entry", "X-Webpin-PrimaryColor"); + if (property == "" || !return_value.parse (property)) { + return null; + } + } catch (Error e) { + warning (e.message); return null; } - } catch (Error e) { - warning (e.message); - return null; + _color = return_value; } - return return_value; + return _color; } set { if (value != null) { - var color = "#%02x%02x%02x".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); + _color = value; + var color = "rgba (%d,%d,%d,1)".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); edit_propertie ("X-Webpin-PrimaryColor", color); } } diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 313c813..f532380 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -45,7 +45,7 @@ namespace Webpin { var color = desktop_file.color; if (color != null) { var mid = color.red + color.blue + color.green; - if (mid / 3 < 0.3) { + if (mid / 3 < 0.5) { Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; } Granite.Widgets.Utils.set_color_primary (this, color); From 57160bd4dbc5798745b699be9ef907a290018d50 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 00:07:55 +0100 Subject: [PATCH 24/31] code clean up --- ...com.github.artemanufrij.webpin.appdata.xml | 8 + ...com.github.artemanufrij.webpin.gschema.xml | 5 + src/Application.vala | 13 +- src/CMakeLists.txt | 4 +- src/Dialogs/InfoDialog.vala | 47 ---- src/Dialogs/Preferences.vala | 77 ++++++ src/MainWindow.vala | 75 ++++-- src/Objects/DesktopFile.vala | 116 +++------ src/Services/DesktopFilesManager.vala | 66 +++++ src/Settings.vala | 5 +- src/UrlEntry.vala | 41 ---- src/WebWindow.vala | 230 +++++++++--------- src/Widgets/ApplicationIcon.vala | 8 +- src/Widgets/ApplicationsView.vala | 14 +- src/Widgets/Assistant.vala | 75 +++--- src/Widgets/WebApp.vala | 112 ++++----- 16 files changed, 466 insertions(+), 430 deletions(-) delete mode 100644 src/Dialogs/InfoDialog.vala create mode 100644 src/Dialogs/Preferences.vala create mode 100644 src/Services/DesktopFilesManager.vala delete mode 100644 src/UrlEntry.vala diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index a7b87f0..fda1276 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,6 +32,14 @@ + + +

    New:

    +
      +
    • Option for Dark Theme
    • +
    +
    +

    Fix:

    diff --git a/schemas/com.github.artemanufrij.webpin.gschema.xml b/schemas/com.github.artemanufrij.webpin.gschema.xml index 44cfdcd..4576dd6 100644 --- a/schemas/com.github.artemanufrij.webpin.gschema.xml +++ b/schemas/com.github.artemanufrij.webpin.gschema.xml @@ -20,5 +20,10 @@ The saved state of the window. The saved state of the window. + + false + Use Dark Theme. + Use Dark Theme. + diff --git a/src/Application.vala b/src/Application.vala index 1a2023a..468ab18 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -27,7 +27,7 @@ */ namespace Webpin { - public class WebpinApp : Granite.Application { + public class WebpinApp : Gtk.Application { static WebpinApp _instance = null; @@ -40,16 +40,12 @@ namespace Webpin { } construct { - program_name = "Webpin"; - exec_name = "com.github.artemanufrij.webpin"; - app_launcher = application_id + ".desktop"; flags |= GLib.ApplicationFlags.HANDLES_OPEN; var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING); add_action (open_web_app); open_web_app.activate.connect ((parameter) => { if (parameter != null) { - debug ("start web app over action: '%s'", parameter.get_string ()); start_webapp (parameter.get_string ()); } }); @@ -63,7 +59,7 @@ namespace Webpin { return; } mainwindow = new MainWindow (); - mainwindow.set_application(this); + mainwindow.set_application (this); } public override void open (File[] files, string hint) { @@ -75,13 +71,14 @@ namespace Webpin { mainwindow.present (); return; } - var app_info = Webpin.DesktopFile.get_app_by_url (url); - var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info); + var app_info = Services.DesktopFilesManager.get_app_by_url (url); + var desktop_file = new Webpin.DesktopFile.from_desktopappinfo (app_info); mainwindow = new WebWindow (desktop_file); mainwindow.set_application (this); } } } + static int main (string[] args) { Gtk.init (ref args); var app = Webpin.WebpinApp.instance; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 62d9098..26b049c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,9 +4,9 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME} Widgets/Assistant.vala Widgets/WebApp.vala Objects/DesktopFile.vala - Dialogs/InfoDialog.vala + Dialogs/Preferences.vala + Services/DesktopFilesManager.vala Settings.vala - UrlEntry.vala MainWindow.vala WebWindow.vala Application.vala diff --git a/src/Dialogs/InfoDialog.vala b/src/Dialogs/InfoDialog.vala deleted file mode 100644 index 596ae38..0000000 --- a/src/Dialogs/InfoDialog.vala +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 2015 Erasmo Marín - * Copyright (c) 2017-2017 Artem Anufrij - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * The Noise authors hereby grant permission for non-GPL compatible - * GStreamer plugins to be used and distributed together with GStreamer - * and Noise. This permission is above and beyond the permissions granted - * by the GPL license by which Noise is covered. If you modify this code - * you may extend this exception to your version of the code, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * - * Authored by: Artem Anufrij - */ - -namespace Webpin { - public class InfoDialog : Gtk.Dialog { - public InfoDialog (string title, string label, string icon_name) { - - this.title = title; - set_default_size (350, 100); - - var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5); - box.pack_start (new Gtk.Image.from_icon_name(icon_name, Gtk.IconSize.DIALOG), false, false, 0); - box.pack_start (new Gtk.Label (label), true, false, 0); - box.margin = 15; - - Gtk.Box content = get_content_area () as Gtk.Box; - content.pack_start (box, true, true, 0); - - add_button (_("Accept"), Gtk.ResponseType.ACCEPT); - } - } -} diff --git a/src/Dialogs/Preferences.vala b/src/Dialogs/Preferences.vala new file mode 100644 index 0000000..81b77e6 --- /dev/null +++ b/src/Dialogs/Preferences.vala @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ + +namespace Webpin.Dialogs { + public class Preferences : Gtk.Dialog { + Webpin.Settings settings; + + construct { + settings = Webpin.Settings.get_default (); + } + + public Preferences (Gtk.Window parent) { + Object ( + transient_for: parent + ); + build_ui (); + + this.response.connect ((source, response_id) => { + switch (response_id) { + case Gtk.ResponseType.CLOSE: + destroy (); + break; + } + }); + } + + private void build_ui () { + this.resizable = false; + var content = get_content_area () as Gtk.Box; + + var grid = new Gtk.Grid (); + grid.column_spacing = 12; + grid.row_spacing = 12; + grid.margin = 12; + + var use_dark_theme_label = new Gtk.Label (_("Use Dark Theme")); + use_dark_theme_label.halign = Gtk.Align.START; + var use_dark_theme = new Gtk.Switch (); + use_dark_theme.active = settings.use_dark_theme; + use_dark_theme.notify["active"].connect (() => { + settings.use_dark_theme = use_dark_theme.active; + }); + + grid.attach (use_dark_theme_label, 0, 0); + grid.attach (use_dark_theme, 1, 0); + + content.pack_start (grid, false, false, 0); + + this.add_button ("_Close", Gtk.ResponseType.CLOSE); + this.show_all (); + } + } +} diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 687ccc5..89368a1 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -28,23 +28,35 @@ namespace Webpin { public class MainWindow : Gtk.ApplicationWindow { - private Settings settings; + Settings settings; - private Gtk.Stack stack; - private Gtk.HeaderBar headerbar; - private Gtk.Button back_button; - private Gtk.Button add_button; + Gtk.Stack stack; + Gtk.HeaderBar headerbar; + Gtk.Button back_button; + Gtk.Button add_button; + Gtk.MenuButton app_menu; - private Assistant assistant; - private ApplicationsView apps_view; + Assistant assistant; + ApplicationsView apps_view; + + construct { + settings = Settings.get_default (); + settings.notify["use-dark-theme"].connect (() => { + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.use_dark_theme; + if (settings.use_dark_theme) { + app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR)); + } else { + app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR)); + } + }); + } public MainWindow () { - settings = Settings.get_default (); - build_ui (); } private void build_ui () { + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.use_dark_theme; set_default_size (700, 500); //headerbar @@ -55,6 +67,7 @@ namespace Webpin { back_button = new Gtk.Button.with_label (_("Applications")); back_button.get_style_context ().add_class ("back-button"); + back_button.valign = Gtk.Align.CENTER; headerbar.pack_start (back_button); add_button = new Gtk.Button (); @@ -62,6 +75,27 @@ namespace Webpin { add_button.tooltip_text = _("Add a new Web App"); headerbar.pack_start (add_button); + // SETTINGS MENU + app_menu = new Gtk.MenuButton (); + if (settings.use_dark_theme) { + app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR)); + } else { + app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR)); + } + + var settings_menu = new Gtk.Menu (); + var menu_item_preferences = new Gtk.MenuItem.with_label (_("Preferences")); + menu_item_preferences.activate.connect (() => { + var preferences = new Dialogs.Preferences (this); + preferences.run (); + }); + + settings_menu.append (menu_item_preferences); + settings_menu.show_all (); + + app_menu.popup = settings_menu; + headerbar.pack_end (app_menu); + var welcome = new Granite.Widgets.Welcome (_("No Web Apps Available"), _("Manage your web apps.")); welcome.append ("document-new", _("Create App"), _("Create a new web app with Webpin")); welcome.activated.connect ((index) => { @@ -109,10 +143,11 @@ namespace Webpin { }); back_button.clicked.connect (() => { - if (apps_view.has_items) + if (apps_view.has_items) { show_apps_view (); - else + } else { show_welcome_view (); + } }); add_button.clicked.connect (() => { @@ -127,10 +162,11 @@ namespace Webpin { this.restore_settings (); show_all (); - if (apps_view.has_items) + if (apps_view.has_items) { show_apps_view (Gtk.StackTransitionType.NONE); - else + } else { show_welcome_view (Gtk.StackTransitionType.NONE); + } this.present (); } @@ -140,11 +176,7 @@ namespace Webpin { stack.set_visible_child_name("assistant"); back_button.show_all (); add_button.hide (); - //fix ugly border at the bottom of headerbar - queue_draw (); - - if (desktop_file != null) - assistant.edit_desktop_file (desktop_file); + assistant.edit_desktop_file (desktop_file); } private void show_apps_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { @@ -153,8 +185,6 @@ namespace Webpin { back_button.hide (); add_button.show_all (); assistant.reset_fields (); - //fix ugly border at the bottom of headerbar - queue_draw (); } private void show_welcome_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { @@ -163,15 +193,14 @@ namespace Webpin { back_button.hide (); add_button.hide (); assistant.reset_fields (); - //fix ugly border at the bottom of headerbar - queue_draw (); } private void restore_settings () { this.set_default_size (settings.window_width, settings.window_height); - if (settings.window_state == Settings.WindowState.MAXIMIZED) + if (settings.window_state == Settings.WindowState.MAXIMIZED) { this.maximize (); + } } private void store_settings () { diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 091c941..ff0094d 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -29,7 +29,7 @@ namespace Webpin { public class DesktopFile : GLib.Object { - private string template = """ + string template = """ [Desktop Entry] Name=Webpin GenericName=Web app @@ -42,9 +42,10 @@ namespace Webpin { Categories=Network; X-GNOME-FullName=webpin StartupWMClass=Webpin - WebpinThemeColor=none"""; + X-Webpin-PrimaryColor=none"""; + + GLib.KeyFile file; - private GLib.KeyFile file; public DesktopAppInfo info { get; set; } public string name { get; private set; } @@ -52,12 +53,11 @@ namespace Webpin { public string icon { get; private set; } public bool hide_on_close { get { - this.file = new GLib.KeyFile(); try { file.load_from_file (info.filename, KeyFileFlags.NONE); return file.get_string ("Desktop Entry", "X-Webpin-StayOpen") == "true"; - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } return false; } @@ -67,16 +67,15 @@ namespace Webpin { public Gdk.RGBA? color { get { if (_color == null) { - Gdk.RGBA return_value = {0, 0, 0, 0}; - this.file = new GLib.KeyFile(); + Gdk.RGBA return_value = {0, 0, 0, 1}; try { file.load_from_file (info.filename, KeyFileFlags.NONE); var property = file.get_string ("Desktop Entry", "X-Webpin-PrimaryColor"); if (property == "" || !return_value.parse (property)) { return null; } - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); return null; } _color = return_value; @@ -85,8 +84,10 @@ namespace Webpin { } set { if (value != null) { _color = value; - var color = "rgba (%d,%d,%d,1)".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); - edit_propertie ("X-Webpin-PrimaryColor", color); + var color = "rgba(%d,%d,%d,1)".printf ((int)(value.red * 255), (int)(value.green * 255), (int)(value.blue * 255)); + edit_property ("X-Webpin-PrimaryColor", color); + } else { + edit_property ("X-Webpin-PrimaryColor", "none"); } } } @@ -99,10 +100,10 @@ namespace Webpin { file = new GLib.KeyFile(); try { file.load_from_data (template, -1, GLib.KeyFileFlags.NONE); - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } - //TODO: Category + file.set_string ("Desktop Entry", "Name", name); file.set_string ("Desktop Entry", "GenericName", name); file.set_string ("Desktop Entry", "X-GNOME-FullName", name); @@ -112,35 +113,33 @@ namespace Webpin { file.set_string ("Desktop Entry", "X-Webpin-StayOpen", stay_open.to_string ()); } - public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) { + public DesktopFile.from_desktopappinfo (GLib.DesktopAppInfo info) { this.info = info; this.file = new GLib.KeyFile(); try { file.load_from_file (info.filename, KeyFileFlags.NONE); - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } this.name = info.get_display_name (); this.icon = info.get_icon ().to_string (); try { this.url = file.get_string ("Desktop Entry", "Exec").substring (31); - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } } - - - public bool edit_propertie (string propertie, string val) { + public bool edit_property (string propertie, string val) { bool return_value = false; try { - string filename = GLib.Environment.get_user_data_dir () + "/applications/" + file.get_string("Desktop Entry", "Name") + "-webpin.desktop"; - file = new GLib.KeyFile(); + string filename = GLib.Environment.get_user_data_dir () + "/applications/" + file.get_string ("Desktop Entry", "Name") + "-webpin.desktop"; + file = new GLib.KeyFile (); file.load_from_file (filename, KeyFileFlags.NONE); file.set_string ("Desktop Entry", propertie, val); return_value = file.save_to_file (filename); - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } return return_value; @@ -149,76 +148,25 @@ namespace Webpin { public GLib.DesktopAppInfo save_to_file () { GLib.DesktopAppInfo return_value = null; try { - string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string("Desktop Entry", "Name") + "-webpin.desktop"; - print("Desktop file created: " + filename); + string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string ("Desktop Entry", "Name") + "-webpin.desktop"; file.save_to_file (filename); return_value = new GLib.DesktopAppInfo.from_filename (filename); - } catch (Error e) { - warning (e.message); + } catch (Error err) { + warning (err.message); } return return_value; } public bool delete_file () { try { - string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string("Desktop Entry", "Name") + "-webpin.desktop"; + string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string ("Desktop Entry", "Name") + "-webpin.desktop"; File file = File.new_for_path (filename); file.delete (); - } catch (Error e) { - print(e.message + "\n"); + } catch (Error err) { + warning (err.message); return false; } return true; } - - public static Gee.HashMap get_webpin_applications () { - - var list = new Gee.HashMap(); - - foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { - - var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); - - //FIXME: This is not working, vala problem? - //var keywords = desktop_app.get_keywords (); - - string keywords = desktop_app.get_string ("Keywords"); - - if (keywords != null && keywords.contains ("webpin")) { - debug (desktop_app.get_name()); - list.set(desktop_app.get_name(), desktop_app); - } - } - return list; - } - - public static GLib.DesktopAppInfo? get_app_by_url (string url) { - foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { - - var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); - - var exec = desktop_app.get_string ("Exec"); - - if (exec != null) { - exec = exec.replace ("%%", "%"); - if (exec.contains (url)) { - return desktop_app; - } - } - } - return null; - } - - public static Gee.HashMap get_applications() { - - var list = new Gee.HashMap(); - - foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { - debug (app.get_name()); - list.set(app.get_name(), app); - } - - return list; - } } } diff --git a/src/Services/DesktopFilesManager.vala b/src/Services/DesktopFilesManager.vala new file mode 100644 index 0000000..8d4b4ee --- /dev/null +++ b/src/Services/DesktopFilesManager.vala @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2017-2017 Artem Anufrij + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * The Noise authors hereby grant permission for non-GPL compatible + * GStreamer plugins to be used and distributed together with GStreamer + * and Noise. This permission is above and beyond the permissions granted + * by the GPL license by which Noise is covered. If you modify this code + * you may extend this exception to your version of the code, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * + * Authored by: Artem Anufrij + */ + +namespace Webpin.Services { + public class DesktopFilesManager { + public static GLib.DesktopAppInfo? get_app_by_url (string url) { + foreach (GLib.AppInfo app in GLib.AppInfo.get_all ()) { + var desktop_app = new GLib.DesktopAppInfo (app.get_id ()); + var exec = desktop_app.get_string ("Exec"); + if (exec != null) { + exec = exec.replace ("%%", "%"); + if (exec.contains (url)) { + return desktop_app; + } + } + } + return null; + } + + public static Gee.HashMap get_applications() { + var list = new Gee.HashMap(); + foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { + list.set(app.get_name(), app); + } + return list; + } + + public static Gee.HashMap get_webpin_applications () { + var list = new Gee.HashMap(); + + foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { + var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); + + string keywords = desktop_app.get_string ("Keywords"); + if (keywords != null && keywords.contains ("webpin")) { + list.set(desktop_app.get_name(), desktop_app); + } + } + return list; + } + } +} diff --git a/src/Settings.vala b/src/Settings.vala index 2170de1..3fc760d 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -31,14 +31,15 @@ namespace Webpin { private static Settings settings; public static Settings get_default () { - if (settings == null) + if (settings == null) { settings = new Settings (); - + } return settings; } public int window_width { get; set; } public int window_height { get; set; } public WindowState window_state { get; set; } + public bool use_dark_theme { get; set; } private Settings () { base ("com.github.artemanufrij.webpin"); diff --git a/src/UrlEntry.vala b/src/UrlEntry.vala deleted file mode 100644 index c0fa3d8..0000000 --- a/src/UrlEntry.vala +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 2015 Erasmo Marín - * Copyright (c) 2017-2017 Artem Anufrij - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * The Noise authors hereby grant permission for non-GPL compatible - * GStreamer plugins to be used and distributed together with GStreamer - * and Noise. This permission is above and beyond the permissions granted - * by the GPL license by which Noise is covered. If you modify this code - * you may extend this exception to your version of the code, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * - * Authored by: Artem Anufrij - */ - -namespace Webpin { - public class UrlEntry : Gtk.Entry { - public UrlEntry () { - editable = false; - set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "view-refresh-symbolic"); - set_icon_from_icon_name (Gtk.EntryIconPosition.PRIMARY, "text-html-symbolic"); - } - public override void get_preferred_width (out int minimum_width, out int natural_width) { - minimum_width = -1; - natural_width = 3000; - } - } -} diff --git a/src/WebWindow.vala b/src/WebWindow.vala index f532380..dfb1550 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -29,37 +29,30 @@ namespace Webpin { public class WebWindow : Gtk.Window { - private bool is_full_screen = false; - - //widgets - private WebApp web_app; + Gdk.WindowState current_state; + WebApp web_app; Gtk.Spinner spinner; public DesktopFile desktop_file { get; private set; } public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; + this.set_wmclass (desktop_file.url, desktop_file.url); this.events |= Gdk.EventMask.STRUCTURE_MASK; var color = desktop_file.color; if (color != null) { - var mid = color.red + color.blue + color.green; - if (mid / 3 < 0.5) { - Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; - } - Granite.Widgets.Utils.set_color_primary (this, color); + set_color (color); } - - set_wmclass (desktop_file.url, desktop_file.url); - web_app = new WebApp (desktop_file.url); + web_app = new WebApp (desktop_file); var headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; headerbar.show_close_button = true; var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); - copy_url.tooltip_text = _("Copy URI into clipboard"); + copy_url.tooltip_text = _("Copy URL into clipboard"); copy_url.clicked.connect (() => { Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (web_app.app_view.uri, -1); }); @@ -74,40 +67,26 @@ namespace Webpin { stay_open.tooltip_text = _("Run in background when closed"); stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); stay_open.toggled.connect (() => { - desktop_file.edit_propertie ("X-Webpin-StayOpen", stay_open.active.to_string ()); + desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ()); desktop_file.save_to_file (); }); headerbar.pack_start (stay_open); this.set_titlebar (headerbar); - var width = desktop_file.info.get_string ("X-Webpin-WindowWidth"); - var height = desktop_file.info.get_string ("X-Webpin-WindowHeight"); - var state = desktop_file.info.get_string ("X-Webpin-WindowMaximized"); - var zoom = desktop_file.info.get_string ("X-Webpin-WindowZoom"); - - if (width != null && height != null) { - set_default_size (int.parse(width), int.parse(height)); - } else { - set_default_size (1000, 600); - } - - if (state != null && state == "max") { - this.maximize (); - } - - if (zoom != null) { - web_app.app_view.zoom_level = double.parse (zoom); - } - this.delete_event.connect (() => { - update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized); + save_settings (); if (desktop_file.hide_on_close) { this.hide_on_delete (); } return desktop_file.hide_on_close; }); + this.window_state_event.connect ((event) => { + current_state = event.new_window_state; + return false; + }); + web_app.external_request.connect ((action) => { debug ("Web app external request: %s", action.get_request ().uri); try { @@ -133,107 +112,122 @@ namespace Webpin { spinner.active = false; }); - add(web_app); - show_all(); + web_app.found_website_color.connect ((color) => { + int gray_val = (int)(desktop_file.color.red * 255); + if (desktop_file.color == null || (gray_val == 222 && desktop_file.color.red == desktop_file.color.green && desktop_file.color.red == desktop_file.color.blue)) { + set_color (color); + desktop_file.color = color; + } + }); + + this.add (web_app); + + load_settings (); + + this.show_all (); } - public new void fullscreen () { - is_full_screen = true; - base.fullscreen(); - } - - public new void unfullscreen () { - is_full_screen = false; - base.unfullscreen(); + private void set_color (Gdk.RGBA color) { + var mid = color.red + color.blue + color.green; + color.alpha = 1; + if (mid / 3 < 0.5) { + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true; + } + Granite.Widgets.Utils.set_color_primary (this, color); } public void toggle_fullscreen() { - if(is_full_screen) { - unfullscreen(); + if (current_state.to_string () == Gdk.WindowState.FULLSCREEN.to_string ()) { + this.unfullscreen (); + } else { + this.fullscreen (); } - else { - fullscreen(); - } - is_full_screen = !is_full_screen; } - public void update_window_state (int width, int height, bool is_maximized) { - var file = web_app.get_desktop_file(); + private void load_settings () { + var width = desktop_file.info.get_string ("X-Webpin-WindowWidth"); + var height = desktop_file.info.get_string ("X-Webpin-WindowHeight"); + var state = desktop_file.info.get_string ("X-Webpin-WindowMaximized"); + var zoom = desktop_file.info.get_string ("X-Webpin-WindowZoom"); - if (is_maximized) { - file.edit_propertie ("X-Webpin-WindowMaximized", "max"); + if (width != null && height != null) { + set_default_size (int.parse(width), int.parse(height)); } else { - file.edit_propertie ("X-Webpin-WindowWidth", width.to_string()); - file.edit_propertie ("X-Webpin-WindowHeight", height.to_string()); - file.edit_propertie ("X-Webpin-WindowMaximized", "norm"); + set_default_size (1000, 600); + } + + if (state != null && state == "max") { + this.maximize (); + } + + if (zoom != null) { + web_app.app_view.zoom_level = double.parse (zoom); + } + } + + private void save_settings () { + if (this.is_maximized) { + desktop_file.edit_property ("X-Webpin-WindowMaximized", "max"); + } else { + desktop_file.edit_property ("X-Webpin-WindowWidth", this.get_allocated_width ().to_string()); + desktop_file.edit_property ("X-Webpin-WindowHeight", this.get_allocated_height ().to_string()); + desktop_file.edit_property ("X-Webpin-WindowMaximized", "norm"); } } public override bool key_press_event (Gdk.EventKey event) { - bool handled = true; switch (event.keyval) { - case Gdk.Key.Escape: - unfullscreen(); - break; - case Gdk.Key.F11: - toggle_fullscreen(); - break; - case Gdk.Key.KP_Add: - case Gdk.Key.plus: - if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level += 0.1; - web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); - } else { - handled = false; - } - break; - case Gdk.Key.KP_Subtract: - case Gdk.Key.minus: - if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level -= 0.1; - web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); - } else { - handled = false; - } - break; - case Gdk.Key.KP_0: - case Gdk.Key.@0: - if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level = 1; - web_app.get_desktop_file().edit_propertie ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); - } else { - handled = false; - } - break; - case Gdk.Key.F5: - if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.reload (); - } else { - web_app.app_view.reload_bypass_cache (); - } - break; - case Gdk.Key.Left: - if (Gdk.ModifierType.MOD1_MASK in event.state) { - web_app.app_view.go_back (); - } else { - handled = false; - } - break; - case Gdk.Key.Right: - if (Gdk.ModifierType.MOD1_MASK in event.state) { - web_app.app_view.go_forward (); - } else { - handled = false; - } - break; - default: - handled = false; - break; + case Gdk.Key.Escape: + unfullscreen(); + break; + case Gdk.Key.F11: + toggle_fullscreen(); + break; + case Gdk.Key.KP_Add: + case Gdk.Key.plus: + if (Gdk.ModifierType.CONTROL_MASK in event.state) { + web_app.app_view.zoom_level += 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + return true; + } + break; + case Gdk.Key.KP_Subtract: + case Gdk.Key.minus: + if (Gdk.ModifierType.CONTROL_MASK in event.state) { + web_app.app_view.zoom_level -= 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + return true; + } + break; + case Gdk.Key.KP_0: + case Gdk.Key.@0: + if (Gdk.ModifierType.CONTROL_MASK in event.state) { + web_app.app_view.zoom_level = 1; + desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + return true; + } + break; + case Gdk.Key.F5: + if (Gdk.ModifierType.CONTROL_MASK in event.state) { + web_app.app_view.reload (); + } else { + web_app.app_view.reload_bypass_cache (); + } + return true; + case Gdk.Key.Left: + if (Gdk.ModifierType.MOD1_MASK in event.state) { + web_app.app_view.go_back (); + return true; + } + break; + case Gdk.Key.Right: + if (Gdk.ModifierType.MOD1_MASK in event.state) { + web_app.app_view.go_forward (); + return true; + } + break; } - if (handled) - return true; - return (base.key_press_event != null) ? base.key_press_event (event) : true; } } diff --git a/src/Widgets/ApplicationIcon.vala b/src/Widgets/ApplicationIcon.vala index 193e5aa..acbd2a8 100644 --- a/src/Widgets/ApplicationIcon.vala +++ b/src/Widgets/ApplicationIcon.vala @@ -75,8 +75,9 @@ namespace Webpin { }); event_box.leave_notify_event.connect ((event) => { - if (event.detail == Gdk.NotifyType.INFERIOR) + if (event.detail == Gdk.NotifyType.INFERIOR) { return false; + } menu.set_reveal_child (false); return false; }); @@ -109,10 +110,11 @@ namespace Webpin { new_height = new_height * pix.height / pix.width; margin_vertical = (new_width - new_height) / 2; } - if (image == null) + if (image == null) { image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR)); - else + } else { image.set_from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR)); + } image.margin_top = margin_vertical; image.margin_bottom = margin_vertical; diff --git a/src/Widgets/ApplicationsView.vala b/src/Widgets/ApplicationsView.vala index 595c040..75edeae 100644 --- a/src/Widgets/ApplicationsView.vala +++ b/src/Widgets/ApplicationsView.vala @@ -33,8 +33,7 @@ namespace Webpin { public signal void edit_request(DesktopFile desktop_file); public signal void app_deleted (); - private Gtk.FlowBox icon_view; - private Gee.HashMap applications; + Gtk.FlowBox icon_view; public bool has_items { get { return icon_view.get_children ().length () > 0; } } @@ -56,20 +55,19 @@ namespace Webpin { var app_icon = (child as Gtk.FlowBoxChild).get_child () as ApplicationIcon; try { Process.spawn_command_line_async ("com.github.artemanufrij.webpin " + app_icon.desktop_file.url.replace("%%", "%")); - } catch (SpawnError e) { - debug ("Error: %s\n", e.message); + } catch (SpawnError err) { + warning (err.message); } } }); load_applications (); - scrolled.add(icon_view); - this.pack_start(scrolled, true, true, 0); - + scrolled.add (icon_view); + this.pack_start (scrolled, true, true, 0); } public void load_applications () { - applications = DesktopFile.get_webpin_applications(); + var applications = Services.DesktopFilesManager.get_webpin_applications (); foreach (GLib.DesktopAppInfo app in applications.values) { this.add_button (app); diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index b180de0..d17ad33 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -57,15 +57,20 @@ namespace Webpin { private assistant_mode mode { get; set; default = assistant_mode.new_app; } + Gdk.RGBA default_color; + + construct { + default_color = { 222, 222, 222, 255 }; + } + public Assistant () { GLib.Object (orientation: Gtk.Orientation.VERTICAL); - apps = DesktopFile.get_applications (); + apps = Services.DesktopFilesManager.get_applications (); this.margin = 15; try { - //http(s)://(words or numbers)(port and numbers) this.protocol_regex = new Regex ("""https?\:\/\/[\w+\d+]((\:\d+)?\/\S*)?"""); } catch (RegexError e) { critical ("%s", e.message); @@ -108,18 +113,18 @@ namespace Webpin { icon_selector_popover.add (popover_box); - primary_color_button = new Gtk.ColorButton.with_rgba ({ 222, 222, 222, 255 }); + primary_color_button = new Gtk.ColorButton.with_rgba (default_color); primary_color_button.use_alpha = false; - - //TODO: categories - //combobox + primary_color_button.color_activated.connect ((color) => { + stdout.printf ("COLOR %s\n", color.to_string ()); + }); //checkbuttons save_cookies_check = new Gtk.CheckButton.with_label (_("Save cookies")); save_cookies_check.active = true; save_password_check = new Gtk.CheckButton.with_label (_("Save login information")); save_password_check.active = false; - stay_open_when_closed = new Gtk.CheckButton.with_label (_("Run in background when closed")); + stay_open_when_closed = new Gtk.CheckButton.with_label (_("Run in background if closed")); stay_open_when_closed.active = false; //app information section @@ -127,7 +132,6 @@ namespace Webpin { app_input_box.halign = Gtk.Align.START; app_input_box.pack_start (app_name_entry, false, false, 0); app_input_box.pack_start (app_url_entry, false, false, 0); - //app_input_box.pack_start (app_category_combo, true, false, 0); var app_info_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5); app_info_box.pack_start (icon_button, false, false, 3); @@ -143,7 +147,7 @@ namespace Webpin { app_options_box.halign = Gtk.Align.CENTER; //create button - accept_button = new Gtk.Button.with_label(_("Save app")); + accept_button = new Gtk.Button.with_label (_("Save app")); accept_button.halign = Gtk.Align.END; accept_button.get_style_context ().add_class ("suggested-action"); accept_button.set_sensitive (false); @@ -161,7 +165,7 @@ namespace Webpin { icon_selector_popover.show_all(); }); - app_url_entry.changed.connect (()=>{ + app_url_entry.changed.connect (() => { if (!this.protocol_regex.match (app_url_entry.get_text())) { app_url_entry.get_style_context ().add_class ("error"); app_url_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); @@ -174,8 +178,8 @@ namespace Webpin { validate (); }); - app_name_entry.changed.connect (()=>{ - if (mode == assistant_mode.new_app && DesktopFile.get_applications().has_key (app_name_entry.get_text()) ) { + app_name_entry.changed.connect (() => { + if (mode == assistant_mode.new_app && Services.DesktopFilesManager.get_applications ().has_key (app_name_entry.get_text())) { app_name_entry.get_style_context ().add_class ("error"); app_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-information"); app_name_entry.set_icon_tooltip_text (Gtk.EntryIconPosition.SECONDARY, _("App already exist")); @@ -204,7 +208,7 @@ namespace Webpin { } //if is a file uri - if (icon.contains("/")) { + if (icon.contains ("/")) { Gdk.Pixbuf pix = null; try { pix = new Gdk.Pixbuf.from_file_at_size (icon, 48, 48); @@ -222,7 +226,7 @@ namespace Webpin { icon_button.set_image (new Gtk.Image.from_pixbuf (pix)); } } else { - icon_button.set_image (new Gtk.Image.from_icon_name (icon, Gtk.IconSize.DIALOG) ); + icon_button.set_image (new Gtk.Image.from_icon_name (icon, Gtk.IconSize.DIALOG)); } validate (); @@ -245,14 +249,14 @@ namespace Webpin { Gtk.FileChooserAction.OPEN, _("Cancel"), Gtk.ResponseType.CANCEL, _("Open"), Gtk.ResponseType.ACCEPT); - file_chooser.set_select_multiple(false); + file_chooser.set_select_multiple (false); file_chooser.add_filter (filter); - var preview = new Gtk.Image(); + var preview = new Gtk.Image (); preview.valign = Gtk.Align.START; - file_chooser.update_preview.connect ( ()=> { - string filename = file_chooser.get_preview_filename(); + file_chooser.update_preview.connect (()=> { + string filename = file_chooser.get_preview_filename (); Gdk.Pixbuf pix = null; if (filename != null) { @@ -274,7 +278,7 @@ namespace Webpin { if (file_chooser.run () == Gtk.ResponseType.ACCEPT) { - icon_name_entry.set_text(file_chooser.get_filename ()); + icon_name_entry.set_text (file_chooser.get_filename ()); file_chooser.destroy (); } file_chooser.destroy (); @@ -297,19 +301,19 @@ namespace Webpin { app_url_entry.set_text (""); app_name_entry.get_style_context ().remove_class ("error"); app_url_entry.get_style_context ().remove_class ("error"); - icon_button.set_image (new Gtk.Image.from_icon_name (default_app_icon, Gtk.IconSize.DIALOG) ); + icon_button.set_image (new Gtk.Image.from_icon_name (default_app_icon, Gtk.IconSize.DIALOG)); mode = assistant_mode.new_app; } private void on_accept () { - string icon = icon_name_entry.get_text (); string name = app_name_entry.get_text (); string url = app_url_entry.get_text ().replace ("%", "%%"); bool stay_open = stay_open_when_closed.active; - if (icon == "") + if (icon == "") { icon = default_app_icon; + } if (app_icon_valid && app_name_valid && app_url_valid) { var desktop_file = new DesktopFile (name, url, icon, stay_open); @@ -321,23 +325,28 @@ namespace Webpin { application_edited (desktop_file.save_to_file ()); break; } + stdout.printf ("Custom Color %s\n", primary_color_button.rgba.to_string ()); desktop_file.color = primary_color_button.rgba; } } - public void edit_desktop_file (DesktopFile desktop_file) { - mode = assistant_mode.edit_app; - app_name_entry.text = desktop_file.name; - app_name_entry.set_sensitive (false); - app_url_entry.text = desktop_file.url.replace ("%%", "%"); - icon_name_entry.text = desktop_file.icon; - stay_open_when_closed.active = desktop_file.hide_on_close; - if (desktop_file.color != null) { - primary_color_button.set_rgba (desktop_file.color); + public void edit_desktop_file (DesktopFile? desktop_file) { + if (desktop_file == null) { + reset_fields (); } else { - primary_color_button.set_rgba ({ 222, 222, 222, 255 }); + mode = assistant_mode.edit_app; + app_name_entry.text = desktop_file.name; + app_name_entry.set_sensitive (false); + app_url_entry.text = desktop_file.url.replace ("%%", "%"); + icon_name_entry.text = desktop_file.icon; + stay_open_when_closed.active = desktop_file.hide_on_close; + if (desktop_file.color != null) { + primary_color_button.set_rgba (desktop_file.color); + } else { + primary_color_button.set_rgba (default_color); + } + update_app_icon (); } - update_app_icon (); } } } diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index f277b74..2e19619 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -28,14 +28,11 @@ namespace Webpin { public class WebApp : Gtk.Stack { + public WebKit.WebView app_view { get; private set; } + public DesktopFile desktop_file { get; private set; } - public WebKit.WebView app_view; - public string ui_color = "none"; - private string app_url; - private GLib.DesktopAppInfo info; - private DesktopFile file; - private WebKit.CookieManager cookie_manager; - private Gtk.Box container; + WebKit.CookieManager cookie_manager; + Gtk.Box container; Granite.Widgets.Toast app_notification; GLib.Icon icon_for_notification; @@ -43,54 +40,60 @@ namespace Webpin { public signal void request_begin (); public signal void request_finished (); public signal void desktop_notification (string title, string body, GLib.Icon icon); + public signal void found_website_color (Gdk.RGBA color); - public WebApp (string app_url) { - - this.app_url = app_url; - - //configure cookies settings - cookie_manager = WebKit.WebContext.get_default ().get_cookie_manager (); - cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); + public WebApp (DesktopFile desktop_file) { + this.desktop_file = desktop_file; + this.transition_duration = 350; + this.transition_type = Gtk.StackTransitionType.SLIDE_UP; string cookie_db = Environment.get_user_cache_dir () + "/webpin/cookies/"; - var dir = GLib.File.new_for_path (cookie_db); - if (!dir.query_exists (null)) { try { dir.make_directory_with_parents (null); - GLib.debug ("Directory '%s' created", dir.get_path ()); - } catch (Error e) { - GLib.error ("Could not create caching directory."); + } catch (Error err) { + warning ("Could not create caching directory."); } } + cookie_manager = WebKit.WebContext.get_default ().get_cookie_manager (); + cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); cookie_manager.set_persistent_storage (cookie_db + "cookies.db", WebKit.CookiePersistentStorage.SQLITE); - //load app viewer app_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ()); - app_view.load_uri (app_url); + app_view.load_uri (desktop_file.url); - container = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); - container.halign = Gtk.Align.FILL; - container.valign = Gtk.Align.FILL; + container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); app_notification = new Granite.Widgets.Toast (""); - //overlay trick to make snapshot work even with the spinner var overlay = new Gtk.Overlay (); overlay.add (app_view); overlay.add_overlay (app_notification); - add_named (container, "splash"); - add_named (overlay, "app"); + this.add_named (container, "splash"); + this.add_named (overlay, "app"); - transition_duration = 350; - transition_type = Gtk.StackTransitionType.SLIDE_UP; + var icon_file = File.new_for_path (desktop_file.icon); + + Gtk.Image icon; + if (icon_file.query_exists ()) { + try { + icon = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (desktop_file.icon, 48, 48, true)); + icon_for_notification = GLib.Icon.new_for_string (desktop_file.icon); + } catch (Error err) { + warning (err.message); + icon = new Gtk.Image.from_icon_name ("com.github.artemanufrij.webpin", Gtk.IconSize.DIALOG); + } + } else { + icon = new Gtk.Image.from_icon_name (desktop_file.icon, Gtk.IconSize.DIALOG); + icon_for_notification = new GLib.ThemedIcon (desktop_file.icon); + } + container.pack_start (icon, true, true, 0); app_view.create.connect ((action) => { - print("external request"); app_notification.title = _("Open request in an external application…"); app_notification.send_notification (); @@ -98,33 +101,7 @@ namespace Webpin { return new WebKit.WebView (); }); - info = DesktopFile.get_app_by_url(app_url); - file = new DesktopFile.from_desktopappinfo(info); - - var icon_file = File.new_for_path (file.icon); - - Gtk.Image icon; - if (icon_file.query_exists ()) { - try { - icon = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (file.icon, 48, 48, true)); - icon_for_notification = GLib.Icon.new_for_string (file.icon); - } catch (Error e) { - warning (e.message); - icon = new Gtk.Image.from_icon_name ("com.github.artemanufrij.webpin", Gtk.IconSize.DIALOG); - } - } else { - icon = new Gtk.Image.from_icon_name (file.icon, Gtk.IconSize.DIALOG); - icon_for_notification = new GLib.ThemedIcon (file.icon); - } - container.pack_start(icon, true, true, 0); - - Gdk.RGBA background = {}; - if (!background.parse (ui_color)){ - background = {1,1,1,1}; - } - container.override_background_color (Gtk.StateFlags.NORMAL, background); - - app_view.load_changed.connect ( (load_event) => { + app_view.load_changed.connect ((load_event) => { request_begin (); if (load_event == WebKit.LoadEvent.FINISHED) { visible_child_name = "app"; @@ -132,6 +109,23 @@ namespace Webpin { app_notification.reveal_child = false; } request_finished (); + var source = app_view.get_main_resource (); + source.get_data.begin (null, (obj, res) => { + try { + var body = (string)source.get_data.end (res); + var regex = new Regex ("(?<= Date: Sun, 26 Nov 2017 00:26:07 +0100 Subject: [PATCH 25/31] simplify filter pattern --- src/WebWindow.vala | 2 +- src/Widgets/Assistant.vala | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/WebWindow.vala b/src/WebWindow.vala index dfb1550..3470b00 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -64,7 +64,7 @@ namespace Webpin { var stay_open = new Gtk.ToggleButton (); stay_open.active = desktop_file.hide_on_close; - stay_open.tooltip_text = _("Run in background when closed"); + stay_open.tooltip_text = _("Run in background if closed"); stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); stay_open.toggled.connect (() => { desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ()); diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index d17ad33..6e6e1f6 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -234,16 +234,8 @@ namespace Webpin { private void on_icon_chooser_activate () { var filter = new Gtk.FileFilter (); - filter.set_filter_name (_("Images")); - filter.add_pattern ("*.png"); - filter.add_pattern ("*.svg"); - filter.add_pattern ("*.jpg"); - filter.add_pattern ("*.jpeg"); - filter.add_pattern ("*.PNG"); - filter.add_pattern ("*.SVG"); - filter.add_pattern ("*.JPG"); - filter.add_pattern ("*.JPEG"); + filter.add_mime_type ("image/*"); file_chooser = new Gtk.FileChooserDialog ("", null, Gtk.FileChooserAction.OPEN, From d1068871d766c6d16a654ee4e6c28471c8e9547b Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 13:39:25 +0100 Subject: [PATCH 26/31] code style --- src/Application.vala | 6 +- src/CMakeLists.txt | 10 +-- src/MainWindow.vala | 42 +++++----- src/Services/DesktopFilesManager.vala | 45 ++++++++++- src/Widgets/{WebApp.vala => Browser.vala} | 6 +- .../{Assistant.vala => Views/Editor.vala} | 6 +- .../WebItemsView.vala} | 65 ++++++++------- .../{ApplicationIcon.vala => WebItem.vala} | 79 ++++++------------- src/{WebWindow.vala => Windows/WebApp.vala} | 46 +++++------ 9 files changed, 156 insertions(+), 149 deletions(-) rename src/Widgets/{WebApp.vala => Browser.vala} (98%) rename src/Widgets/{Assistant.vala => Views/Editor.vala} (99%) rename src/Widgets/{ApplicationsView.vala => Views/WebItemsView.vala} (61%) rename src/Widgets/{ApplicationIcon.vala => WebItem.vala} (63%) rename src/{WebWindow.vala => Windows/WebApp.vala} (87%) diff --git a/src/Application.vala b/src/Application.vala index 468ab18..393f10c 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -51,7 +51,7 @@ namespace Webpin { }); } - public Gtk.Window mainwindow; + public Gtk.Window mainwindow { get; private set; default = null; } protected override void activate () { if (mainwindow != null) { @@ -66,14 +66,14 @@ namespace Webpin { start_webapp (files [0].get_uri ()); } - public void start_webapp (string url) { + private void start_webapp (string url) { if (mainwindow != null ) { mainwindow.present (); return; } var app_info = Services.DesktopFilesManager.get_app_by_url (url); var desktop_file = new Webpin.DesktopFile.from_desktopappinfo (app_info); - mainwindow = new WebWindow (desktop_file); + mainwindow = new Windows.WebApp (desktop_file); mainwindow.set_application (this); } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26b049c..b26fde2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,14 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME} - Widgets/ApplicationIcon.vala - Widgets/ApplicationsView.vala - Widgets/Assistant.vala - Widgets/WebApp.vala + Widgets/WebItem.vala + Widgets/Views/WebItemsView.vala + Widgets/Views/Editor.vala + Widgets/Browser.vala + Windows/WebApp.vala Objects/DesktopFile.vala Dialogs/Preferences.vala Services/DesktopFilesManager.vala Settings.vala MainWindow.vala - WebWindow.vala Application.vala PACKAGES gtk+-3.0 diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 89368a1..2f36c7a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -36,8 +36,8 @@ namespace Webpin { Gtk.Button add_button; Gtk.MenuButton app_menu; - Assistant assistant; - ApplicationsView apps_view; + Widgets.Views.Editor editor; + Widgets.Views.WebItemsView web_items_view; construct { settings = Settings.get_default (); @@ -106,44 +106,44 @@ namespace Webpin { } }); - apps_view = new ApplicationsView(); - assistant = new Assistant(); + web_items_view = new Widgets.Views.WebItemsView (); + editor = new Widgets.Views.Editor (); stack = new Gtk.Stack (); stack.set_transition_duration (500); stack.add_named (welcome, "welcome"); - stack.add_named (apps_view, "apps_view"); - stack.add_named (assistant, "assistant"); + stack.add_named (web_items_view, "apps_view"); + stack.add_named (editor, "editor"); add (stack); - apps_view.add_request.connect (() => { + web_items_view.add_request.connect (() => { show_assistant (); }); - apps_view.edit_request.connect ((desktop_file) => { + web_items_view.edit_request.connect ((desktop_file) => { show_assistant (desktop_file); }); - apps_view.app_deleted.connect (() => { - if (!apps_view.has_items) { + web_items_view.app_deleted.connect (() => { + if (!web_items_view.has_items) { show_welcome_view (Gtk.StackTransitionType.NONE); } }); - assistant.application_created.connect ((new_file) => { - apps_view.add_button (new_file); - apps_view.select_last_item (); + editor.application_created.connect ((new_file) => { + web_items_view.add_web_item (new_file); + web_items_view.select_last_item (); show_apps_view (); }); - assistant.application_edited.connect ((edited_file) => { - apps_view.update_button (edited_file); + editor.application_edited.connect ((edited_file) => { + web_items_view.update_button (edited_file); show_apps_view (); }); back_button.clicked.connect (() => { - if (apps_view.has_items) { + if (web_items_view.has_items) { show_apps_view (); } else { show_welcome_view (); @@ -162,7 +162,7 @@ namespace Webpin { this.restore_settings (); show_all (); - if (apps_view.has_items) { + if (web_items_view.has_items) { show_apps_view (Gtk.StackTransitionType.NONE); } else { show_welcome_view (Gtk.StackTransitionType.NONE); @@ -173,10 +173,10 @@ namespace Webpin { private void show_assistant (DesktopFile? desktop_file = null) { stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT); - stack.set_visible_child_name("assistant"); + stack.set_visible_child_name("editor"); back_button.show_all (); add_button.hide (); - assistant.edit_desktop_file (desktop_file); + editor.edit_desktop_file (desktop_file); } private void show_apps_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { @@ -184,7 +184,7 @@ namespace Webpin { stack.set_visible_child_name ("apps_view"); back_button.hide (); add_button.show_all (); - assistant.reset_fields (); + editor.reset_fields (); } private void show_welcome_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) { @@ -192,7 +192,7 @@ namespace Webpin { stack.set_visible_child_name ("welcome"); back_button.hide (); add_button.hide (); - assistant.reset_fields (); + editor.reset_fields (); } private void restore_settings () { diff --git a/src/Services/DesktopFilesManager.vala b/src/Services/DesktopFilesManager.vala index 8d4b4ee..eda853f 100644 --- a/src/Services/DesktopFilesManager.vala +++ b/src/Services/DesktopFilesManager.vala @@ -50,17 +50,54 @@ namespace Webpin.Services { } public static Gee.HashMap get_webpin_applications () { - var list = new Gee.HashMap(); + var list = new Gee.HashMap (); - foreach (GLib.AppInfo app in GLib.AppInfo.get_all()) { - var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); + foreach (GLib.AppInfo app in GLib.AppInfo.get_all ()) { + var desktop_app = new GLib.DesktopAppInfo (app.get_id ()); string keywords = desktop_app.get_string ("Keywords"); if (keywords != null && keywords.contains ("webpin")) { - list.set(desktop_app.get_name(), desktop_app); + list.set (desktop_app.get_name (), desktop_app); } } return list; } + + public static Gdk.Pixbuf? align_and_scale_pixbuf (Gdk.Pixbuf p, int size) { + Gdk.Pixbuf? pixbuf = p; + if (pixbuf.width != pixbuf.height) { + if (pixbuf.width > pixbuf.height) { + int dif = (pixbuf.width - pixbuf.height) / 2; + pixbuf = new Gdk.Pixbuf.subpixbuf (pixbuf, dif, 0, pixbuf.height, pixbuf.height); + } else { + int dif = (pixbuf.height - pixbuf.width) / 2; + pixbuf = new Gdk.Pixbuf.subpixbuf (pixbuf, 0, dif, pixbuf.width, pixbuf.width); + } + } + pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR); + return pixbuf; + } + + public static string? choose_new_icon () { + string? return_value = null; + var dialog = new Gtk.FileChooserDialog ( + _("Choose an image…"), WebpinApp.instance.mainwindow, + Gtk.FileChooserAction.OPEN, + _("_Cancel"), Gtk.ResponseType.CANCEL, + _("_Open"), Gtk.ResponseType.ACCEPT); + + var filter = new Gtk.FileFilter (); + filter.set_filter_name (_("Images")); + filter.add_mime_type ("image/*"); + + dialog.add_filter (filter); + + if (dialog.run () == Gtk.ResponseType.ACCEPT) { + return_value = dialog.get_filename (); + } + + dialog.destroy(); + return return_value; + } } } diff --git a/src/Widgets/WebApp.vala b/src/Widgets/Browser.vala similarity index 98% rename from src/Widgets/WebApp.vala rename to src/Widgets/Browser.vala index 2e19619..6489345 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/Browser.vala @@ -26,8 +26,8 @@ * Authored by: Artem Anufrij */ -namespace Webpin { - public class WebApp : Gtk.Stack { +namespace Webpin.Widgets { + public class Browser : Gtk.Stack { public WebKit.WebView app_view { get; private set; } public DesktopFile desktop_file { get; private set; } @@ -43,7 +43,7 @@ namespace Webpin { public signal void found_website_color (Gdk.RGBA color); - public WebApp (DesktopFile desktop_file) { + public Browser (DesktopFile desktop_file) { this.desktop_file = desktop_file; this.transition_duration = 350; this.transition_type = Gtk.StackTransitionType.SLIDE_UP; diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Views/Editor.vala similarity index 99% rename from src/Widgets/Assistant.vala rename to src/Widgets/Views/Editor.vala index 6e6e1f6..ae71906 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Views/Editor.vala @@ -26,8 +26,8 @@ * Authored by: Artem Anufrij */ -namespace Webpin { - public class Assistant : Gtk.Box { +namespace Webpin.Widgets.Views { + public class Editor : Gtk.Box { public enum assistant_mode { new_app, edit_app } @@ -63,7 +63,7 @@ namespace Webpin { default_color = { 222, 222, 222, 255 }; } - public Assistant () { + public Editor () { GLib.Object (orientation: Gtk.Orientation.VERTICAL); apps = Services.DesktopFilesManager.get_applications (); diff --git a/src/Widgets/ApplicationsView.vala b/src/Widgets/Views/WebItemsView.vala similarity index 61% rename from src/Widgets/ApplicationsView.vala rename to src/Widgets/Views/WebItemsView.vala index 75edeae..517ffb3 100644 --- a/src/Widgets/ApplicationsView.vala +++ b/src/Widgets/Views/WebItemsView.vala @@ -26,33 +26,33 @@ * Authored by: Artem Anufrij */ -namespace Webpin { - public class ApplicationsView : Gtk.Box { +namespace Webpin.Widgets.Views { + public class WebItemsView : Gtk.Box { - public signal void add_request(); - public signal void edit_request(DesktopFile desktop_file); + public signal void add_request (); + public signal void edit_request (DesktopFile desktop_file); public signal void app_deleted (); - Gtk.FlowBox icon_view; + Gtk.FlowBox web_items; - public bool has_items { get { return icon_view.get_children ().length () > 0; } } + public bool has_items { get { return web_items.get_children ().length () > 0; } } - public ApplicationsView () { + public WebItemsView () { GLib.Object (orientation: Gtk.Orientation.VERTICAL); var scrolled = new Gtk.ScrolledWindow (null, null); scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER; - icon_view = new Gtk.FlowBox(); - icon_view.valign = Gtk.Align.START; - icon_view.vexpand = false; - icon_view.homogeneous = true; - icon_view.column_spacing = 24; - icon_view.row_spacing = 24; - icon_view.margin = 24; - icon_view.child_activated.connect ((child) => { - if ((child as Gtk.FlowBoxChild).get_child () is ApplicationIcon) { - var app_icon = (child as Gtk.FlowBoxChild).get_child () as ApplicationIcon; + web_items = new Gtk.FlowBox(); + web_items.valign = Gtk.Align.START; + web_items.vexpand = false; + web_items.homogeneous = true; + web_items.column_spacing = 12; + web_items.row_spacing = 12; + web_items.margin = 24; + web_items.child_activated.connect ((child) => { + if (child is WebItem) { + var app_icon = child as WebItem; try { Process.spawn_command_line_async ("com.github.artemanufrij.webpin " + app_icon.desktop_file.url.replace("%%", "%")); } catch (SpawnError err) { @@ -62,7 +62,7 @@ namespace Webpin { }); load_applications (); - scrolled.add (icon_view); + scrolled.add (web_items); this.pack_start (scrolled, true, true, 0); } @@ -70,40 +70,39 @@ namespace Webpin { var applications = Services.DesktopFilesManager.get_webpin_applications (); foreach (GLib.DesktopAppInfo app in applications.values) { - this.add_button (app); + this.add_web_item (app); } } - public void add_button (GLib.DesktopAppInfo app) { - var image = new ApplicationIcon (app); - image.edit_request.connect ((desktop_file) => { + public void add_web_item (GLib.DesktopAppInfo app) { + var web_item = new WebItem (app); + web_item.edit_request.connect ((desktop_file) => { edit_request (desktop_file); - icon_view.unselect_all (); + web_items.unselect_all (); }); - image.deleted.connect ((parent) => { - this.icon_view.remove (parent); + web_item.deleted.connect (() => { app_deleted (); }); - icon_view.add (image); - icon_view.show_all (); + web_items.add (web_item); + web_items.show_all (); } public void select_last_item () { - icon_view.select_child (icon_view.get_child_at_index ((int)icon_view.get_children ().length () - 1)); + web_items.select_child (web_items.get_child_at_index ((int)web_items.get_children ().length () - 1)); } public void select_first_item () { - icon_view.select_child (icon_view.get_child_at_index (0)); + web_items.select_child (web_items.get_child_at_index (0)); } public void update_button (GLib.DesktopAppInfo app) { - foreach (var item in icon_view.get_children ()) { - if ((item as Gtk.FlowBoxChild).get_child () is ApplicationIcon) { - var app_icon = (item as Gtk.FlowBoxChild).get_child () as ApplicationIcon; + foreach (var item in web_items.get_children ()) { + if (item is WebItem) { + var app_icon = item as WebItem; if (app_icon.desktop_file.name == app.get_display_name ()) { app_icon.set_new_desktopfile (new DesktopFile.from_desktopappinfo (app)); - icon_view.select_child (item as Gtk.FlowBoxChild); + web_items.select_child (item as Gtk.FlowBoxChild); break; } } diff --git a/src/Widgets/ApplicationIcon.vala b/src/Widgets/WebItem.vala similarity index 63% rename from src/Widgets/ApplicationIcon.vala rename to src/Widgets/WebItem.vala index acbd2a8..7fde4cc 100644 --- a/src/Widgets/ApplicationIcon.vala +++ b/src/Widgets/WebItem.vala @@ -26,51 +26,48 @@ * Authored by: Artem Anufrij */ -namespace Webpin { - public class ApplicationIcon : Gtk.Overlay { +namespace Webpin.Widgets { + public class WebItem : Gtk.FlowBoxChild { Gtk.Image image; Gtk.Label label; - Gtk.Box box; internal DesktopFile desktop_file { get; private set; } - public signal void deleted (Gtk.Container? parent); + public signal void deleted (); public signal void edit_request (DesktopFile desktop_file); - public ApplicationIcon (GLib.DesktopAppInfo app) { + public WebItem (GLib.DesktopAppInfo app) { this.desktop_file = new DesktopFile.from_desktopappinfo (app); + build_ui (); + } - hexpand = false; - vexpand = false; + private void build_ui () { + var content = new Gtk.Grid (); + content.margin = 12; + content.halign = Gtk.Align.CENTER; + content.row_spacing = 6; + image = new Gtk.Image (); label = new Gtk.Label (this.desktop_file.name); set_icon (this.desktop_file.icon); - this.margin = 6; - this.margin_start = 20; - this.margin_end = 20; - var menu = new ActionMenu (); menu.halign = Gtk.Align.CENTER; menu.delete_clicked.connect (() => { remove_application (); }); menu.edit_clicked.connect (() => { edit_request (desktop_file); }); - box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - box.pack_start (image, false, false, 0); - box.pack_start (label, false, false, 0); - box.pack_start (menu, false, false, 0); - - box.hexpand = false; - box.vexpand = false; + content.attach (image, 0, 0); + content.attach (label, 0, 1); + content.attach (menu, 0, 2); var event_box = new Gtk.EventBox (); - event_box.add (box); + event_box.add (content); event_box.events |= Gdk.EventMask.ENTER_NOTIFY_MASK|Gdk.EventMask.LEAVE_NOTIFY_MASK; event_box.enter_notify_event.connect ((event) => { - menu.set_reveal_child (true); + menu.opacity = 0.5; return false; }); @@ -78,7 +75,7 @@ namespace Webpin { if (event.detail == Gdk.NotifyType.INFERIOR) { return false; } - menu.set_reveal_child (false); + menu.opacity = 0; return false; }); @@ -98,30 +95,9 @@ namespace Webpin { } catch (Error e) { warning (e.message); } - int new_height = 64; - int new_width = 64; - int margin_vertical = 0; - int margin_horizontal = 0; - - if (pix.height > pix.width) { - new_width = new_width * pix.width / pix.height; - margin_horizontal = (new_height - new_width) / 2; - } else if (pix.height < pix.width) { - new_height = new_height * pix.height / pix.width; - margin_vertical = (new_width - new_height) / 2; - } - if (image == null) { - image = new Gtk.Image.from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR)); - } else { - image.set_from_pixbuf (pix.scale_simple (new_width, new_height, Gdk.InterpType.BILINEAR)); - } - - image.margin_top = margin_vertical; - image.margin_bottom = margin_vertical; - image.margin_right = margin_horizontal; - image.margin_left = margin_horizontal; + pix = Services.DesktopFilesManager.align_and_scale_pixbuf (pix, 64); + image.set_from_pixbuf (pix); } else { - image = new Gtk.Image (); image.icon_name = icon; image.pixel_size = 64; } @@ -129,12 +105,12 @@ namespace Webpin { private void remove_application () { desktop_file.delete_file (); - deleted (this.get_parent()); + deleted (); this.destroy (); } } - public class ActionMenu : Gtk.Revealer { + public class ActionMenu : Gtk.Grid { public signal void delete_clicked (); public signal void edit_clicked (); @@ -150,14 +126,9 @@ namespace Webpin { edit_button.relief = Gtk.ReliefStyle.NONE; edit_button.clicked.connect (() => { edit_clicked (); }); - var buttons = new Gtk.Grid (); - buttons.orientation = Gtk.Orientation.HORIZONTAL; - buttons.add (edit_button); - buttons.add (delete_button); - buttons.opacity = 0.5; - - this.transition_type = Gtk.RevealerTransitionType.CROSSFADE; - this.add (buttons); + this.add (edit_button); + this.add (delete_button); + this.opacity = 0; } } } diff --git a/src/WebWindow.vala b/src/Windows/WebApp.vala similarity index 87% rename from src/WebWindow.vala rename to src/Windows/WebApp.vala index 3470b00..4db5791 100644 --- a/src/WebWindow.vala +++ b/src/Windows/WebApp.vala @@ -26,17 +26,17 @@ * Authored by: Artem Anufrij */ -namespace Webpin { - public class WebWindow : Gtk.Window { +namespace Webpin.Windows { + public class WebApp : Gtk.Window { Gdk.WindowState current_state; - WebApp web_app; + Widgets.Browser browser; Gtk.Spinner spinner; public DesktopFile desktop_file { get; private set; } - public WebWindow (DesktopFile desktop_file) { + public WebApp (DesktopFile desktop_file) { this.desktop_file = desktop_file; this.set_wmclass (desktop_file.url, desktop_file.url); this.events |= Gdk.EventMask.STRUCTURE_MASK; @@ -45,7 +45,7 @@ namespace Webpin { if (color != null) { set_color (color); } - web_app = new WebApp (desktop_file); + browser = new Widgets.Browser (desktop_file); var headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; @@ -54,7 +54,7 @@ namespace Webpin { var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); copy_url.tooltip_text = _("Copy URL into clipboard"); copy_url.clicked.connect (() => { - Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (web_app.app_view.uri, -1); + Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.app_view.uri, -1); }); headerbar.pack_end (copy_url); @@ -87,7 +87,7 @@ namespace Webpin { return false; }); - web_app.external_request.connect ((action) => { + browser.external_request.connect ((action) => { debug ("Web app external request: %s", action.get_request ().uri); try { Process.spawn_command_line_async ("xdg-open " + action.get_request ().uri); @@ -96,7 +96,7 @@ namespace Webpin { } }); - web_app.desktop_notification.connect ((title, body, icon) => { + browser.desktop_notification.connect ((title, body, icon) => { var desktop_notification = new Notification (title); desktop_notification.set_body (body); desktop_notification.set_icon (icon); @@ -104,15 +104,15 @@ namespace Webpin { WebpinApp.instance.send_notification (null, desktop_notification); }); - web_app.request_begin.connect (() => { + browser.request_begin.connect (() => { spinner.active = true; }); - web_app.request_finished.connect (() => { + browser.request_finished.connect (() => { spinner.active = false; }); - web_app.found_website_color.connect ((color) => { + browser.found_website_color.connect ((color) => { int gray_val = (int)(desktop_file.color.red * 255); if (desktop_file.color == null || (gray_val == 222 && desktop_file.color.red == desktop_file.color.green && desktop_file.color.red == desktop_file.color.blue)) { set_color (color); @@ -120,7 +120,7 @@ namespace Webpin { } }); - this.add (web_app); + this.add (browser); load_settings (); @@ -161,7 +161,7 @@ namespace Webpin { } if (zoom != null) { - web_app.app_view.zoom_level = double.parse (zoom); + browser.app_view.zoom_level = double.parse (zoom); } } @@ -186,43 +186,43 @@ namespace Webpin { case Gdk.Key.KP_Add: case Gdk.Key.plus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level += 0.1; - desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + browser.app_view.zoom_level += 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.KP_Subtract: case Gdk.Key.minus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level -= 0.1; - desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + browser.app_view.zoom_level -= 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.KP_0: case Gdk.Key.@0: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.zoom_level = 1; - desktop_file.edit_property ("X-Webpin-WindowZoom", web_app.app_view.zoom_level.to_string ()); + browser.app_view.zoom_level = 1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.F5: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - web_app.app_view.reload (); + browser.app_view.reload (); } else { - web_app.app_view.reload_bypass_cache (); + browser.app_view.reload_bypass_cache (); } return true; case Gdk.Key.Left: if (Gdk.ModifierType.MOD1_MASK in event.state) { - web_app.app_view.go_back (); + browser.app_view.go_back (); return true; } break; case Gdk.Key.Right: if (Gdk.ModifierType.MOD1_MASK in event.state) { - web_app.app_view.go_forward (); + browser.app_view.go_forward (); return true; } break; From af4865214e8edb20db3bf21c5502998d36230c2b Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 14:09:53 +0100 Subject: [PATCH 27/31] renamed app_view -> web_view --- src/Widgets/Browser.vala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Widgets/Browser.vala b/src/Widgets/Browser.vala index 6489345..06ea8d7 100644 --- a/src/Widgets/Browser.vala +++ b/src/Widgets/Browser.vala @@ -28,7 +28,7 @@ namespace Webpin.Widgets { public class Browser : Gtk.Stack { - public WebKit.WebView app_view { get; private set; } + public WebKit.WebView web_view { get; private set; } public DesktopFile desktop_file { get; private set; } WebKit.CookieManager cookie_manager; @@ -62,15 +62,15 @@ namespace Webpin.Widgets { cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); cookie_manager.set_persistent_storage (cookie_db + "cookies.db", WebKit.CookiePersistentStorage.SQLITE); - app_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ()); - app_view.load_uri (desktop_file.url); + web_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ()); + web_view.load_uri (desktop_file.url); container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); app_notification = new Granite.Widgets.Toast (""); var overlay = new Gtk.Overlay (); - overlay.add (app_view); + overlay.add (web_view); overlay.add_overlay (app_notification); this.add_named (container, "splash"); @@ -93,7 +93,7 @@ namespace Webpin.Widgets { } container.pack_start (icon, true, true, 0); - app_view.create.connect ((action) => { + web_view.create.connect ((action) => { app_notification.title = _("Open request in an external application…"); app_notification.send_notification (); @@ -101,7 +101,7 @@ namespace Webpin.Widgets { return new WebKit.WebView (); }); - app_view.load_changed.connect ((load_event) => { + web_view.load_changed.connect ((load_event) => { request_begin (); if (load_event == WebKit.LoadEvent.FINISHED) { visible_child_name = "app"; @@ -109,7 +109,7 @@ namespace Webpin.Widgets { app_notification.reveal_child = false; } request_finished (); - var source = app_view.get_main_resource (); + var source = web_view.get_main_resource (); source.get_data.begin (null, (obj, res) => { try { var body = (string)source.get_data.end (res); @@ -129,12 +129,12 @@ namespace Webpin.Widgets { } }); - app_view.show_notification.connect ((notification) => { + web_view.show_notification.connect ((notification) => { desktop_notification (notification.title, notification.body, icon_for_notification); return true; }); - app_view.permission_request.connect ((permission) => { + web_view.permission_request.connect ((permission) => { var permission_type = permission as WebKit.NotificationPermissionRequest; if (permission_type != null) { permission_type.allow (); From 3124838c75912a7e8b27ce1c746aa5d806157c0a Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 14:34:18 +0100 Subject: [PATCH 28/31] color background --- src/Widgets/Browser.vala | 11 +++++++++++ src/Windows/WebApp.vala | 24 ++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Widgets/Browser.vala b/src/Widgets/Browser.vala index 06ea8d7..7b6aefb 100644 --- a/src/Widgets/Browser.vala +++ b/src/Widgets/Browser.vala @@ -67,6 +67,17 @@ namespace Webpin.Widgets { container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + if (desktop_file.color != null) { + var css_provider = Gtk.CssProvider.get_default (); + try { + css_provider.load_from_data (""" .box { background: """ + desktop_file.color.to_string () + """; } """); + } catch (Error err) { + warning (err.message); + } + container.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + container.get_style_context ().add_class ("box"); + } + app_notification = new Granite.Widgets.Toast (""); var overlay = new Gtk.Overlay (); diff --git a/src/Windows/WebApp.vala b/src/Windows/WebApp.vala index 4db5791..056015d 100644 --- a/src/Windows/WebApp.vala +++ b/src/Windows/WebApp.vala @@ -54,7 +54,7 @@ namespace Webpin.Windows { var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); copy_url.tooltip_text = _("Copy URL into clipboard"); copy_url.clicked.connect (() => { - Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.app_view.uri, -1); + Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.web_view.uri, -1); }); headerbar.pack_end (copy_url); @@ -161,7 +161,7 @@ namespace Webpin.Windows { } if (zoom != null) { - browser.app_view.zoom_level = double.parse (zoom); + browser.web_view.zoom_level = double.parse (zoom); } } @@ -186,43 +186,43 @@ namespace Webpin.Windows { case Gdk.Key.KP_Add: case Gdk.Key.plus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - browser.app_view.zoom_level += 0.1; - desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); + browser.web_view.zoom_level += 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.web_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.KP_Subtract: case Gdk.Key.minus: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - browser.app_view.zoom_level -= 0.1; - desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); + browser.web_view.zoom_level -= 0.1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.web_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.KP_0: case Gdk.Key.@0: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - browser.app_view.zoom_level = 1; - desktop_file.edit_property ("X-Webpin-WindowZoom", browser.app_view.zoom_level.to_string ()); + browser.web_view.zoom_level = 1; + desktop_file.edit_property ("X-Webpin-WindowZoom", browser.web_view.zoom_level.to_string ()); return true; } break; case Gdk.Key.F5: if (Gdk.ModifierType.CONTROL_MASK in event.state) { - browser.app_view.reload (); + browser.web_view.reload (); } else { - browser.app_view.reload_bypass_cache (); + browser.web_view.reload_bypass_cache (); } return true; case Gdk.Key.Left: if (Gdk.ModifierType.MOD1_MASK in event.state) { - browser.app_view.go_back (); + browser.web_view.go_back (); return true; } break; case Gdk.Key.Right: if (Gdk.ModifierType.MOD1_MASK in event.state) { - browser.app_view.go_forward (); + browser.web_view.go_forward (); return true; } break; From ede1644164192eaf07d0a1f74c9880927c6d3d13 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 14:35:48 +0100 Subject: [PATCH 29/31] Add files via upload --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..423da6e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ + sudo: required + language: generic + + services: + - docker + + script: + - wget -O- https://raw.githubusercontent.com/harisvsulaiman/element-build/master/script.sh | sh - + + branches: + except: + - /^debian\/\d/ From 4ce318fb46a09d022b87559dbc7b228967ac8c3d Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 26 Nov 2017 14:47:20 +0100 Subject: [PATCH 30/31] appdata.xml --- data/com.github.artemanufrij.webpin.appdata.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index fda1276..fd8eac4 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -37,6 +37,7 @@

    New:

    • Option for Dark Theme
    • +
    • Grab theme-color of called website if exists
    From 4010356dafd9ecbc14b66d90207f844a6c21c956 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Mon, 27 Nov 2017 19:58:15 +0100 Subject: [PATCH 31/31] appdata.xml --- data/com.github.artemanufrij.webpin.appdata.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/com.github.artemanufrij.webpin.appdata.xml b/data/com.github.artemanufrij.webpin.appdata.xml index fd8eac4..dfaf69d 100644 --- a/data/com.github.artemanufrij.webpin.appdata.xml +++ b/data/com.github.artemanufrij.webpin.appdata.xml @@ -32,12 +32,12 @@ - +

    New:

    • Option for Dark Theme
    • -
    • Grab theme-color of called website if exists
    • +
    • Grab 'theme-color' (if exists) from called website