Merge lp:~elementary-apps/noise/not-found-dialog into lp:~elementary-apps/noise/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: David Gomes
Approved revision: 1585
Merged at revision: 1584
Proposed branch: lp:~elementary-apps/noise/not-found-dialog
Merge into: lp:~elementary-apps/noise/trunk
Diff against target: 256 lines (+93/-103)
1 file modified
src/Dialogs/FileNotFoundDialog.vala (+93/-103)
To merge this branch: bzr merge lp:~elementary-apps/noise/not-found-dialog
Reviewer Review Type Date Requested Status
David Gomes (community) Approve
Review via email: mp+216607@code.launchpad.net

Commit message

* Rewrite FileNotFoundDialog.vala as a subclass of Gtk.Dialog
* Change dialog copy
* Change icon
* fix code style

Description of the change

Rewrite FileNotFoundDialog.vala as a subclass of Gtk.Dialog

To post a comment you must log in.
1585. By David Gomes

Fixes code style.

Revision history for this message
David Gomes (davidgomes) :
review: Approve
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

+ body_string = (_("The music file for " + "<b>" +"$NAME" + "</b>" +
+ " by " + "<b>" + "$ARTIST" + "</b>" + " could not be found.").replace
+ ("$NAME", s.title.escape ("")).replace ("$ARTIST", s.artist.escape ("")));

How is this suppose to be translated properly?

This looks pretty scary and "...".printf (...) should be used to do it better!
Of cource there is still be possibility an improper translation will let it fail bad.

Revision history for this message
David Gomes (davidgomes) wrote :

That doesn't really belong here but instead in a bug report. Very valid concerns though Rico.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

