2008-05-22 22:17:10 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2008-08-22 01:59:07 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
#include "midori-app.h"
|
|
|
|
|
2008-08-22 01:59:07 +00:00
|
|
|
#include <string.h>
|
2008-05-22 22:17:10 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
#include <unique/unique.h>
|
|
|
|
#endif
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
struct _MidoriApp
|
2008-05-22 22:17:10 +00:00
|
|
|
{
|
2008-06-12 21:46:08 +00:00
|
|
|
GObject parent_instance;
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
GList* browsers;
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
GtkAccelGroup* accel_group;
|
|
|
|
|
|
|
|
MidoriWebSettings* settings;
|
2008-10-01 02:00:16 +00:00
|
|
|
KatzeArray* bookmarks;
|
2008-08-25 23:19:38 +00:00
|
|
|
KatzeArray* trash;
|
|
|
|
KatzeArray* search_engines;
|
2008-10-07 00:19:33 +00:00
|
|
|
KatzeArray* history;
|
2008-08-22 01:59:07 +00:00
|
|
|
|
|
|
|
gpointer instance;
|
2008-05-22 22:17:10 +00:00
|
|
|
};
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
static MidoriApp* _midori_app_singleton = NULL;
|
2008-05-22 22:17:10 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_SETTINGS,
|
2008-09-03 00:28:54 +00:00
|
|
|
PROP_BOOKMARKS,
|
2008-05-22 22:17:10 +00:00
|
|
|
PROP_TRASH,
|
2008-09-03 00:28:54 +00:00
|
|
|
PROP_SEARCH_ENGINES,
|
2008-05-22 22:17:10 +00:00
|
|
|
PROP_BROWSER,
|
2008-10-07 00:19:33 +00:00
|
|
|
PROP_HISTORY,
|
2008-09-03 00:28:54 +00:00
|
|
|
PROP_BROWSER_COUNT
|
2008-05-22 22:17:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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_class_init (MidoriAppClass* class)
|
|
|
|
{
|
2008-09-03 00:28:54 +00:00
|
|
|
GObjectClass* gobject_class;
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
signals[ADD_BROWSER] = g_signal_new (
|
|
|
|
"add-browser",
|
2008-06-07 23:25:57 +00:00
|
|
|
G_TYPE_FROM_CLASS (class),
|
2008-05-22 22:17:10 +00:00
|
|
|
(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",
|
2008-06-07 23:25:57 +00:00
|
|
|
G_TYPE_FROM_CLASS (class),
|
2008-05-22 22:17:10 +00:00
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
G_STRUCT_OFFSET (MidoriAppClass, quit),
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2008-09-03 00:28:54 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2008-05-22 22:17:10 +00:00
|
|
|
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;
|
|
|
|
|
2008-09-03 00:28:54 +00:00
|
|
|
class->add_browser = midori_app_add_browser;
|
|
|
|
class->quit = midori_app_quit;
|
2008-05-22 22:17:10 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SETTINGS,
|
|
|
|
g_param_spec_object (
|
|
|
|
"settings",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Settings",
|
|
|
|
"The associated settings",
|
2008-05-22 22:17:10 +00:00
|
|
|
MIDORI_TYPE_WEB_SETTINGS,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2008-09-03 00:28:54 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BOOKMARKS,
|
|
|
|
g_param_spec_object (
|
|
|
|
"bookmarks",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Bookmarks",
|
|
|
|
"The bookmarks folder, containing all bookmarks",
|
2008-10-01 02:00:16 +00:00
|
|
|
KATZE_TYPE_ARRAY,
|
2008-09-03 00:28:54 +00:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_TRASH,
|
|
|
|
g_param_spec_object (
|
|
|
|
"trash",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Trash",
|
|
|
|
"The trash, collecting recently closed tabs and windows",
|
2008-08-25 23:19:38 +00:00
|
|
|
KATZE_TYPE_ARRAY,
|
2008-05-22 22:17:10 +00:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2008-09-03 00:28:54 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SEARCH_ENGINES,
|
|
|
|
g_param_spec_object (
|
|
|
|
"search-engines",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Search Engines",
|
|
|
|
"The list of search engines",
|
2008-09-03 00:28:54 +00:00
|
|
|
KATZE_TYPE_ARRAY,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BROWSER,
|
|
|
|
g_param_spec_object (
|
|
|
|
"browser",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Browser",
|
|
|
|
"The current browser",
|
2008-05-22 22:17:10 +00:00
|
|
|
MIDORI_TYPE_BROWSER,
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BROWSER_COUNT,
|
|
|
|
g_param_spec_uint (
|
|
|
|
"browser-count",
|
2008-10-15 01:32:11 +00:00
|
|
|
"Browser Count",
|
|
|
|
"The current number of browsers",
|
2008-05-22 22:17:10 +00:00
|
|
|
0, G_MAXUINT, 0,
|
|
|
|
G_PARAM_READABLE));
|
2008-10-07 00:19:33 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_HISTORY,
|
|
|
|
g_param_spec_object (
|
|
|
|
"history",
|
2008-10-15 01:32:11 +00:00
|
|
|
"History",
|
|
|
|
"The list of history items",
|
2008-10-07 00:19:33 +00:00
|
|
|
KATZE_TYPE_ARRAY,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
static UniqueResponse
|
|
|
|
midori_browser_message_received_cb (UniqueApp* instance,
|
|
|
|
UniqueCommand command,
|
|
|
|
UniqueMessageData* message,
|
|
|
|
guint time,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
UniqueResponse response;
|
2008-09-10 17:48:45 +00:00
|
|
|
MidoriBrowser* browser;
|
2008-08-22 01:59:07 +00:00
|
|
|
gchar** uris;
|
2008-10-20 06:50:16 +00:00
|
|
|
MidoriNewPage open_external_pages_in;
|
|
|
|
gboolean first;
|
2008-08-22 01:59:07 +00:00
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case UNIQUE_ACTIVATE:
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (app->browser),
|
|
|
|
unique_message_data_get_screen (message));
|
|
|
|
gtk_window_present (GTK_WINDOW (app->browser));
|
|
|
|
response = UNIQUE_RESPONSE_OK;
|
|
|
|
break;
|
2008-09-10 17:48:45 +00:00
|
|
|
case UNIQUE_NEW:
|
|
|
|
browser = g_object_new (MIDORI_TYPE_BROWSER,
|
|
|
|
"settings", app->settings,
|
|
|
|
"bookmarks", app->bookmarks,
|
|
|
|
"trash", app->trash,
|
|
|
|
"search-engines", app->search_engines,
|
2008-10-07 00:19:33 +00:00
|
|
|
"history", app->history,
|
2008-09-10 17:48:45 +00:00
|
|
|
NULL);
|
|
|
|
/* FIXME: Should open the homepage according to settings */
|
2008-10-07 20:30:09 +00:00
|
|
|
midori_browser_add_uri (browser, "");
|
2008-10-21 20:59:57 +00:00
|
|
|
midori_browser_activate_action (browser, "Location");
|
2008-09-10 17:48:45 +00:00
|
|
|
midori_app_add_browser (app, browser);
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (app->browser),
|
|
|
|
unique_message_data_get_screen (message));
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
|
|
|
response = UNIQUE_RESPONSE_OK;
|
|
|
|
break;
|
2008-08-22 01:59:07 +00:00
|
|
|
case UNIQUE_OPEN:
|
2008-10-03 03:45:10 +00:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (app->browser),
|
|
|
|
unique_message_data_get_screen (message));
|
|
|
|
gtk_window_present (GTK_WINDOW (app->browser));
|
2008-08-22 01:59:07 +00:00
|
|
|
uris = unique_message_data_get_uris (message);
|
|
|
|
if (!uris)
|
|
|
|
response = UNIQUE_RESPONSE_FAIL;
|
|
|
|
else
|
|
|
|
{
|
2008-10-20 06:50:16 +00:00
|
|
|
g_object_get (app->settings, "open-external-pages-in",
|
|
|
|
&open_external_pages_in, NULL);
|
|
|
|
if (open_external_pages_in == MIDORI_NEW_PAGE_WINDOW)
|
|
|
|
{
|
|
|
|
browser = g_object_new (MIDORI_TYPE_BROWSER,
|
|
|
|
"settings", app->settings,
|
|
|
|
"bookmarks", app->bookmarks,
|
|
|
|
"trash", app->trash,
|
|
|
|
"search-engines", app->search_engines,
|
|
|
|
"history", app->history,
|
|
|
|
NULL);
|
|
|
|
midori_app_add_browser (app, browser);
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (app->browser),
|
|
|
|
unique_message_data_get_screen (message));
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
browser = app->browser;
|
|
|
|
first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
|
2008-08-22 01:59:07 +00:00
|
|
|
while (*uris)
|
|
|
|
{
|
2008-10-20 06:50:16 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
midori_browser_set_current_uri (browser, *uris);
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
midori_browser_set_current_page (browser,
|
|
|
|
midori_browser_add_uri (browser, *uris));
|
2008-08-22 01:59:07 +00:00
|
|
|
uris++;
|
|
|
|
}
|
|
|
|
/* g_strfreev (uris); */
|
|
|
|
response = UNIQUE_RESPONSE_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
response = UNIQUE_RESPONSE_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
static void
|
|
|
|
midori_app_init (MidoriApp* app)
|
|
|
|
{
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
gchar* display_name;
|
|
|
|
gchar* instance_name;
|
|
|
|
guint i, n;
|
|
|
|
#endif
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
g_assert (!_midori_app_singleton);
|
|
|
|
|
|
|
|
_midori_app_singleton = app;
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
app->accel_group = gtk_accel_group_new ();
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
app->settings = midori_web_settings_new ();
|
2008-09-03 00:28:54 +00:00
|
|
|
app->bookmarks = NULL;
|
|
|
|
app->trash = NULL;
|
|
|
|
app->search_engines = NULL;
|
2008-10-07 00:19:33 +00:00
|
|
|
app->history = NULL;
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
display_name = g_strdup (gdk_display_get_name (gdk_display_get_default ()));
|
|
|
|
n = strlen (display_name);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
if (display_name[i] == ':' || display_name[i] == '.')
|
|
|
|
display_name[i] = '_';
|
|
|
|
instance_name = g_strdup_printf ("de.twotoasts.midori_%s", display_name);
|
|
|
|
app->instance = unique_app_new (instance_name, NULL);
|
|
|
|
g_free (instance_name);
|
|
|
|
g_free (display_name);
|
|
|
|
g_signal_connect (app->instance, "message-received",
|
|
|
|
G_CALLBACK (midori_browser_message_received_cb), app);
|
|
|
|
#else
|
|
|
|
app->instance = NULL;
|
|
|
|
#endif
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_app_finalize (GObject* object)
|
|
|
|
{
|
|
|
|
MidoriApp* app = MIDORI_APP (object);
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
g_list_free (app->browsers);
|
|
|
|
g_object_unref (app->accel_group);
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->settings, NULL);
|
|
|
|
katze_object_assign (app->bookmarks, NULL);
|
|
|
|
katze_object_assign (app->trash, NULL);
|
|
|
|
katze_object_assign (app->search_engines, NULL);
|
|
|
|
katze_object_assign (app->history, NULL);
|
|
|
|
|
|
|
|
katze_object_assign (app->instance, NULL);
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SETTINGS:
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->settings, g_value_dup_object (value));
|
2008-06-12 21:46:08 +00:00
|
|
|
/* FIXME: Propagate settings to all browsers */
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
2008-09-03 00:28:54 +00:00
|
|
|
case PROP_BOOKMARKS:
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->bookmarks, g_value_dup_object (value));
|
2008-09-03 00:28:54 +00:00
|
|
|
/* FIXME: Propagate bookmarks to all browsers */
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
case PROP_TRASH:
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->trash, g_value_dup_object (value));
|
2008-06-12 21:46:08 +00:00
|
|
|
/* FIXME: Propagate trash to all browsers */
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
2008-06-15 02:02:56 +00:00
|
|
|
case PROP_SEARCH_ENGINES:
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->search_engines, g_value_dup_object (value));
|
2008-06-15 02:02:56 +00:00
|
|
|
/* FIXME: Propagate search engines to all browsers */
|
|
|
|
break;
|
2008-10-07 00:19:33 +00:00
|
|
|
case PROP_HISTORY:
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->history, g_value_dup_object (value));
|
2008-10-07 00:19:33 +00:00
|
|
|
/* FIXME: Propagate history to all browsers */
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SETTINGS:
|
2008-06-12 21:46:08 +00:00
|
|
|
g_value_set_object (value, app->settings);
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
2008-09-03 00:28:54 +00:00
|
|
|
case PROP_BOOKMARKS:
|
|
|
|
g_value_set_object (value, app->bookmarks);
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
case PROP_TRASH:
|
2008-06-12 21:46:08 +00:00
|
|
|
g_value_set_object (value, app->trash);
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
2008-09-03 00:28:54 +00:00
|
|
|
case PROP_SEARCH_ENGINES:
|
|
|
|
g_value_set_object (value, app->search_engines);
|
|
|
|
break;
|
2008-10-07 00:19:33 +00:00
|
|
|
case PROP_HISTORY:
|
|
|
|
g_value_set_object (value, app->history);
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
case PROP_BROWSER:
|
2008-06-12 21:46:08 +00:00
|
|
|
g_value_set_object (value, app->browser);
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
|
|
|
case PROP_BROWSER_COUNT:
|
2008-06-12 21:46:08 +00:00
|
|
|
g_value_set_uint (value, g_list_length (app->browsers));
|
2008-05-22 22:17:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 21:58:00 +00:00
|
|
|
static gboolean
|
2008-05-22 22:17:10 +00:00
|
|
|
midori_browser_focus_in_event_cb (MidoriBrowser* browser,
|
|
|
|
GdkEventFocus* event,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2008-06-12 21:46:08 +00:00
|
|
|
app->browser = browser;
|
2008-09-03 00:28:54 +00:00
|
|
|
g_object_notify (G_OBJECT (app), "browser");
|
2008-06-01 21:58:00 +00:00
|
|
|
return FALSE;
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_browser_new_window_cb (MidoriBrowser* browser,
|
|
|
|
const gchar* uri,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
MidoriBrowser* new_browser = g_object_new (MIDORI_TYPE_BROWSER,
|
2008-06-12 21:46:08 +00:00
|
|
|
"settings", app->settings,
|
2008-09-03 00:28:54 +00:00
|
|
|
"bookmarks", app->bookmarks,
|
2008-06-12 21:46:08 +00:00
|
|
|
"trash", app->trash,
|
2008-08-31 15:05:40 +00:00
|
|
|
"search-engines", app->search_engines,
|
2008-10-07 00:19:33 +00:00
|
|
|
"history", app->history,
|
2008-05-22 22:17:10 +00:00
|
|
|
NULL);
|
2008-05-31 22:21:08 +00:00
|
|
|
midori_browser_add_uri (new_browser, uri);
|
2008-05-22 22:17:10 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-06-12 21:46:08 +00:00
|
|
|
app->browsers = g_list_remove (app->browsers, browser);
|
|
|
|
if (g_list_nth (app->browsers, 0))
|
2008-05-22 22:17:10 +00:00
|
|
|
return FALSE;
|
2008-06-07 23:25:57 +00:00
|
|
|
midori_app_quit (app);
|
2008-05-22 22:17:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_browser_quit_cb (MidoriBrowser* browser,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2008-06-07 23:25:57 +00:00
|
|
|
midori_app_quit (app);
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
2008-06-07 23:25:57 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2008-08-22 01:59:07 +00:00
|
|
|
/**
|
|
|
|
* midori_app_instance_is_running:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
|
|
|
* Determines whether an instance of Midori is
|
|
|
|
* already running on the default display.
|
|
|
|
*
|
|
|
|
* If Midori was built without single instance support
|
|
|
|
* this function will always return %FALSE.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if an instance is already running
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
midori_app_instance_is_running (MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
return unique_app_is_running (app->instance);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* midori_app_instance_send_activate:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
|
|
|
* Sends a message to an instance of Midori already
|
|
|
|
* running on the default display, asking to activate it.
|
|
|
|
*
|
|
|
|
* Practically the current browser will be focussed.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the message was sent successfully
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
midori_app_instance_send_activate (MidoriApp* app)
|
|
|
|
{
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
UniqueResponse response;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
response = unique_app_send_message (app->instance, UNIQUE_ACTIVATE, NULL);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:48:45 +00:00
|
|
|
/**
|
|
|
|
* midori_app_instance_send_new_browser:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
|
|
|
* Sends a message to an instance of Midori already
|
|
|
|
* running on the default display, asking to open a new browser.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the message was sent successfully
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
midori_app_instance_send_new_browser (MidoriApp* app)
|
|
|
|
{
|
|
|
|
#if HAVE_UNIQUE
|
|
|
|
UniqueResponse response;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
|
|
|
|
#if HAVE_UNIQUE
|
|
|
|
response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-22 01:59:07 +00:00
|
|
|
/**
|
|
|
|
* midori_app_instance_send_uris:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
* @uris: a string vector of URIs
|
|
|
|
*
|
|
|
|
* Sends a message to an instance of Midori already
|
|
|
|
* running on the default display, asking to open @uris.
|
|
|
|
*
|
|
|
|
* The strings in @uris will each be opened in a new tab.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the message was sent successfully
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
midori_app_instance_send_uris (MidoriApp* app,
|
|
|
|
gchar** uris)
|
|
|
|
{
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
UniqueMessageData* message;
|
|
|
|
UniqueResponse response;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), FALSE);
|
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
g_return_val_if_fail (uris != NULL, FALSE);
|
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
message = unique_message_data_new ();
|
|
|
|
unique_message_data_set_uris (message, uris);
|
|
|
|
response = unique_app_send_message (app->instance, UNIQUE_OPEN, message);
|
|
|
|
unique_message_data_free (message);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-07 23:25:57 +00:00
|
|
|
/**
|
|
|
|
* midori_app_add_browser:
|
2008-08-22 01:59:07 +00:00
|
|
|
* @app: a #MidoriApp
|
|
|
|
* @browser: a #MidoriBrowser
|
2008-06-07 23:25:57 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-05-22 22:17:10 +00:00
|
|
|
midori_app_add_browser (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser)
|
|
|
|
{
|
2008-08-22 01:59:07 +00:00
|
|
|
g_return_if_fail (MIDORI_IS_APP (app));
|
|
|
|
g_return_if_fail (MIDORI_IS_BROWSER (browser));
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (browser), app->accel_group);
|
2008-05-22 22:17:10 +00:00
|
|
|
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);
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
app->browsers = g_list_prepend (app->browsers, browser);
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
if (app->instance)
|
|
|
|
unique_app_watch_window (app->instance, GTK_WINDOW (browser));
|
|
|
|
#endif
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-07 23:25:57 +00:00
|
|
|
* midori_app_get_settings:
|
|
|
|
* @app: a #MidoriApp
|
2008-05-22 22:17:10 +00:00
|
|
|
*
|
2008-06-07 23:25:57 +00:00
|
|
|
* Retrieves the #MidoriWebSettings of the app.
|
2008-05-22 22:17:10 +00:00
|
|
|
*
|
2008-06-07 23:25:57 +00:00
|
|
|
* Return value: the assigned #MidoriWebSettings
|
2008-05-22 22:17:10 +00:00
|
|
|
**/
|
2008-06-07 23:25:57 +00:00
|
|
|
MidoriWebSettings*
|
|
|
|
midori_app_get_settings (MidoriApp* app)
|
2008-05-22 22:17:10 +00:00
|
|
|
{
|
2008-06-07 23:25:57 +00:00
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
return app->settings;
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-07 23:25:57 +00:00
|
|
|
* midori_app_set_settings:
|
2008-05-22 22:17:10 +00:00
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
2008-06-07 23:25:57 +00:00
|
|
|
* Assigns the #MidoriWebSettings to the app.
|
2008-05-22 22:17:10 +00:00
|
|
|
*
|
|
|
|
* Return value: the assigned #MidoriWebSettings
|
|
|
|
**/
|
2008-06-07 23:25:57 +00:00
|
|
|
void
|
|
|
|
midori_app_set_settings (MidoriApp* app,
|
|
|
|
MidoriWebSettings* settings)
|
2008-05-22 22:17:10 +00:00
|
|
|
{
|
2008-06-07 23:25:57 +00:00
|
|
|
g_return_if_fail (MIDORI_IS_APP (app));
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2008-06-07 23:25:57 +00:00
|
|
|
g_object_set (app, "settings", settings, NULL);
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* midori_app_get_trash:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
2008-06-24 19:54:01 +00:00
|
|
|
* Retrieves the trash of the app.
|
2008-05-22 22:17:10 +00:00
|
|
|
*
|
|
|
|
* Return value: the assigned #MidoriTrash
|
|
|
|
**/
|
2008-08-25 23:19:38 +00:00
|
|
|
KatzeArray*
|
2008-05-22 22:17:10 +00:00
|
|
|
midori_app_get_trash (MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
return app->trash;
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
2008-06-07 23:25:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ();
|
|
|
|
}
|