summaryrefslogtreecommitdiff
path: root/src/dlg-prop.c
blob: cb8ed87433688c11dfc21db26f0e882c9974b3a5 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Engrampa
 *
 *  Copyright (C) 2001, 2004 Free Software Foundation, Inc.
 *
 *  This program 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.
 *
 *  This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include "glib-utils.h"
#include "file-utils.h"
#include "gtk-utils.h"
#include "fr-window.h"
#include "dlg-prop.h"

#define GET_LABEL(x) (GTK_LABEL (gtk_builder_get_object (builder, (x))))
#define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (builder, (x))))

typedef struct {
	GtkWidget *dialog;
} DialogData;

/* called when the main dialog is closed. */
static void
destroy_cb (GtkWidget  *widget,
	    DialogData *data)
{
	g_free (data);
}

static int
help_cb (GtkWidget   *w,
	 DialogData  *data)
{
	show_help_dialog (GTK_WINDOW (data->dialog), "engrampa-view-archive-properties");
	return TRUE;
}

void
dlg_prop (FrWindow *window)
{
	GtkBuilder       *builder;
	DialogData       *data;
	GFile            *parent;
	char             *uri;
	char             *markup;
	char             *s;
	goffset           size, uncompressed_size;
	char             *utf8_name;
	char             *title_txt;
	double            ratio;

	data = g_new (DialogData, 1);
	builder = gtk_builder_new_from_resource (ENGRAMPA_RESOURCE_UI_PATH G_DIR_SEPARATOR_S "properties.ui");

	/* Get the widgets. */

	data->dialog = GET_WIDGET ("prop_dialog");

	/* Set widgets data. */

	uri = remove_level_from_path (fr_window_get_archive_uri (window));
	parent = g_file_new_for_uri (uri);
	utf8_name = g_file_get_parse_name (parent);
	markup = g_strdup_printf ("<a href=\"%s\">%s</a>", uri, utf8_name);
	gtk_label_set_markup (GET_LABEL ("p_path_label"), markup);

	g_free (markup);
	g_free (utf8_name);
	g_free (uri);
	g_object_unref (parent);

	/**/

	utf8_name = g_uri_display_basename (fr_window_get_archive_uri (window));
	gtk_label_set_text (GET_LABEL ("p_name_label"), utf8_name);

	title_txt = g_strdup_printf (_("%s Properties"), utf8_name);
	gtk_window_set_title (GTK_WINDOW (data->dialog), title_txt);
	g_free (title_txt);

	g_free (utf8_name);

	/**/

	GDateTime *date_time;
	date_time = g_date_time_new_from_unix_local (get_file_mtime (fr_window_get_archive_uri (window)));
	s = g_date_time_format (date_time, _("%d %B %Y, %H:%M"));
	g_date_time_unref (date_time);
	gtk_label_set_text (GET_LABEL ("p_date_label"), s);
	g_free (s);

	/**/

	size = get_file_size (fr_window_get_archive_uri (window));
	s = g_format_size_full (size, G_FORMAT_SIZE_LONG_FORMAT);
	gtk_label_set_text (GET_LABEL ("p_size_label"), s);
	g_free (s);

	/**/

	uncompressed_size = 0;
	if (fr_window_archive_is_present (window)) {
		guint i;

		for (i = 0; i < window->archive->command->files->len; i++) {
			FileData *fd = g_ptr_array_index (window->archive->command->files, i);
			uncompressed_size += fd->size;
		}
	}

	s = g_format_size_full (uncompressed_size, G_FORMAT_SIZE_LONG_FORMAT);
	gtk_label_set_text (GET_LABEL ("p_uncomp_size_label"), s);
	g_free (s);

	/**/

	if (uncompressed_size != 0)
		ratio = (double) uncompressed_size / size;
	else
		ratio = 0.0;
	s = g_strdup_printf ("%0.2f", ratio);
	gtk_label_set_text (GET_LABEL ("p_cratio_label"), s);
	g_free (s);

	/**/

	s = g_strdup_printf ("%d", window->archive->command->n_regular_files);
	gtk_label_set_text (GET_LABEL ("p_files_label"), s);
	g_free (s);

	/**/

	gtk_label_set_text (GET_LABEL ("p_mime_type_label"), window->archive->command->mime_type);

	/* Set the signals handlers. */

	gtk_builder_add_callback_symbols (builder,
	                                  "on_prop_dialog_destroy",	G_CALLBACK (destroy_cb),
	                                  "on_p_help_button_clicked",	G_CALLBACK (help_cb),
	                                  NULL);

	gtk_builder_connect_signals (builder, data);

	g_signal_connect_swapped (gtk_builder_get_object (builder, "p_ok_button"),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  G_OBJECT (data->dialog));

	g_object_unref (builder);

	/* Run dialog. */

	gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
				      GTK_WINDOW (window));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);

	gtk_widget_show (data->dialog);
}