diff options
author | Xan Lopez <xlopez@igalia.com> | 2011-11-25 20:39:50 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-03-07 04:49:42 +0800 |
commit | 374d66dd260b989f22eba25dad4fabc49da2d586 (patch) | |
tree | d32121ea4f1769a3a725c75f1cf01229cb533f95 /lib/history/ephy-history-types.c | |
parent | 77ee0fdf4c5383f2134608e741b73f51ef30f430 (diff) | |
download | gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar.gz gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar.bz2 gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar.lz gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar.xz gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.tar.zst gsoc2013-epiphany-374d66dd260b989f22eba25dad4fabc49da2d586.zip |
Add EphyHistoryService and helper classes
EphyHistoryService provides a high-level API to store history
information. It will processed by a worker thread using SQLite to
provide a fast, responsive service to the main UI.
Based on the code by Martin Robinson (mrobinson@igalia.com) and
Claudio Saavedra (csaavedra@igalia.com).
Diffstat (limited to 'lib/history/ephy-history-types.c')
-rw-r--r-- | lib/history/ephy-history-types.c | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/lib/history/ephy-history-types.c b/lib/history/ephy-history-types.c new file mode 100644 index 000000000..1a8fc4380 --- /dev/null +++ b/lib/history/ephy-history-types.c @@ -0,0 +1,218 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* vim: set sw=2 ts=2 sts=2 et: */ +/* + * Copyright © 2011 Igalia S.L. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <glib.h> + +#include "ephy-history-types.h" + +EphyHistoryPageVisit * +ephy_history_page_visit_new_with_url (EphyHistoryURL *url, gint64 visit_time, EphyHistoryPageVisitType visit_type) +{ + EphyHistoryPageVisit *visit = g_slice_alloc0 (sizeof (EphyHistoryPageVisit)); + visit->id = -1; + visit->url = url; + visit->visit_time = visit_time; + visit->visit_type = visit_type; + return visit; +} + +EphyHistoryPageVisit * +ephy_history_page_visit_new (const char *url, gint64 visit_time, EphyHistoryPageVisitType visit_type) +{ + return ephy_history_page_visit_new_with_url (ephy_history_url_new (url, "", 0, 0, 0, 1.0), + visit_time, visit_type); +} + +void +ephy_history_page_visit_free (EphyHistoryPageVisit *visit) +{ + if (visit == NULL) + return; + + ephy_history_url_free (visit->url); + g_slice_free1 (sizeof (EphyHistoryPageVisit), visit); +} + +EphyHistoryPageVisit * +ephy_history_page_visit_copy (EphyHistoryPageVisit *visit) +{ + EphyHistoryPageVisit *copy = ephy_history_page_visit_new_with_url (0, visit->visit_time, visit->visit_type); + copy->id = visit->id; + copy->url = ephy_history_url_copy (visit->url); + return copy; +} + +GList * +ephy_history_page_visit_list_copy (GList *original) +{ + GList *new = g_list_copy (original); + GList *current = new; + while (current) { + current->data = ephy_history_page_visit_copy ((EphyHistoryPageVisit *) current->data); + current = current->next; + } + return new; +} + +void +ephy_history_page_visit_list_free (GList *list) +{ + g_list_free_full (list, (GDestroyNotify) ephy_history_page_visit_free); +} + +EphyHistoryHost * +ephy_history_host_new (const char *url, const char *title, int visit_count) +{ + EphyHistoryHost *host = g_slice_alloc0 (sizeof (EphyHistoryHost)); + + host->id = -1; + host->url = g_strdup (url); + host->title = g_strdup (title); + host->visit_count = visit_count; + + return host; +} + +EphyHistoryHost * +ephy_history_host_copy (EphyHistoryHost *original) +{ + EphyHistoryHost *host; + + if (original == NULL) + return NULL; + + host = ephy_history_host_new (original->url, + original->title, + original->visit_count); + host->id = original->id; + + return host; +} + +void +ephy_history_host_free (EphyHistoryHost *host) +{ + if (host == NULL) + return; + + g_free (host->url); + g_free (host->title); + + g_slice_free1 (sizeof (EphyHistoryHost), host); +} + +EphyHistoryURL * +ephy_history_url_new (const char *url, const char *title, int visit_count, int typed_count, int last_visit_time, double zoom_level) +{ + EphyHistoryURL *history_url = g_slice_alloc0 (sizeof (EphyHistoryURL)); + history_url->id = -1; + history_url->url = g_strdup (url); + history_url->title = g_strdup (title); + history_url->visit_count = visit_count; + history_url->typed_count = typed_count; + history_url->last_visit_time = last_visit_time; + history_url->zoom_level = zoom_level; + history_url->host = NULL; + return history_url; +} + +EphyHistoryURL * +ephy_history_url_copy (EphyHistoryURL *url) +{ + EphyHistoryURL *copy; + if (url == NULL) + return NULL; + + copy = ephy_history_url_new (url->url, + url->title, + url->visit_count, + url->typed_count, + url->last_visit_time, + url->zoom_level); + copy->id = url->id; + copy->host = ephy_history_host_copy (url->host); + return copy; +} + +void +ephy_history_url_free (EphyHistoryURL *url) +{ + if (url == NULL) + return; + + g_free (url->url); + g_free (url->title); + ephy_history_host_free (url->host); + g_slice_free1 (sizeof (EphyHistoryURL), url); +} + +GList * +ephy_history_url_list_copy (GList *original) +{ + GList *new = NULL, *last; + + if (original) { + new = last = g_list_append (NULL, ephy_history_url_copy (original->data)); + original = original->next; + + while (original) { + last = g_list_append (last, ephy_history_url_copy (original->data)); + last = last->next; + original = original->next; + } + } + + return new; +} + +void +ephy_history_url_list_free (GList *list) +{ + g_list_free_full (list, (GDestroyNotify) ephy_history_url_free); +} + +EphyHistoryQuery * +ephy_history_query_new () +{ + return (EphyHistoryQuery*) g_slice_alloc0 (sizeof (EphyHistoryQuery)); +} + +void +ephy_history_query_free (EphyHistoryQuery *query) +{ + g_list_free_full (query->substring_list, g_free); + g_slice_free1 (sizeof (EphyHistoryQuery), query); +} + +EphyHistoryQuery * +ephy_history_query_copy (EphyHistoryQuery *query) +{ + GList *iter; + EphyHistoryQuery *copy = ephy_history_query_new (); + copy->from = query->from; + copy->to = query->to; + + for (iter = query->substring_list; iter != NULL; iter = iter->next) { + copy->substring_list = g_list_prepend (copy->substring_list, g_strdup (iter->data)); + } + copy->substring_list = g_list_reverse (copy->substring_list); + + return copy; +} |