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

View file

@ -71,13 +71,6 @@ midori_app_get_property (GObject* object,
GValue* value, GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
static void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser);
static void
midori_app_quit (MidoriApp* app);
static void static void
midori_app_class_init (MidoriAppClass* class) midori_app_class_init (MidoriAppClass* class)
{ {
@ -296,7 +289,7 @@ midori_browser_destroy_cb (MidoriBrowser* browser,
priv->browsers = g_list_remove (priv->browsers, browser); priv->browsers = g_list_remove (priv->browsers, browser);
if (g_list_nth (priv->browsers, 0)) if (g_list_nth (priv->browsers, 0))
return FALSE; return FALSE;
g_signal_emit (app, signals[QUIT], 0); midori_app_quit (app);
return TRUE; return TRUE;
} }
@ -304,31 +297,7 @@ static void
midori_browser_quit_cb (MidoriBrowser* browser, midori_browser_quit_cb (MidoriBrowser* browser,
MidoriApp* app) MidoriApp* app)
{ {
g_signal_emit (app, signals[QUIT], 0); midori_app_quit (app);
}
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 ();
} }
/** /**
@ -349,6 +318,35 @@ midori_app_new (void)
return app; 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: * midori_app_get_settings:
* @app: a #MidoriApp * @app: a #MidoriApp
@ -367,6 +365,25 @@ midori_app_get_settings (MidoriApp* app)
return priv->settings; 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: * midori_app_get_trash:
* @app: a #MidoriApp * @app: a #MidoriApp
@ -384,3 +401,17 @@ midori_app_get_trash (MidoriApp* app)
return priv->trash; 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* MidoriApp*
midori_app_new (void); midori_app_new (void);
void
midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser);
MidoriWebSettings* MidoriWebSettings*
midori_app_get_web_settings (MidoriApp* app); midori_app_get_settings (MidoriApp* app);
void
midori_app_set_settings (MidoriApp* app,
MidoriWebSettings* settings);
MidoriTrash* MidoriTrash*
midori_app_get_trash (MidoriApp* app); midori_app_get_trash (MidoriApp* app);
void
midori_app_quit (MidoriApp* app);
G_END_DECLS G_END_DECLS
#endif /* __MIDORI_APP_H__ */ #endif /* __MIDORI_APP_H__ */

View file

@ -401,7 +401,7 @@ midori_web_view_load_committed_cb (GtkWidget* web_view,
static gboolean static gboolean
midori_web_view_console_message_cb (GtkWidget* web_view, midori_web_view_console_message_cb (GtkWidget* web_view,
const gchar* message, const gchar* message,
gint line, guint line,
const gchar* source_id, const gchar* source_id,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
@ -508,6 +508,12 @@ midori_web_view_destroy_cb (GtkWidget* widget,
return FALSE; return FALSE;
} }
static void
_midori_browser_will_quit (MidoriBrowser* browser)
{
// Nothing to do
}
static void static void
midori_cclosure_marshal_VOID__OBJECT_POINTER_POINTER (GClosure* closure, midori_cclosure_marshal_VOID__OBJECT_POINTER_POINTER (GClosure* closure,
GValue* return_value, GValue* return_value,
@ -716,7 +722,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
class->add_tab = midori_browser_add_tab; class->add_tab = midori_browser_add_tab;
class->add_uri = midori_browser_add_uri; class->add_uri = midori_browser_add_uri;
class->activate_action = midori_browser_activate_action; 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); GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_browser_finalize; gobject_class->finalize = midori_browser_finalize;

View file

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