116
118
g_cclosure_marshal_VOID__STRING,
121
u1_music_store_signals[URL_LOADED_SIGNAL] = g_signal_new ("url-loaded",
122
G_TYPE_FROM_CLASS (klass),
123
(GSignalFlags) G_SIGNAL_RUN_LAST,
124
G_STRUCT_OFFSET (U1MusicStoreClass, url_loaded),
127
g_cclosure_marshal_VOID__STRING,
130
u1_music_store_signals[DOWNLOAD_FINISHED_SIGNAL] = g_signal_new ("download-finished",
131
G_TYPE_FROM_CLASS (klass),
132
(GSignalFlags) G_SIGNAL_RUN_LAST,
133
G_STRUCT_OFFSET (U1MusicStoreClass, download_finished),
136
g_cclosure_marshal_VOID__STRING,
119
140
object_class->finalize = u1_music_store_finalize;
185
206
gchar **uri_parts;
186
207
NotRegisteredReplacementData *nrrd = (NotRegisteredReplacementData *) user_data;
188
g_debug ("got_new_credentials called");
190
209
get_credentials_from_keyring (&oauth_token, &oauth_token_secret);
192
211
/* Get the return_url parameter from the not-registered url */
272
289
U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
274
g_debug ("Loading URL: %s", webkit_network_request_get_uri (request));
276
291
/* Remove watching callback for the page */
277
292
if (music_store->priv->watch_id != 0) {
278
293
g_source_remove (music_store->priv->watch_id);
389
parse_html_node (WebKitWebView *web_view, htmlNodePtr node, GHashTable *current_downloads)
404
add_watched_downloads_from_hash (gpointer key, gpointer value, gpointer user_data)
406
GHashTable *watched_downloads = (GHashTable *) user_data;
408
g_hash_table_insert (watched_downloads, g_strdup (key), g_strdup (key));
412
parse_html_node (U1MusicStore *music_store, WebKitWebView *web_view, htmlNodePtr node, GHashTable *current_downloads)
391
414
htmlNodePtr subnode;
415
static GHashTable *watched_downloads = NULL;
393
417
if (node == NULL)
420
/* We add all tracked downloads to know which ones were started from us */
421
if (watched_downloads == NULL)
422
watched_downloads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
424
g_hash_table_foreach (current_downloads, (GHFunc) add_watched_downloads_from_hash, watched_downloads);
396
426
for (subnode = node->children; subnode != NULL; subnode = subnode->next) {
397
427
if (!g_strcmp0 ((const gchar *) subnode->name, "li")) {
414
444
escaped_prop = g_string_append_c (escaped_prop, prop[i]);
417
g_debug ("Escaped prop = %s", escaped_prop->str);
419
447
full_path = g_build_filename (g_get_home_dir (),
420
448
".ubuntuone/Purchased from Ubuntu One",
422
g_debug ("Full path = %s", full_path);
424
451
download = g_hash_table_lookup (current_downloads, full_path);
425
452
if (download != NULL) {
432
459
script = g_strdup_printf ("setProgressBar('%s', %.2f, '%ld of %ld bytes read');",
433
460
escaped_prop->str, percent, download->n_bytes_read, download->deflated_size);
462
g_signal_emit (music_store, u1_music_store_signals[DOWNLOAD_FINISHED_SIGNAL], 0,
463
(const gchar *) full_path);
435
465
/* If the file exists, the download is done */
436
if (g_file_test (full_path, G_FILE_TEST_EXISTS))
437
script = g_strdup_printf ("setProgressBar('%s', 1.0, 'Completed', false);", escaped_prop->str);
466
if (g_file_test (full_path, G_FILE_TEST_EXISTS)) {
467
if (g_hash_table_lookup (watched_downloads, (gconstpointer) full_path)) {
468
script = g_strdup_printf ("setProgressBar('%s', 1.0, 'Completed', false);", escaped_prop->str);
469
g_signal_emit (music_store, u1_music_store_signals[DOWNLOAD_FINISHED_SIGNAL], 0,
470
(const gchar *) full_path);
472
/* Remove the file from the watched downloads */
473
g_hash_table_remove (watched_downloads, (gconstpointer) full_path);
475
script = g_strdup_printf ("setProgressBar('%s', 1.0, 'Completed', true);", escaped_prop->str);
439
477
script = g_strdup_printf ("setProgressBar('%s', 0.0, 'Transferring to your Ubuntu One storage');", escaped_prop->str);
445
483
g_free (full_path);
446
484
g_string_free (escaped_prop, TRUE);
448
parse_html_node (web_view, subnode, current_downloads);
486
parse_html_node (music_store, web_view, subnode, current_downloads);
453
update_status_in_library_page (WebKitWebView *web_view, WebKitWebFrame *frame)
491
update_status_in_library_page (U1MusicStore *music_store, WebKitWebView *web_view, WebKitWebFrame *frame)
456
494
WebKitWebDataSource *data_source;
469
507
html_doc = htmlParseDoc (html->str, NULL);
470
508
root_node = xmlDocGetRootElement (html_doc);
471
parse_html_node (web_view, root_node, current_downloads);
509
parse_html_node (music_store, web_view, root_node, current_downloads);
473
511
/* Free memory */
474
512
xmlFreeDoc (html_doc);
482
520
U1MusicStore *music_store = U1_MUSIC_STORE (user_data);
484
update_status_in_library_page (WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
522
update_status_in_library_page (music_store,
523
WEBKIT_WEB_VIEW (music_store->priv->web_viewer),
485
524
music_store->priv->frame_to_use);
517
557
tmp_url = g_strdup_printf ("%s%s", music_store->priv->base_url, U1_LIBRARY_URL);
518
558
if (g_str_has_prefix (webkit_web_view_get_uri (web_view), tmp_url)) {
519
559
music_store->priv->frame_to_use = frame;
520
update_status_in_library_page (web_view, frame);
560
update_status_in_library_page (music_store, web_view, frame);
522
562
/* Inject JavaScript to make songs clickable */
523
563
execute_script (web_view, "u1-songs-clickable.js", NULL);
529
569
g_free (tmp_url);
571
/* Signal users the URL finished loading */
572
g_signal_emit (music_store, u1_music_store_signals[URL_LOADED_SIGNAL], 0,
573
(const gchar *) webkit_web_view_get_uri (music_store->priv->web_viewer));
664
711
new_user_agent = g_strdup_printf ("%s U1MusicStore/" VERSION ,
665
712
webkit_web_settings_get_user_agent (
666
713
webkit_web_view_get_settings (WEBKIT_WEB_VIEW (music_store->priv->web_viewer))));
667
g_debug (new_user_agent);
669
715
g_object_set (G_OBJECT (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (music_store->priv->web_viewer))),
670
716
"user-agent", new_user_agent,