Fix segfault on quit, improve app and browser interface

This commit is contained in:
Christian Dywan 2008-06-08 01:25:57 +02:00
parent 674b237f97
commit 6d35511604
5 changed files with 91 additions and 44 deletions

View file

@ -406,7 +406,7 @@ main (int argc, char** argv)
stock_items_init ();
MidoriApp* app = midori_app_new ();
g_object_set (app, "settings", settings, NULL);
midori_app_set_settings (app, settings);
MidoriTrash* trash = midori_app_get_trash (app);
guint n = katze_xbel_folder_get_n_items (xbel_trash);
@ -421,8 +421,7 @@ main (int argc, char** argv)
"settings", settings,
"trash", trash,
NULL);
g_signal_emit_by_name (app, "add-browser", browser);
midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser));
KatzeXbelItem* session = katze_xbel_folder_new ();

View file

@ -71,19 +71,12 @@ midori_app_get_property (GObject* object,
GValue* value,
GParamSpec* pspec);
static void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser);
static void
midori_app_quit (MidoriApp* app);
static void
midori_app_class_init (MidoriAppClass* class)
{
signals[ADD_BROWSER] = g_signal_new (
"add-browser",
G_TYPE_FROM_CLASS(class),
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriAppClass, add_browser),
0,
@ -94,7 +87,7 @@ midori_app_class_init (MidoriAppClass* class)
signals[QUIT] = g_signal_new (
"quit",
G_TYPE_FROM_CLASS(class),
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET (MidoriAppClass, quit),
0,
@ -296,7 +289,7 @@ midori_browser_destroy_cb (MidoriBrowser* browser,
priv->browsers = g_list_remove (priv->browsers, browser);
if (g_list_nth (priv->browsers, 0))
return FALSE;
g_signal_emit (app, signals[QUIT], 0);
midori_app_quit (app);
return TRUE;
}
@ -304,31 +297,7 @@ static void
midori_browser_quit_cb (MidoriBrowser* browser,
MidoriApp* app)
{
g_signal_emit (app, signals[QUIT], 0);
}
static void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser)
{
MidoriAppPrivate* priv = app->priv;
gtk_window_add_accel_group (GTK_WINDOW (browser), priv->accel_group);
g_object_connect (browser,
"signal::focus-in-event", midori_browser_focus_in_event_cb, app,
"signal::new-window", midori_browser_new_window_cb, app,
"signal::delete-event", midori_browser_delete_event_cb, app,
"signal::destroy", midori_browser_destroy_cb, app,
"signal::quit", midori_browser_quit_cb, app,
NULL);
priv->browsers = g_list_prepend (priv->browsers, browser);
}
static void
midori_app_quit (MidoriApp* app)
{
gtk_main_quit ();
midori_app_quit (app);
}
/**
@ -349,6 +318,35 @@ midori_app_new (void)
return app;
}
/**
* midori_app_add_browser:
*
* Adds a #MidoriBrowser to the #MidoriApp singleton.
*
* The app will take care of the browser's new-window and quit signals, as well
* as watch window closing so that the last closed window quits the app.
* Also the app watches focus changes to indicate the 'current' browser.
*
* Return value: a new #MidoriApp
**/
void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser)
{
MidoriAppPrivate* priv = app->priv;
gtk_window_add_accel_group (GTK_WINDOW (browser), priv->accel_group);
g_object_connect (browser,
"signal::focus-in-event", midori_browser_focus_in_event_cb, app,
"signal::new-window", midori_browser_new_window_cb, app,
"signal::delete-event", midori_browser_delete_event_cb, app,
"signal::destroy", midori_browser_destroy_cb, app,
"signal::quit", midori_browser_quit_cb, app,
NULL);
priv->browsers = g_list_prepend (priv->browsers, browser);
}
/**
* midori_app_get_settings:
* @app: a #MidoriApp
@ -367,6 +365,25 @@ midori_app_get_settings (MidoriApp* app)
return priv->settings;
}
/**
* midori_app_set_settings:
* @app: a #MidoriApp
*
* Assigns the #MidoriWebSettings to the app.
*
* Return value: the assigned #MidoriWebSettings
**/
void
midori_app_set_settings (MidoriApp* app,
MidoriWebSettings* settings)
{
g_return_if_fail (MIDORI_IS_APP (app));
MidoriAppPrivate* priv = app->priv;
g_object_set (app, "settings", settings, NULL);
}
/**
* midori_app_get_trash:
* @app: a #MidoriApp
@ -384,3 +401,17 @@ midori_app_get_trash (MidoriApp* app)
return priv->trash;
}
/**
* midori_app_quit:
* @app: a #MidoriApp
*
* Quits the #MidoriApp singleton.
**/
void
midori_app_quit (MidoriApp* app)
{
g_return_if_fail (MIDORI_IS_APP (app));
gtk_main_quit ();
}

View file

@ -62,12 +62,23 @@ midori_app_get_type (void);
MidoriApp*
midori_app_new (void);
void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser);
MidoriWebSettings*
midori_app_get_web_settings (MidoriApp* app);
midori_app_get_settings (MidoriApp* app);
void
midori_app_set_settings (MidoriApp* app,
MidoriWebSettings* settings);
MidoriTrash*
midori_app_get_trash (MidoriApp* app);
void
midori_app_quit (MidoriApp* app);
G_END_DECLS
#endif /* __MIDORI_APP_H__ */

View file

@ -401,7 +401,7 @@ midori_web_view_load_committed_cb (GtkWidget* web_view,
static gboolean
midori_web_view_console_message_cb (GtkWidget* web_view,
const gchar* message,
gint line,
guint line,
const gchar* source_id,
MidoriBrowser* browser)
{
@ -508,6 +508,12 @@ midori_web_view_destroy_cb (GtkWidget* widget,
return FALSE;
}
static void
_midori_browser_will_quit (MidoriBrowser* browser)
{
// Nothing to do
}
static void
midori_cclosure_marshal_VOID__OBJECT_POINTER_POINTER (GClosure* closure,
GValue* return_value,
@ -716,7 +722,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
class->add_tab = midori_browser_add_tab;
class->add_uri = midori_browser_add_uri;
class->activate_action = midori_browser_activate_action;
class->quit = midori_browser_quit;
class->quit = _midori_browser_will_quit;
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_browser_finalize;
@ -1058,7 +1064,7 @@ _midori_browser_find (MidoriBrowser* browser,
else
icon = gtk_image_new_from_stock (GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (priv->find_text),
SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE (icon));
webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (web_view), text,
case_sensitive, 0);
const gboolean highlight = gtk_toggle_tool_button_get_active (

View file

@ -62,10 +62,10 @@ struct _MidoriBrowserClass
(*new_window) (MidoriBrowser* browser,
const gchar* uri);
void
gint
(*add_tab) (MidoriBrowser* browser,
GtkWidget* widget);
void
gint
(*add_uri) (MidoriBrowser* browser,
const gchar* uri);
void