aboutsummaryrefslogtreecommitdiffstats
path: root/lib/history/ephy-history-types.c
blob: c003e04b23f0ec2d0b9f88ef67d644ca92a800b2 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* -*- 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, url, 0, 0, 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, double zoom_level)
{
  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;
  host->zoom_level = zoom_level;

  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,
                                original->zoom_level);
  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)
{
  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->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);
  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;
  copy->limit = query->limit;
  copy->sort_type = query->sort_type;
  copy->host = query->host;

  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;
}