Skip to content

Commit eecf06c

Browse files
committed
Updates Settings dialog
1 parent cf6ba7f commit eecf06c

File tree

4 files changed

+116
-17
lines changed

4 files changed

+116
-17
lines changed

data/Application.css

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.settings-button,
32
.resize-button {
43
background-color: transparent;
@@ -7,11 +6,11 @@
76
box-shadow: none;
87
}
98

10-
.settings-button:focus-visible,
11-
.resize-button:focus-visible {
12-
outline: none;
13-
box-shadow: none;
14-
}
9+
.settings-button:focus-visible,
10+
.resize-button:focus-visible {
11+
outline: none;
12+
box-shadow: none;
13+
}
1514

1615
.settings-dialog {
1716
padding-right: 16px;
@@ -26,7 +25,7 @@
2625
border-right: none;
2726
border-top-right-radius: 0;
2827
border-bottom-right-radius: 0;
29-
outline: none;
28+
outline: none;
3029
box-shadow: none;
3130
}
3231

@@ -36,6 +35,20 @@
3635
box-shadow: none;
3736
}
3837

38+
.album-picker-text {
39+
border-right: none;
40+
border-top-right-radius: 0;
41+
border-bottom-right-radius: 0;
42+
outline: none;
43+
box-shadow: none;
44+
}
45+
46+
.album-picker-btn {
47+
border-top-left-radius: 0;
48+
border-bottom-left-radius: 0;
49+
box-shadow: none;
50+
}
51+
3952
.window-legend-label {
4053
padding-top: 30px;
4154
}

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ executable(
3131
'src' / 'Application.vala',
3232
'src' / 'Constants.vala',
3333
'src' / 'widgets' / 'EntryButton.vala',
34+
'src' / 'widgets' / 'AlbumPicker.vala',
3435
'src' / 'views' / 'MainWindow.vala',
3536
'src' / 'views' / 'SettingsDialog.vala',
3637
'src' / 'models' / 'SlideshowImage.vala',

src/views/SettingsDialog.vala

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ using Larawan.Widgets;
99

1010
public class Larawan.Views.SettingsDialog : Granite.Dialog {
1111

12-
EntryButton album_folder = null;
12+
const double MAX_WINDOW_HEIGHT = 650;
13+
const double MAX_WINDOW_WIDTH = 650;
14+
const double MIN_WINDOW_HEIGHT = 300;
15+
const double MIN_WINDOW_WIDTH = 300;
16+
17+
AlbumPicker album_picker = null;
1318
Switch shuffle_switch = null;
1419
GLib.Settings settings;
1520
FileDialog file_dialog;
@@ -61,11 +66,11 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
6166
}
6267

6368
private void bind_events () {
64-
album_folder.clicked.connect (() => {
69+
album_picker.clicked.connect (() => {
6570
file_dialog.select_folder.begin (window, null, (obj, result) => {
6671
try {
6772
File file = file_dialog.select_folder.end (result);
68-
album_folder.text = file.get_path ();
73+
album_picker.value = file.get_path ();
6974
} catch (Error e) {
7075
info (e.message);
7176
}
@@ -81,7 +86,7 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
8186

8287
private void bind_settings () {
8388
settings = new GLib.Settings (APP_ID);
84-
settings.bind ("album-folder", album_folder, "text", SettingsBindFlags.DEFAULT);
89+
settings.bind ("album-folder", album_picker, "value", SettingsBindFlags.DEFAULT);
8590
settings.bind ("shuffle", shuffle_switch, "active", SettingsBindFlags.DEFAULT);
8691
settings.bind ("recursive", recursive_switch, "active", SettingsBindFlags.DEFAULT);
8792
settings.bind ("duration", duration_scale.adjustment, "value", SettingsBindFlags.DEFAULT);
@@ -95,9 +100,8 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
95100
width_request = 150,
96101
hexpand = false
97102
};
98-
album_folder = new EntryButton.from_icon_name ("folder-open");
99-
album_folder.readonly = true;
100-
album_folder.hexpand = true;
103+
album_picker = new AlbumPicker.from_icon_name ("folder-open");
104+
album_picker.hexpand = true;
101105
string pictures_dir = Path.build_filename (Environment.get_home_dir (), "Pictures");
102106

103107
file_dialog = new FileDialog () {
@@ -106,7 +110,7 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
106110

107111
var album_folder_box = new Box (Orientation.HORIZONTAL, 10);
108112
album_folder_box.append (folder_label);
109-
album_folder_box.append (album_folder);
113+
album_folder_box.append (album_picker);
110114
root_box.append (album_folder_box);
111115
}
112116

@@ -192,7 +196,12 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
192196
width_request = 150
193197
};
194198

195-
window_width_scale = new Scale.with_range (Orientation.HORIZONTAL, 300, 800, 1) {
199+
window_width_scale = new Scale.with_range (
200+
Orientation.HORIZONTAL,
201+
MIN_WINDOW_WIDTH,
202+
MAX_WINDOW_WIDTH,
203+
1
204+
) {
196205
digits = 0,
197206
draw_value = true,
198207
hexpand = true,
@@ -212,7 +221,12 @@ public class Larawan.Views.SettingsDialog : Granite.Dialog {
212221
width_request = 150
213222
};
214223

215-
window_height_scale = new Scale.with_range (Orientation.HORIZONTAL, 300, 800, 1) {
224+
window_height_scale = new Scale.with_range (
225+
Orientation.HORIZONTAL,
226+
MIN_WINDOW_HEIGHT,
227+
MAX_WINDOW_HEIGHT,
228+
1
229+
) {
216230
digits = 0,
217231
draw_value = true,
218232
hexpand = true,

src/widgets/AlbumPicker.vala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2024 Christian Camilon <[email protected]>
4+
*/
5+
using Gtk;
6+
7+
namespace Larawan.Widgets {
8+
9+
public class AlbumPicker : Gtk.Box {
10+
Button value_text;
11+
Button button;
12+
string _value;
13+
14+
public signal void clicked ();
15+
16+
public string text {
17+
get {
18+
return this.value_text.label;
19+
}
20+
protected set {
21+
this.value_text.label = value;
22+
}
23+
}
24+
25+
public string value {
26+
get {
27+
return this._value;
28+
}
29+
set {
30+
this._value = value;
31+
}
32+
}
33+
34+
public string icon_name { get; construct set; }
35+
36+
public AlbumPicker.from_icon_name (string icon_name) {
37+
Object (icon_name: icon_name);
38+
}
39+
40+
construct {
41+
orientation = Orientation.HORIZONTAL;
42+
43+
value_text = new Button () {
44+
hexpand = true
45+
};
46+
value_text.add_css_class ("album-picker-text");
47+
48+
button = new Button.from_icon_name (icon_name);
49+
if (button.get_icon_name () != null) {
50+
button.remove_css_class ("image-button");
51+
}
52+
button.add_css_class ("album-picker-btn");
53+
54+
append (value_text);
55+
append (button);
56+
57+
value_text.clicked.connect(() => clicked());
58+
button.clicked.connect (() => clicked ());
59+
60+
notify["value"].connect(on_value_changed);
61+
}
62+
63+
private void on_value_changed() {
64+
update_text();
65+
}
66+
67+
private void update_text() {
68+
this.text = Path.get_basename(value);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)