aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-browse-history.c
blob: c6a0669c6bd3ad6d97140db9b722d10bbd9a3caf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* vim: set sw=2 ts=2 sts=2 et: */
/*
 *  Copyright © 2011, 2012 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 "config.h"
#include "ephy-browse-history.h"

#include "ephy-file-helpers.h"
#include "ephy-request-about.h"

G_DEFINE_TYPE (EphyBrowseHistory, ephy_browse_history, G_TYPE_OBJECT)

#define EPHY_BROWSE_HISTORY_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_BROWSE_HISTORY, EphyBrowseHistoryPrivate))

struct _EphyBrowseHistoryPrivate {
  EphyHistoryService *history_service;
};

static void
ephy_browse_history_dispose (GObject *object)
{
  EphyBrowseHistory *history = EPHY_BROWSE_HISTORY (object);

  g_clear_object (&history->priv->history_service);

  G_OBJECT_CLASS (ephy_browse_history_parent_class)->dispose (object);
}

static void
ephy_browse_history_class_init (EphyBrowseHistoryClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (EphyBrowseHistoryPrivate));

  object_class->dispose = ephy_browse_history_dispose;
}

static void
ephy_browse_history_init (EphyBrowseHistory *history)
{
  gchar *filename;

  history->priv = EPHY_BROWSE_HISTORY_PRIVATE (history);

  filename = g_build_filename (ephy_dot_dir (), "ephy-history.db", NULL);
  history->priv->history_service = ephy_history_service_new (filename);
  g_free (filename);
}

EphyBrowseHistory *
ephy_browse_history_new (void)
{
  return g_object_new (EPHY_TYPE_BROWSE_HISTORY, NULL);
}

void
ephy_browse_history_add_page (EphyBrowseHistory *history,
                              const char *orig_url)
{
  EphyHistoryPageVisit *visit;
  char *url;

  if (g_str_has_prefix (orig_url, EPHY_ABOUT_SCHEME))
    url = g_strdup_printf ("about:%s", orig_url + EPHY_ABOUT_SCHEME_LEN + 1);
  else
    url = g_strdup (orig_url);

  visit = ephy_history_page_visit_new (url,
                                       time (NULL),
                                       EPHY_PAGE_VISIT_TYPED);
  ephy_history_service_add_visit (history->priv->history_service,
                                  visit, NULL, NULL);
  ephy_history_page_visit_free (visit);
}

void
ephy_browse_history_set_page_title (EphyBrowseHistory *history,
                                    const char *url,
                                    const char *title)
{
  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));
  g_return_if_fail (url != NULL);

  ephy_history_service_set_url_title (history->priv->history_service,
                                      url,
                                      title,
                                      NULL, NULL);
}

void
ephy_browse_history_set_page_zoom_level (EphyBrowseHistory *history,
                                         const char *url,
                                         const double zoom_level)
{
  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));
  g_return_if_fail (url != NULL);

  ephy_history_service_set_url_zoom_level (history->priv->history_service,
                                           url,
                                           zoom_level,
                                           NULL, NULL);
}

void
ephy_browse_history_get_url (EphyBrowseHistory *history,
                             const char *url,
                             EphyHistoryJobCallback callback,
                             gpointer user_data)
{
  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));
  g_return_if_fail (url != NULL);

  ephy_history_service_get_url (history->priv->history_service,
                                url, callback, user_data);
}

void
ephy_browse_history_find_urls (EphyBrowseHistory *history,
                               gint64 from, gint64 to,
                               guint limit,
                               GList *substring_list,
                               EphyHistoryJobCallback callback,
                               gpointer user_data)
{
  EphyHistoryQuery *query;

  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));

  query = ephy_history_query_new ();
  query->from = from;
  query->to = to;
  query->substring_list = substring_list;
  query->sort_type = EPHY_HISTORY_SORT_MV;

  if (limit != 0)
    query->limit = limit;

  ephy_history_service_query_urls (history->priv->history_service,
                                   query, callback, user_data);
}

void
ephy_browse_history_delete_urls (EphyBrowseHistory *history,
                                 GList *urls,
                                 EphyHistoryJobCallback callback,
                                 gpointer user_data)
{
  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));

  ephy_history_service_delete_urls (history->priv->history_service,
                                    urls, callback, user_data);
}

void
ephy_browse_history_get_host_for_url (EphyBrowseHistory *history,
                                      const char *url,
                                      EphyHistoryJobCallback callback,
                                      gpointer user_data)
{
  g_return_if_fail (EPHY_IS_BROWSE_HISTORY (history));

  ephy_history_service_get_host_for_url (history->priv->history_service,
                                         url, callback, user_data);
}