[gnac/devel] Code refactoring
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code refactoring
- Date: Sat, 10 Dec 2011 15:22:54 +0000 (UTC)
commit 2bb90bf4edb2a144eca65d48d17e05f26042ea05
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sat Dec 10 14:46:25 2011 +0000
Code refactoring
src/gnac-main.c | 106 +++++++++++++++++++++++-------------------------------
src/gnac-utils.c | 1 -
src/gnac-utils.h | 1 +
3 files changed, 46 insertions(+), 62 deletions(-)
---
diff --git a/src/gnac-main.c b/src/gnac-main.c
index 2c6228e..76ca904 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -80,6 +80,9 @@ static const gchar *states[] = {
};
+static void gnac_add(GFile *file);
+
+
static void
gnac_change_state(GnacState new_state)
{
@@ -141,71 +144,53 @@ gnac_return_prev_state(void)
static void
-gnac_add(GFile *file)
+gnac_add_directory(GFile *file)
{
- GFile *child;
- GFileInfo *current_info;
- GFileEnumerator *enumerator;
GError *error = NULL;
-
- if (continue_files_action) {
- switch (g_file_query_file_type(file,
- G_FILE_QUERY_INFO_NONE, NULL)) {
+ GFileEnumerator *enumerator = g_file_enumerate_children(file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (error) {
+ libgnac_debug("%s", error->message);
+ g_clear_error(&error);
+ return;
+ }
- case G_FILE_TYPE_REGULAR:
- gnac_add_file(file);
- break;
+ GFileInfo *info;
+ while ((info = g_file_enumerator_next_file(enumerator, NULL, &error))) {
+ GFile *child = g_file_get_child(file, g_file_info_get_name(info));
+ gnac_add(child);
+ g_object_unref(child);
+ }
- case G_FILE_TYPE_DIRECTORY:
- enumerator = g_file_enumerate_children(file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE ","
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL, &error);
-
- if (error) {
- libgnac_debug("%s", error->message);
- g_clear_error(&error);
- return;
- }
-
- current_info = g_file_enumerator_next_file(enumerator, NULL, &error);
- if (error) {
- libgnac_debug("%s", error->message);
- g_clear_error(&error);
- return;
- }
-
- while (current_info)
- {
- child = g_file_get_child(file, g_file_info_get_name(current_info));
- gnac_add(child);
- g_object_unref(child);
- current_info = g_file_enumerator_next_file(enumerator, NULL, &error);
- if (error) {
- libgnac_debug("%s", error->message);
- g_clear_error(&error);
- return;
- }
- }
+ if (error) {
+ libgnac_debug("%s", error->message);
+ g_clear_error(&error);
+ }
+
+ g_file_enumerator_close(enumerator, NULL, &error);
+ if (error) {
+ libgnac_debug("%s", error->message);
+ g_clear_error(&error);
+ }
+}
- g_file_enumerator_close(enumerator, NULL, &error);
- if (error) {
- libgnac_debug("%s", error->message);
- g_clear_error(&error);
- return;
- }
- break;
- case G_FILE_TYPE_UNKNOWN:
- case G_FILE_TYPE_SYMBOLIC_LINK:
- case G_FILE_TYPE_SPECIAL:
- case G_FILE_TYPE_SHORTCUT:
- case G_FILE_TYPE_MOUNTABLE:
- default:
- /* Nothing is done*/
+static void
+gnac_add(GFile *file)
+{
+ if (!continue_files_action) return;
+
+ switch (g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL)) {
+ case G_FILE_TYPE_REGULAR:
+ gnac_add_file(file);
+ break;
+ case G_FILE_TYPE_DIRECTORY:
+ gnac_add_directory(file);
+ break;
+ default:
+ /* Nothing is done */
break;
- }
}
}
@@ -271,8 +256,7 @@ gnac_add_files(GSList *files)
continue_files_action = TRUE;
gnac_change_state(GNAC_AUDIO_FILE_ACTION_STATE);
file_action_thread = g_thread_create(
- (GThreadFunc) gnac_add_files_thread_entry,
- files, TRUE, &error);
+ (GThreadFunc) gnac_add_files_thread_entry, files, TRUE, &error);
if (error) {
libgnac_debug("Failed to create thread");
libgnac_warning(_("Failed to add files: %s"), error->message);
@@ -478,7 +462,6 @@ gnac_on_converter_progress_cb(LibgnacConverter *converter,
if (progress <= 0) return;
guint64 left = ((time_left / progress) * PROGRESS_TIMEOUT) / 1000;
-
gchar *time_str = gnac_utils_format_duration_for_display(
gnac_utils_moving_avg_add_sample(left));
/* Translators: time left (the format for time is hours:minutes:seconds) */
@@ -670,6 +653,7 @@ gnac_on_ui_pause_cb(GtkWidget *widget,
g_clear_error(&error);
}
+
void
gnac_on_ui_convert_cb(GtkWidget *widget,
gpointer data)
diff --git a/src/gnac-utils.c b/src/gnac-utils.c
index ced7ca0..a55ef61 100644
--- a/src/gnac-utils.c
+++ b/src/gnac-utils.c
@@ -27,7 +27,6 @@
#include "config.h"
#endif
-#include <gio/gio.h>
#include <glib/gi18n.h>
#include "gnac-utils.h"
diff --git a/src/gnac-utils.h b/src/gnac-utils.h
index be4f463..52fb87a 100644
--- a/src/gnac-utils.h
+++ b/src/gnac-utils.h
@@ -26,6 +26,7 @@
#ifndef GNAC_UTILS_H
#define GNAC_UTILS_H
+#include <gio/gio.h>
#include <glib.h>
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]