Move variable declarations to the beginnings of blocks

This commit is contained in:
Christian Dywan 2008-11-16 02:00:17 +01:00
parent c49ed67ab0
commit 24ca48cc1e
7 changed files with 76 additions and 36 deletions

View file

@ -1281,8 +1281,10 @@ _action_open_activate (GtkAction* action,
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) 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)); 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); midori_browser_set_current_uri (browser, uri);
g_free (last_dir); g_free (last_dir);

View file

@ -64,9 +64,11 @@ midori_console_treeview_render_text_cb (GtkTreeViewColumn* column,
gchar* message; gchar* message;
gint line; gint line;
gchar* source_id; gchar* source_id;
gchar* text;
gtk_tree_model_get (model, iter, 0, &message, 1, &line, 2, &source_id, -1); 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_object_set (renderer, "text", text, NULL);
g_free (text); g_free (text);
@ -153,10 +155,13 @@ midori_console_get_toolbar (MidoriConsole* console)
if (!console->toolbar) 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_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON); 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? */ /* TODO: What about a find entry here that filters e.g. by url? */
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
gtk_widget_show (GTK_WIDGET (toolitem)); gtk_widget_show (GTK_WIDGET (toolitem));

View file

@ -109,6 +109,9 @@ midori_cclosure_marshal_BOOLEAN__VOID (GClosure* closure,
static void static void
midori_panel_class_init (MidoriPanelClass* class) midori_panel_class_init (MidoriPanelClass* class)
{ {
GObjectClass* gobject_class;
GParamFlags flags;
signals[CLOSE] = g_signal_new ( signals[CLOSE] = g_signal_new (
"close", "close",
@ -133,12 +136,12 @@ midori_panel_class_init (MidoriPanelClass* class)
class->close = midori_panel_close_cb; 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->finalize = midori_panel_finalize;
gobject_class->set_property = midori_panel_set_property; gobject_class->set_property = midori_panel_set_property;
gobject_class->get_property = midori_panel_get_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, g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE, PROP_SHADOW_TYPE,
@ -180,6 +183,10 @@ midori_panel_button_close_clicked_cb (GtkWidget* toolitem,
static void static void
midori_panel_init (MidoriPanel* panel) midori_panel_init (MidoriPanel* panel)
{ {
GtkWidget* vbox;
GtkWidget* labelbar;
GtkToolItem* toolitem;
/* Create the sidebar */ /* Create the sidebar */
panel->toolbar = gtk_toolbar_new (); panel->toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), GTK_TOOLBAR_BOTH); gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), GTK_TOOLBAR_BOTH);
@ -189,14 +196,14 @@ midori_panel_init (MidoriPanel* panel)
GTK_ORIENTATION_VERTICAL); GTK_ORIENTATION_VERTICAL);
gtk_box_pack_start (GTK_BOX (panel), panel->toolbar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (panel), panel->toolbar, FALSE, FALSE, 0);
gtk_widget_show_all (panel->toolbar); 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); gtk_box_pack_start (GTK_BOX (panel), vbox, TRUE, TRUE, 0);
/* Create the titlebar */ /* 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_icon_size (GTK_TOOLBAR (labelbar), GTK_ICON_SIZE_MENU);
gtk_toolbar_set_style (GTK_TOOLBAR (labelbar), GTK_TOOLBAR_ICONS); 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); gtk_tool_item_set_expand (toolitem, TRUE);
panel->toolbar_label = gtk_label_new (NULL); panel->toolbar_label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (panel->toolbar_label), 0, 0.5); gtk_misc_set_alignment (GTK_MISC (panel->toolbar_label), 0, 0.5);
@ -559,9 +566,12 @@ gint
midori_panel_page_num (MidoriPanel* panel, midori_panel_page_num (MidoriPanel* panel,
GtkWidget* child) 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); return gtk_notebook_page_num (GTK_NOTEBOOK (panel->notebook), scrolled);
} }
@ -579,12 +589,14 @@ void
midori_panel_set_current_page (MidoriPanel* panel, midori_panel_set_current_page (MidoriPanel* panel,
gint n) gint n)
{ {
GtkWidget* child;
g_return_if_fail (MIDORI_IS_PANEL (panel)); 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->toolbook), n);
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->notebook), 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"); const gchar* label = g_object_get_data (G_OBJECT (child), "label");
g_object_set (panel->toolbar_label, "label", label, NULL); g_object_set (panel->toolbar_label, "label", label, NULL);

View file

@ -167,10 +167,12 @@ GtkWidget*
midori_preferences_new (GtkWindow* parent, midori_preferences_new (GtkWindow* parent,
MidoriWebSettings* settings) MidoriWebSettings* settings)
{ {
MidoriPreferences* preferences;
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL); g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL); g_return_val_if_fail (MIDORI_IS_WEB_SETTINGS (settings), NULL);
MidoriPreferences* preferences = g_object_new (MIDORI_TYPE_PREFERENCES, preferences = g_object_new (MIDORI_TYPE_PREFERENCES,
"transient-for", parent, "transient-for", parent,
"settings", settings, "settings", settings,
NULL); NULL);

View file

@ -76,14 +76,16 @@ GType
midori_load_status_get_type (void) midori_load_status_get_type (void)
{ {
static GType type = 0; static GType type = 0;
if (type)
return type;
static const GEnumValue values[] = { static const GEnumValue values[] = {
{ MIDORI_LOAD_PROVISIONAL, "MIDORI_LOAD_PROVISIONAL", "Load Provisional" }, { MIDORI_LOAD_PROVISIONAL, "MIDORI_LOAD_PROVISIONAL", "Load Provisional" },
{ MIDORI_LOAD_COMMITTED, "MIDORI_LOAD_COMMITTED", "Load Committed" }, { MIDORI_LOAD_COMMITTED, "MIDORI_LOAD_COMMITTED", "Load Committed" },
{ MIDORI_LOAD_FINISHED, "MIDORI_LOAD_FINISHED", "Load Finished" }, { MIDORI_LOAD_FINISHED, "MIDORI_LOAD_FINISHED", "Load Finished" },
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };
if (type)
return type;
type = g_enum_register_static ("MidoriLoadStatus", values); type = g_enum_register_static ("MidoriLoadStatus", values);
return type; return type;
} }

View file

@ -230,12 +230,15 @@ midori_web_settings_get_property (GObject* object,
static void static void
midori_web_settings_class_init (MidoriWebSettingsClass* class) 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->finalize = midori_web_settings_finalize;
gobject_class->set_property = midori_web_settings_set_property; gobject_class->set_property = midori_web_settings_set_property;
gobject_class->get_property = midori_web_settings_get_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, g_object_class_install_property (gobject_class,
PROP_REMEMBER_LAST_WINDOW_SIZE, PROP_REMEMBER_LAST_WINDOW_SIZE,
@ -610,11 +613,14 @@ static void
notify_default_encoding_cb (GObject* object, notify_default_encoding_cb (GObject* object,
GParamSpec* pspec) GParamSpec* pspec)
{ {
MidoriWebSettings* web_settings = MIDORI_WEB_SETTINGS (object); MidoriWebSettings* web_settings;
const gchar* string; const gchar* string;
const gchar* encoding;
web_settings = MIDORI_WEB_SETTINGS (object);
g_object_get (object, "default-encoding", &string, NULL); g_object_get (object, "default-encoding", &string, NULL);
const gchar* encoding = string ? string : ""; encoding = string ? string : "";
if (!strcmp (encoding, "BIG5")) if (!strcmp (encoding, "BIG5"))
web_settings->preferred_encoding = MIDORI_ENCODING_CHINESE; web_settings->preferred_encoding = MIDORI_ENCODING_CHINESE;
else if (!strcmp (encoding, "SHIFT_JIS")) else if (!strcmp (encoding, "SHIFT_JIS"))

View file

@ -178,12 +178,13 @@ void
sokoke_combo_box_add_strings (GtkComboBox* combobox, sokoke_combo_box_add_strings (GtkComboBox* combobox,
const gchar* label_first, ...) const gchar* label_first, ...)
{ {
const gchar* label;
/* Add a number of strings to a combobox, terminated with NULL /* Add a number of strings to a combobox, terminated with NULL
This works only for text comboboxes */ This works only for text comboboxes */
va_list args; va_list args;
va_start (args, label_first); va_start (args, label_first);
const gchar* label;
for (label = label_first; label; label = va_arg (args, const gchar*)) for (label = label_first; label; label = va_arg (args, const gchar*))
gtk_combo_box_append_text (combobox, label); 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 */ This returns NULL if the desktop is not Xfce */
if (sokoke_get_desktop () == SOKOKE_DESKTOP_XFCE) if (sokoke_get_desktop () == SOKOKE_DESKTOP_XFCE)
{ {
GtkWidget* entry = gtk_entry_new (); GtkWidget* entry;
gchar* markup; 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, gtk_widget_modify_bg (xfce_heading, GTK_STATE_NORMAL,
&entry->style->base[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); gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
GtkWidget* image = gtk_image_new_from_icon_name (icon, image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_DIALOG);
GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); 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 gtk_widget_modify_fg (label, GTK_STATE_NORMAL
, &entry->style->text[GTK_STATE_NORMAL]); , &entry->style->text[GTK_STATE_NORMAL]);
markup = g_strdup_printf ("<span size='large' weight='bold'>%s</span>", markup = g_strdup_printf ("<span size='large' weight='bold'>%s</span>",
@ -287,11 +293,13 @@ sokoke_superuser_warning_new (void)
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
if (G_UNLIKELY (!geteuid ())) /* effective superuser? */ 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, gtk_widget_modify_bg (hbox, GTK_STATE_NORMAL,
&hbox->style->bg[GTK_STATE_SELECTED]); &hbox->style->bg[GTK_STATE_SELECTED]);
GtkWidget* label = gtk_label_new ( label = gtk_label_new (_("Warning: You are using a superuser account!"));
_("Warning: You are using a superuser account!"));
gtk_misc_set_padding (GTK_MISC (label), 0, 2); gtk_misc_set_padding (GTK_MISC (label), 0, 2);
gtk_widget_modify_fg (GTK_WIDGET (label), GTK_STATE_NORMAL, gtk_widget_modify_fg (GTK_WIDGET (label), GTK_STATE_NORMAL,
&GTK_WIDGET (label)->style->fg[GTK_STATE_SELECTED]); &GTK_WIDGET (label)->style->fg[GTK_STATE_SELECTED]);
@ -458,10 +466,13 @@ sokoke_key_file_save_to_file (GKeyFile* key_file,
const gchar* filename, const gchar* filename,
GError** error) 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) if (!data)
return FALSE; return FALSE;
FILE* fp;
if (!(fp = fopen (filename, "w"))) if (!(fp = fopen (filename, "w")))
{ {
*error = g_error_new (G_FILE_ERROR, G_FILE_ERROR_ACCES, *error = g_error_new (G_FILE_ERROR, G_FILE_ERROR_ACCES,