From e080811e4361279af1aaecc71bc2a67e1144d036 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 21:28:19 -0300 Subject: [PATCH 01/13] use margin_start & margin_end instead of margin_left & margin_right --- src/views/SiteListView.vala | 2 +- src/views/SiteView.vala | 2 +- src/widgets/SiteItem.vala | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/views/SiteListView.vala b/src/views/SiteListView.vala index ec8b306..b6db936 100644 --- a/src/views/SiteListView.vala +++ b/src/views/SiteListView.vala @@ -45,7 +45,7 @@ namespace App.Views { this.content = new Gtk.Box (Gtk.Orientation.VERTICAL, 10); this.headerLabel = new Granite.HeaderLabel (""); - this.headerLabel.margin_left = 15; + this.headerLabel.margin_start = 15; this.headerLabel.get_style_context ().add_class ("h1"); this.content.add (this.headerLabel); diff --git a/src/views/SiteView.vala b/src/views/SiteView.vala index 249156f..253bbe3 100644 --- a/src/views/SiteView.vala +++ b/src/views/SiteView.vala @@ -65,7 +65,7 @@ namespace App.Views { this.urlLabel = new Gtk.Label (null); this.updateButton = new Gtk.Button.from_icon_name ("edit-symbolic", Gtk.IconSize.BUTTON); this.updateButton.get_style_context ().add_class ("image-button"); - this.updateButton.margin_left = 10; + this.updateButton.margin_start = 10; this.updateButton.clicked.connect (() => { this.updatePopover.show (); this.formView.clear (); diff --git a/src/widgets/SiteItem.vala b/src/widgets/SiteItem.vala index babdf06..62d0cb9 100644 --- a/src/widgets/SiteItem.vala +++ b/src/widgets/SiteItem.vala @@ -67,7 +67,7 @@ namespace App.Widgets { this.nextImage.opacity = 0.3; var imageBox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - imageBox.margin_left = 10; + imageBox.margin_start = 10; imageBox.valign = Gtk.Align.CENTER; imageBox.width_request = 28; imageBox.add (Site.get_icon_image ()); @@ -80,7 +80,7 @@ namespace App.Widgets { statusGrid.hexpand = true; statusGrid.halign = Gtk.Align.END; statusGrid.valign = Gtk.Align.CENTER; - statusGrid.margin_right = 10; + statusGrid.margin_end = 10; var statusBox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); statusBox.width_request = 100; From 0415e579508b6d928115da5eba4de45cc8c02aba Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 22:12:26 -0300 Subject: [PATCH 02/13] Use elipsis instead of three dots --- post_install.py | 2 +- src/views/SiteListView.vala | 2 +- src/widgets/HeaderBar.vala | 2 +- src/widgets/IndicatorItem.vala | 2 +- src/widgets/SiteItem.vala | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/post_install.py b/post_install.py index 846fd49..636507d 100644 --- a/post_install.py +++ b/post_install.py @@ -6,5 +6,5 @@ schemadir = os.path.join(os.environ['MESON_INSTALL_PREFIX'], 'share', 'glib-2.0', 'schemas') if not os.environ.get('DESTDIR'): - print('Compiling gsettings schemas...') + print('Compiling gsettings schemas…') subprocess.call(['glib-compile-schemas', schemadir], shell=False) \ No newline at end of file diff --git a/src/views/SiteListView.vala b/src/views/SiteListView.vala index b6db936..3faa426 100644 --- a/src/views/SiteListView.vala +++ b/src/views/SiteListView.vala @@ -87,7 +87,7 @@ namespace App.Views { if (results != null && results >= 0) { switch (results) { case 0: - text = _("No results..."); + text = _("No results…"); break; case 1: text = "1 " + _("result"); diff --git a/src/widgets/HeaderBar.vala b/src/widgets/HeaderBar.vala index 78ff6d9..22c67cf 100644 --- a/src/widgets/HeaderBar.vala +++ b/src/widgets/HeaderBar.vala @@ -83,7 +83,7 @@ namespace App.Widgets { this.searchEntry = new Gtk.SearchEntry (); - this.searchEntry.placeholder_text = _("Filter sites..."); + this.searchEntry.placeholder_text = _("Filter sites…"); this.searchEntry.search_changed.connect (() => { this.filter (this.searchEntry.text); }); diff --git a/src/widgets/IndicatorItem.vala b/src/widgets/IndicatorItem.vala index a5fba0e..64fa486 100644 --- a/src/widgets/IndicatorItem.vala +++ b/src/widgets/IndicatorItem.vala @@ -59,7 +59,7 @@ namespace App.Widgets { private void update () { var label = Site.url + ((Site.title != null && Site.title.length > 0) ? " - " + Site.title : ""); if (label.length > 45) { - label = label.substring (0, 45) + "..."; + label = label.substring (0, 45) + "…"; } if (this.previousLabel != null && this.previousLabel != this.label) { diff --git a/src/widgets/SiteItem.vala b/src/widgets/SiteItem.vala index 62d0cb9..923baac 100644 --- a/src/widgets/SiteItem.vala +++ b/src/widgets/SiteItem.vala @@ -114,7 +114,7 @@ namespace App.Widgets { public void update () { var title = Site.title ?? "--"; if (title.length > 35) { - title = title.substring (0, 35) + "..."; + title = title.substring (0, 35) + "…"; } this.titleLabel.label = title; From 6bf5d525b989e51308929590c6533f4cfc681c3a Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 22:58:39 -0300 Subject: [PATCH 03/13] use the correct form of verbatim strings --- src/models/ResultModel.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/ResultModel.vala b/src/models/ResultModel.vala index 7274415..db86f5f 100644 --- a/src/models/ResultModel.vala +++ b/src/models/ResultModel.vala @@ -103,7 +103,7 @@ namespace App.Models { // Update SQL if (id > 0) { state = SiteEvent.UPDATED; - sql = " + sql = """ UPDATE `results` SET `site_id` = $SITE_ID, `response` = $RESPONSE, @@ -113,15 +113,15 @@ namespace App.Models { `created_dt` = $CREATED_DT WHERE `id` = $ID - "; + """; } // Insert SQL else { - sql = " + sql = """ INSERT INTO `results` (`site_id`, `response`, `response_code`, `status`, `offline`, `created_dt`) VALUES ($SITE_ID, $RESPONSE, $RESPONSE_CODE, $STATUS, $OFFLINE, $CREATED_DT) - "; + """; this.created_dt = (new DateTime.now_utc ()).to_unix (); } From 1738a8fca4a83b960610783375310c6bfc7d3688 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:02:00 -0300 Subject: [PATCH 04/13] fix warning: use explicit .begin --- src/models/SiteModel.vala | 4 ++-- src/views/SiteView.vala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index 24642f0..1b3a728 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -433,10 +433,10 @@ namespace App.Models { private void update_icon () { var iconFile = this.get_icon_file (); if (iconFile != null) { - this._iconImage.set_from_file_async (iconFile, 32, 32, true); + this._iconImage.set_from_file_async.begin (iconFile, 32, 32, true); } else { - this._iconImage.set_from_icon_name_async ("www", Gtk.IconSize.DND); + this._iconImage.set_from_icon_name_async.begin ("www", Gtk.IconSize.DND); } } diff --git a/src/views/SiteView.vala b/src/views/SiteView.vala index 253bbe3..5ac4249 100644 --- a/src/views/SiteView.vala +++ b/src/views/SiteView.vala @@ -163,10 +163,10 @@ namespace App.Views { var iconFile = Site.get_icon_file (); if (iconFile != null) { - this.iconImage.set_from_file_async (iconFile, 64, 64, true); + this.iconImage.set_from_file_async.begin (iconFile, 64, 64, true); } else { - this.iconImage.set_from_icon_name_async ("www", Gtk.IconSize.DIALOG); + this.iconImage.set_from_icon_name_async.begin ("www", Gtk.IconSize.DIALOG); } Gtk.TreeIter iter; From 4c0f5acc5a2e9bda2b3cfbbfdf8bc2e661130b8b Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:08:25 -0300 Subject: [PATCH 05/13] fix vala-lint warning 'space-before-paren' --- src/models/SiteModel.vala | 2 +- src/utils/FileUtil.vala | 2 +- src/utils/URLUtil.vala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index 1b3a728..bdf6c45 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -127,7 +127,7 @@ namespace App.Models { this.updated_dt = val.to_int64 (); break; case "icon_updated_dt": - this.icon_updated_dt = val.to_int64(); + this.icon_updated_dt = val.to_int64 (); break; } } diff --git a/src/utils/FileUtil.vala b/src/utils/FileUtil.vala index eb66321..3aef3ff 100644 --- a/src/utils/FileUtil.vala +++ b/src/utils/FileUtil.vala @@ -64,7 +64,7 @@ namespace App.Utils { if (!directory.query_exists ()) { // Create directory and parent directories if none exist - directory.make_directory_with_parents(); + directory.make_directory_with_parents (); } var file = File.new_for_path (dir + "/" + name_file); diff --git a/src/utils/URLUtil.vala b/src/utils/URLUtil.vala index 2c12188..6998f2f 100644 --- a/src/utils/URLUtil.vala +++ b/src/utils/URLUtil.vala @@ -43,7 +43,7 @@ namespace App.Utils { } } catch (RegexError e) { - GLib.message("Erro: %s", e.message); + GLib.message ("Erro: %s", e.message); } return true; From 5ab0324569c146a6ee50a3280250a4cc320bdff2 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:10:33 -0300 Subject: [PATCH 06/13] fix vala-lint warning 'use-of-tabs' --- src/controllers/AppController.vala | 6 +- src/models/BaseModel.vala | 4 +- src/models/ResultModel.vala | 6 +- src/models/SiteModel.vala | 6 +- src/utils/FileUtil.vala | 144 ++++++++++++++--------------- src/utils/URLUtil.vala | 44 ++++----- src/views/AppIndicatorView.vala | 8 +- src/views/AppView.vala | 12 +-- src/views/SiteFormView.vala | 10 +- src/views/SiteListView.vala | 8 +- src/views/SiteView.vala | 8 +- src/views/WelcomeView.vala | 10 +- 12 files changed, 133 insertions(+), 133 deletions(-) diff --git a/src/controllers/AppController.vala b/src/controllers/AppController.vala index ecd3de9..dd42e9d 100644 --- a/src/controllers/AppController.vala +++ b/src/controllers/AppController.vala @@ -29,7 +29,7 @@ namespace App.Controllers { * * @since 1.0.0 */ - public class AppController { + public class AppController { private Gtk.Application application; private AppView appView; @@ -47,7 +47,7 @@ namespace App.Controllers { /** * Constructs a new {@code AppController} object. */ - public AppController (Gtk.ApplicationWindow window, Gtk.Application application) { + public AppController (Gtk.ApplicationWindow window, Gtk.Application application) { this.settings = App.Configs.Settings.get_instance (); this.window = window; @@ -233,5 +233,5 @@ namespace App.Controllers { this.application.add_accelerator ("f", "app.find", null); this.application.add_accelerator ("q", "app.quit", null); } - } + } } diff --git a/src/models/BaseModel.vala b/src/models/BaseModel.vala index 50f7ffe..cd1355f 100644 --- a/src/models/BaseModel.vala +++ b/src/models/BaseModel.vala @@ -21,7 +21,7 @@ namespace App.Models { * * @since 1.0.0 */ - public abstract class BaseModel { + public abstract class BaseModel { protected unowned App.Database.DB db { get { return App.Database.DB.GetInstance (); } } @@ -29,6 +29,6 @@ namespace App.Models { public abstract bool load (Sqlite.Statement statement); public abstract bool save (); public abstract bool delete (); - } + } } diff --git a/src/models/ResultModel.vala b/src/models/ResultModel.vala index db86f5f..6229932 100644 --- a/src/models/ResultModel.vala +++ b/src/models/ResultModel.vala @@ -24,7 +24,7 @@ namespace App.Models { * * @since 1.0.0 */ - public class ResultModel : BaseModel { + public class ResultModel : BaseModel { public int id { get; set; } public int site_id { get; set; } @@ -39,7 +39,7 @@ namespace App.Models { /** * Constructs a new {@code ResultModel} object. */ - public ResultModel () {} + public ResultModel () {} public ResultModel.with_details (int site, double response, int code, string status) { this.site_id = site; @@ -151,6 +151,6 @@ namespace App.Models { public override bool delete () { return false; } - } + } } diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index bdf6c45..e48103b 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -24,7 +24,7 @@ namespace App.Models { * * @since 1.0.0 */ - public class SiteModel : BaseModel { + public class SiteModel : BaseModel { private int failures = 0; private bool fetching_icon = false; @@ -51,7 +51,7 @@ namespace App.Models { /** * Constructs a new {@code SiteModel} object. */ - public SiteModel () { + public SiteModel () { session = new Soup.Session (); session.timeout = 60; session.user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36"; @@ -456,6 +456,6 @@ namespace App.Models { return null; } - } + } } diff --git a/src/utils/FileUtil.vala b/src/utils/FileUtil.vala index 3aef3ff..8e85402 100644 --- a/src/utils/FileUtil.vala +++ b/src/utils/FileUtil.vala @@ -19,92 +19,92 @@ namespace App.Utils { - /** + /** * The {@code FileUtil} class related to files handling. * * @since 1.0.0 */ public class FileUtil { - /** - * Open folder in app files. - * - * Exemple: - * > FileUtil.open_folder_files(uris) - * - * @param {@code string} - uris - */ - public static void open_folder_file_app (string[] uris) { - string cmd = "pantheon-files -t"; + /** + * Open folder in app files. + * + * Exemple: + * > FileUtil.open_folder_files(uris) + * + * @param {@code string} - uris + */ + public static void open_folder_file_app (string[] uris) { + string cmd = "pantheon-files -t"; - foreach (string s in uris) { - cmd += (StringUtil.SPACE + s); - } + foreach (string s in uris) { + cmd += (StringUtil.SPACE + s); + } - try { - Process.spawn_command_line_async (cmd); - } catch (Error e) { - critical ("Unable to open item or folder with command %s. %s".printf (cmd, e.message)); - } - } + try { + Process.spawn_command_line_async (cmd); + } catch (Error e) { + critical ("Unable to open item or folder with command %s. %s".printf (cmd, e.message)); + } + } - /** - * Create file and write. - * - * Exemple: - * > FileUtil.create_file("/etc", "ola.text", array.data); - * - * @param {@code string} - dir - * @param {@code string} - name_file - * @param {@code GenericArray > data} - words - */ - public static void create_file (string dir, string name_file, string[] words) { - try { - var directory = File.new_for_path (dir); - - if (!directory.query_exists ()) { - // Create directory and parent directories if none exist - directory.make_directory_with_parents (); - } + /** + * Create file and write. + * + * Exemple: + * > FileUtil.create_file("/etc", "ola.text", array.data); + * + * @param {@code string} - dir + * @param {@code string} - name_file + * @param {@code GenericArray > data} - words + */ + public static void create_file (string dir, string name_file, string[] words) { + try { + var directory = File.new_for_path (dir); + + if (!directory.query_exists ()) { + // Create directory and parent directories if none exist + directory.make_directory_with_parents (); + } - var file = File.new_for_path (dir + "/" + name_file); - var text = StringUtil.EMPTY; + var file = File.new_for_path (dir + "/" + name_file); + var text = StringUtil.EMPTY; - foreach (string word in words) { - text += (StringUtil.SPACE + word); - } + foreach (string word in words) { + text += (StringUtil.SPACE + word); + } - if (!file.query_exists ()) { - var file_stream = file.create (FileCreateFlags.NONE); - var data_stream = new DataOutputStream (file_stream); - data_stream.put_string (text); - } + if (!file.query_exists ()) { + var file_stream = file.create (FileCreateFlags.NONE); + var data_stream = new DataOutputStream (file_stream); + data_stream.put_string (text); + } - } catch (Error e) { - critical (e.message); - } - } + } catch (Error e) { + critical (e.message); + } + } - /** - * Delete file. - * - * Exemple: - * > FileUtil.delete_file("/etc", "ola.text"); - * - * @param {@code string} - dir - * @param {@code string} - name_file - */ - public static void delete_file (string dir, string name_file) { - try { - var file = File.new_for_path (dir + "/" + name_file); + /** + * Delete file. + * + * Exemple: + * > FileUtil.delete_file("/etc", "ola.text"); + * + * @param {@code string} - dir + * @param {@code string} - name_file + */ + public static void delete_file (string dir, string name_file) { + try { + var file = File.new_for_path (dir + "/" + name_file); - if (file.query_exists ()) { - file.delete (); - } + if (file.query_exists ()) { + file.delete (); + } - } catch (Error e) { - critical (e.message); - } - } - } + } catch (Error e) { + critical (e.message); + } + } + } } \ No newline at end of file diff --git a/src/utils/URLUtil.vala b/src/utils/URLUtil.vala index 6998f2f..ef925cb 100644 --- a/src/utils/URLUtil.vala +++ b/src/utils/URLUtil.vala @@ -19,34 +19,34 @@ namespace App.Utils { - /** + /** * The {@code URLUtil} class is responsible for manipulating urls. * * @since 1.0.0 */ public class URLUtil { - /** - * Check if url is valid. - * - * Exemple: - * > URLUtil.check_url_with_regex("https://elementary.io"); - * - * @param {@code string} url - */ - public static bool check_url_with_regex (string url) { - try { - var regex = new Regex ("""(http|https)://[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?"""); - - if (!regex.match (url)) { - return false; - } + /** + * Check if url is valid. + * + * Exemple: + * > URLUtil.check_url_with_regex("https://elementary.io"); + * + * @param {@code string} url + */ + public static bool check_url_with_regex (string url) { + try { + var regex = new Regex ("""(http|https)://[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?"""); + + if (!regex.match (url)) { + return false; + } - } catch (RegexError e) { - GLib.message ("Erro: %s", e.message); - } + } catch (RegexError e) { + GLib.message ("Erro: %s", e.message); + } - return true; - } - } + return true; + } + } } diff --git a/src/views/AppIndicatorView.vala b/src/views/AppIndicatorView.vala index 558b219..606ba8b 100644 --- a/src/views/AppIndicatorView.vala +++ b/src/views/AppIndicatorView.vala @@ -21,22 +21,22 @@ using App.Widgets; namespace App.Views { - /** + /** * The {@code AppView} class. * * @since 1.0.0 */ - public class AppIndicatorView : Gtk.Menu { + public class AppIndicatorView : Gtk.Menu { public signal void menu_event (SiteModel? site, IndicatorEvent event); private Gee.HashMap sitesList = new Gee.HashMap (); private AppIndicator.Indicator indicator; - /** + /** * Constructs a new {@code AppIndicatorView} object. */ - public AppIndicatorView (AppIndicator.Indicator indicator) { + public AppIndicatorView (AppIndicator.Indicator indicator) { this.indicator = indicator; build_menu (); } diff --git a/src/views/AppView.vala b/src/views/AppView.vala index cca4523..b2bf6ab 100644 --- a/src/views/AppView.vala +++ b/src/views/AppView.vala @@ -21,12 +21,12 @@ using App.Widgets; namespace App.Views { - /** + /** * The {@code AppView} class. * * @since 1.0.0 */ - public class AppView : Gtk.Grid { + public class AppView : Gtk.Grid { private Gtk.ApplicationWindow app; private SiteView activeSiteView; @@ -40,16 +40,16 @@ namespace App.Views { public signal void menu_event (SiteModel? site, IndicatorEvent event); public signal void site_event (SiteModel site, SiteEvent event); - /** + /** * Constructs a new {@code AppView} object. */ - public AppView (Gtk.ApplicationWindow app) { + public AppView (Gtk.ApplicationWindow app) { this.app = app; this.app.set_default_size (700, 600); this.app.set_size_request (700, 600); this.app.deletable = true; this.app.resizable = true; - + this.headerbar = new HeaderBar (); this.headerbar.menu_event.connect ((site, event) => { this.menu_event (site, event); }); this.headerbar.site_event.connect ((site, event) => { this.site_event (site, event); }); @@ -121,5 +121,5 @@ namespace App.Views { this.stack.visible_child_name = "main-content"; this.headerbar.hide_back (); } - } + } } diff --git a/src/views/SiteFormView.vala b/src/views/SiteFormView.vala index 0a099a0..f4c9610 100644 --- a/src/views/SiteFormView.vala +++ b/src/views/SiteFormView.vala @@ -21,12 +21,12 @@ using App.Widgets; namespace App.Views { - /** + /** * The {@code AppView} class. * * @since 1.0.0 */ - public class SiteFormView : Gtk.Box { + public class SiteFormView : Gtk.Box { public signal void site_event (SiteModel site, SiteEvent event); @@ -38,10 +38,10 @@ namespace App.Views { private SiteModel site; private Gtk.Entry urlEntry; - /** + /** * Constructs a new {@code SiteFormView} object. */ - public SiteFormView (SiteModel? site = null) { + public SiteFormView (SiteModel? site = null) { this.site = site; this.urlEntry = new Gtk.Entry (); @@ -174,5 +174,5 @@ namespace App.Views { this.deleteButton.visible = (this.site != null) ? true : false; } - } + } } diff --git a/src/views/SiteListView.vala b/src/views/SiteListView.vala index 3faa426..5cf82ed 100644 --- a/src/views/SiteListView.vala +++ b/src/views/SiteListView.vala @@ -22,12 +22,12 @@ using App.Widgets; namespace App.Views { - /** + /** * The {@code SiteListView} class. * * @since 1.0.0 */ - public class SiteListView : Gtk.Viewport { + public class SiteListView : Gtk.Viewport { private Gtk.Label headerLabel; private Gtk.Box content; @@ -35,7 +35,7 @@ namespace App.Views { public signal void site_selected (SiteModel site); - /** + /** * Constructs a new {@code SiteListView} object. */ public SiteListView () { @@ -141,5 +141,5 @@ namespace App.Views { this.update_header (results); Gtk.StyleContext.reset_widgets (get_style_context ().screen); } - } + } } diff --git a/src/views/SiteView.vala b/src/views/SiteView.vala index 5ac4249..bc7b89b 100644 --- a/src/views/SiteView.vala +++ b/src/views/SiteView.vala @@ -22,12 +22,12 @@ using App.Widgets; namespace App.Views { - /** + /** * The {@code SiteView} class. * * @since 1.0.0 */ - public class SiteView : Gtk.Box { + public class SiteView : Gtk.Box { private Gtk.ScrolledWindow scrollResultsWindow; private Gtk.Viewport resultsViewport; @@ -48,7 +48,7 @@ namespace App.Views { public SiteModel Site { get { return _site; } } - /** + /** * Constructs a new {@code SiteView} object. */ public SiteView (SiteModel site) { @@ -230,5 +230,5 @@ namespace App.Views { this.treeView.set_model (store); this.treeView.show_all (); } - } + } } diff --git a/src/views/WelcomeView.vala b/src/views/WelcomeView.vala index b23ee0e..110bc56 100644 --- a/src/views/WelcomeView.vala +++ b/src/views/WelcomeView.vala @@ -19,19 +19,19 @@ using App.Configs; namespace App.Views { - /** + /** * The {@code WelcomeView} class. * * @since 1.0.0 */ - public class WelcomeView : Gtk.Viewport { + public class WelcomeView : Gtk.Viewport { - /** + /** * Constructs a new {@code WelcomeView} object. */ - public WelcomeView () { + public WelcomeView () { var welcome = new Granite.Widgets.Welcome (_("Start monitoring your sites"), _("Add a new site to begin")); this.add (welcome); } - } + } } From dbf4cd48a9b92149418cff5b49a623e30a32d858 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:15:43 -0300 Subject: [PATCH 07/13] fix vala-lint warning 'trailing-whitespace' --- src/Application.vala | 4 ++-- src/Window.vala | 8 ++++---- src/configs/Constants.vala | 2 +- src/configs/Properties.vala | 2 +- src/configs/Settings.vala | 10 +++++----- src/controllers/AppController.vala | 18 +++++++++--------- src/database/Database.vala | 6 +++--- src/models/ResultModel.vala | 4 ++-- src/models/SiteModel.vala | 16 ++++++++-------- src/utils/FileUtil.vala | 14 +++++++------- src/utils/StringUtil.vala | 10 +++++----- src/utils/TimeUtil.vala | 10 +++++----- src/utils/URLUtil.vala | 6 +++--- src/utils/WidgetUtil.vala | 4 ++-- src/views/AppIndicatorView.vala | 8 ++++---- src/views/AppView.vala | 8 ++++---- src/views/SiteFormView.vala | 16 ++++++++-------- src/views/SiteListView.vala | 4 ++-- src/views/SiteView.vala | 14 +++++++------- src/widgets/HeaderBar.vala | 10 +++++----- src/widgets/IndicatorItem.vala | 2 +- src/widgets/SiteItem.vala | 6 +++--- 22 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 6ed3fb5..0f0c14a 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -51,7 +51,7 @@ namespace App { /** * Create the window of this application through the class {@code Window} and show it. If user clicks * or press the window will be destroyed. - * + * * @return {@code void} */ public override void activate () { @@ -81,7 +81,7 @@ namespace App { if (x != -1 && y != -1) { window.move (x, y); } - + window.get_focus (); window.no_show_all = false; window.show_all (); diff --git a/src/Window.vala b/src/Window.vala index 95490b7..89f8574 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -24,14 +24,14 @@ using App.Views; namespace App { /** - * Class responsible for creating the u window and will contain contain other widgets. + * Class responsible for creating the u window and will contain contain other widgets. * allowing the user to manipulate the window (resize it, move it, close it, ...). * * @see Gtk.ApplicationWindow * @since 1.0.0 */ public class Window : Gtk.ApplicationWindow { - + /** * Constructs a new {@code Window} object. * @@ -57,13 +57,13 @@ namespace App { var css_provider = new Gtk.CssProvider (); css_provider.load_from_resource (Constants.URL_CSS); - + Gtk.StyleContext.add_provider_for_screen ( Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION ); - + new AppController (this, app); } } diff --git a/src/configs/Constants.vala b/src/configs/Constants.vala index 098bcd0..7c2e831 100644 --- a/src/configs/Constants.vala +++ b/src/configs/Constants.vala @@ -17,7 +17,7 @@ namespace App.Configs { /** - * The {@code Constants} class is responsible for defining all + * The {@code Constants} class is responsible for defining all * the constants used in the application. * * @since 1.0.0 diff --git a/src/configs/Properties.vala b/src/configs/Properties.vala index 3d02176..ecfa0e8 100644 --- a/src/configs/Properties.vala +++ b/src/configs/Properties.vala @@ -20,7 +20,7 @@ namespace App.Configs { /** - * The {@code Properties} class is responsible for defining all + * The {@code Properties} class is responsible for defining all * the texts that are displayed in the application and must be translated. * * @since 1.0.0 diff --git a/src/configs/Settings.vala b/src/configs/Settings.vala index 7eecab5..02ebbca 100644 --- a/src/configs/Settings.vala +++ b/src/configs/Settings.vala @@ -20,7 +20,7 @@ namespace App.Configs { /** - * The {@code Settings} class is responsible for defining all + * The {@code Settings} class is responsible for defining all * the texts that are displayed in the application and must be translated. * * @see Granite.Services.Settings @@ -52,11 +52,11 @@ namespace App.Configs { * Should application start hidden */ public bool hide_on_start { get; set; } - + /** - * Constructs a new {@code Settings} object + * Constructs a new {@code Settings} object * and sets the default exit folder. - * + * * @see webwatcher.Utils.StringUtil#is_empty(string) * @see webwatcher.Constants */ @@ -66,7 +66,7 @@ namespace App.Configs { /** * Returns a single instance of this class. - * + * * @return {@code Settings} */ public static unowned Settings get_instance () { diff --git a/src/controllers/AppController.vala b/src/controllers/AppController.vala index dd42e9d..47a4412 100644 --- a/src/controllers/AppController.vala +++ b/src/controllers/AppController.vala @@ -79,7 +79,7 @@ namespace App.Controllers { this.indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE); this.indicatorView = new AppIndicatorView (indicator); this.indicatorView.menu_event.connect (this.indicator_event); - + // Initialize our database and get a list of active locations this.database = DB.GetInstance (); var statement = this.database.Prepare ("SELECT id FROM `sites` ORDER BY `order` ASC"); @@ -140,7 +140,7 @@ namespace App.Controllers { return true; }); } - + private void site_changed (SiteModel site, SiteEvent event) { switch (event) { case SiteEvent.ADDED: @@ -171,27 +171,27 @@ namespace App.Controllers { if (!site.notify || !site.active) { return; } - + var title = (event == SiteEvent.ONLINE) ? _("Website is up") : _("Website is down"); var body = (site.title != null) ? site.title + "\n" + site.url : site.url; - + var notification = new Notification (title); notification.set_body (body); notification.set_priority (NotificationPriority.NORMAL); - + if (site.icon != null && site.icon != "") { notification.set_icon (site.get_icon_image ().gicon_async); } - + application.send_notification (Constants.ID, notification); - + if (event == SiteEvent.ONLINE) { this.offlineCount--; } else { this.offlineCount++; } - + this.launcherEntry.count_visible = this.offlineCount > 0; this.launcherEntry.count = this.offlineCount; break; @@ -229,7 +229,7 @@ namespace App.Controllers { this.application.add_action (find_action); this.application.add_action (quit_action); - + this.application.add_accelerator ("f", "app.find", null); this.application.add_accelerator ("q", "app.quit", null); } diff --git a/src/database/Database.vala b/src/database/Database.vala index d9164f4..d6aeed5 100644 --- a/src/database/Database.vala +++ b/src/database/Database.vala @@ -21,7 +21,7 @@ namespace App.Database { /** - * The {@code Database} provides all of the basic functions + * The {@code Database} provides all of the basic functions * needed to access and maintain the Sqlite database * * @see Sqlite.Database @@ -105,7 +105,7 @@ namespace App.Database { CREATE INDEX `active` ON `sites` (active); CREATE INDEX `title` ON `sites` (title); CREATE INDEX `updated_dt` ON `sites` (updated_dt); - CREATE UNIQUE INDEX `url` ON `sites` (url); + CREATE UNIQUE INDEX `url` ON `sites` (url); "; this.Execute (sitesSQL); @@ -164,7 +164,7 @@ namespace App.Database { Sqlite.Statement statement; var result = this.db.prepare_v2 (query, query.length, out statement); errorMsg = ""; - + if (result != Sqlite.OK) { warning ("Error querying DB: %d - %s", this.db.errcode (), this.db.errmsg ()); errorMsg = this.db.errmsg (); diff --git a/src/models/ResultModel.vala b/src/models/ResultModel.vala index 6229932..e6503e6 100644 --- a/src/models/ResultModel.vala +++ b/src/models/ResultModel.vala @@ -95,7 +95,7 @@ namespace App.Models { return loaded; } - + public override bool save () { var sql = ""; var state = SiteEvent.ADDED; @@ -144,7 +144,7 @@ namespace App.Models { if (state == SiteEvent.ADDED) { this.id = (int)this.db.LastID (); } - + return true; } diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index e48103b..c2ece29 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -144,7 +144,7 @@ namespace App.Models { return loaded; } - + public override bool save () { var sql = ""; var state = SiteEvent.ADDED; @@ -203,7 +203,7 @@ namespace App.Models { if (state == SiteEvent.ADDED) { this.id = (int)this.db.LastID (); } - + this.update_icon (); this.changed (this, state); return true; @@ -261,7 +261,7 @@ namespace App.Models { if (this.status == "bad") { this.changed (this, SiteEvent.ONLINE); } - + this.status = "good"; this.failures = 0; } @@ -300,7 +300,7 @@ namespace App.Models { new ResultModel.with_details (this.id, this.response, (int)statusCode, this.status); this.running = false; - this.save (); + this.save (); // If everything is good and the last time we updated the icon was more than 5 minutes ago, fetch a new icon if (this.status == "good" && currentTime - this.icon_updated_dt > 300) { @@ -314,10 +314,10 @@ namespace App.Models { if (this.fetching_icon) { return; } - + info ("Fetching updated icon for " + this.url); this.fetching_icon = true; - + var currentTime = (new DateTime.now_utc ()).to_unix (); var message = new Soup.Message ("GET", "https://favicongrabber.com/api/grab/" + this.url.replace ("http://", "").replace ("https://", "")); @@ -364,7 +364,7 @@ namespace App.Models { if (iconObj.has_member ("sizes")) { string sizeString = iconObj.get_string_member ("sizes"); int64 iconSize; - + if (!int64.try_parse (sizeString.substring (sizeString.index_of ("x") + 1), out iconSize)) { continue; } @@ -412,7 +412,7 @@ namespace App.Models { var file = File.new_for_path (_iconDir + name); var outputStream = file.replace (null, false, FileCreateFlags.NONE); var dataOutputStream = new DataOutputStream (outputStream); - + long written = 0; while (written < data.length) { written += dataOutputStream.write (data[written:data.length]); diff --git a/src/utils/FileUtil.vala b/src/utils/FileUtil.vala index 8e85402..9c79e5e 100644 --- a/src/utils/FileUtil.vala +++ b/src/utils/FileUtil.vala @@ -31,7 +31,7 @@ namespace App.Utils { * * Exemple: * > FileUtil.open_folder_files(uris) - * + * * @param {@code string} - uris */ public static void open_folder_file_app (string[] uris) { @@ -53,7 +53,7 @@ namespace App.Utils { * * Exemple: * > FileUtil.create_file("/etc", "ola.text", array.data); - * + * * @param {@code string} - dir * @param {@code string} - name_file * @param {@code GenericArray > data} - words @@ -61,11 +61,11 @@ namespace App.Utils { public static void create_file (string dir, string name_file, string[] words) { try { var directory = File.new_for_path (dir); - + if (!directory.query_exists ()) { // Create directory and parent directories if none exist directory.make_directory_with_parents (); - } + } var file = File.new_for_path (dir + "/" + name_file); var text = StringUtil.EMPTY; @@ -74,7 +74,7 @@ namespace App.Utils { text += (StringUtil.SPACE + word); } - if (!file.query_exists ()) { + if (!file.query_exists ()) { var file_stream = file.create (FileCreateFlags.NONE); var data_stream = new DataOutputStream (file_stream); data_stream.put_string (text); @@ -90,7 +90,7 @@ namespace App.Utils { * * Exemple: * > FileUtil.delete_file("/etc", "ola.text"); - * + * * @param {@code string} - dir * @param {@code string} - name_file */ @@ -98,7 +98,7 @@ namespace App.Utils { try { var file = File.new_for_path (dir + "/" + name_file); - if (file.query_exists ()) { + if (file.query_exists ()) { file.delete (); } diff --git a/src/utils/StringUtil.vala b/src/utils/StringUtil.vala index 0bd507a..59bb7c9 100644 --- a/src/utils/StringUtil.vala +++ b/src/utils/StringUtil.vala @@ -42,7 +42,7 @@ namespace App.Utils { /** * A empty string. - * + * * Exemple: * > StringUtil.EMPTY */ @@ -50,7 +50,7 @@ namespace App.Utils { /** * Break line. - * + * * Exemple: * > StringUtil.BREAK_LINE */ @@ -65,7 +65,7 @@ namespace App.Utils { * > StringUtil.is_empty(" ") = false * > StringUtil.is_empty("test") = false * > StringUtil.is_empty(" test ") = false - * + * * @param {@code string} value - the string to check, not may be null * @return {@code bool} true - if the string is empty or null */ @@ -92,7 +92,7 @@ namespace App.Utils { /** * Checks if a string is empty (""), null or with whitespace. - * + * * Exemple: * > StringUtil.is_blank(null) = true * > StringUtil.is_blank("") = true @@ -119,7 +119,7 @@ namespace App.Utils { /** * Checks if a string is not empty (""), not null or has no whitespace. - * + * * Exemple: * > StringUtil.is_not_blank(null) = false * > StringUtil.is_not_blank("") = false diff --git a/src/utils/TimeUtil.vala b/src/utils/TimeUtil.vala index 6bad4e4..126a710 100644 --- a/src/utils/TimeUtil.vala +++ b/src/utils/TimeUtil.vala @@ -15,7 +15,7 @@ * License along with this program; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA -* +* */ namespace App.Utils { @@ -26,14 +26,14 @@ namespace App.Utils { * @since 1.0.0 */ public class TimeUtil { - + /** - * Responsible for getting the value of in string duration in + * Responsible for getting the value of in string duration in * the format "00:00:00:00.00" and returning the duration in seconds. * * Exemple: * > TimeUtil.duration_in_seconds("00:01:14:36.00") = 74 - * + * * @param {@code string} duration * @return {@code int} */ @@ -44,7 +44,7 @@ namespace App.Utils { var hours = int.parse (time[0]); var mins = int.parse (time[1]); var secs = int.parse (time[2]); - + return secs + (hours * 3600) + (mins * 60); } } diff --git a/src/utils/URLUtil.vala b/src/utils/URLUtil.vala index ef925cb..95bb12c 100644 --- a/src/utils/URLUtil.vala +++ b/src/utils/URLUtil.vala @@ -31,13 +31,13 @@ namespace App.Utils { * * Exemple: * > URLUtil.check_url_with_regex("https://elementary.io"); - * - * @param {@code string} url + * + * @param {@code string} url */ public static bool check_url_with_regex (string url) { try { var regex = new Regex ("""(http|https)://[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?"""); - + if (!regex.match (url)) { return false; } diff --git a/src/utils/WidgetUtil.vala b/src/utils/WidgetUtil.vala index 830aba5..d67a389 100644 --- a/src/utils/WidgetUtil.vala +++ b/src/utils/WidgetUtil.vala @@ -31,10 +31,10 @@ namespace App.Utils { * * Exemple: * > WidgetUtil.set_visible(widget, true) - * + * * @param {@code widget} widget - component * @param {@code bool} visible - if true the component is displayed if false is not displayed - * @return {@code void} + * @return {@code void} */ public static void set_visible (Gtk.Widget widget, bool visible) { widget.no_show_all = !visible; diff --git a/src/views/AppIndicatorView.vala b/src/views/AppIndicatorView.vala index 606ba8b..f11332a 100644 --- a/src/views/AppIndicatorView.vala +++ b/src/views/AppIndicatorView.vala @@ -44,7 +44,7 @@ namespace App.Views { public void addSite (SiteModel site) { var item = new IndicatorItem (site); item.show_all (); - + item.changed.connect (() => { build_menu (true); }); @@ -79,7 +79,7 @@ namespace App.Views { return; }*/ - + foreach (var child in this.get_children ()) { this.remove (child); } @@ -91,8 +91,8 @@ namespace App.Views { this.add (entry.value); } - - + + var showItem = new Gtk.MenuItem.with_label (_("Show Web Watcher")); showItem.activate.connect (() => { this.menu_event (null, IndicatorEvent.SHOW); diff --git a/src/views/AppView.vala b/src/views/AppView.vala index b2bf6ab..d74635e 100644 --- a/src/views/AppView.vala +++ b/src/views/AppView.vala @@ -49,7 +49,7 @@ namespace App.Views { this.app.set_size_request (700, 600); this.app.deletable = true; this.app.resizable = true; - + this.headerbar = new HeaderBar (); this.headerbar.menu_event.connect ((site, event) => { this.menu_event (site, event); }); this.headerbar.site_event.connect ((site, event) => { this.site_event (site, event); }); @@ -75,7 +75,7 @@ namespace App.Views { this.stack.expand = true; this.stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; this.add (stack); - + this.mainContent = new Gtk.ScrolledWindow (null, null); this.siteContent = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); this.siteContent.hexpand = true; @@ -85,12 +85,12 @@ namespace App.Views { this.stack.add_named (siteContent, "site-content"); this.stack.visible_child_name = "main-content"; } - + public void show_welcome () { foreach (var child in mainContent.get_children ()) { mainContent.remove (child); } - + mainContent.add (this.welcomeView); mainContent.show_all (); } diff --git a/src/views/SiteFormView.vala b/src/views/SiteFormView.vala index f4c9610..9099c36 100644 --- a/src/views/SiteFormView.vala +++ b/src/views/SiteFormView.vala @@ -30,7 +30,7 @@ namespace App.Views { public signal void site_event (SiteModel site, SiteEvent event); - + private Gtk.Switch activeSwitch; private Gtk.Switch alertSwitch; private Gtk.Button deleteButton; @@ -51,7 +51,7 @@ namespace App.Views { this.urlEntry.secondary_icon_tooltip_text = _("Must be a valid URL that starts with http or https"); this.urlEntry.key_press_event.connect (this.handleInput); this.urlEntry.activate.connect (this.handleInputSubmit); - + var urlLabel = new Gtk.Label.with_mnemonic (_("Site _URL") + ":"); urlLabel.halign = Gtk.Align.END; urlLabel.mnemonic_widget = this.urlEntry; @@ -88,7 +88,7 @@ namespace App.Views { grid.column_homogeneous = false; grid.column_spacing = 12; grid.row_spacing = 12; - + grid.attach (urlLabel, 0, 0); grid.attach (urlEntry, 1, 0); grid.attach (alertLabel, 0, 1); @@ -103,7 +103,7 @@ namespace App.Views { grid.attach (saveButton, 1, 3); grid.show_all (); - + this.pack_start (grid, true, true, 0); this.margin = 12; this.orientation = Gtk.Orientation.VERTICAL; @@ -116,7 +116,7 @@ namespace App.Views { } private bool handleInput (Gdk.EventKey key) { - + this.saveButton.sensitive = this.isValid (); return false; } @@ -135,7 +135,7 @@ namespace App.Views { this.site.active = this.activeSwitch.active; this.site.notify = this.alertSwitch.active; this.site.url = this.urlEntry.text; - + if (this.site.save ()) { site_event (this.site, SiteEvent.UPDATED); } @@ -156,7 +156,7 @@ namespace App.Views { this.site.delete (); site_event (this.site, SiteEvent.DELETED); } - + public void clear () { if (this.site != null) { this.activeSwitch.active = this.site.active; @@ -171,7 +171,7 @@ namespace App.Views { this.urlEntry.text = ""; this.urlEntry.has_focus = true; } - + this.deleteButton.visible = (this.site != null) ? true : false; } } diff --git a/src/views/SiteListView.vala b/src/views/SiteListView.vala index 5cf82ed..7e0a244 100644 --- a/src/views/SiteListView.vala +++ b/src/views/SiteListView.vala @@ -41,7 +41,7 @@ namespace App.Views { public SiteListView () { get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW); get_style_context ().add_class (Granite.STYLE_CLASS_WELCOME); - + this.content = new Gtk.Box (Gtk.Orientation.VERTICAL, 10); this.headerLabel = new Granite.HeaderLabel (""); @@ -77,7 +77,7 @@ namespace App.Views { this.content.remove (item); this.update_header (); - + Gtk.StyleContext.reset_widgets (get_style_context ().screen); } diff --git a/src/views/SiteView.vala b/src/views/SiteView.vala index bc7b89b..2608b52 100644 --- a/src/views/SiteView.vala +++ b/src/views/SiteView.vala @@ -76,7 +76,7 @@ namespace App.Views { this.urlBox.margin_bottom = 10; this.urlBox.add (this.urlLabel); this.urlBox.add (this.updateButton); - + this.iconImage = new Granite.AsyncImage (); this.iconImage.margin = 10; @@ -174,19 +174,19 @@ namespace App.Views { var db = App.Database.DB.GetInstance (); var sql = " - SELECT - created_dt, - response, - response_code, + SELECT + created_dt, + response, + response_code, status - FROM `results` + FROM `results` WHERE site_id = $SITE_ID AND created_dt >= $CREATED_DT ORDER BY created_dt DESC"; var statement = db.Prepare (sql); db.bind_int (statement, "$SITE_ID", Site.id); db.bind_int64 (statement, "$CREATED_DT", new DateTime.now_utc ().to_unix () - 7200); - + var columns = statement.column_count (); while (statement.step () == Sqlite.ROW) { var time = ""; diff --git a/src/widgets/HeaderBar.vala b/src/widgets/HeaderBar.vala index 22c67cf..95f0631 100644 --- a/src/widgets/HeaderBar.vala +++ b/src/widgets/HeaderBar.vala @@ -37,7 +37,7 @@ namespace App.Widgets { public signal void site_event (SiteModel site, SiteEvent event); public signal void back (); public signal void filter (string filter); - + private Gtk.Button backButton; private Gtk.Box buttonBox; private Views.SiteFormView formView; @@ -46,7 +46,7 @@ namespace App.Widgets { private Gtk.Button newButton; private Gtk.Popover newPopover; private Gtk.SearchEntry searchEntry; - + /** * Constructs a new {@code HeaderBar} object. @@ -61,7 +61,7 @@ namespace App.Widgets { /** * Add gear icon to open settings menu. - * + * * @see menu_settings * @return {@code void} */ @@ -80,7 +80,7 @@ namespace App.Widgets { this.hide_back (); this.back (); }); - + this.searchEntry = new Gtk.SearchEntry (); this.searchEntry.placeholder_text = _("Filter sites…"); @@ -143,7 +143,7 @@ namespace App.Widgets { this.menu.show_all (); this.menuButton.popup = this.menu; - + // Handle events settings.changed.connect (() => { hideStartItem.active = settings.hide_on_start; diff --git a/src/widgets/IndicatorItem.vala b/src/widgets/IndicatorItem.vala index 64fa486..ff15d4c 100644 --- a/src/widgets/IndicatorItem.vala +++ b/src/widgets/IndicatorItem.vala @@ -39,7 +39,7 @@ namespace App.Widgets { public signal void changed (); public SiteModel Site { get { return _site; } } - + /** * Constructs a new {@code Toolbar} object. diff --git a/src/widgets/SiteItem.vala b/src/widgets/SiteItem.vala index 923baac..d8696fd 100644 --- a/src/widgets/SiteItem.vala +++ b/src/widgets/SiteItem.vala @@ -42,9 +42,9 @@ namespace App.Widgets { private Gtk.Image statusImage; private Gtk.Label titleLabel; private Gtk.Label urlLabel; - + public SiteModel Site { get { return _site; } } - + /** * Constructs a new {@code Toolbar} object. */ @@ -74,7 +74,7 @@ namespace App.Widgets { var textBox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); textBox.add (titleLabel); - textBox.add (urlLabel); + textBox.add (urlLabel); var statusGrid = new Gtk.Grid (); statusGrid.hexpand = true; From 4c680460ca7b511ad2e43ad138acc32e81ddb0f0 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:37:42 -0300 Subject: [PATCH 08/13] use the correct form of verbatim strings --- src/database/Database.vala | 12 ++++++------ src/models/SiteModel.vala | 8 ++++---- src/views/SiteView.vala | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/database/Database.vala b/src/database/Database.vala index d6aeed5..785eea7 100644 --- a/src/database/Database.vala +++ b/src/database/Database.vala @@ -73,7 +73,7 @@ namespace App.Database { // Initial migration if (1 > oldVersion) { - var settingsSQL = " + var settingsSQL = """ CREATE TABLE `settings` ( id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT NOT NULL, @@ -82,11 +82,11 @@ namespace App.Database { INSERT INTO `settings` (`key`, `value`) VALUES ('version', '1.0.0'); CREATE INDEX `key` ON `settings` (key); - "; + """; this.Execute (settingsSQL); - var sitesSQL = " + var sitesSQL = """ CREATE TABLE `sites` ( id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT NOT NULL, @@ -106,11 +106,11 @@ namespace App.Database { CREATE INDEX `title` ON `sites` (title); CREATE INDEX `updated_dt` ON `sites` (updated_dt); CREATE UNIQUE INDEX `url` ON `sites` (url); - "; + """; this.Execute (sitesSQL); - var siteResultSQL = " + var siteResultSQL = """ CREATE TABLE `results` ( id INTEGER PRIMARY KEY AUTOINCREMENT, site_id INTEGER NOT NULL, @@ -124,7 +124,7 @@ namespace App.Database { CREATE INDEX `site_id` ON `results` (site_id); CREATE INDEX `status` ON `results` (status); CREATE INDEX `created_dt` ON `results` (created_dt); - "; + """; this.Execute (siteResultSQL); } diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index c2ece29..d077df2 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -152,7 +152,7 @@ namespace App.Models { // Update SQL if (id > 0) { state = SiteEvent.UPDATED; - sql = " + sql = """ UPDATE `sites` SET `url` = $URL, `description` = $DESCRIPTION, @@ -167,15 +167,15 @@ namespace App.Models { `icon_updated_dt` = $ICON_UPDATED_DT WHERE `id` = $ID - "; + """; } // Insert SQL else { - sql = " + sql = """ INSERT INTO `sites` (`url`, `description`, `active`, `order`, `status`, `notify`) VALUES ($URL, $DESCRIPTION, $ACTIVE, $ORDER, $STATUS, $NOTIFY) - "; + """; } var statement = this.db.Prepare (sql); diff --git a/src/views/SiteView.vala b/src/views/SiteView.vala index 2608b52..9721188 100644 --- a/src/views/SiteView.vala +++ b/src/views/SiteView.vala @@ -173,7 +173,7 @@ namespace App.Views { var store = new Gtk.ListStore (4, typeof (string), typeof (string), typeof (string), typeof (string)); var db = App.Database.DB.GetInstance (); - var sql = " + var sql = """ SELECT created_dt, response, @@ -181,7 +181,7 @@ namespace App.Views { status FROM `results` WHERE site_id = $SITE_ID AND created_dt >= $CREATED_DT - ORDER BY created_dt DESC"; + ORDER BY created_dt DESC"""; var statement = db.Prepare (sql); db.bind_int (statement, "$SITE_ID", Site.id); From c5485d7fa78ba4326ec9424b546955d65210d0d2 Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:40:16 -0300 Subject: [PATCH 09/13] fix warning 'Gtk.Application.add_accelerator has been deprecated since 3.14' --- src/controllers/AppController.vala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controllers/AppController.vala b/src/controllers/AppController.vala index 47a4412..56f97f4 100644 --- a/src/controllers/AppController.vala +++ b/src/controllers/AppController.vala @@ -230,8 +230,11 @@ namespace App.Controllers { this.application.add_action (find_action); this.application.add_action (quit_action); - this.application.add_accelerator ("f", "app.find", null); - this.application.add_accelerator ("q", "app.quit", null); + string[] find = {"f", "0"}; + string[] quit = {"q", "0"}; + + this.application.set_accels_for_action ("app.find", find); + this.application.set_accels_for_action ("app.quit", quit); } } } From 01daab378a05c02d8212142048b31edcd87a30ce Mon Sep 17 00:00:00 2001 From: Cleiton Floss Date: Sun, 4 Nov 2018 23:54:28 -0300 Subject: [PATCH 10/13] fix warning: add try-catch to Regex --- src/models/SiteModel.vala | 113 +++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/src/models/SiteModel.vala b/src/models/SiteModel.vala index d077df2..87292c5 100644 --- a/src/models/SiteModel.vala +++ b/src/models/SiteModel.vala @@ -242,72 +242,75 @@ namespace App.Models { } this.running = true; + try { + var titleRegex = new Regex ("""\(.+)\<\/title\>""", RegexCompileFlags.CASELESS); + var message = new Soup.Message ("GET", this.url); + var timer = new Timer (); + session.queue_message (message, (ses, response) => { + timer.stop (); + + var currentTime = (new DateTime.now_utc ()).to_unix (); + var data = (string) response.response_body.data ?? ""; + var statusCode = response.status_code; + + // Timer is in seconds - multiple by 1000 to get MS, the cast to int to drop remainder + this.response = (int)(timer.elapsed () * 1000); + + // Update the status based on the status code value (200 is usually expected) + if (statusCode >= 200 && statusCode < 300 && this.response < 30000) { + if (this.status == "bad") { + this.changed (this, SiteEvent.ONLINE); + } - var titleRegex = new Regex ("""\(.+)\<\/title\>""", RegexCompileFlags.CASELESS); - var message = new Soup.Message ("GET", this.url); - var timer = new Timer (); - session.queue_message (message, (ses, response) => { - timer.stop (); - - var currentTime = (new DateTime.now_utc ()).to_unix (); - var data = (string) response.response_body.data ?? ""; - var statusCode = response.status_code; - - // Timer is in seconds - multiple by 1000 to get MS, the cast to int to drop remainder - this.response = (int)(timer.elapsed () * 1000); - - // Update the status based on the status code value (200 is usually expected) - if (statusCode >= 200 && statusCode < 300 && this.response < 30000) { - if (this.status == "bad") { - this.changed (this, SiteEvent.ONLINE); + this.status = "good"; + this.failures = 0; } - this.status = "good"; - this.failures = 0; - } - - // Permanent redirect - update our link to it - else if (statusCode == 308) { - var headers = response.response_headers; - this.url = headers.get_one ("Location"); - } + // Permanent redirect - update our link to it + else if (statusCode == 308) { + var headers = response.response_headers; + this.url = headers.get_one ("Location"); + } - else if (this.status == "bad") {} + else if (this.status == "bad") {} - // 30 second timeout should be considered an offline situation - else if (this.response >= 30000) { - this.failures = 3; - } + // 30 second timeout should be considered an offline situation + else if (this.response >= 30000) { + this.failures = 3; + } - // 300+ is redirect, 400+ are user/permission errors, 500+ are server errors - else { - this.status = "warning"; - this.failures++; - } + // 300+ is redirect, 400+ are user/permission errors, 500+ are server errors + else { + this.status = "warning"; + this.failures++; + } - // After 5 failed attempts, display a notification if enabled - if (this.failures >= 3 && this.status != "bad") { - this.status = "bad"; - this.changed (this, SiteEvent.OFFLINE); - } + // After 5 failed attempts, display a notification if enabled + if (this.failures >= 3 && this.status != "bad") { + this.status = "bad"; + this.changed (this, SiteEvent.OFFLINE); + } - // Attempt to parse out tag - MatchInfo match; - if (titleRegex.match (data, 0, out match)) { - this.title = App.Utils.StringUtil.html_entity_decode (match.fetch (1) ?? "").strip (); - } + // Attempt to parse out <title> tag + MatchInfo match; + if (titleRegex.match (data, 0, out match)) { + this.title = App.Utils.StringUtil.html_entity_decode (match.fetch (1) ?? "").strip (); + } - new ResultModel.with_details (this.id, this.response, (int)statusCode, this.status); + new ResultModel.with_details (this.id, this.response, (int)statusCode, this.status); - this.running = false; - this.save (); + this.running = false; + this.save (); - // If everything is good and the last time we updated the icon was more than 5 minutes ago, fetch a new icon - if (this.status == "good" && currentTime - this.icon_updated_dt > 300) { - this.fetching_icon = false; // if it's still running after 5 minutes just let it run again - this.fetch_icon (); - } - }); + // If everything is good and the last time we updated the icon was more than 5 minutes ago, fetch a new icon + if (this.status == "good" && currentTime - this.icon_updated_dt > 300) { + this.fetching_icon = false; // if it's still running after 5 minutes just let it run again + this.fetch_icon (); + } + }); + } catch (RegexError e) { + GLib.message ("Erro: %s", e.message); + } } public void fetch_icon () { From e948fbbda13d15bb4860070b3dc7f651481b742b Mon Sep 17 00:00:00 2001 From: Cleiton Floss <cleitonfloss@gmail.com> Date: Mon, 5 Nov 2018 00:07:42 -0300 Subject: [PATCH 11/13] update travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 13582f2..1d2755d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: - env: DIST=juno install: - - npm install @elementaryos/houston + - npm i -g @elementaryos/houston script: - houston ci From 49796db5d9689a0fe5298ab3577794d0e409a4fa Mon Sep 17 00:00:00 2001 From: Cleiton Floss <cleitonfloss@gmail.com> Date: Sat, 10 Nov 2018 05:34:51 -0300 Subject: [PATCH 12/13] update AppController --- src/controllers/AppController.vala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/controllers/AppController.vala b/src/controllers/AppController.vala index 56f97f4..7c60189 100644 --- a/src/controllers/AppController.vala +++ b/src/controllers/AppController.vala @@ -230,11 +230,8 @@ namespace App.Controllers { this.application.add_action (find_action); this.application.add_action (quit_action); - string[] find = {"<Control>f", "0"}; - string[] quit = {"<Control>q", "0"}; - - this.application.set_accels_for_action ("app.find", find); - this.application.set_accels_for_action ("app.quit", quit); + this.application.set_accels_for_action ("app.find", {"<Control>f"}); + this.application.set_accels_for_action ("app.quit", {"<Control>q"}); } } } From 5c7778dd58f0b05e28297e6a006cfd462720acb4 Mon Sep 17 00:00:00 2001 From: Cleiton Floss <cleitonfloss@gmail.com> Date: Sat, 10 Nov 2018 05:36:50 -0300 Subject: [PATCH 13/13] Only create tables & indices if they do not exist --- src/database/Database.vala | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/database/Database.vala b/src/database/Database.vala index 785eea7..9987746 100644 --- a/src/database/Database.vala +++ b/src/database/Database.vala @@ -74,20 +74,20 @@ namespace App.Database { // Initial migration if (1 > oldVersion) { var settingsSQL = """ - CREATE TABLE `settings` ( + CREATE TABLE IF NOT EXISTS `settings` ( id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT NOT NULL, value TEXT NOT NULL ); INSERT INTO `settings` (`key`, `value`) VALUES ('version', '1.0.0'); - CREATE INDEX `key` ON `settings` (key); + CREATE INDEX IF NOT EXISTS `key` ON `settings` (key); """; this.Execute (settingsSQL); var sitesSQL = """ - CREATE TABLE `sites` ( + CREATE TABLE IF NOT EXISTS `sites` ( id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT NOT NULL, description TEXT NULL, @@ -102,16 +102,16 @@ namespace App.Database { icon_updated_dt INTEGER NULL ); - CREATE INDEX `active` ON `sites` (active); - CREATE INDEX `title` ON `sites` (title); - CREATE INDEX `updated_dt` ON `sites` (updated_dt); - CREATE UNIQUE INDEX `url` ON `sites` (url); + CREATE INDEX IF NOT EXISTS `active` ON `sites` (active); + CREATE INDEX IF NOT EXISTS `title` ON `sites` (title); + CREATE INDEX IF NOT EXISTS `updated_dt` ON `sites` (updated_dt); + CREATE UNIQUE INDEX IF NOT EXISTS `url` ON `sites` (url); """; this.Execute (sitesSQL); var siteResultSQL = """ - CREATE TABLE `results` ( + CREATE TABLE IF NOT EXISTS `results` ( id INTEGER PRIMARY KEY AUTOINCREMENT, site_id INTEGER NOT NULL, response REAL NOT NULL, @@ -121,9 +121,9 @@ namespace App.Database { created_dt INTEGER NOT NULL ); - CREATE INDEX `site_id` ON `results` (site_id); - CREATE INDEX `status` ON `results` (status); - CREATE INDEX `created_dt` ON `results` (created_dt); + CREATE INDEX IF NOT EXISTS `site_id` ON `results` (site_id); + CREATE INDEX IF NOT EXISTS `status` ON `results` (status); + CREATE INDEX IF NOT EXISTS `created_dt` ON `results` (created_dt); """; this.Execute (siteResultSQL);