Merge lp:~rodrigo-moya/libubuntuone/bring-music-store-live into lp:libubuntuone

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/libubuntuone/bring-music-store-live
Merge into: lp:libubuntuone
Diff against target: 288 lines (+149/-13)
7 files modified
configure.ac (+3/-8)
libubuntuone/Makefile.am (+12/-0)
libubuntuone/u1-contacts-picker.c (+2/-2)
libubuntuone/u1-marshal.list (+2/-0)
libubuntuone/u1-music-store.c (+111/-3)
libubuntuone/u1-music-store.h (+3/-0)
tests/test-music-store.c (+16/-0)
To merge this branch: bzr merge lp:~rodrigo-moya/libubuntuone/bring-music-store-live
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Review via email: mp+16426@code.launchpad.net

Commit message

Use now live music store as default location and add signal for previewing MP3

To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Use now live music store as default location and add signal for previewing MP3

7. By Rodrigo Moya

Capture preview-mp3 signal in test program

Revision history for this message
Elliot Murphy (statik) wrote :

/usr/include/gtk-2.0/gtk/gtkcontainer.h:111: note: expected ‘struct GtkContainer *’ but argument is of type ‘struct GtkScrolledWindow *’

code looks pretty good! I get this compile error.

review: Needs Fixing
8. By Rodrigo Moya

Kill some warnings

Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Fixed that warning and pushed again, so please try again

Revision history for this message
Elliot Murphy (statik) wrote :

I have to manually cd into libubuntuone and 'make u1-marshal.h' before it will compile for me, but otherwise looks good.

review: Approve
9. By Rodrigo Moya

