Update of /cvsroot/gtkpod/gtkpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv22228/src

Modified Files:
        ipod_init.c ipod_init.h repository.c 
Log Message:
         * src/repository.c: use GtkComboEntry to select iPod model
           just like in ipod_init.c



Index: ipod_init.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/ipod_init.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ipod_init.c 7 Jun 2006 16:26:07 -0000       1.3
+++ ipod_init.c 8 Jun 2006 15:40:16 -0000       1.4
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-08 00:16:13 jcs>
+/* Time-stamp: <2006-06-09 00:16:50 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -138,20 +138,23 @@
 }
 
 
-void init_model_combo (IpodInit *ii)
+
+/**
+ * init_model_number_combo:
+ *
+ * Set up the the model for a model_number combo with all iPod models
+ * known to libgpod.
+ *
+ * @cb: the combobox that should be set up with a model.
+ */
+void init_model_number_combo (GtkComboBox *cb)
 {
     const IpodInfo *table;
     Itdb_IpodGeneration generation;
     GtkCellRenderer *renderer;
     GtkTreeStore *store;
     gboolean info_found;
-    GtkComboBox *cb;
-    const IpodInfo *info;
-    const gint BUFLEN = 50;
-    gchar buf[BUFLEN];
-    GtkEntry *entry;
-
-    g_return_if_fail (ii && ii->itdb);
+    gchar buf[PATH_MAX];
 
     table = itdb_info_get_ipod_info_table ();
     g_return_if_fail (table);
@@ -167,8 +170,9 @@
     do
     {
        GtkTreeIter iter;
-       info = table;
+       const IpodInfo *info = table;
        info_found = FALSE;
+
        while (info->model_number)
        {
            if (info->ipod_generation == generation)
@@ -186,7 +190,7 @@
                gtk_tree_store_append (store, &iter_child, &iter);
                /* gtk_tree_store_set() is intelligent enough to copy
                   strings we pass to it */
-               g_snprintf (buf, BUFLEN, "x%s", info->model_number);
+               g_snprintf (buf, PATH_MAX, "x%s", info->model_number);
                gtk_tree_store_set (store, &iter_child,
                                    COL_POINTER, info,
                                    COL_STRING, buf,
@@ -200,7 +204,6 @@
     /* set the model, specify the text column, and clear the cell
        layout (glade seems to automatically add a text column which
        messes up the entire layout) */
-    cb = GTK_COMBO_BOX (GET_WIDGET (MODEL_COMBO));
     gtk_combo_box_set_model (cb, GTK_TREE_MODEL (store));
     g_object_unref (store);
     gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (cb),
@@ -213,19 +216,6 @@
                                        renderer,
                                        set_cell,
                                        NULL, NULL);
-
-    /* If available set current model, otherwise indicate that */
-    info = itdb_device_get_ipod_info (ii->itdb->device);
-    if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN))
-    {
-       g_snprintf (buf, BUFLEN, "x%s", info->model_number);
-    }
-    else
-    {
-       g_snprintf (buf, BUFLEN, "%s", gettext (SELECT_OR_ENTER_YOUR_MODEL));
-    }
-    entry = GTK_ENTRY (gtk_bin_get_child(GTK_BIN (cb)));
-    gtk_entry_set_text (entry, buf);
 }
 
 
@@ -237,6 +227,10 @@
     gboolean result = FALSE;
     gchar *mountpoint, *new_mount, *name, *model;
     GError *error = NULL;
+    GtkEntry *entry;
+    gchar buf[PATH_MAX];
+    GtkComboBox *cb;
+    const IpodInfo *info;
 
     g_return_val_if_fail (itdb, FALSE);
 
@@ -260,8 +254,25 @@
     g_signal_connect (GET_WIDGET (MOUNTPOINT_BUTTON), "clicked",
                      G_CALLBACK (mountpoint_button_clicked), ii);
 
-    /* Setup model combo */
-    init_model_combo (ii);
+
+    /* Setup model number combo */
+    cb = GTK_COMBO_BOX (GET_WIDGET (MODEL_COMBO));
+    init_model_number_combo (cb);
+
+    /* If available set current model number, otherwise indicate that
+       none is available */
+    info = itdb_device_get_ipod_info (ii->itdb->device);
+    if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN))
+    {
+       g_snprintf (buf, PATH_MAX, "x%s", info->model_number);
+    }
+    else
+    {
+       g_snprintf (buf, PATH_MAX, "%s", gettext (SELECT_OR_ENTER_YOUR_MODEL));
+    }
+    entry = GTK_ENTRY (gtk_bin_get_child(GTK_BIN (cb)));
+    gtk_entry_set_text (entry, buf);
+
 
     response = gtk_dialog_run (GTK_DIALOG (ii->window));
 

