nautilus-rpm-verify-window.c 8.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* 
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 *
 * Nautilus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Nautilus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Andy Hertzfeld <andy@eazel.com>
 *
 * This is the implementation for the rpm verify window dialog
 *
 */

#include <config.h>
#include "nautilus-rpm-verify-window.h"

#include <libgnome/gnome-defs.h>

#include <math.h>
#include <gnome.h>
#include <gdk/gdk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtksignal.h>
#include <libgnome/gnome-util.h>
#include <libgnomeui/gnome-pixmap.h>
#include <libnautilus-extensions/nautilus-gdk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-label.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-theme.h>

struct NautilusRPMVerifyWindowDetails {
	GtkWidget *package_name;
	GtkWidget *file_message;	
51
52
		
	gboolean error_mode;
53
54
	GtkWidget *continue_button;
	GtkWidget *cancel_button;
55
56
57

	unsigned long amount, total;
	char *current_file;
58
59
};

60
61
62
63
64
65
enum {
	CONTINUE,
	LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];

66
67
68
69
70
71
72
73
74
75
static void     nautilus_rpm_verify_window_initialize_class	(NautilusRPMVerifyWindowClass *klass);
static void     nautilus_rpm_verify_window_initialize		(NautilusRPMVerifyWindow *rpm_verify_window);
static void	nautilus_rpm_verify_window_destroy		(GtkObject *object);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusRPMVerifyWindow, nautilus_rpm_verify_window, GNOME_TYPE_DIALOG)

static void
nautilus_rpm_verify_window_initialize_class (NautilusRPMVerifyWindowClass *rpm_verify_window_class)
{
	GtkObjectClass *object_class = GTK_OBJECT_CLASS (rpm_verify_window_class);
76
77
78
79
80
81
82
83
84
85
86

	signals[CONTINUE]
		= gtk_signal_new ("continue",
				  GTK_RUN_LAST,
				  object_class->type,
				  GTK_SIGNAL_OFFSET (NautilusRPMVerifyWindowClass,
						     continue_verify),
				  gtk_marshal_NONE__NONE,
				  GTK_TYPE_NONE, 0);
	
	gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
87
88
89
90
91
92
93
94
95
96
97
98
99
		
	object_class->destroy = nautilus_rpm_verify_window_destroy;
}

static void 
nautilus_rpm_verify_window_destroy (GtkObject *object)
{
	NautilusRPMVerifyWindow *rpm_verify_window;
	
	rpm_verify_window = NAUTILUS_RPM_VERIFY_WINDOW (object);
		
	g_free (NAUTILUS_RPM_VERIFY_WINDOW (object)->details);
	
100
	NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
101
102
}

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* handle the continue button  */
static void
continue_button_callback (GtkWidget *widget, NautilusRPMVerifyWindow *rpm_verify_window)
{
	gtk_signal_emit (GTK_OBJECT (rpm_verify_window),
		signals[CONTINUE]);	
}

/* handle the cancel button */
static void
cancel_button_callback (GtkWidget *widget, NautilusRPMVerifyWindow *rpm_verify_window)
{
	nautilus_rpm_verify_window_set_error_mode (rpm_verify_window, FALSE);
	gnome_dialog_close (GNOME_DIALOG (rpm_verify_window));
	
}
119
120
121
122
123
124

/* initialize the rpm_verify_window */
static void
nautilus_rpm_verify_window_initialize (NautilusRPMVerifyWindow *rpm_verify_window)
{	
	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
130
131
132
133
134
135
136
137
	/* allocate a vbox to hold the contents */

	window_contents = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (GNOME_DIALOG(rpm_verify_window)->vbox), window_contents);
	gtk_widget_show (window_contents);
	
	/* allocate the package title label */
        label = nautilus_label_new ("");
	gtk_widget_show (label);
