Implement MidoriApp singleton and improve multiple window support
The new singleton holds the shared settings and trash. It is further more used to keep track of all open windows and quits when the last window was closed. It also watches the focus in case you need something like a "current" browser.
This commit is contained in:
parent
61d26feae8
commit
4a488da7b1
10 changed files with 502 additions and 80 deletions
|
@ -18,6 +18,7 @@ bin_PROGRAMS = \
|
||||||
|
|
||||||
midori_SOURCES = \
|
midori_SOURCES = \
|
||||||
main.c main.h \
|
main.c main.h \
|
||||||
|
midori-app.c midori-app.h \
|
||||||
midori-browser.c midori-browser.h \
|
midori-browser.c midori-browser.h \
|
||||||
midori-panel.c midori-panel.h \
|
midori-panel.c midori-panel.h \
|
||||||
midori-addons.c midori-addons.h \
|
midori-addons.c midori-addons.h \
|
||||||
|
|
67
src/main.c
67
src/main.c
|
@ -14,12 +14,13 @@
|
||||||
#include "sokoke.h"
|
#include "sokoke.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
|
|
||||||
|
#include "midori-app.h"
|
||||||
#include "midori-websettings.h"
|
#include "midori-websettings.h"
|
||||||
#include "midori-trash.h"
|
#include "midori-trash.h"
|
||||||
#include "midori-browser.h"
|
#include "midori-browser.h"
|
||||||
#include <katze/katze.h>
|
|
||||||
#include "gjs.h"
|
#include "gjs.h"
|
||||||
|
|
||||||
|
#include <katze/katze.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
@ -27,9 +28,6 @@
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
# if HAVE_LOCALE_H
|
|
||||||
# include <locale.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -- stock icons
|
// -- stock icons
|
||||||
|
@ -76,47 +74,6 @@ static void stock_items_init(void)
|
||||||
g_object_unref(factory);
|
g_object_unref(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
midori_browser_delete_event_cb (MidoriBrowser* browser,
|
|
||||||
GdkEvent* event,
|
|
||||||
GList* browsers)
|
|
||||||
{
|
|
||||||
browsers = g_list_remove (browsers, browser);
|
|
||||||
if (g_list_nth (browsers, 0))
|
|
||||||
return FALSE;
|
|
||||||
gtk_main_quit ();
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
midori_browser_quit_cb (MidoriBrowser* browser,
|
|
||||||
GdkEvent* event,
|
|
||||||
GList* browsers)
|
|
||||||
{
|
|
||||||
gtk_main_quit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
midori_browser_new_window_cb (MidoriBrowser* browser,
|
|
||||||
const gchar* uri,
|
|
||||||
GList* browsers)
|
|
||||||
{
|
|
||||||
MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER,
|
|
||||||
// "settings", settings,
|
|
||||||
// "trash", trash,
|
|
||||||
NULL);
|
|
||||||
// gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group);
|
|
||||||
g_object_connect (new_browser,
|
|
||||||
"signal::new-window", midori_browser_new_window_cb, browsers,
|
|
||||||
"signal::delete-event", midori_browser_delete_event_cb, browsers,
|
|
||||||
"signal::quit", midori_browser_quit_cb, browsers,
|
|
||||||
NULL);
|
|
||||||
browsers = g_list_prepend(browsers, new_browser);
|
|
||||||
gtk_widget_show (GTK_WIDGET (new_browser));
|
|
||||||
|
|
||||||
midori_browser_append_uri (new_browser, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
locale_init (void)
|
locale_init (void)
|
||||||
{
|
{
|
||||||
|
@ -443,9 +400,10 @@ main (int argc, char** argv)
|
||||||
|
|
||||||
stock_items_init ();
|
stock_items_init ();
|
||||||
|
|
||||||
MidoriTrash* trash = g_object_new (MIDORI_TYPE_TRASH,
|
MidoriApp* app = midori_app_new ();
|
||||||
"limit", 10,
|
g_object_set (app, "settings", settings, NULL);
|
||||||
NULL);
|
|
||||||
|
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);
|
||||||
guint i;
|
guint i;
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
@ -454,20 +412,12 @@ main (int argc, char** argv)
|
||||||
midori_trash_prepend_xbel_item (trash, item);
|
midori_trash_prepend_xbel_item (trash, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkAccelGroup* accel_group = gtk_accel_group_new();
|
|
||||||
GList* browsers = NULL;
|
|
||||||
|
|
||||||
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER,
|
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER,
|
||||||
"settings", settings,
|
"settings", settings,
|
||||||
"trash", trash,
|
"trash", trash,
|
||||||
NULL);
|
NULL);
|
||||||
gtk_window_add_accel_group (GTK_WINDOW (browser), accel_group);
|
g_signal_emit_by_name (app, "add-browser", browser);
|
||||||
g_object_connect (browser,
|
|
||||||
"signal::new-window", midori_browser_new_window_cb, browsers,
|
|
||||||
"signal::delete-event", midori_browser_delete_event_cb, browsers,
|
|
||||||
"signal::quit", midori_browser_quit_cb, browsers,
|
|
||||||
NULL);
|
|
||||||
browsers = g_list_prepend (browsers, 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 ();
|
||||||
|
@ -509,7 +459,6 @@ main (int argc, char** argv)
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
JSGlobalContextRelease (js_context);
|
JSGlobalContextRelease (js_context);
|
||||||
g_object_unref (accel_group);
|
|
||||||
|
|
||||||
// Save configuration files
|
// Save configuration files
|
||||||
config_path = g_build_filename (g_get_user_config_dir(), PACKAGE_NAME,
|
config_path = g_build_filename (g_get_user_config_dir(), PACKAGE_NAME,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#ifndef __MAIN_H__
|
#ifndef __MAIN_H__
|
||||||
#define __MAIN_H__ 1
|
#define __MAIN_H__ 1
|
||||||
|
|
||||||
#include "midori-websettings.h"
|
|
||||||
#include <katze/katze.h>
|
#include <katze/katze.h>
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
385
src/midori-app.c
Normal file
385
src/midori-app.c
Normal file
|
@ -0,0 +1,385 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
See the file COPYING for the full license text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "midori-app.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static MidoriApp* _midori_app_singleton = NULL;
|
||||||
|
|
||||||
|
struct _MidoriAppPrivate
|
||||||
|
{
|
||||||
|
GList* browsers;
|
||||||
|
MidoriBrowser* browser;
|
||||||
|
GtkAccelGroup* accel_group;
|
||||||
|
|
||||||
|
MidoriWebSettings* settings;
|
||||||
|
MidoriTrash* trash;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MIDORI_APP_GET_PRIVATE(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
|
||||||
|
MIDORI_TYPE_APP, MidoriAppPrivate))
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
|
||||||
|
PROP_SETTINGS,
|
||||||
|
PROP_TRASH,
|
||||||
|
PROP_BROWSER,
|
||||||
|
PROP_BROWSER_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ADD_BROWSER,
|
||||||
|
QUIT,
|
||||||
|
|
||||||
|
LAST_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[LAST_SIGNAL];
|
||||||
|
|
||||||
|
static GObject*
|
||||||
|
midori_app_constructor (GType type,
|
||||||
|
guint n_construct_properties,
|
||||||
|
GObjectConstructParam* construct_properties);
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_finalize (GObject* object);
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_set_property (GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue* value,
|
||||||
|
GParamSpec* pspec);
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_get_property (GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
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),
|
||||||
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
||||||
|
G_STRUCT_OFFSET (MidoriAppClass, add_browser),
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
g_cclosure_marshal_VOID__OBJECT,
|
||||||
|
G_TYPE_NONE, 1,
|
||||||
|
MIDORI_TYPE_BROWSER);
|
||||||
|
|
||||||
|
signals[QUIT] = g_signal_new (
|
||||||
|
"quit",
|
||||||
|
G_TYPE_FROM_CLASS(class),
|
||||||
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
||||||
|
G_STRUCT_OFFSET (MidoriAppClass, quit),
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
|
||||||
|
gobject_class->constructor = midori_app_constructor;
|
||||||
|
gobject_class->finalize = midori_app_finalize;
|
||||||
|
gobject_class->set_property = midori_app_set_property;
|
||||||
|
gobject_class->get_property = midori_app_get_property;
|
||||||
|
|
||||||
|
MidoriAppClass* midoriapp_class = MIDORI_APP_CLASS (class);
|
||||||
|
midoriapp_class->add_browser = midori_app_add_browser;
|
||||||
|
midoriapp_class->quit = midori_app_quit;
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_SETTINGS,
|
||||||
|
g_param_spec_object (
|
||||||
|
"settings",
|
||||||
|
_("Settings"),
|
||||||
|
_("The associated settings"),
|
||||||
|
MIDORI_TYPE_WEB_SETTINGS,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_TRASH,
|
||||||
|
g_param_spec_object (
|
||||||
|
"trash",
|
||||||
|
_("Trash"),
|
||||||
|
_("The trash, collecting recently closed tabs and windows"),
|
||||||
|
MIDORI_TYPE_TRASH,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_BROWSER,
|
||||||
|
g_param_spec_object (
|
||||||
|
"browser",
|
||||||
|
_("Browser"),
|
||||||
|
_("The current browser"),
|
||||||
|
MIDORI_TYPE_BROWSER,
|
||||||
|
G_PARAM_READABLE));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_BROWSER_COUNT,
|
||||||
|
g_param_spec_uint (
|
||||||
|
"browser-count",
|
||||||
|
_("Browser Count"),
|
||||||
|
_("The current number of browsers"),
|
||||||
|
0, G_MAXUINT, 0,
|
||||||
|
G_PARAM_READABLE));
|
||||||
|
|
||||||
|
g_type_class_add_private (class, sizeof (MidoriAppPrivate));
|
||||||
|
}
|
||||||
|
|
||||||
|
static GObject*
|
||||||
|
midori_app_constructor (GType type,
|
||||||
|
guint n_construct_properties,
|
||||||
|
GObjectConstructParam* construct_properties)
|
||||||
|
{
|
||||||
|
if (_midori_app_singleton)
|
||||||
|
return g_object_ref (_midori_app_singleton);
|
||||||
|
else
|
||||||
|
return G_OBJECT_CLASS (midori_app_parent_class)->constructor (
|
||||||
|
type, n_construct_properties, construct_properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_init (MidoriApp* app)
|
||||||
|
{
|
||||||
|
g_assert (!_midori_app_singleton);
|
||||||
|
|
||||||
|
_midori_app_singleton = app;
|
||||||
|
|
||||||
|
app->priv = MIDORI_APP_GET_PRIVATE (app);
|
||||||
|
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
priv->accel_group = gtk_accel_group_new ();
|
||||||
|
|
||||||
|
priv->settings = midori_web_settings_new ();
|
||||||
|
priv->trash = midori_trash_new (10);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_finalize (GObject* object)
|
||||||
|
{
|
||||||
|
MidoriApp* app = MIDORI_APP (object);
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
g_list_free (priv->browsers);
|
||||||
|
g_object_unref (priv->accel_group);
|
||||||
|
|
||||||
|
g_object_unref (priv->settings);
|
||||||
|
g_object_unref (priv->trash);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (midori_app_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_set_property (GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue* value,
|
||||||
|
GParamSpec* pspec)
|
||||||
|
{
|
||||||
|
MidoriApp* app = MIDORI_APP (object);
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_SETTINGS:
|
||||||
|
katze_object_assign (priv->settings, g_value_get_object (value));
|
||||||
|
g_object_ref (priv->settings);
|
||||||
|
// FIXME: Propagate settings to all browsers
|
||||||
|
break;
|
||||||
|
case PROP_TRASH:
|
||||||
|
katze_object_assign (priv->trash, g_value_get_object (value));
|
||||||
|
g_object_ref (priv->trash);
|
||||||
|
// FIXME: Propagate trash to all browsers
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_app_get_property (GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue* value,
|
||||||
|
GParamSpec* pspec)
|
||||||
|
{
|
||||||
|
MidoriApp* app = MIDORI_APP (object);
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_SETTINGS:
|
||||||
|
g_value_set_object (value, priv->settings);
|
||||||
|
break;
|
||||||
|
case PROP_TRASH:
|
||||||
|
g_value_set_object (value, priv->trash);
|
||||||
|
break;
|
||||||
|
case PROP_BROWSER:
|
||||||
|
g_value_set_object (value, priv->browser);
|
||||||
|
break;
|
||||||
|
case PROP_BROWSER_COUNT:
|
||||||
|
g_value_set_uint (value, g_list_length (priv->browsers));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_browser_focus_in_event_cb (MidoriBrowser* browser,
|
||||||
|
GdkEventFocus* event,
|
||||||
|
MidoriApp* app)
|
||||||
|
{
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
priv->browser = browser;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_browser_new_window_cb (MidoriBrowser* browser,
|
||||||
|
const gchar* uri,
|
||||||
|
MidoriApp* app)
|
||||||
|
{
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER,
|
||||||
|
"settings", priv->settings,
|
||||||
|
"trash", priv->trash,
|
||||||
|
NULL);
|
||||||
|
midori_browser_append_uri (new_browser, uri);
|
||||||
|
gtk_widget_show (GTK_WIDGET (new_browser));
|
||||||
|
|
||||||
|
g_signal_emit (app, signals[ADD_BROWSER], 0, new_browser);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
midori_browser_delete_event_cb (MidoriBrowser* browser,
|
||||||
|
GdkEvent* event,
|
||||||
|
MidoriApp* app)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
midori_browser_destroy_cb (MidoriBrowser* browser,
|
||||||
|
MidoriApp* app)
|
||||||
|
{
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
priv->browsers = g_list_remove (priv->browsers, browser);
|
||||||
|
if (g_list_nth (priv->browsers, 0))
|
||||||
|
return FALSE;
|
||||||
|
g_signal_emit (app, signals[QUIT], 0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_new:
|
||||||
|
*
|
||||||
|
* Instantiates a new #MidoriApp singleton.
|
||||||
|
*
|
||||||
|
* Subsequent calls will ref the initial instance.
|
||||||
|
*
|
||||||
|
* Return value: a new #MidoriApp
|
||||||
|
**/
|
||||||
|
MidoriApp*
|
||||||
|
midori_app_new (void)
|
||||||
|
{
|
||||||
|
MidoriApp* app = g_object_new (MIDORI_TYPE_APP,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* midori_app_get_settings:
|
||||||
|
* @app: a #MidoriApp
|
||||||
|
*
|
||||||
|
* Retrieves the #MidoriWebSettings of the app.
|
||||||
|
*
|
||||||
|
* Return value: the assigned #MidoriWebSettings
|
||||||
|
**/
|
||||||
|
MidoriWebSettings*
|
||||||
|
midori_app_get_settings (MidoriApp* app)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
|
||||||
|
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
return priv->settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* midori_app_get_trash:
|
||||||
|
* @app: a #MidoriApp
|
||||||
|
*
|
||||||
|
* Retrieves the #MidoriTrash of the app.
|
||||||
|
*
|
||||||
|
* Return value: the assigned #MidoriTrash
|
||||||
|
**/
|
||||||
|
MidoriTrash*
|
||||||
|
midori_app_get_trash (MidoriApp* app)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
|
||||||
|
|
||||||
|
MidoriAppPrivate* priv = app->priv;
|
||||||
|
|
||||||
|
return priv->trash;
|
||||||
|
}
|
73
src/midori-app.h
Normal file
73
src/midori-app.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
See the file COPYING for the full license text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MIDORI_APP_H__
|
||||||
|
#define __MIDORI_APP_H__
|
||||||
|
|
||||||
|
#include <katze/katze.h>
|
||||||
|
|
||||||
|
#include "midori-browser.h"
|
||||||
|
#include "midori-websettings.h"
|
||||||
|
#include "midori-trash.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define MIDORI_TYPE_APP \
|
||||||
|
(midori_app_get_type ())
|
||||||
|
#define MIDORI_APP(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_APP, MidoriApp))
|
||||||
|
#define MIDORI_APP_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_APP, MidoriAppClass))
|
||||||
|
#define MIDORI_IS_APP(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_APP))
|
||||||
|
#define MIDORI_IS_APP_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_APP))
|
||||||
|
#define MIDORI_APP_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_APP, MidoriAppClass))
|
||||||
|
|
||||||
|
typedef struct _MidoriApp MidoriApp;
|
||||||
|
typedef struct _MidoriAppPrivate MidoriAppPrivate;
|
||||||
|
typedef struct _MidoriAppClass MidoriAppClass;
|
||||||
|
|
||||||
|
struct _MidoriApp
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
|
||||||
|
MidoriAppPrivate* priv;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MidoriAppClass
|
||||||
|
{
|
||||||
|
GObjectClass parent_class;
|
||||||
|
|
||||||
|
/* Signals */
|
||||||
|
void
|
||||||
|
(*add_browser) (MidoriApp* app,
|
||||||
|
MidoriBrowser* browser);
|
||||||
|
void
|
||||||
|
(*quit) (MidoriApp* app);
|
||||||
|
};
|
||||||
|
|
||||||
|
GType
|
||||||
|
midori_app_get_type (void);
|
||||||
|
|
||||||
|
MidoriApp*
|
||||||
|
midori_app_new (void);
|
||||||
|
|
||||||
|
MidoriWebSettings*
|
||||||
|
midori_app_get_web_settings (MidoriApp* app);
|
||||||
|
|
||||||
|
MidoriTrash*
|
||||||
|
midori_app_get_trash (MidoriApp* app);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __MIDORI_APP_H__ */
|
|
@ -540,7 +540,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
|
||||||
signals[WINDOW_OBJECT_CLEARED] = g_signal_new (
|
signals[WINDOW_OBJECT_CLEARED] = g_signal_new (
|
||||||
"window-object-cleared",
|
"window-object-cleared",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriBrowserClass, window_object_cleared),
|
G_STRUCT_OFFSET (MidoriBrowserClass, window_object_cleared),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -553,7 +553,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
|
||||||
signals[STATUSBAR_TEXT_CHANGED] = g_signal_new (
|
signals[STATUSBAR_TEXT_CHANGED] = g_signal_new (
|
||||||
"statusbar-text-changed",
|
"statusbar-text-changed",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriBrowserClass, statusbar_text_changed),
|
G_STRUCT_OFFSET (MidoriBrowserClass, statusbar_text_changed),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -564,7 +564,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
|
||||||
signals[ELEMENT_MOTION] = g_signal_new (
|
signals[ELEMENT_MOTION] = g_signal_new (
|
||||||
"element-motion",
|
"element-motion",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriBrowserClass, element_motion),
|
G_STRUCT_OFFSET (MidoriBrowserClass, element_motion),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -585,7 +585,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
|
||||||
signals[NEW_WINDOW] = g_signal_new (
|
signals[NEW_WINDOW] = g_signal_new (
|
||||||
"new-window",
|
"new-window",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriBrowserClass, new_window),
|
G_STRUCT_OFFSET (MidoriBrowserClass, new_window),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -807,7 +807,7 @@ static void
|
||||||
_action_quit_activate (GtkAction* action,
|
_action_quit_activate (GtkAction* action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
g_signal_emit (browser, signals[QUIT], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2305,6 +2305,16 @@ midori_browser_size_allocate_cb (MidoriBrowser* browser,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_browser_destroy_cb (MidoriBrowser* browser)
|
||||||
|
{
|
||||||
|
MidoriBrowserPrivate* priv = browser->priv;
|
||||||
|
|
||||||
|
// Destroy tabs first, so widgets can still see window elements on destroy
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (priv->notebook),
|
||||||
|
G_CALLBACK (gtk_widget_destroy), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static const gchar* ui_markup =
|
static const gchar* ui_markup =
|
||||||
"<ui>"
|
"<ui>"
|
||||||
"<menubar>"
|
"<menubar>"
|
||||||
|
@ -2437,6 +2447,8 @@ midori_browser_init (MidoriBrowser* browser)
|
||||||
G_CALLBACK (midori_browser_window_state_event_cb), NULL);
|
G_CALLBACK (midori_browser_window_state_event_cb), NULL);
|
||||||
g_signal_connect (browser, "size-allocate",
|
g_signal_connect (browser, "size-allocate",
|
||||||
G_CALLBACK (midori_browser_size_allocate_cb), NULL);
|
G_CALLBACK (midori_browser_size_allocate_cb), NULL);
|
||||||
|
g_signal_connect (browser, "destroy",
|
||||||
|
G_CALLBACK (midori_browser_destroy_cb), NULL);
|
||||||
// FIXME: Use custom program icon
|
// FIXME: Use custom program icon
|
||||||
gtk_window_set_icon_name (GTK_WINDOW (browser), "web-browser");
|
gtk_window_set_icon_name (GTK_WINDOW (browser), "web-browser");
|
||||||
gtk_window_set_title (GTK_WINDOW (browser), g_get_application_name ());
|
gtk_window_set_title (GTK_WINDOW (browser), g_get_application_name ());
|
||||||
|
@ -3037,6 +3049,8 @@ midori_browser_set_property (GObject* object,
|
||||||
_midori_browser_update_settings (browser);
|
_midori_browser_update_settings (browser);
|
||||||
g_signal_connect (priv->settings, "notify",
|
g_signal_connect (priv->settings, "notify",
|
||||||
G_CALLBACK (midori_browser_settings_notify), browser);
|
G_CALLBACK (midori_browser_settings_notify), browser);
|
||||||
|
// FIXME: Assigning settings must be conditional, if web view or not
|
||||||
|
// FIXME: Assign settings only if the same settings object was used
|
||||||
gtk_container_foreach (GTK_CONTAINER (priv->notebook),
|
gtk_container_foreach (GTK_CONTAINER (priv->notebook),
|
||||||
(GtkCallback) midori_web_view_set_settings,
|
(GtkCallback) midori_web_view_set_settings,
|
||||||
priv->settings);
|
priv->settings);
|
||||||
|
@ -3097,17 +3111,18 @@ midori_browser_get_property (GObject* object,
|
||||||
*
|
*
|
||||||
* Creates a new browser widget.
|
* Creates a new browser widget.
|
||||||
*
|
*
|
||||||
* A browser is a window with toolbars and one or multiple web views.
|
* A browser is a window with a menubar, toolbars, a notebook, panels
|
||||||
|
* and a statusbar. You should mostly treat it as an opaque widget.
|
||||||
*
|
*
|
||||||
* Return value: a new #MidoriBrowser
|
* Return value: a new #MidoriBrowser
|
||||||
**/
|
**/
|
||||||
GtkWidget*
|
MidoriBrowser*
|
||||||
midori_browser_new (void)
|
midori_browser_new (void)
|
||||||
{
|
{
|
||||||
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER,
|
MidoriBrowser* browser = g_object_new (MIDORI_TYPE_BROWSER,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return GTK_WIDGET (browser);
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -68,7 +68,7 @@ struct _MidoriBrowserClass
|
||||||
GType
|
GType
|
||||||
midori_browser_get_type (void);
|
midori_browser_get_type (void);
|
||||||
|
|
||||||
GtkWidget*
|
MidoriBrowser*
|
||||||
midori_browser_new (void);
|
midori_browser_new (void);
|
||||||
|
|
||||||
gint
|
gint
|
||||||
|
|
|
@ -122,7 +122,7 @@ midori_panel_class_init (MidoriPanelClass* class)
|
||||||
signals[SWITCH_PAGE] = g_signal_new (
|
signals[SWITCH_PAGE] = g_signal_new (
|
||||||
"switch-page",
|
"switch-page",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriPanelClass, switch_page),
|
G_STRUCT_OFFSET (MidoriPanelClass, switch_page),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -63,7 +63,7 @@ midori_trash_class_init (MidoriTrashClass* class)
|
||||||
signals[INSERTED] = g_signal_new (
|
signals[INSERTED] = g_signal_new (
|
||||||
"inserted",
|
"inserted",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriTrashClass, inserted),
|
G_STRUCT_OFFSET (MidoriTrashClass, inserted),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -74,7 +74,7 @@ midori_trash_class_init (MidoriTrashClass* class)
|
||||||
signals[REMOVED] = g_signal_new (
|
signals[REMOVED] = g_signal_new (
|
||||||
"removed",
|
"removed",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriTrashClass, removed),
|
G_STRUCT_OFFSET (MidoriTrashClass, removed),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -108,7 +108,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[PROGRESS_STARTED] = g_signal_new (
|
signals[PROGRESS_STARTED] = g_signal_new (
|
||||||
"progress-started",
|
"progress-started",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, progress_started),
|
G_STRUCT_OFFSET (MidoriWebViewClass, progress_started),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -119,7 +119,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[PROGRESS_CHANGED] = g_signal_new (
|
signals[PROGRESS_CHANGED] = g_signal_new (
|
||||||
"progress-changed",
|
"progress-changed",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, progress_changed),
|
G_STRUCT_OFFSET (MidoriWebViewClass, progress_changed),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -130,7 +130,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[PROGRESS_DONE] = g_signal_new (
|
signals[PROGRESS_DONE] = g_signal_new (
|
||||||
"progress-done",
|
"progress-done",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, progress_done),
|
G_STRUCT_OFFSET (MidoriWebViewClass, progress_done),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -141,7 +141,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[LOAD_DONE] = g_signal_new (
|
signals[LOAD_DONE] = g_signal_new (
|
||||||
"load-done",
|
"load-done",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, load_done),
|
G_STRUCT_OFFSET (MidoriWebViewClass, load_done),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -152,7 +152,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[ELEMENT_MOTION] = g_signal_new(
|
signals[ELEMENT_MOTION] = g_signal_new(
|
||||||
"element-motion",
|
"element-motion",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, element_motion),
|
G_STRUCT_OFFSET (MidoriWebViewClass, element_motion),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -184,7 +184,7 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
signals[NEW_WINDOW] = g_signal_new(
|
signals[NEW_WINDOW] = g_signal_new(
|
||||||
"new-window",
|
"new-window",
|
||||||
G_TYPE_FROM_CLASS(class),
|
G_TYPE_FROM_CLASS(class),
|
||||||
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
G_STRUCT_OFFSET (MidoriWebViewClass, new_window),
|
G_STRUCT_OFFSET (MidoriWebViewClass, new_window),
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
Loading…
Reference in a new issue