Index: ipod_init.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/ipod_init.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ipod_init.h 4 Jun 2006 16:27:33 -0000       1.1
+++ ipod_init.h 8 Jun 2006 15:40:16 -0000       1.2
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-04 21:14:50 jcs>
+/* Time-stamp: <2006-06-09 00:31:54 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -38,5 +38,8 @@
 #include "itdb.h"
 
 
+extern const gchar *SELECT_OR_ENTER_YOUR_MODEL;
+
 gboolean ipod_init (iTunesDB *itdb);
+void init_model_number_combo (GtkComboBox *cb);
 #endif

Index: repository.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/repository.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- repository.c        7 Jun 2006 16:26:07 -0000       1.11
+++ repository.c        8 Jun 2006 15:40:16 -0000       1.12
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-08 01:19:05 jcs>
+/* Time-stamp: <2006-06-09 00:36:22 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -36,6 +36,7 @@
 #include "display_itdb.h"
 #include "fileselection.h"
 #include "info.h"
+#include "ipod_init.h"
 #include "misc.h"
 #include "prefs.h"
 #include "repository.h"
@@ -81,7 +82,8 @@
 static const gchar *BACKUP_ENTRY="backup_entry";
 static const gchar *BACKUP_BUTTON="backup_button";
 static const gchar *IPOD_MODEL_LABEL="ipod_model_label";
-static const gchar *IPOD_MODEL_ENTRY="ipod_model_entry";
+static const gchar *IPOD_MODEL_COMBO="ipod_model_combo";
+static const gchar *IPOD_MODEL_ENTRY="ipod_model_entry--not-a-glade-name";
 static const gchar *LOCAL_PATH_LABEL="local_path_label";
 static const gchar *LOCAL_PATH_BUTTON="local_path_button";
 static const gchar *LOCAL_PATH_ENTRY="local_path_entry";
@@ -140,10 +142,6 @@
 
 
 
-/* shortcut to reference widgets when repwin->xml is already set */
-#define GET_WIDGET(a) gtkpod_xml_get_widget (repwin->xml,a)
-
-
 /* Declarations */
 static void update_buttons (RepWin *repwin);
 static void repwin_free (RepWin *repwin);
@@ -154,6 +152,34 @@
 static void create_repository (RepWin *repwin);
 
 
+
+/* ------------------------------------------------------------
+ *
+ *        Helper functions to retrieve widgets.
+ *
+ * ------------------------------------------------------------ */
+/* shortcut to reference widgets when repwin->xml is already set */
+#define GET_WIDGET(a) repository_xml_get_widget (repwin->xml,a)
+
+
+/* This is quite dirty: MODEL_ENTRY is not a real widget
+   name. Instead it's the entry of a ComboBoxEntry -- hide this from
+   the application */
+GtkWidget *repository_xml_get_widget (GladeXML *xml, const gchar *name)
+{
+    if (name == IPOD_MODEL_ENTRY)
+    {
+       GtkWidget *cb = gtkpod_xml_get_widget (xml, IPOD_MODEL_COMBO);
+       return gtk_bin_get_child (GTK_BIN (cb));
+    }
+    else
+    {
+       return gtkpod_xml_get_widget (xml, name);
+    }
+}
+
+
+
 /* Store the window size */
 static void store_window_state (RepWin *repwin)
 {
@@ -167,7 +193,6 @@
 }
 
 
-
 /* ------------------------------------------------------------
  *
  *        Helper functions for prefs interfaceing.
@@ -1176,8 +1201,9 @@
            MOUNTPOINT_BUTTON,
            BACKUP_LABEL,
            BACKUP_ENTRY,
+           BACKUP_BUTTON,
            IPOD_MODEL_LABEL,
-           IPOD_MODEL_ENTRY,
+           IPOD_MODEL_COMBO,
            LOCAL_PATH_ENTRY,
            IPOD_SYNC_LABEL,
            IPOD_SYNC_CONTACTS_LABEL,
@@ -1241,7 +1267,7 @@
            BACKUP_ENTRY,
            BACKUP_BUTTON,
            IPOD_MODEL_LABEL,
-           IPOD_MODEL_ENTRY,
+           IPOD_MODEL_COMBO,
            IPOD_SYNC_LABEL,
            IPOD_SYNC_CONTACTS_LABEL,
            IPOD_SYNC_CONTACTS_ENTRY,
@@ -1837,6 +1863,7 @@
 void repository_edit (iTunesDB *itdb, Playlist *playlist)
 {
     RepWin *repwin;
+    GtkComboBox *cb;
     gint defx, defy;
     gint i;
     /* widget names and corresponding keys for 'standard' toggle
@@ -1900,6 +1927,11 @@
 
     repwins = g_list_append (repwins, repwin);
 
+
+    /* Setup model number combo */
+    cb = GTK_COMBO_BOX (GET_WIDGET (IPOD_MODEL_COMBO));
+    init_model_number_combo (cb);
+
     /* Window control */
     g_signal_connect (GET_WIDGET ("apply_button"), "clicked",
                      G_CALLBACK (edit_apply_clicked), repwin);
