aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-task-widget.c
blob: c6cd524c2fd4381aabe6252d27821875518f00a3 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-task-widget.c
 *
 * Copyright (C) 2001  Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli <ettore@ximian.com>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-task-widget.h"

#include <gtk/gtkframe.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkimage.h>
#include <gtk/gtktooltips.h>

#include <libgnome/gnome-i18n.h>

#include <gal/util/e-util.h>


#define SPACING 2

#define PARENT_TYPE (gtk_event_box_get_type ())
static GtkEventBoxClass *parent_class = NULL;

struct _ETaskWidgetPrivate {
    char *component_id;

    GtkTooltips *tooltips;

    GdkPixbuf *icon_pixbuf;
    GtkWidget *label;
    GtkWidget *image;
};


/* GObject methods.  */

static void
impl_dispose (GObject *object)
{
    ETaskWidget *task_widget;
    ETaskWidgetPrivate *priv;

    task_widget = E_TASK_WIDGET (object);

    priv = task_widget->priv;

    if (priv->tooltips != NULL) {
        g_object_unref (priv->tooltips);
        priv->tooltips = NULL;
    }

    if (priv->icon_pixbuf != NULL) {
        g_object_unref (priv->icon_pixbuf);
        priv->icon_pixbuf = NULL;
    }

    (* G_OBJECT_CLASS (parent_class)->dispose) (object);
}

static void
impl_finalize (GObject *object)
{
    ETaskWidget *task_widget;
    ETaskWidgetPrivate *priv;

    task_widget = E_TASK_WIDGET (object);
    priv = task_widget->priv;

    g_free (priv->component_id);
    g_free (priv);

    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
}


static void
class_init (GObjectClass *object_class)
{
    parent_class = g_type_class_ref(PARENT_TYPE);

    object_class->dispose  = impl_dispose;
    object_class->finalize = impl_finalize;
}

static void
init (ETaskWidget *task_widget)
{
    ETaskWidgetPrivate *priv;

    priv = g_new (ETaskWidgetPrivate, 1);

    priv->component_id = NULL;
    priv->tooltips     = NULL;
    priv->icon_pixbuf  = NULL;
    priv->label        = NULL;
    priv->image        = NULL;

    task_widget->priv = priv;
}


void
e_task_widget_construct (ETaskWidget *task_widget,
             GdkPixbuf *icon_pixbuf,
             const char *component_id,
             const char *information)
{
    ETaskWidgetPrivate *priv;
    GdkPixmap *pixmap;
    GdkBitmap *mask;
    GtkWidget *box;
    GtkWidget *frame;

    g_return_if_fail (task_widget != NULL);
    g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
    g_return_if_fail (icon_pixbuf != NULL);
    g_return_if_fail (component_id != NULL);
    g_return_if_fail (information != NULL);

    priv = task_widget->priv;

    priv->component_id = g_strdup (component_id);

    frame = gtk_frame_new (NULL);
    gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
    gtk_container_add (GTK_CONTAINER (task_widget), frame);
    gtk_widget_show (frame);

    box = gtk_hbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (frame), box);
    gtk_widget_show (box);

    gtk_widget_set_size_request (box, 1, -1);

    priv->icon_pixbuf = g_object_ref (icon_pixbuf);

    gdk_pixbuf_render_pixmap_and_mask (icon_pixbuf, &pixmap, &mask, 128);

    priv->image = gtk_image_new_from_pixmap (pixmap, mask);
    gtk_widget_show (priv->image);
    gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, TRUE, 0);

    priv->label = gtk_label_new ("");
    gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
    gtk_widget_show (priv->label);
    gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0);

    gdk_pixmap_unref (pixmap);
    g_object_unref (mask);

    priv->tooltips = gtk_tooltips_new ();
    g_object_ref (priv->tooltips);
    gtk_object_sink (GTK_OBJECT (priv->tooltips));

    e_task_widget_update (task_widget, information, -1.0);
}

GtkWidget *
e_task_widget_new (GdkPixbuf *icon_pixbuf,
           const char *component_id,
           const char *information)
{
    ETaskWidget *task_widget;

    g_return_val_if_fail (icon_pixbuf != NULL, NULL);
    g_return_val_if_fail (information != NULL, NULL);

    task_widget = g_object_new (e_task_widget_get_type (), NULL);
    e_task_widget_construct (task_widget, icon_pixbuf, component_id, information);

    return GTK_WIDGET (task_widget);
}


