[xiph-commits] r11082 - trunk/maemo/OggPlay/src

mgrimme at svn.xiph.org mgrimme at svn.xiph.org
Sun Apr 2 09:30:03 PDT 2006


Author: mgrimme
Date: 2006-04-02 09:29:59 -0700 (Sun, 02 Apr 2006)
New Revision: 11082

Added:
   trunk/maemo/OggPlay/src/playlist.c
   trunk/maemo/OggPlay/src/playlist.h
   trunk/maemo/OggPlay/src/playlistwidget.c
   trunk/maemo/OggPlay/src/playlistwidget.h
Log:
new files

Added: trunk/maemo/OggPlay/src/playlist.c
===================================================================
--- trunk/maemo/OggPlay/src/playlist.c	2006-04-02 16:29:16 UTC (rev 11081)
+++ trunk/maemo/OggPlay/src/playlist.c	2006-04-02 16:29:59 UTC (rev 11082)
@@ -0,0 +1,128 @@
+/*
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+#include "playlist.h"
+
+
+/*
+ * Creates and returns a new playlist object.
+ */
+Playlist *
+playlist_new() {
+
+  Playlist *pl;
+
+  pl = g_new(Playlist, 1);
+  pl->list = g_ptr_array_new();
+  pl->position = 0;
+
+  return pl;
+
+}
+
+
+void
+playlist_free(Playlist *pl) {
+
+  g_free(pl->list);
+  g_free(pl);
+
+}
+
+
+void
+playlist_clear(Playlist *pl) {
+
+  // TODO: IMPLEMENT
+
+}
+
+
+void
+playlist_append(Playlist *pl,
+		const char *uri) {
+
+  g_ptr_array_add(pl->list, g_strdup(uri));
+  (pl->change_cb)(pl->change_cb_data);
+
+}
+
+
+void
+playlist_previous(Playlist *pl) {
+
+  char *uri;
+
+  if (pl->list->len == 0) return;
+
+  pl->position = MAX(0, pl->position - 1);  
+  uri = g_ptr_array_index(pl->list, pl->position);
+  (pl->play_cb)(pl->play_cb_data, uri);
+
+}
+
+
+void
+playlist_next(Playlist *pl) {
+
+  char *uri;
+  
+  if (pl->list->len == 0) return;
+
+  pl->position = MIN(pl->list->len - 1, pl->position + 1);
+  uri = g_ptr_array_index(pl->list, pl->position);
+  (pl->play_cb)(pl->play_cb_data, uri);
+
+}
+
+
+void
+playlist_jump_to(Playlist *pl,
+		 int index) {
+
+  char *uri;
+
+  if (index < pl->list->len) {
+    pl->position = index;
+    uri = g_ptr_array_index(pl->list, pl->position);
+    (pl->play_cb)(pl->play_cb_data, uri);
+  }
+    
+}
+
+
+void
+playlist_set_play_cb(Playlist *pl,
+		     PLAY_CB,
+		     void *userdata) {
+
+  pl->play_cb = play_cb;
+  pl->play_cb_data = userdata;
+
+}
+
+
+void
+playlist_set_change_cb(Playlist *pl,
+		       CHANGE_CB,
+		       void *userdata) {
+  
+  pl->change_cb = change_cb;
+  pl->change_cb_data = userdata;
+
+}

