diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2013-09-13 10:56:30 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-09-13 10:56:30 +0800 |
commit | 713b07d75c924f989a8bab0cab9d640dec35b180 (patch) | |
tree | 8fe2f44528ff0cabe745c33edd842b377534555c | |
parent | e131748ff7a62f6e82b7402452450019642538ec (diff) | |
download | gsoc2013-libgnome-autoar-713b07d75c924f989a8bab0cab9d640dec35b180.tar.gz gsoc2013-libgnome-autoar-713b07d75c924f989a8bab0cab9d640dec35b180.tar.zst gsoc2013-libgnome-autoar-713b07d75c924f989a8bab0cab9d640dec35b180.zip |
AutoarCreate: Reduce progress signal frequency by setting minimal interval
-rw-r--r-- | gnome-autoar/autoar-create.c | 77 | ||||
-rw-r--r-- | gnome-autoar/autoar-create.h | 4 |
2 files changed, 53 insertions, 28 deletions
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c index f5a16a8..9580dc7 100644 --- a/gnome-autoar/autoar-create.c +++ b/gnome-autoar/autoar-create.c @@ -66,6 +66,8 @@ struct _AutoarCreatePrivate guint files; guint completed_files; + gint64 notify_last; + gint64 notify_interval; AutoarPref *arpref; GOutputStream *ostream; @@ -108,7 +110,8 @@ enum PROP_COMPLETED_SIZE, PROP_FILES, PROP_COMPLETED_FILES, - PROP_OUTPUT_IS_DEST + PROP_OUTPUT_IS_DEST, + PROP_NOTIFY_INTERVAL }; static guint autoar_create_signals[LAST_SIGNAL] = { 0 }; @@ -153,6 +156,9 @@ autoar_create_get_property (GObject *object, case PROP_OUTPUT_IS_DEST: g_value_set_boolean (value, priv->output_is_dest); break; + case PROP_NOTIFY_INTERVAL: + g_value_set_int64 (value, priv->notify_interval); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -204,6 +210,9 @@ autoar_create_set_property (GObject *object, case PROP_OUTPUT_IS_DEST: priv->output_is_dest = g_value_get_boolean (value); break; + case PROP_NOTIFY_INTERVAL: + priv->notify_interval = g_value_get_int64 (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -273,6 +282,13 @@ autoar_create_get_output_is_dest (AutoarCreate *arcreate) return arcreate->priv->output_is_dest; } +gint64 +autoar_create_get_notify_interval (AutoarCreate *arcreate) +{ + g_return_val_if_fail (AUTOAR_IS_CREATE (arcreate), G_MININT64); + return arcreate->priv->notify_interval; +} + void autoar_create_set_size (AutoarCreate *arcreate, guint64 size) @@ -315,6 +331,15 @@ autoar_create_set_output_is_dest (AutoarCreate *arcreate, arcreate->priv->output_is_dest = output_is_dest; } +void +autoar_create_set_notify_interval (AutoarCreate *arcreate, + gint64 notify_interval) +{ + g_return_if_fail (AUTOAR_IS_CREATE (arcreate)); + g_return_if_fail (notify_interval >= 0); + arcreate->priv->notify_interval = notify_interval; +} + static void autoar_create_dispose (GObject *object) { @@ -500,10 +525,15 @@ autoar_create_signal_decide_dest (AutoarCreate *arcreate) static inline void autoar_create_signal_progress (AutoarCreate *arcreate) { - autoar_common_g_signal_emit (arcreate, arcreate->priv->in_thread, - autoar_create_signals[PROGRESS], 0, - arcreate->priv->completed_size, - arcreate->priv->completed_files); + gint64 mtime; + mtime = g_get_monotonic_time (); + if (mtime - arcreate->priv->notify_last >= arcreate->priv->notify_interval) { + autoar_common_g_signal_emit (arcreate, arcreate->priv->in_thread, + autoar_create_signals[PROGRESS], 0, + arcreate->priv->completed_size, + arcreate->priv->completed_files); + arcreate->priv->notify_last = mtime; + } } static inline void @@ -962,8 +992,18 @@ autoar_create_class_init (AutoarCreateClass *klass) "Whether output file is used as destination", FALSE, G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_NOTIFY_INTERVAL, + g_param_spec_int64 ("notify-interval", + "Notify interval", + "Minimal time interval between progress signal", + 0, G_MAXINT64, 100000, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + autoar_create_signals[DECIDE_DEST] = g_signal_new ("decide-dest", type, @@ -1027,20 +1067,11 @@ autoar_create_init (AutoarCreate *arcreate) priv = AUTOAR_CREATE_GET_PRIVATE (arcreate); arcreate->priv = priv; - priv->source = NULL; - priv->output = NULL; - - priv->source_file = NULL; - priv->output_file = NULL; - priv->size = 0; priv->completed_size = 0; - priv->files = 0; priv->completed_files = 0; - priv->arpref = NULL; - priv->ostream = NULL; priv->buffer_size = BUFFER_SIZE; priv->buffer = g_new (char, priv->buffer_size); @@ -1057,7 +1088,6 @@ autoar_create_init (AutoarCreate *arcreate) priv->in_thread = FALSE; priv->prepend_basename = FALSE; - priv->output_is_dest = FALSE; } static AutoarCreate* @@ -1065,7 +1095,6 @@ autoar_create_new_full (const char **source, GFile **source_file, const char *output, GFile *output_file, - gboolean output_is_dest, AutoarPref *arpref) { AutoarCreate *arcreate; @@ -1109,7 +1138,7 @@ autoar_create_new_full (const char **source, "source-file", gen_source_file, "output", output != NULL ? output : gen_output, "output-file", output_file != NULL ? output_file : gen_output_file, - "output-is-dest", output_is_dest, NULL); + NULL); arcreate->priv->arpref = g_object_ref (arpref); g_strfreev ((char**)gen_source); @@ -1143,8 +1172,7 @@ autoar_create_new (AutoarPref *arpref, va_end (ap); arcreate = autoar_create_new_full ((const char**) strv->pdata, NULL, - output, NULL, - FALSE, arpref); + output, NULL, arpref); g_ptr_array_unref (strv); return arcreate; } @@ -1169,8 +1197,7 @@ autoar_create_new_file (AutoarPref *arpref, va_end (ap); arcreate = autoar_create_new_full (NULL, (GFile**)filev->pdata, - NULL, output_file, - FALSE, arpref); + NULL, output_file, arpref); g_ptr_array_unref (filev); return arcreate; } @@ -1184,9 +1211,7 @@ autoar_create_newv (AutoarPref *arpref, g_return_val_if_fail (*source != NULL, NULL); g_return_val_if_fail (output != NULL, NULL); - return autoar_create_new_full (source, NULL, - output, NULL, - FALSE, arpref); + return autoar_create_new_full (source, NULL, output, NULL, arpref); } @@ -1199,9 +1224,7 @@ autoar_create_new_filev (AutoarPref *arpref, g_return_val_if_fail (*source_file != NULL, NULL); g_return_val_if_fail (output_file != NULL, NULL); - return autoar_create_new_full (NULL, source_file, - NULL, output_file, - FALSE, arpref); + return autoar_create_new_full (NULL, source_file, NULL, output_file, arpref); } static void diff --git a/gnome-autoar/autoar-create.h b/gnome-autoar/autoar-create.h index 6e5288c..43dcfb4 100644 --- a/gnome-autoar/autoar-create.h +++ b/gnome-autoar/autoar-create.h @@ -99,6 +99,7 @@ guint64 autoar_create_get_completed_size (AutoarCreate *arcreate); guint autoar_create_get_files (AutoarCreate *arcreate); guint autoar_create_get_completed_files (AutoarCreate *arcreate); gboolean autoar_create_get_output_is_dest (AutoarCreate *arcreate); +gint64 autoar_create_get_notify_interval (AutoarCreate *arcreate); void autoar_create_set_size (AutoarCreate *arcreate, guint64 size); @@ -110,7 +111,8 @@ void autoar_create_set_completed_files (AutoarCreate *arcreate, guint completed_files); void autoar_create_set_output_is_dest (AutoarCreate *arcreate, gboolean output_is_dest); - +void autoar_create_set_notify_interval (AutoarCreate *arcreate, + gint64 notify_interval); G_END_DECLS #endif /* AUTOAR_CREATE_H */ |