138
139
	nautilus_label_make_larger (NAUTILUS_LABEL (label), 2);
	nautilus_label_set_justify (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
140
141
142
143
144
145
	gtk_box_pack_start (GTK_BOX (window_contents), label, FALSE, FALSE, 8);
	rpm_verify_window->details->package_name = label;
	
	/* allocate the message label */
        label = nautilus_label_new ("");
	gtk_widget_show (label);
146
	nautilus_label_set_justify (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
147
148
149
	gtk_box_pack_start (GTK_BOX (window_contents), label, FALSE, FALSE, 8);
	rpm_verify_window->details->file_message = label;
	
150
151
152
153
154
155
156
157
158
159
160
161
162
	/* allocate the error mode buttons */
	button_box = gtk_hbox_new (FALSE, 2);
	gtk_widget_show (button_box);
	gtk_box_pack_start (GTK_BOX (window_contents), button_box, FALSE, FALSE, 8);
	
	rpm_verify_window->details->continue_button = gtk_button_new_with_label ("Continue");
	gtk_box_pack_start (GTK_BOX (button_box), rpm_verify_window->details->continue_button, FALSE, FALSE, 4);
	gtk_signal_connect(GTK_OBJECT (rpm_verify_window->details->continue_button), "clicked", GTK_SIGNAL_FUNC (continue_button_callback), rpm_verify_window);
	
	rpm_verify_window->details->cancel_button = gtk_button_new_with_label ("Cancel");
	gtk_box_pack_start (GTK_BOX (button_box), rpm_verify_window->details->cancel_button, FALSE, FALSE, 4);
	gtk_signal_connect(GTK_OBJECT (rpm_verify_window->details->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_button_callback), rpm_verify_window);
	
163
	/* configure the dialog */                                  
164
	gtk_widget_set_usize (GTK_WIDGET (rpm_verify_window), 420, 180);
165
166
167
168
169
170
171
172
173
	
	gnome_dialog_append_button ( GNOME_DIALOG(rpm_verify_window),
				     GNOME_STOCK_BUTTON_OK);
	
	gnome_dialog_set_close (GNOME_DIALOG(rpm_verify_window), TRUE);			
	gnome_dialog_close_hides (GNOME_DIALOG(rpm_verify_window), TRUE);			
}

/* allocate a new rpm_verify_window dialog */
174
GtkWidget *
175
176
177
178
179
nautilus_rpm_verify_window_new (const char *package_name)
{
	char *title_string;
	NautilusRPMVerifyWindow *rpm_verify_window;
	
180
	rpm_verify_window = NAUTILUS_RPM_VERIFY_WINDOW (gtk_widget_new (nautilus_rpm_verify_window_get_type (), NULL));
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
	
	/* set up the window title */
	title_string = g_strdup_printf (_("Verifying %s..."), package_name);
	gtk_window_set_title (GTK_WINDOW (rpm_verify_window), title_string);
	
	/* set up the package name */
	nautilus_label_set_text (NAUTILUS_LABEL (rpm_verify_window->details->package_name), title_string);
	g_free (title_string);
	
	return GTK_WIDGET (rpm_verify_window);
}

void
nautilus_rpm_verify_window_set_message (NautilusRPMVerifyWindow *window, const char *message)
{
	nautilus_label_set_text (NAUTILUS_LABEL (window->details->file_message), message);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
        while (gtk_events_pending ()) {
                gtk_main_iteration ();
        }
}

static void
nautilus_rpm_verify_window_update_message (NautilusRPMVerifyWindow *window)
{
	char *message = NULL;
	if (window->details->error_mode) {
		message = g_strdup_printf (_("Failed on \"%s\""), window->details->current_file); 
	} else {
		/* TRANSLATORS: this is printed while verifying files from packages, 
		   %s is the filename, %d/%d is filenumber of total-number-of-files */
211
		message = g_strdup_printf (_("Checking \"%s\" (%ld/%ld)"), 
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
					   window->details->current_file, 
					   window->details->amount, 
					   window->details->total);
	}
	nautilus_rpm_verify_window_set_message (window, message);
	g_free (message);
}

void
nautilus_rpm_verify_window_set_progress (NautilusRPMVerifyWindow *window, 
					 const char *file, 
					 unsigned long amount, 
					 unsigned long total)
{
	g_free (window->details->current_file);
	window->details->current_file = g_strdup (file);
	window->details->amount = amount;
	window->details->total = total;
230
	nautilus_rpm_verify_window_update_message (window);
231
}
232
233
234
235
236
237
238
239
240
241
242
243
244

void
nautilus_rpm_verify_window_set_error_mode (NautilusRPMVerifyWindow *window, gboolean error_mode)
{
	if (window->details->error_mode != error_mode) {
		window->details->error_mode = error_mode;
		if (error_mode) {
			gtk_widget_show (window->details->continue_button);
			gtk_widget_show (window->details->cancel_button);
		} else {
			gtk_widget_hide (window->details->continue_button);
			gtk_widget_hide (window->details->cancel_button);
		}
245
		nautilus_rpm_verify_window_update_message (window);			
246
247
248
	}
}