[Goodies-commits] r3949 - xfmpc/trunk/src
Mike Massonnet
mmassonnet at xfce.org
Fri Feb 15 03:35:28 CET 2008
Author: mmassonnet
Date: 2008-02-15 02:35:28 +0000 (Fri, 15 Feb 2008)
New Revision: 3949
Modified:
xfmpc/trunk/src/mpdclient.c
xfmpc/trunk/src/mpdclient.h
xfmpc/trunk/src/playlist.c
xfmpc/trunk/src/playlist.h
Log:
Display the current song in bold in the playlist
* src/mpdclient.c,
src/mpdclient.h:
- New function xfmpc_mpdclient_get_id that returns the current id
* src/playlist.c(xfmpc_playlist_init):
- Allow multiple selection in the treeview
- Add new column (IS_CURRENT) and bind it to the attribute weight of both
song and length cell renderers
- Connect to signal song-changed in addition to playlist-changed
* src/playlist.c(xfmpc_playlist_append),
src/playlist.h:
- New argument gboolean is_current to use within gtk_list_store_set
* src/playlist.c(cb_playlist_changed):
- Get the id of the current song
- Return a gboolean result to xfmpc_playlist_append
Modified: xfmpc/trunk/src/mpdclient.c
===================================================================
--- xfmpc/trunk/src/mpdclient.c 2008-02-11 17:50:30 UTC (rev 3948)
+++ xfmpc/trunk/src/mpdclient.c 2008-02-15 02:35:28 UTC (rev 3949)
@@ -371,6 +371,14 @@
return TRUE;
}
+gint
+xfmpc_mpdclient_get_id (XfmpcMpdclient *mpdclient)
+{
+ XfmpcMpdclientPrivate *priv = XFMPC_MPDCLIENT_GET_PRIVATE (mpdclient);
+
+ return mpd_player_get_current_song_id (priv->mi);
+}
+
const gchar *
xfmpc_mpdclient_get_artist (XfmpcMpdclient *mpdclient)
{
@@ -482,7 +490,7 @@
gboolean
xfmpc_mpdclient_playlist_read (XfmpcMpdclient *mpdclient,
- gint *pos,
+ gint *id,
gchar **song,
gchar **length)
{
@@ -507,7 +515,7 @@
*song = g_path_get_basename (data->song->file);
*length = g_strdup_printf ("%d:%02d", data->song->time / 60, data->song->time % 60);
- *pos = data->song->id;
+ *id = data->song->id;
}
return NULL != data;
Modified: xfmpc/trunk/src/mpdclient.h
===================================================================
--- xfmpc/trunk/src/mpdclient.h 2008-02-11 17:50:30 UTC (rev 3948)
+++ xfmpc/trunk/src/mpdclient.h 2008-02-15 02:35:28 UTC (rev 3949)
@@ -61,6 +61,8 @@
guint8 volume);
gboolean xfmpc_mpdclient_set_song_time (XfmpcMpdclient *mpdclient,
guint time);
+gint xfmpc_mpdclient_get_id (XfmpcMpdclient *mpdclient);
+
const gchar * xfmpc_mpdclient_get_artist (XfmpcMpdclient *mpdclient);
const gchar * xfmpc_mpdclient_get_title (XfmpcMpdclient *mpdclient);
@@ -82,7 +84,7 @@
void xfmpc_mpdclient_update_status (XfmpcMpdclient *mpdclient);
gboolean xfmpc_mpdclient_playlist_read (XfmpcMpdclient *mpdclient,
- gint *pos,
+ gint *id,
gchar **song,
gchar **length);
Modified: xfmpc/trunk/src/playlist.c
===================================================================
--- xfmpc/trunk/src/playlist.c 2008-02-11 17:50:30 UTC (rev 3948)
+++ xfmpc/trunk/src/playlist.c 2008-02-15 02:35:28 UTC (rev 3949)
@@ -49,6 +49,7 @@
COLUMN_POS,
COLUMN_SONG,
COLUMN_LENGTH,
+ COLUMN_IS_CURRENT,
N_COLUMNS,
};
@@ -131,10 +132,12 @@
priv->store = gtk_list_store_new (N_COLUMNS,
G_TYPE_INT,
G_TYPE_STRING,
- G_TYPE_STRING);
+ G_TYPE_STRING,
+ G_TYPE_INT);
/* Tree view */
priv->treeview = gtk_tree_view_new ();
+ gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)), GTK_SELECTION_MULTIPLE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->treeview), TRUE);
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), GTK_TREE_MODEL (priv->store));
@@ -145,9 +148,11 @@
g_object_set (G_OBJECT (cell),
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
- GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Song", cell,
- "text", COLUMN_SONG,
- NULL);
+ GtkTreeViewColumn *column =
+ gtk_tree_view_column_new_with_attributes ("Song", cell,
+ "text", COLUMN_SONG,
+ "weight", COLUMN_IS_CURRENT,
+ NULL);
g_object_set (G_OBJECT (column),
"expand", TRUE,
NULL);
@@ -155,10 +160,13 @@
/* Column "length" */
cell = gtk_cell_renderer_text_new ();
- g_object_set (G_OBJECT (cell), "xalign", 1.0, NULL);
+ g_object_set (G_OBJECT (cell),
+ "xalign", 1.0,
+ NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->treeview),
-1, "Length", cell,
"text", COLUMN_LENGTH,
+ "weight", COLUMN_IS_CURRENT,
NULL);
/* Scrolled window */
@@ -172,6 +180,8 @@
gtk_box_pack_start (GTK_BOX (playlist), scrolled, TRUE, TRUE, 0);
/* Signals */
+ g_signal_connect_swapped (playlist->mpdclient, "song-changed",
+ G_CALLBACK (cb_playlist_changed), playlist);
g_signal_connect_swapped (playlist->mpdclient, "playlist-changed",
G_CALLBACK (cb_playlist_changed), playlist);
}
@@ -200,18 +210,20 @@
void
xfmpc_playlist_append (XfmpcPlaylist *playlist,
- gint pos,
+ gint id,
gchar *song,
- gchar *length)
+ gchar *length,
+ gboolean is_current)
{
XfmpcPlaylistPrivate *priv = XFMPC_PLAYLIST_GET_PRIVATE (playlist);
- GtkTreeIter iter;
+ GtkTreeIter iter;
gtk_list_store_append (priv->store, &iter);
gtk_list_store_set (priv->store, &iter,
- COLUMN_POS, pos,
+ COLUMN_POS, id,
COLUMN_SONG, song,
COLUMN_LENGTH, length,
+ COLUMN_IS_CURRENT, is_current ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
-1);
}
@@ -228,12 +240,15 @@
{
gchar *song;
gchar *length;
- gint pos;
+ gint id;
+ gint current;
+ current = xfmpc_mpdclient_get_id (playlist->mpdclient);
+
xfmpc_playlist_clear (playlist);
- while (xfmpc_mpdclient_playlist_read (playlist->mpdclient, &pos, &song, &length))
+ while (xfmpc_mpdclient_playlist_read (playlist->mpdclient, &id, &song, &length))
{
- xfmpc_playlist_append (playlist, pos, song, length);
+ xfmpc_playlist_append (playlist, id, song, length, current == id);
g_free (song);
g_free (length);
}
Modified: xfmpc/trunk/src/playlist.h
===================================================================
--- xfmpc/trunk/src/playlist.h 2008-02-11 17:50:30 UTC (rev 3948)
+++ xfmpc/trunk/src/playlist.h 2008-02-15 02:35:28 UTC (rev 3949)
@@ -40,9 +40,10 @@
GtkWidget * xfmpc_playlist_new ();
void xfmpc_playlist_append (XfmpcPlaylist *playlist,
- gint pos,
+ gint id,
gchar *song,
- gchar *length);
+ gchar *length,
+ gboolean is_current);
void xfmpc_playlist_clear (XfmpcPlaylist *playlist);
G_END_DECLS
More information about the Goodies-commits
mailing list