[gnac/devel] Code refactoring
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code refactoring
- Date: Mon, 12 Dec 2011 17:31:09 +0000 (UTC)
commit 86504ca194c425d6655d589116aca88c154e8b2b
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sat Dec 10 20:23:00 2011 +0000
Code refactoring
src/gnac-file-list.c | 19 ++++++++-----------
src/gnac-stock-items.c | 3 +--
src/gnac-ui.c | 20 ++++++++------------
src/profiles/gnac-profiles.c | 18 +++++++++---------
src/profiles/gnac-profiles.h | 3 ---
5 files changed, 26 insertions(+), 37 deletions(-)
---
diff --git a/src/gnac-file-list.c b/src/gnac-file-list.c
index 5174d35..5fd6acc 100644
--- a/src/gnac-file-list.c
+++ b/src/gnac-file-list.c
@@ -207,22 +207,19 @@ gnac_file_list_get(GtkTreeRowReference *reference,
{
g_return_val_if_fail(reference, FALSE);
- GtkTreeIter iter;
GtkTreePath *path = gtk_tree_row_reference_get_path(reference);
+ if (!path) return FALSE;
- if (path) {
- gboolean path_exists = gtk_tree_model_get_iter(model, &iter, path);
-
- if (path_exists) {
- gtk_tree_model_get(model, &iter, COL_URI, file_uri, -1);
- }
-
- gtk_tree_path_free(path);
+ GtkTreeIter iter;
+ gboolean path_exists = gtk_tree_model_get_iter(model, &iter, path);
- return path_exists;
+ if (path_exists) {
+ gtk_tree_model_get(model, &iter, COL_URI, file_uri, -1);
}
- return FALSE;
+ gtk_tree_path_free(path);
+
+ return path_exists;
}
diff --git a/src/gnac-stock-items.c b/src/gnac-stock-items.c
index d6fc6b4..6f71ad8 100644
--- a/src/gnac-stock-items.c
+++ b/src/gnac-stock-items.c
@@ -48,8 +48,7 @@ gnac_stock_items_register_icons(void)
gtk_icon_factory_add_default(factory);
guint i;
- for (i = 0; i < G_N_ELEMENTS(gnac_stock_items); i++)
- {
+ for (i = 0; i < G_N_ELEMENTS(gnac_stock_items); i++) {
if (g_str_equal(gnac_stock_items[i].stock_id, GNAC_STOCK_RESUME)) {
GtkIconSet *icon_set;
icon_set = gtk_icon_factory_lookup_default(GTK_STOCK_MEDIA_PLAY);
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 38bea68..9047851 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -375,13 +375,12 @@ static void
gnac_remove_track(gpointer data,
gpointer user_data)
{
- GError *error = NULL;
gchar *uri = NULL;
-
GtkTreeRowReference *ref = (GtkTreeRowReference *) data;
-
gnac_file_list_get(ref, &uri);
+
GFile *file = g_file_new_for_uri(uri);
+ GError *error = NULL;
libgnac_converter_remove(converter, file, &error);
if (error) {
@@ -499,16 +498,13 @@ gnac_ui_file_chooser_response_cb(GtkDialog *dialog,
switch (response) {
/* Add button */
case GTK_RESPONSE_NONE: {
- GSList *list_files = NULL;
- GSList *list_path = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(dialog));
-
- /* Add the differents files */
- g_slist_foreach(list_path,(GFunc) gnac_ui_file_chooser_foreach,
- (gpointer) &list_files);
-
- g_slist_free(list_path);
+ GSList *files = NULL;
+ GSList *paths = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(dialog));
- gnac_add_files(list_files);
+ /* Add the different files */
+ g_slist_foreach(paths, (GFunc) gnac_ui_file_chooser_foreach, &files);
+ g_slist_free(paths);
+ gnac_add_files(files);
/* Do we have to close the file chooser? */
if (!gnac_ui_file_chooser_close_on_add_button_is_active()) return;
diff --git a/src/profiles/gnac-profiles.c b/src/profiles/gnac-profiles.c
index 4cf1dc3..392f943 100755
--- a/src/profiles/gnac-profiles.c
+++ b/src/profiles/gnac-profiles.c
@@ -98,8 +98,8 @@ gnac_profiles_get_name(void)
}
-void
-gnac_profiles_set_current_profile(const gchar *name)
+static void
+gnac_profiles_select_last_used_profile(void)
{
GtkTreeIter iter;
GtkComboBox *combo_profile = GTK_COMBO_BOX(gnac_ui_get_widget("combo_profile"));
@@ -107,17 +107,21 @@ gnac_profiles_set_current_profile(const gchar *name)
gboolean has_next = gtk_tree_model_get_iter_first(model, &iter);
gboolean found = FALSE;
+ gchar *last_used_profile = g_settings_get_string(settings,
+ GNAC_KEY_LAST_USED_PROFILE);
while (has_next && !found) {
AudioProfileGeneric *profile;
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
- if (gnac_utils_str_equal(profile->name, name)) {
+ if (gnac_utils_str_equal(profile->name, last_used_profile)) {
gtk_combo_box_set_active_iter(combo_profile, &iter);
found = TRUE;
}
has_next = gtk_tree_model_iter_next(model, &iter);
}
+ g_free(last_used_profile);
+
if (!found && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) {
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_profile), &iter);
}
@@ -137,9 +141,6 @@ gnac_profiles_populate_combo(void)
return;
}
- gchar *last_used_profile = g_settings_get_string(settings,
- GNAC_KEY_LAST_USED_PROFILE);
-
gtk_widget_set_sensitive(combo_profile, TRUE);
gtk_list_store_clear(model);
@@ -153,13 +154,12 @@ gnac_profiles_populate_combo(void)
gchar *name = gnac_profiles_utils_get_combo_format_name(formatted_name,
profile->extension);
gtk_list_store_append(model, &iter);
- gtk_list_store_set(model, &iter, 0, name, 1, profile, -1);
+ gtk_list_store_set(model, &iter, COL_NAME, name, COL_PROFILE, profile, -1);
}
g_list_free(profiles);
- gnac_profiles_set_current_profile(last_used_profile);
- g_free(last_used_profile);
+ gnac_profiles_select_last_used_profile();
}
diff --git a/src/profiles/gnac-profiles.h b/src/profiles/gnac-profiles.h
index f73bfca..981e473 100755
--- a/src/profiles/gnac-profiles.h
+++ b/src/profiles/gnac-profiles.h
@@ -46,9 +46,6 @@ const gchar *
gnac_profiles_get_name(void);
void
-gnac_profiles_set_current_profile(const gchar *name);
-
-void
gnac_profiles_on_combo_profile_changed(GtkWidget *widget,
gpointer data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]