root/trunk/third/nautilus/components/rpmview/nautilus-rpm-verify-window.c @ 15547

Revision 15547, 8.4 KB (checked in by ghudson, 9 years ago)

This commit was generated by cvs2svn to compensate for changes in r15546,
which included commits to RCS files with non-trunk default branches.

Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/*
4 * Nautilus
5 *
6 * Copyright (C) 2000 Eazel, Inc.
7 *
8 * Nautilus is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 *
22 * Author: Andy Hertzfeld <andy@eazel.com>
23 *
24 * This is the implementation for the rpm verify window dialog
25 *
26 */
27
28#include <config.h>
29#include "nautilus-rpm-verify-window.h"
30
31#include <libgnome/gnome-defs.h>
32
33#include <math.h>
34#include <gnome.h>
35#include <gdk/gdk.h>
36#include <gdk-pixbuf/gdk-pixbuf.h>
37#include <gtk/gtksignal.h>
38#include <libgnome/gnome-util.h>
39#include <libgnomeui/gnome-pixmap.h>
40#include <libnautilus-extensions/nautilus-gdk-extensions.h>
41#include <libnautilus-extensions/nautilus-gtk-macros.h>
42#include <libnautilus-extensions/nautilus-gtk-extensions.h>
43#include <libnautilus-extensions/nautilus-glib-extensions.h>
44#include <libnautilus-extensions/nautilus-label.h>
45#include <libnautilus-extensions/nautilus-file-utilities.h>
46#include <libnautilus-extensions/nautilus-theme.h>
47
48struct NautilusRPMVerifyWindowDetails {
49        GtkWidget *package_name;
50        GtkWidget *file_message;       
51               
52        gboolean error_mode;
53        GtkWidget *continue_button;
54        GtkWidget *cancel_button;
55
56        unsigned long amount, total;
57        char *current_file;
58};
59
60enum {
61        CONTINUE,
62        LAST_SIGNAL
63};
64static guint signals[LAST_SIGNAL];
65
66static void     nautilus_rpm_verify_window_initialize_class     (NautilusRPMVerifyWindowClass *klass);
67static void     nautilus_rpm_verify_window_initialize           (NautilusRPMVerifyWindow *rpm_verify_window);
68static void     nautilus_rpm_verify_window_destroy              (GtkObject *object);
69
70NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusRPMVerifyWindow, nautilus_rpm_verify_window, GNOME_TYPE_DIALOG)
71
72static void
73nautilus_rpm_verify_window_initialize_class (NautilusRPMVerifyWindowClass *rpm_verify_window_class)
74{
75        GtkObjectClass *object_class = GTK_OBJECT_CLASS (rpm_verify_window_class);
76
77        signals[CONTINUE]
78                = gtk_signal_new ("continue",
79                                  GTK_RUN_LAST,
80                                  object_class->type,
81                                  GTK_SIGNAL_OFFSET (NautilusRPMVerifyWindowClass,
82                                                     continue_verify),
83                                  gtk_marshal_NONE__NONE,
84                                  GTK_TYPE_NONE, 0);
85       
86        gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
87               
88        object_class->destroy = nautilus_rpm_verify_window_destroy;
89}
90
91static void 
92nautilus_rpm_verify_window_destroy (GtkObject *object)
93{
94        NautilusRPMVerifyWindow *rpm_verify_window;
95       
96        rpm_verify_window = NAUTILUS_RPM_VERIFY_WINDOW (object);
97               
98        g_free (NAUTILUS_RPM_VERIFY_WINDOW (object)->details);
99       
100        NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
101}
102
103/* handle the continue button  */
104static void
105continue_button_callback (GtkWidget *widget, NautilusRPMVerifyWindow *rpm_verify_window)
106{
107        gtk_signal_emit (GTK_OBJECT (rpm_verify_window),
108                signals[CONTINUE]);     
109}
110
111/* handle the cancel button */
112static void
113cancel_button_callback (GtkWidget *widget, NautilusRPMVerifyWindow *rpm_verify_window)
114{
115        nautilus_rpm_verify_window_set_error_mode (rpm_verify_window, FALSE);
116        gnome_dialog_close (GNOME_DIALOG (rpm_verify_window));
117       
118}
119
120/* initialize the rpm_verify_window */
121static void
122nautilus_rpm_verify_window_initialize (NautilusRPMVerifyWindow *rpm_verify_window)
123{       
124        GtkWidget *window_contents;
125        GtkWidget *label, *button_box;
126       
127        rpm_verify_window->details = g_new0 (NautilusRPMVerifyWindowDetails, 1);
128        rpm_verify_window->details->current_file = NULL;
129        /* allocate a vbox to hold the contents */
130
131        window_contents = gtk_vbox_new (FALSE, 0);
132        gtk_container_add (GTK_CONTAINER (GNOME_DIALOG(rpm_verify_window)->vbox), window_contents);
133        gtk_widget_show (window_contents);
134       
135        /* allocate the package title label */
136        label = nautilus_label_new ("");
137        gtk_widget_show (label);
138        nautilus_label_make_larger (NAUTILUS_LABEL (label), 2);
139        nautilus_label_set_justify (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
140        gtk_box_pack_start (GTK_BOX (window_contents), label, FALSE, FALSE, 8);
141        rpm_verify_window->details->package_name = label;
142       
143        /* allocate the message label */
144        label = nautilus_label_new ("");
145        gtk_widget_show (label);
146        nautilus_label_set_justify (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
147        gtk_box_pack_start (GTK_BOX (window_contents), label, FALSE, FALSE, 8);
148        rpm_verify_window->details->file_message = label;
149       
150        /* allocate the error mode buttons */
151        button_box = gtk_hbox_new (FALSE, 2);
152        gtk_widget_show (button_box);
153        gtk_box_pack_start (GTK_BOX (window_contents), button_box, FALSE, FALSE, 8);
154       
155        rpm_verify_window->details->continue_button = gtk_button_new_with_label ("Continue");
156        gtk_box_pack_start (GTK_BOX (button_box), rpm_verify_window->details->continue_button, FALSE, FALSE, 4);
157        gtk_signal_connect(GTK_OBJECT (rpm_verify_window->details->continue_button), "clicked", GTK_SIGNAL_FUNC (continue_button_callback), rpm_verify_window);
158       
159        rpm_verify_window->details->cancel_button = gtk_button_new_with_label ("Cancel");
160        gtk_box_pack_start (GTK_BOX (button_box), rpm_verify_window->details->cancel_button, FALSE, FALSE, 4);
161        gtk_signal_connect(GTK_OBJECT (rpm_verify_window->details->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_button_callback), rpm_verify_window);
162       
163        /* configure the dialog */                                 
164        gtk_widget_set_usize (GTK_WIDGET (rpm_verify_window), 420, 180);
165       
166        gnome_dialog_append_button ( GNOME_DIALOG(rpm_verify_window),
167                                     GNOME_STOCK_BUTTON_OK);
168       
169        gnome_dialog_set_close (GNOME_DIALOG(rpm_verify_window), TRUE);                 
170        gnome_dialog_close_hides (GNOME_DIALOG(rpm_verify_window), TRUE);                       
171}
172
173/* allocate a new rpm_verify_window dialog */
174GtkWidget *
175nautilus_rpm_verify_window_new (const char *package_name)
176{
177        char *title_string;
178        NautilusRPMVerifyWindow *rpm_verify_window;
179       
180        rpm_verify_window = NAUTILUS_RPM_VERIFY_WINDOW (gtk_widget_new (nautilus_rpm_verify_window_get_type (), NULL));
181       
182        /* set up the window title */
183        title_string = g_strdup_printf (_("Verifying %s..."), package_name);
184        gtk_window_set_title (GTK_WINDOW (rpm_verify_window), title_string);
185       
186        /* set up the package name */
187        nautilus_label_set_text (NAUTILUS_LABEL (rpm_verify_window->details->package_name), title_string);
188        g_free (title_string);
189       
190        return GTK_WIDGET (rpm_verify_window);
191}
192
193void
194nautilus_rpm_verify_window_set_message (NautilusRPMVerifyWindow *window, const char *message)
195{
196        nautilus_label_set_text (NAUTILUS_LABEL (window->details->file_message), message);
197        while (gtk_events_pending ()) {
198                gtk_main_iteration ();
199        }
200}
201
202static void
203nautilus_rpm_verify_window_update_message (NautilusRPMVerifyWindow *window)
204{
205        char *message = NULL;
206        if (window->details->error_mode) {
207                message = g_strdup_printf (_("Failed on \"%s\""), window->details->current_file); 
208        } else {
209                /* TRANSLATORS: this is printed while verifying files from packages,
210                   %s is the filename, %d/%d is filenumber of total-number-of-files */
211                message = g_strdup_printf (_("Checking \"%s\" (%ld/%ld)"), 
212                                           window->details->current_file, 
213                                           window->details->amount, 
214                                           window->details->total);
215        }
216        nautilus_rpm_verify_window_set_message (window, message);
217        g_free (message);
218}
219
220void
221nautilus_rpm_verify_window_set_progress (NautilusRPMVerifyWindow *window, 
222                                         const char *file, 
223                                         unsigned long amount, 
224                                         unsigned long total)
225{
226        g_free (window->details->current_file);
227        window->details->current_file = g_strdup (file);
228        window->details->amount = amount;
229        window->details->total = total;
230        nautilus_rpm_verify_window_update_message (window);
231}
232
233void
234nautilus_rpm_verify_window_set_error_mode (NautilusRPMVerifyWindow *window, gboolean error_mode)
235{
236        if (window->details->error_mode != error_mode) {
237                window->details->error_mode = error_mode;
238                if (error_mode) {
239                        gtk_widget_show (window->details->continue_button);
240                        gtk_widget_show (window->details->cancel_button);
241                } else {
242                        gtk_widget_hide (window->details->continue_button);
243                        gtk_widget_hide (window->details->cancel_button);
244                }
245                nautilus_rpm_verify_window_update_message (window);                     
246        }
247}
248
Note: See TracBrowser for help on using the browser.