replace deprecated gtk_progress*
[claws.git] / src / gtk / progressdialog.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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/gtkscrolledwindow.h>
31 #include <gtk/gtkbutton.h>
32
33 #include "intl.h"
34 #include "progressdialog.h"
35 #include "gtkutils.h"
36 #include "utils.h"
37
38 ProgressDialog *progress_dialog_create(void)
39 {
40         ProgressDialog *progress;
41         GtkWidget *window;
42         GtkWidget *vbox;
43         GtkWidget *hbox;
44         GtkWidget *label;
45         GtkWidget *cancel_btn;
46         GtkWidget *cancel_area;
47         GtkWidget *progressbar;
48         GtkWidget *scrolledwin;
49         GtkWidget *clist;
50         gchar *text[] = {NULL, NULL, NULL};
51
52         text[1] = _("Account");
53         text[2] = _("Status");
54
55         debug_print("Creating progress dialog...\n");
56         progress = g_new0(ProgressDialog, 1);
57
58         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
59         gtk_widget_set_usize(window, 460, -1);
60         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
61         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
62         gtk_widget_realize(window);
63
64         vbox = gtk_vbox_new(FALSE, 8);
65         gtk_container_add(GTK_CONTAINER(window), vbox);
66         gtk_widget_show(vbox);
67
68         hbox = gtk_hbox_new(FALSE, 0);
69         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 8);
70         gtk_widget_show(hbox);
71
72         label = gtk_label_new("");
73         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
74         gtk_widget_show(label);
75
76         gtkut_button_set_create(&cancel_area, &cancel_btn, _("Cancel"),
77                                 NULL, NULL, NULL, NULL);
78         gtk_box_pack_end(GTK_BOX(vbox), cancel_area, FALSE, FALSE, 0);
79         gtk_widget_grab_default(cancel_btn);
80         gtk_widget_show_all(cancel_area);
81
82         progressbar = gtk_progress_bar_new();
83         gtk_box_pack_start(GTK_BOX(vbox), progressbar, FALSE, FALSE, 0);
84         gtk_widget_show(progressbar);
85
86         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
87         gtk_widget_show(scrolledwin);
88         gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
89         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
90                                        GTK_POLICY_AUTOMATIC,
91                                        GTK_POLICY_AUTOMATIC);
92
93         clist = gtk_clist_new_with_titles(3, text);
94         gtk_widget_show(clist);
95         gtk_container_add(GTK_CONTAINER(scrolledwin), clist);
96         gtk_widget_set_usize(clist, -1, 120);
97         gtk_clist_set_column_justification(GTK_CLIST(clist), 0,
98                                            GTK_JUSTIFY_CENTER);
99         gtk_clist_set_column_width(GTK_CLIST(clist), 0, 16);
100         gtk_clist_set_column_width(GTK_CLIST(clist), 1, 160);
101
102         progress->window      = window;
103         progress->label       = label;
104         progress->cancel_btn  = cancel_btn;
105         progress->progressbar = progressbar;
106         progress->clist       = clist;
107
108         return progress;
109 }
110
111 void progress_dialog_set_label(ProgressDialog *progress, gchar *str)
112 {
113         gtk_label_set_text(GTK_LABEL(progress->label), str);
114 }
115
116 void progress_dialog_get_fraction(ProgressDialog *progress)
117 {
118         gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->progressbar));
119 }
120
121 void progress_dialog_set_fraction(ProgressDialog *progress,
122                                   gfloat percentage)
123 {
124         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->progressbar),
125                                       percentage);
126 }
127
128 void progress_dialog_destroy(ProgressDialog *progress)
129 {
130         if (progress) {
131                 gtk_widget_destroy(progress->window);
132                 g_free(progress);
133         }
134 }