summaryrefslogtreecommitdiff
path: root/components/rpmview/nautilus-rpm-verify-window.c
blob: 28daf31e7b8204373cf2bf8658b5862110944fd6 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* -*- 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-scalable-font.h>
#include <libnautilus-extensions/nautilus-theme.h>

struct NautilusRPMVerifyWindowDetails {
	GtkWidget *package_name;
	GtkWidget *file_message;	
		
	gboolean error_mode;
	GtkWidget *continue_button;
	GtkWidget *cancel_button;
};

enum {
	CONTINUE,
	LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];

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);

	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);
		
	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);
	
	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}

/* 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));
	
}

/* initialize the rpm_verify_window */
static void
nautilus_rpm_verify_window_initialize (NautilusRPMVerifyWindow *rpm_verify_window)
{	
	GtkWidget *window_contents;
	GtkWidget *label, *button_box;
	
	rpm_verify_window->details = g_new0 (NautilusRPMVerifyWindowDetails, 1);
	
	/* 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);
	nautilus_label_set_font_size (NAUTILUS_LABEL (label), 20);
	nautilus_label_set_text_justification (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
	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);
	nautilus_label_set_font_size (NAUTILUS_LABEL (label), 14);
	nautilus_label_set_text_justification (NAUTILUS_LABEL(label), GTK_JUSTIFY_CENTER);
	gtk_box_pack_start (GTK_BOX (window_contents), label, FALSE, FALSE, 8);
	rpm_verify_window->details->file_message = label;
	
	/* 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);
	
	/* configure the dialog */                                  
	gtk_widget_set_usize (GTK_WIDGET (rpm_verify_window), 320, 180);
	
	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 */
GtkWidget *
nautilus_rpm_verify_window_new (const char *package_name)
{
	char *title_string;
	NautilusRPMVerifyWindow *rpm_verify_window;
	
	rpm_verify_window = NAUTILUS_RPM_VERIFY_WINDOW (gtk_widget_new (nautilus_rpm_verify_window_get_type (), NULL));
	
	/* 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);
}

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);
		}
	}
}