[gnac/devel] Code cleanup
- From: BenoÃt Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/devel] Code cleanup
- Date: Fri, 18 Nov 2011 10:10:45 +0000 (UTC)
commit 9e15da43bea71923a79549dddabe7a7b93ca4858
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date: Fri Nov 18 00:43:05 2011 +0000
Code cleanup
src/gnac-main.c | 5 +-
src/gnac-ui.c | 165 ++++++++++++++--------------------
src/gnac-ui.h | 2 +-
src/profiles/gnac-profiles-manager.c | 16 ++--
4 files changed, 80 insertions(+), 108 deletions(-)
---
diff --git a/src/gnac-main.c b/src/gnac-main.c
index 159072a..e108c94 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -269,11 +269,14 @@ gnac_add_files_thread_entry(gpointer data)
void
gnac_add_files(GSList *files)
{
+ if (!files) return;
+
GError *error = NULL;
+
continue_files_action = TRUE;
gnac_change_state(GNAC_AUDIO_FILE_ACTION_STATE);
file_action_thread = g_thread_create(
- (GThreadFunc)gnac_add_files_thread_entry,
+ (GThreadFunc) gnac_add_files_thread_entry,
files, TRUE, &error);
if (error) {
libgnac_debug("Failed to create thread");
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index e5a3446..45fe319 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -52,15 +52,14 @@
GSettings *settings_ui;
-static GSList *filters;
-static GtkBuilder *gnac_main_builder = NULL;
-static GtkFileFilter *default_file_filter;
-static GtkStatusIcon *trayicon = NULL;
-static GtkWidget *gnac_file_chooser;
-static gchar *status_msg = NULL;
-static gchar *tooltip_path = NULL;
-static gchar *progress_msg = NULL;
-static guint timeout_id;
+static GSList *filters;
+static GtkBuilder *gnac_main_builder = NULL;
+static GtkFileFilter *default_file_filter;
+static GtkStatusIcon *trayicon = NULL;
+static GtkWidget *gnac_file_chooser;
+static gchar *status_msg = NULL;
+static gchar *tooltip_path = NULL;
+static guint timeout_id;
static gint root_x;
static gint root_y;
@@ -348,8 +347,8 @@ gnac_ui_file_chooser_foreach(gpointer data,
GFile *file;
GSList **list;
- list = (GSList**) user_data;
- file = g_file_new_for_uri((gchar*)data);
+ list = (GSList **) user_data;
+ file = g_file_new_for_uri((gchar *) data);
*list = g_slist_append(*list, file);
g_free(data);
@@ -535,7 +534,7 @@ gnac_ui_file_chooser_response_cb(GtkDialog *dialog,
/* Add the differents files */
g_slist_foreach(list_path,(GFunc) gnac_ui_file_chooser_foreach,
- (gpointer)&list_files);
+ (gpointer) &list_files);
g_slist_free(list_path);
@@ -602,11 +601,11 @@ gnac_ui_add_audio_profile_combo_box(void)
gtk_box_pack_start(GTK_BOX(audio_profile_hbox), audio_profile_chooser_combo,
FALSE, TRUE, 0);
-
gtk_box_pack_start(GTK_BOX(audio_profile_hbox), audio_profile_edit_button,
FALSE, TRUE, 6);
}
+
void
gnac_ui_new(void)
{
@@ -646,22 +645,18 @@ gnac_ui_set_progress_fraction(gdouble fraction)
void
-gnac_ui_set_progress_text(gchar *text)
+gnac_ui_set_progress_text(const gchar *text)
{
GtkProgressBar *progress_bar;
progress_bar = GTK_PROGRESS_BAR(gnac_ui_get_widget("progressbar"));
- progress_msg = text;
- gtk_progress_bar_set_text(progress_bar, progress_msg);
+ gtk_progress_bar_set_text(progress_bar, text);
}
void
gnac_ui_show_progress(gboolean show)
{
- GtkWidget *progress_bar;
-
- progress_bar = gnac_ui_get_widget("progressbar");
-
+ GtkWidget *progress_bar = gnac_ui_get_widget("progressbar");
if (show) gtk_widget_show(progress_bar);
else gtk_widget_hide(progress_bar);
}
@@ -670,20 +665,20 @@ gnac_ui_show_progress(gboolean show)
gboolean
gnac_ui_pulse_progress(void)
{
- GtkWidget *progress_bar;
- gchar *progress_text;
+ GtkProgressBar *progress_bar;
+ gchar *progress_text;
if (state != GNAC_AUDIO_FILE_ACTION_STATE) return FALSE;
- progress_bar = gnac_ui_get_widget("progressbar");
+ progress_bar = GTK_PROGRESS_BAR(gnac_ui_get_widget("progressbar"));
- gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar));
+ gtk_progress_bar_pulse(progress_bar);
progress_text = g_strdup_printf(
ngettext("%u file added", "%u files added", nb_files_added),
nb_files_added);
gnac_ui_set_progress_text(progress_text);
g_free(progress_text);
-
+
return TRUE;
}
@@ -691,10 +686,7 @@ gnac_ui_pulse_progress(void)
void
gnac_ui_show_pause(gboolean show)
{
- GtkWidget *button;
-
- button = gnac_ui_get_widget("pause_button");
-
+ GtkWidget *button = gnac_ui_get_widget("pause_button");
if (show) gtk_widget_show(button);
else gtk_widget_hide(button);
}
@@ -716,7 +708,7 @@ gnac_ui_push_status(const gchar *message)
void
gnac_ui_append_status(const gchar *message)
{
- gchar *old_msg;
+ gchar *old_msg;
GtkStatusbar *status_bar;
status_bar = GTK_STATUSBAR(gnac_ui_get_widget("statusbar"));
@@ -756,9 +748,8 @@ gnac_ui_show_popup_menu(GtkWidget *treeview,
GdkEventButton *event,
gpointer user_data)
{
- GtkWidget * popup_menu;
- popup_menu = gnac_ui_get_widget("main_popup");
- gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL,
+ GtkMenu *popup_menu = GTK_MENU(gnac_ui_get_widget("main_popup"));
+ gtk_menu_popup(popup_menu, NULL, NULL, NULL, NULL,
event ? event->button : 0, gdk_event_get_time((GdkEvent *) event));
}
@@ -782,7 +773,7 @@ gnac_about_url_hook(GtkAboutDialog *dialog,
url, gtk_get_current_event_time(), &error))
{
g_warning(_("Could not open link %s: %s"), url, error->message);
- g_error_free(error);
+ g_clear_error(&error);
}
}
@@ -812,14 +803,17 @@ void
gnac_ui_on_audio_empty_state(void)
{
gnac_bars_on_row_deleted();
+ gnac_bars_on_convert_stop();
+
gnac_ui_hide_trayicon();
gnac_ui_show_progress(FALSE);
gnac_ui_show_pause(FALSE);
- gnac_bars_on_convert_stop();
+
if (timeout_id != 0) {
g_source_remove(timeout_id);
timeout_id = 0;
}
+
gnac_ui_set_progress_fraction(0.0f);
gnac_ui_set_progress_text("");
}
@@ -838,18 +832,22 @@ void
gnac_ui_on_audio_ready_state(void)
{
gnac_bars_on_row_inserted();
+
if (gtk_window_has_toplevel_focus(
GTK_WINDOW(gnac_ui_get_widget("main_window"))))
{
gnac_ui_hide_trayicon();
}
+
gnac_ui_show_progress(FALSE);
gnac_ui_show_pause(FALSE);
gnac_bars_on_convert_stop();
+
if (timeout_id != 0) {
g_source_remove(timeout_id);
timeout_id = 0;
}
+
gnac_ui_set_progress_fraction(0.0f);
gnac_ui_set_progress_text("");
}
@@ -884,13 +882,7 @@ void
gnac_ui_on_clear_cb(GtkAction *action,
gpointer data)
{
- GError *error = NULL;
-
libgnac_converter_clear(converter);
- if (error) {
- g_printerr("%s: %s\n", _("Error"), error->message);
- g_clear_error(&error);
- }
}
@@ -898,10 +890,8 @@ void
gnac_ui_on_view_toolbar_cb(GtkAction *action,
gpointer user_data)
{
- gboolean visible;
- GtkWidget *toolbar;
- toolbar = gnac_ui_get_widget("main_toolbar"),
- visible = !gtk_widget_get_visible(toolbar);
+ GtkWidget *toolbar = gnac_ui_get_widget("main_toolbar");
+ gboolean visible = !gtk_widget_get_visible(toolbar);
gtk_widget_set_visible(toolbar, visible);
g_settings_set_boolean(settings_ui, GNAC_KEY_TOOLBAR_VISIBLE, visible);
}
@@ -918,7 +908,7 @@ gnac_ui_on_help_cb(GtkAction *action,
"ghelp:gnac", gtk_get_current_event_time(), &error);
if (!ret && error) {
g_printerr("%s: %s\n", _("Could not display help"), error->message);
- g_error_free(error);
+ g_clear_error(&error);
}
}
@@ -943,8 +933,7 @@ void
gnac_ui_on_remove_cb(GtkAction *action,
gpointer data)
{
- GList *rows;
- rows = gnac_file_list_get_selected_rows();
+ GList *rows = gnac_file_list_get_selected_rows();
/* References are freed by gnac_remove_track */
g_list_free_full(rows, (GDestroyNotify) gnac_remove_track);
}
@@ -960,31 +949,29 @@ gnac_ui_on_drag_data_received_cb(GtkWidget *widget,
guint time,
gpointer data)
{
- GFile *file;
- GSList *list_uris = NULL;
- gchar **uris;
- gchar *uri;
- gint index = 0;
-
/* Disable any filtering for DnD. */
gnac_ui_reset_file_filter();
- uris = gtk_selection_data_get_uris(selection_data);
+ gchar **uris = gtk_selection_data_get_uris(selection_data);
if (!uris) {
gtk_drag_finish (context, FALSE, FALSE, time);
return;
}
- uri = uris[0];
+ guint index = 0;
+ gchar *uri;
+ GSList *list_uris = NULL;
+
+ uri = uris[index];
while (uri) {
- file = g_file_new_for_uri(uri);
+ GFile *file = g_file_new_for_uri(uri);
list_uris = g_slist_append(list_uris, file);
index++;
uri = uris[index];
}
- if (list_uris) gnac_add_files(list_uris);
+ gnac_add_files(list_uris);
gtk_drag_finish(context, TRUE, FALSE, time);
g_strfreev(uris);
@@ -999,9 +986,7 @@ gnac_ui_message_received_cb(UniqueApp *app,
guint time,
gpointer user_data)
{
- GtkWindow *main_window;
-
- main_window = GTK_WINDOW(gnac_ui_get_widget("main_window"));
+ GtkWindow *main_window = GTK_WINDOW(gnac_ui_get_widget("main_window"));
switch (command)
{
@@ -1128,13 +1113,11 @@ gnac_ui_init(void)
void
gnac_ui_show(void)
{
- GtkWidget *main_window;
-
if (!gnac_main_builder) {
gnac_ui_new();
}
- main_window = gnac_ui_get_widget("main_window");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
#ifdef HAVE_LIBUNIQUE
unique_app_watch_window(app, GTK_WINDOW(main_window));
@@ -1251,8 +1234,7 @@ gnac_ui_query_tooltip_cb(GtkStatusIcon *status_icon,
}
else
{
- gchar *name;
- name = gnac_utils_get_display_name(tooltip_path, NULL);
+ gchar *name = gnac_utils_get_display_name(tooltip_path, NULL);
if (name) {
text = g_markup_printf_escaped(" <b>%s</b> ", name);
} else {
@@ -1264,8 +1246,7 @@ gnac_ui_query_tooltip_cb(GtkStatusIcon *status_icon,
gtk_tooltip_set_markup(tooltip, text);
/* check wether we have a cover to display */
- if (libgnac_metadata_tag_exists(tags, GST_TAG_IMAGE))
- {
+ if (libgnac_metadata_tag_exists(tags, GST_TAG_IMAGE)) {
GdkPixbuf *pixbuf;
pixbuf = g_value_get_object(LIBGNAC_METADATA_TAG_IMAGE(tags));
pixbuf = gnac_utils_scale_pixbuf(pixbuf, 80, 80);
@@ -1283,11 +1264,9 @@ gnac_ui_query_tooltip_cb(GtkStatusIcon *status_icon,
void
gnac_ui_show_trayicon(void)
{
- GtkWidget *main_window;
-
if (!g_settings_get_boolean(settings_ui, GNAC_KEY_TRAY_ICON)) return;
- main_window = gnac_ui_get_widget("main_window");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
if (!trayicon) {
trayicon = gtk_status_icon_new_from_icon_name("gnac");
@@ -1309,16 +1288,15 @@ gnac_ui_show_trayicon(void)
void
gnac_ui_hide_trayicon(void)
{
- GtkWidget *main_window;
- gboolean window_displayed;
-
if (!g_settings_get_boolean(settings_ui, GNAC_KEY_TRAY_ICON) ||
!trayicon)
{
return;
}
- main_window = gnac_ui_get_widget("main_window");
+ gboolean window_displayed;
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
+
g_object_get(main_window, "visible", &window_displayed, NULL);
gtk_widget_show_all(main_window);
@@ -1335,10 +1313,9 @@ void
gnac_ui_on_trayicon(GtkStatusIcon *trayicon,
gpointer data)
{
- GtkWidget *main_window;
gboolean window_displayed;
- main_window = gnac_ui_get_widget("main_window");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
g_object_get(main_window, "visible", &window_displayed, NULL);
if (window_displayed) {
@@ -1361,24 +1338,21 @@ gnac_ui_on_trayicon_popup(GtkStatusIcon *trayicon,
guint activate_time,
gpointer data)
{
- gboolean window_displayed;
- gchar *label_text;
- GtkAction *show_action;
- GtkWidget *main_window;
- GtkWidget *trayicon_menu;
+ gboolean window_displayed;
- main_window = gnac_ui_get_widget("main_window");
- show_action = gnac_ui_get_action("tray_show_hide_item");
- trayicon_menu = gnac_ui_get_widget("tray_popup");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
g_object_get(main_window, "visible", &window_displayed, NULL);
+
/* Translators: Show/Hide main window */
- label_text = g_strdup(window_displayed ? _("Hide") : _("Show"));
+ gchar *label_text = g_strdup(window_displayed ? _("Hide") : _("Show"));
+
+ GtkAction *show_action = gnac_ui_get_action("tray_show_hide_item");
+ GtkMenu *trayicon_menu = GTK_MENU(gnac_ui_get_widget("tray_popup"));
/* update the menu and then display it */
- gtk_action_set_label(GTK_ACTION(show_action), label_text);
- gtk_menu_popup(GTK_MENU(trayicon_menu), NULL, NULL, NULL, NULL,
- button, activate_time);
+ gtk_action_set_label(show_action, label_text);
+ gtk_menu_popup(trayicon_menu, NULL, NULL, NULL, NULL, button, activate_time);
g_free(label_text);
}
@@ -1387,8 +1361,6 @@ gnac_ui_on_trayicon_popup(GtkStatusIcon *trayicon,
void
gnac_ui_trayicon_tooltip_update(const gchar *tooltip)
{
- GdkDisplay *display;
-
if (!g_settings_get_boolean(settings_ui, GNAC_KEY_TRAY_ICON) ||
!trayicon)
{
@@ -1398,7 +1370,7 @@ gnac_ui_trayicon_tooltip_update(const gchar *tooltip)
g_free(tooltip_path);
tooltip_path = g_strdup(tooltip);
- display = gdk_display_get_default();
+ GdkDisplay *display = gdk_display_get_default();
if (display) gtk_tooltip_trigger_tooltip_query(display);
}
@@ -1420,10 +1392,9 @@ void
gnac_ui_trayicon_menu_stop(gpointer data,
gpointer user_data)
{
- GtkWidget *main_window;
gboolean window_displayed;
- main_window = gnac_ui_get_widget("main_window");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
g_object_get(main_window, "visible", &window_displayed, NULL);
if (!window_displayed) {
@@ -1448,13 +1419,11 @@ gnac_ui_trayicon_menu_pause(gpointer data,
gint
gnac_ui_show_error_trash(const gchar *filename)
{
- GtkWidget *main_window;
- GtkWidget *dialog;
gint response;
- main_window = gnac_ui_get_widget("main_window");
+ GtkWidget *main_window = gnac_ui_get_widget("main_window");
- dialog = gtk_message_dialog_new(GTK_WINDOW(main_window),
+ GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(main_window),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
_("Failed to move the file to the Trash. Delete it permanently?"));
gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_DELETE, 1);
diff --git a/src/gnac-ui.h b/src/gnac-ui.h
index 51555cf..9f3c74f 100644
--- a/src/gnac-ui.h
+++ b/src/gnac-ui.h
@@ -47,7 +47,7 @@ void
gnac_ui_set_progress_fraction(gdouble fraction);
void
-gnac_ui_set_progress_text(gchar *text);
+gnac_ui_set_progress_text(const gchar *text);
void
gnac_ui_show_progress(gboolean show);
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index c784762..2e185c9 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -251,7 +251,7 @@ gnac_profiles_mgr_get_profiles_dir(void)
if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
libgnac_warning("%s: %s",
_("Unable to create the profiles directory"), error->message);
- g_error_free(error);
+ g_clear_error(&error);
return NULL;
}
@@ -283,7 +283,7 @@ gnac_profiles_mgr_list_profiles(void)
G_FILE_QUERY_INFO_NONE, NULL, &error);
if (!files) {
- g_error_free(error);
+ g_clear_error(&error);
/* no profiles found, try to import the default ones */
gnac_profiles_mgr_import_default_profiles();
files = g_file_enumerate_children(dir,
@@ -293,7 +293,7 @@ gnac_profiles_mgr_list_profiles(void)
if (!files) {
g_printerr(_("No profiles available"));
libgnac_warning("%s", error->message);
- g_error_free(error);
+ g_clear_error(&error);
return;
}
}
@@ -389,7 +389,7 @@ gnac_profiles_mgr_populate(void)
_("You may not be able to save your profiles"),
error->message);
gnac_profiles_mgr_display_status_message(NULL, msg);
- g_error_free(error);
+ g_clear_error(&error);
return;
} else {
gnac_profiles_mgr_import_default_profiles();
@@ -407,7 +407,7 @@ gnac_profiles_mgr_populate(void)
const gchar *msg = N_("Unable to browse the profiles directory");
libgnac_warning("%s: %s", msg, error->message);
gnac_profiles_mgr_display_status_message(NULL, msg);
- g_error_free(error);
+ g_clear_error(&error);
return;
}
@@ -464,7 +464,7 @@ gnac_profiles_mgr_import_default_profiles(void)
libgnac_warning("%s: %s",
_("Unable to find the default profiles directory"),
error->message);
- g_error_free(error);
+ g_clear_error(&error);
return;
}
@@ -476,7 +476,7 @@ gnac_profiles_mgr_import_default_profiles(void)
libgnac_warning("%s: %s",
_("Unable to browse the default profiles directory"),
error->message);
- g_error_free(error);
+ g_clear_error(&error);
return;
}
@@ -863,7 +863,7 @@ gnac_profiles_mgr_on_drag_data_received(GtkWidget *widget,
libgnac_debug("Failed to create thread: %s", error->message);
gnac_profiles_mgr_display_status_message(NULL,
_("Impossible to import file(s)"));
- g_error_free(error);
+ g_clear_error(&error);
}
gtk_drag_finish(context, TRUE, FALSE, time);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]