Loading data/mlm.ui +14 −11 Original line number Diff line number Diff line Loading @@ -829,7 +829,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Title of the track</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -857,7 +857,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Album name</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -885,7 +885,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Album band</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -915,7 +915,7 @@ <property name="adjustment">year_adjustment</property> <property name="text">1900</property> <property name="tooltip-text" translatable="yes">Year of release</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -944,7 +944,7 @@ <property name="adjustment">disc_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Disc number</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">3</property> Loading Loading @@ -973,7 +973,7 @@ <property name="adjustment">track_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Track number</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1002,7 +1002,7 @@ <property name="adjustment">total_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Total number of tracks</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">3</property> Loading Loading @@ -1040,7 +1040,7 @@ <property name="text">Blues</property> <property name="completion">genre_completion</property> <property name="tooltip-text" translatable="yes">Genre of the track</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> </child> </object> Loading Loading @@ -1070,7 +1070,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Track comment</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1099,7 +1099,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Track composer</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1127,7 +1127,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Original artist</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1418,6 +1418,9 @@ <child> <object class="GtkLabel" id="time_label"> <property name="visible">True</property> <property name="width-request">42</property> <property name="halign">start</property> <property name="xalign">0.0</property> <property name="label">00:00</property> </object> </child> Loading src/application/application-window.vala +36 −53 Original line number Diff line number Diff line Loading @@ -159,6 +159,8 @@ namespace MLM { /* The MLM application. */ private Application mlm; /* The file tags. */ private FileTags tags; /** * Initializes the application window. Loading Loading @@ -195,57 +197,50 @@ namespace MLM { /* The on previous clicked callback. */ [GtkCallback] private void on_previous_clicked() { mlm.previous(); mlm.activate_action("prev", null); } /* The on next clicked callback. */ [GtkCallback] private void on_next_clicked() { mlm.next(); mlm.activate_action("next", null); } /* The on popover visibility changed callback. */ [GtkCallback] private void on_popover_visibility_changed() { if (!encode_popover.visible) { mlm.stop_encoder(); mlm.activate_action("stop-encoder", null); } else { encode_progress_bar.set_fraction(0.0); mlm.start_encoder(); mlm.activate_action("start-encoder", null); } } /* The on save clicked callback. */ [GtkCallback] private void on_save_clicked() { mlm.save(); save_button.sensitive = false; mlm.activate_action("save", null); } /* The on play clicked callback. */ [GtkCallback] private void on_play_clicked() { if (!mlm.is_player_playing()) { play_image.set_from_icon_name(ICON_NAME_PAUSE, ICON_SIZE); mlm.start_player(); } else { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); mlm.pause_player(); } mlm.activate_action("play", null); } /* The on open artist image clicked callback. */ [GtkCallback] private void on_open_artist_image_clicked() { var data = select_image(_("Select image for artist")); mlm.set_artist_picture_data(data); tags.artist_picture = data; update_image(artist_image, data); } /* The on clear artist image clicked callback. */ [GtkCallback] private void on_clear_artist_image_clicked() { mlm.set_artist_picture_data(null); tags.artist_picture = null; set_default_image(artist_image); save_button.sensitive = true; } Loading @@ -254,14 +249,14 @@ namespace MLM { [GtkCallback] private void on_open_cover_image_clicked() { var data = select_image(_("Select image for cover")); mlm.set_cover_picture_data(data); tags.cover_picture = data; update_image(cover_image, data); } /* The on clear cover image clicked callback. */ [GtkCallback] private void on_clear_cover_image_clicked() { mlm.set_cover_picture_data(null); tags.cover_picture = null; set_default_image(cover_image); save_button.sensitive = true; } Loading Loading @@ -295,22 +290,6 @@ namespace MLM { /* The on window key press callback. */ [GtkCallback] private bool on_window_key_press(Gdk.EventKey e) { if (e.keyval == Gdk.Key.Page_Up) { on_previous_clicked(); return true; } if (e.keyval == Gdk.Key.Page_Down) { on_next_clicked(); return true; } if (e.keyval == Gdk.Key.Escape) { mlm.quit(); return true; } if (e.keyval == Gdk.Key.space && (e.state & Gdk.ModifierType.CONTROL_MASK) != 0) { on_play_clicked(); } return false; } Loading @@ -330,19 +309,26 @@ namespace MLM { } /** * Sets the view at play started. * Updates the player view. * @param percentage the percentage of the player. * @param time the player time string. */ public void update_player_view(double percentage, string time) { play_adjustment.set_value(percentage); time_label.set_text(time); } /** * Sets the pause icon. */ public void play_started() { public void set_pause_icon() { play_image.set_from_icon_name(ICON_NAME_PAUSE, ICON_SIZE); GLib.Idle.add(monitor_player); } /** * Sets the view at play paused. * Sets the play icon. */ public void play_paused() { if (mlm.player_completion() == 0.0) reset_timer(); public void set_play_icon() { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); } Loading @@ -360,17 +346,6 @@ namespace MLM { dialog.destroy(); } /* Monitors the player in the model. */ private bool monitor_player() { if (!mlm.is_player_playing()) { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); return false; } play_adjustment.set_value(mlm.player_completion()); time_label.set_text(mlm.player_time()); return true; } /* Resets the timer. */ private void reset_timer() { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); Loading @@ -389,6 +364,13 @@ namespace MLM { tags_frame.sensitive = enable; } /** * Enables the save button. */ public void enable_save(bool enable) { save_button.sensitive = enable; } /** * Updates the view. * @param filename the filename. Loading @@ -398,6 +380,7 @@ namespace MLM { */ public void update_view(string filename, FileTags tags, int current, int total) { this.tags = tags; header_bar.set_subtitle("%d / %d".printf(current, total)); var basename = GLib.Path.get_basename(filename); var markup = GLib.Markup.printf_escaped("<b>%s</b>", basename); Loading Loading @@ -470,13 +453,13 @@ namespace MLM { /** * Shows the about dialog. */ public void about() { public void show_about_dialog() { string[] authors = { "Canek Peláez Valdés <canek@ciencias.unam.mx>" }; Gtk.show_about_dialog( this, "authors", authors, "comments", _("A Gtk+ based music library maintainer"), "copyright", "Copyright © 2013-2018 Canek Peláez Valdés", "copyright", "Copyright © 2013-2019 Canek Peláez Valdés", "license-type", Gtk.License.GPL_3_0, "logo-icon-name", "mlm", "version", Config.PACKAGE_VERSION, Loading src/application/application.vala +100 −106 Original line number Diff line number Diff line Loading @@ -62,20 +62,44 @@ namespace MLM { public override void startup() { base.startup(); var action = new GLib.SimpleAction("about", null); var action = new GLib.SimpleAction("prev", null); action.activate.connect(previous); add_action(action); set_accels_for_action("app.prev", new string[]{"<Ctrl>Page_Up"}); action = new GLib.SimpleAction("next", null); action.activate.connect(next); add_action(action); set_accels_for_action("app.next", new string[]{"<Ctrl>Page_Down"}); action = new GLib.SimpleAction("save", null); action.activate.connect(save); add_action(action); set_accels_for_action("app.save", new string[]{"<Ctrl>S"}); action = new GLib.SimpleAction("play", null); action.activate.connect(play); add_action(action); set_accels_for_action("app.play", new string[]{"<Ctrl>space"}); action = new GLib.SimpleAction("start-encoder", null); action.activate.connect(start_encoder); add_action(action); action = new GLib.SimpleAction("stop-encoder", null); action.activate.connect(stop_encoder); add_action(action); action = new GLib.SimpleAction("about", null); action.activate.connect(about); add_action(action); add_accelerator("<Ctrl>A", "app.quit", null); set_accels_for_action("app.about", new string[]{"<Ctrl>B"}); action = new GLib.SimpleAction("quit", null); action.activate.connect(quit); add_action(action); add_accelerator("<Ctrl>Q", "app.quit", null); var menu = new GLib.Menu(); menu.append(_("About"), "app.about"); menu.append(_("Quit"), "app.quit"); set_app_menu(menu); set_accels_for_action("app.quit", new string[]{"<Ctrl>Q", "Escape"}); } /** Loading Loading @@ -127,9 +151,35 @@ namespace MLM { } /** * Iterates to the previous file. * Seeks a percentage in the player. * @return ''true'' if the seeking succeeds; ''false'' otherwise. */ public void previous() { public bool seek_player(double percentage) { return player.seek(percentage); } /* Returns the player completion percentage. */ private double player_completion() { if (player == null || !player.working) return 0.0; int64 d, p; return player.get_completion(out d, out p); } /* Returns a string representing the playing time. */ private string player_time() { if (player == null || !player.working) return "00:00"; int64 position = -1, duration = -1; player.get_completion(out position, out duration); int64 tsecs = duration / 1000000000l; int mins = (int)(tsecs / 60); int secs = (int)(tsecs % 60); return "%02d:%02d".printf(mins, secs); } /* The previous action. */ private void previous() { if (player != null && player.working) player.pause(); if (!iterator.has_previous()) Loading @@ -139,10 +189,8 @@ namespace MLM { update_file(); } /** * Iterates to the next file. */ public void next() { /* The next action. */ private void next() { if (player != null && player.working) player.pause(); if (!iterator.has_next()) Loading @@ -152,28 +200,34 @@ namespace MLM { update_file(); } /** * Saves the current file. */ /* The save action. */ public void save() { window.update_model(tags); window.enable_save(false); tags.update(); } /** * Starts the encoder. */ public void start_encoder() { /* The play action. */ private void play() { if (player != null && !player.working) { window.set_pause_icon(); player.play(); } else { window.set_play_icon(); player.pause(); } } /* Starts the encoder. */ private void start_encoder() { target = window.get_normalized_filename(filename); encoder = new Encoder(filename, target); encoder.encode(); GLib.Idle.add(update_encoding); } /** * Stops the encoder. */ public void stop_encoder() { /* Stops the encoder. */ private void stop_encoder() { if (target == null || encoder == null) return; encoder.cancel(); Loading @@ -182,80 +236,10 @@ namespace MLM { encoder = null; } /** * Sets the cover picture data. * @param cover_data the cover picture data. */ public void set_cover_picture_data(uint8[]? cover_data) { tags.cover_picture = cover_data; } /** * Sets the artist picture data. * @param artist_data the artist picture data. */ public void set_artist_picture_data(uint8[]? artist_data) { tags.artist_picture = artist_data; } /** * Starts the player. */ public void start_player() { if (is_player_playing()) return; player.play(); } /** * Pauses the player. */ public void pause_player() { if (!is_player_playing()) return; player.pause(); } /** * Seeks a percentage in the player. * @return ''true'' if the seeking succeeds; ''false'' otherwise. */ public bool seek_player(double percentage) { return player.seek(percentage); } /** * Returns the player completion percentage. * @return the player completion percentage. */ public double player_completion() { if (!is_player_playing()) return 0.0; int64 d, p; return player.get_completion(out d, out p); } /** * Whether the player is playing. * @return ''true'' if the player is playing, ''false'' otherwise. */ public bool is_player_playing() { return (player != null && player.working); } /** * Returns a string representing the playing time. * @return a string representing the playing time. */ public string player_time() { if (!is_player_playing()) return "00:00"; int64 position = -1, duration = -1; player.get_completion(out position, out duration); int64 tsecs = duration / 1000000000l; int mins = (int)(tsecs / 60); int secs = (int)(tsecs % 60); return "%02d:%02d".printf(mins, secs); /* The about action. */ private void about() { window.show_about_dialog(); tags.update(); } /* Compares two files by path. */ Loading @@ -281,11 +265,6 @@ namespace MLM { tags.update(); } /* The about action. */ private void about() { window.about(); } /* Updates the encoding process. */ private bool update_encoding() { if (encoder == null || target == null) Loading Loading @@ -315,12 +294,27 @@ namespace MLM { private void player_state_changed(Gst.State state) { switch (state) { case Gst.State.PLAYING: window.play_started(); window.set_pause_icon(); GLib.Idle.add(monitor_player); break; case Gst.State.PAUSED: window.play_paused(); if (player_completion() == 0.0) window.update_player_view(0.0, "00:00"); window.set_play_icon(); break; } } /* Monitors the player in the model. */ private bool monitor_player() { if (player != null && !player.working) { window.set_play_icon(); return false; } window.update_player_view(player_completion(), player_time()); return true; } } } Loading
data/mlm.ui +14 −11 Original line number Diff line number Diff line Loading @@ -829,7 +829,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Title of the track</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -857,7 +857,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Album name</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -885,7 +885,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Album band</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -915,7 +915,7 @@ <property name="adjustment">year_adjustment</property> <property name="text">1900</property> <property name="tooltip-text" translatable="yes">Year of release</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -944,7 +944,7 @@ <property name="adjustment">disc_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Disc number</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">3</property> Loading Loading @@ -973,7 +973,7 @@ <property name="adjustment">track_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Track number</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1002,7 +1002,7 @@ <property name="adjustment">total_adjustment</property> <property name="text">1</property> <property name="tooltip-text" translatable="yes">Total number of tracks</property> <signal name="value-changed" handler="tags_changed" swapped="no"/> <signal name="value-changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">3</property> Loading Loading @@ -1040,7 +1040,7 @@ <property name="text">Blues</property> <property name="completion">genre_completion</property> <property name="tooltip-text" translatable="yes">Genre of the track</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> </child> </object> Loading Loading @@ -1070,7 +1070,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Track comment</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1099,7 +1099,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Track composer</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1127,7 +1127,7 @@ <property name="can-focus">True</property> <property name="hexpand">True</property> <property name="tooltip-text" translatable="yes">Original artist</property> <signal name="changed" handler="tags_changed" swapped="no"/> <signal name="changed" handler="on_tags_changed" swapped="no"/> </object> <packing> <property name="left-attach">1</property> Loading Loading @@ -1418,6 +1418,9 @@ <child> <object class="GtkLabel" id="time_label"> <property name="visible">True</property> <property name="width-request">42</property> <property name="halign">start</property> <property name="xalign">0.0</property> <property name="label">00:00</property> </object> </child> Loading
src/application/application-window.vala +36 −53 Original line number Diff line number Diff line Loading @@ -159,6 +159,8 @@ namespace MLM { /* The MLM application. */ private Application mlm; /* The file tags. */ private FileTags tags; /** * Initializes the application window. Loading Loading @@ -195,57 +197,50 @@ namespace MLM { /* The on previous clicked callback. */ [GtkCallback] private void on_previous_clicked() { mlm.previous(); mlm.activate_action("prev", null); } /* The on next clicked callback. */ [GtkCallback] private void on_next_clicked() { mlm.next(); mlm.activate_action("next", null); } /* The on popover visibility changed callback. */ [GtkCallback] private void on_popover_visibility_changed() { if (!encode_popover.visible) { mlm.stop_encoder(); mlm.activate_action("stop-encoder", null); } else { encode_progress_bar.set_fraction(0.0); mlm.start_encoder(); mlm.activate_action("start-encoder", null); } } /* The on save clicked callback. */ [GtkCallback] private void on_save_clicked() { mlm.save(); save_button.sensitive = false; mlm.activate_action("save", null); } /* The on play clicked callback. */ [GtkCallback] private void on_play_clicked() { if (!mlm.is_player_playing()) { play_image.set_from_icon_name(ICON_NAME_PAUSE, ICON_SIZE); mlm.start_player(); } else { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); mlm.pause_player(); } mlm.activate_action("play", null); } /* The on open artist image clicked callback. */ [GtkCallback] private void on_open_artist_image_clicked() { var data = select_image(_("Select image for artist")); mlm.set_artist_picture_data(data); tags.artist_picture = data; update_image(artist_image, data); } /* The on clear artist image clicked callback. */ [GtkCallback] private void on_clear_artist_image_clicked() { mlm.set_artist_picture_data(null); tags.artist_picture = null; set_default_image(artist_image); save_button.sensitive = true; } Loading @@ -254,14 +249,14 @@ namespace MLM { [GtkCallback] private void on_open_cover_image_clicked() { var data = select_image(_("Select image for cover")); mlm.set_cover_picture_data(data); tags.cover_picture = data; update_image(cover_image, data); } /* The on clear cover image clicked callback. */ [GtkCallback] private void on_clear_cover_image_clicked() { mlm.set_cover_picture_data(null); tags.cover_picture = null; set_default_image(cover_image); save_button.sensitive = true; } Loading Loading @@ -295,22 +290,6 @@ namespace MLM { /* The on window key press callback. */ [GtkCallback] private bool on_window_key_press(Gdk.EventKey e) { if (e.keyval == Gdk.Key.Page_Up) { on_previous_clicked(); return true; } if (e.keyval == Gdk.Key.Page_Down) { on_next_clicked(); return true; } if (e.keyval == Gdk.Key.Escape) { mlm.quit(); return true; } if (e.keyval == Gdk.Key.space && (e.state & Gdk.ModifierType.CONTROL_MASK) != 0) { on_play_clicked(); } return false; } Loading @@ -330,19 +309,26 @@ namespace MLM { } /** * Sets the view at play started. * Updates the player view. * @param percentage the percentage of the player. * @param time the player time string. */ public void update_player_view(double percentage, string time) { play_adjustment.set_value(percentage); time_label.set_text(time); } /** * Sets the pause icon. */ public void play_started() { public void set_pause_icon() { play_image.set_from_icon_name(ICON_NAME_PAUSE, ICON_SIZE); GLib.Idle.add(monitor_player); } /** * Sets the view at play paused. * Sets the play icon. */ public void play_paused() { if (mlm.player_completion() == 0.0) reset_timer(); public void set_play_icon() { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); } Loading @@ -360,17 +346,6 @@ namespace MLM { dialog.destroy(); } /* Monitors the player in the model. */ private bool monitor_player() { if (!mlm.is_player_playing()) { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); return false; } play_adjustment.set_value(mlm.player_completion()); time_label.set_text(mlm.player_time()); return true; } /* Resets the timer. */ private void reset_timer() { play_image.set_from_icon_name(ICON_NAME_PLAY, ICON_SIZE); Loading @@ -389,6 +364,13 @@ namespace MLM { tags_frame.sensitive = enable; } /** * Enables the save button. */ public void enable_save(bool enable) { save_button.sensitive = enable; } /** * Updates the view. * @param filename the filename. Loading @@ -398,6 +380,7 @@ namespace MLM { */ public void update_view(string filename, FileTags tags, int current, int total) { this.tags = tags; header_bar.set_subtitle("%d / %d".printf(current, total)); var basename = GLib.Path.get_basename(filename); var markup = GLib.Markup.printf_escaped("<b>%s</b>", basename); Loading Loading @@ -470,13 +453,13 @@ namespace MLM { /** * Shows the about dialog. */ public void about() { public void show_about_dialog() { string[] authors = { "Canek Peláez Valdés <canek@ciencias.unam.mx>" }; Gtk.show_about_dialog( this, "authors", authors, "comments", _("A Gtk+ based music library maintainer"), "copyright", "Copyright © 2013-2018 Canek Peláez Valdés", "copyright", "Copyright © 2013-2019 Canek Peláez Valdés", "license-type", Gtk.License.GPL_3_0, "logo-icon-name", "mlm", "version", Config.PACKAGE_VERSION, Loading
src/application/application.vala +100 −106 Original line number Diff line number Diff line Loading @@ -62,20 +62,44 @@ namespace MLM { public override void startup() { base.startup(); var action = new GLib.SimpleAction("about", null); var action = new GLib.SimpleAction("prev", null); action.activate.connect(previous); add_action(action); set_accels_for_action("app.prev", new string[]{"<Ctrl>Page_Up"}); action = new GLib.SimpleAction("next", null); action.activate.connect(next); add_action(action); set_accels_for_action("app.next", new string[]{"<Ctrl>Page_Down"}); action = new GLib.SimpleAction("save", null); action.activate.connect(save); add_action(action); set_accels_for_action("app.save", new string[]{"<Ctrl>S"}); action = new GLib.SimpleAction("play", null); action.activate.connect(play); add_action(action); set_accels_for_action("app.play", new string[]{"<Ctrl>space"}); action = new GLib.SimpleAction("start-encoder", null); action.activate.connect(start_encoder); add_action(action); action = new GLib.SimpleAction("stop-encoder", null); action.activate.connect(stop_encoder); add_action(action); action = new GLib.SimpleAction("about", null); action.activate.connect(about); add_action(action); add_accelerator("<Ctrl>A", "app.quit", null); set_accels_for_action("app.about", new string[]{"<Ctrl>B"}); action = new GLib.SimpleAction("quit", null); action.activate.connect(quit); add_action(action); add_accelerator("<Ctrl>Q", "app.quit", null); var menu = new GLib.Menu(); menu.append(_("About"), "app.about"); menu.append(_("Quit"), "app.quit"); set_app_menu(menu); set_accels_for_action("app.quit", new string[]{"<Ctrl>Q", "Escape"}); } /** Loading Loading @@ -127,9 +151,35 @@ namespace MLM { } /** * Iterates to the previous file. * Seeks a percentage in the player. * @return ''true'' if the seeking succeeds; ''false'' otherwise. */ public void previous() { public bool seek_player(double percentage) { return player.seek(percentage); } /* Returns the player completion percentage. */ private double player_completion() { if (player == null || !player.working) return 0.0; int64 d, p; return player.get_completion(out d, out p); } /* Returns a string representing the playing time. */ private string player_time() { if (player == null || !player.working) return "00:00"; int64 position = -1, duration = -1; player.get_completion(out position, out duration); int64 tsecs = duration / 1000000000l; int mins = (int)(tsecs / 60); int secs = (int)(tsecs % 60); return "%02d:%02d".printf(mins, secs); } /* The previous action. */ private void previous() { if (player != null && player.working) player.pause(); if (!iterator.has_previous()) Loading @@ -139,10 +189,8 @@ namespace MLM { update_file(); } /** * Iterates to the next file. */ public void next() { /* The next action. */ private void next() { if (player != null && player.working) player.pause(); if (!iterator.has_next()) Loading @@ -152,28 +200,34 @@ namespace MLM { update_file(); } /** * Saves the current file. */ /* The save action. */ public void save() { window.update_model(tags); window.enable_save(false); tags.update(); } /** * Starts the encoder. */ public void start_encoder() { /* The play action. */ private void play() { if (player != null && !player.working) { window.set_pause_icon(); player.play(); } else { window.set_play_icon(); player.pause(); } } /* Starts the encoder. */ private void start_encoder() { target = window.get_normalized_filename(filename); encoder = new Encoder(filename, target); encoder.encode(); GLib.Idle.add(update_encoding); } /** * Stops the encoder. */ public void stop_encoder() { /* Stops the encoder. */ private void stop_encoder() { if (target == null || encoder == null) return; encoder.cancel(); Loading @@ -182,80 +236,10 @@ namespace MLM { encoder = null; } /** * Sets the cover picture data. * @param cover_data the cover picture data. */ public void set_cover_picture_data(uint8[]? cover_data) { tags.cover_picture = cover_data; } /** * Sets the artist picture data. * @param artist_data the artist picture data. */ public void set_artist_picture_data(uint8[]? artist_data) { tags.artist_picture = artist_data; } /** * Starts the player. */ public void start_player() { if (is_player_playing()) return; player.play(); } /** * Pauses the player. */ public void pause_player() { if (!is_player_playing()) return; player.pause(); } /** * Seeks a percentage in the player. * @return ''true'' if the seeking succeeds; ''false'' otherwise. */ public bool seek_player(double percentage) { return player.seek(percentage); } /** * Returns the player completion percentage. * @return the player completion percentage. */ public double player_completion() { if (!is_player_playing()) return 0.0; int64 d, p; return player.get_completion(out d, out p); } /** * Whether the player is playing. * @return ''true'' if the player is playing, ''false'' otherwise. */ public bool is_player_playing() { return (player != null && player.working); } /** * Returns a string representing the playing time. * @return a string representing the playing time. */ public string player_time() { if (!is_player_playing()) return "00:00"; int64 position = -1, duration = -1; player.get_completion(out position, out duration); int64 tsecs = duration / 1000000000l; int mins = (int)(tsecs / 60); int secs = (int)(tsecs % 60); return "%02d:%02d".printf(mins, secs); /* The about action. */ private void about() { window.show_about_dialog(); tags.update(); } /* Compares two files by path. */ Loading @@ -281,11 +265,6 @@ namespace MLM { tags.update(); } /* The about action. */ private void about() { window.about(); } /* Updates the encoding process. */ private bool update_encoding() { if (encoder == null || target == null) Loading Loading @@ -315,12 +294,27 @@ namespace MLM { private void player_state_changed(Gst.State state) { switch (state) { case Gst.State.PLAYING: window.play_started(); window.set_pause_icon(); GLib.Idle.add(monitor_player); break; case Gst.State.PAUSED: window.play_paused(); if (player_completion() == 0.0) window.update_player_view(0.0, "00:00"); window.set_play_icon(); break; } } /* Monitors the player in the model. */ private bool monitor_player() { if (player != null && !player.working) { window.set_play_icon(); return false; } window.update_player_view(player_completion(), player_time()); return true; } } }