Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / src / display / canvas-temporary-item.cpp
1 /** \file
2  * Provides a class that can contain active TemporaryItem's on a desktop
3  * When the object is deleted, it also deletes the canvasitem it contains!
4  * This object should be created/managed by a TemporaryItemList.
5  * After its lifetime, it fires the timeout signal, afterwards *it deletes itself*.
6  *
7  * (part of code inspired by message-stack.cpp)
8  *
9  * Authors:
10  *   Johan Engelen
11  *
12  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include "display/canvas-temporary-item.h"
19 #include <gtk/gtkobject.h>
21 namespace Inkscape {
22 namespace Display {
24 /** lifetime is measured in milliseconds
25  */
26 TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime, bool deselect_destroy)
27     : canvasitem(item),
28       timeout_id(0),
29       destroy_on_deselect(deselect_destroy)
30 {
31     if (lifetime > 0 && destroy_on_deselect) {
32         g_print ("Warning: lifetime should be 0 when destroy_on_deselect is true\n");
33         lifetime = 0;
34     }
35     // zero lifetime means stay forever, so do not add timeout event.
36     if (lifetime > 0) {
37         timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);
38     }
39 }
41 TemporaryItem::~TemporaryItem()
42 {
43     // when it has not expired yet...
44     if (timeout_id) {
45         g_source_remove(timeout_id);
46         timeout_id = 0;
47     }
49     if (canvasitem) {
50         // destroying the item automatically hides it
51         gtk_object_destroy (GTK_OBJECT (canvasitem));
52         canvasitem = NULL;
53     }
54 }
56 /* static method*/
57 gboolean TemporaryItem::_timeout(gpointer data) {
58     TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);
59     tempitem->timeout_id = 0;
60     tempitem->signal_timeout.emit(tempitem);
61     delete tempitem;
62     return FALSE;
63 }
66 } //namespace Display
67 } /* namespace Inkscape */
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :