commit 528bde4c8d5259f25d76a6ee289bbe04cfdfa42b
Author: phantomjinx <[email protected]>
Date: Mon Jan 24 23:04:27 2011 +0000
Adding / Removing files and progress
* file.c
* playlist_display_actions.c
* Improve the ability to save files as addition goes along rather than
trying to do a great save at the end. With a large number of files at
least only the last 9 would be lost with a hang/crash rather than all
of them.
* file_itunesdb.c
* Remove the progress dialog for saving and replace with existing anjuta
progress framework.
* gtkpod_app_iface.*
* anjuta-app.c
* Framework functions for accessing anjuta progress bar.
libgtkpod/file.c | 18 ++--
libgtkpod/file_itunesdb.c | 122 +++----------------
libgtkpod/gtkpod_app_iface.c | 10 ++
libgtkpod/gtkpod_app_iface.h | 4 +
.../playlist_display/playlist_display_actions.c | 7 +
src/anjuta-app.c | 16 +++
6 files changed, 67 insertions(+), 110 deletions(-)
---
diff --git a/libgtkpod/file.c b/libgtkpod/file.c
index 663ab58..c54b84c 100644
--- a/libgtkpod/file.c
+++ b/libgtkpod/file.c
@@ -300,6 +300,7 @@ gboolean add_directory_by_name(iTunesDB *itdb, gchar *name,
Playlist *plitem, gb
block_widgets();
if (dir != NULL) {
G_CONST_RETURN gchar *next;
+ gint count = 0;
do {
next = g_dir_read_name(dir);
if (next != NULL) {
@@ -308,8 +309,16 @@ gboolean add_directory_by_name(iTunesDB *itdb, gchar
*name, Playlist *plitem, gb
result &= add_directory_by_name(itdb, nextfull,
plitem, descend, addtrackfunc, data);
g_free(nextfull);
}
+ count++;
+ if (count == 10) { /* update and save every ten tracks added */
+ gp_save_itdb(itdb);
+ gtkpod_tracks_statusbar_update();
+ count = 0;
+ }
}
while (next != NULL);
+
+ gp_save_itdb(itdb);
g_dir_close(dir);
}
release_widgets();
@@ -1409,8 +1418,6 @@ void update_track_from_file(iTunesDB *itdb, Track *track)
{
"add_track_to_playlist () -- used for dropping tracks at a specific
position in the track view */
gboolean add_track_by_filename(iTunesDB *itdb, gchar *fname, Playlist *plitem,
gboolean descend, AddTrackFunc addtrackfunc, gpointer data) {
- static gint count = 0; /* do a gtkpod_tracks_statusbar_update() every
- 10 tracks */
Track *oldtrack;
gchar str[PATH_MAX];
gchar *basename;
@@ -1569,17 +1576,12 @@ gboolean add_track_by_filename(iTunesDB *itdb, gchar
*fname, Playlist *plitem, g
/* indicate that non-transferred files exist */
data_changed(itdb);
- ++count;
- if (count >= 10) /* update every ten tracks added */
- {
- gtkpod_tracks_statusbar_update();
- count = 0;
- }
}
else { /* !track */
result = FALSE;
}
}
+
while (widgets_blocked && gtk_events_pending())
gtk_main_iteration();
return result;
diff --git a/libgtkpod/file_itunesdb.c b/libgtkpod/file_itunesdb.c
index d640e0e..56e0d6e 100644
--- a/libgtkpod/file_itunesdb.c
+++ b/libgtkpod/file_itunesdb.c
@@ -88,10 +88,7 @@ typedef struct {
gboolean finished; /* background thread has finished */
Track *track; /* Current track */
const gchar *filename; /* Filename to copy/remove */
- /* Widgets for progress dialog */
- GtkWidget *dialog;
- GtkWidget *textlabel;
- GtkProgressBar *progressbar;
+ gdouble current_progress; /* Record of current progress */
} TransferData;
/* Used to keep the "extended information" until the iTunesDB is loaded */
@@ -1147,6 +1144,7 @@ TransferData *transfer_data_new(void) {
transfer_data = g_new0 (TransferData, 1);
transfer_data->mutex = g_mutex_new ();
transfer_data->finished_cond = g_cond_new ();
+ transfer_data->current_progress = 0;
return transfer_data;
}
@@ -1172,24 +1170,6 @@ static gpointer th_remove(gpointer userdata) {
return GINT_TO_POINTER(result);
}
-/* This function is called when the user presses the abort button
- * during transfer_tracks() or delete_tracks() */
-static void file_dialog_abort(TransferData *transfer_data) {
- g_return_if_fail (transfer_data);
-
- g_mutex_lock (transfer_data->mutex);
-
- transfer_data->abort = TRUE;
-
- g_mutex_unlock (transfer_data->mutex);
-}
-
-/* This function is called when the user closes the window */
-static gboolean file_dialog_delete(TransferData *transfer_data) {
- file_dialog_abort(transfer_data);
- return TRUE; /* don't close the window -- let our own code take care of
this */
-}
-
/* check if iPod directory stucture is present */
static gboolean ipod_dirs_present(const gchar *mountpoint) {
gchar *file;
@@ -1216,49 +1196,9 @@ static gboolean ipod_dirs_present(const gchar
*mountpoint) {
return result;
}
-static GtkWidget *create_transfer_information_dialog(TransferData *td) {
- GladeXML *dialog_xml;
- GtkWidget *dialog, *widget;
-
- dialog_xml = gtkpod_xml_new(gtkpod_get_glade_xml(),
"file_transfer_information_dialog");
- glade_xml_signal_autoconnect(dialog_xml);
-
- dialog = gtkpod_xml_get_widget(dialog_xml,
"file_transfer_information_dialog");
- g_return_val_if_fail (dialog, NULL);
-
- /* the window itself */
- td->dialog = dialog;
-
- /* text label */
- td->textlabel = gtkpod_xml_get_widget(dialog_xml, "textlabel");
-
- /* progress bar */
- td->progressbar = GTK_PROGRESS_BAR (
- gtkpod_xml_get_widget (dialog_xml, "progressbar"));
-
- /* Indicate that user wants to abort */
- widget = gtkpod_xml_get_widget(dialog_xml, "abortbutton");
- g_signal_connect_swapped (GTK_OBJECT (widget), "clicked",
- G_CALLBACK (file_dialog_abort),
- td);
-
- /* User tried to close the window */
- g_signal_connect_swapped (GTK_OBJECT (dialog), "delete-event",
- G_CALLBACK (file_dialog_delete),
- td);
-
- /* Set the dialog parent */
- gtk_window_set_transient_for(GTK_WINDOW (dialog), GTK_WINDOW (gtkpod_app));
-
- return dialog;
-}
-
-static void set_progressbar(GtkProgressBar *progressbar, time_t start, gint n,
gint count, gint init_count) {
+static gdouble set_progress(time_t start, gint n, gint count, gint init_count,
gdouble old_fraction) {
gchar *progtext;
- const gchar *progtext_old;
- gdouble fraction, fraction_old;
-
- g_return_if_fail (progressbar);
+ gdouble fraction;
if (n == 0) {
fraction = 1;
@@ -1278,23 +1218,21 @@ static void set_progressbar(GtkProgressBar
*progressbar, time_t start, gint n, g
hrs = fullsecs / 3600;
mins = (fullsecs % 3600) / 60;
secs = ((fullsecs % 60) / 5) * 5;
- /* don't bounce up too quickly (>10% change only) */
- /* left = ((mins < left) || (100*mins >= 110*left)) ? mins : left;*/
progtext
= g_strdup_printf(_("%d%% (%d/%d %d:%02d:%02d left)"), (gint)
(fraction * 100), count, n, (gint) hrs, (gint) mins, (gint) secs);
}
- progtext_old = gtk_progress_bar_get_text(progressbar);
- if (!progtext_old || (strcmp(progtext_old, progtext) != 0)) { /* only
update progressbar text if it has changed */
- gtk_progress_bar_set_text(progressbar, progtext);
- }
- fraction_old = gtk_progress_bar_get_fraction(progressbar);
- if (fraction_old != fraction) { /* only update progressbar fraction if it
has changed */
- gtk_progress_bar_set_fraction(progressbar, fraction);
- }
+ gdouble ticks = fraction - old_fraction;
+ gtkpod_statusbar_increment_progress_ticks(ticks * 100, progtext);
g_free(progtext);
+
+ if (fraction == 1) {
+ gtkpod_statusbar_reset_progress(100);
+ }
+
+ return fraction;
}
/* Removes all tracks that were marked for deletion from the iPod or
@@ -1326,7 +1264,7 @@ static gboolean delete_files(iTunesDB *itdb, TransferData
*td) {
interference with slow access harddisks */
file_transfer_activate(itdb, FALSE);
- gtk_label_set_text(GTK_LABEL (td->textlabel), _("Status: Deleting File"));
+ gtkpod_statusbar_message(_("Status: Deleting File"));
n = g_list_length(eitdb->pending_deletion);
count = 0; /* number of tracks removed */
@@ -1360,7 +1298,7 @@ static gboolean delete_files(iTunesDB *itdb, TransferData
*td) {
do {
GTimeVal gtime;
- set_progressbar(td->progressbar, start, n, count, 0);
+ td->current_progress = set_progress(start, n, count, 0,
td->current_progress);
g_mutex_unlock (td->mutex);
@@ -1395,7 +1333,7 @@ static gboolean delete_files(iTunesDB *itdb, TransferData
*td) {
eitdb->pending_deletion = g_list_delete_link(eitdb->pending_deletion,
eitdb->pending_deletion);
}
- set_progressbar(td->progressbar, start, n, count, 0);
+ td->current_progress = set_progress(start, n, count, 0,
td->current_progress);
while (widgets_blocked && gtk_events_pending())
gtk_main_iteration();
@@ -1437,8 +1375,6 @@ static void transfer_tracks_show_failed(iTunesDB *itdb,
TransferData *td) {
g_return_if_fail (itdb && td);
- gtk_widget_hide(td->dialog);
-
string_transfer = g_string_sized_new(1000);
string_convert = g_string_sized_new(1000);
string = g_string_sized_new(1000);
@@ -1536,14 +1472,10 @@ static gboolean transfer_tracks(iTunesDB *itdb,
TransferData *td) {
do {
gchar *buf;
- const gchar *buf_old;
status
= file_transfer_get_status(itdb, &to_convert_num,
&converting_num, &to_transfer_num, &transferred_num, &failed_num);
- set_progressbar(td->progressbar, start, to_convert_num +
to_transfer_num + failed_num + transferred_num, transferred_num
- + failed_num, transferred_init);
-
if (to_transfer_num > 0) {
buf = g_strdup_printf(_("Status: Copying track"));
}
@@ -1556,15 +1488,9 @@ static gboolean transfer_tracks(iTunesDB *itdb,
TransferData *td) {
}
}
- /* buf = g_strdup_printf (_("Status: %d. To convert: %d. To
transfer: %d\n"
- "Transferred: %d. Failed: %d"),
- status, to_convert_num, to_transfer_num,
- transferred_num, failed_num);*/
- buf_old = gtk_label_get_text(GTK_LABEL(td->textlabel));
- if (!buf_old || (strcmp(buf_old, buf) != 0)) { /* only set label if it
has changed */
- gtk_label_set_text(GTK_LABEL(td->textlabel), buf);
- }
- g_free(buf);
+ gtkpod_statusbar_message(buf);
+ td->current_progress = set_progress(start, to_convert_num +
to_transfer_num + failed_num + transferred_num, transferred_num
+ + failed_num, transferred_init, td->current_progress);
if ((to_convert_num != 0) && (converting_num == 0)) { /* Force the
conversion to continue. Not sure if this scenario
* is likely to happen, but better be safe then sorry */
@@ -1589,8 +1515,6 @@ static gboolean transfer_tracks(iTunesDB *itdb,
TransferData *td) {
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.",
@@ -1622,7 +1546,6 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
gchar *cfgdir;
gboolean success = TRUE;
ExtraiTunesDBData *eitdb;
- GtkWidget *dialog;
Playlist *mpl;
TransferData *transferdata;
GList *it;
@@ -1680,8 +1603,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
block_widgets();
transferdata = transfer_data_new();
- dialog = create_transfer_information_dialog(transferdata);
- gtk_widget_show(dialog);
+ gtkpod_statusbar_reset_progress(100);
if ((itdb->usertype & GP_ITDB_TYPE_IPOD) && !get_offline(itdb)) {
const gchar *mountpoint = itdb_get_mountpoint(itdb);
@@ -1712,10 +1634,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
}
if (success) {
- gchar *buf;
- buf = g_strdup_printf(_("Now writing database '%s'. Please wait..."),
mpl->name);
- gtk_label_set_text(GTK_LABEL (transferdata->textlabel), buf);
- g_free(buf);
+ gtkpod_statusbar_message(_("Now writing database '%s'. Please
wait..."), mpl->name);
while (widgets_blocked && gtk_events_pending())
gtk_main_iteration();
@@ -1871,7 +1790,6 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
g_free(cfgdir);
- gtk_widget_destroy(dialog);
transfer_data_free(transferdata);
release_widgets();
diff --git a/libgtkpod/gtkpod_app_iface.c b/libgtkpod/gtkpod_app_iface.c
index e5e66db..c97dde6 100644
--- a/libgtkpod/gtkpod_app_iface.c
+++ b/libgtkpod/gtkpod_app_iface.c
@@ -184,6 +184,16 @@ gint gtkpod_cleanup_quit() {
return FALSE; // dont quit!
}
+void gtkpod_statusbar_reset_progress(gint total) {
+ g_return_if_fail (GTKPOD_IS_APP(gtkpod_app));
+ GTKPOD_APP_GET_INTERFACE
(gtkpod_app)->statusbar_reset_progress(gtkpod_app, total);
+}
+
+void gtkpod_statusbar_increment_progress_ticks(gint ticks, gchar* text) {
+ g_return_if_fail (GTKPOD_IS_APP(gtkpod_app));
+ GTKPOD_APP_GET_INTERFACE
(gtkpod_app)->statusbar_increment_progress_ticks(gtkpod_app, ticks, text);
+}
+
void gtkpod_statusbar_message(gchar* message, ...) {
g_return_if_fail (GTKPOD_IS_APP(gtkpod_app));
gchar* msg;
diff --git a/libgtkpod/gtkpod_app_iface.h b/libgtkpod/gtkpod_app_iface.h
index ab6ddaa..64b5e98 100644
--- a/libgtkpod/gtkpod_app_iface.h
+++ b/libgtkpod/gtkpod_app_iface.h
@@ -142,6 +142,8 @@ struct _GtkPodAppInterface {
GHashTable *filetypes;
void (*itdb_updated)(GtkPodApp *obj, iTunesDB *oldItdb, iTunesDB *newItbd);
+ void (*statusbar_reset_progress)(GtkPodApp *obj, gint total);
+ void (*statusbar_increment_progress_ticks)(GtkPodApp *obj, gint ticks,
gchar* text);
void (*statusbar_message)(GtkPodApp *obj, gchar* message, ...);
void (*gtkpod_warning)(GtkPodApp *obj, gchar *message, ...);
void (*gtkpod_warning_hig)(GtkPodApp *obj, GtkMessageType icon, const
gchar *primary_text, const gchar *secondary_text);
@@ -166,6 +168,8 @@ gchar* gtkpod_get_glade_xml();
gboolean ok_to_close_gtkpod();
gint gtkpod_cleanup_quit();
+void gtkpod_statusbar_reset_progress(gint total);
+void gtkpod_statusbar_increment_progress_ticks(gint ticks, gchar* text);
void gtkpod_statusbar_message(gchar* message, ...);
void gtkpod_statusbar_busy_push();
void gtkpod_statusbar_busy_pop();
diff --git a/plugins/playlist_display/playlist_display_actions.c
b/plugins/playlist_display/playlist_display_actions.c
index df44af7..5387c41 100644
--- a/plugins/playlist_display/playlist_display_actions.c
+++ b/plugins/playlist_display/playlist_display_actions.c
@@ -232,6 +232,7 @@ static void create_add_playlists_dialog(iTunesDB *itdb) {
}
static void fileselection_add_files(GSList* names, Playlist *playlist) {
+ gint count = 0;
GSList* gsl; /* Current node in list */
gboolean result = TRUE; /* Result of file adding */
@@ -245,6 +246,12 @@ static void fileselection_add_files(GSList* names,
Playlist *playlist) {
for (gsl = names; gsl; gsl = gsl->next) {
result
&= add_track_by_filename(playlist->itdb, gsl->data, playlist,
prefs_get_int("add_recursively"), NULL, NULL);
+ count++;
+ if (count == 10) { /* update and save every ten tracks added */
+ gp_save_itdb(playlist->itdb);
+ gtkpod_tracks_statusbar_update();
+ count = 0;
+ }
}
/* clear log of non-updated tracks */
diff --git a/src/anjuta-app.c b/src/anjuta-app.c
index 4819af8..9aeb155 100644
--- a/src/anjuta-app.c
+++ b/src/anjuta-app.c
@@ -973,6 +973,20 @@ static void anjuta_shell_iface_init(AnjutaShellIface
*iface) {
* -- GtkPodAppInterface implementations --
* -------------------------------------------------------------------------
*/
+
+static void anjuta_gtkpod_statusbar_reset_progress(GtkPodApp *obj, gint total)
{
+ g_return_if_fail(ANJUTA_IS_APP(gtkpod_app));
+ AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app),
NULL);
+ anjuta_status_progress_reset (status);
+ anjuta_status_progress_add_ticks (status, total);
+}
+
+static void anjuta_gtkpod_statusbar_increment_progress_ticks(GtkPodApp *obj,
gint ticks, gchar* text) {
+ g_return_if_fail(ANJUTA_IS_APP(gtkpod_app));
+ AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app),
NULL);
+ anjuta_status_progress_increment_ticks(status, ticks, text);
+}
+
static void anjuta_gtkpod_app_statusbar_message(GtkPodApp *gtkpod_app, gchar*
message, ...) {
g_return_if_fail(ANJUTA_IS_APP(gtkpod_app));
@@ -1439,6 +1453,8 @@ static GtkResponseType
anjuta_gtkpod_app_confirmation(GtkPodApp *obj, gint id, g
}
static void gtkpod_app_iface_init(GtkPodAppInterface *iface) {
+ iface->statusbar_reset_progress = anjuta_gtkpod_statusbar_reset_progress;
+ iface->statusbar_increment_progress_ticks =
anjuta_gtkpod_statusbar_increment_progress_ticks;
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;
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2