The line was heavily changed into this, so it pretty much concerns this merge. It wasn't good before either though.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Dialogs/FileNotFoundDialog.vala'
2--- src/Dialogs/FileNotFoundDialog.vala 2014-04-20 17:04:53 +0000
3+++ src/Dialogs/FileNotFoundDialog.vala 2014-04-21 18:21:07 +0000
4@@ -29,158 +29,148 @@
5 * Corentin Noël <tintou@mailoo.org>
6 */
7
8-public class Noise.FileNotFoundDialog : Gtk.Window {
9+public class Noise.FileNotFoundDialog : Gtk.Dialog {
10 Gee.LinkedList<Media> media_list;
11
12- private Gtk.Box content;
13- private Gtk.Box padding;
14-
15- Gtk.Button removeMedia;
16- Gtk.Button locateMedia;
17 Gtk.Button rescanLibrary;
18- Gtk.Button doNothing;
19
20 public FileNotFoundDialog (Gee.LinkedList<Media> media_list) {
21 this.media_list = media_list;
22
23- // set the size based on saved gconf settings
24- //this.window_position = WindowPosition.CENTER;
25- this.type_hint = Gdk.WindowTypeHint.DIALOG;
26- this.title = ((Noise.App) GLib.Application.get_default ()).get_name ();
27 this.set_modal (true);
28 this.set_transient_for (App.main_window);
29 this.destroy_with_parent = true;
30-
31- set_default_size(475, -1);
32+ this.border_width = 6;
33 resizable = false;
34
35- content = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
36- padding = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 20);
37+ var content = get_content_area () as Gtk.Box;
38
39 // initialize controls
40- Gtk.Image warning = new Gtk.Image.from_icon_name ("dialog-error", Gtk.IconSize.DIALOG);
41- Gtk.Label title = new Gtk.Label("");
42- Gtk.Label info = new Gtk.Label("");
43- removeMedia = new Gtk.Button.with_label(_("Remove Media"));
44- locateMedia = new Gtk.Button.with_label(_("Locate Media"));
45- rescanLibrary = new Gtk.Button.with_label(_("Rescan Library"));
46- doNothing = new Gtk.Button.with_label(_("Do Nothing"));
47-
48- // pretty up labels
49-
50- // be a bit explicit to make translations better
51- var MARKUP_TEMPLATE = "<span weight=\"bold\" size=\"larger\">%s</span>";
52- var title_string = MARKUP_TEMPLATE.printf (String.escape (_("Could not find media file")));
53- title.set_markup (title_string);
54- title.xalign = 0.0f; //FIXME: deprecated
55-
56- info.set_line_wrap (true);
57- info.xalign = 0.0f; //FIXME: deprecated
58+ Gtk.Image warning = new Gtk.Image.from_icon_name ("dialog-warning", Gtk.IconSize.DIALOG);
59+ warning.yalign = 0;
60+
61+ var title_string = _("File not found");
62+ var body_string = "";
63
64 if (media_list.size == 1) {
65 var s = media_list.get (0);
66- info.set_markup (_("The music file for $NAME by $ARTIST could not be found. What would you like to do?").replace ("$NAME", s.title.escape ("")).replace ("$ARTIST", s.artist.escape ("")));
67+
68+ body_string = (_("The music file for " + "<b>" +"$NAME" + "</b>" +
69+ " by " + "<b>" + "$ARTIST" + "</b>" + " could not be found.").replace
70+ ("$NAME", s.title.escape ("")).replace ("$ARTIST", s.artist.escape ("")));
71 } else {
72- info.set_text (_("%i media files could not be found. What would you like to do?").printf (media_list.size));
73+ body_string = (_("%i music files could not be found?").printf (media_list.size));
74 }
75
76-
77-
78- rescanLibrary.set_sensitive(!libraries_manager.local_library.doing_file_operations());
79-
80- /* set up controls layout */
81- var information = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
82- var information_text = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
83- information.pack_start(warning, false, false, 10);
84- information_text.pack_start(title, false, true, 10);
85- information_text.pack_start(info, false, true, 0);
86- information.pack_start(information_text, true, true, 10);
87-
88- var bottomButtons = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
89- bottomButtons.set_layout(Gtk.ButtonBoxStyle.END);
90- bottomButtons.pack_end(removeMedia, false, false, 0);
91- bottomButtons.pack_end(rescanLibrary, false, false, 0);
92- bottomButtons.pack_end(locateMedia, false, false, 0);
93- bottomButtons.pack_end(doNothing, false, false, 10);
94- bottomButtons.set_spacing(10);
95-
96- content.pack_start(information, false, true, 0);
97- content.pack_start(bottomButtons, false, true, 10);
98-
99- padding.pack_start(content, true, true, 10);
100-
101- removeMedia.clicked.connect(removeMediaClicked);
102- locateMedia.clicked.connect(locateMediaClicked);
103- rescanLibrary.clicked.connect(rescanLibraryClicked);
104- doNothing.clicked.connect( () => {
105- this.destroy();
106+ var info = new Granite.Widgets.WrapLabel (("<span weight=\"bold\" size=\"larger\">%s</span>").printf
107+ (String.escape (title_string)) + "\n\n" + ("%s").printf (body_string)
108+ );
109+
110+ info.m_wrap_width = 350;
111+ info.set_selectable (true);
112+ info.set_use_markup (true);
113+
114+ rescanLibrary.set_sensitive (!libraries_manager.local_library.doing_file_operations ());
115+
116+ var layout = new Gtk.Grid ();
117+ layout.set_column_spacing (12);
118+ layout.set_margin_right (6);
119+ layout.set_margin_bottom (24);
120+ layout.set_margin_left (6);
121+ layout.add (warning);
122+ layout.add (info);
123+
124+ content.add (layout);
125+
126+ add_button (_("Rescan Library"), 1);
127+ add_button (_("Remove Song"), 2);
128+ add_button (_("Cancel"), Gtk.ResponseType.CLOSE);
129+ add_button (_("Find Song"), 3);
130+
131+ this.response.connect ((response_id) => {
132+ switch (response_id) {
133+ case 1:
134+ rescan_library_clicked ();
135+ break;
136+ case 2:
137+ remove_media_clicked ();
138+ break;
139+ case 3:
140+ locate_media_clicked ();
141+ break;
142+ case Gtk.ResponseType.CLOSE:
143+ destroy ();
144+ break;
145+ }
146 });
147
148- libraries_manager.local_library.file_operations_started.connect(file_operations_started);
149- libraries_manager.local_library.file_operations_done.connect(file_operations_done);
150+ libraries_manager.local_library.file_operations_started.connect (file_operations_started);
151+ libraries_manager.local_library.file_operations_done.connect (file_operations_done);
152
153- add(padding);
154- show_all();
155+ show_all ();
156 }
157
158- void removeMediaClicked() {
159+ void remove_media_clicked () {
160 libraries_manager.local_library.remove_medias (media_list, false);
161
162- this.destroy();
163+ this.destroy ();
164 }
165
166- void locateMediaClicked() {
167- Media m = media_list.get(0);
168+ void locate_media_clicked () {
169+ Media m = media_list.get (0);
170 int media_id = m.rowid;
171
172 string file = "";
173 var file_chooser = new Gtk.FileChooserDialog (_("Choose Music Folder"), this,
174- Gtk.FileChooserAction.OPEN,
175- _(STRING_CANCEL), Gtk.ResponseType.CANCEL,
176- _(STRING_OPEN), Gtk.ResponseType.ACCEPT);
177+ Gtk.FileChooserAction.OPEN,
178+ _(STRING_CANCEL), Gtk.ResponseType.CANCEL,
179+ _(STRING_OPEN), Gtk.ResponseType.ACCEPT);
180
181 // try and help user by setting a sane default folder
182- var invalid_file = File.new_for_uri(libraries_manager.local_library.media_from_id(media_id).uri);
183+ var invalid_file = File.new_for_uri (libraries_manager.local_library.media_from_id (media_id).uri);
184 var music_folder = Settings.Main.get_default ().music_folder;
185- if(invalid_file.get_parent().query_exists())
186- file_chooser.set_current_folder(invalid_file.get_parent().get_path());
187- else if(invalid_file.get_parent().get_parent().query_exists() &&
188- invalid_file.get_parent ().get_parent ().get_path ().contains (music_folder))
189- file_chooser.set_current_folder(invalid_file.get_parent().get_parent().get_path());
190- else if(File.new_for_path (music_folder).query_exists ())
191+
192+ if (invalid_file.get_parent ().query_exists ()) {
193+ file_chooser.set_current_folder (invalid_file.get_parent().get_path ());
194+ } else if (invalid_file.get_parent ().get_parent ().query_exists () &&
195+ invalid_file.get_parent ().get_parent ().get_path ().contains (music_folder)) {
196+
197+ file_chooser.set_current_folder (invalid_file.get_parent ().get_parent ().get_path ());
198+ } else if (File.new_for_path (music_folder).query_exists ()) {
199 file_chooser.set_current_folder (music_folder);
200- else
201- file_chooser.set_current_folder(Environment.get_home_dir());
202+ } else {
203+ file_chooser.set_current_folder (Environment.get_home_dir ());
204+ }
205
206 if (file_chooser.run () == Gtk.ResponseType.ACCEPT) {
207- file = file_chooser.get_filename();
208+ file = file_chooser.get_filename ();
209 }
210
211 file_chooser.destroy ();
212
213- if(file != "" && File.new_for_path(file).query_exists()) {
214- m.uri = File.new_for_path(file).get_uri();
215+ if (file != "" && File.new_for_path (file).query_exists ()) {
216+ m.uri = File.new_for_path (file).get_uri ();
217 m.location_unknown = false;
218 m.unique_status_image = null;
219+
220 // TODO: lm.lw.media_found(m.rowid);
221 libraries_manager.local_library.update_media (m, false, false);
222
223- this.destroy();
224+ this.destroy ();
225 }
226 }
227
228- void rescanLibraryClicked() {
229- ((LocalLibrary)libraries_manager.local_library).rescan_music_folder ();
230-
231- this.destroy();
232- }
233-
234- void file_operations_done() {
235- rescanLibrary.set_sensitive(true);
236- }
237-
238- void file_operations_started() {
239- rescanLibrary.set_sensitive(false);
240- }
241-
242+ void rescan_library_clicked () {
243+ ((LocalLibrary) libraries_manager.local_library).rescan_music_folder ();
244+
245+ this.destroy ();
246+ }
247+
248+ void file_operations_done () {
249+ rescanLibrary.set_sensitive (true);
250+ }
251+
252+ void file_operations_started () {
253+ rescanLibrary.set_sensitive (false);
254+ }
255 }
256\ No newline at end of file

Subscribers

People subscribed via source and target branches