void
e_task_widget_update (ETaskWidget *task_widget,
              const char *information,
              double completion)
{
    ETaskWidgetPrivate *priv;
    char *text;

    g_return_if_fail (task_widget != NULL);
    g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
    g_return_if_fail (information != NULL);

    priv = task_widget->priv;

    if (completion < 0.0) {
        text = g_strdup_printf (_("%s (...)"), information);
    } else {
        int percent_complete;

        percent_complete = (int) (completion * 100.0 + .5);
        text = g_strdup_printf (_("%s (%d%% complete)"), information, percent_complete);
    }

    gtk_label_set_text (GTK_LABEL (priv->label), text);

    gtk_tooltips_set_tip (priv->tooltips, GTK_WIDGET (task_widget), text, NULL);

    g_free (text);
}

void
e_task_wiget_alert (ETaskWidget *task_widget)
{
    g_return_if_fail (task_widget != NULL);
    g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
}

void
e_task_wiget_unalert (ETaskWidget *task_widget)
{
    g_return_if_fail (task_widget != NULL);
    g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
}
    

const char *
e_task_widget_get_component_id  (ETaskWidget *task_widget)
{
    g_return_val_if_fail (task_widget != NULL, NULL);
    g_return_val_if_fail (E_IS_TASK_WIDGET (task_widget), NULL);

    return task_widget->priv->component_id;
}


E_MAKE_TYPE (e_task_widget, "ETaskWidget", ETaskWidget, class_init, init, PARENT_TYPE)
by Ivar Smolin.Priit Laes2005-11-072-22/+30 * Updated Finnish translationIlkka Tuohela2005-11-032-1103/+1546 * Updated Canadian English translation.Adam Weinberger2005-11-022-9/+13 * Updated Lithuanian translation.Žygimantas Beručka2005-11-012-1157/+1634 * *** empty log message ***Ignacio Casal Quinteiro2005-11-012-3796/+3590 * Added Kurdish translationErdal Ronahi2005-10-282-0/+19845 * Updated Canadian English translation.Adam Weinberger2005-10-232-125/+160 * Updated Spanish translation.Francisco Javier F. Serrador2005-10-232-123/+164 * Updated Spanish translation.Francisco Javier F. Serrador2005-10-222-1375/+1677 * Updated Traditional Chinese translation.Chao-Hsiung Liao2005-10-212-549/+926 * Updated Simplified Chinese translationFunda Wang2005-10-201-203/+483 * Added a number of missing files. Updated Canadian English translation.Adam Weinberger2005-10-203-525/+850 * Updated Simplified Chinese translationFunda Wang2005-10-192-976/+1087 * Updated Danish translation.Martin Willemoes Hansen2005-10-172-788/+845 * Translation updated by Ivar Smolin.Priit Laes2005-10-172-1925/+2151 * Updated Bengali (bn) Translation:10/17Runa Bhattacharjee2005-10-171-1213/+1217 * Added entry for Bengali (bn) Translation addition:10/17Runa Bhattacharjee2005-10-171-0/+4 * Added Bengali (bn) Translation:10/17Runa Bhattacharjee2005-10-171-0/+20132 * Updated Traditional Chinese translation.Chao-Hsiung Liao2005-10-162-874/+982 * Translation updated.Vincent van Adrighem2005-10-152-273/+3033 * Updated Canadian English translation.Adam Weinberger2005-10-152-420/+478 * Translation updated by Ivar Smolin.Priit Laes2005-10-142-1528/+1418 * Updated Canadian English translation.Adam Weinberger2005-10-013-5210/+5117 * Updated Russian translation.Nickolay V. Shmyrev2005-09-302-421/+433 * Reverted unauthorized changes made by user 'kloczek'. Also updated theChristian Rose2005-09-302-1001/+20150 * Merged from gnome-2-12Nguyen Thai Ngoc Duy2005-09-171-27/+27 * Updated Persian translation by Elnaz Sarbar <elnaz@farsiweb.info> andRoozbeh Pournader2005-09-132-2527/+3216 * Updated Romanian translationMugurel Tudor2005-09-132-2/+6 * fixed translation, <arangela@cvs.gnome.org>Arangel Angov2005-09-121-173/+173 * removed outdated strings and run "mak update-po".Tomasz Kłoczko2005-09-11