Added: trunk/maemo/OggPlay/src/playlist.h
===================================================================
--- trunk/maemo/OggPlay/src/playlist.h	2006-04-02 16:29:16 UTC (rev 11081)
+++ trunk/maemo/OggPlay/src/playlist.h	2006-04-02 16:29:59 UTC (rev 11082)
@@ -0,0 +1,57 @@
+/*
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+#ifndef PLAYLIST_H
+#define PLAYLIST_H
+
+#include <glib.h>
+
+
+#define PLAY_CB    void (*play_cb)    (void *userdata, const char *uri)
+#define CHANGE_CB    void (*change_cb)    (void *userdata)
+
+
+struct _Playlist {
+
+  PLAY_CB;
+  void *play_cb_data;
+
+  CHANGE_CB;
+  void *change_cb_data;
+
+
+  GPtrArray *list;
+  int position;
+
+};
+typedef struct _Playlist Playlist;
+
+
+
+Playlist *playlist_new();
+void playlist_free(Playlist *pl);
+void playlist_clear(Playlist *pl);
+void playlist_append(Playlist *pl, const char *uri);
+void playlist_previous(Playlist *pl);
+void playlist_next(Playlist *pl);
+void playlist_jump_to(Playlist *pl, int index);
+
+void playlist_set_play_cb(Playlist *pl, PLAY_CB, void *userdata);
+void playlist_set_change_cb(Playlist *pl, CHANGE_CB, void *userdata);
+
+#endif

Added: trunk/maemo/OggPlay/src/playlistwidget.c
===================================================================
--- trunk/maemo/OggPlay/src/playlistwidget.c	2006-04-02 16:29:16 UTC (rev 11081)
+++ trunk/maemo/OggPlay/src/playlistwidget.c	2006-04-02 16:29:59 UTC (rev 11082)
@@ -0,0 +1,132 @@
+/*
+ *    Playlist widget
+ *    Copyright (c) 2005, 2006 Martin Grimme  <martin.grimme at lintegra.de>
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "playlistwidget.h"
+
+
+static gboolean
+doubleclick_cb(GtkWidget *src,
+	       GdkEventMotion *event,
+	       PLWidget *plw) {
+
+  GtkTreeSelection *selection;
+  GList *rows;
+  gint *indices;
+
+  if (event->type == GDK_2BUTTON_PRESS) {
+
+    selection = gtk_tree_view_get_selection(plw->treeview);
+    rows = gtk_tree_selection_get_selected_rows(selection, NULL);
+    indices = gtk_tree_path_get_indices(rows->data);
+    if (indices) {
+      playlist_jump_to(plw->playlist, indices[0]);
+    }
+    
+    g_list_foreach(rows, gtk_tree_path_free, NULL);
+    g_list_free(rows);
+
+  }
+
+  return FALSE;
+
+}
+
+
+static void
+change_cb(PLWidget *plw) {
+
+  GPtrArray *list = plw->playlist->list;
+  GtkTreeIter iter;
+  char *item;
+  int i;
+  
+  gtk_list_store_clear(plw->liststore);
+
+  /* did I mention that the API sucks..? ;) */
+  for (i = 0; i < list->len; i++) {
+
+    item = g_path_get_basename(g_ptr_array_index(list, i));
+    gtk_list_store_append(plw->liststore, &iter);
+    gtk_list_store_set(plw->liststore, &iter, 1, item, -1);
+    g_free(item);
+
+  }
+
+}
+
+
+
+PLWidget *
+plwidget_new() {
+
+  /* the API for list widgets in GTK totally sucks... */
+  GtkTreeViewColumn *col1;
+  GtkTreeViewColumn *col2;
+  GtkCellRenderer *crender1;
+  GtkCellRenderer *crender2;
+  GtkTreeIter iter;
+  GValue fontsize = {0,};
+
+  PLWidget *plw = g_new(PLWidget, 1);
+
+  plw->liststore = gtk_list_store_new(2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
+  plw->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(plw->liststore));
+
+  /* column 1: image */
+  crender1 = gtk_cell_renderer_pixbuf_new();
+  col1 = gtk_tree_view_column_new_with_attributes("", crender1, "pixbuf", 0,
+						  NULL);
+  gtk_tree_view_append_column(plw->treeview, col1);
+
+  /* column 2: song name */
+  crender2 = gtk_cell_renderer_text_new();
+  g_value_init(&fontsize, G_TYPE_DOUBLE);
+  g_value_set_double(&fontsize, 14.0);
+  g_object_set_property(G_OBJECT(crender2), "size-points", &fontsize);
+  col2 = gtk_tree_view_column_new_with_attributes("", crender2, "text", 1, 
+						  NULL);
+  gtk_tree_view_append_column(plw->treeview, col2);
+
+  /* handle double clicks */
+  g_signal_connect(G_OBJECT(plw->treeview), "button-press-event",
+		   G_CALLBACK(doubleclick_cb), plw);
+
+  return plw;
+
+}
+
+
+
+GtkWidget *
+plwidget_get_widget(PLWidget *plw) {
+
+  return plw->treeview;
+
+}
+
+
+void
+plwidget_set_playlist(PLWidget *plw,
+		      Playlist *pl) {
+
+  plw->playlist = pl;
+  playlist_set_change_cb(pl, change_cb, (void *) plw);
+
+}

Added: trunk/maemo/OggPlay/src/playlistwidget.h
===================================================================
--- trunk/maemo/OggPlay/src/playlistwidget.h	2006-04-02 16:29:16 UTC (rev 11081)
+++ trunk/maemo/OggPlay/src/playlistwidget.h	2006-04-02 16:29:59 UTC (rev 11082)
@@ -0,0 +1,53 @@
+/*
+ *    Playlist widget
+ *    Copyright (c) 2005, 2006 Martin Grimme  <martin.grimme at lintegra.de>
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+#ifndef PLAYLISTWIDGET_H
+#define PLAYLISTWIDGET_H
+
+#include <gtk/gtk.h>
+#include <glib.h>
+#include "playlist.h"
+
+/* callback handlers */
+//#define OPEN_CB    void (*open_cb)    (void *userdata, GSList *filenames)
+//#define SEEK_CB    void (*seek_cb)    (void *userdata, int seconds)
+//#define VOLUME_CB  void (*volume_cb)  (void *userdata, int volume)
+//#define CONTROL_CB void (*control_cb) (void *userdata, int command)
+
+//enum Command { PLAY, STOP, PREVIOUS, NEXT };
+
+
+struct _PLWidget {
+
+  GtkListStore *liststore;
+  GtkWidget *treeview;
+
+  Playlist *playlist;
+
+};
+typedef struct _PLWidget PLWidget;
+
+
+PLWidget *plwidget_new();
+GtkWidget *plwidget_get_widget(PLWidget *plw);
+void plwidget_set_playlist(PLWidget *plw, Playlist *pl);
+
+#endif



More information about the commits mailing list