[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, 19 Nov 2011 11:28:08 +0000 (UTC)
commit 5554a21ac1c6065cd9089eac433e4be1bbd9564c
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Fri Nov 18 22:24:36 2011 +0000
Code refactoring
data/profiles/ui/gnac-profiles-manager.xml | 2 +
data/ui/gnac-properties-window.xml | 1 +
data/ui/gnac.xml | 2 +-
src/gnac-file-list.c | 14 +-
src/gnac-main.c | 216 ++++++--------
src/gnac-prefs.c | 62 ++---
src/gnac-properties.c | 78 ++----
src/gnac-stock-items.c | 9 +-
src/gnac-ui.c | 33 ++-
src/profiles/gnac-profiles-default.c | 2 +-
src/profiles/gnac-profiles-manager.c | 432 +++++++++++-----------------
src/profiles/gnac-profiles-properties.c | 80 ++----
src/profiles/gnac-profiles-utils.h | 3 +
src/profiles/gnac-profiles-xml-engine.c | 18 +-
src/profiles/gnac-profiles.c | 2 +-
15 files changed, 392 insertions(+), 562 deletions(-)
---
diff --git a/data/profiles/ui/gnac-profiles-manager.xml b/data/profiles/ui/gnac-profiles-manager.xml
index 0dfbd0d..0eb820c 100644
--- a/data/profiles/ui/gnac-profiles-manager.xml
+++ b/data/profiles/ui/gnac-profiles-manager.xml
@@ -18,6 +18,8 @@
<property name="title" translatable="yes">Profile Manager</property>
<property name="default_width">400</property>
<property name="default_height">400</property>
+ <property name="modal">True</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<signal name="key_press_event" handler="gnac_profiles_mgr_on_key_pressed"/>
<signal name="delete_event" handler="gnac_profiles_mgr_on_delete_event"/>
<child>
diff --git a/data/ui/gnac-properties-window.xml b/data/ui/gnac-properties-window.xml
index 2abcfd1..45e2343 100644
--- a/data/ui/gnac-properties-window.xml
+++ b/data/ui/gnac-properties-window.xml
@@ -18,6 +18,7 @@
<property name="resizable">False</property>
<property name="destroy_with_parent">True</property>
<property name="skip_taskbar_hint">True</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<signal name="delete_event" handler="gnac_properties_on_delete_event"/>
<child>
<object class="GtkVBox" id="vbox1">
diff --git a/data/ui/gnac.xml b/data/ui/gnac.xml
index af6367e..39f2275 100644
--- a/data/ui/gnac.xml
+++ b/data/ui/gnac.xml
@@ -410,7 +410,7 @@ Alexandre Roux <alexroux src gnome org></property>
<property name="title" translatable="yes">Open a File...</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
- <property name="type_hint">dialog</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<property name="select_multiple">True</property>
<property name="use_preview_label">False</property>
diff --git a/src/gnac-file-list.c b/src/gnac-file-list.c
index 1c6cbf9..c62ec57 100644
--- a/src/gnac-file-list.c
+++ b/src/gnac-file-list.c
@@ -56,11 +56,11 @@ gnac_file_list_select_row(GtkTreeRowReference *reference)
static void
-gnac_file_list_display_stock(GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
+gnac_file_list_display_stock(GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
{
gchar *stock_id;
gtk_tree_model_get(tree_model, iter, COL_STOCK, &stock_id, -1);
@@ -88,7 +88,7 @@ gnac_file_list_on_row_activated_cb(GtkTreeView *treeview,
GtkTreeViewColumn *col,
gpointer user_data)
{
- gnac_properties_window_show();
+ gnac_properties_window_show();
}
@@ -123,7 +123,7 @@ gnac_file_list_new(void)
GtkTreeViewColumn *column;
reference_table = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, (GDestroyNotify)gtk_tree_row_reference_free);
+ g_free, (GDestroyNotify) gtk_tree_row_reference_free);
view = GTK_TREE_VIEW(gnac_ui_get_widget("file_list"));
gtk_tree_view_set_tooltip_column(view, COL_TOOLTIP);
diff --git a/src/gnac-main.c b/src/gnac-main.c
index e108c94..ccc105c 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -31,7 +31,6 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
#include <stdlib.h>
#include "gnac-bars.h"
@@ -53,12 +52,12 @@
#include "profiles/gnac-profiles-utils.h"
-static gboolean conversion_errors = FALSE;
-static gboolean continue_files_action;
-static gboolean quit_app = FALSE;
-static gboolean remember_overwrite = FALSE;
-static GThread *file_action_thread = NULL;
-static guint64 prev_time_left = -1;
+static gboolean conversion_errors = FALSE;
+static gboolean continue_files_action;
+static gboolean quit_app = FALSE;
+static gboolean remember_overwrite = FALSE;
+static GThread *file_action_thread = NULL;
+static guint64 prev_time_left = -1;
guint nb_files_added;
guint nb_files_total;
@@ -216,9 +215,7 @@ static void
gnac_files_names_list_foreach(gpointer data,
gpointer user_data)
{
- GFile *file;
-
- file = (GFile*) data;
+ GFile *file = (GFile *) data;
gnac_add(file);
g_object_unref(file);
}
@@ -228,11 +225,10 @@ static void
gnac_add_files_thread_entry(gpointer data)
{
static GSList *files;
- gchar *files_added_text;
/* If we are already adding files, simply update the list */
if (files) {
- files = g_slist_concat(files, (GSList*)data);
+ files = g_slist_concat(files, (GSList *) data);
return;
}
@@ -241,7 +237,7 @@ gnac_add_files_thread_entry(gpointer data)
gnac_ui_push_status(_("Importing files..."));
gdk_threads_leave();
- files = (GSList*) data;
+ files = (GSList *) data;
nb_files_added = 0;
while (files) {
gnac_files_names_list_foreach(files->data, NULL);
@@ -254,7 +250,7 @@ gnac_add_files_thread_entry(gpointer data)
gnac_ui_set_progress_text("");
gnac_file_list_attach_default_model(TRUE);
gnac_change_state(GNAC_AUDIO_READY_STATE);
- files_added_text = g_strdup_printf(
+ gchar *files_added_text = g_strdup_printf(
ngettext("%u file imported", "%u files imported", nb_files_added),
nb_files_added);
gnac_ui_push_status(files_added_text);
@@ -265,7 +261,7 @@ gnac_add_files_thread_entry(gpointer data)
}
-//The GList is freed by the thread itself.
+// The GList is freed by the thread itself.
void
gnac_add_files(GSList *files)
{
@@ -281,7 +277,7 @@ gnac_add_files(GSList *files)
if (error) {
libgnac_debug("Failed to create thread");
libgnac_warning(_("Failed to add files: %s"), error->message);
- g_error_free(error);
+ g_clear_error(&error);
gnac_return_prev_state();
}
}
@@ -290,25 +286,21 @@ gnac_add_files(GSList *files)
void
gnac_add_file(GFile *file)
{
- const gchar *mime_type;
- gchar *uri;
- GError *error = NULL;
- GFileInfo *info;
-
- uri = g_file_get_uri(file);
+ gchar *uri = g_file_get_uri(file);
libgnac_debug("Trying to add file %s", uri);
- info = g_file_query_info(file,
+ GError *error = NULL;
+ GFileInfo *info = g_file_query_info(file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error);
if (error) {
- libgnac_debug("Unable to query file info");
+ libgnac_debug("Unable to query file info for %s: %s", uri, error->message);
g_clear_error(&error);
g_free(uri);
return;
}
- mime_type = g_file_info_get_content_type(info);
+ const gchar *mime_type = g_file_info_get_content_type(info);
if (gnac_playlist_is_mime_playlist(mime_type)) {
gnac_playlist_parse(file, mime_type);
@@ -351,11 +343,8 @@ gboolean
gnac_settings_set(const gchar *key,
GVariant *value)
{
- gboolean ret;
- gchar *val_str;
-
- val_str = g_variant_print(value, FALSE);
- ret = g_settings_set_value(settings, key, value);
+ gchar *val_str = g_variant_print(value, FALSE);
+ gboolean ret = g_settings_set_value(settings, key, value);
if (!ret) {
libgnac_debug("Failed to set key \"%s\" to \"%s\"", key, val_str);
@@ -382,7 +371,6 @@ gnac_on_ui_destroy_cb(GtkWidget *widget,
gpointer data)
{
switch (state) {
-
/* Do not allow the destruction of the main window during
* the installation of a plugin */
case GNAC_PLUGIN_INSTALL_STATE:
@@ -390,8 +378,8 @@ gnac_on_ui_destroy_cb(GtkWidget *widget,
case GNAC_AUDIO_CONVERT_STATE:
case GNAC_AUDIO_PAUSED_STATE: {
- GError *error = NULL;
if (!gnac_ui_confirm_exit()) return TRUE;
+ GError *error = NULL;
libgnac_converter_stop(converter, &error);
if (error) {
libgnac_debug("Error: %s", error->message);
@@ -402,13 +390,13 @@ gnac_on_ui_destroy_cb(GtkWidget *widget,
case GNAC_AUDIO_FILE_ACTION_STATE: {
GThread *thread = NULL;
- if (file_action_thread != NULL) {
+ if (file_action_thread) {
thread = file_action_thread;
quit_app = TRUE;
continue_files_action = FALSE;
gnac_change_state(GNAC_AUDIO_READY_STATE);
}
- if (thread != NULL) g_thread_join(thread);
+ if (thread) g_thread_join(thread);
}
case GNAC_AUDIO_EMPTY_STATE:
@@ -435,32 +423,25 @@ gnac_on_converter_overwrite_cb(LibgnacConverter *converter,
gpointer file,
gpointer user_data)
{
- GFile *uri;
- GFileInfo *info;
- GError *error = NULL;
static gboolean overwrite = FALSE;
- uri = (GFile*) file;
- info = g_file_query_info(uri,
+ GError *error = NULL;
+ GFile *uri = (GFile *) file;
+ GFileInfo *info = g_file_query_info(uri,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_QUERY_INFO_NONE, NULL, &error);
- if (!remember_overwrite)
- {
- gint response;
- GtkWidget *dialog;
- GtkWidget *checkbox;
-
- dialog = gtk_message_dialog_new(
+ 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,
+ 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,
@@ -468,7 +449,7 @@ gnac_on_converter_overwrite_cb(LibgnacConverter *converter,
gtk_widget_show(checkbox);
gdk_threads_enter();
- response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gint response = gtk_dialog_run(GTK_DIALOG(dialog));
gdk_threads_leave();
remember_overwrite = gtk_toggle_button_get_active(
@@ -491,33 +472,26 @@ gnac_on_converter_progress_cb(LibgnacConverter *converter,
gfloat fraction,
guint64 time_left)
{
- if (state == GNAC_AUDIO_CONVERT_STATE)
- {
+ if (state == GNAC_AUDIO_CONVERT_STATE) {
gint total;
- gchar *msg;
g_object_get(G_OBJECT(converter), "nb-files", &total, NULL);
- msg = g_strdup_printf(_("Converting file %d of %d"), nb_converted, total);
+ gchar *msg = g_strdup_printf(_("Converting file %d of %d"),
+ nb_converted, total);
gnac_ui_push_status(msg);
g_free(msg);
gnac_ui_set_progress_fraction(fraction);
- if (prev_time_left != -1)
- {
- gchar *time_str;
- gchar *time_str_label;
- guint64 dprogress;
- guint64 left;
-
- dprogress = prev_time_left - time_left;
+ if (prev_time_left != -1) {
+ guint64 dprogress = prev_time_left - time_left;
if (dprogress <= 0) return;
- left = ((time_left / dprogress) * PROGRESS_TIMEOUT) / 1000;
+ guint64 left = ((time_left / dprogress) * PROGRESS_TIMEOUT) / 1000;
- time_str = gnac_utils_format_duration_for_display(
- gnac_utils_moving_avg_add_sample(left));
+ 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) */
- time_str_label = g_strdup_printf(_("%s left"), time_str);
+ gchar *time_str_label = g_strdup_printf(_("%s left"), time_str);
gnac_ui_set_progress_text(time_str_label);
@@ -564,52 +538,49 @@ static void
gnac_on_converter_file_completed_cb(LibgnacConverter *converter,
const gchar *uri)
{
- GFile *file;
+ /* if delete source is selected, there is nothing else to do */
+ if (!g_settings_get_boolean(settings, GNAC_KEY_CLEAR_SOURCE)) {
+ return;
+ }
+
GError *error = NULL;
-
- /* Delete source if selected */
- if (g_settings_get_boolean(settings, GNAC_KEY_CLEAR_SOURCE))
- {
- file = g_file_new_for_uri(uri);
- g_file_trash(file, NULL, &error);
- if (error)
- {
- if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
- {
- gint response;
- gchar *filename;
+ GFile *file = g_file_new_for_uri(uri);
+ g_file_trash(file, NULL, &error);
+ if (error) {
+ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
+ g_clear_error(&error);
+ gchar *filename = gnac_utils_get_display_name(uri, &error);
+ if (error) {
g_clear_error(&error);
- filename = gnac_utils_get_display_name(uri, &error);
- if (error) {
- g_clear_error(&error);
- g_object_unref(file);
- return;
- }
+ g_object_unref(file);
+ return;
+ }
+
+ gdk_threads_enter();
+ gint response = gnac_ui_show_error_trash(filename);
+ gdk_threads_leave();
+
+ g_free(filename);
- gdk_threads_enter();
- response = gnac_ui_show_error_trash(filename);
- gdk_threads_leave();
- g_free(filename);
-
- switch (response) {
- case 1:
- g_file_delete(file, NULL, &error);
- if (error) {
- g_printerr("%s: %s\n", _("Error"), error->message);
- g_clear_error(&error);
- }
+ switch (response) {
+ case 1:
+ g_file_delete(file, NULL, &error);
+ if (error) {
+ g_printerr("%s: %s\n", _("Error"), error->message);
+ g_clear_error(&error);
+ }
break;
- case GTK_RESPONSE_CANCEL:
- case GTK_RESPONSE_CLOSE:
- default:
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_CLOSE:
+ default:
/* do nothing */
break;
- }
}
- g_object_unref(file);
- g_clear_error(&error);
}
+
+ g_object_unref(file);
+ g_clear_error(&error);
}
}
@@ -678,20 +649,15 @@ gnac_on_converter_error_cb(LibgnacConverter *converter,
const gchar *msg,
GError *error)
{
- if (g_error_matches(error, LIBGNAC_ERROR, LIBGNAC_ERROR_FILE_EXISTS))
- {
- gchar *text;
- text = g_strdup_printf("%s (%s)", _("File not converted"), msg);
+ if (g_error_matches(error, LIBGNAC_ERROR, LIBGNAC_ERROR_FILE_EXISTS)) {
+ gchar *text = g_strdup_printf("%s (%s)", _("File not converted"), msg);
gnac_file_list_visual_error(uri, text, GTK_STOCK_DIALOG_INFO);
g_free(text);
- }
- else
- {
+ } else {
conversion_errors = TRUE;
gnac_file_list_visual_error(uri, msg, NULL);
g_printerr("%s %s\n %s: %s\n",
- _("Failed to convert file"), uri,
- _("Error"), msg);
+ _("Failed to convert file"), uri, _("Error"), msg);
}
}
@@ -704,13 +670,10 @@ gnac_on_ui_pause_cb(GtkWidget *widget,
{
GError *error = NULL;
- if (state == GNAC_AUDIO_CONVERT_STATE)
- {
+ if (state == GNAC_AUDIO_CONVERT_STATE) {
gnac_change_state(GNAC_AUDIO_PAUSED_STATE);
libgnac_converter_pause(converter, &error);
- }
- else
- {
+ } else {
gnac_change_state(GNAC_AUDIO_CONVERT_STATE);
libgnac_converter_resume(converter, &error);
}
@@ -724,22 +687,18 @@ gnac_on_ui_convert_cb(GtkWidget *widget,
{
GError *error = NULL;
- switch(state) {
+ switch (state) {
case GNAC_AUDIO_CONVERT_STATE:
case GNAC_AUDIO_PAUSED_STATE:
libgnac_converter_stop(converter, &error);
break;
- case GNAC_AUDIO_READY_STATE:
- {
- gchar *folder_hierarchy;
- gchar *folder_path;
- gchar *rename_pattern;
- folder_hierarchy = g_settings_get_string(settings,
- GNAC_KEY_FOLDER_HIERARCHY_PATTERN),
- folder_path = g_settings_get_string(settings,
+ case GNAC_AUDIO_READY_STATE: {
+ gchar *folder_hierarchy = g_settings_get_string(settings,
+ GNAC_KEY_FOLDER_HIERARCHY_PATTERN);
+ gchar *folder_path = g_settings_get_string(settings,
GNAC_KEY_DESTINATION_DIRECTORY);
- rename_pattern = g_settings_get_string(settings,
+ gchar *rename_pattern = g_settings_get_string(settings,
GNAC_KEY_RENAME_PATTERN_PATTERN);
g_object_set(G_OBJECT(converter),
"extension", gnac_profiles_get_extension(),
@@ -751,10 +710,13 @@ gnac_on_ui_convert_cb(GtkWidget *widget,
"strip-special", g_settings_get_boolean(settings,
GNAC_KEY_STRIP_SPECIAL),
NULL);
+
libgnac_converter_start(converter, &error);
+
g_free(folder_path);
g_free(folder_hierarchy);
g_free(rename_pattern);
+
break;
}
@@ -840,7 +802,7 @@ main(gint argc,
gnac_options_process_late();
gdk_threads_enter();
- gtk_main();
+ gtk_main();
gdk_threads_leave();
return EXIT_SUCCESS;
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index 80e9c00..06eb10c 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -36,8 +36,10 @@
#include "gnac-ui.h"
#include "gnac-ui-utils.h"
#include "gnac-utils.h"
+
#include "libgnac-debug.h"
#include "libgnac-output.h"
+
#include "profiles/gnac-profiles.h"
static GtkBuilder *gnac_prefs_builder = NULL;
@@ -94,6 +96,7 @@ gnac_prefs_get_tooltip_patterns(void)
"\n <b>\%y:</b> ", _("Year"),
NULL);
}
+
return tooltip_patterns;
}
@@ -105,18 +108,24 @@ gnac_prefs_free_tooltip_patterns(void)
}
+static GObject *
+gnac_prefs_get_object(const gchar *object_name)
+{
+ return gtk_builder_get_object(gnac_prefs_builder, object_name);
+}
+
+
static GtkWidget *
gnac_prefs_get_widget(const gchar *widget_name)
{
- return GTK_WIDGET(gtk_builder_get_object(gnac_prefs_builder, widget_name));
+ return GTK_WIDGET(gnac_prefs_get_object(widget_name));
}
static const gchar *
gnac_prefs_entry_get_text(const gchar *entry_name)
{
- GtkEntry *entry;
- entry = GTK_ENTRY(gnac_prefs_get_widget(entry_name));
+ GtkEntry *entry = GTK_ENTRY(gnac_prefs_get_widget(entry_name));
return gtk_entry_get_text(entry);
}
@@ -125,8 +134,7 @@ static void
gnac_prefs_entry_set_text(const gchar *entry_name,
const gchar *text)
{
- GtkEntry *entry;
- entry = GTK_ENTRY(gnac_prefs_get_widget(entry_name));
+ GtkEntry *entry = GTK_ENTRY(gnac_prefs_get_widget(entry_name));
gtk_entry_set_text(entry, text);
}
@@ -135,8 +143,7 @@ static void
gnac_prefs_set_widget_sensitive(const gchar *widget_name,
gboolean sensitive)
{
- GtkWidget *widget;
- widget = gnac_prefs_get_widget(widget_name);
+ GtkWidget *widget = gnac_prefs_get_widget(widget_name);
gtk_widget_set_sensitive(widget, sensitive);
}
@@ -277,7 +284,7 @@ gnac_prefs_window_new(void)
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")));
+ GTK_WINDOW(gnac_ui_get_widget("main_window")));
/* GSettings binding */
check_button = gnac_prefs_get_widget("check_notification_icon");
@@ -297,7 +304,6 @@ gnac_prefs_window_new(void)
void
gnac_prefs_window_show(void)
{
- GtkWidget *notebook;
if (G_UNLIKELY(!gnac_prefs_window)) {
gnac_prefs_window = gnac_prefs_window_new();
}
@@ -305,7 +311,7 @@ gnac_prefs_window_show(void)
gnac_prefs_retrieve_settings();
/* always start with the general tab selected */
- notebook = gnac_prefs_get_widget("notebook");
+ GtkWidget *notebook = gnac_prefs_get_widget("notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
gtk_widget_show_all(gnac_prefs_window);
@@ -367,10 +373,9 @@ void
gnac_prefs_subfolder_radio_toggled(GtkWidget *widget,
gpointer data)
{
- const gchar *subfolder;
gnac_prefs_set_subfolder_mode();
gnac_settings_set_int(GNAC_KEY_FOLDER_TYPE, FOLDER_SUBDIRECTORY);
- subfolder = gnac_prefs_entry_get_text("subfolder_entry");
+ const gchar *subfolder = gnac_prefs_entry_get_text("subfolder_entry");
gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, subfolder);
}
@@ -379,8 +384,7 @@ void
gnac_prefs_subfolder_editing_done(GtkWidget *widget,
gpointer data)
{
- const gchar *subfolder;
- subfolder = gtk_entry_get_text(GTK_ENTRY(widget));
+ const gchar *subfolder = gtk_entry_get_text(GTK_ENTRY(widget));
gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, subfolder);
}
@@ -421,11 +425,9 @@ gnac_prefs_update_example_label(GtkWidget *widget,
gchar *clean_label;
gchar *pattern;
gchar *preview;
- GtkWidget *combo;
- GtkWidget *label;
- combo = gnac_prefs_get_widget("folder_hierarchy_combo");
- label = gnac_prefs_get_widget("example_label");
+ 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");
if (!gnac_utils_string_is_null_or_empty(pattern_filename))
@@ -465,20 +467,14 @@ gnac_prefs_button_press_event_cb(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
- GtkWidget *child;
- GType widget_type;
-
if (!gnac_ui_utils_event_is_left_click(event)) return FALSE;
- child = gtk_bin_get_child(GTK_BIN(user_data));
- widget_type = G_OBJECT_TYPE(widget);
+ GtkWidget *child = gtk_bin_get_child(GTK_BIN(user_data));
+ GType widget_type = G_OBJECT_TYPE(widget);
- if (widget_type == GTK_TYPE_COMBO_BOX)
- {
+ if (widget_type == GTK_TYPE_COMBO_BOX) {
gnac_prefs_select_custom_pattern(GTK_COMBO_BOX(widget));
- }
- else if (widget_type == GTK_TYPE_RADIO_BUTTON)
- {
+ } else if (widget_type == GTK_TYPE_RADIO_BUTTON) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
}
@@ -511,12 +507,11 @@ void
gnac_prefs_pattern_changed_cb(GtkWidget *widget,
gpointer data)
{
- gint selected_index;
gboolean is_custom_pattern;
gchar *pattern;
GtkWidget *filename_entry;
- selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+ gint selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
gnac_prefs_update_example_label(widget, data);
@@ -542,12 +537,11 @@ void
gnac_prefs_folder_hierarchy_changed_cb(GtkWidget *widget,
gpointer data)
{
- gint selected_index;
gboolean is_custom_pattern;
gchar *pattern;
GtkWidget *folder_entry;
- selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+ 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");
@@ -601,10 +595,8 @@ gnac_prefs_on_close(GtkWidget *widget,
void
gnac_prefs_destroy(void)
{
- GtkWidget *window;
-
if (gnac_prefs_builder) {
- window = gnac_prefs_get_widget("gnac_preference_window");
+ GtkWidget *window = gnac_prefs_get_widget("gnac_preference_window");
if (window) gtk_widget_destroy(window);
g_object_unref(gnac_prefs_builder);
gnac_prefs_builder = NULL;
diff --git a/src/gnac-properties.c b/src/gnac-properties.c
index 8e4e1e5..954ea91 100644
--- a/src/gnac-properties.c
+++ b/src/gnac-properties.c
@@ -197,11 +197,8 @@ gnac_properties_build_table(void)
gnac_properties_table = g_hash_table_new_full(g_str_hash,
g_str_equal, g_free, (GDestroyNotify)gtk_tree_row_reference_free);
- for (i = 0; displayed_properties[i][0]; i++)
- {
+ for (i = 0; displayed_properties[i][0]; i++) {
GtkTreeIter iter;
- GtkTreePath *path;
- GtkTreeRowReference *ref;
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
@@ -209,8 +206,8 @@ gnac_properties_build_table(void)
PROPERTY_VISIBLE, TRUE,
-1);
- path = gtk_tree_model_get_path(model, &iter);
- ref = gtk_tree_row_reference_new(model, path);
+ GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
+ GtkTreeRowReference *ref = gtk_tree_row_reference_new(model, path);
g_hash_table_insert(gnac_properties_table,
g_strdup(displayed_properties[i][0]), ref);
@@ -325,9 +322,7 @@ static void
gnac_properties_set_entry(const gchar *entry_name,
const GValue *entry_value)
{
- GtkWidget *widget = NULL;
-
- widget = gnac_properties_get_widget(entry_name);
+ GtkWidget *widget = gnac_properties_get_widget(entry_name);
if (!widget) {
gnac_properties_set_property(entry_name, entry_value);
return;
@@ -338,8 +333,7 @@ gnac_properties_set_entry(const gchar *entry_name,
return;
}
- if (LIBGNAC_METADATA_TAG_IS_IMAGE(entry_name))
- {
+ if (LIBGNAC_METADATA_TAG_IS_IMAGE(entry_name)) {
gnac_properties_set_image(widget, entry_value);
return;
}
@@ -373,36 +367,34 @@ static gchar *
gnac_properties_get_property_from_value(const gchar *name,
const GValue *value)
{
- if (LIBGNAC_METADATA_TAG_IS_DURATION(name))
- {
- guint64 duration;
- duration = g_value_get_uint64(value);
+ if (LIBGNAC_METADATA_TAG_IS_DURATION(name)) {
+ guint64 duration = g_value_get_uint64(value);
return gnac_utils_format_duration_for_display(duration);
}
- if (LIBGNAC_METADATA_TAG_IS_BITRATE(name))
- {
+
+ if (LIBGNAC_METADATA_TAG_IS_BITRATE(name)) {
return gnac_properties_dup_bitrate(value);
}
- if (LIBGNAC_METADATA_TAG_IS_FILE_SIZE(name))
- {
+
+ if (LIBGNAC_METADATA_TAG_IS_FILE_SIZE(name)) {
gint64 val = g_value_get_int64(value);
if (val == 0) return NULL;
- gchar *size;
- size = g_format_size_for_display(val);
+ gchar *size = g_format_size_for_display(val);
return size;
}
- if (LIBGNAC_METADATA_TAG_IS_RATE(name))
- {
+
+ if (LIBGNAC_METADATA_TAG_IS_RATE(name)) {
return gnac_properties_dup_rate(value);
}
- if (LIBGNAC_METADATA_TAG_IS_FRAMERATE(name))
- {
+
+ if (LIBGNAC_METADATA_TAG_IS_FRAMERATE(name)) {
return gnac_properties_dup_framerate(value);
}
- if (LIBGNAC_METADATA_TAG_IS_CHANNELS(name))
- {
+
+ if (LIBGNAC_METADATA_TAG_IS_CHANNELS(name)) {
return gnac_properties_dup_channels(value);
}
+
if (LIBGNAC_METADATA_TAG_IS_TRACK_GAIN(name) ||
LIBGNAC_METADATA_TAG_IS_TRACK_PEAK(name))
{
@@ -410,6 +402,7 @@ gnac_properties_get_property_from_value(const gchar *name,
if (val == 0) return NULL;
else return g_strdup_printf("%g", val);
}
+
if (LIBGNAC_METADATA_TAG_IS_AUDIO_CODEC(name)
|| LIBGNAC_METADATA_TAG_IS_CONTAINER(name)
|| LIBGNAC_METADATA_TAG_IS_ENCODER(name)
@@ -422,6 +415,7 @@ gnac_properties_get_property_from_value(const gchar *name,
if (!str) return NULL;
return g_markup_escape_text(str, -1);
}
+
return NULL;
}
@@ -493,8 +487,6 @@ gnac_properties_window_new(void)
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")));
- gtk_window_set_type_hint(GTK_WINDOW(properties_window),
- GDK_WINDOW_TYPE_HINT_DIALOG);
return properties_window;
}
@@ -506,11 +498,10 @@ gnac_properties_update_display(GtkTreeRowReference *reference)
if (!properties_displayed) return;
gchar *uri;
- GFile *file;
if (!gnac_file_list_get(reference, &uri)) return;
- file = g_file_new_for_uri(uri);
+ GFile *file = g_file_new_for_uri(uri);
g_free(uri);
tags = libgnac_metadata_extract(metadata, file, NULL);
@@ -563,9 +554,7 @@ gnac_properties_update_backward_arrow(void)
static void
gnac_properties_reset_spin_if_empty(const gchar *name)
{
- GtkWidget *spin;
-
- spin = gnac_properties_get_widget(name);
+ GtkWidget *spin = gnac_properties_get_widget(name);
if (gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)) == 0) {
gtk_entry_set_text(GTK_ENTRY(spin), "");
@@ -576,13 +565,11 @@ gnac_properties_reset_spin_if_empty(const gchar *name)
void
gnac_properties_window_show(void)
{
- GtkWidget *notebook;
-
if (!gnac_properties_window) {
gnac_properties_window = gnac_properties_window_new();
}
- notebook = gnac_properties_get_widget("notebook1");
+ GtkWidget *notebook = gnac_properties_get_widget("notebook1");
properties_displayed = TRUE;
@@ -637,14 +624,11 @@ gnac_properties_on_back(GtkWidget *widget,
old_ref = gtk_tree_row_reference_copy(current_ref);
- if (gnac_file_list_get_prev_row(¤t_ref))
- {
+ if (gnac_file_list_get_prev_row(¤t_ref)) {
gnac_file_list_select_row_and_follow(current_ref);
gnac_properties_update_display(current_ref);
gtk_tree_row_reference_free(old_ref);
- }
- else
- {
+ } else {
gtk_tree_row_reference_free(current_ref);
current_ref = old_ref;
}
@@ -661,14 +645,11 @@ gnac_properties_on_forward(GtkWidget *widget,
old_ref = gtk_tree_row_reference_copy(current_ref);
- if (gnac_file_list_get_next_row(¤t_ref))
- {
+ if (gnac_file_list_get_next_row(¤t_ref)) {
gnac_file_list_select_row_and_follow(current_ref);
gnac_properties_update_display(current_ref);
gtk_tree_row_reference_free(old_ref);
- }
- else
- {
+ } else {
gtk_tree_row_reference_free(current_ref);
current_ref = old_ref;
}
@@ -699,9 +680,8 @@ gnac_properties_on_delete_event(GtkWidget *widget,
void
gnac_properties_destroy(void)
{
- GtkWidget *window = NULL;
if (gnac_properties_builder) {
- window = gnac_properties_get_widget("properties_window");
+ GtkWidget *window = gnac_properties_get_widget("properties_window");
if (window) gtk_widget_destroy(window);
g_object_unref(gnac_properties_builder);
gnac_properties_builder = NULL;
diff --git a/src/gnac-stock-items.c b/src/gnac-stock-items.c
index a158b3e..d6fc6b4 100644
--- a/src/gnac-stock-items.c
+++ b/src/gnac-stock-items.c
@@ -42,18 +42,15 @@ static const GtkStockItem gnac_stock_items[] = {
static void
gnac_stock_items_register_icons(void)
{
- GtkIconFactory *factory;
- guint i;
-
gtk_stock_add(gnac_stock_items, G_N_ELEMENTS(gnac_stock_items));
- factory = gtk_icon_factory_new();
+ GtkIconFactory *factory = gtk_icon_factory_new();
gtk_icon_factory_add_default(factory);
+ guint 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))
- {
+ 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);
gtk_icon_factory_add(factory, gnac_stock_items[i].stock_id, icon_set);
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index 836de35..200fe95 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -654,12 +654,30 @@ gnac_ui_set_progress_text(const gchar *text)
}
+static void
+gnac_ui_show_widget(const gchar *widget_name,
+ gboolean show)
+{
+ GtkWidget *widget = gnac_ui_get_widget(widget_name);
+ if (show) {
+ gtk_widget_show(widget);
+ } else {
+ gtk_widget_hide(widget);
+ }
+}
+
+
+void
+gnac_ui_show_pause(gboolean show)
+{
+ gnac_ui_show_widget("pause_button", show);
+}
+
+
void
gnac_ui_show_progress(gboolean show)
{
- GtkWidget *progress_bar = gnac_ui_get_widget("progressbar");
- if (show) gtk_widget_show(progress_bar);
- else gtk_widget_hide(progress_bar);
+ gnac_ui_show_widget("progressbar", show);
}
@@ -684,15 +702,6 @@ gnac_ui_pulse_progress(void)
}
-void
-gnac_ui_show_pause(gboolean show)
-{
- GtkWidget *button = gnac_ui_get_widget("pause_button");
- if (show) gtk_widget_show(button);
- else gtk_widget_hide(button);
-}
-
-
void
gnac_ui_push_status(const gchar *message)
{
diff --git a/src/profiles/gnac-profiles-default.c b/src/profiles/gnac-profiles-default.c
index 57202f4..a9c6347 100755
--- a/src/profiles/gnac-profiles-default.c
+++ b/src/profiles/gnac-profiles-default.c
@@ -47,7 +47,7 @@ gnac_profiles_default_init(BasicFormatInfo *bfi)
PKGDATADIR "/profiles/gnac-profiles-base-advanced.xml", &error))
{
libgnac_critical("%s", error->message);
- g_error_free(error);
+ g_clear_error(&error);
gnac_exit(EXIT_FAILURE);
}
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index f037539..c3ac215 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -108,12 +108,6 @@ static void
gnac_profiles_mgr_activate_buttons(gboolean activate);
static void
-gnac_profiles_mgr_show_description_frame(gboolean show);
-
-static void
-gnac_profiles_mgr_show_import_progressbar(gboolean show);
-
-static void
gnac_profiles_mgr_set_progress_bar_fraction(gdouble fraction);
static void
@@ -164,12 +158,38 @@ static void
gnac_profiles_mgr_set_widget_sensitive(const gchar *widget_name,
gboolean sensitive)
{
- GtkWidget *widget;
- widget = gnac_profiles_mgr_get_widget(widget_name);
+ GtkWidget *widget = gnac_profiles_mgr_get_widget(widget_name);
gtk_widget_set_sensitive(widget, sensitive);
}
+static void
+gnac_profiles_mgr_show_widget(const gchar *widget_name,
+ gboolean show)
+{
+ GtkWidget *widget = gnac_profiles_mgr_get_widget(widget_name);
+ if (show) {
+ gtk_widget_show_all(widget);
+ } else {
+ gtk_widget_hide(widget);
+ }
+}
+
+
+static void
+gnac_profiles_mgr_show_description_frame(gboolean show)
+{
+ gnac_profiles_mgr_show_widget("frame-description", show);
+}
+
+
+static void
+gnac_profiles_mgr_show_import_progressbar(gboolean show)
+{
+ gnac_profiles_mgr_show_widget("frame-import", show);
+}
+
+
void
gnac_profiles_mgr_init(void)
{
@@ -177,7 +197,6 @@ gnac_profiles_mgr_init(void)
GtkCellRenderer *renderer;
GtkTreeView *view;
GtkTreeModel *model;
- GtkWidget *widget;
profiles_mgr_builder = gnac_ui_utils_create_gtk_builder(
PKGDATADIR "/profiles/gnac-profiles-manager.xml");
@@ -210,10 +229,6 @@ gnac_profiles_mgr_init(void)
gtk_drag_source_set(GTK_WIDGET(view), GDK_BUTTON1_MASK, target_list,
n_targets, GDK_ACTION_COPY);
- widget = gnac_profiles_mgr_get_widget("profile_manager_window");
- gtk_window_set_modal(GTK_WINDOW(widget), TRUE);
- gtk_window_set_type_hint(GTK_WINDOW(widget), GDK_WINDOW_TYPE_HINT_DIALOG);
-
gnac_profiles_properties_init();
gnac_profiles_mgr_show_import_progressbar(FALSE);
@@ -226,12 +241,10 @@ gnac_profiles_mgr_init(void)
void
gnac_profiles_mgr_set_parent(GtkWindow *parent)
{
- GtkWindow *window;
-
- window = GTK_WINDOW(gnac_profiles_mgr_get_widget("profile_manager_window"));
+ GtkWindow *window = GTK_WINDOW(
+ gnac_profiles_mgr_get_widget("profile_manager_window"));
gtk_window_set_transient_for(window, parent);
gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT);
-
gnac_profiles_properties_set_parent(window);
}
@@ -265,20 +278,11 @@ gnac_profiles_mgr_get_profiles_dir(void)
void
gnac_profiles_mgr_list_profiles(void)
{
- AudioProfileGeneric *profile;
- const gchar *profile_file_name;
- gchar *profile_file_full_path;
- gchar *profile_file_path;
- GError *error = NULL;
- GFile *dir;
- GFile *profile_file;
- GFileEnumerator *files;
- GFileInfo *file_info;
-
- dir = gnac_profiles_mgr_get_profiles_dir();
+ GFile *dir = gnac_profiles_mgr_get_profiles_dir();
if (!dir) return;
- files = g_file_enumerate_children(dir,
+ GError *error = NULL;
+ GFileEnumerator *files = g_file_enumerate_children(dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error);
@@ -305,13 +309,16 @@ gnac_profiles_mgr_list_profiles(void)
gchar *last_used_profile = g_settings_get_string(settings,
GNAC_KEY_LAST_USED_PROFILE);
- GSList *profiles = NULL;
+ GFileInfo *file_info;
+ GSList *profiles = NULL;
+
while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
- profile_file = g_file_enumerator_get_container(files);
- profile_file_path = g_file_get_path(profile_file);
- profile_file_name = g_file_info_get_name(file_info);
- profile_file_full_path = g_build_filename(profile_file_path,
+ AudioProfileGeneric *profile;
+ GFile *profile_file = g_file_enumerator_get_container(files);
+ gchar *profile_file_path = g_file_get_path(profile_file);
+ const gchar *profile_file_name = g_file_info_get_name(file_info);
+ gchar *profile_file_full_path = g_build_filename(profile_file_path,
profile_file_name, NULL);
gnac_profiles_default_load_generic_audio_profile(profile_file_full_path,
&profile);
@@ -320,7 +327,6 @@ gnac_profiles_mgr_list_profiles(void)
profiles = g_slist_append(profiles, name);
}
- /* Cleanup */
g_free(profile_file_path);
g_free(profile_file_full_path);
}
@@ -336,7 +342,7 @@ gnac_profiles_mgr_list_profiles(void)
} else {
/* check if last_used_profile exists */
if (!g_slist_find_custom(profiles, last_used_profile,
- (GCompareFunc)g_strcmp0))
+ (GCompareFunc) g_strcmp0))
{
last_used_profile = NULL;
}
@@ -357,7 +363,6 @@ gnac_profiles_mgr_list_profiles(void)
g_print("\n");
- /* Cleanup */
g_slist_free(profiles);
g_free(last_used_profile);
g_object_unref(dir);
@@ -369,19 +374,11 @@ gnac_profiles_mgr_list_profiles(void)
static void
gnac_profiles_mgr_populate(void)
{
- gpointer profile;
- GFile *dir;
- GFile *profile_file;
- gchar *profile_file_path;
- gchar *profile_file_full_path;
- const gchar *profile_file_name;
- GFileInfo *file_info;
- GFileEnumerator *files;
- GError *error = NULL;
-
gnac_profiles_mgr_clear();
- dir = g_file_new_for_path(saved_profiles_dir);
+ GError *error = NULL;
+
+ GFile *dir = g_file_new_for_path(saved_profiles_dir);
if (!g_file_query_exists(dir, NULL)) {
if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
const gchar *msg = N_("Unable to create the profiles directory");
@@ -400,7 +397,7 @@ gnac_profiles_mgr_populate(void)
/* TODO if the profiles directory exists, but does not
* contain any profile, import the default ones */
- files = g_file_enumerate_children(dir,
+ GFileEnumerator *files = g_file_enumerate_children(dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error);
@@ -412,15 +409,16 @@ gnac_profiles_mgr_populate(void)
return;
}
- while ((file_info = g_file_enumerator_next_file(files, NULL, NULL)) != NULL)
+ GFileInfo *file_info;
+ while ((file_info = g_file_enumerator_next_file(files, NULL, NULL)))
{
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
- profile_file = g_file_enumerator_get_container(files);
- profile_file_path = g_file_get_path(profile_file);
- profile_file_name = g_file_info_get_name(file_info);
- profile_file_full_path = g_build_filename(profile_file_path,
+ GFile *profile_file = g_file_enumerator_get_container(files);
+ gchar *profile_file_path = g_file_get_path(profile_file);
+ const gchar *profile_file_name = g_file_info_get_name(file_info);
+ gchar *profile_file_full_path = g_build_filename(profile_file_path,
profile_file_name, NULL);
- profile = gnac_profiles_properties_load_profile_from_file(
+ gpointer profile = gnac_profiles_properties_load_profile_from_file(
profile_file_full_path, profile_file_name, &error);
g_free(profile_file_path);
@@ -445,31 +443,17 @@ gnac_profiles_mgr_populate(void)
}
-static void
-gnac_profiles_mgr_import_default_profiles(void)
+static GFileEnumerator *
+gnac_profiles_mgr_get_default_profiles_enumerator(void)
{
- gpointer profile;
- GFile *dir;
- GFile *profile_file;
- gchar *profile_file_path;
- gchar *profile_file_full_path;
- const gchar *profile_file_name;
- GFileInfo *file_info;
- GFileEnumerator *files;
- GError *error = NULL;
-
- gnac_profiles_mgr_clear();
-
- dir = g_file_new_for_path(PKGDATADIR "/profiles/default");
+ GFile *dir = g_file_new_for_path(PKGDATADIR "/profiles/default");
if (!g_file_query_exists(dir, NULL)) {
- libgnac_warning("%s: %s",
- _("Unable to find the default profiles directory"),
- error->message);
- g_clear_error(&error);
- return;
+ libgnac_warning("%s", _("Unable to find the default profiles directory"));
+ return NULL;
}
- files = g_file_enumerate_children(dir,
+ GError *error = NULL;
+ GFileEnumerator *files = g_file_enumerate_children(dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error);
@@ -478,18 +462,33 @@ gnac_profiles_mgr_import_default_profiles(void)
_("Unable to browse the default profiles directory"),
error->message);
g_clear_error(&error);
- return;
+ g_object_unref(dir);
+ return NULL;
}
- while ((file_info = g_file_enumerator_next_file(files, NULL, NULL)))
- {
+ g_object_unref(dir);
+
+ return files;
+}
+
+
+static void
+gnac_profiles_mgr_import_default_profiles(void)
+{
+ gnac_profiles_mgr_clear();
+
+ GFileEnumerator *files = gnac_profiles_mgr_get_default_profiles_enumerator();
+
+ GFileInfo *file_info;
+ while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
- profile_file = g_file_enumerator_get_container(files);
- profile_file_path = g_file_get_path(profile_file);
- profile_file_name = g_file_info_get_name(file_info);
- profile_file_full_path = g_build_filename(profile_file_path,
+ GError *error = NULL;
+ GFile *profile_file = g_file_enumerator_get_container(files);
+ gchar *profile_file_path = g_file_get_path(profile_file);
+ const gchar *profile_file_name = g_file_info_get_name(file_info);
+ gchar *profile_file_full_path = g_build_filename(profile_file_path,
profile_file_name, NULL);
- profile = gnac_profiles_properties_load_profile_from_file(
+ gpointer profile = gnac_profiles_properties_load_profile_from_file(
profile_file_full_path, profile_file_name, &error);
if (profile) {
@@ -507,7 +506,6 @@ gnac_profiles_mgr_import_default_profiles(void)
g_object_unref(G_OBJECT(file_info));
}
- g_object_unref(dir);
g_file_enumerator_close(files, NULL, NULL);
g_object_unref(files);
}
@@ -520,12 +518,12 @@ gnac_profiles_mgr_get_profiles_list(void)
GList *list = NULL;
GtkTreeModel *model;
GtkTreeIter iter;
- AudioProfileGeneric *profile;
model = GTK_TREE_MODEL(gnac_profiles_mgr_get_object("liststore"));
has_next = gtk_tree_model_get_iter_first(model, &iter);
while (has_next) {
+ AudioProfileGeneric *profile;
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
list = g_list_append(list, profile);
has_next = gtk_tree_model_iter_next(model, &iter);
@@ -538,14 +536,12 @@ gnac_profiles_mgr_get_profiles_list(void)
void
gnac_profiles_mgr_destroy(void)
{
- GtkWidget *widget;
-
gnac_profiles_mgr_clear();
if (profiles_mgr_builder) {
- widget = gnac_profiles_mgr_get_widget("profile_manager_window");
- g_object_unref(profiles_mgr_builder);
+ GtkWidget *widget = gnac_profiles_mgr_get_widget("profile_manager_window");
gtk_widget_destroy(widget);
+ g_object_unref(profiles_mgr_builder);
}
gnac_profiles_properties_destroy();
@@ -555,8 +551,6 @@ gnac_profiles_mgr_destroy(void)
void
gnac_profiles_mgr_show(void)
{
- GtkWidget *window;
- GList *selected;
static gboolean first_show = TRUE;
if (!first_show) {
@@ -565,10 +559,10 @@ gnac_profiles_mgr_show(void)
first_show = FALSE;
}
- window = gnac_profiles_mgr_get_widget("profile_manager_window");
+ GtkWidget *window = gnac_profiles_mgr_get_widget("profile_manager_window");
gtk_widget_show(window);
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) {
gnac_profiles_mgr_show_description_frame(FALSE);
gnac_profiles_mgr_activate_buttons(FALSE);
@@ -581,15 +575,15 @@ gnac_profiles_mgr_show(void)
static void
gnac_profiles_mgr_clear(void)
{
- gboolean has_next;
- GtkTreeModel *model;
- GtkTreeIter iter;
- AudioProfileGeneric *profile;
+ gboolean has_next;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
model = GTK_TREE_MODEL(gnac_profiles_mgr_get_object("liststore"));
has_next = gtk_tree_model_get_iter_first(model, &iter);
while (has_next) {
+ AudioProfileGeneric *profile;
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
gnac_profiles_properties_free_audio_profile(profile);
has_next = gtk_tree_model_iter_next(model, &iter);
@@ -607,7 +601,7 @@ gnac_profiles_mgr_insert(gpointer profile)
AudioProfileGeneric *generic;
gchar *formatted_name;
- generic = ((AudioProfileGeneric*) profile)->generic;
+ generic = AUDIO_PROFILE_GET_GENERIC(profile);
model = GTK_LIST_STORE(gnac_profiles_mgr_get_object("liststore"));
formatted_name = gnac_profiles_properties_filter_text_for_displaying(
@@ -627,25 +621,25 @@ gnac_profiles_mgr_insert(gpointer profile)
static void
gnac_profiles_mgr_remove(GtkTreeRowReference *ref)
{
+ g_return_if_fail(ref);
+
GtkTreeModel *model;
GtkTreePath *path;
- g_return_if_fail(ref);
-
model = GTK_TREE_MODEL(gnac_profiles_mgr_get_object("liststore"));
path = gtk_tree_row_reference_get_path(ref);
if (!path) return;
- AudioProfileGeneric *profile;
- GtkTreeIter iter;
+ GtkTreeIter iter;
if (gtk_tree_model_get_iter(model, &iter, path)) {
+ AudioProfileGeneric *profile;
gtk_tree_model_get(model, &iter, COL_PROFILE, &profile, -1);
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
+ gnac_profiles_properties_free_audio_profile(profile);
}
gtk_tree_path_free(path);
- gnac_profiles_properties_free_audio_profile(profile);
}
@@ -740,36 +734,6 @@ gnac_profiles_mgr_activate_buttons(gboolean activate)
static void
-gnac_profiles_mgr_show_description_frame(gboolean show)
-{
- GtkWidget *widget;
-
- widget = gnac_profiles_mgr_get_widget("frame-description");
-
- if (show) {
- gtk_widget_show_all(widget);
- } else {
- gtk_widget_hide(widget);
- }
-}
-
-
-static void
-gnac_profiles_mgr_show_import_progressbar(gboolean show)
-{
- GtkWidget *widget;
-
- widget = gnac_profiles_mgr_get_widget("frame-import");
-
- if (show) {
- gtk_widget_show_all(widget);
- } else {
- gtk_widget_hide(widget);
- }
-}
-
-
-static void
gnac_profiles_mgr_set_window_sensitive(gboolean sensitive)
{
gnac_profiles_mgr_set_widget_sensitive("frame-profiles-list", sensitive);
@@ -782,8 +746,7 @@ gnac_profiles_mgr_set_window_sensitive(gboolean sensitive)
static void
gnac_profiles_mgr_set_progress_bar_fraction(gdouble fraction)
{
- GtkWidget *widget;
- widget = gnac_profiles_mgr_get_widget("progressbar-import");
+ GtkWidget *widget = gnac_profiles_mgr_get_widget("progressbar-import");
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widget), fraction);
}
@@ -792,9 +755,7 @@ static void
gnac_profiles_mgr_display_status_message(const gchar *success_message,
const gchar *error_message)
{
- GtkWidget *frame_status;
-
- frame_status = gnac_profiles_mgr_get_widget("frame-status");
+ GtkWidget *frame_status = gnac_profiles_mgr_get_widget("frame-status");
if (!success_message && !error_message) {
gtk_widget_hide(frame_status);
@@ -843,16 +804,13 @@ gnac_profiles_mgr_on_drag_data_received(GtkWidget *widget,
guint time,
gpointer data)
{
- gchar **uris;
-
- uris = g_uri_list_extract_uris((const gchar*) selection_data->data);
+ gchar **uris = g_uri_list_extract_uris((const gchar*) selection_data->data);
if (!uris) {
gtk_drag_finish(context, FALSE, FALSE, time);
return;
}
- ThreadCopyData *tcopy_data;
- tcopy_data = g_malloc(sizeof(ThreadCopyData));
+ ThreadCopyData *tcopy_data = g_malloc(sizeof(ThreadCopyData));
tcopy_data->uris = uris;
tcopy_data->info = info;
@@ -875,11 +833,9 @@ static gchar *
gnac_profiles_mgr_get_file_name(GFile *file,
guint target_type)
{
- gchar *name;
- GError *error = NULL;
- GFileInfo *file_info;
+ GError *error = NULL;
- file_info = g_file_query_info(file,
+ GFileInfo *file_info = g_file_query_info(file,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error);
@@ -889,6 +845,8 @@ gnac_profiles_mgr_get_file_name(GFile *file,
return NULL;
}
+ gchar *name;
+
switch (target_type)
{
case TARGET_URI:
@@ -928,9 +886,9 @@ gnac_profiles_mgr_display_import_status(guint profiles_ok,
}
gdk_threads_enter();
- gnac_profiles_mgr_set_window_sensitive(TRUE);
- gnac_profiles_mgr_show_import_progressbar(FALSE);
- gnac_profiles_mgr_display_status_message(oks, errors);
+ gnac_profiles_mgr_set_window_sensitive(TRUE);
+ gnac_profiles_mgr_show_import_progressbar(FALSE);
+ gnac_profiles_mgr_display_status_message(oks, errors);
gdk_threads_leave();
g_free(oks);
@@ -956,7 +914,7 @@ gnac_profiles_mgr_copy_file(GFile *src_file,
copy_data.toggle = FALSE;
gdk_threads_enter();
- gnac_profiles_mgr_set_progress_bar_fraction(0.0);
+ gnac_profiles_mgr_set_progress_bar_fraction(0.0);
gdk_threads_leave();
success = g_file_copy(src_file, dest_file, G_FILE_COPY_NONE, NULL,
@@ -977,29 +935,25 @@ gnac_profiles_mgr_copy_file(GFile *src_file,
static void
gnac_profiles_mgr_copy_and_load_files(gpointer data)
{
- gchar **uris;
- gchar *uri;
- guint profiles_ok = 0;
- guint profiles_error = 0;
- gint index = 0;
- ThreadCopyData *tcopy_data;
+ gchar *uri;
+ guint profiles_ok = 0;
+ guint profiles_error = 0;
+ gint index = 0;
- tcopy_data = (ThreadCopyData*) data;
- uris = tcopy_data->uris;
+ ThreadCopyData *tcopy_data = (ThreadCopyData *) data;
+ gchar **uris = tcopy_data->uris;
uri = uris[index];
gdk_threads_enter();
- gnac_profiles_mgr_set_window_sensitive(FALSE);
- gnac_profiles_mgr_show_import_progressbar(TRUE);
+ gnac_profiles_mgr_set_window_sensitive(FALSE);
+ gnac_profiles_mgr_show_import_progressbar(TRUE);
gdk_threads_leave();
while (uri) {
- gchar *name;
- GFile *file;
+ GFile *file = g_file_new_for_uri(uri);
+ gchar *name = gnac_profiles_mgr_get_file_name(file, tcopy_data->info);
- file = g_file_new_for_uri(uri);
- name = gnac_profiles_mgr_get_file_name(file, tcopy_data->info);
if (!name) {
libgnac_warning(
_("Impossible to import file \"%s\". File type not supported."),
@@ -1036,35 +990,32 @@ gnac_profiles_mgr_on_drag_profile_copied(goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
{
- AudioProfileGeneric *profile;
- CopyData *copy_data;
- GFile *file;
-
/* CLAMP ensures that frac is between 0.0 and 1.0 */
gdouble frac = CLAMP(
((gdouble) current_num_bytes) / ((gdouble) total_num_bytes),
0.0, 1.0);
gdk_threads_enter();
- gnac_profiles_mgr_set_progress_bar_fraction(frac);
+ gnac_profiles_mgr_set_progress_bar_fraction(frac);
gdk_threads_leave();
if (current_num_bytes >= total_num_bytes) {
- copy_data = (CopyData *) user_data;
+ CopyData *copy_data = (CopyData *) user_data;
if (!copy_data->toggle) {
copy_data->toggle = TRUE;
} else {
+ AudioProfileGeneric *profile;
profile = gnac_profiles_properties_load_profile_from_file(
copy_data->path, copy_data->name, copy_data->error);
if (profile && !(*(copy_data->error))) {
gdk_threads_enter();
- gnac_profiles_properties_save_profile(profile);
- gnac_profiles_mgr_insert(profile);
+ gnac_profiles_properties_save_profile(profile);
+ gnac_profiles_mgr_insert(profile);
gdk_threads_leave();
}
- file = g_file_new_for_path(copy_data->path);
+ GFile *file = g_file_new_for_path(copy_data->path);
g_file_delete(file, NULL, NULL);
g_object_unref(file);
@@ -1081,8 +1032,7 @@ gnac_profiles_mgr_on_drag_data_get(GtkWidget *widget,
guint time,
gpointer user_data)
{
- gchar **uris;
- uris = gnac_profiles_mgr_get_selected_uris();
+ gchar **uris = gnac_profiles_mgr_get_selected_uris();
gtk_selection_data_set_uris(data, uris);
}
@@ -1090,29 +1040,22 @@ gnac_profiles_mgr_on_drag_data_get(GtkWidget *widget,
static gchar **
gnac_profiles_mgr_get_selected_uris(void)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return NULL;
- gchar **uris;
- GtkTreeRowReference *reference;
-
- reference = (GtkTreeRowReference*) selected->data;
- uris = g_malloc((g_list_length(selected)+1) * sizeof(gchar*));
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
+ gchar **uris = g_malloc((g_list_length(selected)+1) * sizeof(gchar *));
guint i;
GList *temp;
for (i = 0, temp = selected; temp; temp = temp->next, ++i) {
- GFile *file;
AudioProfileGeneric *profile;
- gchar *path;
-
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
profile = profile->generic;
- path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(profile->name), NULL);
- file = g_file_new_for_path(path);
+ gchar *path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(profile->name),
+ NULL);
+ GFile *file = g_file_new_for_path(path);
uris[i] = g_file_get_uri(file);
g_free(path);
@@ -1148,38 +1091,27 @@ void
gnac_profiles_mgr_on_copy(GtkWidget *widget,
gpointer data)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return;
- AudioProfileGeneric *copy_profile;
- AudioProfileGeneric *generic;
- AudioProfileGeneric *profile;
- gchar *full_path;
- gchar *new_name;
- gchar *new_path;
- GError *error = NULL;
- GFile *dst;
- GFile *src;
- GtkTreeRowReference *reference;
-
- reference = (GtkTreeRowReference*) selected->data;
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
+ AudioProfileGeneric *profile;
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
- generic = profile->generic;
+ AudioProfileGeneric *generic = profile->generic;
- full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(generic->name),
+ gchar *full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(generic->name),
NULL);
- new_name = g_strconcat(GNAC_SAVED_PROFILES_URL(generic->name),
+ gchar *new_name = g_strconcat(GNAC_SAVED_PROFILES_URL(generic->name),
gettext(GNAC_COPY_SUFFIX), NULL);
- new_path = g_strconcat(new_name, ".xml", NULL);
+ gchar *new_path = g_strconcat(new_name, ".xml", NULL);
- src = g_file_new_for_path(full_path);
- dst = g_file_new_for_path(new_path);
+ GFile *src = g_file_new_for_path(full_path);
+ GFile *dst = g_file_new_for_path(new_path);
g_free(full_path);
+ GError *error = NULL;
g_file_copy(src, dst, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
if (error)
{
@@ -1198,6 +1130,7 @@ gnac_profiles_mgr_on_copy(GtkWidget *widget,
return;
}
+ AudioProfileGeneric *copy_profile;
copy_profile = gnac_profiles_properties_load_profile_from_file(
new_path, new_name, &error);
if (copy_profile)
@@ -1228,15 +1161,11 @@ void
gnac_profiles_mgr_on_edit(GtkWidget *widget,
gpointer data)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return;
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
AudioProfileGeneric *profile;
- GtkTreeRowReference *reference;
-
- reference = (GtkTreeRowReference*) selected->data;
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
profile->generic->user_data = selected->data;
@@ -1251,31 +1180,23 @@ static void
gnac_profiles_mgr_on_edit_profile(GtkWidget *widget,
gpointer data)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return;
- AudioProfileGeneric *generic;
- AudioProfileGeneric *old_generic;
- AudioProfileGeneric *old_profile;
- AudioProfileGeneric *profile;
- gchar *formatted_name;
- GtkTreeRowReference *reference;
-
- reference = (GtkTreeRowReference*) selected->data;
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
+ AudioProfileGeneric *old_profile;
gnac_profiles_mgr_get(reference, COL_PROFILE, &old_profile);
- old_generic = old_profile->generic;
+ AudioProfileGeneric *old_generic = old_profile->generic;
- profile = (AudioProfileGeneric*) data;
- generic = profile->generic;
+ AudioProfileGeneric *profile = (AudioProfileGeneric *) data;
+ AudioProfileGeneric *generic = profile->generic;
if (!gnac_utils_str_equal(generic->name, old_generic->name)) {
gnac_profiles_mgr_delete_profile_file(old_generic->name);
}
- formatted_name = gnac_profiles_properties_filter_text_for_displaying(
+ gchar *formatted_name = gnac_profiles_properties_filter_text_for_displaying(
generic->name, MAX_NAME_DISPLAY_SIZE);
gnac_profiles_mgr_set(reference,
COL_NAME, formatted_name,
@@ -1298,28 +1219,22 @@ void
gnac_profiles_mgr_on_remove(GtkWidget *widget,
gpointer data)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return;
- AudioProfileGeneric *profile;
- gboolean new_selected = FALSE;
- GtkTreeIter iter;
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeRowReference *reference;
-
- reference = (GtkTreeRowReference*) selected->data;
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
+ AudioProfileGeneric *profile;
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
gnac_profiles_mgr_delete_profile_file(profile->generic->name);
gnac_profiles_mgr_display_status_message(NULL, NULL);
- model = gtk_tree_row_reference_get_model(reference);
- path = gtk_tree_row_reference_get_path(reference);
+ GtkTreeModel *model = gtk_tree_row_reference_get_model(reference);
+ GtkTreePath *path = gtk_tree_row_reference_get_path(reference);
+ GtkTreeIter iter;
+ gboolean new_selected = FALSE;
if (gtk_tree_model_get_iter(model, &iter, path)) {
if (gtk_tree_model_iter_next(model, &iter)
|| (gtk_tree_path_prev(path) &&
@@ -1348,11 +1263,9 @@ gnac_profiles_mgr_on_remove(GtkWidget *widget,
static void
gnac_profiles_mgr_delete_profile_file(const gchar *name)
{
- GFile *file;
- gchar *full_path;
-
- full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(name), NULL);
- file = g_file_new_for_path(full_path);
+ gchar *full_path = g_strconcat(GNAC_SAVED_PROFILES_URL_WITH_EXT(name), NULL);
+ GFile *file = g_file_new_for_path(full_path);
+
g_file_delete(file, NULL, NULL);
g_object_unref(file);
@@ -1363,24 +1276,18 @@ gnac_profiles_mgr_delete_profile_file(const gchar *name)
static void
gnac_profiles_mgr_on_treeselection_changed(void)
{
- GList *selected;
-
- selected = gnac_profiles_mgr_get_selected_rows();
+ GList *selected = gnac_profiles_mgr_get_selected_rows();
if (!selected) return;
- AudioProfileGeneric *profile;
- gchar *descr;
- GtkTreeRowReference *reference;
- GtkWidget *widget;
-
- reference = (GtkTreeRowReference*) selected->data;
+ GtkTreeRowReference *reference = (GtkTreeRowReference *) selected->data;
gnac_profiles_mgr_activate_buttons(TRUE);
gnac_profiles_mgr_display_status_message(NULL, NULL);
+ AudioProfileGeneric *profile;
gnac_profiles_mgr_get(reference, COL_PROFILE, &profile);
- widget = gnac_profiles_mgr_get_widget("label-description-content");
- descr = gnac_profiles_properties_filter_text_for_displaying(
+ GtkWidget *widget = gnac_profiles_mgr_get_widget("label-description-content");
+ gchar *descr = gnac_profiles_properties_filter_text_for_displaying(
profile->generic->description, MAX_DESCR_DISPLAY_SIZE);
gtk_label_set_text(GTK_LABEL(widget), descr);
@@ -1396,8 +1303,7 @@ void
gnac_profiles_mgr_on_close(GtkWidget *widget,
gpointer data)
{
- GtkWidget *window;
- window = gnac_profiles_mgr_get_widget("profile_manager_window");
+ GtkWidget *window = gnac_profiles_mgr_get_widget("profile_manager_window");
gtk_widget_hide(window);
gnac_profiles_populate_combo();
}
diff --git a/src/profiles/gnac-profiles-properties.c b/src/profiles/gnac-profiles-properties.c
index d039441..2e646d3 100644
--- a/src/profiles/gnac-profiles-properties.c
+++ b/src/profiles/gnac-profiles-properties.c
@@ -169,10 +169,7 @@ gnac_profiles_properties_init(void)
void
gnac_profiles_properties_set_parent(GtkWindow *parent)
{
- GtkWindow *window;
-
- window = GTK_WINDOW(gnac_profiles_properties_get_widget("window1"));
-
+ GtkWindow *window = GTK_WINDOW(gnac_profiles_properties_get_widget("window1"));
gtk_window_set_transient_for(window, parent);
gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT);
}
@@ -280,7 +277,7 @@ gnac_profiles_properties_show(gpointer profile,
AudioProfileGeneric *generic;
const gchar *format_id;
- generic = ((AudioProfileGeneric*)profile)->generic;
+ generic = AUDIO_PROFILE_GET_GENERIC(profile);
format_id = generic->format_id;
if (!format_id) return;
@@ -318,7 +315,7 @@ gnac_profiles_properties_free_audio_profile(gpointer profile)
AudioProfileGeneric *generic;
const gchar *format_id;
- generic = ((AudioProfileGeneric*)profile)->generic;
+ generic = AUDIO_PROFILE_GET_GENERIC(profile);
format_id = generic->format_id;
if (!format_id) return;
@@ -339,14 +336,13 @@ gnac_profiles_properties_destroy(void)
{
if (!formats) return;
- GList *list;
- GList *temp;
- GtkWidget *window;
- FormatModule *format_module;
+ GList *list;
+ GList *temp;
list = g_hash_table_get_values(formats);
for (temp = list; temp; temp = temp->next) {
- format_module = ((FormatModule*)temp->data);
+ FormatModule *format_module;
+ format_module = (FormatModule *) temp->data;
format_module->funcs.clean_up();
g_free(format_module);
}
@@ -356,7 +352,7 @@ gnac_profiles_properties_destroy(void)
formats = NULL;
g_free(saved_profiles_dir);
- window = gnac_profiles_properties_get_widget("window1");
+ GtkWidget *window = gnac_profiles_properties_get_widget("window1");
gtk_widget_destroy(window);
g_object_unref(G_OBJECT(profiles_properties_builder));
}
@@ -369,14 +365,13 @@ gnac_profiles_properties_combo_format_on_changed(GtkComboBox *widget,
GtkWidget *properties;
GtkWidget *label;
GtkWidget *text_view;
- GtkTreeModel *model;
GtkTreeIter iter;
FormatModule *format_module;
- model = gtk_combo_box_get_model(widget);
+ GtkTreeModel *model = gtk_combo_box_get_model(widget);
if (!gtk_combo_box_get_active_iter(widget, &iter)) return;
- gtk_tree_model_get(model, &iter, 1, (gpointer*)&format_module, -1);
+ gtk_tree_model_get(model, &iter, 1, &format_module, -1);
gnac_profiles_properties_display_status_message(NULL);
@@ -419,9 +414,8 @@ gnac_profiles_properties_update_textbuffer(const gchar *pipeline)
static void
gnac_profiles_properties_display_status_message(const gchar *error_message)
{
- GtkWidget *widget;
-
- widget = gnac_profiles_properties_get_widget("hbox-properties-status");
+ GtkWidget *widget = gnac_profiles_properties_get_widget(
+ "hbox-properties-status");
if (!error_message) {
gtk_widget_hide(widget);
@@ -447,7 +441,7 @@ gnac_profiles_properties_reinit(void)
list = g_hash_table_get_values(formats);
for (temp = list; temp; temp = temp->next) {
- ((FormatModule*)temp->data)->funcs.fullfill_fields(NULL);
+ ((FormatModule *) temp->data)->funcs.fullfill_fields(NULL);
}
g_list_free(list);
@@ -468,9 +462,7 @@ gnac_profiles_properties_name_set_text(const gchar *name)
{
if (!name) return;
- GtkWidget *widget;
-
- widget = gnac_profiles_properties_get_widget("name_entry");
+ GtkWidget *widget = gnac_profiles_properties_get_widget("name_entry");
gtk_entry_set_text(GTK_ENTRY(widget), name);
current_profile_name = name;
}
@@ -481,9 +473,7 @@ gnac_profiles_properties_description_set_text(const gchar *description)
{
if (!description) return;
- GtkTextBuffer *text_buffer;
-
- text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
+ GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
gnac_profiles_properties_get_widget("profile_description_text_view")));
gtk_text_buffer_set_text(text_buffer, description,
g_utf8_strlen(description, -1));
@@ -494,28 +484,25 @@ static void
gnac_profiles_properties_on_save(GtkWidget *widget,
gpointer data)
{
- AudioProfileGeneric *generic;
- const gchar *name;
- gpointer profile;
- GtkWidget *text_view;
- GtkWidget *window;
- GError *error = NULL;
+ gpointer profile;
+ GError *error = NULL;
StandardCallBack call_back = (StandardCallBack) data;
- window = gnac_profiles_properties_get_widget("window1");
+ GtkWidget *window = gnac_profiles_properties_get_widget("window1");
profile = current_format_module->funcs.generate_audio_profile(&error);
if (!profile) {
if (error) {
gnac_profiles_properties_display_status_message(error->message);
- g_error_free(error);
+ g_clear_error(&error);
}
return;
}
- text_view = gnac_profiles_properties_get_widget("gstreamer_pipeline_text_view");
- generic = ((AudioProfileGeneric*) profile)->generic;
+ GtkWidget *text_view = gnac_profiles_properties_get_widget(
+ "gstreamer_pipeline_text_view");
+ AudioProfileGeneric *generic = AUDIO_PROFILE_GET_GENERIC(profile);
if (!generic->pipeline) {
generic->pipeline = gnac_profiles_utils_text_view_get_text(
@@ -523,7 +510,7 @@ gnac_profiles_properties_on_save(GtkWidget *widget,
}
widget = gnac_profiles_properties_get_widget("name_entry");
- name = gtk_entry_get_text(GTK_ENTRY(widget));
+ const gchar *name = gtk_entry_get_text(GTK_ENTRY(widget));
if (!gnac_profiles_properties_is_valid_profile_name(name)) return;
@@ -590,8 +577,7 @@ gnac_profiles_properties_on_name_entry_key_pressed(GtkWidget *widget,
return FALSE;
}
- gchar *message;
- message = g_strconcat(
+ gchar *message = g_strconcat(
_("Profile name cannot contain the following characters:"),
" ", forbidden_chars_string, NULL);
gnac_profiles_properties_display_status_message(message);
@@ -607,8 +593,7 @@ gnac_profiles_properties_on_window_key_pressed(GtkWidget *widget,
gpointer data)
{
if (gnac_ui_utils_event_is_escape_key(event)) {
- GtkWidget *widget;
- widget = gnac_profiles_properties_get_widget("cancel-button");
+ GtkWidget *widget = gnac_profiles_properties_get_widget("cancel-button");
gtk_button_clicked(GTK_BUTTON(widget));
return TRUE;
}
@@ -655,8 +640,7 @@ void
gnac_profiles_properties_on_cancel(GtkWidget *widget,
gpointer data)
{
- GtkWidget *window;
- window = gnac_profiles_properties_get_widget("window1");
+ GtkWidget *window = gnac_profiles_properties_get_widget("window1");
gtk_widget_hide(window);
}
@@ -722,14 +706,10 @@ gnac_profiles_properties_saved_profiles_contain_name(const gchar *name)
void
gnac_profiles_properties_save_profile(gpointer profile)
{
- const gchar *format_id;
-
- format_id = ((AudioProfileGeneric*)profile)->generic->format_id;
+ const gchar *format_id = AUDIO_PROFILE_GET_GENERIC(profile)->format_id;
if (!format_id) return;
- FormatModule *format_module;
-
- format_module = g_hash_table_lookup(formats, format_id);
+ FormatModule *format_module = g_hash_table_lookup(formats, format_id);
if (format_module) {
format_module->funcs.save_profile_in_file(profile);
}
@@ -743,9 +723,9 @@ gnac_profiles_properties_filter_text_for_displaying(const gchar *text,
if (!text) return NULL;
gchar *filtered;
- glong length;
- length = g_utf8_strlen(text, -1);
+ glong length = g_utf8_strlen(text, -1);
+
if (length > chars_to_display) {
gchar *prefix;
prefix = g_strndup(text, length);
diff --git a/src/profiles/gnac-profiles-utils.h b/src/profiles/gnac-profiles-utils.h
index b0a6eab..852daf9 100755
--- a/src/profiles/gnac-profiles-utils.h
+++ b/src/profiles/gnac-profiles-utils.h
@@ -32,6 +32,9 @@
#include "gnac-profiles-xml-engine.h"
+#define AUDIO_PROFILE_GET_GENERIC(profile) \
+ ((AudioProfileGeneric *)(profile))->generic
+
G_BEGIN_DECLS
typedef struct _audio_profile_generic
diff --git a/src/profiles/gnac-profiles-xml-engine.c b/src/profiles/gnac-profiles-xml-engine.c
index 2c3ff66..328af19 100755
--- a/src/profiles/gnac-profiles-xml-engine.c
+++ b/src/profiles/gnac-profiles-xml-engine.c
@@ -29,6 +29,7 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
+
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
@@ -125,7 +126,7 @@ gnac_profiles_xml_engine_get_text_node(XMLDoc *dx,
if (node->children) {
xmlXPathFreeObject(xpath_obj);
- return g_strdup(gettext((const gchar *)node->children->content));
+ return g_strdup(gettext((const gchar *) node->children->content));
}
}
}
@@ -328,25 +329,25 @@ gnac_profiles_xml_engine_get_slider_values(XMLDoc *dx,
"default-value"))
{
default_value = g_ascii_strtod(
- (const gchar*) current_node->children->content, NULL);
+ (const gchar *) current_node->children->content, NULL);
}
else if (gnac_profiles_xml_engine_node_name_equal(current_node,
"min-value"))
{
min = g_ascii_strtod(
- (const gchar*) current_node->children->content, NULL);
+ (const gchar *) current_node->children->content, NULL);
}
else if (gnac_profiles_xml_engine_node_name_equal(current_node,
"max-value"))
{
max = g_ascii_strtod(
- (const gchar*) current_node->children->content, NULL);
+ (const gchar *) current_node->children->content, NULL);
}
else if (gnac_profiles_xml_engine_node_name_equal(current_node,
"step-value"))
{
step = g_ascii_strtod(
- (const gchar*) current_node->children->content, NULL);
+ (const gchar *) current_node->children->content, NULL);
}
}
@@ -396,7 +397,7 @@ gnac_profiles_xml_engine_get_check_values(XMLDoc *dx,
if (gnac_profiles_xml_engine_node_name_equal(current_node,
"variable-name"))
{
- variable_name = g_strdup((gchar*) current_node->children->content);
+ variable_name = g_strdup((gchar *) current_node->children->content);
}
else if (gnac_profiles_xml_engine_node_name_equal(current_node,
"control-type"))
@@ -452,11 +453,8 @@ gnac_profiles_xml_engine_modify_values(XMLDoc *dx,
gint i;
for (i = nodes->nodeNr-1; i >= 0; i--) {
- gchar *value_formatted;
-
- value_formatted = gnac_profiles_xml_engine_format_text_to_xml(value);
+ gchar *value_formatted = gnac_profiles_xml_engine_format_text_to_xml(value);
xmlNodeSetContent(nodes->nodeTab[i], BAD_CAST value_formatted);
-
g_free(value_formatted);
if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL) nodes->nodeTab[i] = NULL;
diff --git a/src/profiles/gnac-profiles.c b/src/profiles/gnac-profiles.c
index 874a861..f739422 100755
--- a/src/profiles/gnac-profiles.c
+++ b/src/profiles/gnac-profiles.c
@@ -214,7 +214,7 @@ gnac_profiles_populate_combo(void)
gchar *formatted_name;
AudioProfileGeneric *profile;
- profile = ((AudioProfileGeneric*)temp->data)->generic;
+ profile = AUDIO_PROFILE_GET_GENERIC(temp->data);
formatted_name = gnac_profiles_properties_filter_text_for_displaying(
profile->name, MAX_NAME_DISPLAY_SIZE);
name = gnac_profiles_utils_get_combo_format_name(formatted_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]