@@ -2088,9 +2120,11 @@
 static const gchar *REPOSITORY_NAME_ENTRY="repository_name_entry";
 
 
+
+
 /* shortcut to reference widgets when repwin->xml is already set */
 #undef GET_WIDGET
-#define GET_WIDGET(a) gtkpod_xml_get_widget (cr->xml,a)
+#define GET_WIDGET(a) repository_xml_get_widget (cr->xml,a)
 
 
 /* ------------------------------------------------------------
@@ -2162,6 +2196,10 @@
 
     ipod_model = gtk_entry_get_text (
        GTK_ENTRY (GET_WIDGET (IPOD_MODEL_ENTRY)));
+    if (strcmp (ipod_model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0)
+    {   /* User didn't choose a model */
+       ipod_model = "";
+    }
 
     local_path = gtk_entry_get_text (
        GTK_ENTRY (GET_WIDGET (LOCAL_PATH_ENTRY)));
@@ -2191,6 +2229,9 @@
        set_itdb_index_prefs_string (itdb_index,
                                     KEY_BACKUP, backup);
        set_itdb_index_prefs_int (itdb_index, "type", GP_ITDB_TYPE_IPOD);
+       if (strlen (ipod_model) != 0)
+           set_itdb_index_prefs_string (itdb_index,
+                                        KEY_IPOD_MODEL, ipod_model);
        break;
     case REPOSITORY_TYPE_LOCAL:
        set_itdb_index_prefs_string (itdb_index,
@@ -2246,7 +2287,7 @@
     const gchar *show_ipod[] = {
        MOUNTPOINT_LABEL, MOUNTPOINT_ENTRY, MOUNTPOINT_BUTTON,
        BACKUP_LABEL, BACKUP_ENTRY, BACKUP_BUTTON,
-       IPOD_MODEL_LABEL, IPOD_MODEL_ENTRY,
+       IPOD_MODEL_LABEL, IPOD_MODEL_COMBO,
        NULL };
     /* widgets to show for local repositories */
     const gchar *show_local[] = {
@@ -2256,7 +2297,7 @@
     const gchar *hide_all[] = {
        MOUNTPOINT_LABEL, MOUNTPOINT_ENTRY, MOUNTPOINT_BUTTON,
        BACKUP_LABEL, BACKUP_ENTRY, BACKUP_BUTTON,
-       IPOD_MODEL_LABEL, IPOD_MODEL_ENTRY,
+       IPOD_MODEL_LABEL, IPOD_MODEL_COMBO,
        LOCAL_PATH_LABEL, LOCAL_PATH_ENTRY, LOCAL_PATH_BUTTON,
        NULL };
 
@@ -2388,6 +2429,7 @@
 static void create_repository (RepWin *repwin1)
 {
     CreateRep *cr;
+    GtkComboBox *cb;
     gchar *str, *buf1, *buf2;
     struct itdbs_head *itdbs_head = gp_get_itdbs_head (gtkpod_window);
 
@@ -2436,6 +2478,12 @@
     g_signal_connect (GET_WIDGET (LOCAL_PATH_BUTTON), "clicked",
                      G_CALLBACK (cr_local_path_button_clicked), cr);
 
+    /* Setup model number combo */
+    cb = GTK_COMBO_BOX (GET_WIDGET (IPOD_MODEL_COMBO));
+    init_model_number_combo (cb);
+    gtk_entry_set_text (GTK_ENTRY (GET_WIDGET (IPOD_MODEL_ENTRY)),
+                       gettext (SELECT_OR_ENTER_YOUR_MODEL));
+
     /* Set initial repository type */
     gtk_combo_box_set_active (
        GTK_COMBO_BOX (GET_WIDGET (REPOSITORY_TYPE_COMBO)),



_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to