Commit dd6a86d9 authored by Jonathan Matthew's avatar Jonathan Matthew

podcast: remove uses of gtk_dialog_run

parent 7d832705
......@@ -194,14 +194,29 @@ feed_updates_available_cb (RBPodcastManager *pd,
}
static gboolean
static void
error_dialog_response_cb (GtkDialog *dialog, int response, RBPodcastMainSource *source)
{
const char *url = g_object_get_data (G_OBJECT (dialog), "feed-url");
if (response == GTK_RESPONSE_YES) {
RBPodcastManager *pd;
g_object_get (source, "podcast-manager", &pd, NULL);
rb_podcast_manager_insert_feed_url (pd, url);
g_object_unref (pd);
}
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
feed_error_cb (RBPodcastManager *pd,
const char *url,
const char *error,
gboolean existing,
RBPodcastMainSource *source)
{
GtkWidget *dialog;
int result;
/* if the podcast feed doesn't already exist in the db,
* ask if the user wants to add it anyway; if it already
......@@ -224,13 +239,10 @@ feed_error_cb (RBPodcastManager *pd,
gtk_window_set_title (GTK_WINDOW (dialog), "");
gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_object_set_data_full (G_OBJECT (dialog), "feed-url", g_strdup (url), g_free);
g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_response_cb), source);
/* in the existing feed case, the response will be _OK or _NONE.
* we want to return FALSE here in this case, so this check works.
*/
return (result == GTK_RESPONSE_YES);
gtk_widget_show_all (dialog);
}
static void
......
......@@ -154,7 +154,7 @@ static void rb_podcast_manager_db_entry_added_cb (RBPodcastManager *pd,
RhythmDBEntry *entry);
static gboolean rb_podcast_manager_next_file (RBPodcastManager * pd);
static void rb_podcast_manager_insert_feed (RBPodcastManager *pd, RBPodcastChannel *data);
static gboolean rb_podcast_manager_handle_feed_error (RBPodcastManager *mgr,
static void rb_podcast_manager_handle_feed_error (RBPodcastManager *mgr,
const char *url,
GError *error,
gboolean emit);
......@@ -244,9 +244,10 @@ rb_podcast_manager_class_init (RBPodcastManagerClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (RBPodcastManagerClass, process_error),
NULL, NULL,
rb_marshal_BOOLEAN__STRING_BOOLEAN,
G_TYPE_BOOLEAN,
2,
NULL,
G_TYPE_NONE,
3,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
......@@ -1077,8 +1078,6 @@ rb_podcast_manager_free_parse_result (RBPodcastManagerParseResult *result)
static gboolean
rb_podcast_manager_parse_complete_cb (RBPodcastManagerParseResult *result)
{
gboolean add_feed = TRUE;
GDK_THREADS_ENTER ();
if (result->pd->priv->shutdown) {
GDK_THREADS_LEAVE ();
......@@ -1086,15 +1085,11 @@ rb_podcast_manager_parse_complete_cb (RBPodcastManagerParseResult *result)
}
if (result->error) {
if (rb_podcast_manager_handle_feed_error (result->pd,
(char *)result->channel->url,
result->error,
result->automatic == FALSE) == FALSE) {
add_feed = FALSE;
}
}
if (add_feed) {
rb_podcast_manager_handle_feed_error (result->pd,
(char *)result->channel->url,
result->error,
(result->automatic == FALSE));
} else {
rb_podcast_manager_insert_feed (result->pd, result->channel);
}
......@@ -1102,11 +1097,25 @@ rb_podcast_manager_parse_complete_cb (RBPodcastManagerParseResult *result)
return FALSE;
}
static gboolean
confirm_bad_mime_type (const char *url)
static void
confirm_bad_mime_type_response_cb (GtkDialog *dialog, int response, RBPodcastThreadInfo *info)
{
if (response == GTK_RESPONSE_YES) {
/* set the 'existing feed' flag to avoid the mime type check */
info->existing_feed = TRUE;
rb_podcast_manager_thread_parse_feed (info);
} else {
g_free (info->url);
g_free (info);
}
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
confirm_bad_mime_type (RBPodcastThreadInfo *info)
{
GtkWidget *dialog;
gboolean result = FALSE;
GDK_THREADS_ENTER ();
dialog = gtk_message_dialog_new (NULL, 0,
......@@ -1115,23 +1124,16 @@ confirm_bad_mime_type (const char *url)
_("The URL '%s' does not appear to be a podcast feed. "
"It may be the wrong URL, or the feed may be broken. "
"Would you like Rhythmbox to attempt to use it anyway?"),
url);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) {
result = TRUE;
}
gtk_widget_destroy (dialog);
info->url);
gtk_widget_show_all (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (confirm_bad_mime_type_response_cb), info);
GDK_THREADS_LEAVE ();
return result;
}
static gpointer
rb_podcast_manager_thread_parse_feed (RBPodcastThreadInfo *info)
{
RBPodcastChannel *feed = g_new0 (RBPodcastChannel, 1);
gboolean retry = FALSE;
gboolean existing_feed;
RBPodcastManagerParseResult *result;
result = g_new0 (RBPodcastManagerParseResult, 1);
......@@ -1139,27 +1141,17 @@ rb_podcast_manager_thread_parse_feed (RBPodcastThreadInfo *info)
result->pd = info->pd; /* adopts our reference */
result->automatic = info->automatic;
existing_feed = info->existing_feed;
do {
retry = FALSE;
g_clear_error (&result->error);
rb_debug ("attempting to parse feed %s", info->url);
if (rb_podcast_parse_load_feed (feed, info->url, existing_feed, &result->error) == FALSE) {
if (g_error_matches (result->error,
RB_PODCAST_PARSE_ERROR,
RB_PODCAST_PARSE_ERROR_MIME_TYPE)) {
/* ask if the user really wants to use this feed.
* if so, set the 'existing feed' flag, which causes
* the mime type check to be skipped next time.
*/
if (confirm_bad_mime_type (info->url)) {
existing_feed = TRUE;
retry = TRUE;
}
}
g_clear_error (&result->error);
rb_debug ("attempting to parse feed %s", info->url);
if (rb_podcast_parse_load_feed (feed, info->url, info->existing_feed, &result->error) == FALSE) {
if (g_error_matches (result->error,
RB_PODCAST_PARSE_ERROR,
RB_PODCAST_PARSE_ERROR_MIME_TYPE)) {
confirm_bad_mime_type (info);
return NULL;
}
} while (retry);
}
if (feed->is_opml) {
GList *l;
......@@ -1876,6 +1868,48 @@ remove_if_not_downloaded (GtkTreeModel *model,
return FALSE;
}
void
rb_podcast_manager_insert_feed_url (RBPodcastManager *pd, const char *url)
{
RhythmDBEntry *entry;
GValue status_val = { 0, };
GValue title_val = { 0, };
GValue author_val = { 0, };
GValue last_update_val = { 0, };
entry = rhythmdb_entry_lookup_by_location (pd->priv->db, url);
if (entry) {
rb_debug ("podcast feed entry for %s found", url);
return;
}
rb_debug ("adding podcast feed %s with no entries", url);
entry = rhythmdb_entry_new (pd->priv->db,
RHYTHMDB_ENTRY_TYPE_PODCAST_FEED,
url);
if (entry == NULL)
return;
g_value_init (&status_val, G_TYPE_ULONG);
g_value_set_ulong (&status_val, 1);
rhythmdb_entry_set (pd->priv->db, entry, RHYTHMDB_PROP_STATUS, &status_val);
g_value_unset (&status_val);
g_value_init (&title_val, G_TYPE_STRING);
g_value_set_string (&title_val, url);
rhythmdb_entry_set (pd->priv->db, entry, RHYTHMDB_PROP_TITLE, &title_val);
g_value_unset (&title_val);
g_value_init (&author_val, G_TYPE_STRING);
g_value_set_static_string (&author_val, _("Unknown"));
rhythmdb_entry_set (pd->priv->db, entry, RHYTHMDB_PROP_ARTIST, &author_val);
g_value_unset (&author_val);
g_value_init (&last_update_val, G_TYPE_ULONG);
g_value_set_ulong (&last_update_val, time(NULL));
rhythmdb_entry_set (pd->priv->db, entry, RHYTHMDB_PROP_LAST_SEEN, &last_update_val);
g_value_unset (&last_update_val);
}
static void
rb_podcast_manager_insert_feed (RBPodcastManager *pd, RBPodcastChannel *data)
{
......@@ -2125,7 +2159,7 @@ rb_podcast_manager_insert_feed (RBPodcastManager *pd, RBPodcastChannel *data)
rhythmdb_commit (db);
}
static gboolean
static void
rb_podcast_manager_handle_feed_error (RBPodcastManager *mgr,
const char *url,
GError *error,
......@@ -2134,7 +2168,6 @@ rb_podcast_manager_handle_feed_error (RBPodcastManager *mgr,
RhythmDBEntry *entry;
GValue v = {0,};
gboolean existing = FALSE;
gboolean ret = FALSE;
/* set the error in the feed entry, if one exists */
entry = rhythmdb_entry_lookup_by_location (mgr->priv->db, url);
......@@ -2155,11 +2188,9 @@ rb_podcast_manager_handle_feed_error (RBPodcastManager *mgr,
error->message, url);
g_signal_emit (mgr,
rb_podcast_manager_signals[PROCESS_ERROR],
0, error_msg, existing, &ret);
0, url, error_msg, existing);
g_free (error_msg);
}
return ret;
}
void
......
......@@ -54,12 +54,12 @@ typedef struct
{
GObjectClass parent_class;
/* signals */
void (*status_changed) (RBPodcastManager* pd, RhythmDBEntry *entry, glong value);
void (*start_download) (RBPodcastManager* pd, RhythmDBEntry *entry);
void (*finish_download) (RBPodcastManager* pd, RhythmDBEntry *entry);
void (*feed_updates_available) (RBPodcastManager* pd, RhythmDBEntry *entry);
gboolean (*process_error) (RBPodcastManager* pd, const char *error, gboolean existing);
/* signals */
void (*status_changed) (RBPodcastManager* pd, RhythmDBEntry *entry, glong value);
void (*start_download) (RBPodcastManager* pd, RhythmDBEntry *entry);
void (*finish_download) (RBPodcastManager* pd, RhythmDBEntry *entry);
void (*feed_updates_available) (RBPodcastManager* pd, RhythmDBEntry *entry);
void (*process_error) (RBPodcastManager* pd, const char *url, const char *error, gboolean existing);
} RBPodcastManagerClass;
......@@ -76,6 +76,7 @@ gboolean rb_podcast_manager_remove_feed (RBPodcastManager *pd,
gchar * rb_podcast_manager_get_podcast_dir (RBPodcastManager *pd);
gboolean rb_podcast_manager_subscribe_feed (RBPodcastManager *pd, const gchar* url, gboolean automatic);
void rb_podcast_manager_insert_feed_url (RBPodcastManager *pd, const char *url);
void rb_podcast_manager_unsubscribe_feed (RhythmDB *db, const gchar* url);
void rb_podcast_manager_shutdown (RBPodcastManager *pd);
RhythmDBEntry * rb_podcast_manager_add_post (RhythmDB *db,
......
......@@ -349,18 +349,24 @@ podcast_location_added_cb (RBURIDialog *dialog,
FALSE);
}
static void
podcast_add_response_cb (GtkDialog *dialog, int response, gpointer meh)
{
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
podcast_cmd_new_podcast (GtkAction *action, RBPodcastSource *source)
{
GtkWidget *dialog;
dialog = rb_uri_dialog_new (_("New Podcast Feed"), _("URL of podcast feed:"));
g_signal_connect_object (G_OBJECT (dialog),
g_signal_connect_object (dialog,
"location-added",
G_CALLBACK (podcast_location_added_cb),
source, 0);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (podcast_add_response_cb), NULL);
gtk_widget_show_all (dialog);
}
......@@ -431,10 +437,32 @@ podcast_cmd_cancel_download (GtkAction *action, RBPodcastSource *source)
}
static void
podcast_cmd_delete_feed (GtkAction *action, RBPodcastSource *source)
podcast_remove_response_cb (GtkDialog *dialog, int response, RBPodcastSource *source)
{
GList *feeds, *l;
gint ret;
gtk_widget_destroy (GTK_WIDGET (dialog));
if (response == GTK_RESPONSE_CANCEL || response == GTK_RESPONSE_DELETE_EVENT) {
return;
}
feeds = rb_string_list_copy (source->priv->selected_feeds);
for (l = feeds; l != NULL; l = g_list_next (l)) {
const char *location = l->data;
rb_debug ("Removing podcast location: %s", location);
rb_podcast_manager_remove_feed (source->priv->podcast_mgr,
location,
(response == GTK_RESPONSE_YES));
}
rb_list_deep_free (feeds);
}
static void
podcast_cmd_delete_feed (GtkAction *action, RBPodcastSource *source)
{
GtkWidget *dialog;
GtkWidget *button;
GtkWindow *window;
......@@ -474,23 +502,8 @@ podcast_cmd_delete_feed (GtkAction *action, RBPodcastSource *source)
gtk_window_set_focus (GTK_WINDOW (dialog), button);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
ret = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
if (ret == GTK_RESPONSE_CANCEL || ret == GTK_RESPONSE_DELETE_EVENT)
return;
feeds = rb_string_list_copy (source->priv->selected_feeds);
for (l = feeds; l != NULL; l = g_list_next (l)) {
const char *location = l->data;
rb_debug ("Removing podcast location: %s", location);
rb_podcast_manager_remove_feed (source->priv->podcast_mgr,
location,
(ret == GTK_RESPONSE_YES));
}
rb_list_deep_free (feeds);
gtk_widget_show_all (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (podcast_remove_response_cb), source);
}
static void
......@@ -1028,12 +1041,46 @@ impl_can_add_to_queue (RBSource *source)
}
static void
impl_delete (RBSource *asource)
delete_response_cb (GtkDialog *dialog, int response, RBPodcastSource *source)
{
RBPodcastSource *source = RB_PODCAST_SOURCE (asource);
GList *entries;
GList *l;
gint ret;
gtk_widget_destroy (GTK_WIDGET (dialog));
if (response == GTK_RESPONSE_CANCEL || response == GTK_RESPONSE_DELETE_EVENT) {
return;
}
entries = rb_entry_view_get_selected_entries (source->priv->posts);
for (l = entries; l != NULL; l = g_list_next (l)) {
RhythmDBEntry *entry = l->data;
rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry);
if (response == GTK_RESPONSE_YES) {
rb_podcast_manager_delete_download (source->priv->podcast_mgr, entry);
}
/* set podcast entries to invisible instead of deleted so they will
* not reappear after the podcast has been updated
*/
GValue v = {0,};
g_value_init (&v, G_TYPE_BOOLEAN);
g_value_set_boolean (&v, TRUE);
rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_HIDDEN, &v);
g_value_unset (&v);
}
g_list_foreach (entries, (GFunc)rhythmdb_entry_unref, NULL);
g_list_free (entries);
rhythmdb_commit (source->priv->db);
}
static void
impl_delete (RBSource *asource)
{
RBPodcastSource *source = RB_PODCAST_SOURCE (asource);
GtkWidget *dialog;
GtkWidget *button;
GtkWindow *window;
......@@ -1071,36 +1118,8 @@ impl_delete (RBSource *asource)
gtk_window_set_focus (GTK_WINDOW (dialog), button);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
ret = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
if (ret == GTK_RESPONSE_CANCEL || ret == GTK_RESPONSE_DELETE_EVENT)
return;
entries = rb_entry_view_get_selected_entries (source->priv->posts);
for (l = entries; l != NULL; l = g_list_next (l)) {
RhythmDBEntry *entry = l->data;
rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry);
if (ret == GTK_RESPONSE_YES) {
rb_podcast_manager_delete_download (source->priv->podcast_mgr, entry);
}
/* set podcast entries to invisible instead of deleted so they will
* not reappear after the podcast has been updated
*/
GValue v = {0,};
g_value_init (&v, G_TYPE_BOOLEAN);
g_value_set_boolean (&v, TRUE);
rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_HIDDEN, &v);
g_value_unset (&v);
}
g_list_foreach (entries, (GFunc)rhythmdb_entry_unref, NULL);
g_list_free (entries);
rhythmdb_commit (source->priv->db);
g_signal_connect (dialog, "response", G_CALLBACK (delete_response_cb), source);
gtk_widget_show_all (dialog);
}
static RBEntryView *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment