2007-12-16 22:20:24 +00:00
|
|
|
/*
|
2009-03-16 01:13:35 +00:00
|
|
|
Copyright (C) 2007-2009 Christian Dywan <christian@twotoasts.de>
|
2008-10-07 00:19:33 +00:00
|
|
|
Copyright (C) 2008 Dale Whittaker <dayul@users.sf.net>
|
2007-12-16 22:20:24 +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-15 00:03:55 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-31 16:09:04 +00:00
|
|
|
#include "midori.h"
|
2008-11-20 02:49:57 +00:00
|
|
|
#include "midori-addons.h"
|
2009-03-31 16:09:04 +00:00
|
|
|
#include "midori-array.h"
|
2009-01-31 03:09:35 +00:00
|
|
|
#include "midori-bookmarks.h"
|
2008-11-20 02:49:57 +00:00
|
|
|
#include "midori-console.h"
|
2008-12-04 00:45:32 +00:00
|
|
|
#include "midori-extensions.h"
|
2009-02-21 22:59:02 +00:00
|
|
|
#include "midori-history.h"
|
2009-01-18 19:34:50 +00:00
|
|
|
#include "midori-plugins.h"
|
2009-03-22 14:25:57 +00:00
|
|
|
#include "midori-transfers.h"
|
2008-11-20 02:49:57 +00:00
|
|
|
|
2008-09-03 00:39:25 +00:00
|
|
|
#include "sokoke.h"
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2009-02-12 22:52:14 +00:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2009-11-18 18:13:07 +00:00
|
|
|
|
2009-05-04 00:09:46 +00:00
|
|
|
#include <errno.h>
|
2009-03-31 16:09:04 +00:00
|
|
|
#include <stdlib.h>
|
2007-12-16 22:20:24 +00:00
|
|
|
#include <string.h>
|
2008-12-12 09:20:19 +00:00
|
|
|
#include <glib/gstdio.h>
|
2009-03-16 01:13:35 +00:00
|
|
|
#include <webkit/webkit.h>
|
2008-11-18 21:26:06 +00:00
|
|
|
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-10-13 15:50:07 +00:00
|
|
|
#include <sqlite3.h>
|
|
|
|
#endif
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if ENABLE_NLS
|
2008-05-22 22:17:10 +00:00
|
|
|
#include <libintl.h>
|
2009-01-22 12:12:05 +00:00
|
|
|
#include <locale.h>
|
2008-03-22 02:38:23 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-31 03:46:23 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 22:50:59 +00:00
|
|
|
#if HAVE_HILDON
|
|
|
|
#define BOOKMARK_FILE "/home/user/.bookmarks/MyBookmarks.xml"
|
|
|
|
#else
|
|
|
|
#define BOOKMARK_FILE "bookmarks.xbel"
|
|
|
|
#endif
|
|
|
|
|
2008-10-07 00:19:33 +00:00
|
|
|
#define MIDORI_HISTORY_ERROR g_quark_from_string("MIDORI_HISTORY_ERROR")
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MIDORI_HISTORY_ERROR_DB_OPEN, /* Error opening the database file */
|
|
|
|
MIDORI_HISTORY_ERROR_EXEC_SQL, /* Error executing SQL statement */
|
|
|
|
|
|
|
|
} MidoriHistoryError;
|
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
static gchar*
|
|
|
|
build_config_filename (const gchar* filename)
|
|
|
|
{
|
2009-11-29 22:50:59 +00:00
|
|
|
const gchar* path;
|
|
|
|
|
|
|
|
if (g_path_is_absolute (filename))
|
|
|
|
return g_strdup (filename);
|
|
|
|
path = sokoke_set_config_dir (NULL);
|
2008-12-12 09:20:19 +00:00
|
|
|
return g_build_filename (path, filename, NULL);
|
|
|
|
}
|
|
|
|
|
2008-04-13 19:51:43 +00:00
|
|
|
static MidoriWebSettings*
|
2009-04-21 01:46:11 +00:00
|
|
|
settings_new_from_file (const gchar* filename,
|
|
|
|
gchar*** extensions)
|
2008-04-13 19:51:43 +00:00
|
|
|
{
|
|
|
|
MidoriWebSettings* settings = midori_web_settings_new ();
|
|
|
|
GKeyFile* key_file = g_key_file_new ();
|
|
|
|
GError* error = NULL;
|
2008-06-14 00:23:33 +00:00
|
|
|
GObjectClass* class;
|
|
|
|
guint i, n_properties;
|
|
|
|
GParamSpec** pspecs;
|
|
|
|
GParamSpec* pspec;
|
|
|
|
GType type;
|
|
|
|
const gchar* property;
|
2009-01-09 21:54:40 +00:00
|
|
|
gchar* str;
|
2008-06-14 00:23:33 +00:00
|
|
|
gint integer;
|
|
|
|
gfloat number;
|
|
|
|
gboolean boolean;
|
|
|
|
|
2008-04-13 19:51:43 +00:00
|
|
|
if (!g_key_file_load_from_file (key_file, filename,
|
|
|
|
G_KEY_FILE_KEEP_COMMENTS, &error))
|
|
|
|
{
|
2009-08-27 21:32:13 +00:00
|
|
|
if (error->code == G_FILE_ERROR_NOENT)
|
|
|
|
{
|
2009-10-02 21:07:36 +00:00
|
|
|
gchar* config_file = sokoke_find_config_filename (NULL, "config");
|
2009-08-27 21:32:13 +00:00
|
|
|
g_key_file_load_from_file (key_file, config_file,
|
|
|
|
G_KEY_FILE_KEEP_COMMENTS, NULL);
|
|
|
|
}
|
|
|
|
else
|
2008-11-02 23:17:43 +00:00
|
|
|
printf (_("The configuration couldn't be loaded: %s\n"),
|
2008-04-13 19:51:43 +00:00
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2008-06-14 00:23:33 +00:00
|
|
|
class = G_OBJECT_GET_CLASS (settings);
|
|
|
|
pspecs = g_object_class_list_properties (class, &n_properties);
|
2008-04-13 19:51:43 +00:00
|
|
|
for (i = 0; i < n_properties; i++)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
pspec = pspecs[i];
|
2008-04-13 19:51:43 +00:00
|
|
|
if (!(pspec->flags & G_PARAM_WRITABLE))
|
|
|
|
continue;
|
2008-06-14 00:23:33 +00:00
|
|
|
type = G_PARAM_SPEC_TYPE (pspec);
|
|
|
|
property = g_param_spec_get_name (pspec);
|
2008-04-13 19:51:43 +00:00
|
|
|
if (type == G_TYPE_PARAM_STRING)
|
|
|
|
{
|
2009-01-09 21:54:40 +00:00
|
|
|
str = sokoke_key_file_get_string_default (key_file,
|
2008-04-13 19:51:43 +00:00
|
|
|
"settings", property,
|
|
|
|
G_PARAM_SPEC_STRING (pspec)->default_value, NULL);
|
2009-01-09 21:54:40 +00:00
|
|
|
g_object_set (settings, property, str, NULL);
|
|
|
|
g_free (str);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_INT)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
integer = sokoke_key_file_get_integer_default (key_file,
|
2008-04-13 19:51:43 +00:00
|
|
|
"settings", property,
|
|
|
|
G_PARAM_SPEC_INT (pspec)->default_value, NULL);
|
|
|
|
g_object_set (settings, property, integer, NULL);
|
|
|
|
}
|
2008-06-01 09:26:10 +00:00
|
|
|
else if (type == G_TYPE_PARAM_FLOAT)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
number = sokoke_key_file_get_double_default (key_file,
|
2008-06-01 09:26:10 +00:00
|
|
|
"settings", property,
|
|
|
|
G_PARAM_SPEC_FLOAT (pspec)->default_value, NULL);
|
|
|
|
g_object_set (settings, property, number, NULL);
|
|
|
|
}
|
2008-04-13 19:51:43 +00:00
|
|
|
else if (type == G_TYPE_PARAM_BOOLEAN)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
boolean = sokoke_key_file_get_boolean_default (key_file,
|
2008-04-13 19:51:43 +00:00
|
|
|
"settings", property,
|
|
|
|
G_PARAM_SPEC_BOOLEAN (pspec)->default_value, NULL);
|
|
|
|
g_object_set (settings, property, boolean, NULL);
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_ENUM)
|
|
|
|
{
|
|
|
|
GEnumClass* enum_class = G_ENUM_CLASS (
|
|
|
|
g_type_class_ref (pspec->value_type));
|
|
|
|
GEnumValue* enum_value = g_enum_get_value (enum_class,
|
|
|
|
G_PARAM_SPEC_ENUM (pspec)->default_value);
|
2009-01-09 21:54:40 +00:00
|
|
|
str = sokoke_key_file_get_string_default (key_file,
|
2008-04-13 19:51:43 +00:00
|
|
|
"settings", property,
|
|
|
|
enum_value->value_name, NULL);
|
2009-01-09 21:54:40 +00:00
|
|
|
enum_value = g_enum_get_value_by_name (enum_class, str);
|
2008-04-20 16:28:55 +00:00
|
|
|
if (enum_value)
|
2009-02-17 17:34:27 +00:00
|
|
|
g_object_set (settings, property, enum_value->value, NULL);
|
|
|
|
else
|
|
|
|
g_warning (_("Value '%s' is invalid for %s"),
|
|
|
|
str, property);
|
2008-04-20 16:28:55 +00:00
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
g_free (str);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_type_class_unref (enum_class);
|
|
|
|
}
|
|
|
|
else
|
2008-11-10 00:08:38 +00:00
|
|
|
g_warning (_("Invalid configuration value '%s'"), property);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
2009-04-05 21:46:15 +00:00
|
|
|
g_free (pspecs);
|
2009-04-21 01:46:11 +00:00
|
|
|
|
|
|
|
*extensions = g_key_file_get_keys (key_file, "extensions", NULL, NULL);
|
|
|
|
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
|
2008-04-13 19:51:43 +00:00
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
settings_save_to_file (MidoriWebSettings* settings,
|
2009-04-21 01:46:11 +00:00
|
|
|
MidoriApp* app,
|
2008-04-13 19:51:43 +00:00
|
|
|
const gchar* filename,
|
|
|
|
GError** error)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
GKeyFile* key_file;
|
|
|
|
GObjectClass* class;
|
2008-04-13 19:51:43 +00:00
|
|
|
guint i, n_properties;
|
2008-06-14 00:23:33 +00:00
|
|
|
GParamSpec** pspecs;
|
|
|
|
GParamSpec* pspec;
|
|
|
|
GType type;
|
|
|
|
const gchar* property;
|
2008-11-10 00:08:38 +00:00
|
|
|
gboolean saved;
|
2009-04-21 01:46:11 +00:00
|
|
|
KatzeArray* extensions = katze_object_get_object (app, "extensions");
|
|
|
|
MidoriExtension* extension;
|
2009-08-23 22:26:26 +00:00
|
|
|
gchar** _extensions;
|
2008-06-14 00:23:33 +00:00
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
|
|
|
class = G_OBJECT_GET_CLASS (settings);
|
|
|
|
pspecs = g_object_class_list_properties (class, &n_properties);
|
2008-04-13 19:51:43 +00:00
|
|
|
for (i = 0; i < n_properties; i++)
|
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
pspec = pspecs[i];
|
|
|
|
type = G_PARAM_SPEC_TYPE (pspec);
|
|
|
|
property = g_param_spec_get_name (pspec);
|
2008-04-13 19:51:43 +00:00
|
|
|
if (!(pspec->flags & G_PARAM_WRITABLE))
|
|
|
|
continue;
|
|
|
|
if (type == G_TYPE_PARAM_STRING)
|
|
|
|
{
|
2009-04-05 21:46:15 +00:00
|
|
|
gchar* string;
|
2009-12-09 19:34:54 +00:00
|
|
|
const gchar* def_string = G_PARAM_SPEC_STRING (pspec)->default_value;
|
2008-04-13 19:51:43 +00:00
|
|
|
g_object_get (settings, property, &string, NULL);
|
2009-12-09 19:34:54 +00:00
|
|
|
if (!string)
|
|
|
|
string = g_strdup ("");
|
|
|
|
if (!def_string)
|
|
|
|
def_string = "";
|
|
|
|
if (strcmp (string, def_string))
|
|
|
|
g_key_file_set_string (key_file, "settings", property, string);
|
2009-04-05 21:46:15 +00:00
|
|
|
g_free (string);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_INT)
|
|
|
|
{
|
|
|
|
gint integer;
|
|
|
|
g_object_get (settings, property, &integer, NULL);
|
2009-12-09 19:34:54 +00:00
|
|
|
if (integer != G_PARAM_SPEC_INT (pspec)->default_value)
|
|
|
|
g_key_file_set_integer (key_file, "settings", property, integer);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
2008-06-01 09:26:10 +00:00
|
|
|
else if (type == G_TYPE_PARAM_FLOAT)
|
|
|
|
{
|
2008-06-08 16:42:39 +00:00
|
|
|
gfloat number;
|
2008-06-01 09:26:10 +00:00
|
|
|
g_object_get (settings, property, &number, NULL);
|
2009-12-09 19:34:54 +00:00
|
|
|
if (number != G_PARAM_SPEC_FLOAT (pspec)->default_value)
|
|
|
|
g_key_file_set_double (key_file, "settings", property, number);
|
2008-06-01 09:26:10 +00:00
|
|
|
}
|
2008-04-13 19:51:43 +00:00
|
|
|
else if (type == G_TYPE_PARAM_BOOLEAN)
|
|
|
|
{
|
2009-06-17 21:39:50 +00:00
|
|
|
gboolean truth;
|
|
|
|
g_object_get (settings, property, &truth, NULL);
|
2009-12-09 19:34:54 +00:00
|
|
|
if (truth != G_PARAM_SPEC_BOOLEAN (pspec)->default_value)
|
|
|
|
g_key_file_set_boolean (key_file, "settings", property, truth);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_ENUM)
|
|
|
|
{
|
|
|
|
GEnumClass* enum_class = G_ENUM_CLASS (
|
|
|
|
g_type_class_ref (pspec->value_type));
|
|
|
|
gint integer;
|
2009-12-09 19:34:54 +00:00
|
|
|
GEnumValue* enum_value;
|
2008-04-13 19:51:43 +00:00
|
|
|
g_object_get (settings, property, &integer, NULL);
|
2009-12-09 19:34:54 +00:00
|
|
|
enum_value = g_enum_get_value (enum_class, integer);
|
|
|
|
if (integer != G_PARAM_SPEC_ENUM (pspec)->default_value)
|
|
|
|
g_key_file_set_string (key_file, "settings", property,
|
|
|
|
enum_value->value_name);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
|
|
|
else
|
2008-11-10 00:08:38 +00:00
|
|
|
g_warning (_("Invalid configuration value '%s'"), property);
|
2008-04-13 19:51:43 +00:00
|
|
|
}
|
2009-04-05 21:46:15 +00:00
|
|
|
g_free (pspecs);
|
2009-04-21 01:46:11 +00:00
|
|
|
|
2009-08-23 22:26:26 +00:00
|
|
|
if (extensions)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
while ((extension = katze_array_get_nth_item (extensions, i++)))
|
|
|
|
if (midori_extension_is_active (extension))
|
|
|
|
g_key_file_set_boolean (key_file, "extensions",
|
|
|
|
g_object_get_data (G_OBJECT (extension), "filename"), TRUE);
|
|
|
|
g_object_unref (extensions);
|
|
|
|
}
|
|
|
|
else if ((_extensions = g_object_get_data (G_OBJECT (app), "extensions")))
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
while (_extensions[i])
|
|
|
|
{
|
|
|
|
g_key_file_set_boolean (key_file, "extensions", _extensions[i], TRUE);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-21 01:46:11 +00:00
|
|
|
|
2008-11-10 00:08:38 +00:00
|
|
|
saved = sokoke_key_file_save_to_file (key_file, filename, error);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_key_file_free (key_file);
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2008-08-25 23:19:38 +00:00
|
|
|
static KatzeArray*
|
2008-06-14 00:23:33 +00:00
|
|
|
search_engines_new_from_file (const gchar* filename,
|
|
|
|
GError** error)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-08-25 23:19:38 +00:00
|
|
|
KatzeArray* search_engines;
|
2008-06-14 00:23:33 +00:00
|
|
|
GKeyFile* key_file;
|
|
|
|
gchar** engines;
|
|
|
|
guint i, j, n_properties;
|
2008-08-23 16:32:53 +00:00
|
|
|
KatzeItem* item;
|
2008-06-14 00:23:33 +00:00
|
|
|
GParamSpec** pspecs;
|
|
|
|
const gchar* property;
|
|
|
|
gchar* value;
|
|
|
|
|
2008-08-25 23:19:38 +00:00
|
|
|
search_engines = katze_array_new (KATZE_TYPE_ITEM);
|
2008-06-14 00:23:33 +00:00
|
|
|
key_file = g_key_file_new ();
|
|
|
|
g_key_file_load_from_file (key_file, filename,
|
|
|
|
G_KEY_FILE_KEEP_COMMENTS, error);
|
|
|
|
/*g_key_file_load_from_data_dirs(keyFile, sFilename, NULL
|
|
|
|
, G_KEY_FILE_KEEP_COMMENTS, error);*/
|
|
|
|
engines = g_key_file_get_groups (key_file, NULL);
|
2008-08-23 16:32:53 +00:00
|
|
|
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines),
|
|
|
|
&n_properties);
|
2008-06-14 00:23:33 +00:00
|
|
|
for (i = 0; engines[i] != NULL; i++)
|
|
|
|
{
|
2008-08-23 16:32:53 +00:00
|
|
|
item = katze_item_new ();
|
2008-06-14 00:23:33 +00:00
|
|
|
for (j = 0; j < n_properties; j++)
|
|
|
|
{
|
2008-10-18 20:07:18 +00:00
|
|
|
if (!G_IS_PARAM_SPEC_STRING (pspecs[j]))
|
|
|
|
continue;
|
2008-06-14 00:23:33 +00:00
|
|
|
property = g_param_spec_get_name (pspecs[j]);
|
|
|
|
value = g_key_file_get_string (key_file, engines[i],
|
|
|
|
property, NULL);
|
2008-08-23 16:32:53 +00:00
|
|
|
g_object_set (item, property, value, NULL);
|
2008-06-14 00:23:33 +00:00
|
|
|
g_free (value);
|
|
|
|
}
|
2008-08-25 23:19:38 +00:00
|
|
|
katze_array_add_item (search_engines, item);
|
2008-06-14 00:23:33 +00:00
|
|
|
}
|
2009-04-05 21:46:15 +00:00
|
|
|
g_free (pspecs);
|
2008-06-14 00:23:33 +00:00
|
|
|
g_strfreev (engines);
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
return search_engines;
|
|
|
|
}
|
2008-04-16 23:38:22 +00:00
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
static gboolean
|
2008-08-25 23:19:38 +00:00
|
|
|
search_engines_save_to_file (KatzeArray* search_engines,
|
|
|
|
const gchar* filename,
|
|
|
|
GError** error)
|
2008-06-14 00:23:33 +00:00
|
|
|
{
|
|
|
|
GKeyFile* key_file;
|
2009-03-31 01:24:29 +00:00
|
|
|
guint i, j, n_properties;
|
2008-08-23 16:32:53 +00:00
|
|
|
KatzeItem* item;
|
2008-06-14 00:23:33 +00:00
|
|
|
const gchar* name;
|
|
|
|
GParamSpec** pspecs;
|
|
|
|
const gchar* property;
|
|
|
|
gchar* value;
|
|
|
|
gboolean saved;
|
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
2008-08-23 16:32:53 +00:00
|
|
|
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (search_engines),
|
|
|
|
&n_properties);
|
2009-03-31 01:24:29 +00:00
|
|
|
i = 0;
|
|
|
|
while ((item = katze_array_get_nth_item (search_engines, i++)))
|
2008-06-14 00:23:33 +00:00
|
|
|
{
|
2008-08-23 16:32:53 +00:00
|
|
|
name = katze_item_get_name (item);
|
2008-06-14 00:23:33 +00:00
|
|
|
for (j = 0; j < n_properties; j++)
|
|
|
|
{
|
2008-10-18 20:07:18 +00:00
|
|
|
if (!G_IS_PARAM_SPEC_STRING (pspecs[j]))
|
|
|
|
continue;
|
2008-06-14 00:23:33 +00:00
|
|
|
property = g_param_spec_get_name (pspecs[j]);
|
2008-08-23 16:32:53 +00:00
|
|
|
g_object_get (item, property, &value, NULL);
|
2008-06-14 00:23:33 +00:00
|
|
|
if (value)
|
|
|
|
g_key_file_set_string (key_file, name, property, value);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
}
|
2009-04-05 21:46:15 +00:00
|
|
|
g_free (pspecs);
|
2008-06-14 00:23:33 +00:00
|
|
|
saved = sokoke_key_file_save_to_file (key_file, filename, error);
|
|
|
|
g_key_file_free (key_file);
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-10-07 00:19:33 +00:00
|
|
|
/* Open database 'dbname' */
|
|
|
|
static sqlite3*
|
|
|
|
db_open (const char* dbname,
|
|
|
|
GError** error)
|
|
|
|
{
|
|
|
|
sqlite3* db;
|
|
|
|
|
|
|
|
if (sqlite3_open (dbname, &db))
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = g_error_new (MIDORI_HISTORY_ERROR,
|
|
|
|
MIDORI_HISTORY_ERROR_DB_OPEN,
|
2008-11-02 23:17:43 +00:00
|
|
|
_("Failed to open database: %s\n"),
|
2008-10-07 00:19:33 +00:00
|
|
|
sqlite3_errmsg (db));
|
|
|
|
}
|
|
|
|
sqlite3_close (db);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (db);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close database 'db' */
|
|
|
|
static void
|
|
|
|
db_close (sqlite3* db)
|
|
|
|
{
|
|
|
|
sqlite3_close (db);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute an SQL statement and run 'callback' on the result data */
|
|
|
|
static gboolean
|
|
|
|
db_exec_callback (sqlite3* db,
|
|
|
|
const char* sqlcmd,
|
|
|
|
int (*callback)(void*, int, char**, char**),
|
|
|
|
void* cbarg,
|
|
|
|
GError** error)
|
|
|
|
{
|
|
|
|
char* errmsg;
|
|
|
|
|
|
|
|
if (sqlite3_exec (db, sqlcmd, callback, cbarg, &errmsg) != SQLITE_OK)
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = g_error_new (MIDORI_HISTORY_ERROR,
|
|
|
|
MIDORI_HISTORY_ERROR_EXEC_SQL,
|
2009-01-19 21:30:42 +00:00
|
|
|
_("Failed to execute database statement: %s\n"),
|
2008-10-07 00:19:33 +00:00
|
|
|
errmsg);
|
|
|
|
}
|
|
|
|
sqlite3_free (errmsg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute a SQL statement */
|
|
|
|
static gboolean
|
|
|
|
db_exec (sqlite3* db,
|
|
|
|
const char* sqlcmd,
|
|
|
|
GError** error)
|
|
|
|
{
|
|
|
|
return (db_exec_callback (db, sqlcmd, NULL, NULL, error));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sqlite method for retrieving the date/ time */
|
|
|
|
static int
|
|
|
|
gettimestr (void* data,
|
|
|
|
int argc,
|
|
|
|
char** argv,
|
|
|
|
char** colname)
|
|
|
|
{
|
|
|
|
KatzeItem* item = KATZE_ITEM (data);
|
|
|
|
(void) colname;
|
|
|
|
|
|
|
|
g_return_val_if_fail (argc == 1, 1);
|
|
|
|
|
2008-10-15 23:31:47 +00:00
|
|
|
katze_item_set_added (item, g_ascii_strtoull (argv[0], NULL, 10));
|
2008-10-07 00:19:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_remove_item_cb (KatzeArray* history,
|
|
|
|
KatzeItem* item,
|
|
|
|
sqlite3* db)
|
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (KATZE_IS_ITEM (item));
|
|
|
|
|
2009-01-11 18:30:43 +00:00
|
|
|
sqlcmd = sqlite3_mprintf (
|
|
|
|
"DELETE FROM history WHERE uri = '%q' AND"
|
2009-11-19 22:49:28 +00:00
|
|
|
" title = '%q' AND date = %llu",
|
2008-10-17 06:21:07 +00:00
|
|
|
katze_item_get_uri (item),
|
|
|
|
katze_item_get_name (item),
|
2008-11-08 01:23:08 +00:00
|
|
|
katze_item_get_added (item));
|
2008-10-07 00:19:33 +00:00
|
|
|
success = db_exec (db, sqlcmd, &error);
|
|
|
|
if (!success)
|
|
|
|
{
|
2008-11-02 23:17:43 +00:00
|
|
|
g_printerr (_("Failed to remove history item: %s\n"), error->message);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return ;
|
|
|
|
}
|
2009-01-11 18:30:43 +00:00
|
|
|
sqlite3_free (sqlcmd);
|
2008-10-07 00:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_clear_before_cb (KatzeArray* item,
|
|
|
|
sqlite3* db)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (item, midori_history_remove_item_cb, db);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_clear_cb (KatzeArray* history,
|
|
|
|
sqlite3* db)
|
|
|
|
{
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (KATZE_IS_ARRAY (history));
|
|
|
|
|
|
|
|
if (!db_exec (db, "DELETE FROM history", &error))
|
|
|
|
{
|
2008-11-02 23:17:43 +00:00
|
|
|
g_printerr (_("Failed to clear history: %s\n"), error->message);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-26 02:43:59 +00:00
|
|
|
static void
|
|
|
|
midori_history_notify_item_cb (KatzeItem* item,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
sqlite3* db)
|
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
sqlcmd = sqlite3_mprintf ("UPDATE history SET title='%q' WHERE "
|
2009-11-19 22:49:28 +00:00
|
|
|
"uri='%q' AND date=%llu",
|
2009-01-26 02:43:59 +00:00
|
|
|
katze_item_get_name (item),
|
|
|
|
katze_item_get_uri (item),
|
|
|
|
katze_item_get_added (item));
|
|
|
|
success = db_exec (db, sqlcmd, &error);
|
|
|
|
sqlite3_free (sqlcmd);
|
|
|
|
if (!success)
|
|
|
|
{
|
2009-12-27 16:20:42 +00:00
|
|
|
g_printerr (_("Failed to update history item: %s\n"), error->message);
|
2009-01-26 02:43:59 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 00:19:33 +00:00
|
|
|
static void
|
|
|
|
midori_history_add_item_cb (KatzeArray* array,
|
|
|
|
KatzeItem* item,
|
|
|
|
sqlite3* db)
|
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (KATZE_IS_ITEM (item));
|
|
|
|
|
|
|
|
if (KATZE_IS_ARRAY (item))
|
|
|
|
{
|
|
|
|
g_signal_connect_after (item, "add-item",
|
|
|
|
G_CALLBACK (midori_history_add_item_cb), db);
|
|
|
|
g_signal_connect (item, "remove-item",
|
|
|
|
G_CALLBACK (midori_history_remove_item_cb), db);
|
|
|
|
g_signal_connect (item, "clear",
|
|
|
|
G_CALLBACK (midori_history_clear_before_cb), db);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* New item, set added to the current date/ time */
|
|
|
|
if (!katze_item_get_added (item))
|
|
|
|
{
|
2008-10-15 23:31:47 +00:00
|
|
|
if (!db_exec_callback (db, "SELECT date('now')",
|
2008-10-07 00:19:33 +00:00
|
|
|
gettimestr, item, &error))
|
|
|
|
{
|
2009-12-27 16:20:42 +00:00
|
|
|
g_printerr (_("Failed to get current time: %s\n"), error->message);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 13:35:54 +00:00
|
|
|
sqlcmd = sqlite3_mprintf ("INSERT INTO history VALUES"
|
2009-11-19 22:49:28 +00:00
|
|
|
"('%q', '%q', %llu,"
|
|
|
|
" %llu)",
|
2008-10-07 00:19:33 +00:00
|
|
|
katze_item_get_uri (item),
|
|
|
|
katze_item_get_name (item),
|
2009-01-23 21:38:39 +00:00
|
|
|
katze_item_get_added (item),
|
|
|
|
katze_item_get_added (KATZE_ITEM (array)));
|
2008-10-07 00:19:33 +00:00
|
|
|
success = db_exec (db, sqlcmd, &error);
|
2008-12-06 13:35:54 +00:00
|
|
|
sqlite3_free (sqlcmd);
|
2008-10-07 00:19:33 +00:00
|
|
|
if (!success)
|
|
|
|
{
|
2008-11-02 23:17:43 +00:00
|
|
|
g_printerr (_("Failed to add history item: %s\n"), error->message);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return ;
|
|
|
|
}
|
2009-01-26 02:43:59 +00:00
|
|
|
|
|
|
|
/* The title is set after the item is added */
|
|
|
|
g_signal_connect_after (item, "notify::name",
|
|
|
|
G_CALLBACK (midori_history_notify_item_cb), db);
|
2008-10-07 00:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
midori_history_add_items (void* data,
|
|
|
|
int argc,
|
|
|
|
char** argv,
|
|
|
|
char** colname)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
2009-01-23 21:38:39 +00:00
|
|
|
KatzeArray* parent;
|
|
|
|
KatzeArray* array;
|
2008-10-15 23:31:47 +00:00
|
|
|
gint64 date;
|
2009-01-23 21:38:39 +00:00
|
|
|
gint64 day;
|
2009-01-11 18:30:43 +00:00
|
|
|
gint i;
|
2009-01-23 21:38:39 +00:00
|
|
|
gint j;
|
|
|
|
gint n;
|
|
|
|
gint ncols = 4;
|
2009-01-11 18:30:43 +00:00
|
|
|
gchar token[50];
|
2008-10-07 00:19:33 +00:00
|
|
|
|
2009-01-23 21:38:39 +00:00
|
|
|
array = KATZE_ARRAY (data);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_return_val_if_fail (KATZE_IS_ARRAY (array), 1);
|
|
|
|
|
|
|
|
/* Test whether have the right number of columns */
|
|
|
|
g_return_val_if_fail (argc % ncols == 0, 1);
|
|
|
|
|
2009-01-09 21:54:40 +00:00
|
|
|
for (i = 0; i < (argc - ncols) + 1; i++)
|
2008-10-07 00:19:33 +00:00
|
|
|
{
|
|
|
|
if (argv[i])
|
|
|
|
{
|
2008-10-17 06:21:07 +00:00
|
|
|
if (colname[i] && !g_ascii_strcasecmp (colname[i], "uri") &&
|
|
|
|
colname[i + 1] && !g_ascii_strcasecmp (colname[i + 1], "title") &&
|
2009-01-23 21:38:39 +00:00
|
|
|
colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "date") &&
|
|
|
|
colname[i + 3] && !g_ascii_strcasecmp (colname[i + 3], "day"))
|
2008-10-07 00:19:33 +00:00
|
|
|
{
|
|
|
|
item = katze_item_new ();
|
|
|
|
katze_item_set_uri (item, argv[i]);
|
|
|
|
katze_item_set_name (item, argv[i + 1]);
|
2008-10-15 23:31:47 +00:00
|
|
|
date = g_ascii_strtoull (argv[i + 2], NULL, 10);
|
2009-01-23 21:38:39 +00:00
|
|
|
day = g_ascii_strtoull (argv[i + 3], NULL, 10);
|
2008-10-15 23:31:47 +00:00
|
|
|
katze_item_set_added (item, date);
|
2008-10-07 00:19:33 +00:00
|
|
|
|
2009-01-23 21:38:39 +00:00
|
|
|
n = katze_array_get_length (array);
|
|
|
|
for (j = n - 1; j >= 0; j--)
|
|
|
|
{
|
|
|
|
parent = katze_array_get_nth_item (array, j);
|
|
|
|
if (day == katze_item_get_added (KATZE_ITEM (parent)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j < 0)
|
2008-10-07 00:19:33 +00:00
|
|
|
{
|
|
|
|
parent = katze_array_new (KATZE_TYPE_ARRAY);
|
2009-01-23 21:38:39 +00:00
|
|
|
katze_item_set_added (KATZE_ITEM (parent), day);
|
2009-02-28 22:03:23 +00:00
|
|
|
strftime (token, sizeof (token), "%x",
|
2009-01-23 21:38:39 +00:00
|
|
|
localtime ((time_t *)&date));
|
2009-03-07 13:00:14 +00:00
|
|
|
katze_item_set_name (KATZE_ITEM (parent), token);
|
2008-10-07 00:19:33 +00:00
|
|
|
katze_array_add_item (array, parent);
|
|
|
|
}
|
|
|
|
katze_array_add_item (parent, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-23 21:38:39 +00:00
|
|
|
static int
|
|
|
|
midori_history_test_day_column (void* data,
|
|
|
|
int argc,
|
|
|
|
char** argv,
|
|
|
|
char** colname)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gboolean* has_day;
|
|
|
|
|
|
|
|
has_day = (gboolean*)data;
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (argv[i] &&
|
|
|
|
!g_ascii_strcasecmp (colname[i], "name") &&
|
|
|
|
!g_ascii_strcasecmp (argv[i], "day"))
|
|
|
|
{
|
|
|
|
*has_day = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-07 00:19:33 +00:00
|
|
|
static sqlite3*
|
|
|
|
midori_history_initialize (KatzeArray* array,
|
|
|
|
const gchar* filename,
|
|
|
|
GError** error)
|
|
|
|
{
|
|
|
|
sqlite3* db;
|
|
|
|
KatzeItem* item;
|
2009-03-31 01:24:29 +00:00
|
|
|
gint i;
|
2009-01-23 21:38:39 +00:00
|
|
|
gboolean has_day;
|
|
|
|
|
|
|
|
has_day = FALSE;
|
2008-10-07 00:19:33 +00:00
|
|
|
|
|
|
|
if ((db = db_open (filename, error)) == NULL)
|
|
|
|
return db;
|
|
|
|
|
|
|
|
if (!db_exec (db,
|
|
|
|
"CREATE TABLE IF NOT EXISTS "
|
2009-01-23 21:38:39 +00:00
|
|
|
"history(uri text, title text, date integer, day integer)",
|
2008-10-07 00:19:33 +00:00
|
|
|
error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!db_exec_callback (db,
|
2009-01-23 21:38:39 +00:00
|
|
|
"PRAGMA table_info(history)",
|
|
|
|
midori_history_test_day_column,
|
|
|
|
&has_day, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!has_day)
|
|
|
|
{
|
|
|
|
if (!db_exec (db,
|
|
|
|
"BEGIN TRANSACTION;"
|
|
|
|
"CREATE TEMPORARY TABLE backup (uri text, title text, date integer);"
|
|
|
|
"INSERT INTO backup SELECT uri,title,date FROM history;"
|
|
|
|
"DROP TABLE history;"
|
|
|
|
"CREATE TABLE history (uri text, title text, date integer, day integer);"
|
|
|
|
"INSERT INTO history SELECT uri,title,date,"
|
|
|
|
"julianday(date(date,'unixepoch','start of day','+1 day'))"
|
|
|
|
" - julianday('0001-01-01','start of day')"
|
|
|
|
"FROM backup;"
|
|
|
|
"DROP TABLE backup;"
|
|
|
|
"COMMIT;",
|
|
|
|
error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!db_exec_callback (db,
|
|
|
|
"SELECT uri, title, date, day FROM history "
|
2008-10-15 23:31:47 +00:00
|
|
|
"ORDER BY date ASC",
|
2008-10-07 00:19:33 +00:00
|
|
|
midori_history_add_items,
|
|
|
|
array,
|
|
|
|
error))
|
|
|
|
return NULL;
|
|
|
|
|
2009-03-31 01:24:29 +00:00
|
|
|
i = 0;
|
|
|
|
while ((item = katze_array_get_nth_item (array, i++)))
|
2008-10-07 00:19:33 +00:00
|
|
|
{
|
|
|
|
g_signal_connect_after (item, "add-item",
|
|
|
|
G_CALLBACK (midori_history_add_item_cb), db);
|
|
|
|
g_signal_connect (item, "remove-item",
|
|
|
|
G_CALLBACK (midori_history_remove_item_cb), db);
|
|
|
|
g_signal_connect (item, "clear",
|
|
|
|
G_CALLBACK (midori_history_clear_before_cb), db);
|
|
|
|
}
|
|
|
|
return db;
|
|
|
|
}
|
2008-10-15 23:31:47 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
midori_history_terminate (sqlite3* db,
|
|
|
|
gint max_history_age)
|
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
sqlcmd = g_strdup_printf (
|
|
|
|
"DELETE FROM history WHERE "
|
|
|
|
"(julianday(date('now')) - julianday(date(date,'unixepoch')))"
|
|
|
|
" >= %d", max_history_age);
|
|
|
|
db_exec (db, sqlcmd, &error);
|
|
|
|
if (!success)
|
|
|
|
{
|
2008-11-08 02:05:30 +00:00
|
|
|
/* i18n: Couldn't remove items that are older than n days */
|
2008-11-02 23:17:43 +00:00
|
|
|
g_printerr (_("Failed to remove old history items: %s\n"), error->message);
|
2008-10-15 23:31:47 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
g_free (sqlcmd);
|
|
|
|
db_close (db);
|
|
|
|
}
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2008-10-07 00:19:33 +00:00
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
static void
|
|
|
|
midori_app_quit_cb (MidoriApp* app)
|
|
|
|
{
|
|
|
|
gchar* config_file = build_config_filename ("running");
|
|
|
|
g_unlink (config_file);
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
settings_notify_cb (MidoriWebSettings* settings,
|
2009-04-21 01:46:11 +00:00
|
|
|
GParamSpec* pspec,
|
|
|
|
MidoriApp* app)
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
|
|
|
config_file = build_config_filename ("config");
|
|
|
|
error = NULL;
|
2009-04-21 01:46:11 +00:00
|
|
|
if (!settings_save_to_file (settings, app, config_file, &error))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The configuration couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
2009-06-07 00:15:32 +00:00
|
|
|
static void
|
|
|
|
extension_activate_cb (MidoriExtension* extension,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
MidoriWebSettings* settings = katze_object_get_object (app, "settings");
|
|
|
|
settings_notify_cb (settings, NULL, app);
|
|
|
|
g_object_unref (settings);
|
|
|
|
}
|
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
static void
|
|
|
|
accel_map_changed_cb (GtkAccelMap* accel_map,
|
|
|
|
gchar* accel_path,
|
|
|
|
guint accel_key,
|
|
|
|
GdkModifierType accel_mods)
|
|
|
|
{
|
|
|
|
gchar* config_file = build_config_filename ("accels");
|
|
|
|
gtk_accel_map_save (config_file);
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-31 18:31:50 +00:00
|
|
|
midori_search_engines_modify_cb (KatzeArray* array,
|
|
|
|
gpointer item,
|
|
|
|
KatzeArray* search_engines)
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
|
|
|
config_file = build_config_filename ("search");
|
|
|
|
error = NULL;
|
|
|
|
if (!search_engines_save_to_file (search_engines, config_file, &error))
|
|
|
|
{
|
|
|
|
g_warning (_("The search engines couldn't be saved. %s"),
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
2009-01-16 04:04:42 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_notify_item_cb (KatzeArray* folder,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
KatzeArray* bookmarks)
|
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
2009-11-29 22:50:59 +00:00
|
|
|
config_file = build_config_filename (BOOKMARK_FILE);
|
2009-01-16 04:04:42 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (bookmarks, config_file, "xbel", &error))
|
2009-01-16 04:04:42 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
static void
|
2008-12-30 03:16:10 +00:00
|
|
|
midori_bookmarks_add_item_cb (KatzeArray* folder,
|
2009-12-11 22:59:08 +00:00
|
|
|
KatzeItem* item,
|
2008-12-30 03:16:10 +00:00
|
|
|
KatzeArray* bookmarks);
|
|
|
|
|
|
|
|
static void
|
2009-04-03 23:32:02 +00:00
|
|
|
midori_bookmarks_remove_item_cb (KatzeArray* folder,
|
|
|
|
GObject* item,
|
|
|
|
KatzeArray* bookmarks);
|
2008-12-30 03:16:10 +00:00
|
|
|
|
2009-12-11 22:59:08 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_connect_item (KatzeArray* folder,
|
|
|
|
KatzeItem* item,
|
|
|
|
KatzeArray* bookmarks)
|
|
|
|
{
|
|
|
|
if (KATZE_IS_ARRAY (item))
|
|
|
|
{
|
|
|
|
KatzeItem* child;
|
|
|
|
guint i = 0;
|
|
|
|
while ((child = katze_array_get_nth_item ((KatzeArray*)item, i++)))
|
|
|
|
midori_bookmarks_connect_item ((KatzeArray*)item, child, bookmarks);
|
|
|
|
|
|
|
|
g_signal_connect_after (item, "add-item",
|
|
|
|
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
|
|
|
|
g_signal_connect_after (item, "remove-item",
|
|
|
|
G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect_after (item, "notify",
|
|
|
|
G_CALLBACK (midori_bookmarks_notify_item_cb), bookmarks);
|
|
|
|
}
|
|
|
|
|
2008-12-30 03:16:10 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_add_item_cb (KatzeArray* folder,
|
2009-12-11 22:59:08 +00:00
|
|
|
KatzeItem* item,
|
2008-12-30 03:16:10 +00:00
|
|
|
KatzeArray* bookmarks)
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
2009-11-29 22:50:59 +00:00
|
|
|
config_file = build_config_filename (BOOKMARK_FILE);
|
2008-12-12 09:20:19 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (bookmarks, config_file, "xbel", &error))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
2008-12-30 03:16:10 +00:00
|
|
|
|
2009-12-11 22:59:08 +00:00
|
|
|
midori_bookmarks_connect_item (folder, item, bookmarks);
|
2008-12-12 09:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-03 23:32:02 +00:00
|
|
|
midori_bookmarks_remove_item_cb (KatzeArray* folder,
|
|
|
|
GObject* item,
|
|
|
|
KatzeArray* bookmarks)
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
2009-11-29 22:50:59 +00:00
|
|
|
config_file = build_config_filename (BOOKMARK_FILE);
|
2008-12-12 09:20:19 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (bookmarks, config_file, "xbel", &error))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The bookmarks couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
2008-12-30 03:16:10 +00:00
|
|
|
|
|
|
|
if (KATZE_IS_ARRAY (item))
|
2009-12-11 22:59:08 +00:00
|
|
|
{
|
2008-12-30 03:16:10 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (item,
|
|
|
|
midori_bookmarks_add_item_cb, bookmarks);
|
2009-12-11 22:59:08 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (item,
|
|
|
|
midori_bookmarks_remove_item_cb, bookmarks);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (item,
|
|
|
|
midori_bookmarks_notify_item_cb, bookmarks);
|
2008-12-12 09:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_trash_add_item_cb (KatzeArray* trash,
|
|
|
|
GObject* item)
|
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
GObject* obsolete_item;
|
|
|
|
|
|
|
|
config_file = build_config_filename ("tabtrash.xbel");
|
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (trash, config_file, "xbel", &error))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
2009-01-13 00:05:15 +00:00
|
|
|
/* i18n: Trash, or wastebin, containing closed tabs */
|
2008-12-12 09:20:19 +00:00
|
|
|
g_warning (_("The trash couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
|
2009-03-31 01:24:29 +00:00
|
|
|
if (katze_array_get_nth_item (trash, 10))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
obsolete_item = katze_array_get_nth_item (trash, 0);
|
|
|
|
katze_array_remove_item (trash, obsolete_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_trash_remove_item_cb (KatzeArray* trash,
|
|
|
|
GObject* item)
|
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
|
|
|
config_file = build_config_filename ("tabtrash.xbel");
|
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (trash, config_file, "xbel", &error))
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The trash couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
|
2008-11-20 02:49:57 +00:00
|
|
|
static void
|
|
|
|
midori_app_add_browser_cb (MidoriApp* app,
|
|
|
|
MidoriBrowser* browser,
|
|
|
|
KatzeNet* net)
|
|
|
|
{
|
|
|
|
GtkWidget* panel;
|
|
|
|
GtkWidget* addon;
|
|
|
|
|
|
|
|
panel = katze_object_get_object (browser, "panel");
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
/* Bookmarks */
|
|
|
|
addon = g_object_new (MIDORI_TYPE_BOOKMARKS, "app", app, NULL);
|
|
|
|
gtk_widget_show (addon);
|
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
|
|
|
|
2009-02-21 22:59:02 +00:00
|
|
|
/* History */
|
|
|
|
addon = g_object_new (MIDORI_TYPE_HISTORY, "app", app, NULL);
|
|
|
|
gtk_widget_show (addon);
|
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
|
|
|
|
2008-11-20 02:49:57 +00:00
|
|
|
/* Transfers */
|
2009-03-22 14:25:57 +00:00
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 3)
|
|
|
|
addon = g_object_new (MIDORI_TYPE_TRANSFERS, "app", app, NULL);
|
2008-11-20 02:49:57 +00:00
|
|
|
gtk_widget_show (addon);
|
2009-03-22 14:25:57 +00:00
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
2008-11-22 00:17:23 +00:00
|
|
|
#endif
|
2008-11-20 02:49:57 +00:00
|
|
|
|
|
|
|
/* Console */
|
2008-12-04 00:45:32 +00:00
|
|
|
addon = g_object_new (MIDORI_TYPE_CONSOLE, "app", app, NULL);
|
2008-11-20 02:49:57 +00:00
|
|
|
gtk_widget_show (addon);
|
2008-12-04 00:45:32 +00:00
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
2008-11-20 02:49:57 +00:00
|
|
|
|
|
|
|
/* Userscripts */
|
2008-11-22 00:17:23 +00:00
|
|
|
addon = midori_addons_new (MIDORI_ADDON_USER_SCRIPTS, GTK_WIDGET (browser));
|
2008-11-20 02:49:57 +00:00
|
|
|
gtk_widget_show (addon);
|
2008-12-04 00:45:32 +00:00
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
2008-11-23 04:19:43 +00:00
|
|
|
|
2009-01-18 19:34:50 +00:00
|
|
|
/* Plugins */
|
|
|
|
addon = g_object_new (MIDORI_TYPE_PLUGINS, "app", app, NULL);
|
|
|
|
gtk_widget_show (addon);
|
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
|
|
|
|
2008-11-20 02:49:57 +00:00
|
|
|
/* Extensions */
|
2009-10-30 20:43:42 +00:00
|
|
|
addon = g_object_new (MIDORI_TYPE_EXTENSIONS, NULL);
|
2008-11-20 02:49:57 +00:00
|
|
|
gtk_widget_show (addon);
|
2009-10-30 20:43:42 +00:00
|
|
|
g_object_set (addon, "app", app, NULL);
|
2008-12-04 00:45:32 +00:00
|
|
|
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
|
2009-04-05 21:46:15 +00:00
|
|
|
|
|
|
|
g_object_unref (panel);
|
2008-11-20 02:49:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 21:54:53 +00:00
|
|
|
static guint save_timeout = 0;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
midori_session_save_timeout_cb (KatzeArray* session)
|
2008-09-03 22:35:15 +00:00
|
|
|
{
|
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
config_file = build_config_filename ("session.xbel");
|
2008-09-03 22:35:15 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_to_file (session, config_file, "xbel", &error))
|
2008-09-03 22:35:15 +00:00
|
|
|
{
|
|
|
|
g_warning (_("The session couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
2009-09-02 21:54:53 +00:00
|
|
|
|
|
|
|
save_timeout = 0;
|
|
|
|
g_object_unref (session);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_browser_session_cb (MidoriBrowser* browser,
|
|
|
|
gpointer pspec,
|
|
|
|
KatzeArray* session)
|
|
|
|
{
|
|
|
|
if (!save_timeout)
|
|
|
|
{
|
|
|
|
g_object_ref (session);
|
|
|
|
save_timeout = g_timeout_add_full (G_PRIORITY_LOW, 5000,
|
|
|
|
(GSourceFunc)midori_session_save_timeout_cb, session, NULL);
|
|
|
|
}
|
2008-09-03 22:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_browser_weak_notify_cb (MidoriBrowser* browser,
|
2008-10-01 02:00:16 +00:00
|
|
|
KatzeArray* session)
|
2008-09-03 22:35:15 +00:00
|
|
|
{
|
|
|
|
g_object_disconnect (browser, "any-signal",
|
|
|
|
G_CALLBACK (midori_browser_session_cb), session, NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-08 23:53:30 +00:00
|
|
|
static void
|
2009-08-29 21:33:24 +00:00
|
|
|
midori_soup_session_set_proxy_uri (SoupSession* session,
|
|
|
|
const gchar* uri)
|
2008-12-08 23:53:30 +00:00
|
|
|
{
|
2009-08-29 21:33:24 +00:00
|
|
|
gchar* fixed_uri;
|
2008-12-08 23:53:30 +00:00
|
|
|
SoupURI* proxy_uri;
|
|
|
|
|
2009-03-30 23:10:35 +00:00
|
|
|
/* soup_uri_new expects a non-NULL string with a protocol */
|
2009-08-29 21:33:24 +00:00
|
|
|
if (uri && g_str_has_prefix (uri, "http://"))
|
|
|
|
proxy_uri = soup_uri_new (uri);
|
|
|
|
else if (uri && *uri)
|
2009-03-30 23:10:35 +00:00
|
|
|
{
|
2009-08-29 21:33:24 +00:00
|
|
|
fixed_uri = g_strconcat ("http://", uri, NULL);
|
|
|
|
proxy_uri = soup_uri_new (fixed_uri);
|
|
|
|
g_free (fixed_uri);
|
2009-03-30 23:10:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
proxy_uri = NULL;
|
2008-12-08 23:53:30 +00:00
|
|
|
g_object_set (session, "proxy-uri", proxy_uri, NULL);
|
2009-02-12 23:49:30 +00:00
|
|
|
if (proxy_uri)
|
|
|
|
soup_uri_free (proxy_uri);
|
2008-12-08 23:53:30 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 21:33:24 +00:00
|
|
|
static void
|
|
|
|
soup_session_settings_notify_http_proxy_cb (MidoriWebSettings* settings,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
SoupSession* session)
|
|
|
|
{
|
|
|
|
gboolean auto_detect_proxy;
|
|
|
|
|
|
|
|
auto_detect_proxy = katze_object_get_boolean (settings, "auto-detect-proxy");
|
|
|
|
if (auto_detect_proxy)
|
|
|
|
{
|
|
|
|
gboolean gnome_supported = FALSE;
|
|
|
|
GModule* module;
|
|
|
|
GType (*get_type_function) (void);
|
|
|
|
if (g_module_supported ())
|
|
|
|
if ((module = g_module_open ("libsoup-gnome-2.4.so", G_MODULE_BIND_LOCAL)))
|
|
|
|
{
|
|
|
|
if (g_module_symbol (module, "soup_proxy_resolver_gnome_get_type",
|
|
|
|
(void*) &get_type_function))
|
|
|
|
{
|
|
|
|
soup_session_add_feature_by_type (session, get_type_function ());
|
|
|
|
gnome_supported = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!gnome_supported)
|
|
|
|
midori_soup_session_set_proxy_uri (session, g_getenv ("http_proxy"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar* http_proxy = katze_object_get_string (settings, "http-proxy");
|
|
|
|
midori_soup_session_set_proxy_uri (session, http_proxy);
|
|
|
|
g_free (http_proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !WEBKIT_CHECK_VERSION (1, 1, 11)
|
2008-12-08 23:53:30 +00:00
|
|
|
static void
|
|
|
|
soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
SoupSession* session)
|
|
|
|
{
|
|
|
|
gchar* ident_string = katze_object_get_string (settings, "ident-string");
|
|
|
|
g_object_set (session, "user-agent", ident_string, NULL);
|
|
|
|
g_free (ident_string);
|
|
|
|
}
|
2009-08-29 21:33:24 +00:00
|
|
|
#endif
|
2008-12-08 23:53:30 +00:00
|
|
|
|
2009-02-17 13:17:28 +00:00
|
|
|
static void
|
|
|
|
midori_soup_session_debug (SoupSession* session)
|
|
|
|
{
|
|
|
|
const char* soup_debug = g_getenv ("MIDORI_SOUP_DEBUG");
|
|
|
|
|
|
|
|
if (soup_debug)
|
|
|
|
{
|
|
|
|
gint soup_debug_level = atoi (soup_debug);
|
|
|
|
SoupLogger* logger = soup_logger_new (soup_debug_level, -1);
|
|
|
|
soup_logger_attach (logger, session);
|
|
|
|
g_object_unref (logger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-07 20:38:00 +00:00
|
|
|
static void
|
2009-03-06 19:29:40 +00:00
|
|
|
midori_soup_session_prepare (SoupSession* session,
|
2009-03-24 00:10:15 +00:00
|
|
|
SoupCookieJar* cookie_jar,
|
2009-03-06 19:29:40 +00:00
|
|
|
MidoriWebSettings* settings)
|
2008-12-07 20:38:00 +00:00
|
|
|
{
|
2009-02-14 03:14:01 +00:00
|
|
|
SoupSessionFeature* feature;
|
|
|
|
gchar* config_file;
|
2008-12-07 20:38:00 +00:00
|
|
|
|
2008-12-08 23:53:30 +00:00
|
|
|
soup_session_settings_notify_http_proxy_cb (settings, NULL, session);
|
|
|
|
g_signal_connect (settings, "notify::http-proxy",
|
2009-03-06 19:29:40 +00:00
|
|
|
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
2009-02-12 23:49:30 +00:00
|
|
|
g_signal_connect (settings, "notify::auto-detect-proxy",
|
2009-03-06 19:29:40 +00:00
|
|
|
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
2009-08-29 21:33:24 +00:00
|
|
|
|
|
|
|
#if !WEBKIT_CHECK_VERSION (1, 1, 11)
|
|
|
|
soup_session_settings_notify_ident_string_cb (settings, NULL, session);
|
2008-12-08 23:53:30 +00:00
|
|
|
g_signal_connect (settings, "notify::ident-string",
|
2009-03-06 19:29:40 +00:00
|
|
|
G_CALLBACK (soup_session_settings_notify_ident_string_cb), session);
|
2009-08-29 21:33:24 +00:00
|
|
|
#endif
|
2008-12-08 23:53:30 +00:00
|
|
|
|
2009-09-07 21:51:43 +00:00
|
|
|
config_file = build_config_filename ("logins");
|
|
|
|
feature = g_object_new (KATZE_TYPE_HTTP_AUTH, "filename", config_file, NULL);
|
|
|
|
g_free (config_file);
|
|
|
|
soup_session_add_feature (session, feature);
|
|
|
|
g_object_unref (feature);
|
2009-02-17 13:17:28 +00:00
|
|
|
midori_soup_session_debug (session);
|
2009-02-14 03:14:01 +00:00
|
|
|
|
|
|
|
feature = g_object_new (KATZE_TYPE_HTTP_COOKIES, NULL);
|
|
|
|
config_file = build_config_filename ("cookies.txt");
|
|
|
|
g_object_set_data_full (G_OBJECT (feature), "filename",
|
|
|
|
config_file, (GDestroyNotify)g_free);
|
2009-03-24 00:10:15 +00:00
|
|
|
soup_session_add_feature (session, SOUP_SESSION_FEATURE (cookie_jar));
|
2009-09-10 15:03:17 +00:00
|
|
|
soup_session_add_feature (session, feature);
|
2009-09-07 21:51:43 +00:00
|
|
|
g_object_unref (feature);
|
2008-12-07 20:38:00 +00:00
|
|
|
}
|
2009-03-06 19:29:40 +00:00
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
static void
|
|
|
|
button_modify_preferences_clicked_cb (GtkWidget* button,
|
|
|
|
MidoriWebSettings* settings)
|
|
|
|
{
|
2009-01-11 19:51:18 +00:00
|
|
|
GtkWidget* dialog = midori_preferences_new (
|
|
|
|
GTK_WINDOW (gtk_widget_get_toplevel (button)), settings);
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_DELETE_EVENT)
|
|
|
|
gtk_widget_destroy (dialog);
|
2008-12-12 09:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
button_reset_session_clicked_cb (GtkWidget* button,
|
|
|
|
KatzeArray* session)
|
|
|
|
{
|
2009-09-30 20:30:19 +00:00
|
|
|
gchar* config_file;
|
|
|
|
GError* error;
|
|
|
|
|
|
|
|
config_file = build_config_filename ("session.old.xbel");
|
|
|
|
error = NULL;
|
|
|
|
if (!midori_array_to_file (session, config_file, "xbel", &error))
|
|
|
|
{
|
|
|
|
g_warning (_("The session couldn't be saved. %s"), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_array_clear (session);
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-08-23 22:57:44 +00:00
|
|
|
static void
|
|
|
|
button_disable_extensions_clicked_cb (GtkWidget* button,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (app), "extensions", NULL);
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
}
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
static GtkWidget*
|
|
|
|
midori_create_diagnostic_dialog (MidoriWebSettings* settings,
|
|
|
|
KatzeArray* _session)
|
|
|
|
{
|
|
|
|
GtkWidget* dialog;
|
|
|
|
GdkScreen* screen;
|
|
|
|
GtkIconTheme* icon_theme;
|
|
|
|
GtkWidget* box;
|
|
|
|
GtkWidget* button;
|
2009-08-23 22:57:44 +00:00
|
|
|
MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session));
|
2008-12-24 23:41:11 +00:00
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (
|
2009-10-13 21:26:48 +00:00
|
|
|
NULL, 0, GTK_MESSAGE_WARNING,
|
2009-12-21 15:15:41 +00:00
|
|
|
#ifdef HAVE_HILDON_2_2
|
2009-10-13 21:26:48 +00:00
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
#else
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
#endif
|
2009-02-03 21:59:57 +00:00
|
|
|
_("Midori seems to have crashed the last time it was opened. "
|
2009-03-29 22:49:48 +00:00
|
|
|
"If this happened repeatedly, try one of the following options "
|
2009-02-03 21:59:57 +00:00
|
|
|
"to solve the problem."));
|
2008-12-24 23:41:11 +00:00
|
|
|
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), g_get_application_name ());
|
|
|
|
screen = gtk_widget_get_screen (dialog);
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
if (gtk_icon_theme_has_icon (icon_theme, "midori"))
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), "midori");
|
|
|
|
else
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser");
|
|
|
|
}
|
|
|
|
box = gtk_hbox_new (FALSE, 0);
|
|
|
|
button = gtk_button_new_with_mnemonic (_("Modify _preferences"));
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (button_modify_preferences_clicked_cb), settings);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
|
|
|
|
button = gtk_button_new_with_mnemonic (_("Reset the last _session"));
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (button_reset_session_clicked_cb), _session);
|
|
|
|
gtk_widget_set_sensitive (button, !katze_array_is_empty (_session));
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
|
|
|
|
button = gtk_button_new_with_mnemonic (_("Disable all _extensions"));
|
2009-08-23 22:57:44 +00:00
|
|
|
if (g_object_get_data (G_OBJECT (app), "extensions"))
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (button_disable_extensions_clicked_cb), app);
|
|
|
|
else
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
2008-12-24 23:41:11 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);
|
2009-12-21 15:15:41 +00:00
|
|
|
#ifdef HAVE_HILDON_2_2
|
2009-10-13 21:26:48 +00:00
|
|
|
box = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), box, TRUE, FALSE, 4);
|
|
|
|
button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_HALFSCREEN_WIDTH);
|
|
|
|
gtk_button_set_label (GTK_BUTTON (button), GTK_STOCK_OK);
|
|
|
|
gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy), dialog);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 4);
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
#endif
|
2009-02-05 21:43:24 +00:00
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
/* GtkLabel can't wrap the text properly. Until some day
|
|
|
|
this works, we implement this hack to do it ourselves. */
|
|
|
|
GtkWidget* content_area;
|
|
|
|
GtkWidget* hbox;
|
|
|
|
GtkWidget* vbox;
|
|
|
|
GtkWidget* label;
|
|
|
|
GList* ch;
|
|
|
|
GtkRequisition req;
|
|
|
|
|
|
|
|
content_area = GTK_DIALOG (dialog)->vbox;
|
|
|
|
ch = gtk_container_get_children (GTK_CONTAINER (content_area));
|
|
|
|
hbox = (GtkWidget*)g_list_nth_data (ch, 0);
|
|
|
|
g_list_free (ch);
|
|
|
|
ch = gtk_container_get_children (GTK_CONTAINER (hbox));
|
|
|
|
vbox = (GtkWidget*)g_list_nth_data (ch, 1);
|
|
|
|
g_list_free (ch);
|
|
|
|
ch = gtk_container_get_children (GTK_CONTAINER (vbox));
|
|
|
|
label = (GtkWidget*)g_list_nth_data (ch, 0);
|
|
|
|
g_list_free (ch);
|
|
|
|
gtk_widget_size_request (content_area, &req);
|
|
|
|
gtk_widget_set_size_request (label, req.width * 0.9, -1);
|
|
|
|
}
|
2008-12-24 23:41:11 +00:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2009-03-28 02:04:27 +00:00
|
|
|
static gboolean
|
|
|
|
midori_load_cookie_jar (gpointer data)
|
|
|
|
{
|
|
|
|
MidoriWebSettings* settings = MIDORI_WEB_SETTINGS (data);
|
|
|
|
SoupSession* webkit_session;
|
|
|
|
SoupCookieJar* jar;
|
|
|
|
|
|
|
|
webkit_session = webkit_get_default_session ();
|
|
|
|
jar = soup_cookie_jar_new ();
|
|
|
|
g_object_set_data (G_OBJECT (jar), "midori-settings", settings);
|
|
|
|
midori_soup_session_prepare (webkit_session, jar, settings);
|
|
|
|
g_object_unref (jar);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
static gboolean
|
|
|
|
midori_load_extensions (gpointer data)
|
|
|
|
{
|
|
|
|
MidoriApp* app = MIDORI_APP (data);
|
2009-04-21 01:46:11 +00:00
|
|
|
gchar** active_extensions = g_object_get_data (G_OBJECT (app), "extensions");
|
2008-12-24 23:41:11 +00:00
|
|
|
KatzeArray* extensions;
|
|
|
|
MidoriExtension* extension;
|
|
|
|
|
|
|
|
/* Load extensions */
|
|
|
|
extensions = katze_array_new (MIDORI_TYPE_EXTENSION);
|
2009-04-21 01:46:11 +00:00
|
|
|
g_object_set (app, "extensions", extensions, NULL);
|
2008-12-24 23:41:11 +00:00
|
|
|
if (g_module_supported ())
|
|
|
|
{
|
2009-01-16 19:22:01 +00:00
|
|
|
/* FIXME: Read extensions from system data dirs */
|
|
|
|
gchar* extension_path;
|
|
|
|
GDir* extension_dir;
|
|
|
|
|
|
|
|
if (!(extension_path = g_strdup (g_getenv ("MIDORI_EXTENSION_PATH"))))
|
|
|
|
extension_path = g_build_filename (LIBDIR, PACKAGE_NAME, NULL);
|
|
|
|
extension_dir = g_dir_open (extension_path, 0, NULL);
|
2009-01-09 23:16:07 +00:00
|
|
|
if (extension_dir != NULL)
|
2008-12-24 23:41:11 +00:00
|
|
|
{
|
2009-04-21 01:46:11 +00:00
|
|
|
const gchar* filename;
|
2009-06-07 00:15:32 +00:00
|
|
|
gchar* config_file = build_config_filename ("config");
|
2009-04-21 01:46:11 +00:00
|
|
|
|
2009-01-09 23:16:07 +00:00
|
|
|
while ((filename = g_dir_read_name (extension_dir)))
|
2008-12-30 02:00:08 +00:00
|
|
|
{
|
2009-01-09 23:16:07 +00:00
|
|
|
gchar* fullname;
|
|
|
|
GModule* module;
|
|
|
|
typedef MidoriExtension* (*extension_init_func)(void);
|
|
|
|
extension_init_func extension_init;
|
|
|
|
|
2009-01-16 19:22:01 +00:00
|
|
|
/* Ignore files which don't have the correct suffix */
|
|
|
|
if (!g_str_has_suffix (filename, G_MODULE_SUFFIX))
|
|
|
|
continue;
|
|
|
|
|
2009-01-09 23:16:07 +00:00
|
|
|
fullname = g_build_filename (extension_path, filename, NULL);
|
|
|
|
module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
|
|
|
|
g_free (fullname);
|
|
|
|
|
|
|
|
if (module && g_module_symbol (module, "extension_init",
|
|
|
|
(gpointer) &extension_init))
|
2009-03-05 21:22:18 +00:00
|
|
|
{
|
2009-01-09 23:16:07 +00:00
|
|
|
extension = extension_init ();
|
2009-03-05 21:22:18 +00:00
|
|
|
/* Signal that we want the extension to load and save */
|
2009-04-21 01:46:11 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (extension), "filename",
|
|
|
|
g_strdup (filename), g_free);
|
2009-09-10 00:02:49 +00:00
|
|
|
if (midori_extension_is_prepared (extension))
|
|
|
|
midori_extension_get_config_dir (extension);
|
2009-03-05 21:22:18 +00:00
|
|
|
}
|
2009-01-09 23:16:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
extension = g_object_new (MIDORI_TYPE_EXTENSION,
|
|
|
|
"name", filename,
|
|
|
|
"description", g_module_error (),
|
|
|
|
NULL);
|
|
|
|
g_warning ("%s", g_module_error ());
|
|
|
|
}
|
|
|
|
katze_array_add_item (extensions, extension);
|
2009-04-21 01:46:11 +00:00
|
|
|
if (active_extensions)
|
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
gchar* name;
|
|
|
|
while ((name = active_extensions[i++]))
|
|
|
|
if (!g_strcmp0 (filename, name))
|
|
|
|
g_signal_emit_by_name (extension, "activate", app);
|
|
|
|
}
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (extension, "activate",
|
|
|
|
G_CALLBACK (extension_activate_cb), app);
|
|
|
|
g_signal_connect_after (extension, "deactivate",
|
|
|
|
G_CALLBACK (extension_activate_cb), app);
|
2009-01-09 23:16:07 +00:00
|
|
|
g_object_unref (extension);
|
2008-12-30 02:00:08 +00:00
|
|
|
}
|
2009-01-09 23:16:07 +00:00
|
|
|
g_dir_close (extension_dir);
|
2009-06-07 00:15:32 +00:00
|
|
|
g_free (config_file);
|
2008-12-24 23:41:11 +00:00
|
|
|
}
|
2009-01-09 23:16:07 +00:00
|
|
|
g_free (extension_path);
|
2008-12-24 23:41:11 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 01:46:11 +00:00
|
|
|
g_strfreev (active_extensions);
|
2008-12-24 23:41:11 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-30 21:02:10 +00:00
|
|
|
static void
|
|
|
|
midori_browser_action_last_session_activate_cb (GtkAction* action,
|
|
|
|
MidoriBrowser* browser)
|
|
|
|
{
|
|
|
|
KatzeArray* old_session = katze_array_new (KATZE_TYPE_ITEM);
|
|
|
|
gchar* config_file = build_config_filename ("session.old.xbel");
|
|
|
|
GError* error = NULL;
|
|
|
|
if (midori_array_from_file (old_session, config_file, "xbel", &error))
|
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
KatzeItem* item;
|
|
|
|
while ((item = katze_array_get_nth_item (old_session, i++)))
|
|
|
|
midori_browser_add_item (browser, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning (_("The session couldn't be loaded: %s\n"), error->message);
|
|
|
|
/* FIXME: Show a graphical dialog */
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
g_free (config_file);
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
g_signal_handlers_disconnect_by_func (action,
|
|
|
|
midori_browser_action_last_session_activate_cb, browser);
|
|
|
|
}
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
static gboolean
|
|
|
|
midori_load_session (gpointer data)
|
|
|
|
{
|
|
|
|
KatzeArray* _session = KATZE_ARRAY (data);
|
|
|
|
MidoriBrowser* browser;
|
|
|
|
MidoriApp* app = katze_item_get_parent (KATZE_ITEM (_session));
|
2009-02-12 22:52:14 +00:00
|
|
|
gchar* config_file;
|
2008-12-24 23:41:11 +00:00
|
|
|
KatzeArray* session;
|
|
|
|
KatzeItem* item;
|
2009-03-31 01:24:29 +00:00
|
|
|
guint i;
|
2009-07-04 23:17:00 +00:00
|
|
|
gint64 current;
|
2009-06-16 21:31:35 +00:00
|
|
|
gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
|
2008-12-24 23:41:11 +00:00
|
|
|
|
|
|
|
browser = midori_app_create_browser (app);
|
2009-09-30 21:02:10 +00:00
|
|
|
config_file = build_config_filename ("session.old.xbel");
|
2009-12-19 09:39:24 +00:00
|
|
|
if (g_access (config_file, F_OK) == 0)
|
2009-09-30 21:02:10 +00:00
|
|
|
{
|
|
|
|
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
|
|
|
|
GtkAction* action = gtk_action_group_get_action (action_group, "LastSession");
|
|
|
|
g_signal_connect (action, "activate",
|
|
|
|
G_CALLBACK (midori_browser_action_last_session_activate_cb), browser);
|
2009-10-31 21:43:58 +00:00
|
|
|
gtk_action_set_visible (action, TRUE);
|
2009-09-30 21:02:10 +00:00
|
|
|
}
|
2008-12-24 23:41:11 +00:00
|
|
|
midori_app_add_browser (app, browser);
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
|
|
|
|
2009-09-30 21:02:10 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("accels"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (gtk_accel_map_get (), "changed",
|
|
|
|
G_CALLBACK (accel_map_changed_cb), NULL);
|
2009-01-24 14:22:45 +00:00
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
if (katze_array_is_empty (_session))
|
|
|
|
{
|
|
|
|
MidoriWebSettings* settings = katze_object_get_object (app, "settings");
|
|
|
|
MidoriStartup load_on_startup;
|
|
|
|
gchar* homepage;
|
|
|
|
item = katze_item_new ();
|
|
|
|
|
|
|
|
g_object_get (settings, "load-on-startup", &load_on_startup, NULL);
|
|
|
|
if (load_on_startup == MIDORI_STARTUP_BLANK_PAGE)
|
|
|
|
katze_item_set_uri (item, "");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_get (settings, "homepage", &homepage, NULL);
|
|
|
|
katze_item_set_uri (item, homepage);
|
|
|
|
g_free (homepage);
|
|
|
|
}
|
2009-04-05 21:46:15 +00:00
|
|
|
g_object_unref (settings);
|
2008-12-24 23:41:11 +00:00
|
|
|
katze_array_add_item (_session, item);
|
2009-04-05 21:46:15 +00:00
|
|
|
g_object_unref (item);
|
2008-12-24 23:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
session = midori_browser_get_proxy_array (browser);
|
2009-03-31 01:24:29 +00:00
|
|
|
i = 0;
|
|
|
|
while ((item = katze_array_get_nth_item (_session, i++)))
|
2008-12-24 23:41:11 +00:00
|
|
|
midori_browser_add_item (browser, item);
|
2009-07-04 23:17:00 +00:00
|
|
|
current = katze_item_get_meta_integer (KATZE_ITEM (_session), "current");
|
|
|
|
if (current < 0)
|
|
|
|
current = 0;
|
|
|
|
midori_browser_set_current_page (browser, current);
|
2009-07-19 16:45:00 +00:00
|
|
|
if (!(item = katze_array_get_nth_item (_session, current)))
|
|
|
|
item = katze_array_get_nth_item (_session, 0);
|
2008-12-24 23:41:11 +00:00
|
|
|
if (!strcmp (katze_item_get_uri (item), ""))
|
|
|
|
midori_browser_activate_action (browser, "Location");
|
|
|
|
g_object_unref (_session);
|
|
|
|
|
2009-02-12 22:52:14 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("session.xbel"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (browser, "notify::uri",
|
|
|
|
G_CALLBACK (midori_browser_session_cb), session);
|
|
|
|
g_signal_connect_after (browser, "add-tab",
|
|
|
|
G_CALLBACK (midori_browser_session_cb), session);
|
|
|
|
g_signal_connect_after (browser, "remove-tab",
|
|
|
|
G_CALLBACK (midori_browser_session_cb), session);
|
|
|
|
g_object_weak_ref (G_OBJECT (session),
|
|
|
|
(GWeakNotify)(midori_browser_weak_notify_cb), browser);
|
2008-12-24 23:41:11 +00:00
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
if (command)
|
|
|
|
midori_app_send_command (app, command);
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
midori_run_script (const gchar* filename)
|
|
|
|
{
|
|
|
|
if (!(filename))
|
|
|
|
{
|
|
|
|
g_print ("%s - %s\n", _("Midori"), _("No filename specified"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSGlobalContextRef js_context;
|
|
|
|
gchar* exception;
|
|
|
|
gchar* script;
|
|
|
|
GError* error = NULL;
|
|
|
|
|
|
|
|
js_context = JSGlobalContextCreateInGroup (NULL, NULL);
|
|
|
|
|
|
|
|
if (g_file_get_contents (filename, &script, NULL, &error))
|
|
|
|
{
|
|
|
|
if (sokoke_js_script_eval (js_context, script, &exception))
|
|
|
|
exception = NULL;
|
|
|
|
g_free (script);
|
|
|
|
}
|
|
|
|
else if (error)
|
|
|
|
{
|
|
|
|
exception = g_strdup (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
exception = g_strdup (_("An unknown error occured."));
|
|
|
|
|
|
|
|
JSGlobalContextRelease (js_context);
|
|
|
|
if (!exception)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
g_print ("%s - Exception: %s\n", filename, exception);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-05 21:02:45 +00:00
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 6)
|
2009-05-04 00:09:46 +00:00
|
|
|
static void
|
|
|
|
snapshot_load_finished_cb (GtkWidget* web_view,
|
|
|
|
WebKitWebFrame* web_frame,
|
|
|
|
gchar* filename)
|
|
|
|
{
|
|
|
|
GError* error;
|
|
|
|
GtkPrintOperation* operation = gtk_print_operation_new ();
|
|
|
|
GtkPrintOperationAction action = GTK_PRINT_OPERATION_ACTION_EXPORT;
|
|
|
|
GtkPrintOperationResult result;
|
|
|
|
|
|
|
|
gtk_print_operation_set_export_filename (operation, filename);
|
|
|
|
error = NULL;
|
|
|
|
result = webkit_web_frame_print_full (web_frame, operation, action, &error);
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_error ("%s", error->message);
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (operation);
|
|
|
|
g_print (_("Snapshot saved to: %s\n"), filename);
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
2009-05-05 21:02:45 +00:00
|
|
|
#endif
|
2009-05-04 00:09:46 +00:00
|
|
|
|
2009-07-16 21:45:45 +00:00
|
|
|
static void
|
|
|
|
midori_web_app_browser_notify_load_status_cb (MidoriBrowser* browser,
|
|
|
|
GParamSpec* pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
if (katze_object_get_enum (browser, "load-status") != MIDORI_LOAD_PROVISIONAL)
|
|
|
|
{
|
|
|
|
GtkWidget* view = midori_browser_get_current_tab (browser);
|
|
|
|
GdkPixbuf* icon = midori_view_get_icon (MIDORI_VIEW (view));
|
|
|
|
gtk_window_set_icon (GTK_WINDOW (browser), icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-28 21:12:35 +00:00
|
|
|
static void
|
|
|
|
midori_remove_config_file (gint clear_prefs,
|
|
|
|
gint flag,
|
|
|
|
const gchar* filename)
|
|
|
|
{
|
|
|
|
if ((clear_prefs & flag) == flag)
|
|
|
|
{
|
|
|
|
gchar* config_file = build_config_filename (filename);
|
2009-11-18 18:13:07 +00:00
|
|
|
g_unlink (config_file);
|
2009-07-28 21:12:35 +00:00
|
|
|
g_free (config_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-31 03:46:23 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
static void
|
|
|
|
signal_handler (int signal_id)
|
|
|
|
{
|
2009-12-07 19:10:33 +00:00
|
|
|
signal (signal_id, 0);
|
2009-11-17 17:57:32 +00:00
|
|
|
midori_app_quit_cb (NULL);
|
2009-12-07 19:10:33 +00:00
|
|
|
if (kill (getpid (), signal_id))
|
|
|
|
exit (1);
|
2009-10-31 03:46:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
int
|
2008-08-25 23:19:38 +00:00
|
|
|
main (int argc,
|
2008-06-14 00:23:33 +00:00
|
|
|
char** argv)
|
|
|
|
{
|
2009-04-13 02:38:01 +00:00
|
|
|
gchar* webapp;
|
2009-04-09 17:28:36 +00:00
|
|
|
gchar* config;
|
2009-12-21 15:15:41 +00:00
|
|
|
gboolean diagnostic_dialog;
|
2008-10-16 18:54:26 +00:00
|
|
|
gboolean run;
|
2009-05-04 00:09:46 +00:00
|
|
|
gchar* snapshot;
|
2009-06-16 21:31:35 +00:00
|
|
|
gboolean execute;
|
2008-06-14 00:23:33 +00:00
|
|
|
gboolean version;
|
2008-09-10 17:18:16 +00:00
|
|
|
gchar** uris;
|
2008-08-22 01:59:07 +00:00
|
|
|
MidoriApp* app;
|
|
|
|
gboolean result;
|
2008-06-14 00:23:33 +00:00
|
|
|
GError* error;
|
2007-12-16 22:20:24 +00:00
|
|
|
GOptionEntry entries[] =
|
|
|
|
{
|
2009-04-13 02:38:01 +00:00
|
|
|
{ "app", 'a', 0, G_OPTION_ARG_STRING, &webapp,
|
|
|
|
N_("Run ADDRESS as a web application"), N_("ADDRESS") },
|
2009-11-10 22:34:25 +00:00
|
|
|
#if !HAVE_HILDON
|
2009-04-09 17:28:36 +00:00
|
|
|
{ "config", 'c', 0, G_OPTION_ARG_FILENAME, &config,
|
|
|
|
N_("Use FOLDER as configuration folder"), N_("FOLDER") },
|
2009-11-10 22:34:25 +00:00
|
|
|
#endif
|
2009-12-21 15:15:41 +00:00
|
|
|
{ "diagnostic-dialog", 'd', 0, G_OPTION_ARG_NONE, &diagnostic_dialog,
|
|
|
|
N_("Show a diagnostic dialog"), NULL },
|
2008-10-16 18:54:26 +00:00
|
|
|
{ "run", 'r', 0, G_OPTION_ARG_NONE, &run,
|
|
|
|
N_("Run the specified filename as javascript"), NULL },
|
2009-05-05 21:02:45 +00:00
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 6)
|
2009-05-04 00:09:46 +00:00
|
|
|
{ "snapshot", 's', 0, G_OPTION_ARG_STRING, &snapshot,
|
|
|
|
N_("Take a snapshot of the specified URI"), NULL },
|
2009-05-05 21:02:45 +00:00
|
|
|
#endif
|
2009-06-16 21:31:35 +00:00
|
|
|
{ "execute", 'e', 0, G_OPTION_ARG_NONE, &execute,
|
|
|
|
N_("Execute the specified command"), NULL },
|
2008-11-22 00:45:47 +00:00
|
|
|
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version,
|
2008-04-16 23:38:22 +00:00
|
|
|
N_("Display program version"), NULL },
|
2008-09-10 17:18:16 +00:00
|
|
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
2009-01-04 18:21:25 +00:00
|
|
|
N_("Addresses"), NULL },
|
2008-04-16 23:38:22 +00:00
|
|
|
{ NULL }
|
2007-12-16 22:20:24 +00:00
|
|
|
};
|
2008-12-12 09:20:19 +00:00
|
|
|
GString* error_messages;
|
2009-04-21 01:46:11 +00:00
|
|
|
gchar** extensions;
|
2008-12-12 09:20:19 +00:00
|
|
|
MidoriWebSettings* settings;
|
|
|
|
gchar* config_file;
|
2008-06-14 00:23:33 +00:00
|
|
|
MidoriStartup load_on_startup;
|
2008-08-25 23:19:38 +00:00
|
|
|
KatzeArray* search_engines;
|
2008-10-01 02:00:16 +00:00
|
|
|
KatzeArray* bookmarks;
|
2008-10-07 00:19:33 +00:00
|
|
|
KatzeArray* history;
|
2008-10-01 02:00:16 +00:00
|
|
|
KatzeArray* _session;
|
|
|
|
KatzeArray* trash;
|
2008-12-24 23:41:11 +00:00
|
|
|
guint i;
|
2008-09-10 17:18:16 +00:00
|
|
|
gchar* uri;
|
2008-10-01 02:00:16 +00:00
|
|
|
KatzeItem* item;
|
2008-09-10 17:18:16 +00:00
|
|
|
gchar* uri_ready;
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-10-07 00:19:33 +00:00
|
|
|
sqlite3* db;
|
2008-10-15 23:31:47 +00:00
|
|
|
gint max_history_age;
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2009-07-28 21:12:35 +00:00
|
|
|
gint clear_prefs = MIDORI_CLEAR_NONE;
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2008-08-23 21:44:55 +00:00
|
|
|
#if ENABLE_NLS
|
2009-01-22 00:59:23 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2009-10-03 00:27:51 +00:00
|
|
|
if (g_getenv ("MIDORI_NLSPATH"))
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, g_getenv ("MIDORI_NLSPATH"));
|
2009-01-22 00:59:23 +00:00
|
|
|
else
|
2009-07-20 07:51:29 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
{
|
|
|
|
gchar* path = sokoke_find_data_filename ("locale");
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, path);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
#else
|
2009-01-22 00:59:23 +00:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
2009-07-20 07:51:29 +00:00
|
|
|
#endif
|
2008-08-15 00:03:55 +00:00
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
#endif
|
2008-06-14 00:23:33 +00:00
|
|
|
|
2009-10-31 03:46:23 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2009-11-17 17:57:32 +00:00
|
|
|
#ifdef SIGHUP
|
2009-10-31 03:46:23 +00:00
|
|
|
signal (SIGHUP, &signal_handler);
|
2009-11-17 17:57:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
2009-10-31 03:46:23 +00:00
|
|
|
signal (SIGINT, &signal_handler);
|
2009-11-17 17:57:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
2009-10-31 03:46:23 +00:00
|
|
|
signal (SIGTERM, &signal_handler);
|
2009-11-17 17:57:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2009-10-31 03:46:23 +00:00
|
|
|
signal (SIGQUIT, &signal_handler);
|
|
|
|
#endif
|
2009-11-17 17:57:32 +00:00
|
|
|
#endif
|
2009-10-31 03:46:23 +00:00
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
/* Parse cli options */
|
2009-04-13 02:38:01 +00:00
|
|
|
webapp = NULL;
|
2009-04-09 17:28:36 +00:00
|
|
|
config = NULL;
|
2009-12-22 00:07:01 +00:00
|
|
|
diagnostic_dialog = FALSE;
|
2008-10-16 18:54:26 +00:00
|
|
|
run = FALSE;
|
2009-05-04 00:09:46 +00:00
|
|
|
snapshot = NULL;
|
2009-06-16 21:31:35 +00:00
|
|
|
execute = FALSE;
|
2008-06-14 00:23:33 +00:00
|
|
|
version = FALSE;
|
2008-09-10 17:18:16 +00:00
|
|
|
uris = NULL;
|
2008-06-14 00:23:33 +00:00
|
|
|
error = NULL;
|
2009-01-04 18:21:25 +00:00
|
|
|
if (!gtk_init_with_args (&argc, &argv, _("[Addresses]"), entries,
|
2008-04-28 20:38:57 +00:00
|
|
|
GETTEXT_PACKAGE, &error))
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-09-23 15:16:22 +00:00
|
|
|
g_print ("%s - %s\n", _("Midori"), error->message);
|
2008-04-28 20:38:57 +00:00
|
|
|
g_error_free (error);
|
2007-12-16 22:20:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-31 16:20:31 +00:00
|
|
|
/* libSoup uses threads, so we need to initialize threads. */
|
2008-10-19 22:13:41 +00:00
|
|
|
if (!g_thread_supported ()) g_thread_init (NULL);
|
2009-02-21 21:36:03 +00:00
|
|
|
sokoke_register_stock_items ();
|
2008-10-11 03:46:26 +00:00
|
|
|
g_set_application_name (_("Midori"));
|
2008-10-15 01:07:38 +00:00
|
|
|
|
2008-04-28 20:38:57 +00:00
|
|
|
if (version)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-04-28 20:38:57 +00:00
|
|
|
g_print (
|
2008-06-07 23:16:06 +00:00
|
|
|
"%s %s\n\n"
|
2009-03-01 20:00:06 +00:00
|
|
|
"Copyright (c) 2007-2009 Christian Dywan\n\n"
|
2008-03-22 02:38:23 +00:00
|
|
|
"%s\n"
|
2008-06-07 23:16:06 +00:00
|
|
|
"\t%s\n\n"
|
2008-03-22 02:38:23 +00:00
|
|
|
"%s\n"
|
2008-08-18 21:50:20 +00:00
|
|
|
"\thttp://www.twotoasts.de\n",
|
2008-08-01 13:43:24 +00:00
|
|
|
_("Midori"), PACKAGE_VERSION,
|
2008-03-22 02:38:23 +00:00
|
|
|
_("Please report comments, suggestions and bugs to:"),
|
|
|
|
PACKAGE_BUGREPORT,
|
|
|
|
_("Check for new versions at:")
|
|
|
|
);
|
2007-12-16 22:20:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-05 21:02:45 +00:00
|
|
|
#if WEBKIT_CHECK_VERSION (1, 1, 6)
|
2009-05-04 00:09:46 +00:00
|
|
|
if (snapshot)
|
|
|
|
{
|
|
|
|
gchar* filename;
|
|
|
|
gint fd;
|
|
|
|
GtkWidget* web_view;
|
|
|
|
|
|
|
|
fd = g_file_open_tmp ("snapshot-XXXXXX.pdf", &filename, &error);
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_error ("%s", error->message);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_unlink (filename) == -1)
|
|
|
|
{
|
|
|
|
g_error ("%s", g_strerror (errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
web_view = webkit_web_view_new ();
|
|
|
|
g_signal_connect (web_view, "load-finished",
|
|
|
|
G_CALLBACK (snapshot_load_finished_cb), filename);
|
|
|
|
webkit_web_view_open (WEBKIT_WEB_VIEW (web_view), snapshot);
|
|
|
|
gtk_main ();
|
|
|
|
g_free (filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-05-05 21:02:45 +00:00
|
|
|
#endif
|
2009-05-04 00:09:46 +00:00
|
|
|
|
2009-04-13 02:38:01 +00:00
|
|
|
/* Web Application support */
|
|
|
|
if (webapp)
|
|
|
|
{
|
|
|
|
MidoriBrowser* browser = midori_browser_new ();
|
|
|
|
settings = katze_object_get_object (browser, "settings");
|
|
|
|
g_object_set (settings,
|
|
|
|
"show-menubar", FALSE,
|
|
|
|
"show-navigationbar", TRUE,
|
|
|
|
"toolbar-items", "Back,Forward,ReloadStop,Location",
|
2009-07-19 16:31:13 +00:00
|
|
|
"homepage", NULL,
|
2009-04-13 02:38:01 +00:00
|
|
|
"show-statusbar", TRUE,
|
|
|
|
NULL);
|
|
|
|
g_object_unref (settings);
|
|
|
|
g_object_set (browser, "settings", settings, NULL);
|
2009-12-07 19:58:07 +00:00
|
|
|
sokoke_set_config_dir ("/");
|
2009-07-16 21:45:45 +00:00
|
|
|
g_signal_connect (browser, "notify::load-status",
|
|
|
|
G_CALLBACK (midori_web_app_browser_notify_load_status_cb), NULL);
|
2009-04-13 02:38:01 +00:00
|
|
|
midori_browser_add_uri (browser, webapp);
|
|
|
|
g_object_set_data (G_OBJECT (browser), "locked", (void*)1);
|
2009-12-07 19:41:13 +00:00
|
|
|
g_signal_connect (browser, "quit",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
2009-04-13 02:38:01 +00:00
|
|
|
g_signal_connect (browser, "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
|
|
|
gtk_widget_show (GTK_WIDGET (browser));
|
|
|
|
midori_browser_activate_action (browser, "Location");
|
2009-12-07 19:44:29 +00:00
|
|
|
if (execute)
|
2009-12-07 19:52:32 +00:00
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
while (uris[i] != NULL)
|
|
|
|
{
|
|
|
|
midori_browser_activate_action (browser, uris[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-13 02:38:01 +00:00
|
|
|
gtk_main ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
/* Standalone javascript support */
|
2008-10-16 18:54:26 +00:00
|
|
|
if (run)
|
2008-12-24 23:41:11 +00:00
|
|
|
return midori_run_script (uris ? *uris : NULL);
|
2008-05-05 22:51:04 +00:00
|
|
|
|
2009-04-09 18:26:06 +00:00
|
|
|
if (config && !g_path_is_absolute (config))
|
|
|
|
{
|
|
|
|
g_critical (_("The specified configuration folder is invalid."));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
sokoke_set_config_dir (config);
|
|
|
|
if (config)
|
|
|
|
{
|
|
|
|
gchar* name_hash;
|
|
|
|
gchar* app_name;
|
|
|
|
name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
|
|
|
|
app_name = g_strconcat ("midori", "_", name_hash, NULL);
|
|
|
|
g_free (name_hash);
|
|
|
|
app = g_object_new (MIDORI_TYPE_APP, "name", app_name, NULL);
|
|
|
|
g_free (app_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
app = midori_app_new ();
|
|
|
|
g_free (config);
|
|
|
|
|
2008-12-12 09:20:19 +00:00
|
|
|
/* FIXME: The app might be 'running' but actually showing a dialog
|
|
|
|
after a crash, so running a new window isn't a good idea. */
|
2008-08-22 01:59:07 +00:00
|
|
|
if (midori_app_instance_is_running (app))
|
|
|
|
{
|
2009-01-11 20:16:02 +00:00
|
|
|
GtkWidget* dialog;
|
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
if (execute)
|
|
|
|
result = midori_app_send_command (app, uris);
|
2009-08-13 21:55:15 +00:00
|
|
|
else if (uris)
|
|
|
|
{
|
|
|
|
/* TODO: Open a tab per URI, seperated by pipes */
|
|
|
|
/* FIXME: Handle relative files or magic URI here */
|
2009-10-04 01:12:10 +00:00
|
|
|
/* Encode any IDN addresses because libUnique doesn't like them */
|
|
|
|
i = 0;
|
|
|
|
while (uris[i] != NULL)
|
|
|
|
{
|
2009-10-10 09:09:10 +00:00
|
|
|
gchar* new_uri = sokoke_uri_to_ascii (uris[i]);
|
|
|
|
katze_assign (uris[i], new_uri);
|
2009-10-04 01:12:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
2008-09-10 17:48:45 +00:00
|
|
|
result = midori_app_instance_send_uris (app, uris);
|
2009-08-13 21:55:15 +00:00
|
|
|
}
|
2008-08-22 01:59:07 +00:00
|
|
|
else
|
2008-09-10 17:48:45 +00:00
|
|
|
result = midori_app_instance_send_new_browser (app);
|
2008-08-22 01:59:07 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
return 0;
|
|
|
|
|
2009-01-11 20:16:02 +00:00
|
|
|
dialog = gtk_message_dialog_new (NULL,
|
|
|
|
0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s",
|
|
|
|
_("An instance of Midori is already running but not responding.\n"));
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_DELETE_EVENT)
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
/* FIXME: Allow killing the existing instance */
|
2008-08-22 01:59:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-11-18 18:13:07 +00:00
|
|
|
katze_mkdir_with_parents (sokoke_set_config_dir (NULL), 0700);
|
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
/* Load configuration files */
|
2008-12-12 09:20:19 +00:00
|
|
|
error_messages = g_string_new (NULL);
|
|
|
|
config_file = build_config_filename ("config");
|
2007-12-16 22:20:24 +00:00
|
|
|
error = NULL;
|
2009-04-21 01:46:11 +00:00
|
|
|
settings = settings_new_from_file (config_file, &extensions);
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("accels"));
|
2009-12-19 09:39:24 +00:00
|
|
|
if (g_access (config_file, F_OK) != 0)
|
2009-11-30 18:24:48 +00:00
|
|
|
katze_assign (config_file, sokoke_find_config_filename (NULL, "accels"));
|
2008-04-13 19:51:43 +00:00
|
|
|
gtk_accel_map_load (config_file);
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("search"));
|
2007-12-16 22:20:24 +00:00
|
|
|
error = NULL;
|
2008-06-14 00:23:33 +00:00
|
|
|
search_engines = search_engines_new_from_file (config_file, &error);
|
2009-01-31 18:31:50 +00:00
|
|
|
/* We ignore for instance empty files */
|
2009-02-16 02:05:25 +00:00
|
|
|
if (error && (error->code == G_KEY_FILE_ERROR_PARSE
|
|
|
|
|| error->code == G_FILE_ERROR_NOENT))
|
2009-01-31 18:31:50 +00:00
|
|
|
{
|
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
|
|
|
}
|
2009-01-31 18:07:27 +00:00
|
|
|
if (!error && katze_array_is_empty (search_engines))
|
|
|
|
{
|
2009-07-20 07:27:47 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gchar* dir;
|
|
|
|
|
|
|
|
dir = g_win32_get_package_installation_directory_of_module (NULL);
|
|
|
|
katze_assign (config_file,
|
|
|
|
g_build_filename (dir, "etc", "xdg", PACKAGE_NAME, "search", NULL));
|
|
|
|
g_free (dir);
|
|
|
|
search_engines = search_engines_new_from_file (config_file, NULL);
|
|
|
|
#else
|
2009-08-27 21:32:13 +00:00
|
|
|
katze_assign (config_file,
|
2009-10-02 21:07:36 +00:00
|
|
|
sokoke_find_config_filename (NULL, "search"));
|
2009-08-27 21:32:13 +00:00
|
|
|
search_engines = search_engines_new_from_file (config_file, NULL);
|
2009-07-20 07:27:47 +00:00
|
|
|
#endif
|
2009-01-31 18:07:27 +00:00
|
|
|
}
|
|
|
|
else if (error)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
if (error->code != G_FILE_ERROR_NOENT)
|
2008-04-13 19:51:43 +00:00
|
|
|
g_string_append_printf (error_messages,
|
|
|
|
_("The search engines couldn't be loaded. %s\n"),
|
2009-01-31 18:07:27 +00:00
|
|
|
error->message);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_error_free (error);
|
2007-12-16 22:20:24 +00:00
|
|
|
}
|
2008-11-18 21:26:06 +00:00
|
|
|
bookmarks = katze_array_new (KATZE_TYPE_ARRAY);
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_LIBXML
|
2009-11-29 22:50:59 +00:00
|
|
|
katze_assign (config_file, build_config_filename (BOOKMARK_FILE));
|
2007-12-16 22:20:24 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_from_file (bookmarks, config_file, "xbel", &error))
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2009-08-27 21:32:13 +00:00
|
|
|
if (error->code == G_FILE_ERROR_NOENT)
|
|
|
|
{
|
|
|
|
katze_assign (config_file,
|
2009-10-02 21:07:36 +00:00
|
|
|
sokoke_find_config_filename (NULL, "bookmarks.xbel"));
|
2009-08-27 21:32:13 +00:00
|
|
|
midori_array_from_file (bookmarks, config_file, "xbel", NULL);
|
|
|
|
}
|
|
|
|
else
|
2008-04-13 19:51:43 +00:00
|
|
|
g_string_append_printf (error_messages,
|
2008-11-02 23:17:43 +00:00
|
|
|
_("The bookmarks couldn't be loaded: %s\n"), error->message);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_error_free (error);
|
2007-12-16 22:20:24 +00:00
|
|
|
}
|
2008-11-18 21:26:06 +00:00
|
|
|
#endif
|
2008-10-01 02:00:16 +00:00
|
|
|
_session = katze_array_new (KATZE_TYPE_ITEM);
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_LIBXML
|
2008-04-16 23:38:22 +00:00
|
|
|
g_object_get (settings, "load-on-startup", &load_on_startup, NULL);
|
|
|
|
if (load_on_startup == MIDORI_STARTUP_LAST_OPEN_PAGES)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("session.xbel"));
|
2007-12-16 22:20:24 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_from_file (_session, config_file, "xbel", &error))
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-04-13 19:51:43 +00:00
|
|
|
if (error->code != G_FILE_ERROR_NOENT)
|
|
|
|
g_string_append_printf (error_messages,
|
2008-11-02 23:17:43 +00:00
|
|
|
_("The session couldn't be loaded: %s\n"), error->message);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_error_free (error);
|
2007-12-16 22:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-18 21:26:06 +00:00
|
|
|
#endif
|
2008-10-01 02:00:16 +00:00
|
|
|
trash = katze_array_new (KATZE_TYPE_ITEM);
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_LIBXML
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("tabtrash.xbel"));
|
2007-12-16 22:20:24 +00:00
|
|
|
error = NULL;
|
2009-03-31 16:09:04 +00:00
|
|
|
if (!midori_array_from_file (trash, config_file, "xbel", &error))
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-04-13 19:51:43 +00:00
|
|
|
if (error->code != G_FILE_ERROR_NOENT)
|
2008-07-06 14:13:42 +00:00
|
|
|
g_string_append_printf (error_messages,
|
2008-11-02 23:17:43 +00:00
|
|
|
_("The trash couldn't be loaded: %s\n"), error->message);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_error_free (error);
|
2007-12-16 22:20:24 +00:00
|
|
|
}
|
2008-11-18 21:26:06 +00:00
|
|
|
#endif
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-12-12 09:20:19 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("history.db"));
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2008-10-07 00:19:33 +00:00
|
|
|
history = katze_array_new (KATZE_TYPE_ARRAY);
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-10-07 00:19:33 +00:00
|
|
|
error = NULL;
|
|
|
|
if ((db = midori_history_initialize (history, config_file, &error)) == NULL)
|
|
|
|
{
|
|
|
|
g_string_append_printf (error_messages,
|
2008-11-02 23:17:43 +00:00
|
|
|
_("The history couldn't be loaded: %s\n"), error->message);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2008-06-14 00:23:33 +00:00
|
|
|
/* In case of errors */
|
2008-04-13 19:51:43 +00:00
|
|
|
if (error_messages->len)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-07-06 14:13:42 +00:00
|
|
|
GdkScreen* screen;
|
|
|
|
GtkIconTheme* icon_theme;
|
2008-06-14 00:23:33 +00:00
|
|
|
GtkWidget* dialog = gtk_message_dialog_new (
|
|
|
|
NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE,
|
|
|
|
_("The following errors occured:"));
|
|
|
|
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), g_get_application_name ());
|
2008-07-06 14:13:42 +00:00
|
|
|
screen = gtk_widget_get_screen (dialog);
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
if (gtk_icon_theme_has_icon (icon_theme, "midori"))
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), "midori");
|
|
|
|
else
|
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser");
|
|
|
|
}
|
2008-06-14 00:23:33 +00:00
|
|
|
gtk_message_dialog_format_secondary_text (
|
|
|
|
GTK_MESSAGE_DIALOG (dialog), "%s", error_messages->str);
|
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2008-11-30 01:08:28 +00:00
|
|
|
_("_Ignore"), GTK_RESPONSE_ACCEPT,
|
2008-06-14 00:23:33 +00:00
|
|
|
NULL);
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-06-14 00:23:33 +00:00
|
|
|
g_object_unref (settings);
|
|
|
|
g_object_unref (search_engines);
|
2008-10-01 02:00:16 +00:00
|
|
|
g_object_unref (bookmarks);
|
|
|
|
g_object_unref (_session);
|
|
|
|
g_object_unref (trash);
|
2008-10-07 00:19:33 +00:00
|
|
|
g_object_unref (history);
|
2008-06-14 00:23:33 +00:00
|
|
|
g_string_free (error_messages, TRUE);
|
2007-12-16 22:20:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-06-14 00:23:33 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
2007-12-16 22:20:24 +00:00
|
|
|
/* FIXME: Since we will overwrite files that could not be loaded
|
|
|
|
, would we want to make backups? */
|
|
|
|
}
|
2008-04-13 19:51:43 +00:00
|
|
|
g_string_free (error_messages, TRUE);
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
/* If -e or --execute was specified, "uris" refers to the command. */
|
|
|
|
if (!execute)
|
|
|
|
{
|
2008-09-10 17:18:16 +00:00
|
|
|
/* Open as many tabs as we have uris, seperated by pipes */
|
|
|
|
i = 0;
|
|
|
|
while (uris && uris[i])
|
2007-12-16 22:20:24 +00:00
|
|
|
{
|
2008-09-10 17:18:16 +00:00
|
|
|
uri = strtok (g_strdup (uris[i]), "|");
|
|
|
|
while (uri != NULL)
|
|
|
|
{
|
2008-10-01 02:00:16 +00:00
|
|
|
item = katze_item_new ();
|
2009-08-13 21:55:15 +00:00
|
|
|
/* Construct an absolute path if the file is relative */
|
2009-11-02 21:33:37 +00:00
|
|
|
if (g_path_is_absolute (uri))
|
|
|
|
uri_ready = g_strconcat ("file://", uri, NULL);
|
|
|
|
else if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
|
2009-08-13 21:55:15 +00:00
|
|
|
{
|
|
|
|
gchar* current_dir = g_get_current_dir ();
|
|
|
|
uri_ready = g_strconcat ("file://", current_dir,
|
|
|
|
G_DIR_SEPARATOR_S, uri, NULL);
|
|
|
|
g_free (current_dir);
|
|
|
|
}
|
|
|
|
else
|
2010-01-01 21:47:24 +00:00
|
|
|
uri_ready = sokoke_magic_uri (uri, NULL, NULL);
|
2008-10-01 02:00:16 +00:00
|
|
|
katze_item_set_uri (item, uri_ready);
|
2008-09-10 17:18:16 +00:00
|
|
|
g_free (uri_ready);
|
2008-10-01 02:00:16 +00:00
|
|
|
katze_array_add_item (_session, item);
|
2008-09-10 17:18:16 +00:00
|
|
|
uri = strtok (NULL, "|");
|
|
|
|
}
|
|
|
|
g_free (uri);
|
|
|
|
i++;
|
2007-12-16 22:20:24 +00:00
|
|
|
}
|
2009-06-16 21:31:35 +00:00
|
|
|
}
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2009-02-12 22:52:14 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("config"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (settings, "notify",
|
|
|
|
G_CALLBACK (settings_notify_cb), app);
|
2009-02-12 22:52:14 +00:00
|
|
|
|
|
|
|
katze_assign (config_file, build_config_filename ("search"));
|
2009-11-18 18:13:07 +00:00
|
|
|
if (1)
|
2009-01-31 18:31:50 +00:00
|
|
|
{
|
2009-02-12 22:52:14 +00:00
|
|
|
g_signal_connect_after (search_engines, "add-item",
|
|
|
|
G_CALLBACK (midori_search_engines_modify_cb), search_engines);
|
|
|
|
g_signal_connect_after (search_engines, "remove-item",
|
|
|
|
G_CALLBACK (midori_search_engines_modify_cb), search_engines);
|
|
|
|
if (!katze_array_is_empty (search_engines))
|
2009-01-31 18:31:50 +00:00
|
|
|
{
|
2009-03-31 01:24:29 +00:00
|
|
|
i = 0;
|
|
|
|
while ((item = katze_array_get_nth_item (search_engines, i++)))
|
2009-02-12 22:52:14 +00:00
|
|
|
g_signal_connect_after (item, "notify",
|
|
|
|
G_CALLBACK (midori_search_engines_modify_cb), search_engines);
|
2009-01-31 18:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-29 22:50:59 +00:00
|
|
|
katze_assign (config_file, build_config_filename (BOOKMARK_FILE));
|
|
|
|
/* Don't save bookmarks if they are not our own */
|
|
|
|
if (!g_path_is_absolute (BOOKMARK_FILE))
|
2008-12-30 03:16:10 +00:00
|
|
|
{
|
2009-12-11 22:59:08 +00:00
|
|
|
midori_bookmarks_connect_item (NULL, (KatzeItem*)bookmarks, bookmarks);
|
2009-02-12 22:52:14 +00:00
|
|
|
g_signal_connect_after (bookmarks, "add-item",
|
|
|
|
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
|
|
|
|
g_signal_connect_after (bookmarks, "remove-item",
|
2009-04-03 23:32:02 +00:00
|
|
|
G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
|
2008-12-30 03:16:10 +00:00
|
|
|
}
|
2009-02-12 22:52:14 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("tabtrash.xbel"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (trash, "add-item",
|
|
|
|
G_CALLBACK (midori_trash_add_item_cb), NULL);
|
|
|
|
g_signal_connect_after (trash, "remove-item",
|
|
|
|
G_CALLBACK (midori_trash_remove_item_cb), NULL);
|
2009-02-22 21:39:08 +00:00
|
|
|
#if HAVE_SQLITE
|
2009-02-12 22:52:14 +00:00
|
|
|
katze_assign (config_file, build_config_filename ("history.db"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_signal_connect_after (history, "add-item",
|
|
|
|
G_CALLBACK (midori_history_add_item_cb), db);
|
|
|
|
g_signal_connect_after (history, "clear",
|
|
|
|
G_CALLBACK (midori_history_clear_cb), db);
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2007-12-16 22:20:24 +00:00
|
|
|
|
2009-08-23 22:57:44 +00:00
|
|
|
katze_item_set_parent (KATZE_ITEM (_session), app);
|
2009-08-23 22:26:26 +00:00
|
|
|
g_object_set_data (G_OBJECT (app), "extensions", extensions);
|
2008-12-12 09:20:19 +00:00
|
|
|
/* We test for the presence of a dummy file which is created once
|
|
|
|
and deleted during normal runtime, but persists in case of a crash. */
|
|
|
|
katze_assign (config_file, build_config_filename ("running"));
|
2009-12-21 15:15:41 +00:00
|
|
|
if (g_access (config_file, F_OK) == 0)
|
|
|
|
{
|
|
|
|
if (katze_object_get_boolean (settings, "show-crash-dialog"))
|
|
|
|
diagnostic_dialog = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_file_set_contents (config_file, "RUNNING", -1, NULL);
|
|
|
|
|
|
|
|
if (diagnostic_dialog)
|
2008-12-12 09:20:19 +00:00
|
|
|
{
|
2008-12-24 23:41:11 +00:00
|
|
|
GtkWidget* dialog = midori_create_diagnostic_dialog (settings, _session);
|
2008-12-12 09:20:19 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
g_signal_connect (app, "quit", G_CALLBACK (midori_app_quit_cb), NULL);
|
2008-11-18 01:07:53 +00:00
|
|
|
|
2008-11-20 00:22:25 +00:00
|
|
|
g_object_set (app, "settings", settings,
|
|
|
|
"bookmarks", bookmarks,
|
|
|
|
"trash", trash,
|
|
|
|
"search-engines", search_engines,
|
|
|
|
"history", history,
|
|
|
|
NULL);
|
2008-12-24 23:41:11 +00:00
|
|
|
g_object_unref (history);
|
|
|
|
g_object_unref (search_engines);
|
|
|
|
g_object_unref (bookmarks);
|
|
|
|
g_object_unref (trash);
|
|
|
|
g_object_unref (settings);
|
2008-11-20 02:49:57 +00:00
|
|
|
g_signal_connect (app, "add-browser",
|
|
|
|
G_CALLBACK (midori_app_add_browser_cb), NULL);
|
2008-11-20 00:22:25 +00:00
|
|
|
|
2009-03-28 02:04:27 +00:00
|
|
|
g_idle_add (midori_load_cookie_jar, settings);
|
2008-12-24 23:41:11 +00:00
|
|
|
g_idle_add (midori_load_extensions, app);
|
|
|
|
g_idle_add (midori_load_session, _session);
|
2008-07-23 18:17:13 +00:00
|
|
|
|
2009-06-16 21:31:35 +00:00
|
|
|
if (execute)
|
|
|
|
g_object_set_data (G_OBJECT (app), "execute-command", uris);
|
|
|
|
|
2008-03-10 21:26:09 +00:00
|
|
|
gtk_main ();
|
|
|
|
|
2008-12-24 23:41:11 +00:00
|
|
|
settings = katze_object_get_object (app, "settings");
|
2009-07-28 21:12:35 +00:00
|
|
|
#if HAVE_SQLITE
|
2008-10-15 23:31:47 +00:00
|
|
|
g_object_get (settings, "maximum-history-age", &max_history_age, NULL);
|
|
|
|
midori_history_terminate (db, max_history_age);
|
2008-10-13 15:50:07 +00:00
|
|
|
#endif
|
2009-07-28 21:12:35 +00:00
|
|
|
|
|
|
|
/* Clear data on quit, according to the Clear private data dialog */
|
|
|
|
g_object_get (settings, "clear-private-data", &clear_prefs, NULL);
|
2009-08-08 21:26:37 +00:00
|
|
|
if (clear_prefs & MIDORI_CLEAR_ON_QUIT)
|
2009-07-28 21:12:35 +00:00
|
|
|
{
|
2009-08-08 21:26:37 +00:00
|
|
|
#if HAVE_SQLITE
|
|
|
|
midori_remove_config_file (clear_prefs, MIDORI_CLEAR_HISTORY, "history.db");
|
|
|
|
#endif
|
|
|
|
midori_remove_config_file (clear_prefs, MIDORI_CLEAR_COOKIES, "cookies.txt");
|
|
|
|
if ((clear_prefs & MIDORI_CLEAR_FLASH_COOKIES) == MIDORI_CLEAR_FLASH_COOKIES)
|
|
|
|
{
|
|
|
|
gchar* cache = g_build_filename (g_get_home_dir (), ".macromedia",
|
|
|
|
"Flash_Player", NULL);
|
|
|
|
sokoke_remove_path (cache, TRUE);
|
|
|
|
g_free (cache);
|
|
|
|
}
|
|
|
|
if ((clear_prefs & MIDORI_CLEAR_WEBSITE_ICONS) == MIDORI_CLEAR_WEBSITE_ICONS)
|
|
|
|
{
|
|
|
|
gchar* cache = g_build_filename (g_get_user_cache_dir (),
|
|
|
|
PACKAGE_NAME, "icons", NULL);
|
|
|
|
sokoke_remove_path (cache, TRUE);
|
|
|
|
g_free (cache);
|
|
|
|
}
|
|
|
|
midori_remove_config_file (clear_prefs, MIDORI_CLEAR_TRASH, "tabtrash.xbel");
|
2009-12-02 18:02:59 +00:00
|
|
|
if ((clear_prefs & MIDORI_CLEAR_WEB_CACHE) == MIDORI_CLEAR_WEB_CACHE)
|
|
|
|
{
|
|
|
|
gchar* cache = g_build_filename (g_get_user_cache_dir (),
|
|
|
|
PACKAGE_NAME, "web", NULL);
|
|
|
|
sokoke_remove_path (cache, TRUE);
|
|
|
|
g_free (cache);
|
|
|
|
}
|
2009-07-28 21:12:35 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 21:58:13 +00:00
|
|
|
if (katze_object_get_boolean (settings, "load-on-startup")
|
|
|
|
!= MIDORI_STARTUP_LAST_OPEN_PAGES)
|
|
|
|
{
|
|
|
|
katze_assign (config_file, build_config_filename ("session.xbel"));
|
2009-11-18 18:13:07 +00:00
|
|
|
g_unlink (config_file);
|
2009-08-23 21:58:13 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 21:12:35 +00:00
|
|
|
g_object_unref (settings);
|
2008-12-24 23:41:11 +00:00
|
|
|
g_object_unref (app);
|
2008-04-13 19:51:43 +00:00
|
|
|
g_free (config_file);
|
2007-12-16 22:20:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|