[rhythmbox] ipod: rework ipod init dialog to avoid gtk_dialog_run
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] ipod: rework ipod init dialog to avoid gtk_dialog_run
- Date: Sat, 25 Feb 2012 01:40:23 +0000 (UTC)
commit 3a5b74ee288e52255ee3786f89e389289c22d756
Author: Jonathan Matthew <jonathan d14n org>
Date: Sat Feb 25 11:40:05 2012 +1000
ipod: rework ipod init dialog to avoid gtk_dialog_run
plugins/ipod/rb-ipod-helpers.c | 83 +----------------------
plugins/ipod/rb-ipod-helpers.h | 3 +-
plugins/ipod/rb-ipod-plugin.c | 13 ----
plugins/ipod/rb-ipod-source.c | 144 +++++++++++++++++++++++++++++++++++++--
4 files changed, 139 insertions(+), 104 deletions(-)
---
diff --git a/plugins/ipod/rb-ipod-helpers.c b/plugins/ipod/rb-ipod-helpers.c
index 0500d88..25d624b 100644
--- a/plugins/ipod/rb-ipod-helpers.c
+++ b/plugins/ipod/rb-ipod-helpers.c
@@ -200,8 +200,8 @@ fill_one_generation (gpointer key, gpointer value, gpointer data)
}
}
-static void
-fill_model_combo (GtkWidget *combo, const char *mount_path)
+void
+rb_ipod_helpers_fill_model_combo (GtkWidget *combo, const char *mount_path)
{
GHashTable *models;
Itdb_Device *device;
@@ -237,85 +237,6 @@ fill_model_combo (GtkWidget *combo, const char *mount_path)
NULL, NULL);
}
-gboolean
-rb_ipod_helpers_show_first_time_dialog (GMount *mount, const char *builder_file)
-{
- /* could be an uninitialised iPod, ask the user */
- GtkBuilder *builder;
- GtkWidget *dialog;
- GtkWidget *widget;
- GtkWidget *name_widget;
- GtkTreeModel *tree_model;
- GtkTreeIter iter;
- int response;
- char *mountpoint;
- const Itdb_IpodInfo *info;
- char *ipod_name;
- GFile *root;
- GError *error = NULL;
-
- root = g_mount_get_root (mount);
- if (root == NULL) {
- return FALSE;
- }
- mountpoint = g_file_get_path (root);
- g_object_unref (G_OBJECT (root));
-
- if (mountpoint == NULL) {
- return FALSE;
- }
-
- /* create message dialog with model-number combo box
- * and asking whether they want to initialise the iPod
- */
- builder = rb_builder_load (builder_file, NULL);
- if (builder == NULL) {
- return FALSE;
- }
- dialog = GTK_WIDGET (gtk_builder_get_object (builder, "ipod_init"));
- widget = GTK_WIDGET (gtk_builder_get_object (builder, "model_combo"));
- name_widget = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- fill_model_combo (widget, mountpoint);
- g_object_unref (builder);
-
- rb_debug ("showing init dialog for ipod mount on '%s'", mountpoint);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response != GTK_RESPONSE_ACCEPT) {
- gtk_widget_destroy (dialog);
- g_free (mountpoint);
- return FALSE;
- }
-
- /* get model number and name */
- tree_model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
- gtk_widget_destroy (dialog);
- g_free (mountpoint);
- return FALSE;
- }
- gtk_tree_model_get (tree_model, &iter, COL_INFO, &info, -1);
- ipod_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (name_widget)));
-
- gtk_widget_destroy (dialog);
-
- rb_debug ("attempting to init ipod on '%s', with model '%s' and name '%s'",
- mountpoint, info->model_number, ipod_name);
- if (!itdb_init_ipod (mountpoint, info->model_number, ipod_name, &error)) {
- rb_error_dialog (NULL, _("Unable to initialize new iPod"), "%s", error->message);
-
- g_free (mountpoint);
- g_free (ipod_name);
- g_error_free (error);
- return FALSE;
- }
-
- g_free (mountpoint);
- g_free (ipod_name);
-
- return TRUE;
-}
-
static gchar *
rb_ipod_helpers_get_itunesdb_path (GMount *mount)
{
diff --git a/plugins/ipod/rb-ipod-helpers.h b/plugins/ipod/rb-ipod-helpers.h
index 418ed54..7409c99 100644
--- a/plugins/ipod/rb-ipod-helpers.h
+++ b/plugins/ipod/rb-ipod-helpers.h
@@ -34,8 +34,7 @@
#include "mediaplayerid.h"
G_BEGIN_DECLS
-gboolean rb_ipod_helpers_show_first_time_dialog (GMount *mount,
- const char *builder_file);
+void rb_ipod_helpers_fill_model_combo (GtkWidget *combo, const char *mountpoint);
guint64 rb_ipod_helpers_get_capacity (const char *mountpoint);
guint64 rb_ipod_helpers_get_free_space (const char *mountpoint);
diff --git a/plugins/ipod/rb-ipod-plugin.c b/plugins/ipod/rb-ipod-plugin.c
index 31a0d0b..089c1b4 100644
--- a/plugins/ipod/rb-ipod-plugin.c
+++ b/plugins/ipod/rb-ipod-plugin.c
@@ -213,18 +213,6 @@ create_source_cb (RBRemovableMediaManager *rmm, GMount *mount, MPIDDevice *devic
return NULL;
}
- if (rb_ipod_helpers_needs_init (mount)) {
- gboolean inited;
- gchar *builder_file;
- builder_file = rb_find_plugin_data_file (G_OBJECT (plugin), "ipod-init.ui");
- inited = rb_ipod_helpers_show_first_time_dialog (mount,
- builder_file);
- g_free (builder_file);
- if (!inited) {
- return NULL;
- }
- }
-
g_object_get (plugin, "object", &shell, NULL);
src = RB_SOURCE (rb_ipod_source_new (G_OBJECT (plugin),
shell,
@@ -236,7 +224,6 @@ create_source_cb (RBRemovableMediaManager *rmm, GMount *mount, MPIDDevice *devic
g_signal_connect_object (G_OBJECT (src),
"deleted", G_CALLBACK (rb_ipod_plugin_source_deleted),
plugin, 0);
-
return src;
}
diff --git a/plugins/ipod/rb-ipod-source.c b/plugins/ipod/rb-ipod-source.c
index 8a88f78..9ba212b 100644
--- a/plugins/ipod/rb-ipod-source.c
+++ b/plugins/ipod/rb-ipod-source.c
@@ -57,6 +57,7 @@
#include "rb-gst-media-types.h"
#include "rb-transfer-target.h"
#include "rb-ext-db.h"
+#include "rb-dialog.h"
static void rb_ipod_device_source_init (RBDeviceSourceInterface *interface);
static void rb_ipod_source_transfer_target_init (RBTransferTargetInterface *interface);
@@ -130,6 +131,11 @@ typedef struct
RBExtDB *art_store;
GQueue *offline_plays;
+
+ /* init dialog */
+ GtkWidget *init_dialog;
+ GtkWidget *model_combo;
+ GtkWidget *name_entry;
} RBiPodSourcePrivate;
typedef struct {
@@ -304,18 +310,12 @@ rb_ipod_source_init (RBiPodSource *source)
}
static void
-rb_ipod_source_constructed (GObject *object)
+finish_construction (RBiPodSource *source)
{
- RBiPodSource *source;
RBEntryView *songs;
+ RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (source);
GstEncodingTarget *target;
- RBiPodSourcePrivate *priv;
- RB_CHAIN_GOBJECT_METHOD (rb_ipod_source_parent_class, constructed, object);
- source = RB_IPOD_SOURCE (object);
- priv = IPOD_SOURCE_GET_PRIVATE (object);
-
- rb_device_source_set_display_details (RB_DEVICE_SOURCE (source));
songs = rb_source_get_entry_view (RB_SOURCE (source));
rb_entry_view_append_column (songs, RB_ENTRY_VIEW_COL_RATING, FALSE);
@@ -338,6 +338,129 @@ rb_ipod_source_constructed (GObject *object)
}
static void
+first_time_dialog_response_cb (GtkDialog *dialog, int response, RBiPodSource *source)
+{
+ const Itdb_IpodInfo *info;
+ GtkTreeModel *tree_model;
+ GtkTreeIter iter;
+ char *mountpoint;
+ char *ipod_name;
+ GFile *root;
+ GError *error = NULL;
+ RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (source);
+
+ priv->init_dialog = NULL;
+
+ if (response != GTK_RESPONSE_ACCEPT) {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ rb_display_page_delete_thyself (RB_DISPLAY_PAGE (source));
+ return;
+ }
+
+ /* get model number and name */
+ tree_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->model_combo));
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->model_combo), &iter)) {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ rb_display_page_delete_thyself (RB_DISPLAY_PAGE (source));
+ return;
+ }
+ gtk_tree_model_get (tree_model, &iter, /* COL_INFO */ 0, &info, -1);
+ ipod_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->name_entry)));
+
+ /* get mountpoint again */
+ root = g_mount_get_root (priv->mount);
+ if (root == NULL) {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ return;
+ }
+ mountpoint = g_file_get_path (root);
+ g_object_unref (root);
+
+ rb_debug ("attempting to init ipod on '%s', with model '%s' and name '%s'",
+ mountpoint, info->model_number, ipod_name);
+ if (!itdb_init_ipod (mountpoint, info->model_number, ipod_name, &error)) {
+ rb_error_dialog (NULL, _("Unable to initialize new iPod"), "%s", error->message);
+ g_error_free (error);
+ rb_display_page_delete_thyself (RB_DISPLAY_PAGE (source));
+ } else {
+ finish_construction (source);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_free (mountpoint);
+ g_free (ipod_name);
+}
+
+static gboolean
+create_init_dialog (RBiPodSource *source)
+{
+ GFile *root;
+ char *mountpoint;
+ char *builder_file;
+ GtkBuilder *builder;
+ GObject *plugin;
+ RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (source);
+
+ root = g_mount_get_root (priv->mount);
+ if (root == NULL) {
+ return FALSE;
+ }
+ mountpoint = g_file_get_path (root);
+ g_object_unref (root);
+
+ if (mountpoint == NULL) {
+ return FALSE;
+ }
+
+ g_object_get (source, "plugin", &plugin, NULL);
+ builder_file = rb_find_plugin_data_file (G_OBJECT (plugin), "ipod-init.ui");
+ g_object_unref (plugin);
+
+ builder = rb_builder_load (builder_file, NULL);
+ g_free (builder_file);
+ if (builder == NULL) {
+ g_free (mountpoint);
+ return FALSE;
+ }
+
+ priv->init_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "ipod_init"));
+ priv->model_combo = GTK_WIDGET (gtk_builder_get_object (builder, "model_combo"));
+ priv->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ rb_ipod_helpers_fill_model_combo (priv->model_combo, mountpoint);
+
+ g_signal_connect (priv->init_dialog,
+ "response",
+ G_CALLBACK (first_time_dialog_response_cb),
+ source);
+
+ g_object_unref (builder);
+ g_free (mountpoint);
+ return TRUE;
+}
+
+static void
+rb_ipod_source_constructed (GObject *object)
+{
+ RBiPodSource *source;
+ GMount *mount;
+
+ RB_CHAIN_GOBJECT_METHOD (rb_ipod_source_parent_class, constructed, object);
+ source = RB_IPOD_SOURCE (object);
+
+ g_object_get (source, "mount", &mount, NULL);
+
+ rb_device_source_set_display_details (RB_DEVICE_SOURCE (source));
+
+ if (rb_ipod_helpers_needs_init (mount)) {
+ if (create_init_dialog (source) == FALSE) {
+ rb_display_page_delete_thyself (RB_DISPLAY_PAGE (source));
+ }
+ } else {
+ finish_construction (source);
+ }
+}
+
+static void
rb_ipod_source_dispose (GObject *object)
{
RBiPodSourcePrivate *priv = IPOD_SOURCE_GET_PRIVATE (object);
@@ -374,6 +497,11 @@ rb_ipod_source_dispose (GObject *object)
priv->art_store = NULL;
}
+ if (priv->init_dialog) {
+ gtk_widget_destroy (priv->init_dialog);
+ priv->init_dialog = NULL;
+ }
+
G_OBJECT_CLASS (rb_ipod_source_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]