Skip to content

Commit f83a8b7

Browse files
committed
Validate sizes
1 parent dbb85ce commit f83a8b7

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/Window.vala

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
4141
public Gtk.Entry width;
4242
public Gtk.Entry height;
4343

44-
private File _file;
45-
public File file {
44+
private File? _file;
45+
public File? file {
4646
get {
4747
return _file;
4848
}
@@ -56,12 +56,15 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
5656
pixbuf = pixbuf.scale_simple (image.get_allocated_width (), image.get_allocated_height (), Gdk.InterpType.BILINEAR);
5757

5858
image.set_from_pixbuf (pixbuf);
59-
run_button.sensitive = true;
6059
run_button.label = "Wallpaperize!";
6160
drag_label.visible = false;
6261
drag_label.no_show_all = true;
62+
63+
validate ();
6364
}
6465
}
66+
67+
default = null;
6568
}
6669

6770
public Window (Gtk.Application app) {
@@ -85,14 +88,14 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
8588
grid.expand = true;
8689
grid.row_spacing = 12;
8790

88-
var image_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
91+
var image_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
8992
image_box.get_style_context ().add_class ("frame");
90-
93+
9194
image = new Gtk.Image ();
9295
image.get_style_context ().add_class ("card");
9396
image.hexpand = true;
9497
image.height_request = 200;
95-
98+
9699
image_box.add (image);
97100

98101
drag_label = new Gtk.Label (_("Drop Image Here"));
@@ -106,18 +109,23 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
106109

107110
width = new Gtk.Entry ();
108111
height = new Gtk.Entry ();
109-
112+
113+
width.input_purpose = Gtk.InputPurpose.DIGITS;
114+
height.input_purpose = Gtk.InputPurpose.DIGITS;
115+
110116
width.set_tooltip_text ("Width");
111117
height.set_tooltip_text ("Height");
112118

113119
width.changed.connect (() => {
114120
Wallpaperize.Wallpaperiser.W = int.parse (width.text);
121+
validate ();
115122
});
116123

117124
height.changed.connect (() => {
118125
Wallpaperize.Wallpaperiser.H = int.parse (height.text);
126+
validate ();
119127
});
120-
128+
121129
var reset_button = new Gtk.Button.from_icon_name ("video-display-symbolic");
122130
reset_button.clicked.connect (get_screen_size);
123131
reset_button.set_tooltip_text ("Get resolution");
@@ -152,6 +160,12 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
152160
get_screen_size ();
153161
}
154162

163+
private void validate () {
164+
int w = Wallpaperiser.W;
165+
int h = Wallpaperiser.H;
166+
run_button.sensitive = w > 0 && git@github.com:a-rmz/intro-bots.gith > 0 && w < 15000 && h < 15000 && file != null;
167+
}
168+
155169
private void get_screen_size () {
156170
Wallpaperize.Wallpaperiser.H = Gdk.Screen.height ();
157171
Wallpaperize.Wallpaperiser.W = Gdk.Screen.width ();

0 commit comments

Comments
 (0)