commit 70c95ce0a00b9d6834bf0c49f1af9cfbf78f7e5f
Author: Javier Kohen <[email protected]>
Date: Mon Mar 7 21:45:46 2011 +0100
Revert "Changed auto-save gating to use time based intervals."
This reverts commit e98b100c7658bf62901e0658339f3344cf0bf9fc.
Conflicts:
libgtkpod/file.c
libgtkpod/file.c | 39 ++++++--------------
libgtkpod/file.h | 2 -
libgtkpod/prefs.c | 4 +-
plugins/core_preferences/core_prefs.c | 4 +-
plugins/core_preferences/core_prefs.xml | 7 ++--
.../playlist_display/playlist_display_actions.c | 9 ++++-
6 files changed, 26 insertions(+), 39 deletions(-)
---
diff --git a/libgtkpod/file.c b/libgtkpod/file.c
index 7efa915..978df40 100644
--- a/libgtkpod/file.c
+++ b/libgtkpod/file.c
@@ -87,28 +87,12 @@ FileType *determine_filetype(const gchar *path) {
return type;
}
-/*
- * Save the database every ${file_saving_time_threshold} seconds. This
- * is useful for checkpointing when importing large batches of files.
- *
- * The caller is responsible for calling gp_save_itdb one last time
- * when done.
- *
- * Args:
- * last_save_time: the time of the last save. Initialize to time(NULL) on
- * the first call.
- */
-void gp_save_if_needed(GTime *last_save_time, iTunesDB *itdb) {
- g_assert(NULL != last_save_time);
- int threshold = prefs_get_int("file_saving_time_threshold");
- GTime next_save_time = *last_save_time + threshold;
- GTime now = (GTime) time(NULL);
- if (now >= next_save_time) {
+static void save_if_needed(gint count, iTunesDB *itdb) {
+ /* save every ${file_threshold} files but do at least ${file_theshold}
first*/
+ int threshold = prefs_get_int("file_saving_threshold");
+ if (count >= threshold && count % threshold == 0) {
gp_save_itdb(itdb);
gtkpod_tracks_statusbar_update();
- /* Use the finishing time as the last save time, so if saving
- is slow, we don't save on every call */
- *last_save_time = time(NULL);
}
}
@@ -163,14 +147,13 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile,
Playlist *plitem, gint p
gchar *dirname = NULL, *plname = NULL;
gchar buf[PATH_MAX];
FileType *type = NULL; /* type of playlist file */
- gint line;
+ gint line, tracks;
FILE *fp;
gboolean error;
g_return_val_if_fail (plfile, FALSE);
g_return_val_if_fail (itdb, FALSE);
- GTime last_save_time = (GTime) time(NULL);
if (g_file_test(plfile, G_FILE_TEST_IS_DIR)) {
gtkpod_warning(_("'%s' is a directory, not a playlist file.\n\n"),
plfile);
return FALSE; /* definitely not! */
@@ -211,6 +194,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile,
Playlist *plitem, gint p
all of these are line based -- add different code for different
playlist files */
line = -1; /* nr of line being read */
+ tracks = 0; /* nr of tracks added */
error = FALSE;
while (!error && fgets(buf, PATH_MAX, fp)) {
gchar *bufp = buf;
@@ -280,7 +264,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile,
Playlist *plitem, gint p
gtkpod_warning(_("Skipping '%s' to avoid adding playlist file
recursively\n"), filename);
}
else if (add_track_by_filename(itdb, filename, plitem,
prefs_get_int("add_recursively"), addtrackfunc, data)) {
- gp_save_if_needed(&last_save_time, itdb);
+ save_if_needed(tracks, itdb);
}
g_free(filename);
}
@@ -304,7 +288,7 @@ add_playlist_by_filename(iTunesDB *itdb, gchar *plfile,
Playlist *plitem, gint p
\*------------------------------------------------------------------*/
-static gint add_directory_by_name_internal(GTime *last_save_time, iTunesDB
*itdb, gchar *name, Playlist *plitem, gboolean descend, gint *filecount,
AddTrackFunc addtrackfunc, gpointer data) {
+static gint add_directory_by_name_internal(iTunesDB *itdb, gchar *name,
Playlist *plitem, gboolean descend, gint *filecount, AddTrackFunc addtrackfunc,
gpointer data) {
gint result = 0;
g_return_val_if_fail (itdb, 0);
@@ -320,7 +304,7 @@ static gint add_directory_by_name_internal(GTime
*last_save_time, iTunesDB *itdb
if (next != NULL) {
gchar *nextfull = g_build_filename(name, next, NULL);
if (descend || !g_file_test(nextfull, G_FILE_TEST_IS_DIR))
{
- result +=
add_directory_by_name_internal(last_save_time, itdb, nextfull, plitem, descend,
filecount, addtrackfunc, data);
+ result += add_directory_by_name_internal(itdb,
nextfull, plitem, descend, filecount, addtrackfunc, data);
}
g_free(nextfull);
}
@@ -334,7 +318,7 @@ static gint add_directory_by_name_internal(GTime
*last_save_time, iTunesDB *itdb
else {
if (add_track_by_filename(itdb, name, plitem, descend, addtrackfunc,
data)) {
*filecount = *filecount + 1;
- gp_save_if_needed(last_save_time, itdb);
+ save_if_needed(*filecount, itdb);
}
result += *filecount;
}
@@ -360,8 +344,7 @@ static gint add_directory_by_name_internal(GTime
*last_save_time, iTunesDB *itdb
gint add_directory_by_name(iTunesDB *itdb, gchar *name, Playlist *plitem,
gboolean descend, AddTrackFunc addtrackfunc, gpointer data) {
/* Uses internal method so that a count parameter can be added for saving
purposes. */
gint filecount = 0;
- GTime last_save_time = (GTime) time(NULL);
- return add_directory_by_name_internal(&last_save_time, itdb, name, plitem,
descend, &filecount, addtrackfunc, data);
+ return add_directory_by_name_internal(itdb, name, plitem, descend,
&filecount, addtrackfunc, data);
}
/*------------------------------------------------------------------*\
diff --git a/libgtkpod/file.h b/libgtkpod/file.h
index 1756404..9c99785 100644
--- a/libgtkpod/file.h
+++ b/libgtkpod/file.h
@@ -34,7 +34,6 @@
# include <config.h>
#endif
-#include <glib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include "itdb.h"
@@ -84,7 +83,6 @@ void gp_load_ipods (void);
iTunesDB *gp_load_ipod (iTunesDB *itdb);
gboolean gp_eject_ipod(iTunesDB *itdb);
gboolean gp_save_itdb (iTunesDB *itdb);
-void gp_save_if_needed(GTime* last_save_time, iTunesDB *itdb);
void handle_export (void);
void data_changed (iTunesDB *itdb);
void data_unchanged (iTunesDB *itdb);
diff --git a/libgtkpod/prefs.c b/libgtkpod/prefs.c
index fb95793..96789db 100644
--- a/libgtkpod/prefs.c
+++ b/libgtkpod/prefs.c
@@ -151,10 +151,10 @@ static void set_default_preferences() {
prefs_set_string("initial_mountpoint", "/media/ipod");
/*
- * When adding files, determines how often a
+ * When adding files, determines after how many a
* save should be performed.
*/
- prefs_set_int("file_saving_time_threshold", 60); /* in seconds */
+ prefs_set_int("file_saving_threshold", 10);
str = g_build_filename(get_script_dir(), CONVERT_TO_MP3_SCRIPT, NULL);
prefs_set_string("path_conv_mp3", str);
diff --git a/plugins/core_preferences/core_prefs.c
b/plugins/core_preferences/core_prefs.c
index 533772c..f7ec7a9 100644
--- a/plugins/core_preferences/core_prefs.c
+++ b/plugins/core_preferences/core_prefs.c
@@ -361,7 +361,7 @@ G_MODULE_EXPORT void
on_video_thumbnailer_changed(GtkEditable *sender, gpointer
glade callback
*/
G_MODULE_EXPORT void on_save_threshold_spin_button_value_changed(GtkSpinButton
*spinbutton, gpointer user_data) {
- prefs_set_int("file_saving_time_threshold",
gtk_spin_button_get_value_as_int (spinbutton));
+ prefs_set_int("file_saving_threshold", gtk_spin_button_get_value_as_int
(spinbutton));
}
/*
@@ -667,7 +667,7 @@ static void setup_values() {
GtkWidget *skip_track_update_radio = GTK_WIDGET(gtk_builder_get_object
(builder, "skip_track_update"));
gtk_spin_button_set_value(GTK_SPIN_BUTTON (gtk_builder_get_object
(builder, "agp_track_count")), prefs_get_int("misc_track_nr"));
- gtk_spin_button_set_value(GTK_SPIN_BUTTON (gtk_builder_get_object
(builder, "save_threshold_spin_button")),
prefs_get_int("file_saving_time_threshold"));
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON (gtk_builder_get_object
(builder, "save_threshold_spin_button")),
prefs_get_int("file_saving_threshold"));
/* Check boxes */
for (i = 0; i < COUNTOF(checkbox_map); i++) {
diff --git a/plugins/core_preferences/core_prefs.xml
b/plugins/core_preferences/core_prefs.xml
index 459265d..a5a2f8d 100644
--- a/plugins/core_preferences/core_prefs.xml
+++ b/plugins/core_preferences/core_prefs.xml
@@ -1609,11 +1609,12 @@ Examples:
<property name="tooltip_text"
translatable="yes">When multiple tracks are added to a repository, should an
error occur then it is likely, without saving all added tracks
will be lost since they are not saved. This preference allows for
-a save operation to be conducted periodically.
+a save operation to be conducted after the number of tracks
+specified.
-The default is 60 seconds, so every minute a save
+The default is 10 so after 10 tracks have been added a save
will be imposed on the repository.</property>
- <property name="label"
translatable="yes">Auto-save every seconds:</property>
+ <property name="label"
translatable="yes">Threshold for import of tracks before a save
triggered:</property>
</object>
<packing>
<property name="expand">False</property>
diff --git a/plugins/playlist_display/playlist_display_actions.c
b/plugins/playlist_display/playlist_display_actions.c
index cc22afc..3f7bf34 100644
--- a/plugins/playlist_display/playlist_display_actions.c
+++ b/plugins/playlist_display/playlist_display_actions.c
@@ -234,21 +234,26 @@ 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 */
+ int threshold = prefs_get_int("file_saving_threshold");
/* If we don't have a playlist to add to, don't add anything */
g_return_if_fail (playlist);
block_widgets();
- GTime last_save_time = (GTime) time(NULL);
gtkpod_statusbar_busy_push();
/* Get the filenames and add them */
for (gsl = names; gsl; gsl = gsl->next) {
result
&= add_track_by_filename(playlist->itdb, gsl->data, playlist,
prefs_get_int("add_recursively"), NULL, NULL);
- gp_save_if_needed(&last_save_time, playlist->itdb);
+ count++;
+ if (count % threshold == 0) { /* update and save every ten tracks
added */
+ gp_save_itdb(playlist->itdb);
+ gtkpod_tracks_statusbar_update();
+ }
}
/* Final save of remaining added tracks */
------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2