📄 webkitwebhistoryitem.cpp
字号:
/* * Copyright (C) 2008, 2009 Jan Michael C. Alonzo * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "config.h"#include "webkitwebhistoryitem.h"#include "webkitprivate.h"#include <glib.h>#include "CString.h"#include "HistoryItem.h"#include "PlatformString.h"/** * SECTION:webkitwebhistoryitem * @short_description: One item of the #WebKitWebBackForwardList and or global history * @see_also: #WebKitWebBackForwardList * * A history item consists out of a title and a uri. It can be part of the * #WebKitWebBackForwardList and the global history. The global history is used * for coloring the links of visited sites. #WebKitHistoryItem's constructed with * #webkit_web_history_item_new and #webkit_web_history_item_new_with_data are * automatically added to the global history. * * <informalexample><programlisting> * /<!-- -->* Inject a visited page into the global history *<!-- -->/ * webkit_web_history_item_new_with_data("http://www.gnome.org/", "GNOME: The Free Software Desktop Project"); * webkit_web_history_item_new_with_data("http://www.webkit.org/", "The WebKit Open Source Project"); * </programlisting></informalexample> * */using namespace WebKit;extern "C" {struct _WebKitWebHistoryItemPrivate { WebCore::HistoryItem* historyItem; WebCore::CString title; WebCore::CString alternateTitle; WebCore::CString uri; WebCore::CString originalUri;};#define WEBKIT_WEB_HISTORY_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItemPrivate))enum { PROP_0, PROP_TITLE, PROP_ALTERNATE_TITLE, PROP_URI, PROP_ORIGINAL_URI, PROP_LAST_VISITED_TIME};G_DEFINE_TYPE(WebKitWebHistoryItem, webkit_web_history_item, G_TYPE_OBJECT);static void webkit_web_history_item_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);static void webkit_web_history_item_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);static GHashTable* webkit_history_items(){ static GHashTable* historyItems = g_hash_table_new(g_direct_hash, g_direct_equal); return historyItems;}static void webkit_history_item_add(WebKitWebHistoryItem* webHistoryItem, WebCore::HistoryItem* historyItem){ g_return_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem)); GHashTable* table = webkit_history_items(); g_hash_table_insert(table, historyItem, g_object_ref(webHistoryItem));}static void webkit_history_item_remove(WebCore::HistoryItem* historyItem){ GHashTable* table = webkit_history_items(); WebKitWebHistoryItem* webHistoryItem = (WebKitWebHistoryItem*) g_hash_table_lookup(table, historyItem); g_return_if_fail(webHistoryItem != NULL); g_hash_table_remove(table, historyItem); g_object_unref(webHistoryItem);}static void webkit_web_history_item_dispose(GObject* object){ WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); webkit_history_item_remove(core(webHistoryItem)); /* destroy table if empty */ GHashTable* table = webkit_history_items(); if (!g_hash_table_size(table)) g_hash_table_destroy(table); G_OBJECT_CLASS(webkit_web_history_item_parent_class)->dispose(object);}static void webkit_web_history_item_finalize(GObject* object){ WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; priv->title = WebCore::CString(); priv->alternateTitle = WebCore::CString(); priv->uri = WebCore::CString(); priv->originalUri = WebCore::CString(); G_OBJECT_CLASS(webkit_web_history_item_parent_class)->finalize(object);}static void webkit_web_history_item_class_init(WebKitWebHistoryItemClass* klass){ GObjectClass* gobject_class = G_OBJECT_CLASS(klass); gobject_class->dispose = webkit_web_history_item_dispose; gobject_class->finalize = webkit_web_history_item_finalize; gobject_class->set_property = webkit_web_history_item_set_property; gobject_class->get_property = webkit_web_history_item_get_property; /** * WebKitWebHistoryItem:title: * * The title of the history item. * * Since: 1.0.2 */ g_object_class_install_property(gobject_class, PROP_TITLE, g_param_spec_string( "title", "Title", "The title of the history item", NULL, WEBKIT_PARAM_READABLE)); /** * WebKitWebHistoryItem:alternate-title: * * The alternate title of the history item. * * Since: 1.0.2 */ g_object_class_install_property(gobject_class, PROP_ALTERNATE_TITLE, g_param_spec_string( "alternate-title", "Alternate Title", "The alternate title of the history item", NULL, WEBKIT_PARAM_READWRITE)); /** * WebKitWebHistoryItem:uri: * * The URI of the history item. * * Since: 1.0.2 */ g_object_class_install_property(gobject_class, PROP_URI, g_param_spec_string( "uri", "URI", "The URI of the history item", NULL, WEBKIT_PARAM_READABLE)); /** * WebKitWebHistoryItem:original-uri: * * The original URI of the history item. * * Since: 1.0.2 */ g_object_class_install_property(gobject_class, PROP_ORIGINAL_URI, g_param_spec_string( "original-uri", "Original URI", "The original URI of the history item", NULL, WEBKIT_PARAM_READABLE)); /** * WebKitWebHistoryItem:last-visited-time: * * The time at which the history item was last visited. * * Since: 1.0.2 */ g_object_class_install_property(gobject_class, PROP_LAST_VISITED_TIME, g_param_spec_double( "last-visited-time", "Last visited Time", "The time at which the history item was last visited", 0, G_MAXDOUBLE, 0, WEBKIT_PARAM_READABLE)); g_type_class_add_private(gobject_class, sizeof(WebKitWebHistoryItemPrivate));}static void webkit_web_history_item_init(WebKitWebHistoryItem* webHistoryItem){ webHistoryItem->priv = WEBKIT_WEB_HISTORY_ITEM_GET_PRIVATE(webHistoryItem);}static void webkit_web_history_item_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec){ WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); switch(prop_id) { case PROP_ALTERNATE_TITLE: webkit_web_history_item_set_alternate_title(webHistoryItem, g_value_get_string(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; }}static void webkit_web_history_item_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec){ WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); switch (prop_id) { case PROP_TITLE: g_value_set_string(value, webkit_web_history_item_get_title(webHistoryItem)); break; case PROP_ALTERNATE_TITLE: g_value_set_string(value, webkit_web_history_item_get_alternate_title(webHistoryItem)); break; case PROP_URI: g_value_set_string(value, webkit_web_history_item_get_uri(webHistoryItem)); break; case PROP_ORIGINAL_URI: g_value_set_string(value, webkit_web_history_item_get_original_uri(webHistoryItem)); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -