Imported version 1.0
[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
48         debug_print(_("Creating progress dialog...\n"));
49         progress = g_new0(ProgressDialog, 1);
50
51         window = gtk_window_new(GTK_WINDOW_DIALOG);
52         gtk_widget_set_usize(window, 400, -1);
53         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
54         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
55         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
56         gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
57
58         vbox = gtk_vbox_new(FALSE, 8);
59         gtk_container_add(GTK_CONTAINER(window), vbox);
60         gtk_widget_show(vbox);
61
62         hbox = gtk_hbox_new(FALSE, 0);
63         gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 8);
64         gtk_widget_show(hbox);
65
66         label = gtk_label_new("");
67         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
68         gtk_widget_show(label);
69
70         gtkut_button_set_create(&cancel_area, &cancel_btn, _("Cancel"),
71                                 NULL, NULL, NULL, NULL);
72         gtk_box_pack_end(GTK_BOX(vbox), cancel_area, FALSE, FALSE, 0);
73         gtk_widget_grab_default(cancel_btn);
74         gtk_widget_show_all(cancel_area);
75
76         progressbar = gtk_progress_bar_new();
77         gtk_box_pack_end(GTK_BOX(vbox), progressbar, FALSE, FALSE, 0);
78         gtk_widget_show(progressbar);
79
80         progress->window      = window;
81         progress->label       = label;
82         progress->cancel_btn  = cancel_btn;
83         progress->progressbar = progressbar;
84
85         return progress;
86 }
87
88 void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
89 {
90         gtk_label_set_text(GTK_LABEL(progress->label), str);
91 }
92
93 void progress_dialog_set_value(ProgressDialog *progress, gfloat value)
94 {
95         gtk_progress_set_value(GTK_PROGRESS(progress->progressbar), value);
96 }
97
98 void progress_dialog_set_percentage(ProgressDialog *progress,
99                                     gfloat percentage)
100 {
101         gtk_progress_set_percentage(GTK_PROGRESS(progress->progressbar),
102                                     percentage);
103 }
104
105 void progress_dialog_destroy(ProgressDialog *progress)
106 {
107         if (progress) {
108                 gtk_widget_destroy(progress->window);
109                 g_free(progress);
110         }
111 }