[gnome-music] Added the search bar (not working yet)
- From: Cesar Garcia Tapia <ctapia src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Added the search bar (not working yet)
- Date: Wed, 31 Oct 2012 14:20:09 +0000 (UTC)
commit cca24461726b06e04cf195dde133b77330ecf884
Author: CÃsar GarcÃa Tapia <cesar garcia tapia openshine com>
Date: Wed Oct 31 15:18:45 2012 +0100
Added the search bar (not working yet)
src/Makefile.am | 1 +
src/music-app.vala | 58 ++++++++++++++++++++------
src/music-player.vala | 44 +++++++++++---------
src/music-searchbar.vala | 79 ++++++++++++++++++++++++++++++++++++
src/music-topbar.vala | 48 ++++++++++++++++++++--
src/org.gnome.Music.gschema.xml.in | 5 ++
6 files changed, 198 insertions(+), 37 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index fad167b..d285385 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,7 @@ bin_PROGRAMS = gnome-music
vala_sources = \
music-app.vala \
music-topbar.vala \
+ music-searchbar.vala \
music-player.vala \
music-collection-view.vala \
music-list-store.vala \
diff --git a/src/music-app.vala b/src/music-app.vala
index 3de9ce9..e4ae0d8 100644
--- a/src/music-app.vala
+++ b/src/music-app.vala
@@ -34,12 +34,18 @@ private enum Music.AppPage {
private class Music.App {
public static App app;
+
+ public signal void browse_back (string item_id, Music.ItemType? item_type);
+ public signal void app_state_changed (Music.AppState old_state, Music.AppState new_state);
+ public signal void search_mode_changed (bool search_enabled);
+
public Gtk.ApplicationWindow window;
private bool maximized { get { return WindowState.MAXIMIZED in window.get_window ().get_state (); } }
public GLib.Settings settings;
public Gtk.Box layout;
public Music.Topbar topbar;
+ public Music.Searchbar searchbar;
public Music.Player player;
public Music.CollectionView collectionView;
public Music.PlaylistView playlistView;
@@ -54,9 +60,6 @@ private class Music.App {
private uint configure_id;
public static const uint configure_id_timeout = 100; // 100ms
- public signal void browse_back (string item_id, Music.ItemType? item_type);
-
- public signal void app_state_changed (Music.AppState old_state, Music.AppState new_state);
private Music.AppState _app_state;
public Music.AppState app_state {
get {
@@ -72,7 +75,9 @@ private class Music.App {
public App () {
app = this;
application = new Gtk.Application ("org.gnome.Music", 0);
+
settings = new GLib.Settings ("org.gnome.Music");
+ settings.changed.connect (on_settings_key_changed);
browse_history = new Music.BrowseHistory ();
browse_history.changed.connect (on_browse_history_changed);
@@ -176,6 +181,15 @@ private class Music.App {
topbar.collection_back_btn_clicked.connect (on_collection_back_btn_clicked);
layout.pack_start (topbar.actor, false, false);
+ searchbar = new Music.Searchbar ();
+ if (search_mode == true) {
+ searchbar.show();
+ }
+ else {
+ searchbar.hide();
+ }
+ layout.pack_start (searchbar.actor, false, false);
+
notebook = new Gtk.Notebook ();
notebook.show_border = false;
notebook.show_tabs = false;
@@ -192,9 +206,7 @@ private class Music.App {
playlistView = new Music.PlaylistView (playlist);
notebook.append_page (playlistView.actor, null);
- player = new Music.Player ();
- player.need_next.connect (on_player_need_next);
- player.need_previous.connect (on_player_need_previous);
+ player = new Music.Player (playlist);
layout.pack_start (player.actor, false, false);
layout.show ();
@@ -234,14 +246,6 @@ private class Music.App {
player.load (media);
}
- private void on_player_need_next () {
- playlist.load_next();
- }
-
- private void on_player_need_previous () {
- playlist.load_previous();
- }
-
private void on_browse_history_changed () {
if (browse_history.get_length () > 1) {
topbar.set_collection_back_button_visible (true);
@@ -259,6 +263,21 @@ private class Music.App {
browse_back (last_item_id, last_item_type);
}
+ private void on_settings_key_changed (string key) {
+ if (key == "search") {
+ var val = settings.get_boolean ("search");
+
+ if (val == true) {
+ searchbar.show();
+ }
+ else {
+ searchbar.hide();
+ }
+
+ search_mode_changed (val);
+ }
+ }
+
private bool _selection_mode;
public bool selection_mode {
get {
@@ -269,6 +288,17 @@ private class Music.App {
}
}
+ public bool search_mode {
+ get {
+ return settings.get_boolean ("search");
+ }
+ set {
+ if (value != this.search_mode) {
+ settings.set_boolean ("search", value);
+ }
+ }
+ }
+
private void save_window_geometry () {
int width, height, x, y;
diff --git a/src/music-player.vala b/src/music-player.vala
index 3d0dcda..e25a389 100644
--- a/src/music-player.vala
+++ b/src/music-player.vala
@@ -42,9 +42,6 @@ internal class Music.PlayPauseButton : ToggleButton {
private class Music.Player: GLib.Object {
public Gtk.Widget actor { get { return eventbox; } }
- public signal void need_next ();
- public signal void need_previous ();
-
private Gtk.EventBox eventbox;
private PlayPauseButton play_btn;
@@ -61,29 +58,23 @@ private class Music.Player: GLib.Object {
private Gtk.ToggleButton shuffle_btn;
- private GLib.Settings settings;
- private dynamic Gst.Element playbin;
+ private Music.Playlist playlist;
- private bool shuffle;
+ private dynamic Gst.Element playbin;
private Music.AlbumArtCache cache;
private int ART_SIZE = 42;
private uint position_update_timeout;
- public Player () {
+ public Player (Music.Playlist playlist) {
Object ();
- cache = AlbumArtCache.get_default ();
-
- settings = new GLib.Settings ("org.gnome.Music");
- /*
- settings.bind ("shuffle",
- this,
- "shuffle",
- SettingsBindFlags.DEFAULT);
- */
+ this.playlist = playlist;
+ this.playlist.shuffle_mode_changed.connect (on_playlist_shuffle_mode_changed);
+ cache = AlbumArtCache.get_default ();
+
playbin = Gst.ElementFactory.make ("playbin2", null);
var bus = playbin.get_bus ();
bus.add_watch ( (bus, message) => {
@@ -149,7 +140,7 @@ private class Music.Player: GLib.Object {
box.pack_start (algmnt, false, false, 10);
cover_img = new Gtk.Image();
- toolbar_song_info.pack_start (cover_img, false, false, 0);
+ toolbar_song_info.pack_start (cover_img, false, false, 5);
var databox = new Gtk.Box (Orientation.VERTICAL, 0);
toolbar_song_info.pack_start (databox, false, false, 0);
@@ -191,8 +182,7 @@ private class Music.Player: GLib.Object {
shuffle_btn = new Gtk.ToggleButton ();
shuffle_btn.set_image (new Gtk.Image.from_icon_name ("media-playlist-shuffle-symbolic", IconSize.BUTTON));
- shuffle_btn.clicked.connect ((button) => {
- });
+ shuffle_btn.clicked.connect (on_shuffle_btn_clicked);
toolbar_end.pack_start (shuffle_btn, false, false, 0);
eventbox.show_all ();
@@ -260,6 +250,22 @@ private class Music.Player: GLib.Object {
need_previous ();
}
+ private void need_next () {
+ playlist.load_next();
+ }
+
+ private void need_previous () {
+ playlist.load_previous();
+ }
+
+ private void on_shuffle_btn_clicked () {
+ playlist.shuffle = shuffle_btn.get_active ();
+ }
+
+ private void on_playlist_shuffle_mode_changed (bool mode) {
+ shuffle_btn.set_active (mode);
+ }
+
private void set_duration (uint duration) {
progress_scale.set_range (0.0, (double) (duration * Gst.SECOND));
progress_scale.set_value (0.0);
diff --git a/src/music-searchbar.vala b/src/music-searchbar.vala
new file mode 100644
index 0000000..d33d5bb
--- /dev/null
+++ b/src/music-searchbar.vala
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 Cesar Garcia Tapia <tapia openshine com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+private class Music.Searchbar {
+ public Gtk.Widget actor { get { return eventbox; } }
+
+ private Gtk.EventBox eventbox;
+ private Gd.TaggedEntry search_entry;
+
+ public Searchbar () {
+ setup_ui ();
+ }
+
+ private void setup_ui () {
+ eventbox = new Gtk.EventBox ();
+ //eventbox.get_style_context ().add_class ("music-topbar");
+
+ var container = new Gd.MarginContainer ();
+ container.min_margin = 64;
+ container.max_margin = 128;
+ eventbox.add (container);
+
+ var box = new Gtk.Box (Orientation.HORIZONTAL, 0);
+ box.set_padding (5, 5, 5, 5);
+ container.add (box);
+
+ search_entry = new Gd.TaggedEntry();
+ search_entry.hexpand = true;
+ search_entry.key_press_event.connect (on_search_entry_key_pressed);
+ search_entry.changed.connect (on_search_entry_changed);
+ search_entry.tag_clicked.connect (on_search_entry_tag_clicked);
+ box.add (search_entry);
+
+ eventbox.show_all();
+ }
+
+ private bool on_search_entry_key_pressed (Gdk.EventKey e) {
+ var keyval = e.keyval;
+
+ if (keyval == Gdk.Key.Escape) {
+ App.app.search_mode = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ private void on_search_entry_changed () {
+ debug ("2");
+ }
+
+ private void on_search_entry_tag_clicked () {
+ debug ("3");
+ }
+
+ public void show () {
+ actor.show();
+ }
+
+ public void hide () {
+ actor.hide();
+ }
+}
\ No newline at end of file
diff --git a/src/music-topbar.vala b/src/music-topbar.vala
index f104b56..11c63df 100644
--- a/src/music-topbar.vala
+++ b/src/music-topbar.vala
@@ -36,6 +36,7 @@ private class Music.Topbar {
private Gtk.RadioButton collection_albums_btn;
private Gtk.RadioButton collection_songs_btn;
private Gtk.RadioButton collection_playlists_btn;
+ private Gtk.ToggleButton collection_search_btn;
private Gtk.Button collection_select_btn;
/* SELECTION buttons */
@@ -44,17 +45,20 @@ private class Music.Topbar {
private Gtk.Label selection_name_label;
private Gtk.Label selection_count_label;
private Gtk.Button selection_cancel_btn;
+ private Gtk.ToggleButton selection_search_btn;
private Gtk.Button selection_add_btn;
/* PLAYLIST buttons */
private Gtk.Button playlist_back_btn;
private Gtk.Button playlist_new_btn;
private Gtk.Label playlist_name_label;
+ private Gtk.ToggleButton playlist_search_btn;
private Gtk.Button playlist_select_btn;
public Topbar () {
setup_ui ();
- App.app.app_state_changed.connect (on_app_state_changed);
+ App.app.app_state_changed.connect (on_app_state_changed);
+ App.app.search_mode_changed.connect (on_app_search_mode_changed);
}
private void setup_ui () {
@@ -110,7 +114,13 @@ private class Music.Topbar {
collection_playlists_btn.toggled.connect (on_collection_playlists_btn_toggled);
toolbar_center.pack_start (collection_playlists_btn, false, false, 0);
- var toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 0);
+ var toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 10);
+
+ collection_search_btn = new Gtk.ToggleButton ();
+ collection_search_btn.set_image (new Gtk.Image.from_icon_name ("edit-find-symbolic", IconSize.BUTTON));
+ collection_search_btn.set_active (App.app.search_mode);
+ collection_search_btn.toggled.connect (on_search_btn_toggled);
+ toolbar_end.pack_start (collection_search_btn, false, false, 0);
collection_select_btn = new Gtk.Button ();
collection_select_btn.set_image (new Gtk.Image.from_icon_name ("emblem-default-symbolic", IconSize.BUTTON));
@@ -161,7 +171,13 @@ private class Music.Topbar {
toolbar_center.pack_start (selection_name_label, false, false, 0);
toolbar_center.pack_start (selection_count_label, false, false, 0);
- toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 5);
+ toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 10);
+
+ selection_search_btn = new Gtk.ToggleButton ();
+ selection_search_btn.set_image (new Gtk.Image.from_icon_name ("edit-find-symbolic", IconSize.BUTTON));
+ selection_search_btn.set_active (App.app.search_mode);
+ selection_search_btn.toggled.connect (on_search_btn_toggled);
+ toolbar_end.pack_start (selection_search_btn, false, false, 0);
selection_cancel_btn = new Gtk.Button.with_label (_("Cancel"));
selection_cancel_btn.get_style_context ().add_class ("dark");
@@ -204,7 +220,13 @@ private class Music.Topbar {
playlist_name_label = new Gtk.Label (_("Collection name"));
toolbar_center.pack_start (playlist_name_label, false, false, 0);
- toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 5);
+ toolbar_end = new Gtk.Box (Orientation.HORIZONTAL, 10);
+
+ playlist_search_btn = new Gtk.ToggleButton ();
+ playlist_search_btn.set_image (new Gtk.Image.from_icon_name ("edit-find-symbolic", IconSize.BUTTON));
+ playlist_search_btn.set_active (App.app.search_mode);
+ playlist_search_btn.toggled.connect (on_search_btn_toggled);
+ toolbar_end.pack_start (playlist_search_btn, false, false, 0);
playlist_select_btn = new Gtk.Button ();
playlist_select_btn.set_image (new Gtk.Image.from_icon_name ("emblem-default-symbolic", IconSize.BUTTON));
@@ -290,6 +312,24 @@ private class Music.Topbar {
collection_back_btn_clicked ();
}
+ private void on_search_btn_toggled (Gtk.ToggleButton button) {
+ App.app.search_mode = button.get_active();
+ }
+
+ private void on_app_search_mode_changed (bool search_enabled) {
+ collection_search_btn.toggled.disconnect (on_search_btn_toggled);
+ collection_search_btn.set_active (search_enabled);
+ collection_search_btn.toggled.connect (on_search_btn_toggled);
+
+ selection_search_btn.toggled.disconnect (on_search_btn_toggled);
+ selection_search_btn.set_active (search_enabled);
+ selection_search_btn.toggled.connect (on_search_btn_toggled);
+
+ playlist_search_btn.toggled.disconnect (on_search_btn_toggled);
+ playlist_search_btn.set_active (search_enabled);
+ playlist_search_btn.toggled.connect (on_search_btn_toggled);
+ }
+
private void update_collection_select_btn_sensitivity () {
// collection_select_btn.sensitive = App.app.collection.items.length != 0;
}
diff --git a/src/org.gnome.Music.gschema.xml.in b/src/org.gnome.Music.gschema.xml.in
index e88731e..817181e 100644
--- a/src/org.gnome.Music.gschema.xml.in
+++ b/src/org.gnome.Music.gschema.xml.in
@@ -21,5 +21,10 @@
<_summary>Shuffle playback</_summary>
<_description>If true, do randomized playback through the collection</_description>
</key>
+ <key name="search" type="b">
+ <default>false</default>
+ <_summary>Search mode</_summary>
+ <_description>If true, the search bar is shown</_description>
+ </key>
</schema>
</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]