[gnac/devel] Code cleanup
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code cleanup
- Date: Sat, 10 Dec 2011 15:22:44 +0000 (UTC)
commit 779aaf2a5a72b5bf39d645e17bf0fb3990bc0fd6
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Sat Dec 10 14:05:40 2011 +0000
Code cleanup
configure.ac | 2 +-
src/gnac-file-list.c | 4 +-
src/gnac-main.c | 75 ++++++--------
src/gnac-options.c | 1 +
src/gnac-prefs.c | 170 +++++++++++++++----------------
src/gnac-prefs.h | 6 -
src/gnac-properties.c | 17 ++--
src/gnac-properties.h | 6 -
src/gnac-ui-utils.c | 11 +--
src/gnac-ui.c | 36 +++----
src/gnac-ui.h | 4 -
src/gnac-utils.c | 34 ++----
src/profiles/gnac-profiles-manager.c | 9 +-
src/profiles/gnac-profiles-properties.c | 8 +-
src/profiles/gnac-profiles-utils.c | 12 +-
src/profiles/gnac-profiles.c | 64 +++---------
16 files changed, 187 insertions(+), 272 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9650eba..f8ae313 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,7 +79,7 @@ AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
dnl Find the UI libraries
-GTK_REQUIRED=2.14
+GTK_REQUIRED=2.16
PKG_CHECK_MODULES(UI, [
gtk+-2.0 >= $GTK_REQUIRED
])
diff --git a/src/gnac-file-list.c b/src/gnac-file-list.c
index cf3c4ae..5174d35 100644
--- a/src/gnac-file-list.c
+++ b/src/gnac-file-list.c
@@ -305,7 +305,7 @@ gnac_file_list_get_current_row(GtkTreeRowReference **reference)
GList *rows_path = gtk_tree_selection_get_selected_rows(selection, &model);
/* select the first selected row*/
- *reference = gtk_tree_row_reference_new(model, (GtkTreePath*)(rows_path->data));
+ *reference = gtk_tree_row_reference_new(model, rows_path->data);
g_list_free_full(rows_path, (GDestroyNotify) gtk_tree_path_free);
@@ -513,7 +513,7 @@ gnac_file_list_update_cursor(void)
{
cursor = gdk_cursor_new(GDK_WATCH);
}
- gdk_window_set_cursor(GTK_WIDGET(view)->window, cursor);
+ gdk_window_set_cursor(gtk_tree_view_get_bin_window(view), cursor);
}
diff --git a/src/gnac-main.c b/src/gnac-main.c
index ccc105c..297e53b 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -30,7 +30,6 @@
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <gst/gst.h>
#include <stdlib.h>
#include "gnac-bars.h"
@@ -420,47 +419,44 @@ gnac_on_ui_destroy_cb(GtkWidget *widget,
static gboolean
gnac_on_converter_overwrite_cb(LibgnacConverter *converter,
- gpointer file,
+ GFile *file,
gpointer user_data)
{
static gboolean overwrite = FALSE;
+ if (remember_overwrite) return overwrite;
+
GError *error = NULL;
- GFile *uri = (GFile *) file;
- GFileInfo *info = g_file_query_info(uri,
+ GFileInfo *info = g_file_query_info(file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_QUERY_INFO_NONE, NULL, &error);
- if (!remember_overwrite) {
- GtkWidget *dialog = gtk_message_dialog_new(
- GTK_WINDOW(gnac_ui_get_widget("main_window")),
- GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO,
- _("File %s already exists...\nOverwrite?"),
- g_file_info_get_display_name(info));
-
- gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE_NAME);
-
- GtkWidget *checkbox;
- checkbox = gtk_check_button_new_with_label(_("Remember my decision"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), FALSE);
- gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->vbox), checkbox,
- FALSE, FALSE, 0);
- gtk_widget_show(checkbox);
-
- gdk_threads_enter();
- gint response = gtk_dialog_run(GTK_DIALOG(dialog));
- gdk_threads_leave();
+ GtkWidget *dialog = gtk_message_dialog_new(
+ GTK_WINDOW(gnac_ui_get_widget("main_window")),
+ GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO,
+ _("File %s already exists...\nOverwrite?"),
+ g_file_info_get_display_name(info));
+ gtk_window_set_title(GTK_WINDOW(dialog), PACKAGE_NAME);
- remember_overwrite = gtk_toggle_button_get_active(
- GTK_TOGGLE_BUTTON(checkbox));
+ GtkWidget *checkbox = gtk_check_button_new_with_label(
+ _("Remember my decision"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), FALSE);
+ gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
+ checkbox, FALSE, FALSE, 0);
+ gtk_widget_show(checkbox);
- gtk_widget_destroy(dialog);
+ gdk_threads_enter();
+ gint response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gdk_threads_leave();
- overwrite = (response == GTK_RESPONSE_YES);
- }
+ remember_overwrite = gtk_toggle_button_get_active(
+ GTK_TOGGLE_BUTTON(checkbox));
g_object_unref(info);
+ gtk_widget_destroy(dialog);
+
+ overwrite = (response == GTK_RESPONSE_YES);
return overwrite;
}
@@ -473,20 +469,17 @@ gnac_on_converter_progress_cb(LibgnacConverter *converter,
guint64 time_left)
{
if (state == GNAC_AUDIO_CONVERT_STATE) {
- gint total;
-
- g_object_get(G_OBJECT(converter), "nb-files", &total, NULL);
gchar *msg = g_strdup_printf(_("Converting file %d of %d"),
- nb_converted, total);
+ nb_converted, nb_files_total);
gnac_ui_push_status(msg);
g_free(msg);
gnac_ui_set_progress_fraction(fraction);
if (prev_time_left != -1) {
- guint64 dprogress = prev_time_left - time_left;
- if (dprogress <= 0) return;
+ guint64 progress = prev_time_left - time_left;
+ if (progress <= 0) return;
- guint64 left = ((time_left / dprogress) * PROGRESS_TIMEOUT) / 1000;
+ guint64 left = ((time_left / progress) * PROGRESS_TIMEOUT) / 1000;
gchar *time_str = gnac_utils_format_duration_for_display(
gnac_utils_moving_avg_add_sample(left));
@@ -495,8 +488,8 @@ gnac_on_converter_progress_cb(LibgnacConverter *converter,
gnac_ui_set_progress_text(time_str_label);
- g_free(time_str_label);
g_free(time_str);
+ g_free(time_str_label);
}
prev_time_left = time_left;
@@ -508,7 +501,7 @@ static void
gnac_on_converter_file_added_cb(LibgnacConverter *converter,
const gchar *uri)
{
- ++nb_files_added;
+ nb_files_added++;
gnac_file_list_add_row(uri);
}
@@ -539,9 +532,7 @@ gnac_on_converter_file_completed_cb(LibgnacConverter *converter,
const gchar *uri)
{
/* if delete source is selected, there is nothing else to do */
- if (!g_settings_get_boolean(settings, GNAC_KEY_CLEAR_SOURCE)) {
- return;
- }
+ if (!g_settings_get_boolean(settings, GNAC_KEY_CLEAR_SOURCE)) return;
GError *error = NULL;
GFile *file = g_file_new_for_uri(uri);
@@ -597,10 +588,10 @@ gnac_on_converter_files_cleared_cb(LibgnacConverter *converter)
static void
gnac_on_converter_completion_cb(LibgnacConverter *converter)
{
- const gchar *msg;
-
gnac_change_state(GNAC_AUDIO_READY_STATE);
+ const gchar *msg;
+
if (conversion_errors) {
msg = _("Conversion completed with errors");
} else {
diff --git a/src/gnac-options.c b/src/gnac-options.c
index 26a2547..8d261bb 100644
--- a/src/gnac-options.c
+++ b/src/gnac-options.c
@@ -28,6 +28,7 @@
#endif
#include <glib/gi18n.h>
+#include <gst/gst.h>
#include "gnac-main.h"
#include "gnac-options.h"
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index 1b20f87..c000f66 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -43,7 +43,6 @@
#include "profiles/gnac-profiles.h"
static GtkBuilder *gnac_prefs_builder = NULL;
-static GtkWidget *gnac_prefs_window;
static gchar *tooltip_patterns = NULL;
@@ -144,8 +143,7 @@ static void
gnac_prefs_set_event_box_above_child(const gchar *box_name,
gboolean above_child)
{
- GtkEventBox *event_box;
- event_box = GTK_EVENT_BOX(gnac_prefs_get_widget(box_name));
+ GtkEventBox *event_box = GTK_EVENT_BOX(gnac_prefs_get_widget(box_name));
gtk_event_box_set_above_child(event_box, above_child);
}
@@ -153,8 +151,7 @@ gnac_prefs_set_event_box_above_child(const gchar *box_name,
static gint
gnac_prefs_get_combo_box_active(const gchar *box_name)
{
- GtkComboBox *combo_box;
- combo_box = GTK_COMBO_BOX(gnac_prefs_get_widget(box_name));
+ GtkComboBox *combo_box = GTK_COMBO_BOX(gnac_prefs_get_widget(box_name));
return gtk_combo_box_get_active(combo_box);
}
@@ -163,8 +160,7 @@ static void
gnac_prefs_set_combo_box_active(const gchar *box_name,
gint index)
{
- GtkComboBox *combo_box;
- combo_box = GTK_COMBO_BOX(gnac_prefs_get_widget(box_name));
+ GtkComboBox *combo_box = GTK_COMBO_BOX(gnac_prefs_get_widget(box_name));
return gtk_combo_box_set_active(combo_box, index);
}
@@ -173,8 +169,7 @@ static void
gnac_prefs_set_toggle_button_active(const gchar *button_name,
gboolean is_active)
{
- GtkToggleButton *button;
- button = GTK_TOGGLE_BUTTON(gnac_prefs_get_widget(button_name));
+ GtkToggleButton *button = GTK_TOGGLE_BUTTON(gnac_prefs_get_widget(button_name));
gtk_toggle_button_set_active(button, is_active);
}
@@ -264,50 +259,64 @@ gnac_prefs_retrieve_settings(void)
}
-GtkWidget *
-gnac_prefs_window_new(void)
+static void
+gnac_prefs_set_parent(void)
{
- GtkWidget *check_button;
- GtkWidget *prefs_window;
-
- gnac_prefs_builder = gnac_ui_utils_create_gtk_builder(
- PKGDATADIR "/gnac-pref-window.xml");
+ GtkWidget *prefs_window = gnac_prefs_get_widget("gnac_preference_window");
+ GtkWidget *parent = gnac_ui_get_widget("main_window");
+ gtk_window_set_transient_for(GTK_WINDOW(prefs_window), GTK_WINDOW(parent));
+}
- prefs_window = gnac_prefs_get_widget("gnac_preference_window");
- /* Set the parent */
- gtk_window_set_transient_for(GTK_WINDOW(prefs_window),
- GTK_WINDOW(gnac_ui_get_widget("main_window")));
- /* GSettings binding */
- check_button = gnac_prefs_get_widget("check_notification_icon");
- g_settings_bind(settings_ui, GNAC_KEY_TRAY_ICON, check_button,
+static void
+gnac_prefs_init_gsettings_bindings(void)
+{
+ g_settings_bind(settings_ui, GNAC_KEY_TRAY_ICON,
+ gnac_prefs_get_widget("check_notification_icon"),
"active", G_SETTINGS_BIND_DEFAULT);
- check_button = gnac_prefs_get_widget("erase_originals_checkbutton");
- g_settings_bind(settings, GNAC_KEY_CLEAR_SOURCE, check_button,
+
+ g_settings_bind(settings, GNAC_KEY_CLEAR_SOURCE,
+ gnac_prefs_get_widget("erase_originals_checkbutton"),
"active", G_SETTINGS_BIND_DEFAULT);
- check_button = gnac_prefs_get_widget("strip_special_checkbutton");
- g_settings_bind(settings, GNAC_KEY_STRIP_SPECIAL, check_button,
+
+ g_settings_bind(settings, GNAC_KEY_STRIP_SPECIAL,
+ gnac_prefs_get_widget("strip_special_checkbutton"),
"active", G_SETTINGS_BIND_DEFAULT);
+}
+
+
+static void
+gnac_prefs_init(void)
+{
+ gnac_prefs_builder = gnac_ui_utils_create_gtk_builder(
+ PKGDATADIR "/gnac-pref-window.xml");
+
+ gnac_prefs_set_parent();
+ gnac_prefs_init_gsettings_bindings();
+}
- return prefs_window;
+
+static void
+gnac_prefs_select_general_tab(void)
+{
+ GtkWidget *notebook = gnac_prefs_get_widget("notebook");
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
}
void
gnac_prefs_window_show(void)
{
- if (G_UNLIKELY(!gnac_prefs_window)) {
- gnac_prefs_window = gnac_prefs_window_new();
+ if (G_UNLIKELY(!gnac_prefs_builder)) {
+ gnac_prefs_init();
}
gnac_prefs_retrieve_settings();
+ gnac_prefs_select_general_tab();
- /* always start with the general tab selected */
- GtkWidget *notebook = gnac_prefs_get_widget("notebook");
- gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
-
- gtk_widget_show_all(gnac_prefs_window);
- gtk_window_present(GTK_WINDOW(gnac_prefs_window));
+ GtkWidget *prefs_window = gnac_prefs_get_widget("gnac_preference_window");
+ gtk_widget_show_all(prefs_window);
+ gtk_window_present(GTK_WINDOW(prefs_window));
}
@@ -385,12 +394,10 @@ void
gnac_prefs_selected_radio_toggled(GtkWidget *widget,
gpointer data)
{
- gchar *uri;
- GtkWidget *filechooserbutton;
- filechooserbutton = gnac_prefs_get_widget("filechooserbutton");
+ GtkWidget *filechooserbutton = gnac_prefs_get_widget("filechooserbutton");
gnac_prefs_set_selected_mode();
gnac_settings_set_int(GNAC_KEY_FOLDER_TYPE, FOLDER_SELECTED);
- uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
+ gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, uri);
g_free(uri);
}
@@ -400,10 +407,8 @@ void
gnac_prefs_selected_uri_changed(GtkWidget *widget,
gpointer data)
{
- gchar *uri;
- GtkWidget *filechooserbutton;
- filechooserbutton = gnac_prefs_get_widget("filechooserbutton");
- uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
+ GtkWidget *filechooserbutton = gnac_prefs_get_widget("filechooserbutton");
+ gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, uri);
g_free(uri);
}
@@ -413,23 +418,19 @@ void
gnac_prefs_update_example_label(GtkWidget *widget,
gpointer data)
{
- const gchar *pattern_filename;
- gchar *clean_label;
- gchar *pattern;
- gchar *preview;
-
- GtkWidget *combo = gnac_prefs_get_widget("folder_hierarchy_combo");
- GtkWidget *label = gnac_prefs_get_widget("example_label");
-
- pattern_filename = gnac_prefs_entry_get_text("output_filename_entry");
+ const gchar *pattern_filename = gnac_prefs_entry_get_text(
+ "output_filename_entry");
if (!gnac_utils_string_is_null_or_empty(pattern_filename))
{
gnac_settings_set_string(GNAC_KEY_RENAME_PATTERN_PATTERN, pattern_filename);
}
+ gchar *pattern;
+ GtkWidget *combo = gnac_prefs_get_widget("folder_hierarchy_combo");
+
if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) != 0) {
- const gchar *pattern_folder;
- pattern_folder = gnac_prefs_entry_get_text("folder_hierarchy_entry");
+ const gchar *pattern_folder = gnac_prefs_entry_get_text(
+ "folder_hierarchy_entry");
if (gnac_utils_string_is_null_or_empty(pattern_folder)) {
pattern = g_strdup(pattern_filename);
} else {
@@ -441,15 +442,15 @@ gnac_prefs_update_example_label(GtkWidget *widget,
pattern = g_strdup(pattern_filename);
}
- preview = libgnac_output_get_preview_from_pattern(pattern,
- g_settings_get_boolean(settings, GNAC_KEY_STRIP_SPECIAL));
- clean_label = g_markup_printf_escaped("%s.%s",
- preview, gnac_profiles_get_extension());
-
- gtk_label_set_markup(GTK_LABEL(label), clean_label);
-
+ gchar *preview = libgnac_output_get_preview_from_pattern(pattern,
+ g_settings_get_boolean(settings, GNAC_KEY_STRIP_SPECIAL));
g_free(pattern);
+ gchar *clean_label = g_markup_printf_escaped("%s.%s",
+ preview, gnac_profiles_get_extension());
g_free(preview);
+
+ GtkWidget *label = gnac_prefs_get_widget("example_label");
+ gtk_label_set_markup(GTK_LABEL(label), clean_label);
g_free(clean_label);
}
@@ -499,23 +500,19 @@ void
gnac_prefs_pattern_changed_cb(GtkWidget *widget,
gpointer data)
{
- gboolean is_custom_pattern;
- gchar *pattern;
- GtkWidget *filename_entry;
+ gnac_prefs_update_example_label(widget, data);
gint selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+ gboolean is_custom_pattern = gnac_prefs_custom_pattern_is_selected(
+ GTK_COMBO_BOX(widget), selected_index);
- gnac_prefs_update_example_label(widget, data);
-
- filename_entry = gnac_prefs_get_widget("output_filename_entry");
+ gnac_prefs_set_event_box_above_child("output_filename_eventbox",
+ !is_custom_pattern);
- is_custom_pattern = gnac_prefs_custom_pattern_is_selected(
- GTK_COMBO_BOX(widget), selected_index);
- gnac_prefs_set_event_box_above_child("output_filename_eventbox", !is_custom_pattern);
+ GtkWidget *filename_entry = gnac_prefs_get_widget("output_filename_entry");
gtk_widget_set_sensitive(filename_entry, is_custom_pattern);
- pattern = gnac_prefs_get_rename_pattern_as_str();
-
+ gchar *pattern = gnac_prefs_get_rename_pattern_as_str();
gtk_entry_set_text(GTK_ENTRY(filename_entry), pattern);
gnac_settings_set_int(GNAC_KEY_RENAME_PATTERN, selected_index);
@@ -529,22 +526,18 @@ void
gnac_prefs_folder_hierarchy_changed_cb(GtkWidget *widget,
gpointer data)
{
- gboolean is_custom_pattern;
- gchar *pattern;
- GtkWidget *folder_entry;
-
- gint selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
gnac_prefs_update_example_label(widget, data);
- folder_entry = gnac_prefs_get_widget("folder_hierarchy_entry");
-
- is_custom_pattern = gnac_prefs_custom_pattern_is_selected(
+ gint selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+ GtkWidget *folder_entry = gnac_prefs_get_widget("folder_hierarchy_entry");
+ gboolean is_custom_pattern = gnac_prefs_custom_pattern_is_selected(
GTK_COMBO_BOX(widget), selected_index);
- gnac_prefs_set_event_box_above_child("folder_hierarchy_eventbox", !is_custom_pattern);
- gtk_widget_set_sensitive(folder_entry, is_custom_pattern);
- pattern = gnac_prefs_get_folder_hierarchy_as_str();
+ gnac_prefs_set_event_box_above_child("folder_hierarchy_eventbox",
+ !is_custom_pattern);
+ gtk_widget_set_sensitive(folder_entry, is_custom_pattern);
+ gchar *pattern = gnac_prefs_get_folder_hierarchy_as_str();
gtk_entry_set_text(GTK_ENTRY(folder_entry), pattern);
gnac_settings_set_int(GNAC_KEY_FOLDER_HIERARCHY, selected_index);
@@ -567,11 +560,12 @@ gnac_prefs_query_tooltip_cb(GtkWidget *entry,
}
-void
+static void
gnac_prefs_window_hide(void)
{
- if (gnac_prefs_window) {
- gtk_widget_hide(gnac_prefs_window);
+ if (gnac_prefs_builder) {
+ GtkWidget *prefs_window = gnac_prefs_get_widget("gnac_preference_window");
+ gtk_widget_hide(prefs_window);
}
}
@@ -589,7 +583,7 @@ gnac_prefs_destroy(void)
{
if (gnac_prefs_builder) {
GtkWidget *window = gnac_prefs_get_widget("gnac_preference_window");
- if (window) gtk_widget_destroy(window);
+ gtk_widget_destroy(window);
g_object_unref(gnac_prefs_builder);
gnac_prefs_builder = NULL;
}
diff --git a/src/gnac-prefs.h b/src/gnac-prefs.h
index dcf9208..f55c46a 100644
--- a/src/gnac-prefs.h
+++ b/src/gnac-prefs.h
@@ -30,16 +30,10 @@
G_BEGIN_DECLS
-GtkWidget *
-gnac_prefs_window_new(void);
-
void
gnac_prefs_window_show(void);
void
-gnac_prefs_window_hide(void);
-
-void
gnac_prefs_strip_special_toggled(GtkWidget *widget,
gpointer data);
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index 25f4f4c..c0dc425 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -28,6 +28,7 @@
#endif
#include <glib/gi18n.h>
+#include <gst/gst.h>
#include "gnac-file-list.h"
#include "gnac-main.h"
@@ -45,8 +46,6 @@ static GHashTable *gnac_properties_table;
static GtkTreeModel *properties_filter;
static GtkWidget *gnac_properties_window;
-static GtkWidget *backward_arrow;
-static GtkWidget *forward_arrow;
static gboolean properties_displayed = FALSE;
@@ -195,7 +194,7 @@ gnac_properties_build_table(void)
"Value", renderer, "text", PROPERTY_VALUE, NULL);
gnac_properties_table = g_hash_table_new_full(g_str_hash,
- g_str_equal, g_free, (GDestroyNotify)gtk_tree_row_reference_free);
+ g_str_equal, g_free, (GDestroyNotify) gtk_tree_row_reference_free);
for (i = 0; displayed_properties[i][0]; i++) {
GtkTreeIter iter;
@@ -472,7 +471,7 @@ gnac_properties_dup_channels(const GValue *value)
}
-GtkWidget *
+static GtkWidget *
gnac_properties_window_new(void)
{
GtkWidget *properties_window;
@@ -483,8 +482,6 @@ gnac_properties_window_new(void)
gnac_properties_build_table();
properties_window = gnac_properties_get_widget("properties_window");
- backward_arrow = gnac_properties_get_widget("backward_btn");
- forward_arrow = gnac_properties_get_widget("forward_btn");
gtk_window_set_transient_for(GTK_WINDOW(properties_window),
GTK_WINDOW(gnac_ui_get_widget("main_window")));
@@ -510,7 +507,7 @@ gnac_properties_update_display(GtkTreeRowReference *reference)
gnac_properties_reset_properties();
if (tags) {
- g_hash_table_foreach(tags, (GHFunc)gnac_properties_set_entry, NULL);
+ g_hash_table_foreach(tags, (GHFunc) gnac_properties_set_entry, NULL);
}
}
@@ -528,7 +525,7 @@ gnac_properties_update_arrows(void)
static void
gnac_properties_update_forward_arrow(void)
{
- if (!forward_arrow) return;
+ GtkWidget *forward_arrow = gnac_properties_get_widget("forward_btn");
if (gnac_file_list_has_next_row(current_ref)) {
gtk_widget_set_sensitive(forward_arrow, TRUE);
@@ -541,7 +538,7 @@ gnac_properties_update_forward_arrow(void)
static void
gnac_properties_update_backward_arrow(void)
{
- if (!backward_arrow) return;
+ GtkWidget *backward_arrow = gnac_properties_get_widget("backward_btn");
if (gnac_file_list_has_prev_row(current_ref)) {
gtk_widget_set_sensitive(backward_arrow, TRUE);
@@ -591,7 +588,7 @@ gnac_properties_window_show(void)
}
-void
+static void
gnac_properties_window_hide(void)
{
if (gnac_properties_window) {
diff --git a/src/gnac-properties.h b/src/gnac-properties.h
index 2b4e131..0c488d0 100644
--- a/src/gnac-properties.h
+++ b/src/gnac-properties.h
@@ -42,16 +42,10 @@ enum {
};
-GtkWidget *
-gnac_properties_window_new(void);
-
void
gnac_properties_window_show(void);
void
-gnac_properties_window_hide(void);
-
-void
gnac_properties_set_row(GtkTreeRowReference *current);
void
diff --git a/src/gnac-ui-utils.c b/src/gnac-ui-utils.c
index 97674bc..108a038 100644
--- a/src/gnac-ui-utils.c
+++ b/src/gnac-ui-utils.c
@@ -39,13 +39,11 @@
gint
gnac_ui_utils_get_combo_size(GtkComboBox *combo)
{
- gboolean has_next;
- guint count = 0;
- GtkTreeIter iter;
- GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeModel *model = gtk_combo_box_get_model(combo);
+ gboolean has_next = gtk_tree_model_get_iter_first(model, &iter);
- model = gtk_combo_box_get_model(combo);
- has_next = gtk_tree_model_get_iter_first(model, &iter);
+ guint count = 0;
while (has_next) {
count++;
@@ -169,7 +167,6 @@ GtkBuilder *
gnac_ui_utils_create_gtk_builder(const gchar *filename)
{
GError *error = NULL;
-
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, filename, &error);
if (error) {
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index aed8db7..38bea68 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -29,6 +29,7 @@
#include <glib/gi18n.h>
#include <glib/gprintf.h>
+#include <gst/gst.h>
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
@@ -88,7 +89,7 @@ static void
gnac_ui_file_chooser_unref_filters(void)
{
GSList *f;
- for (f = filters; f; f = f->next) {
+ for (f = filters; f; f = g_slist_next(f)) {
g_object_unref(f->data);
}
g_slist_free(f);
@@ -183,7 +184,7 @@ gnac_ui_file_chooser_get_filters_model(void)
gtk_file_filter_set_name(filter, _("All files"));
gtk_tree_store_append(store, &iter1, NULL);
gtk_tree_store_set(store, &iter1, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Supported files */
filter = gtk_file_filter_new();
@@ -210,7 +211,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter1, NULL);
gtk_tree_store_set(store, &iter1, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
default_file_filter = filter;
/* Audio files */
@@ -233,7 +234,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter1, NULL);
gtk_tree_store_set(store, &iter1, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Lossy files */
filter = gtk_file_filter_new();
@@ -245,7 +246,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter2, &iter1);
gtk_tree_store_set(store, &iter2, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Individual lossy files */
i = 0;
@@ -255,7 +256,7 @@ gnac_ui_file_chooser_get_filters_model(void)
gtk_file_filter_set_name(filter, lossy_mime[i][1]);
gtk_tree_store_append(store, &iter3, &iter2);
gtk_tree_store_set(store, &iter3, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
i++;
}
@@ -269,7 +270,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter2, &iter1);
gtk_tree_store_set(store, &iter2, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Individual lossless files */
i = 0;
@@ -279,7 +280,7 @@ gnac_ui_file_chooser_get_filters_model(void)
gtk_file_filter_set_name(filter, lossless_mime[i][1]);
gtk_tree_store_append(store, &iter3, &iter2);
gtk_tree_store_set(store, &iter3, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
i++;
}
@@ -293,7 +294,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter1, NULL);
gtk_tree_store_set(store, &iter1, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Individual playlists */
i = 0;
@@ -303,7 +304,7 @@ gnac_ui_file_chooser_get_filters_model(void)
gtk_file_filter_set_name(filter, playlists_mime[i][1]);
gtk_tree_store_append(store, &iter2, &iter1);
gtk_tree_store_set(store, &iter2, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
i++;
}
@@ -317,7 +318,7 @@ gnac_ui_file_chooser_get_filters_model(void)
}
gtk_tree_store_append(store, &iter1, NULL);
gtk_tree_store_set(store, &iter1, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
/* Individual video files */
i = 0;
@@ -327,11 +328,11 @@ gnac_ui_file_chooser_get_filters_model(void)
gtk_file_filter_set_name(filter, video_mime[i][1]);
gtk_tree_store_append(store, &iter2, &iter1);
gtk_tree_store_set(store, &iter2, 0, filter, -1);
- filters = g_slist_append(filters, (gpointer)filter);
+ filters = g_slist_append(filters, filter);
i++;
}
- for (f = filters; f; f = f->next) {
+ for (f = filters; f; f = g_slist_next(f)) {
g_object_ref(G_OBJECT(f->data));
}
@@ -370,15 +371,6 @@ gnac_ui_file_chooser_new(void)
}
-void
-gnac_ui_on_profile_changed_cb(GtkComboBox *box,
- gpointer data)
-{
- const gchar *profile_name = gnac_profiles_get_name();
- gnac_settings_set_string(GNAC_KEY_LAST_USED_PROFILE, profile_name);
-}
-
-
static void
gnac_remove_track(gpointer data,
gpointer user_data)
diff --git a/src/gnac-ui.h b/src/gnac-ui.h
index 8a2b55e..c4027ef 100644
--- a/src/gnac-ui.h
+++ b/src/gnac-ui.h
@@ -44,10 +44,6 @@ enum {
extern GSettings *settings_ui;
void
-gnac_ui_on_profile_changed_cb(GtkComboBox *box,
- gpointer data);
-
-void
gnac_ui_set_progress_fraction(gdouble fraction);
void
diff --git a/src/gnac-utils.c b/src/gnac-utils.c
index 508db4b..d3bdabb 100644
--- a/src/gnac-utils.c
+++ b/src/gnac-utils.c
@@ -41,23 +41,20 @@ gchar *
gnac_utils_get_display_name(const gchar *uri,
GError **error)
{
- GError *err = NULL;
- GFile *file;
- GFileInfo *info;
- gchar *display_name;
-
g_return_val_if_fail(!error || !*error, NULL);
- file = g_file_new_for_uri(uri);
- info = g_file_query_info(file,
+ GError *err = NULL;
+ GFile *file = g_file_new_for_uri(uri);
+ GFileInfo *info = g_file_query_info(file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_QUERY_INFO_NONE, NULL, &err);
if (err) {
+ g_object_unref(file);
g_propagate_error(error, err);
return NULL;
}
- display_name = g_strdup(g_file_info_get_display_name(info));
+ gchar *display_name = g_strdup(g_file_info_get_display_name(info));
g_object_unref(info);
g_object_unref(file);
@@ -69,11 +66,8 @@ gnac_utils_get_display_name(const gchar *uri,
gchar *
gnac_utils_format_duration_for_display(guint64 duration)
{
- gint minutes;
- gint seconds;
-
- minutes = (gint) ((duration / 60) % 60);
- seconds = (gint) (duration % 60);
+ gint minutes = (gint) ((duration / 60) % 60);
+ gint seconds = (gint) (duration % 60);
if (duration >= 3600) {
/* Translators: time remaining hours:minutes:seconds. You may change ":" to the separator that your local uses or use "%Id" instead of "%d" if your locale uses localized digits. */
@@ -91,7 +85,7 @@ gnac_utils_format_duration_for_display(guint64 duration)
guint
gnac_utils_convert_bps_to_kbps(guint value)
{
- return value/1000;
+ return value / 1000;
}
@@ -100,7 +94,6 @@ gnac_utils_moving_avg_add_sample(guint64 sample)
{
total_samples++;
average = (average * (total_samples-1) + sample) / total_samples;
-
return average;
}
@@ -119,17 +112,12 @@ gnac_utils_moving_avg_reset(void)
gchar **
gnac_utils_get_filenames_from_cmd_line(gchar **argv)
{
- GPtrArray *array;
-
- array = g_ptr_array_new();
+ GPtrArray *array = g_ptr_array_new();
if (argv) {
guint i;
-
for (i = 0; argv[i]; i++) {
- GFile *file;
-
- file = g_file_new_for_commandline_arg(argv[i]);
+ GFile *file = g_file_new_for_commandline_arg(argv[i]);
if (file) {
g_ptr_array_add(array, g_file_get_uri(file));
g_object_unref(file);
@@ -141,7 +129,7 @@ gnac_utils_get_filenames_from_cmd_line(gchar **argv)
g_ptr_array_add(array, NULL);
- return (gchar**) g_ptr_array_free(array, FALSE);
+ return (gchar **) g_ptr_array_free(array, FALSE);
}
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index a40390f..68f2320 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -766,7 +766,8 @@ gnac_profiles_mgr_on_drag_data_received(GtkWidget *widget G_GNUC_UNUSED,
guint time,
gpointer data G_GNUC_UNUSED)
{
- gchar **uris = g_uri_list_extract_uris((const gchar*) selection_data->data);
+ gchar **uris = g_uri_list_extract_uris((const gchar *)
+ gtk_selection_data_get_data(selection_data));
if (!uris) {
gtk_drag_finish(context, FALSE, FALSE, time);
return;
@@ -916,7 +917,7 @@ gnac_profiles_mgr_copy_and_load_files(gpointer data)
libgnac_warning(
_("Impossible to load file \"%s\": "
"a profile with the same name already exists."), uri);
- ++profiles_error;
+ profiles_error++;
} else if (gnac_profiles_mgr_copy_file(file, name)) {
profiles_ok++;
} else {
@@ -925,7 +926,7 @@ gnac_profiles_mgr_copy_and_load_files(gpointer data)
g_free(name);
- ++index;
+ index++;
uri = uris[index];
g_object_unref(file);
@@ -1002,7 +1003,7 @@ gnac_profiles_mgr_get_selected_uris(void)
guint i;
GList *temp;
- for (i = 0, temp = selected; temp; temp = temp->next, ++i) {
+ for (i = 0, temp = selected; temp; temp = g_list_next(temp), i++) {
AudioProfileGeneric *profile;
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
profile = profile->generic;
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index 948bdfd..d638172 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -166,7 +166,7 @@ gnac_profiles_properties_init_format(void)
guint i;
GtkTreeIter iter;
- for (i = 0; i < G_N_ELEMENTS(formats_get_funcs); ++i) {
+ for (i = 0; i < G_N_ELEMENTS(formats_get_funcs); i++) {
FormatModule *format_module = g_malloc(sizeof(FormatModule));
format_module->funcs = formats_get_funcs[i]();
const gchar *format_id = format_module->funcs.init(
@@ -291,7 +291,7 @@ gnac_profiles_properties_destroy(void)
GList *temp;
GList *list = g_hash_table_get_values(formats);
- for (temp = list; temp; temp = temp->next) {
+ for (temp = list; temp; temp = g_list_next(temp)) {
FormatModule *format_module = (FormatModule *) temp->data;
format_module->funcs.clean_up();
g_free(format_module);
@@ -388,7 +388,7 @@ gnac_profiles_properties_reinit(void)
GList *temp;
GList *list = g_hash_table_get_values(formats);
- for (temp = list; temp; temp = temp->next) {
+ for (temp = list; temp; temp = g_list_next(temp)) {
((FormatModule *) temp->data)->funcs.fullfill_fields(NULL);
}
@@ -549,7 +549,7 @@ static gboolean
gnac_profiles_properties_is_valid_filename_char(guint keyval)
{
guint i;
- for (i = 0; i < G_N_ELEMENTS(forbidden_chars_keys); ++i) {
+ for (i = 0; i < G_N_ELEMENTS(forbidden_chars_keys); i++) {
if (keyval == forbidden_chars_keys[i]) {
return FALSE;
}
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index a8c337b..3a677f8 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -55,9 +55,9 @@ gnac_profiles_utils_add_values_combo(GtkWidget *combo,
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), index);
}
- names = names->next;
- values = values->next;
- ++index;
+ names = g_list_next(names);
+ values = g_list_next(values);
+ index++;
}
}
@@ -198,8 +198,8 @@ gnac_profiles_utils_set_value_combo(GtkWidget *combo,
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), index);
}
- values = values->next;
- ++index;
+ values = g_list_next(values);
+ index++;
}
}
@@ -599,7 +599,7 @@ gnac_profiles_utils_add_pipes(gchar *pipeline,
g_free(v);
pipeline = temp;
- list_temp = list_temp->next;
+ list_temp = g_list_next(list_temp);
}
return pipeline;
diff --git a/src/profiles/gnac-profiles.c b/src/profiles/gnac-profiles.c
index ecfb79b..4cf1dc3 100755
--- a/src/profiles/gnac-profiles.c
+++ b/src/profiles/gnac-profiles.c
@@ -48,28 +48,6 @@ gnac_profiles_init(void)
{
gnac_profiles_mgr_init();
gnac_profiles_populate_combo();
-
- gchar *current_profile = g_settings_get_string(settings,
- GNAC_KEY_LAST_USED_PROFILE);
- gnac_profiles_set_current_profile(current_profile);
- g_free(current_profile);
-}
-
-
-static gchar *
-gnac_profiles_get_display_name(void)
-{
- GtkTreeIter iter;
- GtkComboBox *combo_profile = GTK_COMBO_BOX(gnac_ui_get_widget("combo_profile"));
- GtkTreeModel *model = gtk_combo_box_get_model(combo_profile);
-
- if (gtk_combo_box_get_active_iter(combo_profile, &iter)) {
- gchar *name;
- gtk_tree_model_get(model, &iter, COL_NAME, &name, -1);
- return name;
- }
-
- return NULL;
}
@@ -139,6 +117,10 @@ gnac_profiles_set_current_profile(const gchar *name)
}
has_next = gtk_tree_model_iter_next(model, &iter);
}
+
+ 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);
+ }
}
@@ -149,24 +131,22 @@ gnac_profiles_populate_combo(void)
GtkListStore *model = GTK_LIST_STORE(
gtk_combo_box_get_model(GTK_COMBO_BOX(combo_profile)));
- gchar *display_name = gnac_profiles_get_display_name();
- gtk_list_store_clear(model);
-
GList *profiles = gnac_profiles_mgr_get_profiles_list();
if (!profiles) {
gtk_widget_set_sensitive(combo_profile, FALSE);
- g_free(display_name);
return;
}
- gtk_widget_set_sensitive(combo_profile, TRUE);
+ gchar *last_used_profile = g_settings_get_string(settings,
+ GNAC_KEY_LAST_USED_PROFILE);
- gboolean set_active = FALSE;
+ gtk_widget_set_sensitive(combo_profile, TRUE);
+ gtk_list_store_clear(model);
- GList *temp;
- GtkTreeIter iter;
+ GList *temp;
+ GtkTreeIter iter;
- for (temp = profiles; temp; temp = temp->next) {
+ for (temp = profiles; temp; temp = g_list_next(temp)) {
AudioProfileGeneric *profile = AUDIO_PROFILE_GET_GENERIC(temp->data);
gchar *formatted_name = gnac_profiles_properties_filter_text_for_displaying(
profile->name, MAX_NAME_DISPLAY_SIZE);
@@ -174,25 +154,12 @@ gnac_profiles_populate_combo(void)
profile->extension);
gtk_list_store_append(model, &iter);
gtk_list_store_set(model, &iter, 0, name, 1, profile, -1);
- if (gnac_utils_str_equal(name, display_name)) {
- gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_profile), &iter);
- g_free(display_name);
- display_name = NULL;
- set_active = TRUE;
- }
-
- g_free(name);
- g_free(formatted_name);
- }
-
- if (!set_active) {
- if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) {
- gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_profile), &iter);
- }
}
g_list_free(profiles);
- g_free(display_name);
+
+ gnac_profiles_set_current_profile(last_used_profile);
+ g_free(last_used_profile);
}
@@ -203,6 +170,9 @@ gnac_profiles_on_combo_profile_changed(GtkWidget *widget,
AudioProfileGeneric *profile = gnac_profiles_get_active_profile();
if (!profile) return;
+ const gchar *profile_name = gnac_profiles_get_name();
+ gnac_settings_set_string(GNAC_KEY_LAST_USED_PROFILE, profile_name);
+
gchar *description;
if (gnac_utils_string_is_null_or_empty(profile->description)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]