Skip to content

Commit 845d0ec

Browse files
committed
Fix the merge
1 parent 9e9f7f6 commit 845d0ec

File tree

4 files changed

+164
-191
lines changed

4 files changed

+164
-191
lines changed

src/Application.vala

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Music.Application : Gtk.Application {
1010
public const string ACTION_PREVIOUS = "action-previous";
1111
public const string ACTION_SHUFFLE = "action-shuffle";
1212
public const string ACTION_FIND = "action-find";
13+
public const string ACTION_OPEN = "action-open";
1314
public const string ACTION_QUIT = "action-quit";
1415

1516
private const ActionEntry[] ACTION_ENTRIES = {
@@ -18,6 +19,7 @@ public class Music.Application : Gtk.Application {
1819
{ ACTION_PREVIOUS, action_previous },
1920
{ ACTION_SHUFFLE, action_shuffle },
2021
{ ACTION_FIND, action_find },
22+
{ ACTION_OPEN, action_open },
2123
{ ACTION_QUIT, quit }
2224
};
2325

@@ -187,7 +189,61 @@ public class Music.Application : Gtk.Application {
187189
}
188190

189191
private void action_find () {
190-
((MainWindow)active_window).start_search ();
192+
// ((MainWindow)active_window).start_search ();
193+
}
194+
195+
private void action_open () {
196+
var all_files_filter = new Gtk.FileFilter () {
197+
name = _("All files"),
198+
};
199+
all_files_filter.add_pattern ("*");
200+
201+
var music_files_filter = new Gtk.FileFilter () {
202+
name = _("Music files"),
203+
};
204+
music_files_filter.add_mime_type ("audio/*");
205+
206+
var filter_model = new ListStore (typeof (Gtk.FileFilter));
207+
filter_model.append (all_files_filter);
208+
filter_model.append (music_files_filter);
209+
210+
var file_dialog = new Gtk.FileDialog () {
211+
accept_label = _("Open"),
212+
default_filter = music_files_filter,
213+
filters = filter_model,
214+
modal = true,
215+
title = _("Open audio files")
216+
};
217+
218+
file_dialog.open_multiple.begin (active_window, null, (obj, res) => {
219+
try {
220+
var files = file_dialog.open_multiple.end (res);
221+
222+
File[] file_array = {};
223+
for (int i = 0; i < files.get_n_items (); i++) {
224+
file_array += (File)(files.get_item (i));
225+
}
226+
227+
var files_to_play = Application.loop_through_files (file_array);
228+
PlaybackManager.get_default ().queue_files (files_to_play);
229+
} catch (Error e) {
230+
if (e.matches (Gtk.DialogError.quark (), Gtk.DialogError.DISMISSED)) {
231+
return;
232+
}
233+
234+
var dialog = new Granite.MessageDialog (
235+
"Couldn't add audio files",
236+
e.message,
237+
new ThemedIcon ("document-open")
238+
) {
239+
badge_icon = new ThemedIcon ("dialog-error"),
240+
modal = true,
241+
transient_for = active_window
242+
};
243+
dialog.present ();
244+
dialog.response.connect (dialog.destroy);
245+
}
246+
});
191247
}
192248

193249
private void on_bus_acquired (DBusConnection connection, string name) {

src/MainWindow.vala

Lines changed: 16 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -4,103 +4,25 @@
44
*/
55

66
public class Music.MainWindow : Gtk.ApplicationWindow {
7-
private Gtk.Button repeat_button;
8-
private Gtk.Button shuffle_button;
97
private Settings settings;
10-
private Gtk.SearchEntry search_entry;
11-
private Gtk.Revealer search_revealer;
128

139
construct {
14-
var start_window_controls = new Gtk.WindowControls (Gtk.PackType.START);
10+
var start_window_controls = new Gtk.WindowControls (START);
1511

1612
var stack_switcher = new Gtk.StackSwitcher () {
1713
hexpand = false
1814
};
1915
((Gtk.BoxLayout)stack_switcher.get_layout_manager ()).homogeneous = true;
2016

21-
shuffle_button = new Gtk.Button.from_icon_name ("media-playlist-shuffle-symbolic") {
22-
action_name = Application.ACTION_PREFIX + Application.ACTION_SHUFFLE,
23-
tooltip_text = _("Shuffle")
24-
};
25-
26-
repeat_button = new Gtk.Button ();
27-
28-
search_entry = new Gtk.SearchEntry () {
29-
placeholder_text = _("Search titles in playlist")
30-
};
31-
32-
search_revealer = new Gtk.Revealer () {
33-
child = search_entry
34-
};
35-
36-
playback_manager.bind_property (
37-
"has-items", search_revealer, "reveal-child", DEFAULT | SYNC_CREATE
38-
);
39-
var queue_header = new Gtk.HeaderBar () {
40-
show_title_buttons = false,
41-
title_widget = search_revealer
42-
};
43-
4417
var start_header = new Gtk.HeaderBar () {
4518
show_title_buttons = false,
4619
title_widget = stack_switcher
4720
};
4821
start_header.add_css_class (Granite.STYLE_CLASS_FLAT);
4922
start_header.pack_start (start_window_controls);
50-
start_header.pack_end (shuffle_button);
51-
start_header.pack_end (repeat_button);
52-
53-
var queue_view = new QueueView ();
5423

5524
var library_view = new LibraryView ();
5625

57-
var stack = new Gtk.Stack ();
58-
stack.add_titled (library_view, null, _("Library"));
59-
stack.add_titled (queue_view, null, _("Play Queue"));
60-
61-
<<<<<<< HEAD
62-
stack_switcher.stack = stack;
63-
=======
64-
var add_button_label = new Gtk.Label (_("Open Files…"));
65-
66-
var add_button_box = new Gtk.Box (HORIZONTAL, 0);
67-
add_button_box.append (new Gtk.Image.from_icon_name ("document-open-symbolic"));
68-
add_button_box.append (add_button_label);
69-
70-
var add_button = new Gtk.Button () {
71-
child = add_button_box,
72-
};
73-
add_button.add_css_class (Granite.STYLE_CLASS_FLAT);
74-
75-
add_button_label.mnemonic_widget = add_button;
76-
77-
var queue_action_bar = new Gtk.ActionBar ();
78-
queue_action_bar.pack_start (add_button);
79-
80-
var queue = new Adw.ToolbarView () {
81-
bottom_bar_style = RAISED,
82-
content = scrolled
83-
};
84-
queue.add_controller (drop_target);
85-
queue.add_css_class (Granite.STYLE_CLASS_VIEW);
86-
queue.add_top_bar (queue_header);
87-
queue.add_bottom_bar (queue_action_bar);
88-
>>>>>>> main
89-
90-
var start_box = new Gtk.Box (VERTICAL, 0);
91-
start_box.add_css_class (Granite.STYLE_CLASS_VIEW);
92-
start_box.append (start_header);
93-
start_box.append (stack);
94-
95-
var end_window_controls = new Gtk.WindowControls (Gtk.PackType.END);
96-
97-
var end_header = new Gtk.HeaderBar () {
98-
show_title_buttons = false,
99-
title_widget = new Gtk.Label ("")
100-
};
101-
end_header.add_css_class (Granite.STYLE_CLASS_FLAT);
102-
end_header.pack_end (end_window_controls);
103-
10426
var now_playing_view = new NowPlayingView () {
10527
margin_top = 12,
10628
margin_end = 12,
@@ -109,17 +31,26 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
10931
vexpand = true
11032
};
11133

112-
var now_playing = new Gtk.Box (VERTICAL, 0);
113-
now_playing.append (end_header);
114-
now_playing.append (now_playing_view);
115-
11634
var now_playing_handle = new Gtk.WindowHandle () {
117-
child = now_playing
35+
child = now_playing_view
11836
};
11937

38+
var stack = new Gtk.Stack ();
39+
stack.add_titled (library_view, null, _("Library"));
40+
stack.add_titled (now_playing_handle, null, _("Now Playing"));
41+
42+
stack_switcher.stack = stack;
43+
44+
var start_box = new Gtk.Box (VERTICAL, 0);
45+
start_box.add_css_class (Granite.STYLE_CLASS_VIEW);
46+
start_box.append (start_header);
47+
start_box.append (stack);
48+
49+
var queue_view = new QueueView ();
50+
12051
var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL) {
12152
start_child = start_box,
122-
end_child = now_playing_handle,
53+
end_child = queue_view,
12354
resize_end_child = false,
12455
shrink_end_child = false,
12556
shrink_start_child = false
@@ -135,88 +66,5 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
13566

13667
settings = new Settings ("io.elementary.music");
13768
settings.bind ("pane-position", paned, "position", SettingsBindFlags.DEFAULT);
138-
settings.changed["repeat-mode"].connect (update_repeat_button);
139-
140-
update_repeat_button ();
141-
142-
repeat_button.clicked.connect (() => {
143-
var enum_step = settings.get_enum ("repeat-mode");
144-
if (enum_step < 2) {
145-
settings.set_enum ("repeat-mode", enum_step + 1);
146-
} else {
147-
settings.set_enum ("repeat-mode", 0);
148-
}
149-
});
150-
}
151-
152-
private void action_open () {
153-
var all_files_filter = new Gtk.FileFilter () {
154-
name = _("All files"),
155-
};
156-
all_files_filter.add_pattern ("*");
157-
158-
var music_files_filter = new Gtk.FileFilter () {
159-
name = _("Music files"),
160-
};
161-
music_files_filter.add_mime_type ("audio/*");
162-
163-
var filter_model = new ListStore (typeof (Gtk.FileFilter));
164-
filter_model.append (all_files_filter);
165-
filter_model.append (music_files_filter);
166-
167-
var file_dialog = new Gtk.FileDialog () {
168-
accept_label = _("Open"),
169-
default_filter = music_files_filter,
170-
filters = filter_model,
171-
modal = true,
172-
title = _("Open audio files")
173-
};
174-
175-
file_dialog.open_multiple.begin (this, null, (obj, res) => {
176-
try {
177-
var files = file_dialog.open_multiple.end (res);
178-
179-
File[] file_array = {};
180-
for (int i = 0; i < files.get_n_items (); i++) {
181-
file_array += (File)(files.get_item (i));
182-
}
183-
184-
var files_to_play = Application.loop_through_files (file_array);
185-
PlaybackManager.get_default ().queue_files (files_to_play);
186-
} catch (Error e) {
187-
if (e.matches (Gtk.DialogError.quark (), Gtk.DialogError.DISMISSED)) {
188-
return;
189-
}
190-
191-
var dialog = new Granite.MessageDialog (
192-
"Couldn't add audio files",
193-
e.message,
194-
new ThemedIcon ("document-open")
195-
) {
196-
badge_icon = new ThemedIcon ("dialog-error"),
197-
modal = true,
198-
transient_for = this
199-
};
200-
dialog.present ();
201-
dialog.response.connect (dialog.destroy);
202-
}
203-
});
204-
}
205-
206-
private void update_repeat_button () {
207-
switch (settings.get_string ("repeat-mode")) {
208-
case "disabled":
209-
repeat_button.icon_name = "media-playlist-no-repeat-symbolic";
210-
repeat_button.tooltip_text = _("Repeat None");
211-
break;
212-
case "all":
213-
repeat_button.icon_name = "media-playlist-repeat-symbolic";
214-
repeat_button.tooltip_text = _("Repeat All");
215-
break;
216-
case "one":
217-
repeat_button.icon_name = "media-playlist-repeat-song-symbolic";
218-
repeat_button.tooltip_text = _("Repeat One");
219-
break;
220-
}
22169
}
22270
}

src/Services/PlaybackManager.vala

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,26 @@ public class Music.PlaybackManager : Object {
265265
}
266266

267267
public int find_title (string term) {
268-
var search_object = new AudioObject ("") {
269-
title = term
270-
};
271-
272-
int found_at = -1;
273-
uint position;
274-
if (queue_liststore.find_with_equal_func (
275-
search_object,
276-
(a, b) => {
277-
var term_a = ((AudioObject)a).title.down ();
278-
var term_b = ((AudioObject)b).title.down ();
279-
return term_a.contains (term_b);
280-
},
281-
out position
282-
)) {
283-
found_at = (int)position;
284-
}
285-
286-
return found_at;
268+
return 0;
269+
// var search_object = new AudioObject ("") {
270+
// title = term
271+
// };
272+
273+
// int found_at = -1;
274+
// uint position;
275+
// if (queue_liststore.find_with_equal_func (
276+
// search_object,
277+
// (a, b) => {
278+
// var term_a = ((AudioObject)a).title.down ();
279+
// var term_b = ((AudioObject)b).title.down ();
280+
// return term_a.contains (term_b);
281+
// },
282+
// out position
283+
// )) {
284+
// found_at = (int)position;
285+
// }
286+
287+
// return found_at;
287288
}
288289

289290
private void update_next_previous_sensitivity () {

0 commit comments

Comments
 (0)