Implemented a progress bar that counts the number of completed tasks when the action...
[claws.git] / src / noticeview.c
1 /* 
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002 Hiroyuki Yamamoto & The Sylpheed Claws Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtkhbox.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtklabel.h>
31 #include <gtk/gtkpixmap.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <time.h>
35
36 #if HAVE_LIBCOMPFACE
37 #  include <compface.h>
38 #endif
39
40 #include "intl.h"
41 #include "prefs_common.h"
42 #include "gtkutils.h"
43 #include "utils.h"
44 #include "stock_pixmap.h"
45
46 #include "noticeview.h"
47
48 static void noticeview_button_pressed   (GtkButton *button, NoticeView *noticeview);
49
50 NoticeView *noticeview_create(MainWindow *mainwin)
51 {
52         NoticeView *noticeview;
53         GtkWidget  *vbox;
54         GtkWidget  *hsep;
55         GtkWidget  *hbox;
56         GtkWidget  *icon;
57         GtkWidget  *text;
58         GtkWidget  *widget;
59
60         debug_print("Creating notice view...\n");
61         noticeview = g_new0(NoticeView, 1);
62
63         vbox = gtk_vbox_new(FALSE, 4);
64         gtk_widget_show(vbox);
65         hsep = gtk_hseparator_new();
66         gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 0);
67         
68         hbox = gtk_hbox_new(FALSE, 4);
69         gtk_widget_show(hbox);
70         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
71
72         icon = stock_pixmap_widget(mainwin->window, STOCK_PIXMAP_NOTICE_WARN); 
73 #if 0
74         /* also possible... */
75         icon = gtk_pixmap_new(NULL, NULL);
76 #endif
77         gtk_widget_show(icon);
78         
79         gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, TRUE, 0);
80         
81         text = gtk_label_new("");
82         gtk_widget_show(text);
83         gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
84
85         widget = gtk_button_new_with_label("");
86         gtk_signal_connect(GTK_OBJECT(widget), "clicked", 
87                            GTK_SIGNAL_FUNC(noticeview_button_pressed),
88                            (gpointer) noticeview);
89         gtk_widget_show(widget);
90         gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
91         
92         noticeview->vbox   = vbox;
93         noticeview->hsep   = hsep;
94         noticeview->hbox   = hbox;
95         noticeview->icon   = icon;
96         noticeview->text   = text;
97         noticeview->button = widget;
98
99         noticeview->visible = TRUE;
100
101         return noticeview;
102 }
103
104 void noticeview_destroy(NoticeView *noticeview)
105 {
106         g_free(noticeview);
107 }
108
109 gboolean noticeview_is_visible(NoticeView *noticeview)
110 {
111         return noticeview->visible;
112 }
113
114 void noticeview_show(NoticeView *noticeview)
115 {
116         if (!noticeview->visible) {
117                 gtk_widget_show_all(GTK_WIDGET_PTR(noticeview));
118                 noticeview->visible = TRUE;
119         }       
120 }
121
122 void noticeview_hide(NoticeView *noticeview)
123 {
124         if (noticeview->visible) {
125                 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
126                 noticeview->visible = FALSE;
127         }       
128 }
129
130 void noticeview_set_text(NoticeView *noticeview, const char *text)
131 {
132         g_return_if_fail(noticeview);
133         gtk_label_set_text(GTK_LABEL(noticeview->text), text);
134 }
135
136 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
137 {
138         g_return_if_fail(noticeview);
139         gtk_label_set_text
140                 (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
141 }
142
143 void noticeview_set_button_press_callback(NoticeView    *noticeview,
144                                           GtkSignalFunc  callback,
145                                           gpointer      *user_data)
146 {
147         noticeview->press     = (void (*) (NoticeView *, gpointer)) callback;
148         noticeview->user_data = user_data;
149 }
150
151 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
152 {
153         if (noticeview->press) {
154                 noticeview->press(noticeview, noticeview->user_data);
155         }
156 }
157