2
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
See the file COPYING for the full license text.
12
#include "midori-trash.h"
15
#include <glib/gi18n.h>
17
G_DEFINE_TYPE (MidoriTrash, midori_trash, G_TYPE_OBJECT)
19
struct _MidoriTrashPrivate
22
KatzeXbelItem* xbel_folder;
25
#define MIDORI_TRASH_GET_PRIVATE(obj) \
26
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
27
MIDORI_TYPE_TRASH, MidoriTrashPrivate))
43
static guint signals[LAST_SIGNAL];
46
midori_trash_finalize (GObject* object);
49
midori_trash_set_property (GObject* object,
55
midori_trash_get_property (GObject* object,
61
midori_trash_class_init (MidoriTrashClass* class)
63
signals[INSERTED] = g_signal_new (
65
G_TYPE_FROM_CLASS(class),
66
(GSignalFlags)(G_SIGNAL_RUN_LAST),
67
G_STRUCT_OFFSET (MidoriTrashClass, inserted),
70
g_cclosure_marshal_VOID__UINT,
74
signals[REMOVED] = g_signal_new (
76
G_TYPE_FROM_CLASS(class),
77
(GSignalFlags)(G_SIGNAL_RUN_LAST),
78
G_STRUCT_OFFSET (MidoriTrashClass, removed),
81
g_cclosure_marshal_VOID__UINT,
85
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
86
gobject_class->finalize = midori_trash_finalize;
87
gobject_class->set_property = midori_trash_set_property;
88
gobject_class->get_property = midori_trash_get_property;
90
GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
92
g_object_class_install_property (gobject_class,
97
_("The maximum number of items"),
101
g_type_class_add_private (class, sizeof (MidoriTrashPrivate));
107
midori_trash_init (MidoriTrash* trash)
109
trash->priv = MIDORI_TRASH_GET_PRIVATE (trash);
111
MidoriTrashPrivate* priv = trash->priv;
113
priv->xbel_folder = katze_xbel_folder_new ();
117
midori_trash_finalize (GObject* object)
119
MidoriTrash* trash = MIDORI_TRASH (object);
120
MidoriTrashPrivate* priv = trash->priv;
122
katze_xbel_item_unref (priv->xbel_folder);
124
G_OBJECT_CLASS (midori_trash_parent_class)->finalize (object);
128
midori_trash_set_property (GObject* object,
133
MidoriTrash* trash = MIDORI_TRASH (object);
134
MidoriTrashPrivate* priv = trash->priv;
139
priv->limit = g_value_get_uint (value);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148
midori_trash_get_property (GObject* object,
153
MidoriTrash* trash = MIDORI_TRASH (object);
154
MidoriTrashPrivate* priv = trash->priv;
159
g_value_set_uint (value, priv->limit);
162
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169
* @limit: the maximum number of items
171
* Creates a new #MidoriTrash that can contain a specified number of items,
172
* meaning that each additional item will replace the oldest existing item.
174
* The value 0 for @limit actually means that there is no limit.
176
* You will typically want to assign this to a #MidoriBrowser.
178
* Return value: a new #MidoriTrash
181
midori_trash_new (guint limit)
183
MidoriTrash* trash = g_object_new (MIDORI_TYPE_TRASH,
191
* midori_trash_is_empty:
192
* @trash: a #MidoriTrash
194
* Determines whether the @trash contains no items.
196
* Return value: %TRUE if there are no items, %FALSE otherwise
199
midori_trash_is_empty (MidoriTrash* trash)
201
g_return_val_if_fail (MIDORI_IS_TRASH (trash), FALSE);
203
MidoriTrashPrivate* priv = trash->priv;
205
return katze_xbel_folder_is_empty (priv->xbel_folder);
209
* midori_trash_get_n_items:
210
* @trash: a #MidoriTrash
212
* Determines the number of items in @trash.
214
* Return value: the current number of items
217
midori_trash_get_n_items (MidoriTrash* trash)
219
g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0);
221
MidoriTrashPrivate* priv = trash->priv;
223
return katze_xbel_folder_get_n_items (priv->xbel_folder);
227
* midori_trash_get_nth_xbel_item:
228
* @trash: a #MidoriTrash
229
* @n: the index of an item
231
* Retrieve an item contained in @trash by its index.
233
* Note that you mustn't unref this item.
235
* Return value: the index at the given index or %NULL
238
midori_trash_get_nth_xbel_item (MidoriTrash* trash,
241
g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0);
243
MidoriTrashPrivate* priv = trash->priv;
245
return katze_xbel_folder_get_nth_item (priv->xbel_folder, n);
249
* midori_trash_prepend_xbel_item:
250
* @trash: a #MidoriTrash
251
* @xbel_item: a #KatzeXbelItem
253
* Prepends a #KatzeXbelItem to @trash.
255
* The item is copied. If there is a limit set, the oldest item is
256
* removed automatically.
258
* Return value: %TRUE if there are no items, %FALSE otherwise
261
midori_trash_prepend_xbel_item (MidoriTrash* trash,
262
KatzeXbelItem* xbel_item)
264
g_return_if_fail (MIDORI_IS_TRASH (trash));
266
MidoriTrashPrivate* priv = trash->priv;
268
KatzeXbelItem* copy = katze_xbel_item_copy (xbel_item);
269
katze_xbel_folder_prepend_item (priv->xbel_folder, copy);
270
g_signal_emit (trash, signals[INSERTED], 0, 0);
271
guint n = katze_xbel_folder_get_n_items (priv->xbel_folder);
274
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder,
276
g_signal_emit (trash, signals[REMOVED], 0, n - 1);
277
katze_xbel_item_unref (item);
282
* midori_trash_remove_nth_item:
283
* @trash: a #MidoriTrash
284
* @n: the index of an item
286
* Removes the item at the specified position from @trash.
288
* Nothing happens if the function fails.
291
midori_trash_remove_nth_item (MidoriTrash* trash,
294
g_return_if_fail (MIDORI_IS_TRASH (trash));
296
MidoriTrashPrivate* priv = trash->priv;
298
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder, n);
301
katze_xbel_folder_remove_item (priv->xbel_folder, item);
302
g_signal_emit (trash, signals[REMOVED], 0, n);
303
katze_xbel_item_unref (item);
307
* midori_trash_empty:
308
* @trash: a #MidoriTrash
310
* Deletes all items currently contained in @trash.
313
midori_trash_empty (MidoriTrash* trash)
315
g_return_if_fail (MIDORI_IS_TRASH (trash));
317
MidoriTrashPrivate* priv = trash->priv;
319
guint n = katze_xbel_folder_get_n_items (priv->xbel_folder);
321
for (i = 0; i < n; i++)
323
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder,
325
g_signal_emit (trash, signals[REMOVED], 0, i);
326
katze_xbel_item_unref (item);