diff --git a/.github/workflows/pipelines.yml b/.github/workflows/pipelines.yml index f529343..563b391 100644 --- a/.github/workflows/pipelines.yml +++ b/.github/workflows/pipelines.yml @@ -31,7 +31,7 @@ jobs: uses: flatpak/flatpak-github-actions/flatpak-builder@v6 with: bundle: reco.flatpak - manifest-path: build-aux/appcenter/com.github.gijsgoudzwaard.image-optimizer.yml + manifest-path: com.github.gijsgoudzwaard.image-optimizer.yml run-tests: true repository-name: appcenter repository-url: https://flatpak.elementary.io/repo.flatpakrepo @@ -50,4 +50,4 @@ jobs: uses: actions/checkout@v4 - name: Lint - run: io.elementary.vala-lint -d . \ No newline at end of file + run: io.elementary.vala-lint -d . diff --git a/src/Application.vala b/src/Application.vala index f4565ff..71d7ab0 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -5,12 +5,12 @@ class Application : Granite.Application { private Image[] images = {}; private MainWindow app_window; - public Application() { + public Application () { Object (application_id: "com.github.gijsgoudzwaard.image-optimizer", flags: GLib.ApplicationFlags.HANDLES_OPEN); } - protected override void activate() { + protected override void activate () { if (this.app_window == null) { this.app_window = new MainWindow (this); this.app_window.show_all(); @@ -28,7 +28,7 @@ class Application : Granite.Application { }); } - public override void open(File[] files, string hint) { + public override void open (File[] files, string hint) { if (files [0].query_exists ()) { foreach (File file in files) { var uri = file.get_path().replace("%20", " ").replace("file://", ""); @@ -36,7 +36,7 @@ class Application : Granite.Application { var name = Image.getFileName (uri); var type = Image.getFileType (file.get_basename()); - if (Image.isValid (type.down())) { + if (Image.isValid (type.down ())) { this.images += new Image (uri, name, type.down()); } else { // TODO: add an error message here @@ -45,10 +45,10 @@ class Application : Granite.Application { if (this.app_window == null) { this.app_window = new MainWindow (this); - this.app_window.show_all(); + this.app_window.show_all (); } - this.app_window.set_images(this.images); + this.app_window.set_images (this.images); } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 971af80..e2bad95 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -36,8 +36,8 @@ public class MainWindow : Gtk.Window { * * @var Gtk.TargetEntry[] */ - private const Gtk.TargetEntry[] targets = { - {"text/uri-list",0,0} + private const Gtk.TargetEntry[] TARGETS = { + {"text/uri-list", 0, 0} }; /** @@ -60,7 +60,7 @@ public class MainWindow : Gtk.Window { css_provider.load_from_data (Stylesheet.STYLES); Gtk.StyleContext.add_provider_for_screen ( - this.get_screen(), + this.get_screen (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION ); @@ -79,7 +79,7 @@ public class MainWindow : Gtk.Window { // this.images += new Image ("", "", ""); // } - Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY); + Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, TARGETS, Gdk.DragAction.COPY); this.drag_leave.connect (this.on_drag_leave); this.drag_motion.connect (this.on_drag_motion); this.drag_data_received.connect (this.on_drag_data_received); @@ -131,7 +131,7 @@ public class MainWindow : Gtk.Window { add (images_list.window ()); var add_image = new Gtk.Button.from_icon_name ("list-add-symbolic", Gtk.IconSize.SMALL_TOOLBAR); - add_image.set_tooltip_markup(_("Add Image")); + add_image.set_tooltip_markup (_("Add Image")); this.toolbar.remove (add_image); add_image.get_style_context ().add_class ("titlebutton"); @@ -190,13 +190,13 @@ public class MainWindow : Gtk.Window { private void on_drag_data_received (Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time) { foreach (string uri in data.get_uris ()) { - uri = uri.replace("%20", " ").replace("file://", ""); + uri = uri.replace ("%20", " "). replace("file://", ""); var name = Image.getFileName (uri); var type = Image.getFileType (name); - if (Image.isValid (type.down())) { - this.images += new Image (uri, name, type.down()); + if (Image.isValid (type.down ())) { + this.images += new Image (uri, name, type.down ()); } else { // TODO: add an error message here } @@ -231,8 +231,8 @@ public class MainWindow : Gtk.Window { var name = Image.getFileName (uri); var type = Image.getFileType (name); - if (Image.isValid (type.down())) { - this.images += new Image (uri, name, type.down()); + if (Image.isValid (type.down ())) { + this.images += new Image (uri, name, type.down ()); } else { // TODO: add an error message here } @@ -243,7 +243,7 @@ public class MainWindow : Gtk.Window { } if (this.images.length > 0) { - this.set_list_window(); + this.set_list_window (); } this.images = {}; diff --git a/src/Utils/Image.vala b/src/Utils/Image.vala index 4bf3014..fb0a1a9 100644 --- a/src/Utils/Image.vala +++ b/src/Utils/Image.vala @@ -69,7 +69,7 @@ public class Image { * @return string */ public static string getFileName (string path) { - var array = path.split("/"); + var array = path.split ("/"); return array[array.length - 1]; } @@ -81,7 +81,7 @@ public class Image { * @return string */ public static string getFileType (string name) { - var array = name.split("."); + var array = name.split ("."); return array[array.length - 1]; } @@ -136,6 +136,6 @@ public class Image { public static string calcSavings (float size, float new_size) { float savings = 100.00f - (new_size / size * 100.00f); - return "%.2f%%".printf(savings); + return "%.2f%%".printf (savings); } } diff --git a/src/Utils/JpegOptim.vala b/src/Utils/JpegOptim.vala index b0c80c0..40865d1 100644 --- a/src/Utils/JpegOptim.vala +++ b/src/Utils/JpegOptim.vala @@ -45,7 +45,7 @@ public class JpegOptim { * @return void */ public void compress () throws Error { - var command = "jpegoptim " + Utils.join(" ", this.args); + var command = "jpegoptim " + Utils.join (" ", this.args); ThreadFunc run = () => { foreach (var image in this.images) { @@ -55,14 +55,14 @@ public class JpegOptim { try { Process.spawn_command_line_sync ( - command + " " + image.replace(" ", "\\ "), + command + " " + image.replace (" ", "\\ "), out stdout, out stderr, out status ); - var new_size = this.getNewSize(stdout); - this.list.updateSize(image, new_size); + var new_size = this.getNewSize (stdout); + this.list.updateSize (image, new_size); } catch (SpawnError e) { warning ("Failed to spawn jpegoptim: %s", e.message); @@ -72,7 +72,7 @@ public class JpegOptim { return null; }; - new Thread.try("thread", (owned) run); + new Thread.try ("thread", (owned) run); } /** @@ -83,9 +83,9 @@ public class JpegOptim { */ public int getNewSize (string stdout) { // After the arrow and a space there should be the new size in bytes. - var text = stdout.split(" --> ")[1]; + var text = stdout.split (" --> ")[1]; // The first integer until a space should be the new size in bytes. - return int.parse(text.split(" ")[0]); + return int.parse (text.split (" ")[0]); } } diff --git a/src/Utils/OptiPng.vala b/src/Utils/OptiPng.vala index c0c7f60..0d17965 100644 --- a/src/Utils/OptiPng.vala +++ b/src/Utils/OptiPng.vala @@ -45,7 +45,7 @@ public class OptiPng { * @return void */ public void compress () throws Error { - var command = "optipng " + Utils.join(" ", this.args); + var command = "optipng " + Utils.join (" ", this.args); ThreadFunc run = () => { foreach (var image in this.images) { @@ -55,7 +55,7 @@ public class OptiPng { try { Process.spawn_command_line_sync ( - command + " " + image.replace(" ", "\\ "), + command + " " + image.replace (" ", "\\ "), out stderr, out stdout, out status @@ -64,10 +64,10 @@ public class OptiPng { var new_size = 0; if (! stdout.contains ("is already optimized")) { - new_size = this.getNewSize(stdout); + new_size = this.getNewSize (stdout); } - this.list.updateSize(image, new_size); + this.list.updateSize (image, new_size); } catch (SpawnError e) { warning ("Failed to spawn optipng: %s", e.message); } @@ -76,7 +76,7 @@ public class OptiPng { return null; }; - new Thread.try("thread", (owned) run); + new Thread.try ("thread", (owned) run); } /** @@ -87,9 +87,9 @@ public class OptiPng { */ public int getNewSize (string stdout) { // After the piece of text and a space there should be the new size in bytes. - var text = stdout.split("Output file size = ")[1]; + var text = stdout.split ("Output file size = ")[1]; // The first integer until a space should be the new size in bytes. - return int.parse(text.split(" ")[0]); + return int.parse (text.split (" ")[0]); } } diff --git a/src/Widgets/List.vala b/src/Widgets/List.vala index 685b643..6bc8d87 100644 --- a/src/Widgets/List.vala +++ b/src/Widgets/List.vala @@ -18,12 +18,12 @@ public class List { listmodel = new Gtk.ListStore (6, typeof (bool), typeof (int), typeof (string), typeof (string), typeof (string), typeof (string)); - this.upload_button = new Gtk.Button.with_label("+"); - this.upload_button.get_style_context().add_class("upload_button"); - this.upload_button.get_style_context().add_class("add"); - this.upload_button.set_valign(Gtk.Align.START); - this.upload_button.set_halign(Gtk.Align.END); - ((Gtk.Widget) this.upload_button).set_focus_on_click(false); + this.upload_button = new Gtk.Button.with_label ("+"); + this.upload_button.get_style_context ().add_class ("upload_button"); + this.upload_button.get_style_context ().add_class ("add"); + this.upload_button.set_valign (Gtk.Align.START); + this.upload_button.set_halign (Gtk.Align.END); + ((Gtk.Widget) this.upload_button).set_focus_on_click (false); Gtk.TreeIter iter; foreach (var image in this.images) { @@ -32,7 +32,7 @@ public class List { 0, true, 1, 1, 2, image.name, - 3, Image.getUnit(image.size), + 3, Image.getUnit (image.size), 4, "", 5, ""); } @@ -98,7 +98,7 @@ public class List { } } - Gtk.TreePath tree_path = new Gtk.TreePath.from_string (key.to_string()); + Gtk.TreePath tree_path = new Gtk.TreePath.from_string (key.to_string ()); bool tmp = this.listmodel.get_iter (out iter, tree_path); assert (tmp == true); @@ -108,7 +108,7 @@ public class List { 2, image.name, 3, Image.getUnit (image.size), 4, Image.getUnit (image.new_size), - 5, Image.calcSavings((float) image.size, (float) image.new_size)); + 5, Image.calcSavings ((float) image.size, (float) image.new_size)); } public void updateTreeView (Image[] images) { @@ -128,7 +128,7 @@ public class List { 0, true, 1, 1, 2, image.name, - 3, Image.getUnit(image.size), + 3, Image.getUnit (image.size), 4, "", 5, ""); } diff --git a/src/Widgets/UploadScreen.vala b/src/Widgets/UploadScreen.vala index c1d26cb..11f84d4 100644 --- a/src/Widgets/UploadScreen.vala +++ b/src/Widgets/UploadScreen.vala @@ -6,42 +6,42 @@ public class UploadScreen : Gtk.Box { public Gtk.Box window() { this.border_width = 10; - this.get_style_context().add_class("main"); + this.get_style_context ().add_class ("main"); - var upload_area = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); - upload_area.set_spacing(15); - upload_area.set_valign(Gtk.Align.CENTER); - upload_area.set_halign(Gtk.Align.CENTER); + var upload_area = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + upload_area.set_spacing (15); + upload_area.set_valign (Gtk.Align.CENTER); + upload_area.set_halign (Gtk.Align.CENTER); Gtk.Image icon = new Gtk.Image(); try { - var icon_pixbuf = new Gdk.Pixbuf.from_file_at_scale("/usr/share/icons/hicolor/scalable/apps/upload_icon.svg", 64, 64, true); - icon = new Gtk.Image.from_pixbuf(icon_pixbuf); + var icon_pixbuf = new Gdk.Pixbuf.from_file_at_scale ("/usr/share/icons/hicolor/scalable/apps/upload_icon.svg", 64, 64, true); + icon = new Gtk.Image.from_pixbuf (icon_pixbuf); } catch (Error e) {} - var title = new Gtk.Label(_("Drag and drop images here")); - title.get_style_context().add_class("h1"); + var title = new Gtk.Label (_("Drag and drop images here")); + title.get_style_context ().add_class ("h1"); - var otherwise = new Gtk.Label(_("or")); - otherwise.get_style_context().add_class("h4"); + var otherwise = new Gtk.Label (_("or")); + otherwise.get_style_context ().add_class ("h4"); - this.upload_button = new Gtk.Button.with_label(_("Browse files")); - this.upload_button.get_style_context().add_class ("suggested-action"); - this.upload_button.get_style_context().add_class("upload_button"); - this.upload_button.set_valign(Gtk.Align.CENTER); - this.upload_button.set_halign(Gtk.Align.CENTER); - ((Gtk.Widget) this.upload_button).set_focus_on_click(false); + this.upload_button = new Gtk.Button.with_label (_("Browse files")); + this.upload_button.get_style_context ().add_class ("suggested-action"); + this.upload_button.get_style_context ().add_class ("upload_button"); + this.upload_button.set_valign (Gtk.Align.CENTER); + this.upload_button.set_halign (Gtk.Align.CENTER); + ((Gtk.Widget) this.upload_button).set_focus_on_click (false); if (icon != null) { - upload_area.pack_start(icon, false, false, 0); + upload_area.pack_start (icon, false, false, 0); } - upload_area.pack_start(title, false, false, 0); - upload_area.pack_start(otherwise, false, false, 0); - upload_area.pack_start(this.upload_button, false, false, 0); + upload_area.pack_start (title, false, false, 0); + upload_area.pack_start (otherwise, false, false, 0); + upload_area.pack_start (this.upload_button, false, false, 0); - pack_start(upload_area); + pack_start (upload_area); return this; }