Killed another warning

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2009-12-04 13:22:36 +0000
3+++ configure.ac 2010-01-04 14:29:12 +0000
4@@ -15,6 +15,9 @@
5 AC_PROG_CC
6 AC_PROG_LIBTOOL
7
8+dnl glib-genmarshal
9+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
10+
11 dnl Look for needed modules
12 PKG_CHECK_MODULES(LIBUBUNTUONE, webkit-1.0 libebook-1.2)
13 AC_SUBST(LIBUBUNTUONE_CFLAGS)
14@@ -27,14 +30,6 @@
15 AC_SUBST(LIBUBUNTUONE_REVISION)
16 AC_SUBST(LIBUBUNTUONE_AGE)
17
18-dnl Argument for specifying the URL of the music store
19-AC_MSG_CHECKING([store URL to use])
20-AC_ARG_WITH([store-url],
21- AS_HELP_STRING([--with-store-url=url], [URL to use for the music store]),
22- [with_store_url=$withval], [with_store_url="http://www.google.com"])
23-AC_MSG_RESULT([$with_store_url])
24-AC_DEFINE_UNQUOTED(U1_STORE_URL, ["$with_store_url"], [Define to the URL to use for the store])
25-
26 ##################################################
27 # Check for gtk-doc.
28 ##################################################
29
30=== modified file 'libubuntuone/Makefile.am'
31--- libubuntuone/Makefile.am 2009-12-04 20:23:57 +0000
32+++ libubuntuone/Makefile.am 2010-01-04 14:29:12 +0000
33@@ -3,7 +3,17 @@
34
35 lib_LTLIBRARIES = libubuntuone.la
36
37+# Marshallers
38+MARSHAL_GENERATED = u1-marshal.c u1-marshal.h
39+
40+u1-marshal.h: u1-marshal.list $(GLIB_GENMARSHAL)
41+ $(GLIB_GENMARSHAL) $< --header --prefix=_u1_marshal > $@
42+
43+u1-marshal.c: u1-marshal.list $(GLIB_GENMARSHAL)
44+ $(GLIB_GENMARSHAL) $< --body --prefix=_u1_marshal > $@
45+
46 libubuntuone_la_SOURCES = \
47+ $(MARSHAL_GENERATED) \
48 contacts-picker-model.c \
49 contacts-picker-model.h \
50 u1-contacts-picker.c \
51@@ -13,3 +23,5 @@
52 u1include_HEADERS = \
53 u1-contacts-picker.h \
54 u1-music-store.h
55+
56+EXTRA_DIST = u1-marshal.list
57\ No newline at end of file
58
59=== modified file 'libubuntuone/u1-contacts-picker.c'
60--- libubuntuone/u1-contacts-picker.c 2009-12-09 13:25:49 +0000
61+++ libubuntuone/u1-contacts-picker.c 2010-01-04 14:29:12 +0000
62@@ -80,7 +80,7 @@
63 {
64 U1ContactsPicker *picker = (U1ContactsPicker *) data;
65
66- contacts_picker_model_search (gtk_icon_view_get_model (picker->priv->icon_view), gtk_entry_get_text (entry));
67+ contacts_picker_model_search (gtk_icon_view_get_model (GTK_ICON_VIEW (picker->priv->icon_view)), gtk_entry_get_text (entry));
68 }
69
70 static void
71@@ -123,7 +123,7 @@
72 model = contacts_picker_model_new ();
73 g_signal_connect (G_OBJECT (model), "row_inserted", G_CALLBACK (model_contact_added_cb), picker);
74 g_signal_connect (G_OBJECT (model), "row_deleted", G_CALLBACK (model_contact_removed_cb), picker);
75- gtk_icon_view_set_model (picker->priv->icon_view, model);
76+ gtk_icon_view_set_model (GTK_ICON_VIEW (picker->priv->icon_view), model);
77
78 gtk_widget_show (picker->priv->icon_view);
79 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), picker->priv->icon_view);
80
81=== added file 'libubuntuone/u1-marshal.list'
82--- libubuntuone/u1-marshal.list 1970-01-01 00:00:00 +0000
83+++ libubuntuone/u1-marshal.list 2010-01-04 14:29:12 +0000
84@@ -0,0 +1,2 @@
85+NONE:STRING,OBJECT
86+NONE:STRING,STRING
87
88=== modified file 'libubuntuone/u1-music-store.c'
89--- libubuntuone/u1-music-store.c 2009-11-26 12:12:21 +0000
90+++ libubuntuone/u1-music-store.c 2010-01-04 14:29:12 +0000
91@@ -19,16 +19,43 @@
92 * Boston, MA 02110-1301, USA.
93 */
94
95-#include "config.h"
96 #include <webkit/webkit.h>
97 #include "u1-music-store.h"
98+#include "u1-marshal.h"
99+
100+#define U1_STORE_URL "http://www.7digital.com/stores/default.aspx?shop=34&partner=982"
101+#define U1_PREVIEW_JAVASCRIPT "" \
102+ "(function() {" \
103+ " // capture the preview" \
104+ " if (playTrack) {" \
105+ " playTrack = function(file, title) {" \
106+ " window.status = \"u1preview:::\" + file + \":::\" + title;" \
107+ " }" \
108+ " }" \
109+ " // and hide the flashplayer"\
110+ " var ply = document.getElementById(\"flashPlayer\");" \
111+ " if (ply) {" \
112+ " ply.parentNode.removeChild(ply);" \
113+ " }" \
114+ "})()"
115+#define U1_DEFAULT_ERROR_PAGE "<html><body>Could not load Music Store</body></html>"
116
117 struct _U1MusicStorePrivate {
118 GtkWidget *web_viewer;
119+
120+ GdkCursor *busy_cursor;
121+ GdkCursor *normal_cursor;
122 };
123
124 G_DEFINE_TYPE(U1MusicStore, u1_music_store, GTK_TYPE_VBOX)
125
126+enum {
127+ PREVIEW_MP3_SIGNAL,
128+ LAST_SIGNAL
129+};
130+
131+static guint u1_music_store_signals[LAST_SIGNAL] = { 0, };
132+
133 static void
134 u1_music_store_finalize (GObject *object)
135 {
136@@ -47,9 +74,82 @@
137 {
138 GObjectClass *object_class = G_OBJECT_CLASS (klass);
139
140+ /* Signals */
141+ u1_music_store_signals[PREVIEW_MP3_SIGNAL] = g_signal_new ("preview-mp3",
142+ G_TYPE_FROM_CLASS (klass),
143+ (GSignalFlags) G_SIGNAL_RUN_LAST,
144+ G_STRUCT_OFFSET (U1MusicStoreClass, preview_mp3),
145+ NULL,
146+ NULL,
147+ _u1_marshal_VOID__STRING_STRING,
148+ G_TYPE_NONE, 2,
149+ G_TYPE_STRING, G_TYPE_STRING);
150 object_class->finalize = u1_music_store_finalize;
151 }
152
153+static gboolean
154+navigation_requested_cb (WebKitWebView *web_view,
155+ WebKitWebFrame *frame,
156+ WebKitNetworkRequest *request,
157+ WebKitWebNavigationAction *navigation_action,
158+ WebKitWebPolicyDecision *policy_decision,
159+ gpointer user_data)
160+{
161+ U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
162+
163+ /* Change the cursor when loading */
164+ if (music_store->priv->normal_cursor)
165+ gdk_cursor_unref (music_store->priv->normal_cursor);
166+ music_store->priv->normal_cursor = gdk_window_get_cursor (GTK_WIDGET (web_view)->window);
167+ gdk_cursor_ref (music_store->priv->normal_cursor);
168+
169+ if (music_store->priv->busy_cursor == NULL)
170+ music_store->priv->busy_cursor = gdk_cursor_new_for_display (gdk_display_get_default (), GDK_WATCH);
171+
172+ gdk_window_set_cursor (GTK_WIDGET (web_view)->window, music_store->priv->busy_cursor);
173+
174+ /* Inform webkit to continue with the loading */
175+ webkit_web_policy_decision_use (policy_decision);
176+
177+ return TRUE;
178+}
179+
180+static void
181+load_finished_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data)
182+{
183+ U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
184+
185+ /* Inject some JavaScript to enable previews and hide the Flash player */
186+ webkit_web_view_execute_script (web_view, U1_PREVIEW_JAVASCRIPT);
187+ gdk_window_set_cursor (GTK_WIDGET (web_view)->window, music_store->priv->normal_cursor);
188+}
189+
190+static void
191+status_bar_text_changed_cb (WebKitWebView *web_view, const gchar *text, gpointer user_data)
192+{
193+ U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
194+
195+ if (g_str_has_prefix (text, "u1preview:::")) {
196+ gchar **args;
197+
198+ args = g_strsplit (text, ":::", 0);
199+ if (args != NULL) {
200+ g_signal_emit (music_store, u1_music_store_signals[PREVIEW_MP3_SIGNAL], 0, args[1], args[2]);
201+ g_strfreev (args);
202+ }
203+ }
204+}
205+
206+static gboolean
207+load_error_cb (WebKitWebView *web_view, WebKitWebFrame *frame, const gchar *uri, GError *error, gpointer user_data)
208+{
209+ U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
210+
211+ webkit_web_view_load_string (web_view, U1_DEFAULT_ERROR_PAGE, "text/html", "utf-8", "file:///");
212+
213+ return TRUE;
214+}
215+
216 static void
217 u1_music_store_init (U1MusicStore *music_store)
218 {
219@@ -65,9 +165,17 @@
220 gtk_widget_show (scroll);
221
222 music_store->priv->web_viewer = webkit_web_view_new ();
223+ g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "navigation-policy-decision-requested",
224+ G_CALLBACK (navigation_requested_cb), music_store);
225+ g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "load-finished",
226+ G_CALLBACK (load_finished_cb), music_store);
227+ g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "status-bar-text-changed",
228+ G_CALLBACK (status_bar_text_changed_cb), music_store);
229+ g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "load-error",
230+ G_CALLBACK (load_error_cb), music_store);
231+ gtk_widget_show (music_store->priv->web_viewer);
232+ gtk_container_add (GTK_CONTAINER (scroll), music_store->priv->web_viewer);
233 webkit_web_view_open (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), U1_STORE_URL);
234- gtk_widget_show (music_store->priv->web_viewer);
235- gtk_container_add (GTK_SCROLLED_WINDOW (scroll), music_store->priv->web_viewer);
236
237 gtk_box_pack_start (GTK_BOX (music_store), scroll, TRUE, TRUE, 3);
238 }
239
240=== modified file 'libubuntuone/u1-music-store.h'
241--- libubuntuone/u1-music-store.h 2009-12-04 13:22:36 +0000
242+++ libubuntuone/u1-music-store.h 2010-01-04 14:29:12 +0000
243@@ -42,6 +42,9 @@
244
245 typedef struct {
246 GtkVBoxClass parent_class;
247+
248+ /* Signals */
249+ void (* preview_mp3) (U1MusicStore *music_store, const gchar *url, const gchar *title);
250 } U1MusicStoreClass;
251
252 GType u1_music_store_get_type (void);
253
254=== modified file 'tests/test-music-store.c'
255--- tests/test-music-store.c 2009-11-26 12:12:21 +0000
256+++ tests/test-music-store.c 2010-01-04 14:29:12 +0000
257@@ -21,6 +21,20 @@
258
259 #include <libubuntuone/u1-music-store.h>
260
261+static void
262+preview_mp3_cb (U1MusicStore *music_store, const gchar *url, const gchar *title, gpointer user_data)
263+{
264+ GtkWidget *dialog;
265+
266+ dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (music_store))),
267+ 0,
268+ GTK_MESSAGE_INFO,
269+ GTK_BUTTONS_OK,
270+ "Requested preview of file %s with title %s", url, title);
271+ gtk_dialog_run (GTK_DIALOG (dialog));
272+ gtk_widget_destroy (dialog);
273+}
274+
275 int
276 main (int argc, char *argv[])
277 {
278@@ -31,9 +45,11 @@
279
280 /* Create the main window */
281 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
282+ gtk_widget_set_size_request (window, 839, 600);
283 g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
284
285 music_store = u1_music_store_new ();
286+ g_signal_connect (G_OBJECT (music_store), "preview-mp3", G_CALLBACK (preview_mp3_cb), NULL);
287 gtk_widget_show (music_store);
288 gtk_container_add (GTK_CONTAINER (window), music_store);
289

Subscribers

People subscribed via source and target branches