Skip to content

Commit

Permalink
Some codestyle changes / fix for pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Gijs Goudzwaard committed Aug 21, 2024
1 parent f546704 commit 25c7fdc
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,4 +50,4 @@ jobs:
uses: actions/checkout@v4

- name: Lint
run: io.elementary.vala-lint -d .
run: io.elementary.vala-lint -d .
12 changes: 6 additions & 6 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -28,15 +28,15 @@ 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://", "");

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
Expand All @@ -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);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};

/**
Expand All @@ -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
);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -243,7 +243,7 @@ public class MainWindow : Gtk.Window {
}

if (this.images.length > 0) {
this.set_list_window();
this.set_list_window ();
}

this.images = {};
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/Image.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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];
}
Expand Down Expand Up @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/Utils/JpegOptim.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*> run = () => {
foreach (var image in this.images) {
Expand All @@ -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);
Expand All @@ -72,7 +72,7 @@ public class JpegOptim {
return null;
};

new Thread<void*>.try("thread", (owned) run);
new Thread<void*>.try ("thread", (owned) run);
}

/**
Expand All @@ -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]);
}
}
14 changes: 7 additions & 7 deletions src/Utils/OptiPng.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*> run = () => {
foreach (var image in this.images) {
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -76,7 +76,7 @@ public class OptiPng {
return null;
};

new Thread<void*>.try("thread", (owned) run);
new Thread<void*>.try ("thread", (owned) run);
}

/**
Expand All @@ -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]);
}
}
20 changes: 10 additions & 10 deletions src/Widgets/List.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, "");
}
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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, "");
}
Expand Down
44 changes: 22 additions & 22 deletions src/Widgets/UploadScreen.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 25c7fdc

Please sign in to comment.