b5cade71c3cf10cfafd6150dc85096878f801d3c
[claws.git] / src / progressdialog.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
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 <glib.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkvbox.h>
27 #include <gtk/gtkhbox.h>
28 #include <gtk/gtklabel.h>
29 #include <gtk/gtkprogressbar.h>
30 #include <gtk/gtkbutton.h>
31
32 #include "intl.h"
33 #include "progressdialog.h"
34 #include "gtkutils.h"
35 #include "utils.h"
36
37 ProgressDialog *progress_dialog_create(void)
38 {
39         ProgressDialog *progress;
40         GtkWidget *window;
41         GtkWidget *vbox;
42         GtkWidget *hbox;
43         GtkWidget *label;
44         GtkWidget *cancel_btn;
45         GtkWidget *cancel_area;
46         GtkWidget *progressbar;
47         GtkWidget *clist;
48         gchar *text[] = {NULL, NULL, NULL};
49
50         text[1] = _("Account");
51         text[2] = _("Status");
52
53         debug_print(_("Creating progress dialog...\n"));
54         progress = g_new0(ProgressDialog, 1);
55
56         window = gtk_window_new(GTK_WINDOW_DIALOG);
57         gtk_widget_set_usize(window, 450, -1);
58         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
59         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
60         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
61         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
62
63         vbox = gtk_vbox_new(FALSE, 8);
64         gtk_container_add(GTK_CONTAINER(window), vbox);
65         gtk_widget_show(vbox);
66
67         hbox = gtk_hbox_new(FALSE, 0);
68         gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 8);
69         gtk_widget_show(hbox);
70
71         label = gtk_label_new("");
72         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
73         gtk_widget_show(label);
74
75         gtkut_button_set_create(&cancel_area, &cancel_btn, _("Cancel"),
76                                 NULL, NULL, NULL, NULL);
77         gtk_box_pack_end(GTK_BOX(vbox), cancel_area, FALSE, FALSE, 0);
78         gtk_widget_grab_default(cancel_btn);
79         gtk_widget_show_all(cancel_area);
80
81         progressbar = gtk_progress_bar_new();
82         gtk_box_pack_start(GTK_BOX(vbox), progressbar, FALSE, FALSE, 0);
83         gtk_widget_show(progressbar);
84
85         clist = gtk_clist_new_with_titles(3, text);
86         gtk_widget_show(clist);
87         gtk_box_pack_start(GTK_BOX(vbox), clist, TRUE, TRUE, 0);
88         gtk_widget_set_usize(clist, -1, 120);
89         gtk_clist_set_column_justification(GTK_CLIST(clist), 0,
90                                            GTK_JUSTIFY_CENTER);
91         gtk_clist_set_column_width(GTK_CLIST(clist), 0, 16);
92         gtk_clist_set_column_width(GTK_CLIST(clist), 1, 180);
93
94         progress->window      = window;
95         progress->label       = label;
96         progress->cancel_btn  = cancel_btn;
97         progress->progressbar = progressbar;
98         progress->clist       = clist;
99
100         return progress;
101 }
102
103 void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
104 {
105         gtk_label_set_text(GTK_LABEL(progress->label), str);
106 }
107
108 void progress_dialog_set_value(ProgressDialog *progress, gfloat value)
109 {
110         gtk_progress_set_value(GTK_PROGRESS(progress->progressbar), value);
111 }
112
113 void progress_dialog_set_percentage(ProgressDialog *progress,
114                                     gfloat percentage)
115 {
116         gtk_progress_set_percentage(GTK_PROGRESS(progress->progressbar),
117                                     percentage);
118 }
119
120 void progress_dialog_destroy(ProgressDialog *progress)
121 {
122         if (progress) {
123                 gtk_widget_destroy(progress->window);
124                 g_free(progress);
125         }
126 }