2009-01-31 03:09:35 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
See the file COPYING for the full license text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "midori-bookmarks.h"
|
|
|
|
|
2010-07-01 19:21:01 +00:00
|
|
|
#include "midori-array.h"
|
2009-01-31 03:09:35 +00:00
|
|
|
#include "midori-app.h"
|
|
|
|
#include "midori-browser.h"
|
2011-10-31 21:10:39 +00:00
|
|
|
#include "midori-platform.h"
|
2009-01-31 03:09:35 +00:00
|
|
|
#include "midori-view.h"
|
2012-05-27 14:30:09 +00:00
|
|
|
#include "midori-core.h"
|
2009-01-31 03:09:35 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2009-02-06 02:01:35 +00:00
|
|
|
#include <string.h>
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2009-02-20 21:43:08 +00:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2010-07-03 05:47:41 +00:00
|
|
|
#define COMPLETION_DELAY 200
|
|
|
|
|
2010-07-02 04:50:14 +00:00
|
|
|
gboolean
|
2009-01-31 03:09:35 +00:00
|
|
|
midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
|
|
|
|
KatzeItem* bookmark,
|
2009-02-22 02:11:40 +00:00
|
|
|
gboolean new_bookmark,
|
2012-03-15 18:57:01 +00:00
|
|
|
gboolean is_folder,
|
|
|
|
GtkWidget* proxy);
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2009-11-25 22:55:12 +00:00
|
|
|
void
|
|
|
|
midori_browser_open_bookmark (MidoriBrowser* browser,
|
|
|
|
KatzeItem* item);
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
struct _MidoriBookmarks
|
|
|
|
{
|
|
|
|
GtkVBox parent_instance;
|
|
|
|
|
|
|
|
GtkWidget* toolbar;
|
|
|
|
GtkWidget* edit;
|
|
|
|
GtkWidget* delete;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
MidoriApp* app;
|
|
|
|
KatzeArray* array;
|
2010-07-03 05:47:41 +00:00
|
|
|
|
|
|
|
gint filter_timeout;
|
|
|
|
gchar* filter;
|
2009-01-31 03:09:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MidoriBookmarksClass
|
|
|
|
{
|
|
|
|
GtkVBoxClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_viewable_iface_init (MidoriViewableIface* iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MidoriBookmarks, midori_bookmarks, GTK_TYPE_VBOX,
|
|
|
|
G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE,
|
|
|
|
midori_bookmarks_viewable_iface_init));
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_APP
|
|
|
|
};
|
|
|
|
|
2009-04-05 21:46:15 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_finalize (GObject* object);
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec);
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_class_init (MidoriBookmarksClass* class)
|
|
|
|
{
|
|
|
|
GObjectClass* gobject_class;
|
|
|
|
GParamFlags flags;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2009-04-05 21:46:15 +00:00
|
|
|
gobject_class->finalize = midori_bookmarks_finalize;
|
2009-01-31 03:09:35 +00:00
|
|
|
gobject_class->set_property = midori_bookmarks_set_property;
|
|
|
|
gobject_class->get_property = midori_bookmarks_get_property;
|
|
|
|
|
|
|
|
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_APP,
|
|
|
|
g_param_spec_object (
|
|
|
|
"app",
|
|
|
|
"App",
|
|
|
|
"The app",
|
|
|
|
MIDORI_TYPE_APP,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
midori_bookmarks_get_label (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
return _("Bookmarks");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
midori_bookmarks_get_stock_id (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
return STOCK_BOOKMARKS;
|
|
|
|
}
|
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
/* TODO: Function never used */
|
2010-07-23 17:51:28 +00:00
|
|
|
void
|
2012-06-15 23:06:58 +00:00
|
|
|
midori_bookmarks_export_array_db (sqlite3* db,
|
|
|
|
KatzeArray* array,
|
|
|
|
gint64 parentid)
|
2010-07-23 17:51:28 +00:00
|
|
|
{
|
|
|
|
KatzeArray* root_array;
|
|
|
|
KatzeArray* subarray;
|
|
|
|
KatzeItem* item;
|
2011-01-22 20:17:08 +00:00
|
|
|
GList* list;
|
2012-06-15 23:06:58 +00:00
|
|
|
gchar* parent_id;
|
2010-07-23 17:51:28 +00:00
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
|
|
|
|
if (!(root_array = midori_array_query (array, "*", "parentid = %q", parent_id)))
|
|
|
|
{
|
|
|
|
g_free (parent_id);
|
2011-07-30 18:11:45 +00:00
|
|
|
return;
|
2012-06-15 23:06:58 +00:00
|
|
|
}
|
2011-01-22 20:17:08 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM_L (item, root_array, list)
|
2010-07-23 17:51:28 +00:00
|
|
|
{
|
|
|
|
if (KATZE_ITEM_IS_FOLDER (item))
|
|
|
|
{
|
|
|
|
subarray = katze_array_new (KATZE_TYPE_ARRAY);
|
|
|
|
katze_item_set_name (KATZE_ITEM (subarray), katze_item_get_name (item));
|
2012-06-15 23:06:58 +00:00
|
|
|
midori_bookmarks_export_array_db (db, subarray,
|
|
|
|
katze_item_get_meta_integer (item, "parentid"));
|
2010-07-23 17:51:28 +00:00
|
|
|
katze_array_add_item (array, subarray);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
katze_array_add_item (array, item);
|
|
|
|
}
|
2012-06-15 23:06:58 +00:00
|
|
|
|
|
|
|
g_free (parent_id);
|
2011-01-22 20:17:08 +00:00
|
|
|
g_list_free (list);
|
2010-07-23 17:51:28 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 19:40:28 +00:00
|
|
|
void
|
2012-06-15 23:06:58 +00:00
|
|
|
midori_bookmarks_import_array_db (sqlite3* db,
|
|
|
|
KatzeArray* array,
|
|
|
|
gint64 parentid)
|
2010-06-13 19:40:28 +00:00
|
|
|
{
|
2010-12-05 22:34:17 +00:00
|
|
|
GList* list;
|
2010-09-11 21:39:51 +00:00
|
|
|
KatzeItem* item;
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 id;
|
2010-06-13 19:40:28 +00:00
|
|
|
|
2011-07-30 18:11:45 +00:00
|
|
|
if (!db)
|
|
|
|
return;
|
|
|
|
|
2010-12-05 22:34:17 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
|
2010-06-13 19:40:28 +00:00
|
|
|
{
|
2012-06-15 23:06:58 +00:00
|
|
|
id = midori_bookmarks_insert_item_db (db, item, parentid);
|
2010-09-11 21:39:51 +00:00
|
|
|
if (KATZE_IS_ARRAY (item))
|
2012-06-15 23:06:58 +00:00
|
|
|
midori_bookmarks_import_array_db (db, KATZE_ARRAY (item), id);
|
2010-06-13 19:40:28 +00:00
|
|
|
}
|
2010-12-05 22:34:17 +00:00
|
|
|
g_list_free (list);
|
2010-06-13 19:40:28 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 00:45:14 +00:00
|
|
|
static KatzeArray*
|
2010-06-13 02:54:11 +00:00
|
|
|
midori_bookmarks_read_from_db (MidoriBookmarks* bookmarks,
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 parentid,
|
2010-07-03 05:47:41 +00:00
|
|
|
const gchar* keyword)
|
2010-06-13 02:54:11 +00:00
|
|
|
{
|
2011-11-22 23:23:41 +00:00
|
|
|
KatzeArray* array;
|
2011-07-30 18:11:45 +00:00
|
|
|
|
2010-07-03 05:47:41 +00:00
|
|
|
if (keyword && *keyword)
|
2011-11-22 23:23:41 +00:00
|
|
|
array = midori_array_query (bookmarks->array,
|
2012-06-15 23:06:58 +00:00
|
|
|
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword);
|
2010-07-03 05:47:41 +00:00
|
|
|
else
|
2012-06-15 23:06:58 +00:00
|
|
|
{
|
|
|
|
if (parentid > 0)
|
|
|
|
{
|
|
|
|
gchar* parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
|
|
|
|
array = midori_array_query (bookmarks->array,
|
|
|
|
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id);
|
|
|
|
|
|
|
|
g_free (parent_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
array = midori_array_query (bookmarks->array,
|
|
|
|
"id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL);
|
|
|
|
}
|
2011-11-22 23:23:41 +00:00
|
|
|
return array ? array : katze_array_new (KATZE_TYPE_ITEM);
|
2010-07-01 00:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_read_from_db_to_model (MidoriBookmarks* bookmarks,
|
|
|
|
GtkTreeStore* model,
|
|
|
|
GtkTreeIter* parent,
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 parentid,
|
2010-07-03 05:47:41 +00:00
|
|
|
const gchar* keyword)
|
2010-07-01 00:45:14 +00:00
|
|
|
{
|
|
|
|
KatzeArray* array;
|
2010-07-02 04:01:39 +00:00
|
|
|
gint last;
|
2010-07-03 05:47:41 +00:00
|
|
|
KatzeItem* item;
|
2010-07-02 04:01:39 +00:00
|
|
|
GtkTreeIter child;
|
2010-07-01 00:45:14 +00:00
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
array = midori_bookmarks_read_from_db (bookmarks, parentid, keyword);
|
2010-07-01 15:43:57 +00:00
|
|
|
katze_bookmark_populate_tree_view (array, model, parent);
|
2010-07-02 04:01:39 +00:00
|
|
|
/* Remove invisible dummy row */
|
|
|
|
last = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), parent);
|
2010-07-03 05:47:41 +00:00
|
|
|
if (!last)
|
|
|
|
return;
|
2010-07-02 04:01:39 +00:00
|
|
|
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model), &child, parent, last - 1);
|
2010-07-03 05:47:41 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model), &child, 0, &item, -1);
|
|
|
|
if (KATZE_ITEM_IS_SEPARATOR (item))
|
|
|
|
gtk_tree_store_remove (model, &child);
|
2010-07-04 21:59:01 +00:00
|
|
|
else
|
|
|
|
g_object_unref (item);
|
2010-06-13 02:54:11 +00:00
|
|
|
}
|
2010-06-13 19:40:28 +00:00
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64
|
|
|
|
midori_bookmarks_insert_item_db (sqlite3* db,
|
|
|
|
KatzeItem* item,
|
|
|
|
gint64 parentid)
|
2011-01-18 16:49:57 +00:00
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
char* errmsg = NULL;
|
|
|
|
KatzeItem* old_parent;
|
2012-06-15 23:06:58 +00:00
|
|
|
gchar* new_parentid;
|
|
|
|
gchar* id = NULL;
|
2011-12-11 01:57:04 +00:00
|
|
|
const gchar* uri = NULL;
|
|
|
|
const gchar* desc = NULL;
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 seq = 0;
|
2011-01-18 16:49:57 +00:00
|
|
|
|
2011-01-19 21:29:26 +00:00
|
|
|
/* Bookmarks must have a name, import may produce invalid items */
|
2012-06-15 23:06:58 +00:00
|
|
|
g_return_val_if_fail (katze_item_get_name (item), seq);
|
2011-01-19 20:34:39 +00:00
|
|
|
|
2011-07-30 18:11:45 +00:00
|
|
|
if (!db)
|
2012-06-15 23:06:58 +00:00
|
|
|
return seq;
|
|
|
|
|
|
|
|
if (katze_item_get_meta_integer (item, "id") > 0)
|
|
|
|
id = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer(item, "id"));
|
|
|
|
else
|
|
|
|
id = g_strdup_printf ("NULL");
|
2011-07-30 18:11:45 +00:00
|
|
|
|
2011-01-18 16:49:57 +00:00
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item))
|
2011-12-11 01:57:04 +00:00
|
|
|
uri = katze_item_get_uri (item);
|
2011-01-18 16:49:57 +00:00
|
|
|
|
2011-02-17 19:18:18 +00:00
|
|
|
if (katze_item_get_text (item))
|
2011-12-11 01:57:04 +00:00
|
|
|
desc = katze_item_get_text (item);
|
2011-02-17 19:18:18 +00:00
|
|
|
|
2011-01-18 16:49:57 +00:00
|
|
|
/* Use folder, otherwise fallback to parent folder */
|
|
|
|
old_parent = katze_item_get_parent (item);
|
2012-06-15 23:06:58 +00:00
|
|
|
if (parentid > 0)
|
|
|
|
new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, parentid);
|
|
|
|
else if (old_parent && katze_item_get_meta_integer (old_parent, "id") > 0)
|
|
|
|
new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer (old_parent, "id"));
|
2011-01-18 16:49:57 +00:00
|
|
|
else
|
2012-06-15 23:06:58 +00:00
|
|
|
new_parentid = g_strdup_printf ("NULL");
|
2011-01-18 16:49:57 +00:00
|
|
|
|
|
|
|
sqlcmd = sqlite3_mprintf (
|
2012-06-15 23:06:58 +00:00
|
|
|
"INSERT INTO bookmarks (id, parentid, title, uri, desc, toolbar, app) "
|
|
|
|
"VALUES (%q, %q, '%q', '%q', '%q', %d, %d)",
|
|
|
|
id,
|
|
|
|
new_parentid,
|
2011-01-18 16:49:57 +00:00
|
|
|
katze_item_get_name (item),
|
2012-06-15 23:06:58 +00:00
|
|
|
katze_str_non_null (uri),
|
|
|
|
katze_str_non_null (desc),
|
2011-01-18 16:49:57 +00:00
|
|
|
katze_item_get_meta_boolean (item, "toolbar"),
|
|
|
|
katze_item_get_meta_boolean (item, "app"));
|
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) == SQLITE_OK)
|
|
|
|
{
|
|
|
|
/* Get insert id */
|
|
|
|
if (g_str_equal (id, "NULL"))
|
|
|
|
{
|
|
|
|
KatzeArray* seq_array;
|
|
|
|
|
|
|
|
sqlite3_free (sqlcmd);
|
|
|
|
sqlcmd = sqlite3_mprintf (
|
|
|
|
"SELECT seq FROM sqlite_sequence WHERE name = 'bookmarks'");
|
|
|
|
|
|
|
|
seq_array = katze_array_from_sqlite (db, sqlcmd);
|
|
|
|
if (katze_array_get_nth_item (seq_array, 0))
|
|
|
|
{
|
|
|
|
KatzeItem* seq_item = katze_array_get_nth_item (seq_array, 0);
|
|
|
|
|
|
|
|
seq = katze_item_get_meta_integer (seq_item, "seq");
|
|
|
|
katze_item_set_meta_integer (item, "id", seq);
|
|
|
|
}
|
|
|
|
g_object_unref (seq_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-01-18 16:49:57 +00:00
|
|
|
{
|
|
|
|
g_printerr (_("Failed to add bookmark item: %s\n"), errmsg);
|
|
|
|
sqlite3_free (errmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_free (sqlcmd);
|
2012-06-15 23:06:58 +00:00
|
|
|
g_free (new_parentid);
|
|
|
|
g_free (id);
|
|
|
|
|
|
|
|
return seq;
|
2011-01-18 16:49:57 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 15:49:20 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_add_item_cb (KatzeArray* array,
|
|
|
|
KatzeItem* item,
|
|
|
|
MidoriBookmarks* bookmarks)
|
2010-06-13 19:40:28 +00:00
|
|
|
{
|
2010-11-21 15:49:20 +00:00
|
|
|
GtkTreeModel* model;
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
2012-06-15 23:06:58 +00:00
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks,
|
|
|
|
GTK_TREE_STORE (model), NULL, 0, bookmarks->filter);
|
2010-06-13 19:40:28 +00:00
|
|
|
}
|
|
|
|
|
2010-08-10 21:46:49 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_remove_item_cb (KatzeArray* array,
|
|
|
|
KatzeItem* item,
|
|
|
|
MidoriBookmarks* bookmarks)
|
2010-06-13 19:40:28 +00:00
|
|
|
{
|
2010-08-10 21:46:49 +00:00
|
|
|
GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks,
|
2012-06-15 23:06:58 +00:00
|
|
|
GTK_TREE_STORE (model), NULL, 0, bookmarks->filter);
|
2010-06-13 19:40:28 +00:00
|
|
|
}
|
2010-06-13 02:54:11 +00:00
|
|
|
|
2011-01-19 20:58:26 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_update_cb (KatzeArray* array,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks,
|
2012-06-15 23:06:58 +00:00
|
|
|
GTK_TREE_STORE (model), NULL, 0, bookmarks->filter);
|
2011-01-19 20:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-16 21:16:25 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_row_changed_cb (GtkTreeModel* model,
|
|
|
|
GtkTreePath* path,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
GtkTreeIter parent;
|
2011-12-11 01:57:04 +00:00
|
|
|
KatzeItem* new_parent = NULL;
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 parentid;
|
2010-06-16 21:16:25 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_parent (model, &parent, iter))
|
|
|
|
{
|
2010-07-03 21:05:09 +00:00
|
|
|
gtk_tree_model_get (model, &parent, 0, &new_parent, -1);
|
|
|
|
|
|
|
|
/* Bookmarks must not be moved into non-folder items */
|
|
|
|
if (!KATZE_ITEM_IS_FOLDER (new_parent))
|
2012-06-15 23:06:58 +00:00
|
|
|
parentid = 0;
|
2010-07-03 21:05:09 +00:00
|
|
|
else
|
2012-06-15 23:06:58 +00:00
|
|
|
parentid = katze_item_get_meta_integer (new_parent, "id");
|
2010-06-16 21:16:25 +00:00
|
|
|
}
|
|
|
|
else
|
2012-06-15 23:06:58 +00:00
|
|
|
parentid = 0;
|
2010-06-16 21:16:25 +00:00
|
|
|
|
2010-08-10 21:46:49 +00:00
|
|
|
katze_array_remove_item (bookmarks->array, item);
|
2012-06-15 23:06:58 +00:00
|
|
|
katze_item_set_meta_integer (item, "parentid", parentid);
|
2010-11-21 15:49:20 +00:00
|
|
|
katze_array_add_item (bookmarks->array, item);
|
2011-12-11 01:57:04 +00:00
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
if (new_parent)
|
|
|
|
g_object_unref (new_parent);
|
2010-06-16 21:16:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_add_clicked_cb (GtkWidget* toolitem)
|
|
|
|
{
|
2009-04-23 02:13:19 +00:00
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (toolitem);
|
2009-01-31 03:09:35 +00:00
|
|
|
/* FIXME: Take selected folder into account */
|
2010-06-25 04:11:36 +00:00
|
|
|
if (g_str_equal (gtk_widget_get_name (toolitem), "BookmarkFolderAdd"))
|
2012-03-15 18:57:01 +00:00
|
|
|
midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, TRUE, toolitem);
|
2010-06-25 04:11:36 +00:00
|
|
|
else
|
2012-03-15 18:57:01 +00:00
|
|
|
midori_browser_edit_bookmark_dialog_new (browser, NULL, TRUE, FALSE, toolitem);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_edit_clicked_cb (GtkWidget* toolitem,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview),
|
|
|
|
&model, &iter))
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
2010-06-30 22:13:18 +00:00
|
|
|
MidoriBrowser* browser;
|
2012-06-15 23:06:58 +00:00
|
|
|
gint64 parentid;
|
2009-01-31 03:09:35 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
|
2010-07-01 15:43:57 +00:00
|
|
|
g_assert (!KATZE_ITEM_IS_SEPARATOR (item));
|
2010-06-30 22:13:18 +00:00
|
|
|
|
2010-07-02 04:50:14 +00:00
|
|
|
browser = midori_browser_get_for_widget (bookmarks->treeview);
|
2012-06-15 23:06:58 +00:00
|
|
|
parentid = katze_item_get_meta_integer (item, "parentid");
|
2010-07-19 20:58:18 +00:00
|
|
|
midori_browser_edit_bookmark_dialog_new (
|
2012-03-15 18:57:01 +00:00
|
|
|
browser, item, FALSE, KATZE_ITEM_IS_FOLDER (item), NULL);
|
2012-06-15 23:06:58 +00:00
|
|
|
|
|
|
|
if (katze_item_get_meta_integer (item, "parentid") != parentid)
|
|
|
|
{
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model),
|
|
|
|
NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-20 21:43:08 +00:00
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 00:55:22 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_toolbar_update (MidoriBookmarks *bookmarks)
|
|
|
|
{
|
|
|
|
gboolean selected;
|
|
|
|
|
|
|
|
selected = katze_tree_view_get_selected_iter (
|
|
|
|
GTK_TREE_VIEW (bookmarks->treeview), NULL, NULL);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->delete), selected);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->edit), selected);
|
|
|
|
}
|
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
gboolean
|
|
|
|
midori_bookmarks_update_item_db (sqlite3* db,
|
|
|
|
KatzeItem* item)
|
|
|
|
{
|
|
|
|
gchar* sqlcmd;
|
|
|
|
char* errmsg = NULL;
|
|
|
|
gchar* parentid;
|
|
|
|
gboolean updated;
|
|
|
|
|
|
|
|
if (katze_item_get_meta_integer (item, "parentid") > 0)
|
|
|
|
parentid = g_strdup_printf ("%" G_GINT64_FORMAT,
|
|
|
|
katze_item_get_meta_integer (item, "parentid"));
|
|
|
|
else
|
|
|
|
parentid = g_strdup_printf ("NULL");
|
|
|
|
|
|
|
|
sqlcmd = sqlite3_mprintf (
|
|
|
|
"UPDATE bookmarks SET "
|
|
|
|
"parentid=%q, title='%q', uri='%q', desc='%q', toolbar=%d, app=%d "
|
|
|
|
"WHERE id = %" G_GINT64_FORMAT ";",
|
|
|
|
parentid,
|
|
|
|
katze_item_get_name (item),
|
|
|
|
katze_str_non_null (katze_item_get_uri (item)),
|
|
|
|
katze_str_non_null (katze_item_get_meta_string (item, "desc")),
|
|
|
|
katze_item_get_meta_boolean (item, "toolbar"),
|
|
|
|
katze_item_get_meta_boolean (item, "app"),
|
|
|
|
katze_item_get_meta_integer (item, "id"));
|
|
|
|
|
|
|
|
updated = TRUE;
|
|
|
|
if (sqlite3_exec (db, sqlcmd, NULL, NULL, &errmsg) != SQLITE_OK)
|
|
|
|
{
|
|
|
|
updated = FALSE;
|
|
|
|
g_printerr (_("Failed to update bookmark : %s\n"), errmsg);
|
|
|
|
sqlite3_free (errmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_free (sqlcmd);
|
|
|
|
g_free (parentid);
|
|
|
|
|
|
|
|
return updated;
|
|
|
|
}
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_delete_clicked_cb (GtkWidget* toolitem,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
2010-06-13 20:33:23 +00:00
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview),
|
|
|
|
&model, &iter))
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
|
2010-08-10 21:46:49 +00:00
|
|
|
/* Manually remove the iter and block clearing the treeview */
|
2010-06-13 19:40:28 +00:00
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
|
2010-08-10 21:46:49 +00:00
|
|
|
g_signal_handlers_block_by_func (bookmarks->array,
|
|
|
|
midori_bookmarks_remove_item_cb, bookmarks);
|
|
|
|
katze_array_remove_item (bookmarks->array, item);
|
|
|
|
g_signal_handlers_unblock_by_func (bookmarks->array,
|
|
|
|
midori_bookmarks_remove_item_cb, bookmarks);
|
2009-02-20 21:43:08 +00:00
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
midori_bookmarks_get_toolbar (MidoriViewable* viewable)
|
|
|
|
{
|
|
|
|
MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (viewable);
|
|
|
|
|
|
|
|
if (!bookmarks->toolbar)
|
|
|
|
{
|
|
|
|
GtkWidget* toolbar;
|
|
|
|
GtkToolItem* toolitem;
|
|
|
|
|
|
|
|
toolbar = gtk_toolbar_new ();
|
|
|
|
gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON);
|
2010-12-11 18:49:05 +00:00
|
|
|
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
|
2009-01-31 03:09:35 +00:00
|
|
|
bookmarks->toolbar = toolbar;
|
2012-07-11 16:36:58 +00:00
|
|
|
toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK_ADD);
|
2010-06-25 04:11:36 +00:00
|
|
|
gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkAdd");
|
2009-01-31 03:09:35 +00:00
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Add a new bookmark"));
|
|
|
|
gtk_tool_item_set_is_important (toolitem, TRUE);
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
|
|
|
G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_EDIT);
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Edit the selected bookmark"));
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
|
|
|
G_CALLBACK (midori_bookmarks_edit_clicked_cb), bookmarks);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
bookmarks->edit = GTK_WIDGET (toolitem);
|
|
|
|
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE);
|
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Delete the selected bookmark"));
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
|
|
|
G_CALLBACK (midori_bookmarks_delete_clicked_cb), bookmarks);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
bookmarks->delete = GTK_WIDGET (toolitem);
|
2011-03-18 00:55:22 +00:00
|
|
|
midori_bookmarks_toolbar_update (bookmarks);
|
2009-02-22 02:11:40 +00:00
|
|
|
toolitem = gtk_separator_tool_item_new ();
|
|
|
|
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem), FALSE);
|
|
|
|
gtk_tool_item_set_expand (toolitem, TRUE);
|
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
2009-12-02 22:11:59 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
2012-07-11 16:36:58 +00:00
|
|
|
toolitem = gtk_tool_button_new_from_stock (STOCK_FOLDER_NEW);
|
2010-06-25 04:11:36 +00:00
|
|
|
gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkFolderAdd");
|
2009-02-22 02:11:40 +00:00
|
|
|
gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem),
|
|
|
|
_("Add a new folder"));
|
|
|
|
g_signal_connect (toolitem, "clicked",
|
2010-06-25 04:11:36 +00:00
|
|
|
G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks);
|
2009-02-22 02:11:40 +00:00
|
|
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
|
|
|
|
gtk_widget_show (GTK_WIDGET (toolitem));
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
g_signal_connect (bookmarks->edit, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &bookmarks->edit);
|
|
|
|
g_signal_connect (bookmarks->delete, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &bookmarks->delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bookmarks->toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_viewable_iface_init (MidoriViewableIface* iface)
|
|
|
|
{
|
|
|
|
iface->get_stock_id = midori_bookmarks_get_stock_id;
|
|
|
|
iface->get_label = midori_bookmarks_get_label;
|
|
|
|
iface->get_toolbar = midori_bookmarks_get_toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_set_app (MidoriBookmarks* bookmarks,
|
|
|
|
MidoriApp* app)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
|
2010-06-13 03:06:27 +00:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
2009-01-31 03:09:35 +00:00
|
|
|
if (bookmarks->array)
|
|
|
|
{
|
|
|
|
g_object_unref (bookmarks->array);
|
|
|
|
gtk_tree_store_clear (GTK_TREE_STORE (model));
|
|
|
|
}
|
2009-02-20 21:43:08 +00:00
|
|
|
katze_assign (bookmarks->app, app);
|
|
|
|
if (!app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_ref (app);
|
2009-01-31 03:09:35 +00:00
|
|
|
bookmarks->array = katze_object_get_object (app, "bookmarks");
|
2012-06-15 23:06:58 +00:00
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, 0, NULL);
|
|
|
|
g_signal_connect_after (bookmarks->array, "add-item",
|
2010-11-21 15:49:20 +00:00
|
|
|
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
|
2010-08-10 21:46:49 +00:00
|
|
|
g_signal_connect (bookmarks->array, "remove-item",
|
|
|
|
G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
|
2011-01-19 20:58:26 +00:00
|
|
|
g_signal_connect (bookmarks->array, "update",
|
|
|
|
G_CALLBACK (midori_bookmarks_update_cb), bookmarks);
|
2010-06-16 21:16:25 +00:00
|
|
|
g_signal_connect_after (model, "row-changed",
|
|
|
|
G_CALLBACK (midori_bookmarks_row_changed_cb),
|
|
|
|
bookmarks);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_set_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APP:
|
|
|
|
midori_bookmarks_set_app (bookmarks, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_APP:
|
|
|
|
g_value_set_object (value, bookmarks->app);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkWidget* treeview)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
GdkPixbuf* pixbuf;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
|
|
|
|
|
|
|
/* TODO: Would it be better to not do this on every redraw? */
|
|
|
|
pixbuf = NULL;
|
2010-07-01 15:43:57 +00:00
|
|
|
if (KATZE_ITEM_IS_FOLDER (item))
|
2009-01-31 03:09:35 +00:00
|
|
|
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
|
|
|
GTK_ICON_SIZE_MENU, NULL);
|
2012-05-12 23:53:19 +00:00
|
|
|
else if ((pixbuf = katze_item_get_pixbuf (item, treeview)))
|
|
|
|
;
|
2010-07-01 15:43:57 +00:00
|
|
|
else if (KATZE_ITEM_IS_BOOKMARK (item))
|
2009-11-17 22:22:08 +00:00
|
|
|
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
|
2009-01-31 03:09:35 +00:00
|
|
|
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
2010-06-13 19:40:28 +00:00
|
|
|
if (item)
|
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_treeview_render_text_cb (GtkTreeViewColumn* column,
|
|
|
|
GtkCellRenderer* renderer,
|
|
|
|
GtkTreeModel* model,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkWidget* treeview)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
|
|
|
|
2010-06-13 19:40:28 +00:00
|
|
|
if (item && katze_item_get_name (item))
|
2009-01-31 03:09:35 +00:00
|
|
|
g_object_set (renderer, "markup", NULL,
|
|
|
|
"text", katze_item_get_name (item), NULL);
|
|
|
|
else
|
|
|
|
g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
2010-06-13 19:40:28 +00:00
|
|
|
if (item)
|
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_row_activated_cb (GtkTreeView* treeview,
|
|
|
|
GtkTreePath* path,
|
|
|
|
GtkTreeViewColumn* column,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (treeview);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
2010-07-02 04:23:25 +00:00
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item))
|
|
|
|
{
|
|
|
|
MidoriBrowser* browser;
|
2009-11-25 22:55:12 +00:00
|
|
|
|
2010-07-02 04:23:25 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
|
|
|
|
midori_browser_open_bookmark (browser, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (gtk_tree_view_row_expanded (treeview, path))
|
|
|
|
gtk_tree_view_collapse_row (treeview, path);
|
|
|
|
else
|
|
|
|
gtk_tree_view_expand_row (treeview, path, FALSE);
|
2009-02-20 21:43:08 +00:00
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_popup_item (GtkWidget* menu,
|
|
|
|
const gchar* stock_id,
|
|
|
|
const gchar* label,
|
|
|
|
KatzeItem* item,
|
|
|
|
gpointer callback,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
const gchar* uri;
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
2010-07-01 15:43:57 +00:00
|
|
|
uri = KATZE_ITEM_IS_BOOKMARK (item) ? katze_item_get_uri (item) : NULL;
|
2009-01-31 03:09:35 +00:00
|
|
|
|
|
|
|
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
|
|
|
|
if (label)
|
|
|
|
gtk_label_set_text_with_mnemonic (GTK_LABEL (gtk_bin_get_child (
|
|
|
|
GTK_BIN (menuitem))), label);
|
|
|
|
if (!strcmp (stock_id, GTK_STOCK_EDIT))
|
|
|
|
gtk_widget_set_sensitive (menuitem,
|
2010-07-01 15:43:57 +00:00
|
|
|
!KATZE_ITEM_IS_SEPARATOR (item));
|
|
|
|
else if (!KATZE_ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))
|
2009-01-31 03:09:35 +00:00
|
|
|
gtk_widget_set_sensitive (menuitem, uri != NULL);
|
|
|
|
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
|
|
|
|
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_open_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
|
|
|
|
2010-06-30 22:13:18 +00:00
|
|
|
if ((uri = katze_item_get_uri (item)) && *uri)
|
2009-01-31 03:09:35 +00:00
|
|
|
{
|
2009-05-03 19:11:20 +00:00
|
|
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
|
|
|
|
midori_browser_set_current_uri (browser, uri);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
2010-07-01 15:43:57 +00:00
|
|
|
if (KATZE_ITEM_IS_FOLDER (item))
|
2009-02-27 20:52:51 +00:00
|
|
|
{
|
|
|
|
KatzeItem* child;
|
2010-07-01 00:45:14 +00:00
|
|
|
KatzeArray* array;
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2012-06-15 23:06:58 +00:00
|
|
|
array = midori_bookmarks_read_from_db (bookmarks,
|
|
|
|
katze_item_get_meta_integer (item, "parentid"), NULL);
|
|
|
|
|
2010-07-01 00:45:14 +00:00
|
|
|
g_return_if_fail (KATZE_IS_ARRAY (array));
|
2010-09-11 21:39:51 +00:00
|
|
|
KATZE_ARRAY_FOREACH_ITEM (child, array)
|
2009-02-27 20:52:51 +00:00
|
|
|
{
|
|
|
|
if ((uri = katze_item_get_uri (child)) && *uri)
|
|
|
|
{
|
2009-04-23 02:13:19 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-27 20:52:51 +00:00
|
|
|
|
2009-04-23 02:13:19 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
|
|
|
|
n = midori_browser_add_item (browser, child);
|
2010-07-03 07:28:03 +00:00
|
|
|
midori_browser_set_current_page_smartly (browser, n);
|
2009-02-27 20:52:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-01 00:45:14 +00:00
|
|
|
else if ((uri = katze_item_get_uri (item)) && *uri)
|
2009-01-31 03:09:35 +00:00
|
|
|
{
|
2010-07-01 00:45:14 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-27 20:52:51 +00:00
|
|
|
|
2010-07-01 00:45:14 +00:00
|
|
|
browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks));
|
|
|
|
n = midori_browser_add_item (browser, item);
|
2010-07-03 07:28:03 +00:00
|
|
|
midori_browser_set_current_page_smartly (browser, n);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_open_in_window_activate_cb (GtkWidget* menuitem,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
KatzeItem* item;
|
|
|
|
const gchar* uri;
|
|
|
|
|
|
|
|
item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
|
|
|
|
uri = katze_item_get_uri (item);
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
2009-05-31 01:34:13 +00:00
|
|
|
MidoriBrowser* new_browser = midori_app_create_browser (bookmarks->app);
|
|
|
|
midori_app_add_browser (bookmarks->app, new_browser);
|
|
|
|
gtk_widget_show (GTK_WIDGET (new_browser));
|
|
|
|
midori_browser_add_uri (new_browser, uri);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_popup (GtkWidget* widget,
|
|
|
|
GdkEventButton* event,
|
|
|
|
KatzeItem* item,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkWidget* menu;
|
|
|
|
GtkWidget* menuitem;
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
2010-07-01 15:43:57 +00:00
|
|
|
if (KATZE_ITEM_IS_FOLDER (item))
|
2009-02-27 20:52:51 +00:00
|
|
|
midori_bookmarks_popup_item (menu,
|
|
|
|
STOCK_TAB_NEW, _("Open all in _Tabs"),
|
|
|
|
item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
midori_bookmarks_popup_item (menu, GTK_STOCK_OPEN, NULL,
|
|
|
|
item, midori_bookmarks_open_activate_cb, bookmarks);
|
|
|
|
midori_bookmarks_popup_item (menu, STOCK_TAB_NEW, _("Open in New _Tab"),
|
|
|
|
item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
|
|
|
|
midori_bookmarks_popup_item (menu, STOCK_WINDOW_NEW, _("Open in New _Window"),
|
|
|
|
item, midori_bookmarks_open_in_window_activate_cb, bookmarks);
|
|
|
|
}
|
2009-01-31 03:09:35 +00:00
|
|
|
menuitem = gtk_separator_menu_item_new ();
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
midori_bookmarks_popup_item (menu, GTK_STOCK_EDIT, NULL,
|
2010-07-02 04:50:14 +00:00
|
|
|
item, midori_bookmarks_edit_clicked_cb, bookmarks);
|
2009-01-31 03:09:35 +00:00
|
|
|
midori_bookmarks_popup_item (menu, GTK_STOCK_DELETE, NULL,
|
2010-07-02 04:50:14 +00:00
|
|
|
item, midori_bookmarks_delete_clicked_cb, bookmarks);
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2009-11-15 17:00:33 +00:00
|
|
|
katze_widget_popup (widget, GTK_MENU (menu), event, KATZE_MENU_POSITION_CURSOR);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
midori_bookmarks_button_release_event_cb (GtkWidget* widget,
|
|
|
|
GdkEventButton* event,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (event->button != 2 && event->button != 3)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
|
|
|
{
|
2009-02-20 21:43:08 +00:00
|
|
|
KatzeItem* item;
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
if (event->button == 2)
|
|
|
|
{
|
2010-06-30 22:13:18 +00:00
|
|
|
const gchar* uri;
|
2010-07-01 15:43:57 +00:00
|
|
|
if (KATZE_ITEM_IS_BOOKMARK (item) && (uri = katze_item_get_uri (item)) && *uri)
|
2009-01-31 03:09:35 +00:00
|
|
|
{
|
2009-04-23 02:13:19 +00:00
|
|
|
MidoriBrowser* browser;
|
2009-02-20 21:43:08 +00:00
|
|
|
gint n;
|
|
|
|
|
2009-04-23 02:13:19 +00:00
|
|
|
browser = midori_browser_get_for_widget (widget);
|
|
|
|
n = midori_browser_add_uri (browser, uri);
|
|
|
|
midori_browser_set_current_page (browser, n);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
midori_bookmarks_popup (widget, event, item, bookmarks);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
2010-06-30 22:13:18 +00:00
|
|
|
if (item != NULL)
|
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-02-20 21:43:08 +00:00
|
|
|
static gboolean
|
|
|
|
midori_bookmarks_key_release_event_cb (GtkWidget* widget,
|
|
|
|
GdkEventKey* event,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
2011-10-01 13:12:04 +00:00
|
|
|
if (event->keyval == GDK_KEY_Delete)
|
2010-11-21 15:25:27 +00:00
|
|
|
midori_bookmarks_delete_clicked_cb (widget, bookmarks);
|
2009-02-20 21:43:08 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_popup_menu_cb (GtkWidget* widget,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (model, &iter, 0, &item, -1);
|
|
|
|
midori_bookmarks_popup (widget, NULL, item, bookmarks);
|
2009-02-20 21:43:08 +00:00
|
|
|
g_object_unref (item);
|
2009-01-31 03:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 02:54:11 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_row_expanded_cb (GtkTreeView* treeview,
|
|
|
|
GtkTreeIter* iter,
|
|
|
|
GtkTreePath* path,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
KatzeItem* item;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
|
|
|
|
gtk_tree_model_get (model, iter, 0, &item, -1);
|
2010-07-01 00:45:14 +00:00
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model),
|
2012-06-15 23:06:58 +00:00
|
|
|
iter, katze_item_get_meta_integer (item, "id"), NULL);
|
2010-06-13 02:54:11 +00:00
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_row_collapsed_cb (GtkTreeView *treeview,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeStore* treestore;
|
|
|
|
GtkTreeIter child;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
|
|
|
|
treestore = GTK_TREE_STORE (model);
|
|
|
|
while (gtk_tree_model_iter_nth_child (model, &child, parent, 0))
|
|
|
|
gtk_tree_store_remove (treestore, &child);
|
|
|
|
/* That's an invisible dummy, so we always have an expander */
|
|
|
|
gtk_tree_store_insert_with_values (treestore, &child, parent,
|
|
|
|
0, 0, NULL, -1);
|
|
|
|
}
|
|
|
|
|
2011-03-18 00:55:22 +00:00
|
|
|
static void
|
2011-04-17 20:53:03 +00:00
|
|
|
midori_bookmarks_selection_changed_cb (GtkTreeSelection *treeview,
|
|
|
|
MidoriBookmarks *bookmarks)
|
2011-03-18 00:55:22 +00:00
|
|
|
{
|
|
|
|
midori_bookmarks_toolbar_update (bookmarks);
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:47:41 +00:00
|
|
|
static gboolean
|
|
|
|
midori_bookmarks_filter_timeout_cb (gpointer data)
|
|
|
|
{
|
|
|
|
MidoriBookmarks* bookmarks = data;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeStore* treestore;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
|
|
|
|
treestore = GTK_TREE_STORE (model);
|
|
|
|
|
|
|
|
gtk_tree_store_clear (treestore);
|
|
|
|
midori_bookmarks_read_from_db_to_model (bookmarks,
|
2012-06-15 23:06:58 +00:00
|
|
|
treestore, NULL, 0, bookmarks->filter);
|
2010-07-03 05:47:41 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_filter_entry_changed_cb (GtkEntry* entry,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
if (bookmarks->filter_timeout)
|
|
|
|
g_source_remove (bookmarks->filter_timeout);
|
|
|
|
katze_assign (bookmarks->filter, g_strdup (gtk_entry_get_text (entry)));
|
|
|
|
bookmarks->filter_timeout = g_timeout_add (COMPLETION_DELAY,
|
|
|
|
midori_bookmarks_filter_timeout_cb, bookmarks);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
midori_bookmarks_filter_entry_clear_cb (GtkEntry* entry,
|
|
|
|
gint icon_pos,
|
|
|
|
gint button,
|
|
|
|
MidoriBookmarks* bookmarks)
|
|
|
|
{
|
|
|
|
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
}
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_init (MidoriBookmarks* bookmarks)
|
|
|
|
{
|
2010-07-03 05:47:41 +00:00
|
|
|
GtkWidget* entry;
|
|
|
|
GtkWidget* box;
|
2009-01-31 03:09:35 +00:00
|
|
|
GtkTreeStore* model;
|
|
|
|
GtkWidget* treeview;
|
|
|
|
GtkTreeViewColumn* column;
|
|
|
|
GtkCellRenderer* renderer_pixbuf;
|
|
|
|
GtkCellRenderer* renderer_text;
|
2011-04-17 20:53:03 +00:00
|
|
|
GtkTreeSelection* selection;
|
2009-01-31 03:09:35 +00:00
|
|
|
|
2010-07-03 05:47:41 +00:00
|
|
|
/* Create the filter entry */
|
|
|
|
entry = gtk_icon_entry_new ();
|
|
|
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
|
|
|
|
GTK_ICON_ENTRY_PRIMARY,
|
|
|
|
GTK_STOCK_FIND);
|
2012-01-13 23:45:01 +00:00
|
|
|
sokoke_entry_set_clear_button_visible (GTK_ENTRY (entry), TRUE);
|
2010-07-03 05:47:41 +00:00
|
|
|
g_signal_connect (entry, "icon-release",
|
|
|
|
G_CALLBACK (midori_bookmarks_filter_entry_clear_cb), bookmarks);
|
|
|
|
g_signal_connect (entry, "changed",
|
|
|
|
G_CALLBACK (midori_bookmarks_filter_entry_changed_cb), bookmarks);
|
|
|
|
box = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 3);
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
gtk_box_pack_start (GTK_BOX (bookmarks), box, FALSE, FALSE, 5);
|
|
|
|
|
2009-01-31 03:09:35 +00:00
|
|
|
/* Create the treeview */
|
2010-07-30 23:21:50 +00:00
|
|
|
model = gtk_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING);
|
2009-01-31 03:09:35 +00:00
|
|
|
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
2010-07-30 23:21:50 +00:00
|
|
|
gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 1);
|
2009-01-31 03:09:35 +00:00
|
|
|
column = gtk_tree_view_column_new ();
|
2010-11-24 18:06:12 +00:00
|
|
|
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
2009-01-31 03:09:35 +00:00
|
|
|
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
|
|
|
|
(GtkTreeCellDataFunc)midori_bookmarks_treeview_render_icon_cb,
|
|
|
|
treeview, NULL);
|
|
|
|
renderer_text = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
|
|
|
|
(GtkTreeCellDataFunc)midori_bookmarks_treeview_render_text_cb,
|
|
|
|
treeview, NULL);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
|
2010-06-16 21:16:25 +00:00
|
|
|
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
|
2009-01-31 03:09:35 +00:00
|
|
|
g_object_unref (model);
|
|
|
|
g_object_connect (treeview,
|
|
|
|
"signal::row-activated",
|
|
|
|
midori_bookmarks_row_activated_cb, bookmarks,
|
|
|
|
"signal::button-release-event",
|
|
|
|
midori_bookmarks_button_release_event_cb, bookmarks,
|
2009-02-20 21:43:08 +00:00
|
|
|
"signal::key-release-event",
|
|
|
|
midori_bookmarks_key_release_event_cb, bookmarks,
|
2009-01-31 03:09:35 +00:00
|
|
|
"signal::popup-menu",
|
|
|
|
midori_bookmarks_popup_menu_cb, bookmarks,
|
2010-06-13 02:54:11 +00:00
|
|
|
"signal::row-expanded",
|
|
|
|
midori_bookmarks_row_expanded_cb, bookmarks,
|
|
|
|
"signal::row-collapsed",
|
|
|
|
midori_bookmarks_row_collapsed_cb, bookmarks,
|
2009-01-31 03:09:35 +00:00
|
|
|
NULL);
|
2011-04-17 20:53:03 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
|
|
|
|
g_signal_connect_after (selection, "changed",
|
|
|
|
G_CALLBACK (midori_bookmarks_selection_changed_cb),
|
|
|
|
bookmarks);
|
2009-01-31 03:09:35 +00:00
|
|
|
gtk_widget_show (treeview);
|
|
|
|
gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0);
|
|
|
|
bookmarks->treeview = treeview;
|
|
|
|
}
|
|
|
|
|
2009-04-05 21:46:15 +00:00
|
|
|
static void
|
|
|
|
midori_bookmarks_finalize (GObject* object)
|
|
|
|
{
|
|
|
|
MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (object);
|
|
|
|
|
|
|
|
if (bookmarks->app)
|
|
|
|
g_object_unref (bookmarks->app);
|
|
|
|
}
|
|
|
|
|