static void
open_file_response_cb (GtkWidget *w,
		       int        response,
		       GtkWidget *file_sel)
{
	FrWindow *window = NULL;
	GFile    *file;

	if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) {
		gtk_widget_destroy (file_sel);
		return;
	}

	window = g_object_get_data (G_OBJECT (file_sel), "fr_window");
	file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_sel));

	if ((window == NULL) || (file == NULL))
		return;

	if (fr_window_archive_is_present (window))
		window = (FrWindow *) fr_window_new ();
	g_signal_connect (G_OBJECT (window),
			  "archive_loaded",
			  G_CALLBACK (window_archive_loaded_cb),
			  file_sel);
	fr_window_archive_open (window, file, GTK_WINDOW (file_sel));

	g_object_unref (file);
}
Exemple #2
0
static void
fr_restore_session (EggSMClient *client)
{
	GKeyFile *state = NULL;
	guint i;

	state = egg_sm_client_get_state_file (client);

	i = g_key_file_get_integer (state, "Session", "archives", NULL);

	for (; i > 0; i--) {
		GtkWidget *window;
		char      *key;
		char      *uri;

		key = g_strdup_printf ("archive%d", i);
		uri = g_key_file_get_string (state, "Session", key, NULL);

		window = fr_window_new ();
		if (strlen (uri) > 0) {
			GFile *file;

			file = g_file_new_for_uri (uri);
			fr_window_archive_open (FR_WINDOW (window), file, GTK_WINDOW (window));

			g_object_unref (file);
		}

		g_free (uri);
		g_free (key);
	}
}
static void
new_archive (DlgNewData *data,
	     char       *uri)
{
	GtkWidget  *archive_window;
	gboolean    new_window;
	const char *password;
	gboolean    encrypt_header;
	int         volume_size;

	new_window = fr_window_archive_is_present (data->window) && ! fr_window_is_batch_mode (data->window);
	if (new_window)
		archive_window = fr_window_new ();
	else
		archive_window = (GtkWidget *) data->window;

	password = dlg_new_data_get_password (data);
	encrypt_header = dlg_new_data_get_encrypt_header (data);
	volume_size = dlg_new_data_get_volume_size (data);

	fr_window_set_password (FR_WINDOW (archive_window), password);
	fr_window_set_encrypt_header (FR_WINDOW (archive_window), encrypt_header);
	fr_window_set_volume_size (FR_WINDOW (archive_window), volume_size);

	if (fr_window_archive_new (FR_WINDOW (archive_window), uri)) {
		gtk_widget_destroy (data->dialog);
		if (! fr_window_is_batch_mode (FR_WINDOW (archive_window)))
			gtk_window_present (GTK_WINDOW (archive_window));
	}
	else if (new_window)
		gtk_widget_destroy (archive_window);
}
static void
handle_method_call (GDBusConnection       *connection,
		    const char            *sender,
		    const char            *object_path,
		    const char            *interface_name,
		    const char            *method_name,
		    GVariant              *parameters,
		    GDBusMethodInvocation *invocation,
		    gpointer               user_data)
{
	update_registered_commands_capabilities ();

	if (g_strcmp0 (method_name, "GetSupportedTypes") == 0) {
		char *action;
		int  *supported_types = NULL;

		g_variant_get (parameters, "(s)", &action);

		if (g_strcmp0 (action, "create") == 0) {
			supported_types = save_type;
		}
		else if (g_strcmp0 (action, "create_single_file") == 0) {
			supported_types = single_file_save_type;
		}
		else if (g_strcmp0 (action, "extract") == 0) {
			supported_types = open_type;
		}

		if (supported_types == NULL) {
			g_dbus_method_invocation_return_error (invocation,
							       G_IO_ERROR,
							       G_IO_ERROR_INVALID_ARGUMENT,
							       "Action not valid %s, valid values are: create, create_single_file, extract",
							       action);
		}
		else {
			GVariantBuilder builder;
			int             i;

			g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aa{ss})"));
			g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{ss}"));
			for (i = 0; supported_types[i] != -1; i++) {
				g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{ss}"));
				g_variant_builder_add (&builder, "{ss}",
						       "mime-type",
						       mime_type_desc[supported_types[i]].mime_type);
				g_variant_builder_add (&builder, "{ss}",
						       "default-extension",
						       mime_type_desc[supported_types[i]].default_ext);
				g_variant_builder_add (&builder, "{ss}",
						       "description",
						       _(mime_type_desc[supported_types[i]].name));
				g_variant_builder_close (&builder);
			}
			g_variant_builder_close (&builder);

			g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
		}

		g_free (action);
	}
	else if (g_strcmp0 (method_name, "AddToArchive") == 0) {
		char       *archive;
		char      **files;
		gboolean    use_progress_dialog;
		int         i;
		GList      *file_list = NULL;
		GtkWidget  *window;

		g_variant_get (parameters, "(s^asb)", &archive, &files, &use_progress_dialog);

		for (i = 0; files[i] != NULL; i++)
			file_list = g_list_prepend (file_list, files[i]);
		file_list = g_list_reverse (file_list);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__add (FR_WINDOW (window), archive, file_list);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (archive);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "Compress") == 0) {
		char      **files;
		char       *destination;
		gboolean    use_progress_dialog;
		int         i;
		GList      *file_list = NULL;
		GtkWidget  *window;

		g_variant_get (parameters, "(^assb)", &files, &destination, &use_progress_dialog);

		for (i = 0; files[i] != NULL; i++)
			file_list = g_list_prepend (file_list, files[i]);
		file_list = g_list_reverse (file_list);

		if ((destination == NULL) || (strcmp (destination, "") == 0))
			destination = remove_level_from_path (file_list->data);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
		fr_window_set_default_dir (FR_WINDOW (window), destination, TRUE);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__add (FR_WINDOW (window), NULL, file_list);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (destination);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "Extract") == 0) {
		char      *archive;
		char      *destination;
		gboolean   use_progress_dialog;
		GtkWidget *window;

		g_variant_get (parameters, "(ssb)", &archive, &destination, &use_progress_dialog);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
		if ((destination != NULL) & (strcmp (destination, "") != 0))
			fr_window_set_default_dir (FR_WINDOW (window), destination, TRUE);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__extract (FR_WINDOW (window), archive, destination);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (destination);
		g_free (archive);

		gtk_main ();
	}
	else if (g_strcmp0 (method_name, "ExtractHere") == 0) {
		char      *archive;
		gboolean   use_progress_dialog;
		GtkWidget *window;

		g_variant_get (parameters, "(sb)", &archive, &use_progress_dialog);

		window = fr_window_new ();
		fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);

		g_signal_connect (window, "progress", G_CALLBACK (window_progress_cb), connection);
		g_signal_connect (window, "ready", G_CALLBACK (window_ready_cb), invocation);

		fr_window_new_batch (FR_WINDOW (window));
		fr_window_set_batch__extract_here (FR_WINDOW (window), archive);
		fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		fr_window_start_batch (FR_WINDOW (window));

		g_free (archive);

		gtk_main ();
	}
}
Exemple #5
0
static int
fr_application_command_line (GApplication            *application,
                             GApplicationCommandLine *command_line)
{
	char           **argv;
	int              argc;
	GOptionContext  *context;
	GError          *error = NULL;
	GFile           *extraction_destination = NULL;
	GFile           *add_to_archive = NULL;
	GFile           *default_directory = NULL;

	argv = g_application_command_line_get_arguments (command_line, &argc);

	/* parse command line options */

	context = fr_application_create_option_context ();
	if (! g_option_context_parse (context, &argc, &argv, &error)) {
		g_critical ("Failed to parse arguments: %s", error->message);
		g_error_free (error);
		g_option_context_free (context);

		return fr_application_command_line_finished (application, EXIT_FAILURE);
	}
	g_option_context_free (context);

	/* restore the session */

#ifdef USE_SMCLIENT
	{
		EggSMClient *client;

		client = egg_sm_client_get ();
		g_signal_connect (client,
				  "save_state",
				  G_CALLBACK (client_save_state),
				  NULL);
		g_signal_connect (client,
				  "quit",
				  G_CALLBACK (client_quit_cb),
				  NULL);
		if (egg_sm_client_is_resumed (client)) {
			fr_restore_session (client);
			return fr_application_command_line_finished (application, EXIT_SUCCESS);
		}
	}
#endif

	if (remaining_args == NULL) { /* No archive specified. */
		if (! arg_service)
			gtk_widget_show (fr_window_new ());
		return fr_application_command_line_finished (application, EXIT_SUCCESS);
	}

	if (arg_extract_to != NULL)
		extraction_destination = g_file_new_for_commandline_arg (arg_extract_to);

	if (arg_add_to != NULL)
		add_to_archive = g_file_new_for_commandline_arg (arg_add_to);

	if (arg_default_dir != NULL)
		default_directory = g_file_new_for_commandline_arg (arg_default_dir);

	if ((arg_add_to != NULL) || (arg_add == 1)) { /* Add files to an archive */
		GtkWidget   *window;
		GList       *file_list;
		const char  *filename;
		int          i = 0;

		window = fr_window_new ();

		if (default_directory != NULL)
			fr_window_set_default_dir (FR_WINDOW (window), default_directory, TRUE);

		file_list = NULL;
		while ((filename = remaining_args[i++]) != NULL)
			file_list = g_list_prepend (file_list, g_file_new_for_commandline_arg (filename));
		file_list = g_list_reverse (file_list);

		fr_window_new_batch (FR_WINDOW (window), _("Compress"));
		fr_window_set_batch__add (FR_WINDOW (window), add_to_archive, file_list);

		if (! arg_notify)
			fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		else
			fr_window_set_notify (FR_WINDOW (window), TRUE);
		fr_window_start_batch (FR_WINDOW (window));

		_g_object_list_unref (file_list);
	}
	else if ((arg_extract_to != NULL) || (arg_extract == 1) || (arg_extract_here == 1)) {

		/* Extract all archives. */

		GtkWidget  *window;
		const char *archive;
		int         i = 0;

		window = fr_window_new ();

		if (default_directory != NULL)
			fr_window_set_default_dir (FR_WINDOW (window), default_directory, TRUE);

		fr_window_new_batch (FR_WINDOW (window), _("Extract archive"));
		while ((archive = remaining_args[i++]) != NULL) {
			GFile *file;

			file = g_file_new_for_commandline_arg (archive);
			if (arg_extract_here == 1)
				fr_window_set_batch__extract_here (FR_WINDOW (window), file);
			else
				fr_window_set_batch__extract (FR_WINDOW (window), file, extraction_destination);

			g_object_unref (file);
		}
		if (! arg_notify)
			fr_window_append_batch_action (FR_WINDOW (window), FR_BATCH_ACTION_QUIT, NULL, NULL);
		else
			fr_window_set_notify (FR_WINDOW (window), TRUE);

		fr_window_start_batch (FR_WINDOW (window));
	}
	else { /* Open each archive in a window */
		const char *filename = NULL;

		int i = 0;
		while ((filename = remaining_args[i++]) != NULL) {
			GtkWidget *window;
			GFile     *file;

			window = fr_window_new ();
			gtk_widget_show (window);

			file = g_file_new_for_commandline_arg (filename);
			fr_window_archive_open (FR_WINDOW (window), file, GTK_WINDOW (window));

			g_object_unref (file);
		}
	}

	_g_object_unref (default_directory);
	_g_object_unref (add_to_archive);
	_g_object_unref (extraction_destination);

	return fr_application_command_line_finished (application, EXIT_SUCCESS);
}