2008-05-22 22:17:10 +00:00
|
|
|
/*
|
2009-06-15 21:58:19 +00:00
|
|
|
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
|
2008-05-22 22:17:10 +00:00
|
|
|
|
|
|
|
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"
|
2009-04-12 21:37:15 +00:00
|
|
|
#include "sokoke.h"
|
2008-05-22 22:17:10 +00:00
|
|
|
|
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>
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
#include <libosso.h>
|
2009-11-27 22:42:07 +00:00
|
|
|
#ifdef HAVE_HILDON_2_2
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
#include <mce/mode-names.h>
|
|
|
|
#include <mce/dbus-names.h>
|
|
|
|
#endif
|
2009-11-10 19:18:48 +00:00
|
|
|
typedef osso_context_t* MidoriAppInstance;
|
|
|
|
#define MidoriAppInstanceNull NULL
|
|
|
|
#elif HAVE_UNIQUE
|
2009-06-15 21:58:19 +00:00
|
|
|
typedef gpointer MidoriAppInstance;
|
|
|
|
#define MidoriAppInstanceNull NULL
|
2008-08-22 01:59:07 +00:00
|
|
|
#include <unique/unique.h>
|
2009-06-16 21:31:35 +00:00
|
|
|
#define MIDORI_UNIQUE_COMMAND 1
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
typedef gint MidoriAppInstance;
|
|
|
|
#define MidoriAppInstanceNull -1
|
|
|
|
#include "socket.h"
|
2008-08-22 01:59:07 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-14 22:51:05 +00:00
|
|
|
#if HAVE_LIBNOTIFY
|
|
|
|
#include <libnotify/notify.h>
|
2009-11-10 19:18:48 +00:00
|
|
|
#endif
|
2009-05-09 13:55:10 +00:00
|
|
|
|
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
|
|
|
MidoriBrowser* browser;
|
|
|
|
GtkAccelGroup* accel_group;
|
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
gchar* name;
|
2008-05-22 22:17:10 +00:00
|
|
|
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-11-20 00:22:25 +00:00
|
|
|
KatzeArray* extensions;
|
2009-01-20 21:40:25 +00:00
|
|
|
KatzeArray* browsers;
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
MidoriAppInstance instance;
|
2009-05-09 13:55:10 +00:00
|
|
|
|
2010-01-25 20:27:07 +00:00
|
|
|
#if !HAVE_HILDON || !HAVE_LIBNOTIFY
|
2009-12-14 22:51:05 +00:00
|
|
|
gchar* program_notify_send;
|
2009-11-10 19:18:48 +00:00
|
|
|
#endif
|
2008-05-22 22:17:10 +00:00
|
|
|
};
|
|
|
|
|
2008-11-24 00:41:45 +00:00
|
|
|
struct _MidoriAppClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
|
|
|
/* Signals */
|
|
|
|
void
|
|
|
|
(*add_browser) (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser);
|
|
|
|
void
|
2009-04-22 19:58:00 +00:00
|
|
|
(*remove_browser) (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser);
|
|
|
|
void
|
2008-11-24 00:41:45 +00:00
|
|
|
(*quit) (MidoriApp* app);
|
|
|
|
};
|
|
|
|
|
2008-06-12 21:46:08 +00:00
|
|
|
G_DEFINE_TYPE (MidoriApp, midori_app, G_TYPE_OBJECT)
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
PROP_NAME,
|
2008-05-22 22:17:10 +00:00
|
|
|
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-10-07 00:19:33 +00:00
|
|
|
PROP_HISTORY,
|
2008-11-20 00:22:25 +00:00
|
|
|
PROP_EXTENSIONS,
|
2009-01-20 21:40:25 +00:00
|
|
|
PROP_BROWSERS,
|
2008-11-20 00:22:25 +00:00
|
|
|
PROP_BROWSER,
|
2008-09-03 00:28:54 +00:00
|
|
|
PROP_BROWSER_COUNT
|
2008-05-22 22:17:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ADD_BROWSER,
|
2009-04-22 19:58:00 +00:00
|
|
|
REMOVE_BROWSER,
|
2008-05-22 22:17:10 +00:00
|
|
|
QUIT,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-11-18 01:01:30 +00:00
|
|
|
static gboolean
|
|
|
|
midori_browser_focus_in_event_cb (MidoriBrowser* browser,
|
|
|
|
GdkEventFocus* event,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
app->browser = browser;
|
|
|
|
g_object_notify (G_OBJECT (app), "browser");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-30 22:43:28 +00:00
|
|
|
static MidoriBrowser*
|
2008-11-18 01:01:30 +00:00
|
|
|
midori_browser_new_window_cb (MidoriBrowser* browser,
|
2009-05-17 18:29:31 +00:00
|
|
|
MidoriBrowser* new_browser,
|
2008-11-18 01:01:30 +00:00
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2009-10-30 22:43:28 +00:00
|
|
|
if (new_browser)
|
|
|
|
g_object_set (new_browser,
|
|
|
|
"settings", app->settings,
|
|
|
|
"bookmarks", app->bookmarks,
|
|
|
|
"trash", app->trash,
|
|
|
|
"search-engines", app->search_engines,
|
|
|
|
"history", app->history,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
new_browser = midori_app_create_browser (app);
|
2008-12-24 23:39:35 +00:00
|
|
|
|
2009-05-17 18:29:31 +00:00
|
|
|
midori_app_add_browser (app, new_browser);
|
2008-11-18 01:01:30 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (new_browser));
|
2009-10-30 22:43:28 +00:00
|
|
|
|
|
|
|
return new_browser;
|
2008-11-18 01:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-04-22 19:58:00 +00:00
|
|
|
g_signal_emit (app, signals[REMOVE_BROWSER], 0, browser);
|
2009-01-20 21:40:25 +00:00
|
|
|
katze_array_remove_item (app->browsers, browser);
|
|
|
|
if (!katze_array_is_empty (app->browsers))
|
2010-02-22 17:53:00 +00:00
|
|
|
{
|
|
|
|
app->browser = katze_array_get_nth_item (app->browsers, 0);
|
2008-11-18 01:01:30 +00:00
|
|
|
return FALSE;
|
2010-02-22 17:53:00 +00:00
|
|
|
}
|
2008-11-18 01:01:30 +00:00
|
|
|
midori_app_quit (app);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_browser_quit_cb (MidoriBrowser* browser,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
midori_app_quit (app);
|
|
|
|
}
|
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
static void
|
2008-11-18 01:01:30 +00:00
|
|
|
_midori_app_add_browser (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MIDORI_IS_APP (app));
|
|
|
|
g_return_if_fail (MIDORI_IS_BROWSER (browser));
|
|
|
|
|
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (browser), app->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);
|
2009-05-09 13:55:10 +00:00
|
|
|
g_signal_connect_swapped (browser, "send-notification",
|
|
|
|
G_CALLBACK (midori_app_send_notification), app);
|
2008-11-18 01:01:30 +00:00
|
|
|
|
2009-01-20 21:40:25 +00:00
|
|
|
katze_array_add_item (app->browsers, browser);
|
2008-11-18 01:01:30 +00:00
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
app->browser = browser;
|
2008-11-18 01:01:30 +00:00
|
|
|
#if HAVE_UNIQUE
|
2010-01-06 21:30:59 +00:00
|
|
|
/* We *do not* let unique watch windows because that includes
|
|
|
|
bringing windows in the foreground, even from other workspaces.
|
2009-02-19 01:34:05 +00:00
|
|
|
if (app->instance)
|
2010-01-06 21:30:59 +00:00
|
|
|
unique_app_watch_window (app->instance, GTK_WINDOW (browser)); */
|
2008-11-18 01:01:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
static void
|
2008-12-12 09:12:33 +00:00
|
|
|
_midori_app_quit (MidoriApp* app)
|
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
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);
|
|
|
|
|
2009-04-22 19:58:00 +00:00
|
|
|
/**
|
|
|
|
* MidoriApp::remove-browser:
|
|
|
|
* @app: the object on which the signal is emitted
|
|
|
|
* @browser: a #MidoriBrowser
|
|
|
|
*
|
|
|
|
* A new browser is being added to the app.
|
|
|
|
*
|
|
|
|
* Since: 0.1.7
|
|
|
|
*/
|
|
|
|
signals[REMOVE_BROWSER] = g_signal_new (
|
|
|
|
"remove-browser",
|
|
|
|
G_TYPE_FROM_CLASS (class),
|
|
|
|
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MIDORI_TYPE_BROWSER);
|
|
|
|
|
2008-05-22 22:17:10 +00:00
|
|
|
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->finalize = midori_app_finalize;
|
|
|
|
gobject_class->set_property = midori_app_set_property;
|
|
|
|
gobject_class->get_property = midori_app_get_property;
|
|
|
|
|
2008-11-18 01:01:30 +00:00
|
|
|
class->add_browser = _midori_app_add_browser;
|
2008-12-12 09:12:33 +00:00
|
|
|
class->quit = _midori_app_quit;
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
/**
|
|
|
|
* MidoriApp:name:
|
|
|
|
*
|
|
|
|
* The name of the instance.
|
|
|
|
*
|
|
|
|
* Since: 0.1.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_NAME,
|
|
|
|
g_param_spec_string (
|
|
|
|
"name",
|
|
|
|
"Name",
|
|
|
|
"The name of the instance",
|
|
|
|
"midori",
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-05-22 22:17:10 +00:00
|
|
|
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-09-03 00:28:54 +00:00
|
|
|
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-05-22 22:17:10 +00:00
|
|
|
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-09-03 00:28:54 +00:00
|
|
|
|
2008-11-20 00:22:25 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_HISTORY,
|
|
|
|
g_param_spec_object (
|
|
|
|
"history",
|
|
|
|
"History",
|
|
|
|
"The list of history items",
|
|
|
|
KATZE_TYPE_ARRAY,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-20 00:22:25 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EXTENSIONS,
|
|
|
|
g_param_spec_object (
|
|
|
|
"extensions",
|
|
|
|
"Extensions",
|
|
|
|
"The list of extensions",
|
|
|
|
KATZE_TYPE_ARRAY,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-20 00:22:25 +00:00
|
|
|
|
2009-01-20 21:40:25 +00:00
|
|
|
/**
|
|
|
|
* MidoriApp:browsers:
|
|
|
|
*
|
|
|
|
* The list of browsers.
|
|
|
|
*
|
|
|
|
* Since: 0.1.3
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_BROWSERS,
|
|
|
|
g_param_spec_object (
|
|
|
|
"browsers",
|
|
|
|
"Browsers",
|
|
|
|
"The list of browsers",
|
|
|
|
KATZE_TYPE_ARRAY,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MidoriApp:browser:
|
|
|
|
*
|
|
|
|
* The current browser, that is the one that was last used.
|
|
|
|
*
|
|
|
|
* Since: 0.1.3
|
|
|
|
*/
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2009-01-20 21:40:25 +00:00
|
|
|
/**
|
|
|
|
* MidoriApp:browser-count:
|
|
|
|
*
|
|
|
|
* The number of browsers.
|
|
|
|
*
|
|
|
|
* Deprecated: 0.1.3 Use MidoriApp:browsers instead.
|
|
|
|
*/
|
2008-05-22 22:17:10 +00:00
|
|
|
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,
|
2009-01-16 04:19:43 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
2010-01-06 21:30:59 +00:00
|
|
|
static void
|
|
|
|
midori_app_raise_window (GtkWindow* window,
|
|
|
|
GdkScreen* screen)
|
|
|
|
{
|
|
|
|
gtk_window_set_screen (window, screen);
|
|
|
|
gtk_window_present (window);
|
|
|
|
gtk_window_deiconify (window);
|
|
|
|
}
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
static gboolean
|
|
|
|
midori_app_command_received (MidoriApp* app,
|
|
|
|
const gchar* command,
|
|
|
|
gchar** uris,
|
|
|
|
GdkScreen* screen)
|
|
|
|
{
|
2009-06-16 21:31:35 +00:00
|
|
|
if (!screen)
|
|
|
|
{
|
|
|
|
if (app->browser && gtk_widget_has_screen (GTK_WIDGET (app->browser)))
|
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (app->browser));
|
|
|
|
else
|
|
|
|
screen = gdk_screen_get_default ();
|
|
|
|
}
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
if (g_str_equal (command, "activate"))
|
|
|
|
{
|
2009-11-10 19:18:48 +00:00
|
|
|
if (!app->browser)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-01-06 21:30:59 +00:00
|
|
|
midori_app_raise_window (GTK_WINDOW (app->browser), screen);
|
2009-06-15 21:58:19 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (g_str_equal (command, "new"))
|
|
|
|
{
|
|
|
|
MidoriBrowser* browser = midori_app_create_browser (app);
|
|
|
|
midori_app_add_browser (app, browser);
|
|
|
|
/* FIXME: Should open the homepage according to settings */
|
|
|
|
midori_browser_add_uri (browser, "");
|
|
|
|
midori_browser_activate_action (browser, "Location");
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
2010-01-06 21:30:59 +00:00
|
|
|
midori_app_raise_window (GTK_WINDOW (browser), screen);
|
2009-06-15 21:58:19 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (g_str_equal (command, "open"))
|
|
|
|
{
|
2009-11-10 19:18:48 +00:00
|
|
|
if (!app->browser)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
if (!uris)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
MidoriNewPage open_external_pages_in;
|
|
|
|
gboolean first;
|
|
|
|
|
|
|
|
g_object_get (app->settings, "open-external-pages-in",
|
|
|
|
&open_external_pages_in, NULL);
|
|
|
|
if (open_external_pages_in == MIDORI_NEW_PAGE_WINDOW)
|
|
|
|
{
|
|
|
|
browser = midori_app_create_browser (app);
|
|
|
|
midori_app_add_browser (app, browser);
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
browser = app->browser;
|
2010-01-06 21:30:59 +00:00
|
|
|
|
|
|
|
midori_app_raise_window (GTK_WINDOW (browser), screen);
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
first = (open_external_pages_in == MIDORI_NEW_PAGE_CURRENT);
|
|
|
|
while (*uris)
|
|
|
|
{
|
2010-02-09 17:13:47 +00:00
|
|
|
gchar* fixed_uri = sokoke_magic_uri (*uris);
|
|
|
|
if (!fixed_uri)
|
|
|
|
fixed_uri = g_strdup (*uris);
|
2009-06-15 21:58:19 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
midori_browser_set_current_uri (browser, fixed_uri);
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
midori_browser_set_current_page (browser,
|
|
|
|
midori_browser_add_uri (browser, fixed_uri));
|
|
|
|
g_free (fixed_uri);
|
|
|
|
uris++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-06-16 21:31:35 +00:00
|
|
|
else if (g_str_equal (command, "command"))
|
|
|
|
{
|
2009-12-07 19:52:32 +00:00
|
|
|
guint i = 0;
|
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
if (!uris || !app->browser)
|
|
|
|
return FALSE;
|
2009-12-07 19:52:32 +00:00
|
|
|
while (uris[i] != NULL)
|
|
|
|
{
|
|
|
|
midori_browser_activate_action (app->browser, uris[i]);
|
|
|
|
i++;
|
|
|
|
}
|
2009-06-16 21:31:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-06-15 21:58:19 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
static osso_return_t
|
|
|
|
midori_app_osso_rpc_handler_cb (const gchar* interface,
|
|
|
|
const gchar* method,
|
|
|
|
GArray* arguments,
|
|
|
|
gpointer data,
|
|
|
|
osso_rpc_t * retval)
|
|
|
|
{
|
|
|
|
MidoriApp* app = MIDORI_APP (data);
|
|
|
|
GdkScreen* screen = NULL;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
if (!g_strcmp0 (method, "top_application"))
|
|
|
|
success = midori_app_command_received (app, "activate", NULL, screen);
|
|
|
|
else if (!g_strcmp0 (method, "new"))
|
|
|
|
success = midori_app_command_received (app, "new", NULL, screen);
|
|
|
|
else if (!g_strcmp0 (method, "open"))
|
|
|
|
{
|
|
|
|
/* FIXME: Handle arguments */
|
|
|
|
success = midori_app_command_received (app, "open", NULL, screen);
|
|
|
|
}
|
|
|
|
else if (!g_strcmp0 (method, "command"))
|
|
|
|
{
|
|
|
|
/* FIXME: Handle arguments */
|
|
|
|
success = midori_app_command_received (app, "command", NULL, screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success ? OSSO_OK : OSSO_INVALID;
|
|
|
|
}
|
|
|
|
#elif HAVE_UNIQUE
|
2008-08-22 01:59:07 +00:00
|
|
|
static UniqueResponse
|
|
|
|
midori_browser_message_received_cb (UniqueApp* instance,
|
|
|
|
UniqueCommand command,
|
|
|
|
UniqueMessageData* message,
|
2009-01-09 21:54:40 +00:00
|
|
|
guint timestamp,
|
2008-08-22 01:59:07 +00:00
|
|
|
MidoriApp* app)
|
|
|
|
{
|
2009-06-15 21:58:19 +00:00
|
|
|
gboolean success;
|
|
|
|
GdkScreen* screen = unique_message_data_get_screen (message);
|
2008-08-22 01:59:07 +00:00
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case UNIQUE_ACTIVATE:
|
2009-06-15 21:58:19 +00:00
|
|
|
success = midori_app_command_received (app, "activate", NULL, screen);
|
2008-08-22 01:59:07 +00:00
|
|
|
break;
|
2008-09-10 17:48:45 +00:00
|
|
|
case UNIQUE_NEW:
|
2009-06-15 21:58:19 +00:00
|
|
|
success = midori_app_command_received (app, "new", NULL, screen);
|
2008-09-10 17:48:45 +00:00
|
|
|
break;
|
2008-08-22 01:59:07 +00:00
|
|
|
case UNIQUE_OPEN:
|
2009-06-15 21:58:19 +00:00
|
|
|
{
|
|
|
|
gchar** uris = unique_message_data_get_uris (message);
|
|
|
|
success = midori_app_command_received (app, "open", uris, screen);
|
|
|
|
/* g_strfreev (uris); */
|
2008-08-22 01:59:07 +00:00
|
|
|
break;
|
2009-06-15 21:58:19 +00:00
|
|
|
}
|
2009-06-16 21:31:35 +00:00
|
|
|
case MIDORI_UNIQUE_COMMAND:
|
|
|
|
{
|
|
|
|
gchar** uris = unique_message_data_get_uris (message);
|
|
|
|
success = midori_app_command_received (app, "command", uris, screen);
|
|
|
|
/* g_strfreev (uris); */
|
|
|
|
break;
|
|
|
|
}
|
2008-08-22 01:59:07 +00:00
|
|
|
default:
|
2009-06-15 21:58:19 +00:00
|
|
|
success = FALSE;
|
2008-08-22 01:59:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
return success ? UNIQUE_RESPONSE_OK : UNIQUE_RESPONSE_FAIL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static gboolean
|
|
|
|
midori_app_io_channel_watch_cb (GIOChannel* channel,
|
|
|
|
GIOCondition condition,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (app->browser));
|
|
|
|
gint fd, sock;
|
|
|
|
gchar buf[4096];
|
|
|
|
struct sockaddr_in caddr;
|
|
|
|
guint caddr_len = sizeof(caddr);
|
|
|
|
|
|
|
|
fd = app->instance;
|
|
|
|
sock = accept (fd, (struct sockaddr *)&caddr, &caddr_len);
|
|
|
|
|
|
|
|
while (fd_gets (sock, buf, sizeof (buf)) != -1)
|
|
|
|
{
|
|
|
|
if (strncmp (buf, "activate", 8) == 0)
|
|
|
|
{
|
|
|
|
midori_app_command_received (app, "open", NULL, screen);
|
|
|
|
}
|
|
|
|
else if (strncmp (buf, "new", 3) == 0)
|
|
|
|
{
|
|
|
|
midori_app_command_received (app, "new", NULL, screen);
|
|
|
|
}
|
|
|
|
else if (strncmp (buf, "open", 4) == 0)
|
|
|
|
{
|
|
|
|
while (fd_gets (sock, buf, sizeof (buf)) != -1 && *buf != '.')
|
|
|
|
{
|
|
|
|
gchar** uris = g_strsplit (g_strstrip (buf), "\n", 2);
|
|
|
|
midori_app_command_received (app, "open", uris, screen);
|
|
|
|
g_strfreev (uris);
|
|
|
|
}
|
|
|
|
}
|
2009-06-16 21:31:35 +00:00
|
|
|
else if (strncmp (buf, "command", 7) == 0)
|
|
|
|
{
|
|
|
|
guint i = 0;
|
2009-07-10 15:20:56 +00:00
|
|
|
gchar** uris = g_new (gchar*, 100);
|
2009-06-16 21:31:35 +00:00
|
|
|
while (fd_gets (sock, buf, sizeof (buf)) != -1 && *buf != '.')
|
|
|
|
{
|
|
|
|
uris[i++] = g_strdup (g_strstrip (buf));
|
|
|
|
if (i == 99)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uris[i] = NULL;
|
|
|
|
midori_app_command_received (app, "command", uris, screen);
|
|
|
|
g_strfreev (uris);
|
|
|
|
}
|
2009-06-15 21:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fd_close (sock);
|
|
|
|
|
|
|
|
return TRUE;
|
2008-08-22 01:59:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
static MidoriAppInstance
|
2009-04-09 18:26:06 +00:00
|
|
|
midori_app_create_instance (MidoriApp* app,
|
|
|
|
const gchar* name)
|
2008-05-22 22:17:10 +00:00
|
|
|
{
|
2009-06-15 21:58:19 +00:00
|
|
|
MidoriAppInstance instance;
|
2009-11-10 19:18:48 +00:00
|
|
|
|
|
|
|
#if HAVE_HILDON
|
|
|
|
instance = osso_initialize (PACKAGE_NAME, PACKAGE_VERSION, FALSE, NULL);
|
|
|
|
|
|
|
|
if (!instance)
|
|
|
|
{
|
|
|
|
g_critical ("Error initializing OSSO D-Bus context - Midori");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osso_rpc_set_default_cb_f (instance, midori_app_osso_rpc_handler_cb,
|
|
|
|
app) != OSSO_OK)
|
|
|
|
{
|
|
|
|
g_critical ("Error initializing remote procedure call handler - Midori");
|
|
|
|
osso_deinitialize (instance);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-11-27 22:42:07 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_HILDON_2_2
|
|
|
|
if (OSSO_OK == osso_rpc_run_system (instance, MCE_SERVICE, MCE_REQUEST_PATH,
|
|
|
|
MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ, NULL, DBUS_TYPE_INVALID))
|
|
|
|
/* Accelerometer enabled */;
|
|
|
|
#endif
|
2009-11-10 19:18:48 +00:00
|
|
|
#else
|
2009-02-19 01:34:05 +00:00
|
|
|
GdkDisplay* display;
|
2008-08-22 01:59:07 +00:00
|
|
|
gchar* display_name;
|
|
|
|
gchar* instance_name;
|
|
|
|
guint i, n;
|
2009-06-15 21:58:19 +00:00
|
|
|
#if !HAVE_UNIQUE
|
|
|
|
gboolean exists;
|
|
|
|
GIOChannel* channel;
|
2008-08-22 01:59:07 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
if (!name)
|
|
|
|
name = "midori";
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2009-02-19 01:34:05 +00:00
|
|
|
if (!(display = gdk_display_get_default ()))
|
2009-06-15 21:58:19 +00:00
|
|
|
return MidoriAppInstanceNull;
|
2009-02-19 01:34:05 +00:00
|
|
|
|
|
|
|
display_name = g_strdup (gdk_display_get_name (display));
|
2008-08-22 01:59:07 +00:00
|
|
|
n = strlen (display_name);
|
|
|
|
for (i = 0; i < n; i++)
|
2009-11-19 21:55:21 +00:00
|
|
|
if (display_name[i] == ':' || display_name[i] == '.'
|
|
|
|
|| display_name[i] == '\\')
|
2008-08-22 01:59:07 +00:00
|
|
|
display_name[i] = '_';
|
2009-04-09 18:26:06 +00:00
|
|
|
instance_name = g_strdup_printf ("de.twotoasts.%s_%s", name, display_name);
|
2009-06-15 21:58:19 +00:00
|
|
|
|
|
|
|
#if HAVE_UNIQUE
|
2009-04-09 18:26:06 +00:00
|
|
|
instance = unique_app_new (instance_name, NULL);
|
2009-06-16 21:31:35 +00:00
|
|
|
unique_app_add_command (instance, "midori-command", MIDORI_UNIQUE_COMMAND);
|
2009-04-09 18:26:06 +00:00
|
|
|
g_signal_connect (instance, "message-received",
|
2008-08-22 01:59:07 +00:00
|
|
|
G_CALLBACK (midori_browser_message_received_cb), app);
|
|
|
|
#else
|
2009-06-15 21:58:19 +00:00
|
|
|
instance = socket_init (instance_name, sokoke_set_config_dir (NULL), &exists);
|
|
|
|
g_object_set_data (G_OBJECT (app), "sock-exists",
|
|
|
|
exists ? (gpointer)0xdeadbeef : NULL);
|
2009-11-19 22:34:13 +00:00
|
|
|
if (instance != MidoriAppInstanceNull)
|
|
|
|
{
|
|
|
|
channel = g_io_channel_unix_new (instance);
|
|
|
|
g_io_add_watch (channel, G_IO_IN | G_IO_PRI | G_IO_ERR,
|
|
|
|
(GIOFunc)midori_app_io_channel_watch_cb, app);
|
|
|
|
}
|
2008-08-22 01:59:07 +00:00
|
|
|
#endif
|
2009-06-15 21:58:19 +00:00
|
|
|
|
|
|
|
g_free (instance_name);
|
|
|
|
g_free (display_name);
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#endif
|
2009-06-15 21:58:19 +00:00
|
|
|
return instance;
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
static void
|
|
|
|
midori_app_init (MidoriApp* app)
|
|
|
|
{
|
|
|
|
app->accel_group = gtk_accel_group_new ();
|
|
|
|
|
|
|
|
app->settings = NULL;
|
|
|
|
app->bookmarks = NULL;
|
|
|
|
app->trash = NULL;
|
|
|
|
app->search_engines = NULL;
|
|
|
|
app->history = NULL;
|
|
|
|
app->extensions = NULL;
|
|
|
|
app->browsers = katze_array_new (MIDORI_TYPE_BROWSER);
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
app->instance = MidoriAppInstanceNull;
|
2009-05-09 13:55:10 +00:00
|
|
|
|
2009-12-14 22:51:05 +00:00
|
|
|
#if HAVE_LIBNOTIFY
|
|
|
|
notify_init ("midori");
|
2010-01-25 20:27:07 +00:00
|
|
|
#else
|
|
|
|
app->program_notify_send = g_find_program_in_path ("notify-send");
|
2009-12-14 22:51:05 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
}
|
|
|
|
|
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_object_unref (app->accel_group);
|
2008-05-22 22:17:10 +00:00
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
katze_assign (app->name, NULL);
|
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);
|
2008-11-20 00:22:25 +00:00
|
|
|
katze_object_assign (app->extensions, NULL);
|
2009-01-20 21:40:25 +00:00
|
|
|
katze_object_assign (app->browsers, NULL);
|
2008-10-30 01:21:19 +00:00
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
osso_deinitialize (app->instance);
|
|
|
|
app->instance = NULL;
|
|
|
|
#elif HAVE_UNIQUE
|
2008-10-30 01:21:19 +00:00
|
|
|
katze_object_assign (app->instance, NULL);
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
sock_cleanup ();
|
|
|
|
#endif
|
2008-08-22 01:59:07 +00:00
|
|
|
|
2009-12-14 22:51:05 +00:00
|
|
|
#if HAVE_LIBNOTIFY
|
|
|
|
if (notify_is_initted ())
|
|
|
|
notify_uninit ();
|
2010-01-25 20:27:07 +00:00
|
|
|
#else
|
|
|
|
katze_assign (app->program_notify_send, NULL);
|
2009-11-10 19:18:48 +00:00
|
|
|
#endif
|
2009-05-09 13:55:10 +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)
|
|
|
|
{
|
2009-04-09 18:26:06 +00:00
|
|
|
case PROP_NAME:
|
|
|
|
katze_assign (app->name, g_value_dup_string (value));
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
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-11-20 00:22:25 +00:00
|
|
|
case PROP_EXTENSIONS:
|
|
|
|
katze_object_assign (app->extensions, g_value_dup_object (value));
|
|
|
|
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)
|
|
|
|
{
|
2009-04-09 18:26:06 +00:00
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, app->name);
|
|
|
|
break;
|
2008-05-22 22:17:10 +00:00
|
|
|
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-11-20 00:22:25 +00:00
|
|
|
case PROP_EXTENSIONS:
|
|
|
|
g_value_set_object (value, app->extensions);
|
|
|
|
break;
|
2009-01-20 21:40:25 +00:00
|
|
|
case PROP_BROWSERS:
|
|
|
|
g_value_set_object (value, app->browsers);
|
|
|
|
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:
|
2009-01-20 21:40:25 +00:00
|
|
|
g_value_set_uint (value, katze_array_get_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-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.
|
|
|
|
*
|
2009-04-09 18:26:06 +00:00
|
|
|
* Use the "name" property if you want to run more
|
|
|
|
* than one instance.
|
|
|
|
*
|
2008-08-22 01:59:07 +00:00
|
|
|
* 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);
|
|
|
|
|
2009-06-15 21:58:19 +00:00
|
|
|
if (app->instance == MidoriAppInstanceNull)
|
2009-04-09 18:26:06 +00:00
|
|
|
app->instance = midori_app_create_instance (app, app->name);
|
2009-11-10 19:18:48 +00:00
|
|
|
|
|
|
|
#if HAVE_HILDON
|
|
|
|
/* FIXME: Determine if application is running already */
|
|
|
|
if (app->instance)
|
|
|
|
return FALSE;
|
|
|
|
#elif HAVE_UNIQUE
|
2009-02-19 01:34:05 +00:00
|
|
|
if (app->instance)
|
|
|
|
return unique_app_is_running (app->instance);
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
return g_object_get_data (G_OBJECT (app), "sock-exists") != NULL;
|
2008-08-22 01:59:07 +00:00
|
|
|
#endif
|
2009-02-19 01:34:05 +00:00
|
|
|
return FALSE;
|
2008-08-22 01:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
2008-12-30 02:00:08 +00:00
|
|
|
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
|
2008-08-22 01:59:07 +00:00
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
osso_application_top (app->instance, PACKAGE_NAME, NULL);
|
|
|
|
#elif HAVE_UNIQUE
|
2009-02-19 01:34:05 +00:00
|
|
|
if (app->instance)
|
|
|
|
{
|
|
|
|
response = unique_app_send_message (app->instance, UNIQUE_ACTIVATE, NULL);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
if (app->instance > -1)
|
|
|
|
{
|
|
|
|
send_open_command (app->instance, "activate", NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-22 01:59:07 +00:00
|
|
|
#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
|
|
|
|
|
2008-12-30 02:00:08 +00:00
|
|
|
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
|
2008-09-10 17:48:45 +00:00
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
osso_application_top (app->instance, PACKAGE_NAME, "new");
|
|
|
|
#elif HAVE_UNIQUE
|
2009-02-19 01:34:05 +00:00
|
|
|
if (app->instance)
|
|
|
|
{
|
|
|
|
response = unique_app_send_message (app->instance, UNIQUE_NEW, NULL);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
if (app->instance > -1)
|
|
|
|
{
|
|
|
|
send_open_command (app->instance, "new", NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-10 17:48:45 +00:00
|
|
|
#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
|
|
|
|
|
2008-12-30 02:00:08 +00:00
|
|
|
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
|
2008-08-22 01:59:07 +00:00
|
|
|
g_return_val_if_fail (midori_app_instance_is_running (app), FALSE);
|
|
|
|
g_return_val_if_fail (uris != NULL, FALSE);
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
/* FIXME: Implement */
|
|
|
|
#elif HAVE_UNIQUE
|
2009-02-19 01:34:05 +00:00
|
|
|
if (app->instance)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2009-06-15 21:58:19 +00:00
|
|
|
#else
|
|
|
|
if (app->instance > -1)
|
|
|
|
{
|
|
|
|
send_open_command (app->instance, "open", uris);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-22 01:59:07 +00:00
|
|
|
#endif
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
/**
|
|
|
|
* midori_app_send_command:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
* @command: a string vector of a command to execute
|
|
|
|
*
|
|
|
|
* Sends a command to an instance of Midori, which
|
|
|
|
* is either the current process or an already running
|
|
|
|
* instance with the same name on the default display.
|
|
|
|
*
|
|
|
|
* Names of GtkAction objects of MidoriBrowser are recognized as commands.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the message was sent successfully
|
|
|
|
*
|
|
|
|
* Since: 0.1.8
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
midori_app_send_command (MidoriApp* app,
|
|
|
|
gchar** command)
|
|
|
|
{
|
|
|
|
#if HAVE_UNIQUE
|
|
|
|
UniqueMessageData* message;
|
|
|
|
UniqueResponse response;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* g_return_val_if_fail (MIDORI_IS_APP (app), FALSE); */
|
|
|
|
g_return_val_if_fail (command != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!midori_app_instance_is_running (app))
|
|
|
|
return midori_app_command_received (app, "command", command, NULL);
|
|
|
|
|
2009-11-10 19:18:48 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
/* FIXME: Implement */
|
|
|
|
#elif HAVE_UNIQUE
|
2009-06-16 21:31:35 +00:00
|
|
|
if (app->instance)
|
|
|
|
{
|
|
|
|
message = unique_message_data_new ();
|
|
|
|
unique_message_data_set_uris (message, command);
|
|
|
|
response = unique_app_send_message (app->instance,
|
|
|
|
MIDORI_UNIQUE_COMMAND, message);
|
|
|
|
unique_message_data_free (message);
|
|
|
|
if (response == UNIQUE_RESPONSE_OK)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (app->instance > -1)
|
|
|
|
{
|
|
|
|
send_open_command (app->instance, "command", command);
|
|
|
|
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
|
|
|
*
|
2008-12-24 23:39:35 +00:00
|
|
|
* Adds a #MidoriBrowser to the #MidoriApp.
|
2008-06-07 23:25:57 +00:00
|
|
|
*
|
|
|
|
* 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-11-18 01:01:30 +00:00
|
|
|
g_signal_emit (app, signals[ADD_BROWSER], 0, browser);
|
2008-05-22 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
2008-12-24 23:39:35 +00:00
|
|
|
/**
|
|
|
|
* midori_app_create_browser:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
|
|
|
* Creates a #MidoriBrowser which inherits its settings,
|
|
|
|
* bookmarks, trash, search engines and history from @app.
|
|
|
|
*
|
2009-10-30 22:43:28 +00:00
|
|
|
* Note that creating a browser this way can be a lot
|
|
|
|
* faster than setting it up manually.
|
|
|
|
*
|
2008-12-24 23:39:35 +00:00
|
|
|
* Return value: a new #MidoriBrowser
|
|
|
|
*
|
2009-04-22 19:58:00 +00:00
|
|
|
* Since: 0.1.2
|
2008-12-24 23:39:35 +00:00
|
|
|
**/
|
|
|
|
MidoriBrowser*
|
|
|
|
midori_app_create_browser (MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
|
|
|
|
|
|
|
|
return g_object_new (MIDORI_TYPE_BROWSER,
|
|
|
|
"settings", app->settings,
|
|
|
|
"bookmarks", app->bookmarks,
|
|
|
|
"trash", app->trash,
|
|
|
|
"search-engines", app->search_engines,
|
|
|
|
"history", app->history,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2008-06-07 23:25:57 +00:00
|
|
|
/**
|
|
|
|
* midori_app_quit:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
*
|
|
|
|
* Quits the #MidoriApp singleton.
|
2008-12-12 09:12:33 +00:00
|
|
|
*
|
|
|
|
* Since 0.1.2 the "quit" signal is always emitted before quitting.
|
2008-06-07 23:25:57 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_app_quit (MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MIDORI_IS_APP (app));
|
|
|
|
|
2008-12-12 09:12:33 +00:00
|
|
|
g_signal_emit (app, signals[QUIT], 0);
|
2008-06-07 23:25:57 +00:00
|
|
|
}
|
2009-05-09 13:55:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* midori_app_send_notification:
|
|
|
|
* @app: a #MidoriApp
|
|
|
|
* @title: title of the notification
|
|
|
|
* @message: text of the notification, or NULL
|
|
|
|
*
|
2009-10-26 17:05:16 +00:00
|
|
|
* Send #message to a notification service to display it.
|
2009-05-09 13:55:10 +00:00
|
|
|
*
|
2009-10-26 17:05:16 +00:00
|
|
|
* There is no guarantee that the message has been sent and displayed, as
|
|
|
|
* there might not be any notification service available.
|
2009-05-09 13:55:10 +00:00
|
|
|
*
|
|
|
|
* Since 0.1.7
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
midori_app_send_notification (MidoriApp* app,
|
|
|
|
const gchar* title,
|
|
|
|
const gchar* message)
|
|
|
|
{
|
2009-12-14 22:51:05 +00:00
|
|
|
g_return_if_fail (MIDORI_IS_APP (app));
|
|
|
|
g_return_if_fail (title);
|
|
|
|
|
2009-10-26 17:05:16 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
hildon_banner_show_information_with_markup (GTK_WIDGET (app->browser),
|
|
|
|
"midori", message);
|
|
|
|
#else
|
2009-05-09 13:55:10 +00:00
|
|
|
gboolean sent = FALSE;
|
|
|
|
|
2009-12-14 22:51:05 +00:00
|
|
|
#if HAVE_LIBNOTIFY
|
|
|
|
if (notify_is_initted ())
|
2009-05-09 13:55:10 +00:00
|
|
|
{
|
2009-12-14 22:51:05 +00:00
|
|
|
NotifyNotification* note;
|
2009-05-09 13:55:10 +00:00
|
|
|
|
2009-12-14 22:51:05 +00:00
|
|
|
note = notify_notification_new (title, message, "midori", NULL);
|
|
|
|
sent = notify_notification_show (note, NULL);
|
|
|
|
g_object_unref (note);
|
2009-05-09 13:55:10 +00:00
|
|
|
}
|
2010-01-25 20:27:07 +00:00
|
|
|
#else
|
2009-05-09 13:55:10 +00:00
|
|
|
/* Fall back to the command line program "notify-send" */
|
|
|
|
if (!sent && app->program_notify_send)
|
|
|
|
{
|
|
|
|
gchar* msgq = g_shell_quote (message);
|
|
|
|
gchar* titleq = g_shell_quote (title);
|
|
|
|
gchar* command = g_strdup_printf ("%s -i midori %s %s",
|
|
|
|
app->program_notify_send, titleq, msgq);
|
|
|
|
|
|
|
|
g_spawn_command_line_async (command, NULL);
|
|
|
|
|
|
|
|
g_free (titleq);
|
|
|
|
g_free (msgq);
|
|
|
|
g_free (command);
|
|
|
|
}
|
2009-10-26 17:05:16 +00:00
|
|
|
#endif
|
2010-01-25 20:27:07 +00:00
|
|
|
#endif
|
2009-05-09 13:55:10 +00:00
|
|
|
}
|