2005-08-27 [colin] 1.9.13cvs66
[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 <glib/gi18n.h>
28 #include <gtk/gtkwidget.h>
29 #include <gtk/gtkhbox.h>
30 #include <gtk/gtkvbox.h>
31 #include <gtk/gtklabel.h>
32 #include <gtk/gtkpixmap.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <time.h>
36
37 #if HAVE_LIBCOMPFACE
38 #  include <compface.h>
39 #endif
40
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 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview);
50
51 NoticeView *noticeview_create(MainWindow *mainwin)
52 {
53         NoticeView *noticeview;
54         GtkWidget  *vbox;
55         GtkWidget  *hsep;
56         GtkWidget  *hbox;
57         GtkWidget  *icon;
58         GtkWidget  *text;
59         GtkWidget  *widget;
60         GtkWidget  *widget2;
61
62         debug_print("Creating notice view...\n");
63         noticeview = g_new0(NoticeView, 1);
64
65         noticeview->window = mainwin->window;
66         
67         vbox = gtk_vbox_new(FALSE, 4);
68         gtk_widget_show(vbox);
69         hsep = gtk_hseparator_new();
70         gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 1);
71         
72         hbox = gtk_hbox_new(FALSE, 4);
73         gtk_widget_show(hbox);
74         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 1);
75
76         icon = stock_pixmap_widget(noticeview->window, STOCK_PIXMAP_NOTICE_WARN); 
77 #if 0
78         /* also possible... */
79         icon = gtk_pixmap_new(NULL, NULL);
80 #endif
81         gtk_widget_show(icon);
82         
83         gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, TRUE, 0);
84         
85         text = gtk_label_new("");
86         gtk_widget_show(text);
87         gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
88
89         widget = gtk_button_new_with_label("");
90         gtk_widget_set_size_request(widget, 120, -1);
91         g_signal_connect(G_OBJECT(widget), "clicked", 
92                          G_CALLBACK(noticeview_button_pressed),
93                          (gpointer) noticeview);
94         gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
95         
96         widget2 = gtk_button_new_with_label("");
97         gtk_widget_set_size_request(widget2, 120, -1);
98         g_signal_connect(G_OBJECT(widget2), "clicked", 
99                          G_CALLBACK(noticeview_2ndbutton_pressed),
100                          (gpointer) noticeview);
101         gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 0);
102         
103         noticeview->vbox   = vbox;
104         noticeview->hsep   = hsep;
105         noticeview->hbox   = hbox;
106         noticeview->icon   = icon;
107         noticeview->text   = text;
108         noticeview->button = widget;
109         noticeview->button2 = widget2;
110
111         noticeview->visible = TRUE;
112
113         return noticeview;
114 }
115
116 void noticeview_destroy(NoticeView *noticeview)
117 {
118         g_free(noticeview);
119 }
120
121 gboolean noticeview_is_visible(NoticeView *noticeview)
122 {
123         return noticeview->visible;
124 }
125
126 void noticeview_show(NoticeView *noticeview)
127 {
128         if (!noticeview->visible) {
129                 gtk_widget_show(GTK_WIDGET_PTR(noticeview));
130                 noticeview->visible = TRUE;
131         }       
132 }
133
134 void noticeview_hide(NoticeView *noticeview)
135 {
136         if (noticeview->visible) {
137                 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
138                 noticeview->visible = FALSE;
139         }       
140 }
141
142 void noticeview_set_text(NoticeView *noticeview, const char *text)
143 {
144         g_return_if_fail(noticeview);
145         gtk_label_set_text(GTK_LABEL(noticeview->text), text);
146 }
147
148 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
149 {
150         g_return_if_fail(noticeview);
151
152         if (text != NULL) {
153                 gtk_label_set_text
154                         (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
155                 gtk_widget_show(noticeview->button);
156         } else
157                 gtk_widget_hide(noticeview->button);
158         
159         /* Callers defining only one button don't have to mind 
160          * resetting the second one. Callers defining two have
161          * to define the second button after the first one. 
162          */
163         gtk_widget_hide(noticeview->button2);
164 }
165
166 void noticeview_set_button_press_callback(NoticeView    *noticeview,
167                                           GtkSignalFunc  callback,
168                                           gpointer      *user_data)
169 {
170         noticeview->press     = (void (*) (NoticeView *, gpointer)) callback;
171         noticeview->user_data = user_data;
172 }
173
174 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
175 {
176         if (noticeview->press) {
177                 noticeview->press(noticeview, noticeview->user_data);
178         }
179 }
180
181 void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
182 {
183         g_return_if_fail(noticeview);
184
185         if (text != NULL) {
186                 gtk_label_set_text
187                         (GTK_LABEL(GTK_BIN(noticeview->button2)->child), text);
188                 gtk_widget_show(noticeview->button2);
189         } else
190                 gtk_widget_hide(noticeview->button2);
191 }
192
193 void noticeview_set_2ndbutton_press_callback(NoticeView *noticeview,
194                                           GtkSignalFunc  callback,
195                                           gpointer      *user_data)
196 {
197         noticeview->press2     = (void (*) (NoticeView *, gpointer)) callback;
198         noticeview->user_data2 = user_data;
199 }
200
201 static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
202 {
203         if (noticeview->press2) {
204                 noticeview->press2(noticeview, noticeview->user_data2);
205         }
206 }
207
208 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
209 {
210         GdkPixmap *pixmap;
211         GdkBitmap *bitmap;
212         
213         if (stock_pixmap_gdk(noticeview->window, icon, &pixmap, &bitmap) < 0)
214                 return;
215         
216         gtk_image_set_from_pixmap(GTK_IMAGE(noticeview->icon), pixmap, bitmap);
217 }