From 24ca48cc1eb6c54fbf258eeb2c014485677512a1 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 16 Nov 2008 02:00:17 +0100 Subject: [PATCH] Move variable declarations to the beginnings of blocks --- midori/midori-browser.c | 4 +++- midori/midori-console.c | 11 ++++++++--- midori/midori-panel.c | 30 +++++++++++++++++++++--------- midori/midori-preferences.c | 10 ++++++---- midori/midori-view.c | 6 ++++-- midori/midori-websettings.c | 16 +++++++++++----- midori/sokoke.c | 35 +++++++++++++++++++++++------------ 7 files changed, 76 insertions(+), 36 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index ce8b3049..6d843ed5 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1281,8 +1281,10 @@ _action_open_activate (GtkAction* action, if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { + gchar* folder; + + folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)); uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); - gchar* folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog)); midori_browser_set_current_uri (browser, uri); g_free (last_dir); diff --git a/midori/midori-console.c b/midori/midori-console.c index 2a4df539..507b26dc 100644 --- a/midori/midori-console.c +++ b/midori/midori-console.c @@ -64,9 +64,11 @@ midori_console_treeview_render_text_cb (GtkTreeViewColumn* column, gchar* message; gint line; gchar* source_id; + gchar* text; + gtk_tree_model_get (model, iter, 0, &message, 1, &line, 2, &source_id, -1); - gchar* text = g_strdup_printf ("%d @ %s\n%s", line, source_id, message); + text = g_strdup_printf ("%d @ %s\n%s", line, source_id, message); g_object_set (renderer, "text", text, NULL); g_free (text); @@ -153,10 +155,13 @@ midori_console_get_toolbar (MidoriConsole* console) if (!console->toolbar) { - GtkWidget* toolbar = gtk_toolbar_new (); + GtkWidget* toolbar; + GtkToolItem* toolitem; + + toolbar = gtk_toolbar_new (); gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON); - GtkToolItem* toolitem = gtk_tool_item_new (); + toolitem = gtk_tool_item_new (); /* TODO: What about a find entry here that filters e.g. by url? */ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_widget_show (GTK_WIDGET (toolitem)); diff --git a/midori/midori-panel.c b/midori/midori-panel.c index c4fd41be..2a2cb6f4 100644 --- a/midori/midori-panel.c +++ b/midori/midori-panel.c @@ -109,6 +109,9 @@ midori_cclosure_marshal_BOOLEAN__VOID (GClosure* closure, static void midori_panel_class_init (MidoriPanelClass* class) { + GObjectClass* gobject_class; + GParamFlags flags; + signals[CLOSE] = g_signal_new ( "close", @@ -133,12 +136,12 @@ midori_panel_class_init (MidoriPanelClass* class) class->close = midori_panel_close_cb; - GObjectClass* gobject_class = G_OBJECT_CLASS (class); + gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = midori_panel_finalize; gobject_class->set_property = midori_panel_set_property; gobject_class->get_property = midori_panel_get_property; - GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; + flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; g_object_class_install_property (gobject_class, PROP_SHADOW_TYPE, @@ -180,6 +183,10 @@ midori_panel_button_close_clicked_cb (GtkWidget* toolitem, static void midori_panel_init (MidoriPanel* panel) { + GtkWidget* vbox; + GtkWidget* labelbar; + GtkToolItem* toolitem; + /* Create the sidebar */ panel->toolbar = gtk_toolbar_new (); gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), GTK_TOOLBAR_BOTH); @@ -189,14 +196,14 @@ midori_panel_init (MidoriPanel* panel) GTK_ORIENTATION_VERTICAL); gtk_box_pack_start (GTK_BOX (panel), panel->toolbar, FALSE, FALSE, 0); gtk_widget_show_all (panel->toolbar); - GtkWidget* vbox = gtk_vbox_new (FALSE, 0); + vbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (panel), vbox, TRUE, TRUE, 0); /* Create the titlebar */ - GtkWidget* labelbar = gtk_toolbar_new (); + labelbar = gtk_toolbar_new (); gtk_toolbar_set_icon_size (GTK_TOOLBAR (labelbar), GTK_ICON_SIZE_MENU); gtk_toolbar_set_style (GTK_TOOLBAR (labelbar), GTK_TOOLBAR_ICONS); - GtkToolItem* toolitem = gtk_tool_item_new (); + toolitem = gtk_tool_item_new (); gtk_tool_item_set_expand (toolitem, TRUE); panel->toolbar_label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (panel->toolbar_label), 0, 0.5); @@ -559,9 +566,12 @@ gint midori_panel_page_num (MidoriPanel* panel, GtkWidget* child) { - g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1); + GtkWidget* scrolled; - GtkWidget* scrolled = _midori_panel_scrolled_for_child (panel, child); + g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1); + g_return_val_if_fail (GTK_IS_WIDGET (child), -1); + + scrolled = _midori_panel_scrolled_for_child (panel, child); return gtk_notebook_page_num (GTK_NOTEBOOK (panel->notebook), scrolled); } @@ -579,12 +589,14 @@ void midori_panel_set_current_page (MidoriPanel* panel, gint n) { + GtkWidget* child; + g_return_if_fail (MIDORI_IS_PANEL (panel)); gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->toolbook), n); gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->notebook), n); - GtkWidget* child = midori_panel_get_nth_page (panel, n); - if (child) + + if ((child = midori_panel_get_nth_page (panel, n))) { const gchar* label = g_object_get_data (G_OBJECT (child), "label"); g_object_set (panel->toolbar_label, "label", label, NULL); diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index ec519aae..58791794 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -167,13 +167,15 @@ GtkWidget* midori_preferences_new (GtkWindow* parent, MidoriWebSettings* settings) { + MidoriPreferences* preferences; + g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL); g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL); - MidoriPreferences* preferences = g_object_new (MIDORI_TYPE_PREFERENCES, - "transient-for", parent, - "settings", settings, - NULL); + preferences = g_object_new (MIDORI_TYPE_PREFERENCES, + "transient-for", parent, + "settings", settings, + NULL); return GTK_WIDGET (preferences); } diff --git a/midori/midori-view.c b/midori/midori-view.c index 65ba2eca..36c90dfe 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -76,14 +76,16 @@ GType midori_load_status_get_type (void) { static GType type = 0; - if (type) - return type; static const GEnumValue values[] = { { MIDORI_LOAD_PROVISIONAL, "MIDORI_LOAD_PROVISIONAL", "Load Provisional" }, { MIDORI_LOAD_COMMITTED, "MIDORI_LOAD_COMMITTED", "Load Committed" }, { MIDORI_LOAD_FINISHED, "MIDORI_LOAD_FINISHED", "Load Finished" }, { 0, NULL, NULL } }; + + if (type) + return type; + type = g_enum_register_static ("MidoriLoadStatus", values); return type; } diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index fc6b1ba0..e5487104 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -230,12 +230,15 @@ midori_web_settings_get_property (GObject* object, static void midori_web_settings_class_init (MidoriWebSettingsClass* class) { - GObjectClass* gobject_class = G_OBJECT_CLASS (class); + GObjectClass* gobject_class; + GParamFlags flags; + + gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = midori_web_settings_finalize; gobject_class->set_property = midori_web_settings_set_property; gobject_class->get_property = midori_web_settings_get_property; - GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; + flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; g_object_class_install_property (gobject_class, PROP_REMEMBER_LAST_WINDOW_SIZE, @@ -610,11 +613,14 @@ static void notify_default_encoding_cb (GObject* object, GParamSpec* pspec) { - MidoriWebSettings* web_settings = MIDORI_WEB_SETTINGS (object); - + MidoriWebSettings* web_settings; const gchar* string; + const gchar* encoding; + + web_settings = MIDORI_WEB_SETTINGS (object); + g_object_get (object, "default-encoding", &string, NULL); - const gchar* encoding = string ? string : ""; + encoding = string ? string : ""; if (!strcmp (encoding, "BIG5")) web_settings->preferred_encoding = MIDORI_ENCODING_CHINESE; else if (!strcmp (encoding, "SHIFT_JIS")) diff --git a/midori/sokoke.c b/midori/sokoke.c index 776931c3..d170e5b9 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -178,12 +178,13 @@ void sokoke_combo_box_add_strings (GtkComboBox* combobox, const gchar* label_first, ...) { + const gchar* label; + /* Add a number of strings to a combobox, terminated with NULL This works only for text comboboxes */ va_list args; va_start (args, label_first); - const gchar* label; for (label = label_first; label; label = va_arg (args, const gchar*)) gtk_combo_box_append_text (combobox, label); @@ -255,17 +256,22 @@ sokoke_xfce_header_new (const gchar* icon, This returns NULL if the desktop is not Xfce */ if (sokoke_get_desktop () == SOKOKE_DESKTOP_XFCE) { - GtkWidget* entry = gtk_entry_new (); + GtkWidget* entry; gchar* markup; - GtkWidget* xfce_heading = gtk_event_box_new (); + GtkWidget* xfce_heading; + GtkWidget* hbox; + GtkWidget* image; + GtkWidget* label; + + xfce_heading = gtk_event_box_new (); + entry = gtk_entry_new (); gtk_widget_modify_bg (xfce_heading, GTK_STATE_NORMAL, &entry->style->base[GTK_STATE_NORMAL]); - GtkWidget* hbox = gtk_hbox_new (FALSE, 12); + hbox = gtk_hbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (hbox), 6); - GtkWidget* image = gtk_image_new_from_icon_name (icon, - GTK_ICON_SIZE_DIALOG); + image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - GtkWidget* label = gtk_label_new (NULL); + label = gtk_label_new (NULL); gtk_widget_modify_fg (label, GTK_STATE_NORMAL , &entry->style->text[GTK_STATE_NORMAL]); markup = g_strdup_printf ("%s", @@ -287,11 +293,13 @@ sokoke_superuser_warning_new (void) #if HAVE_UNISTD_H if (G_UNLIKELY (!geteuid ())) /* effective superuser? */ { - GtkWidget* hbox = gtk_event_box_new (); + GtkWidget* hbox; + GtkWidget* label; + + hbox = gtk_event_box_new (); gtk_widget_modify_bg (hbox, GTK_STATE_NORMAL, &hbox->style->bg[GTK_STATE_SELECTED]); - GtkWidget* label = gtk_label_new ( - _("Warning: You are using a superuser account!")); + label = gtk_label_new (_("Warning: You are using a superuser account!")); gtk_misc_set_padding (GTK_MISC (label), 0, 2); gtk_widget_modify_fg (GTK_WIDGET (label), GTK_STATE_NORMAL, >K_WIDGET (label)->style->fg[GTK_STATE_SELECTED]); @@ -458,10 +466,13 @@ sokoke_key_file_save_to_file (GKeyFile* key_file, const gchar* filename, GError** error) { - gchar* data = g_key_file_to_data (key_file, NULL, error); + gchar* data; + FILE* fp; + + data = g_key_file_to_data (key_file, NULL, error); if (!data) return FALSE; - FILE* fp; + if (!(fp = fopen (filename, "w"))) { *error = g_error_new (G_FILE_ERROR, G_FILE_ERROR_ACCES,