Skip to content

Commit

Permalink
Change naming conventions of methods to comply with vala naming conve…
Browse files Browse the repository at this point in the history
…ntions
  • Loading branch information
Gijs Goudzwaard committed Aug 21, 2024
1 parent 25c7fdc commit 0bb6fc2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 50 deletions.
10 changes: 5 additions & 5 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Application : Granite.Application {
protected override void activate () {
if (this.app_window == null) {
this.app_window = new MainWindow (this);
this.app_window.show_all();
this.app_window.show_all ();
}

var quit_action = new SimpleAction ("quit", null);
Expand All @@ -31,13 +31,13 @@ class Application : Granite.Application {
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 uri = file.get_path ().replace ("%20", " ").replace ("file://", "");

var name = Image.getFileName (uri);
var type = Image.getFileType (file.get_basename());
var type = Image.getFileType (file.get_basename ());

if (Image.isValid (type.down ())) {
this.images += new Image (uri, name, type.down());
if (Image.is_valid (type.down ())) {
this.images += new Image (uri, name, type.down ());
} else {
// TODO: add an error message here
}
Expand Down
15 changes: 7 additions & 8 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class MainWindow : Gtk.Window {
* @param Image images
* @return void
*/
public void set_images(Image[] images) {
public void set_images (Image[] images) {
this.images = images;

if (images.length == 0) {
Expand Down Expand Up @@ -187,15 +187,14 @@ public class MainWindow : Gtk.Window {
* @param uint time
* @return void
*/
private void on_drag_data_received (Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time)
{
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 ())) {
if (Image.is_valid (type.down ())) {
this.images += new Image (uri, name, type.down ());
} else {
// TODO: add an error message here
Expand All @@ -205,7 +204,7 @@ public class MainWindow : Gtk.Window {
if (images.length > 0 && this.images_list == null) {
this.set_list_window ();
} else if (this.images_list != null) {
this.images_list.updateTreeView (this.images);
this.images_list.update_tree_view (this.images);
}

this.images = {};
Expand All @@ -231,15 +230,15 @@ public class MainWindow : Gtk.Window {
var name = Image.getFileName (uri);
var type = Image.getFileType (name);

if (Image.isValid (type.down ())) {
if (Image.is_valid (type.down ())) {
this.images += new Image (uri, name, type.down ());
} else {
// TODO: add an error message here
}
}

if (this.images_list != null) {
this.images_list.updateTreeView (this.images);
this.images_list.update_tree_view (this.images);
}

if (this.images.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/Utils/Image.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public class Image {
* @param string type
* @return bool
*/
public static bool isValid (string type) {
public static bool is_valid (string type) {
string[] supported_types = {
"png",
"jpg",
"jpeg",
"bmp"
};

return Utils.inArray (supported_types, type);
return Utils.in_array (supported_types, type);
}

/**
Expand All @@ -109,7 +109,7 @@ public class Image {
* @param int64 bytes
* @return string
*/
public static string getUnit (int64 bytes) {
public static string get_unit (int64 bytes) {
var unit = "";

if (bytes > 1000 && bytes < 1000000) {
Expand All @@ -133,7 +133,7 @@ public class Image {
* @param float new_size
* @return string
*/
public static string calcSavings (float size, float new_size) {
public static string calc_savings (float size, float new_size) {
float savings = 100.00f - (new_size / size * 100.00f);

return "%.2f%%".printf (savings);
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/JpegOptim.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class JpegOptim {
out status
);

var new_size = this.getNewSize (stdout);
this.list.updateSize (image, new_size);
var new_size = this.get_new_size (stdout);
this.list.update_size (image, new_size);

} catch (SpawnError e) {
warning ("Failed to spawn jpegoptim: %s", e.message);
Expand All @@ -81,7 +81,7 @@ public class JpegOptim {
* @param string stdout
* @return int
*/
public int getNewSize (string stdout) {
public int get_new_size (string stdout) {
// After the arrow and a space there should be the new size in bytes.
var text = stdout.split (" --> ")[1];

Expand Down
6 changes: 3 additions & 3 deletions src/Utils/OptiPng.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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.get_new_size (stdout);
}

this.list.updateSize (image, new_size);
this.list.update_size (image, new_size);
} catch (SpawnError e) {
warning ("Failed to spawn optipng: %s", e.message);
}
Expand All @@ -85,7 +85,7 @@ public class OptiPng {
* @param string stdout
* @return int
*/
public int getNewSize (string stdout) {
public int get_new_size (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];

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Optimizer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class Optimizer {
var optipng = new OptiPng (list);

foreach (var image in this.images) {
if (Utils.inArray ({"jpg", "jpeg"}, image.type)) {
if (Utils.in_array ({"jpg", "jpeg"}, image.type)) {
jpegoptim.addImage (image.path);
} else if (Utils.inArray ({"png", "bmp"}, image.type)) {
} else if (Utils.in_array ({"png", "bmp"}, image.type)) {
optipng.addImage (image.path);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class Utils {
*
* @return bool
*/
public static bool inArray (string[] haystack, string needle) {
public static bool in_array (string[] haystack, string needle) {
foreach (var item in haystack) {
if (item == needle) {
return true;
Expand Down
44 changes: 22 additions & 22 deletions src/Widgets/List.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class List {
0, true,
1, 1,
2, image.name,
3, Image.getUnit (image.size),
3, Image.get_unit (image.size),
4, "",
5, "");
}
Expand All @@ -48,29 +48,29 @@ public class List {
var spinner = new Gtk.CellRendererSpinner ();

Gtk.TreeViewColumn column = new Gtk.TreeViewColumn ();
column.set_title ("");
column.pack_start (spinner, false);
column.add_attribute (spinner, "active", 0);
column.add_attribute (spinner, "pulse", 1);
view.append_column (column);
column.set_title ("");
column.pack_start (spinner, false);
column.add_attribute (spinner, "active", 0);
column.add_attribute (spinner, "pulse", 1);
view.append_column (column);

view.insert_column_with_attributes (2, _("File"), cell, "text", 2);
view.insert_column_with_attributes (3, _("Size"), cell, "text", 3);
view.insert_column_with_attributes (4, _("New size"), cell, "text", 4);
view.insert_column_with_attributes (3, _("Size"), cell, "text", 3);
view.insert_column_with_attributes (4, _("New size"), cell, "text", 4);
view.insert_column_with_attributes (5, _("Savings"), cell, "text", 5);

// Rotate the spinner:
Timeout.add (50, () => {
listmodel.foreach ((model, path, iter) => {
Value val;
listmodel.get_value (iter, 1, out val);
val.set_int (val.get_int () + 1);
Timeout.add (50, () => {
listmodel.foreach ((model, path, iter) => {
Value val;
listmodel.get_value (iter, 1, out val);
val.set_int (val.get_int () + 1);
listmodel.set_value (iter, 1, val);

return false;
return false;
});

return true;
return true;
});

var optimizer = new Optimizer (this.images);
Expand All @@ -79,7 +79,7 @@ public class List {
return main;
}

public void updateSize (string path, int size) {
public void update_size (string path, int size) {
// Update image with new attributes
for (var i = 0; i < this.images.length; i++) {
if (this.images[i].path == path) {
Expand All @@ -88,7 +88,7 @@ public class List {
}

Gtk.TreeIter iter;
Image image = new Image("", "", "");
Image image = new Image ("", "", "");
var key = 0;
for (var i = 0; i < this.images.length; i++) {
if (this.images[i].path == path) {
Expand All @@ -106,12 +106,12 @@ public class List {
0, false,
1, 1,
2, image.name,
3, Image.getUnit (image.size),
4, Image.getUnit (image.new_size),
5, Image.calcSavings ((float) image.size, (float) image.new_size));
3, Image.get_unit (image.size),
4, Image.get_unit (image.new_size),
5, Image.calc_savings ((float) image.size, (float) image.new_size));
}

public void updateTreeView (Image[] images) {
public void update_tree_view (Image[] images) {
Gtk.TreeIter iter;

foreach (var image in images) {
Expand All @@ -128,7 +128,7 @@ public class List {
0, true,
1, 1,
2, image.name,
3, Image.getUnit (image.size),
3, Image.get_unit (image.size),
4, "",
5, "");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/UploadScreen.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class UploadScreen : Gtk.Box {

public Gtk.Button upload_button;

public Gtk.Box window() {
public Gtk.Box window () {
this.border_width = 10;
this.get_style_context ().add_class ("main");

Expand All @@ -13,7 +13,7 @@ public class UploadScreen : Gtk.Box {
upload_area.set_valign (Gtk.Align.CENTER);
upload_area.set_halign (Gtk.Align.CENTER);

Gtk.Image icon = new Gtk.Image();
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);
Expand Down

0 comments on commit 0bb6fc2

Please sign in to comment.