Merge MidoriAppPrivate with MidoriApp and hide it

This commit is contained in:
Christian Dywan 2008-06-12 23:46:08 +02:00
parent f9fdf1af63
commit 1ffbfaded9
2 changed files with 32 additions and 62 deletions

View file

@ -14,12 +14,10 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT) struct _MidoriApp
static MidoriApp* _midori_app_singleton = NULL;
struct _MidoriAppPrivate
{ {
GObject parent_instance;
GList* browsers; GList* browsers;
MidoriBrowser* browser; MidoriBrowser* browser;
GtkAccelGroup* accel_group; GtkAccelGroup* accel_group;
@ -28,9 +26,9 @@ struct _MidoriAppPrivate
MidoriTrash* trash; MidoriTrash* trash;
}; };
#define MIDORI_APP_GET_PRIVATE(obj) \ G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT)
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
MIDORI_TYPE_APP, MidoriAppPrivate)) static MidoriApp* _midori_app_singleton = NULL;
enum enum
{ {
@ -140,8 +138,6 @@ midori_app_class_init (MidoriAppClass* class)
_("The current number of browsers"), _("The current number of browsers"),
0, G_MAXUINT, 0, 0, G_MAXUINT, 0,
G_PARAM_READABLE)); G_PARAM_READABLE));
g_type_class_add_private (class, sizeof (MidoriAppPrivate));
} }
static GObject* static GObject*
@ -163,27 +159,22 @@ midori_app_init (MidoriApp* app)
_midori_app_singleton = app; _midori_app_singleton = app;
app->priv = MIDORI_APP_GET_PRIVATE (app); app->accel_group = gtk_accel_group_new ();
MidoriAppPrivate* priv = app->priv; app->settings = midori_web_settings_new ();
app->trash = midori_trash_new (10);
priv->accel_group = gtk_accel_group_new ();
priv->settings = midori_web_settings_new ();
priv->trash = midori_trash_new (10);
} }
static void static void
midori_app_finalize (GObject* object) midori_app_finalize (GObject* object)
{ {
MidoriApp* app = MIDORI_APP (object); MidoriApp* app = MIDORI_APP (object);
MidoriAppPrivate* priv = app->priv;
g_list_free (priv->browsers); g_list_free (app->browsers);
g_object_unref (priv->accel_group); g_object_unref (app->accel_group);
g_object_unref (priv->settings); g_object_unref (app->settings);
g_object_unref (priv->trash); g_object_unref (app->trash);
G_OBJECT_CLASS (midori_app_parent_class)->finalize (object); G_OBJECT_CLASS (midori_app_parent_class)->finalize (object);
} }
@ -195,19 +186,18 @@ midori_app_set_property (GObject* object,
GParamSpec* pspec) GParamSpec* pspec)
{ {
MidoriApp* app = MIDORI_APP (object); MidoriApp* app = MIDORI_APP (object);
MidoriAppPrivate* priv = app->priv;
switch (prop_id) switch (prop_id)
{ {
case PROP_SETTINGS: case PROP_SETTINGS:
katze_object_assign (priv->settings, g_value_get_object (value)); katze_object_assign (app->settings, g_value_get_object (value));
g_object_ref (priv->settings); g_object_ref (app->settings);
// FIXME: Propagate settings to all browsers /* FIXME: Propagate settings to all browsers */
break; break;
case PROP_TRASH: case PROP_TRASH:
katze_object_assign (priv->trash, g_value_get_object (value)); katze_object_assign (app->trash, g_value_get_object (value));
g_object_ref (priv->trash); g_object_ref (app->trash);
// FIXME: Propagate trash to all browsers /* FIXME: Propagate trash to all browsers */
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -222,21 +212,20 @@ midori_app_get_property (GObject* object,
GParamSpec* pspec) GParamSpec* pspec)
{ {
MidoriApp* app = MIDORI_APP (object); MidoriApp* app = MIDORI_APP (object);
MidoriAppPrivate* priv = app->priv;
switch (prop_id) switch (prop_id)
{ {
case PROP_SETTINGS: case PROP_SETTINGS:
g_value_set_object (value, priv->settings); g_value_set_object (value, app->settings);
break; break;
case PROP_TRASH: case PROP_TRASH:
g_value_set_object (value, priv->trash); g_value_set_object (value, app->trash);
break; break;
case PROP_BROWSER: case PROP_BROWSER:
g_value_set_object (value, priv->browser); g_value_set_object (value, app->browser);
break; break;
case PROP_BROWSER_COUNT: case PROP_BROWSER_COUNT:
g_value_set_uint (value, g_list_length (priv->browsers)); g_value_set_uint (value, g_list_length (app->browsers));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -249,9 +238,7 @@ midori_browser_focus_in_event_cb (MidoriBrowser* browser,
GdkEventFocus* event, GdkEventFocus* event,
MidoriApp* app) MidoriApp* app)
{ {
MidoriAppPrivate* priv = app->priv; app->browser = browser;
priv->browser = browser;
return FALSE; return FALSE;
} }
@ -260,11 +247,9 @@ midori_browser_new_window_cb (MidoriBrowser* browser,
const gchar* uri, const gchar* uri,
MidoriApp* app) MidoriApp* app)
{ {
MidoriAppPrivate* priv = app->priv;
MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER, MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER,
"settings", priv->settings, "settings", app->settings,
"trash", priv->trash, "trash", app->trash,
NULL); NULL);
midori_browser_add_uri (new_browser, uri); midori_browser_add_uri (new_browser, uri);
gtk_widget_show (GTK_WIDGET (new_browser)); gtk_widget_show (GTK_WIDGET (new_browser));
@ -284,10 +269,8 @@ static gboolean
midori_browser_destroy_cb (MidoriBrowser* browser, midori_browser_destroy_cb (MidoriBrowser* browser,
MidoriApp* app) MidoriApp* app)
{ {
MidoriAppPrivate* priv = app->priv; app->browsers = g_list_remove (app->browsers, browser);
if (g_list_nth (app->browsers, 0))
priv->browsers = g_list_remove (priv->browsers, browser);
if (g_list_nth (priv->browsers, 0))
return FALSE; return FALSE;
midori_app_quit (app); midori_app_quit (app);
return TRUE; return TRUE;
@ -333,9 +316,7 @@ void
midori_app_add_browser (MidoriApp* app, midori_app_add_browser (MidoriApp* app,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
MidoriAppPrivate* priv = app->priv; gtk_window_add_accel_group (GTK_WINDOW (browser), app->accel_group);
gtk_window_add_accel_group (GTK_WINDOW (browser), priv->accel_group);
g_object_connect (browser, g_object_connect (browser,
"signal::focus-in-event", midori_browser_focus_in_event_cb, app, "signal::focus-in-event", midori_browser_focus_in_event_cb, app,
"signal::new-window", midori_browser_new_window_cb, app, "signal::new-window", midori_browser_new_window_cb, app,
@ -344,7 +325,7 @@ midori_app_add_browser (MidoriApp* app,
"signal::quit", midori_browser_quit_cb, app, "signal::quit", midori_browser_quit_cb, app,
NULL); NULL);
priv->browsers = g_list_prepend (priv->browsers, browser); app->browsers = g_list_prepend (app->browsers, browser);
} }
/** /**
@ -360,9 +341,7 @@ midori_app_get_settings (MidoriApp* app)
{ {
g_return_val_if_fail (MIDORI_IS_APP (app), NULL); g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
MidoriAppPrivate* priv = app->priv; return app->settings;
return priv->settings;
} }
/** /**
@ -395,9 +374,7 @@ midori_app_get_trash (MidoriApp* app)
{ {
g_return_val_if_fail (MIDORI_IS_APP (app), NULL); g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
MidoriAppPrivate* priv = app->priv; return app->trash;
return priv->trash;
} }
/** /**

View file

@ -37,13 +37,6 @@ typedef struct _MidoriApp MidoriApp;
typedef struct _MidoriAppPrivate MidoriAppPrivate; typedef struct _MidoriAppPrivate MidoriAppPrivate;
typedef struct _MidoriAppClass MidoriAppClass; typedef struct _MidoriAppClass MidoriAppClass;
struct _MidoriApp
{
GObject parent_instance;
MidoriAppPrivate* priv;
};
struct _MidoriAppClass struct _MidoriAppClass
{ {
GObjectClass parent_class; GObjectClass parent_class;