=== modified file 'libubuntuone/u1-music-store.c' --- libubuntuone/u1-music-store.c 2010-03-11 13:06:15 +0000 +++ libubuntuone/u1-music-store.c 2010-03-12 16:18:18 +0000 @@ -37,6 +37,7 @@ #define U1_NOT_LOGGED_IN_STORE_URL "/music/store-no-token" #define U1_NOT_REGISTERED_URL "https://one.ubuntu.com/music/notregistered?returnUrl=" +#define U1_INITIAL_PAGE "Loading Ubuntu One music store" #define U1_DEFAULT_ERROR_PAGE "Could not load Music Store" #define U1_IN_DEVELOPMENT_PAGE "The music store is under development, please be patient" #define U1_CONNECTING_PAGE "Connecting to Ubuntu One. Please wait..." @@ -45,6 +46,8 @@ DBusGConnection *bus; gchar *base_url; + GtkWidget *scroll; + GtkWidget *initial_web_viewer; GtkWidget *web_viewer; WebKitWebFrame *frame_to_use; @@ -573,6 +576,18 @@ gchar *tmp_url; U1MusicStore *music_store = U1_MUSIC_STORE (user_data); + /* Remove the initial view if still around */ + if (music_store->priv->initial_web_viewer != NULL) { + gtk_widget_destroy (music_store->priv->initial_web_viewer); + music_store->priv->initial_web_viewer = NULL; + + /* And show the real store viewer */ + g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "navigation-policy-decision-requested", + G_CALLBACK (navigation_requested_cb), music_store); + gtk_widget_show (music_store->priv->web_viewer); + gtk_container_add (GTK_CONTAINER (music_store->priv->scroll), music_store->priv->web_viewer); + } + /* Inject some JavaScript to enable previews and hide the Flash player */ execute_script (web_view, "u1-preview.js", NULL); @@ -601,7 +616,7 @@ /* Signal users the URL finished loading */ g_signal_emit (music_store, u1_music_store_signals[URL_LOADED_SIGNAL], 0, - (const gchar *) webkit_web_view_get_uri (music_store->priv->web_viewer)); + (const gchar *) webkit_web_view_get_uri (WEBKIT_WEB_VIEW (music_store->priv->web_viewer))); } static void @@ -694,11 +709,27 @@ return real_url; } +static gboolean +load_real_store_cb (gpointer user_data) +{ + gchar *real_url; + U1MusicStore *music_store = U1_MUSIC_STORE (user_data); + + g_debug ("Loading the real store page"); + real_url = get_url_to_use (music_store); + if (real_url != NULL) { + webkit_web_view_open (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), real_url); + + /* Free memory */ + g_free (real_url); + } + + return FALSE; +} + static void u1_music_store_init (U1MusicStore *music_store) { - GtkWidget *scroll; - gchar *real_url; gchar *new_user_agent; GError *error = NULL; @@ -732,11 +763,11 @@ syncdaemon_init (); /* Create web viewer object */ - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), + music_store->priv->scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (music_store->priv->scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_widget_show (scroll); + gtk_widget_show (music_store->priv->scroll); music_store->priv->web_viewer = webkit_web_view_new (); @@ -751,27 +782,28 @@ g_free(new_user_agent); - g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "navigation-policy-decision-requested", - G_CALLBACK (navigation_requested_cb), music_store); g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "load-finished", G_CALLBACK (load_finished_cb), music_store); g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "status-bar-text-changed", G_CALLBACK (status_bar_text_changed_cb), music_store); g_signal_connect (G_OBJECT (music_store->priv->web_viewer), "load-error", G_CALLBACK (load_error_cb), music_store); - gtk_widget_show (music_store->priv->web_viewer); - gtk_container_add (GTK_CONTAINER (scroll), music_store->priv->web_viewer); - - - real_url = get_url_to_use (music_store); - if (real_url != NULL) { - webkit_web_view_open (WEBKIT_WEB_VIEW (music_store->priv->web_viewer), real_url); - - /* Free memory */ - g_free (real_url); - } - - gtk_box_pack_start (GTK_BOX (music_store), scroll, TRUE, TRUE, 3); + + /* Show a temp view when loading the initial store page */ + music_store->priv->initial_web_viewer = webkit_web_view_new (); + g_object_set (G_OBJECT (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (music_store->priv->initial_web_viewer))), + "enable-default-context-menu", g_getenv ("U1SHOWCONTEXTMENU") != NULL, + NULL); + webkit_web_view_load_string (WEBKIT_WEB_VIEW (music_store->priv->initial_web_viewer), + U1_INITIAL_PAGE, + "text/html", "utf-8", "file:///"); + gtk_widget_show (music_store->priv->initial_web_viewer); + gtk_container_add (GTK_CONTAINER (music_store->priv->scroll), music_store->priv->initial_web_viewer); + + /* And load the real store in the background */ + g_idle_add ((GSourceFunc) load_real_store_cb, music_store); + + gtk_box_pack_start (GTK_BOX (music_store), music_store->priv->scroll, TRUE, TRUE, 3); } /**