commit db406773ec937ac57b6e6a4c90c7bd615f53c27a Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Sat Feb 6 19:24:25 2010 +0000
Getting save to work - gtkpod.glade Includes the file transfer dialog and progress indicator. Would be nice if this could be more integrated using the anjuta progress bar but that is a little way off yet. - gtkpod_app_iface.* - anjuta_app.c Include API functions for showing the busy cursor using anjuta framework - playlist_display_actions.c File and directory addition processes now show busy cursor - file_convert.c conversion object initialised when any of its related functions are called in order to get the save function working - file_itunesdb.c - ipod_init.c reformatting data/glade/gtkpod.glade | 69 +++ libgtkpod/gtkpod_app_iface.c | 10 + libgtkpod/gtkpod_app_iface.h | 4 + .../playlist_display/playlist_display_actions.c | 8 +- src/anjuta-app.c | 23 +- src/file_convert.c | 23 +- src/file_itunesdb.c | 63 +-- src/ipod_init.c | 555 ++++++++------------ 8 files changed, 389 insertions(+), 366 deletions(-) --- diff --git a/data/glade/gtkpod.glade b/data/glade/gtkpod.glade index 9153115..560ed8b 100644 --- a/data/glade/gtkpod.glade +++ b/data/glade/gtkpod.glade @@ -854,4 +854,73 @@ The quick brown fox jumps over the lazy dog.</property> </widget> </child> </widget> + <widget class="GtkWindow" id="file_transfer_information_dialog"> + <property name="border_width">2</property> + <property name="title" translatable="yes">Progress Information</property> + <property name="skip_taskbar_hint">True</property> + <child> + <widget class="GtkVBox" id="vbox180"><property name="orientation">GTK_ORIENTATION_VERTICAL</property> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="spacing">5</property> + <child> + <widget class="GtkLabel" id="textlabel"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label">Some placeholder text to assure reasonable size.</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + <child> + <widget class="GtkProgressBar" id="progressbar"> + <property name="visible">True</property> + <property name="pulse_step">0.10000000149</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <widget class="GtkHSeparator" id="hseparator59"> + <property name="visible">True</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> + </packing> + </child> + <child> + <widget class="GtkHButtonBox" id="hbuttonbox17"> + <property name="visible">True</property> + <child> + <widget class="GtkButton" id="abortbutton"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="tooltip" translatable="yes">Export can be continued at a later time if canceled.</property> + <property name="border_width">2</property> + <property name="label">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="response_id">0</property> + </widget> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">4</property> + </packing> + </child> + </widget> + </child> + </widget> </glade-interface> diff --git a/libgtkpod/gtkpod_app_iface.c b/libgtkpod/gtkpod_app_iface.c index 1eb2abf..0265e4b 100644 --- a/libgtkpod/gtkpod_app_iface.c +++ b/libgtkpod/gtkpod_app_iface.c @@ -103,6 +103,16 @@ void gtkpod_statusbar_message(gchar* message, ...) { g_free(msg); } +void gtkpod_statusbar_busy_push() { + g_return_if_fail (GTKPOD_IS_APP(gtkpod_app)); + GTKPOD_APP_GET_INTERFACE (gtkpod_app)->statusbar_busy_push(gtkpod_app); +} + +void gtkpod_statusbar_busy_pop() { + g_return_if_fail (GTKPOD_IS_APP(gtkpod_app)); + GTKPOD_APP_GET_INTERFACE (gtkpod_app)->statusbar_busy_pop(gtkpod_app); +} + void gtkpod_tracks_statusbar_update(void) { gchar *buf; Playlist *pl; diff --git a/libgtkpod/gtkpod_app_iface.h b/libgtkpod/gtkpod_app_iface.h index aafc610..bcb2161 100644 --- a/libgtkpod/gtkpod_app_iface.h +++ b/libgtkpod/gtkpod_app_iface.h @@ -108,6 +108,8 @@ struct _GtkPodAppInterface { (*gtkpod_confirmation_hig)(GtkPodApp *obj, GtkMessageType icon, const gchar *primary_text, const gchar *secondary_text, const gchar *accept_button_text, const gchar *cancel_button_text, const gchar *third_button_text, const gchar *help_context); GtkResponseType (*gtkpod_confirmation)(GtkPodApp *obj, gint id, gboolean modal, const gchar *title, const gchar *label, const gchar *text, const gchar *option1_text, CONF_STATE option1_state, const gchar *option1_key, const gchar *option2_text, CONF_STATE option2_state, const gchar *option2_key, gboolean confirm_again, const gchar *confirm_again_key, ConfHandler ok_handler, ConfHandler apply_handler, ConfHandler cancel_handler, gpointer user_data1, gpointer user_data2); + void (*statusbar_busy_push)(GtkPodApp *obj); + void (*statusbar_busy_pop)(GtkPodApp *obj); }; GType gtkpod_app_get_type(void); @@ -118,6 +120,8 @@ void gtkpod_app_set_glade_xml(gchar *xml_file); gchar* gtkpod_get_glade_xml(); void gtkpod_statusbar_message(gchar* message, ...); +void gtkpod_statusbar_busy_push(); +void gtkpod_statusbar_busy_pop(); void gtkpod_tracks_statusbar_update(void); void gtkpod_warning(gchar* message, ...); void gtkpod_warning_simple (const gchar *format, ...); diff --git a/plugins/playlist_display/playlist_display_actions.c b/plugins/playlist_display/playlist_display_actions.c index bc5a1a3..0a47237 100644 --- a/plugins/playlist_display/playlist_display_actions.c +++ b/plugins/playlist_display/playlist_display_actions.c @@ -52,6 +52,7 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { g_return_if_fail (db_active_pl); if (names) { + gtkpod_statusbar_busy_push(); GSList* currentnode; for (currentnode = names; currentnode; currentnode = currentnode->next) { result @@ -69,6 +70,7 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { gtkpod_statusbar_message(_("Successfully added files")); else gtkpod_statusbar_message(_("Some files were not added successfully")); + gtkpod_statusbar_busy_pop(); } } @@ -79,7 +81,6 @@ static gboolean add_selected_dirs_cb(gpointer data) { g_slist_foreach(names, (GFunc) g_free, NULL); g_slist_free(names); - g_warning("add_selected_dir_cb: Finished!!"); return FALSE; } @@ -127,6 +128,7 @@ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { g_warning("fileselection_add_playlists - block widgets commented out"); // block_widgets(); + gtkpod_statusbar_busy_push(); for (gsl = names; gsl; gsl = gsl->next) { add_playlist_by_filename(itdb, gsl->data, NULL, -1, NULL, NULL); } @@ -142,7 +144,7 @@ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { /* display log of detected duplicates */ gp_duplicate_remove(NULL, NULL); - + gtkpod_statusbar_busy_pop(); gtkpod_tracks_statusbar_update(); } @@ -235,6 +237,7 @@ static void fileselection_add_files(GSList* names, Playlist *playlist) { g_warning("fileselection_add_files - block widgets commented out"); // block_widgets(); + gtkpod_statusbar_busy_push(); /* Get the filenames and add them */ for (gsl = names; gsl; gsl = gsl->next) { result @@ -256,6 +259,7 @@ static void fileselection_add_files(GSList* names, Playlist *playlist) { else gtkpod_statusbar_message(_("Some files were not added successfully")); + gtkpod_statusbar_busy_pop(); g_warning("fileselection_add_playlists - release widgets commented out"); // release_widgets(); } diff --git a/src/anjuta-app.c b/src/anjuta-app.c index e2f7324..0f77d54 100644 --- a/src/anjuta-app.c +++ b/src/anjuta-app.c @@ -900,7 +900,20 @@ static void anjuta_shell_iface_init(AnjutaShellIface *iface) { static void anjuta_gtkpod_app_statusbar_message(GtkPodApp *gtkpod_app, gchar* message) { g_return_if_fail(ANJUTA_IS_APP(gtkpod_app)); AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app), NULL); - anjuta_status_push(status, message); + anjuta_status_set(status, message); +} + +static void anjuta_gtkpod_app_statusbar_busy_push(GtkPodApp *gtkpod_app) { + g_return_if_fail(ANJUTA_IS_APP(gtkpod_app)); + AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app), NULL); + g_warning("busy push XXX"); + anjuta_status_busy_push(status); +} + +static void anjuta_gtkpod_app_statusbar_busy_pop(GtkPodApp *gtkpod_app) { + g_return_if_fail(ANJUTA_IS_APP(gtkpod_app)); + AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app), NULL); + anjuta_status_busy_pop(status); } static void anjuta_gtkpod_app_warning(GtkPodApp *gtkpod_app, gchar *message) { @@ -1333,6 +1346,8 @@ static GtkResponseType anjuta_gtkpod_app_confirmation(GtkPodApp *obj, gint id, g static void gtkpod_app_iface_init(GtkPodAppInterface *iface) { iface->statusbar_message = anjuta_gtkpod_app_statusbar_message; + iface->statusbar_busy_push = anjuta_gtkpod_app_statusbar_busy_push; + iface->statusbar_busy_pop = anjuta_gtkpod_app_statusbar_busy_pop; iface->gtkpod_warning = anjuta_gtkpod_app_warning; iface->gtkpod_warning_hig = anjuta_gtkpod_app_warning_hig; iface->gtkpod_confirmation_hig = anjuta_gtkpod_app_confirmation_hig; @@ -1340,6 +1355,6 @@ static void gtkpod_app_iface_init(GtkPodAppInterface *iface) { } ANJUTA_TYPE_BEGIN(AnjutaApp, anjuta_app, GTK_TYPE_WINDOW); -ANJUTA_TYPE_ADD_INTERFACE(anjuta_shell, ANJUTA_TYPE_SHELL); -ANJUTA_TYPE_ADD_INTERFACE(gtkpod_app, GTKPOD_APP_TYPE); -ANJUTA_TYPE_END; + ANJUTA_TYPE_ADD_INTERFACE(anjuta_shell, ANJUTA_TYPE_SHELL); + ANJUTA_TYPE_ADD_INTERFACE(gtkpod_app, GTKPOD_APP_TYPE);ANJUTA_TYPE_END +; diff --git a/src/file_convert.c b/src/file_convert.c index 2aec6fb..4053f4f 100644 --- a/src/file_convert.c +++ b/src/file_convert.c @@ -268,7 +268,7 @@ enum CONV_DIRSIZE_INVALID = -1, /* dirsize not valid */ }; -static Conversion *conversion; +static Conversion *conversion = NULL; /* Set up conversion infrastructure. Must only be called once. */ @@ -277,7 +277,8 @@ void file_convert_init () GladeXML *log_xml; GtkWidget *vbox; - g_return_if_fail (conversion==NULL); + if (conversion != NULL) + return; conversion = g_new0 (Conversion, 1); conversion->mutex = g_mutex_new (); @@ -351,6 +352,7 @@ void file_convert_shutdown () /* This is called just before gtkpod closes down */ void file_convert_update_default_sizes () { + file_convert_init(); conversion_update_default_sizes (conversion); } @@ -358,6 +360,7 @@ void file_convert_update_default_sizes () /* Call this function each time the preferences have been updated */ void file_convert_prefs_changed () { + file_convert_init(); conversion_prefs_changed (conversion); } @@ -369,6 +372,7 @@ void file_convert_prefs_changed () */ gboolean file_convert_add_track (Track *track) { + file_convert_init(); return conversion_add_track (conversion, track); } @@ -376,6 +380,7 @@ gboolean file_convert_add_track (Track *track) /* Reorder the scheduled list so that tracks in @itdb are converted first */ void file_convert_itdb_first (iTunesDB *itdb) { + file_convert_init(); conversion_itdb_first (conversion, itdb); } @@ -383,6 +388,7 @@ void file_convert_itdb_first (iTunesDB *itdb) /* Cancel conversion for all tracks of @itdb */ void file_convert_cancel_itdb (iTunesDB *itdb) { + file_convert_init(); conversion_cancel_itdb (conversion, itdb); } @@ -390,11 +396,13 @@ void file_convert_cancel_itdb (iTunesDB *itdb) /* Cancel conversion for @tracks */ void file_convert_cancel_track (Track *track) { + file_convert_init(); conversion_cancel_track (conversion, track); } void file_convert_continue () { + file_convert_init(); conversion_continue (conversion); } @@ -424,6 +432,7 @@ FileTransferStatus file_transfer_get_status (iTunesDB *itdb, removed again when calling file_convert_cancel_itdb */ void file_transfer_ack_itdb (iTunesDB *itdb) { + file_convert_init(); transfer_ack_itdb (conversion, itdb); } @@ -432,6 +441,7 @@ void file_transfer_ack_itdb (iTunesDB *itdb) * additional space is available. */ void file_transfer_continue (iTunesDB *itdb) { + file_convert_init(); transfer_continue (conversion, itdb); } @@ -440,6 +450,7 @@ void file_transfer_continue (iTunesDB *itdb) from the settings in the preferences */ void file_transfer_activate (iTunesDB *itdb, gboolean active) { + file_convert_init(); transfer_activate (conversion, itdb, active); } @@ -447,6 +458,7 @@ void file_transfer_activate (iTunesDB *itdb, gboolean active) * the preferences */ void file_transfer_reset (iTunesDB *itdb) { + file_convert_init(); transfer_reset (conversion, itdb); } @@ -455,6 +467,7 @@ void file_transfer_reset (iTunesDB *itdb) conversion */ GList *file_transfer_get_failed_tracks (iTunesDB *itdb) { + file_convert_init(); return transfer_get_failed_tracks (conversion, itdb); } @@ -463,6 +476,7 @@ GList *file_transfer_get_failed_tracks (iTunesDB *itdb) failed conversion/transfer */ void file_transfer_reschedule (iTunesDB *itdb) { + file_convert_init(); transfer_reschedule (conversion, itdb); } @@ -2920,7 +2934,10 @@ static void transfer_activate (Conversion *conv, iTunesDB *itdb, gboolean active { TransferItdb *tri; - g_return_if_fail (conv && itdb); + g_return_if_fail (itdb); + + // Initialise Conversion infrastructure is not already initialised. + file_convert_init(); g_mutex_lock (conv->mutex); diff --git a/src/file_itunesdb.c b/src/file_itunesdb.c index 6d4143d..03d330b 100644 --- a/src/file_itunesdb.c +++ b/src/file_itunesdb.c @@ -464,7 +464,7 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint type, const gchar *mp, c } itdb = itdb_parse(mp, &error); if (itdb && !error) { - gtkpod_statusbar_message (_("iPod Database Successfully Imported")); + gtkpod_statusbar_message(_("iPod Database Successfully Imported")); } else { if (error) { @@ -924,7 +924,7 @@ gboolean gp_eject_ipod(iTunesDB *itdb) { * return value: TRUE on succes, FALSE when an error occurred. */ gboolean gp_save_itdb(iTunesDB *itdb) { -// Playlist *pl; + // Playlist *pl; gboolean success; g_return_val_if_fail (itdb, FALSE); @@ -1543,30 +1543,25 @@ static gboolean transfer_tracks(iTunesDB *itdb, TransferData *td) { if (td->abort) { result = FALSE; } - else if (status == FILE_TRANSFER_DISK_FULL) - { - gchar *buf; - GtkWidget *dialog; - - gtk_widget_hide (td->dialog); - - buf = g_strdup_printf (ngettext ( - "One track could not be transferred because your iPod is full. Either delete some tracks or otherwise create space on the iPod before ejecting the iPod again.", - "%d tracks could not be transferred because your iPod is full. Either delete some tracks or otherwise create space on the iPod before ejecting the iPod again.", to_transfer_num), - to_transfer_num); - - dialog = gtk_message_dialog_new ( - GTK_WINDOW (gtkpod_app), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "%s", buf); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - g_free (buf); - result = FALSE; - } - else if (failed_num != 0) /* one error message is enough -> else{... */ + else if (status == FILE_TRANSFER_DISK_FULL) { + gchar *buf; + GtkWidget *dialog; + + gtk_widget_hide(td->dialog); + + buf + = g_strdup_printf(ngettext ( + "One track could not be transferred because your iPod is full. Either delete some tracks or otherwise create space on the iPod before ejecting the iPod again.", + "%d tracks could not be transferred because your iPod is full. Either delete some tracks or otherwise create space on the iPod before ejecting the iPod again.", to_transfer_num), to_transfer_num); + + dialog + = gtk_message_dialog_new(GTK_WINDOW (gtkpod_app), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s", buf); + gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_widget_destroy(dialog); + g_free(buf); + result = FALSE; + } + else if (failed_num != 0) /* one error message is enough -> else{... */ { transfer_tracks_show_failed(itdb, td); result = FALSE; @@ -1815,15 +1810,15 @@ static gboolean gp_write_itdb(iTunesDB *itdb) { /* indicate that files and/or database is saved */ g_warning("TODO indicate that database has been saved\n"); - // if (success) { - // data_unchanged(itdb); - // if (itdb->usertype & GP_ITDB_TYPE_IPOD) { - // gtkpod_statusbar_message(_("%s: Database saved"), mpl->name); - // } - // else { - // gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name); - // } - // } + if (success) { + data_unchanged(itdb); + if (itdb->usertype & GP_ITDB_TYPE_IPOD) { + gtkpod_statusbar_message(_("%s: Database saved"), mpl->name); + } + else { + gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name); + } + } g_free(cfgdir); diff --git a/src/ipod_init.c b/src/ipod_init.c index 8ee3a0f..f2f24d0 100644 --- a/src/ipod_init.c +++ b/src/ipod_init.c @@ -1,31 +1,31 @@ /* Time-stamp: <2008-09-30 23:36:02 jcs> -| -| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> -| Part of the gtkpod project. -| -| URL: http://www.gtkpod.org/ -| URL: http://gtkpod.sourceforge.net/ -| -| This program is free software; you can redistribute it and/or modify -| it under the terms of the GNU General Public License as published by -| the Free Software Foundation; either version 2 of the License, or -| (at your option) any later version. -| -| This program is distributed in the hope that it will be useful, -| but WITHOUT ANY WARRANTY; without even the implied warranty of -| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -| GNU General Public License for more details. -| -| You should have received a copy of the GNU General Public License -| along with this program; if not, write to the Free Software -| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -| -| iTunes and iPod are trademarks of Apple -| -| This product is not supported/written/published by Apple! -| -| $Id$ -*/ + | + | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> + | Part of the gtkpod project. + | + | URL: http://www.gtkpod.org/ + | URL: http://gtkpod.sourceforge.net/ + | + | This program is free software; you can redistribute it and/or modify + | it under the terms of the GNU General Public License as published by + | the Free Software Foundation; either version 2 of the License, or + | (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, write to the Free Software + | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + | + | iTunes and iPod are trademarks of Apple + | + | This product is not supported/written/published by Apple! + | + | $Id$ + */ /* This file provides functions to initialize a new iPod */ @@ -37,119 +37,82 @@ #include <glib/gi18n-lib.h> #include "file.h" -struct _IpodInit -{ - GladeXML *xml; /* XML info */ - GtkWidget *window; /* pointer to repository window */ +struct _IpodInit { + GladeXML *xml; /* XML info */ + GtkWidget *window; /* pointer to repository window */ iTunesDB *itdb; }; typedef struct _IpodInit IpodInit; /* Strings used several times */ -const gchar *SELECT_OR_ENTER_YOUR_MODEL=N_("Select or enter your model"); +const gchar *SELECT_OR_ENTER_YOUR_MODEL = N_("Select or enter your model"); /* string constants for window widgets used more than once */ -static const gchar *IID_MOUNTPOINT_ENTRY="iid_mountpoint_entry"; -static const gchar *IID_MOUNTPOINT_BUTTON="iid_mountpoint_button"; -static const gchar *IID_MODEL_COMBO="iid_model_combo"; -static const gchar *SIMD_MODEL_COMBO="simd_model_combo"; -static const gchar *SIMD_LABEL="simd_label"; +static const gchar *IID_MOUNTPOINT_ENTRY = "iid_mountpoint_entry"; +static const gchar *IID_MOUNTPOINT_BUTTON = "iid_mountpoint_button"; +static const gchar *IID_MODEL_COMBO = "iid_model_combo"; +static const gchar *SIMD_MODEL_COMBO = "simd_model_combo"; +static const gchar *SIMD_LABEL = "simd_label"; /* Columns for the model_combo tree model */ -enum -{ - COL_POINTER, - COL_STRING +enum { + COL_POINTER, COL_STRING }; - /* shortcut to reference widgets when ii->xml is already set */ #define GET_WIDGET(a) gtkpod_xml_get_widget (ii->xml,a) /* mountpoint browse button was clicked -> open a directory browser * and copy the result into the mountpoint entry. */ -static void mountpoint_button_clicked (GtkButton *button, IpodInit *ii) -{ +static void mountpoint_button_clicked(GtkButton *button, IpodInit *ii) { const gchar *old_dir; gchar *new_dir; g_return_if_fail (ii); - old_dir = gtk_entry_get_text ( - GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY))); + old_dir = gtk_entry_get_text(GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY))); - new_dir = fileselection_get_file_or_dir ( - _("Select mountpoint"), - old_dir, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + new_dir = fileselection_get_file_or_dir(_("Select mountpoint"), old_dir, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); - if (new_dir) - { - gtk_entry_set_text (GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)), - new_dir); - g_free (new_dir); + if (new_dir) { + gtk_entry_set_text(GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)), new_dir); + g_free(new_dir); } } +static void set_cell(GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { + gboolean header; + gchar *text; + IpodInfo *info; -static void -set_cell (GtkCellLayout *cell_layout, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - gboolean header; - gchar *text; - IpodInfo *info; - - gtk_tree_model_get (tree_model, iter, COL_POINTER, &info, -1); - g_return_if_fail (info); - - header = gtk_tree_model_iter_has_child (tree_model, iter); - - if (header) - { - text = g_strdup ( - itdb_info_get_ipod_generation_string (info->ipod_generation)); - } - else - { - if (info->capacity >= 1) - { /* size in GB */ - text = g_strdup_printf ("%2.0f GB %s (x%s)", - info->capacity, - itdb_info_get_ipod_model_name_string ( - info->ipod_model), - info->model_number); - } - else if (info->capacity > 0) - { /* size in MB */ - text = g_strdup_printf ("%3.0f MB %s (x%s)", - info->capacity * 1024, - itdb_info_get_ipod_model_name_string ( - info->ipod_model), - info->model_number); - } - else - { /* no capacity information available */ - text = g_strdup_printf ("%s (x%s)", - itdb_info_get_ipod_model_name_string ( - info->ipod_model), - info->model_number); - } - } - - g_object_set (cell, - "sensitive", !header, - "text", text, - NULL); - - g_free (text); -} + gtk_tree_model_get(tree_model, iter, COL_POINTER, &info, -1); + g_return_if_fail (info); + + header = gtk_tree_model_iter_has_child(tree_model, iter); + + if (header) { + text = g_strdup(itdb_info_get_ipod_generation_string(info->ipod_generation)); + } + else { + if (info->capacity >= 1) { /* size in GB */ + text + = g_strdup_printf("%2.0f GB %s (x%s)", info->capacity, itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number); + } + else if (info->capacity > 0) { /* size in MB */ + text + = g_strdup_printf("%3.0f MB %s (x%s)", info->capacity * 1024, itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number); + } + else { /* no capacity information available */ + text + = g_strdup_printf("%s (x%s)", itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number); + } + } + g_object_set(cell, "sensitive", !header, "text", text, NULL); + g_free(text); +} /** * gp_init_model_number_combo: @@ -159,8 +122,7 @@ set_cell (GtkCellLayout *cell_layout, * * @cb: the combobox that should be set up with a model. */ -void gp_init_model_number_combo (GtkComboBox *cb) -{ +void gp_init_model_number_combo(GtkComboBox *cb) { const IpodInfo *table; Itdb_IpodGeneration generation; GtkCellRenderer *renderer; @@ -168,69 +130,54 @@ void gp_init_model_number_combo (GtkComboBox *cb) gboolean info_found; gchar buf[PATH_MAX]; - table = itdb_info_get_ipod_info_table (); + table = itdb_info_get_ipod_info_table(); g_return_if_fail (table); /* We need the G_TYPE_STRING column because GtkComboBoxEntry - requires it */ - store = gtk_tree_store_new (2, G_TYPE_POINTER, G_TYPE_STRING); - + requires it */ + store = gtk_tree_store_new(2, G_TYPE_POINTER, G_TYPE_STRING); /* Create a tree model with the model numbers listed as a branch - under each generation */ + under each generation */ generation = ITDB_IPOD_GENERATION_FIRST; - do - { - GtkTreeIter iter; - const IpodInfo *info = table; - info_found = FALSE; - - while (info->model_number) - { - if (info->ipod_generation == generation) - { - GtkTreeIter iter_child; - if (!info_found) - { - gtk_tree_store_append (store, &iter, NULL); - gtk_tree_store_set (store, &iter, - COL_POINTER, info, - COL_STRING, "", - -1); - info_found = TRUE; - } - 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, PATH_MAX, "x%s", info->model_number); - gtk_tree_store_set (store, &iter_child, - COL_POINTER, info, - COL_STRING, buf, - -1); - } - ++info; - } - ++generation; - } while (info_found); + do { + GtkTreeIter iter; + const IpodInfo *info = table; + info_found = FALSE; + + while (info->model_number) { + if (info->ipod_generation == generation) { + GtkTreeIter iter_child; + if (!info_found) { + gtk_tree_store_append(store, &iter, NULL); + gtk_tree_store_set(store, &iter, COL_POINTER, info, COL_STRING, "", -1); + info_found = TRUE; + } + 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, PATH_MAX, "x%s", info->model_number); + gtk_tree_store_set(store, &iter_child, COL_POINTER, info, COL_STRING, buf, -1); + } + ++info; + } + ++generation; + } + while (info_found); /* 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) */ - 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), - COL_STRING); - gtk_cell_layout_clear (GTK_CELL_LAYOUT (cb)); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cb), renderer, FALSE); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cb), - renderer, - set_cell, - NULL, NULL); + layout (glade seems to automatically add a text column which + messes up the entire layout) */ + 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), COL_STRING); + gtk_cell_layout_clear(GTK_CELL_LAYOUT (cb)); + + renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (cb), renderer, FALSE); + gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT (cb), renderer, set_cell, NULL, NULL); } - /** * gp_ipod_init: * @@ -240,8 +187,7 @@ void gp_init_model_number_combo (GtkComboBox *cb) * @itdb: itdb from where to extract the mountpoint. After * initialisation the model number is set. */ -gboolean gp_ipod_init (iTunesDB *itdb) -{ +gboolean gp_ipod_init(iTunesDB *itdb) { IpodInit *ii; gint response; gboolean result = FALSE; @@ -257,143 +203,116 @@ gboolean gp_ipod_init (iTunesDB *itdb) /* Create window */ ii = g_new0 (IpodInit, 1); ii->itdb = itdb; - ii->xml = gtkpod_xml_new (gtkpod_get_glade_xml(), "ipod_init_dialog"); + ii->xml = gtkpod_xml_new(gtkpod_get_glade_xml(), "ipod_init_dialog"); - ii->window = gtkpod_xml_get_widget (ii->xml, - "ipod_init_dialog"); + ii->window = gtkpod_xml_get_widget(ii->xml, "ipod_init_dialog"); g_return_val_if_fail (ii->window, FALSE); /* Set mountpoint */ - mountpoint = get_itdb_prefs_string (itdb, KEY_MOUNTPOINT); - if (mountpoint) - { - gtk_entry_set_text (GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)), - mountpoint); + mountpoint = get_itdb_prefs_string(itdb, KEY_MOUNTPOINT); + if (mountpoint) { + gtk_entry_set_text(GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)), mountpoint); } /* Signal handlers */ g_signal_connect (GET_WIDGET (IID_MOUNTPOINT_BUTTON), "clicked", - G_CALLBACK (mountpoint_button_clicked), ii); - + G_CALLBACK (mountpoint_button_clicked), ii); /* Setup model number combo */ cb = GTK_COMBO_BOX (GET_WIDGET (IID_MODEL_COMBO)); - gp_init_model_number_combo (cb); + gp_init_model_number_combo(cb); /* If available set current model number, otherwise indicate that - none is available */ + none is available */ /* If available set current model number, otherwise indicate that - none is available */ - info = itdb_device_get_ipod_info (itdb->device); - if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN)) - { - g_snprintf (buf, PATH_MAX, "x%s", info->model_number); + none is available */ + info = itdb_device_get_ipod_info(itdb->device); + if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN)) { + g_snprintf(buf, PATH_MAX, "x%s", info->model_number); } - else - { - model = get_itdb_prefs_string (itdb, KEY_IPOD_MODEL); - if (model && (strlen (g_strstrip (model)) != 0)) - { - g_snprintf (buf, PATH_MAX, "%s", model); - g_free (model); - } - else - { - g_snprintf (buf, PATH_MAX, "%s", gettext (SELECT_OR_ENTER_YOUR_MODEL)); - } + else { + model = get_itdb_prefs_string(itdb, KEY_IPOD_MODEL); + if (model && (strlen(g_strstrip (model)) != 0)) { + g_snprintf(buf, PATH_MAX, "%s", model); + g_free(model); + } + 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); + gtk_entry_set_text(entry, buf); - response = gtk_dialog_run (GTK_DIALOG (ii->window)); + response = gtk_dialog_run(GTK_DIALOG (ii->window)); - switch (response) - { + switch (response) { case GTK_RESPONSE_OK: - new_mount = g_strdup ( - gtk_entry_get_text ( - GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)))); - /* remove trailing '/' in case it's present. */ - if (mountpoint && (strlen (mountpoint) > 0)) - { - if (G_IS_DIR_SEPARATOR(mountpoint[strlen(mountpoint) - 1])) - { - mountpoint[strlen(mountpoint) - 1] = 0; - } - } - if (new_mount && (strlen (new_mount) > 0)) - { - if (G_IS_DIR_SEPARATOR(new_mount[strlen(new_mount) - 1])) - { - new_mount[strlen(new_mount) - 1] = 0; - } - } - if (!(mountpoint && new_mount && - (strcmp (mountpoint, new_mount) == 0))) - { /* mountpoint has changed */ - g_free (mountpoint); - mountpoint = new_mount; - new_mount = NULL; - set_itdb_prefs_string (itdb, KEY_MOUNTPOINT, mountpoint); - call_script ("gtkpod.load", mountpoint, NULL); - itdb_set_mountpoint (itdb, mountpoint); - } - else - { - g_free (new_mount); - new_mount = NULL; - } - model = gtk_combo_box_get_active_text ( - GTK_COMBO_BOX (GET_WIDGET (IID_MODEL_COMBO))); - if ((strcmp (model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) || - (strlen (model) == 0)) - { /* User didn't choose a model */ - g_free (model); - model = NULL; - } - - /* Set model in the prefs system */ - set_itdb_prefs_string (itdb, KEY_IPOD_MODEL, model); - - name = get_itdb_prefs_string (itdb, "name"); - result = itdb_init_ipod (mountpoint, model, name, &error); - if (!result) - { - if (error) - { - gtkpod_warning (_("Error initialising iPod: %s\n"), - error->message); - g_error_free (error); - error = NULL; - } - else - { - gtkpod_warning (_("Error initialising iPod, unknown error\n")); - } - } - g_free (name); - g_free (model); - break; + new_mount = g_strdup(gtk_entry_get_text(GTK_ENTRY (GET_WIDGET (IID_MOUNTPOINT_ENTRY)))); + /* remove trailing '/' in case it's present. */ + if (mountpoint && (strlen(mountpoint) > 0)) { + if (G_IS_DIR_SEPARATOR(mountpoint[strlen(mountpoint) - 1])) { + mountpoint[strlen(mountpoint) - 1] = 0; + } + } + if (new_mount && (strlen(new_mount) > 0)) { + if (G_IS_DIR_SEPARATOR(new_mount[strlen(new_mount) - 1])) { + new_mount[strlen(new_mount) - 1] = 0; + } + } + if (!(mountpoint && new_mount && (strcmp(mountpoint, new_mount) == 0))) { /* mountpoint has changed */ + g_free(mountpoint); + mountpoint = new_mount; + new_mount = NULL; + set_itdb_prefs_string(itdb, KEY_MOUNTPOINT, mountpoint); + call_script("gtkpod.load", mountpoint, NULL); + itdb_set_mountpoint(itdb, mountpoint); + } + else { + g_free(new_mount); + new_mount = NULL; + } + model = gtk_combo_box_get_active_text(GTK_COMBO_BOX (GET_WIDGET (IID_MODEL_COMBO))); + if ((strcmp(model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) || (strlen(model) == 0)) { /* User didn't choose a model */ + g_free(model); + model = NULL; + } + + /* Set model in the prefs system */ + set_itdb_prefs_string(itdb, KEY_IPOD_MODEL, model); + + name = get_itdb_prefs_string(itdb, "name"); + result = itdb_init_ipod(mountpoint, model, name, &error); + if (!result) { + if (error) { + gtkpod_warning(_("Error initialising iPod: %s\n"), error->message); + g_error_free(error); + error = NULL; + } + else { + gtkpod_warning(_("Error initialising iPod, unknown error\n")); + } + } + g_free(name); + g_free(model); + break; default: - /* canceled -- do nothing */ - break; + /* canceled -- do nothing */ + break; } - gtk_widget_destroy (ii->window); + gtk_widget_destroy(ii->window); - g_free (mountpoint); + g_free(mountpoint); - g_free (ii); + g_free(ii); return result; } - /* Redefine shortcut to reference widgets.*/ #undef GET_WIDGET #define GET_WIDGET(a) gtkpod_xml_get_widget (xml,a) - /** * gp_ipod_init_set_model: * @@ -403,8 +322,7 @@ gboolean gp_ipod_init (iTunesDB *itdb) * @itdb: the itdb to set * @old_model: the model number string to initially propose. */ -void gp_ipod_init_set_model (iTunesDB *itdb, const gchar *old_model) -{ +void gp_ipod_init_set_model(iTunesDB *itdb, const gchar *old_model) { GladeXML *xml; GtkWidget *window; gint response; @@ -417,74 +335,65 @@ void gp_ipod_init_set_model (iTunesDB *itdb, const gchar *old_model) g_return_if_fail (itdb); /* Create window */ - xml = gtkpod_xml_new (gtkpod_get_glade_xml(), "set_ipod_model_dialog"); + xml = gtkpod_xml_new(gtkpod_get_glade_xml(), "set_ipod_model_dialog"); window = GET_WIDGET ("set_ipod_model_dialog"); g_return_if_fail (window); /* Set up label */ - mountpoint = get_itdb_prefs_string (itdb, KEY_MOUNTPOINT); + mountpoint = get_itdb_prefs_string(itdb, KEY_MOUNTPOINT); g_return_if_fail (mountpoint); - g_snprintf (buf, PATH_MAX, _("<b>Please select your iPod model at </b><i>%s</i>"), mountpoint); - gtk_label_set_markup (GTK_LABEL (GET_WIDGET (SIMD_LABEL)), buf); - g_free (mountpoint); + g_snprintf(buf, PATH_MAX, _("<b>Please select your iPod model at </b><i>%s</i>"), mountpoint); + gtk_label_set_markup(GTK_LABEL (GET_WIDGET (SIMD_LABEL)), buf); + g_free(mountpoint); /* Setup model number combo */ cb = GTK_COMBO_BOX (GET_WIDGET (SIMD_MODEL_COMBO)); - gp_init_model_number_combo (cb); + gp_init_model_number_combo(cb); /* If available set current model number, otherwise indicate that - none is available */ - info = itdb_device_get_ipod_info (itdb->device); - if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN)) - { - g_snprintf (buf, PATH_MAX, "x%s", info->model_number); + none is available */ + info = itdb_device_get_ipod_info(itdb->device); + if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN)) { + g_snprintf(buf, PATH_MAX, "x%s", info->model_number); } - else - { - model = get_itdb_prefs_string (itdb, KEY_IPOD_MODEL); - if (model && (strlen (g_strstrip (model)) != 0)) - { - g_snprintf (buf, PATH_MAX, "%s", model); - g_free (model); - } - else - { - g_snprintf (buf, PATH_MAX, "%s", gettext (SELECT_OR_ENTER_YOUR_MODEL)); - } + else { + model = get_itdb_prefs_string(itdb, KEY_IPOD_MODEL); + if (model && (strlen(g_strstrip (model)) != 0)) { + g_snprintf(buf, PATH_MAX, "%s", model); + g_free(model); + } + 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); + gtk_entry_set_text(entry, buf); - response = gtk_dialog_run (GTK_DIALOG (window)); + response = gtk_dialog_run(GTK_DIALOG (window)); - switch (response) - { + switch (response) { case GTK_RESPONSE_OK: - model = gtk_combo_box_get_active_text ( - GTK_COMBO_BOX (GET_WIDGET (SIMD_MODEL_COMBO))); - if (!model) - { - gtkpod_warning (_("Could not determine the model you selected -- this could be a bug or incompatibilty in the GTK+ or glade library.\n\n")); - } - else if (strcmp (model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) - { /* User didn't choose a model */ - g_free (model); - model = NULL; - } - if (model) - { - /* Set model in the prefs system */ - set_itdb_prefs_string (itdb, KEY_IPOD_MODEL, model); - /* Set the model on the iPod */ - itdb_device_set_sysinfo (itdb->device, "ModelNumStr", model); - g_free (model); - } - break; + model = gtk_combo_box_get_active_text(GTK_COMBO_BOX (GET_WIDGET (SIMD_MODEL_COMBO))); + if (!model) { + gtkpod_warning(_("Could not determine the model you selected -- this could be a bug or incompatibilty in the GTK+ or glade library.\n\n")); + } + else if (strcmp(model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) { /* User didn't choose a model */ + g_free(model); + model = NULL; + } + if (model) { + /* Set model in the prefs system */ + set_itdb_prefs_string(itdb, KEY_IPOD_MODEL, model); + /* Set the model on the iPod */ + itdb_device_set_sysinfo(itdb->device, "ModelNumStr", model); + g_free(model); + } + break; default: - /* canceled -- do nothing */ - break; + /* canceled -- do nothing */ + break; } - gtk_widget_destroy (window); + gtk_widget_destroy(window); } ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2