* src/folder.[ch]
[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 "main.h"
42 #include "headerview.h"
43 #include "prefs_common.h"
44 #include "gtkutils.h"
45 #include "utils.h"
46 #include "stock_pixmap.h"
47
48 #include "noticeview.h"
49
50 static void noticeview_button_pressed   (GtkButton *button, NoticeView *noticeview);
51
52 NoticeView *noticeview_create(MainWindow *mainwin)
53 {
54         NoticeView *noticeview;
55         GtkWidget  *vbox;
56         GtkWidget  *hsep;
57         GtkWidget  *hbox;
58         GtkWidget  *icon;
59         GtkWidget  *text;
60         GtkWidget  *widget;
61
62         debug_print("Creating notice view...\n");
63         noticeview = g_new0(NoticeView, 1);
64
65         vbox = gtk_vbox_new(FALSE, 4);
66         gtk_widget_show(vbox);
67         hsep = gtk_hseparator_new();
68         gtk_box_pack_start(GTK_BOX(vbox), hsep, FALSE, TRUE, 0);
69         
70         hbox = gtk_hbox_new(FALSE, 4);
71         gtk_widget_show(hbox);
72         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
73
74         icon = stock_pixmap_widget(mainwin->window, STOCK_PIXMAP_NOTICE_WARN); 
75 #if 0
76         /* also possible... */
77         icon = gtk_pixmap_new(NULL, NULL);
78 #endif
79         gtk_widget_show(icon);
80         
81         gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, TRUE, 0);
82         
83         text = gtk_label_new("");
84         gtk_widget_show(text);
85         gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 0);
86
87         widget = gtk_button_new_with_label("");
88         gtk_signal_connect(GTK_OBJECT(widget), "clicked", 
89                            GTK_SIGNAL_FUNC(noticeview_button_pressed),
90                            (gpointer) noticeview);
91         gtk_widget_show(widget);
92         gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
93         
94         noticeview->vbox   = vbox;
95         noticeview->hsep   = hsep;
96         noticeview->hbox   = hbox;
97         noticeview->icon   = icon;
98         noticeview->text   = text;
99         noticeview->button = widget;
100
101         noticeview->visible = TRUE;
102
103         return noticeview;
104 }
105
106 void noticeview_destroy(NoticeView *noticeview)
107 {
108         g_free(noticeview);
109 }
110
111 gboolean noticeview_is_visible(NoticeView *noticeview)
112 {
113         return noticeview->visible;
114 }
115
116 void noticeview_show(NoticeView *noticeview)
117 {
118         if (!noticeview->visible) {
119                 gtk_widget_show_all(GTK_WIDGET_PTR(noticeview));
120                 noticeview->visible = TRUE;
121         }       
122 }
123
124 void noticeview_hide(NoticeView *noticeview)
125 {
126         if (noticeview->visible) {
127                 gtk_widget_hide(GTK_WIDGET_PTR(noticeview));
128                 noticeview->visible = FALSE;
129         }       
130 }
131
132 void noticeview_set_text(NoticeView *noticeview, const char *text)
133 {
134         g_return_if_fail(noticeview);
135         gtk_label_set_text(GTK_LABEL(noticeview->text), text);
136 }
137
138 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
139 {
140         g_return_if_fail(noticeview);
141         gtk_label_set_text
142                 (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
143 }
144
145 void noticeview_set_button_press_callback(NoticeView    *noticeview,
146                                           GtkSignalFunc  callback,
147                                           gpointer      *user_data)
148 {
149         noticeview->press     = (void (*) (NoticeView *, gpointer)) callback;
150         noticeview->user_data = user_data;
151 }
152
153 static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
154 {
155         if (noticeview->press) {
156                 noticeview->press(noticeview, noticeview->user_data);
157         }
158 }
159