[Gpa-commits] r854 - trunk/src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Mar 19 03:18:23 CET 2008
Author: marcus
Date: 2008-03-19 03:18:22 +0100 (Wed, 19 Mar 2008)
New Revision: 854
Modified:
trunk/src/ChangeLog
trunk/src/clipboard.c
trunk/src/fileman.c
trunk/src/gpabackupop.c
trunk/src/gpaexportfileop.c
trunk/src/gtktools.c
trunk/src/gtktools.h
Log:
2008-03-19 Marcus Brinkmann <marcus at g10code.de>
* fileman.c (dnd_data_received_handler): Silence gcc warning.
* gpaexportfileop.c (gpa_export_file_operation_get_destination):
Use save button instead load button.
* gpabackupop.c (export_browse): Removed.
(gpa_backup_operation_dialog_run): Rewritten.
* fileman.c (get_load_file_name): New function.
(open_file): Use it.
(gpa_file_manager_constructor): Don't pack ALIGN twice.
* clipboard.c (get_load_file_name): New function.
(file_open): Use it.
(get_save_file_name): New function.
(file_save_as): Use it.
* gtktools.h (gpa_get_save_file_name, gpa_get_load_file_name):
Removed prototypes.
* gtktools.c (gpa_get_save_file_name, gpa_get_load_file_name):
Removed.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/ChangeLog 2008-03-19 02:18:22 UTC (rev 854)
@@ -1,5 +1,22 @@
2008-03-19 Marcus Brinkmann <marcus at g10code.de>
+ * fileman.c (dnd_data_received_handler): Silence gcc warning.
+ * gpaexportfileop.c (gpa_export_file_operation_get_destination):
+ Use save button instead load button.
+ * gpabackupop.c (export_browse): Removed.
+ (gpa_backup_operation_dialog_run): Rewritten.
+ * fileman.c (get_load_file_name): New function.
+ (open_file): Use it.
+ (gpa_file_manager_constructor): Don't pack ALIGN twice.
+ * clipboard.c (get_load_file_name): New function.
+ (file_open): Use it.
+ (get_save_file_name): New function.
+ (file_save_as): Use it.
+ * gtktools.h (gpa_get_save_file_name, gpa_get_load_file_name):
+ Removed prototypes.
+ * gtktools.c (gpa_get_save_file_name, gpa_get_load_file_name):
+ Removed.
+
* clipboard.c (gpa_clipboard_constructor): Create text_frame
early.
(gpa_clipboard_constructor): Don't pack ALIGN twice.
Modified: trunk/src/clipboard.c
===================================================================
--- trunk/src/clipboard.c 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/clipboard.c 2008-03-19 02:18:22 UTC (rev 854)
@@ -318,6 +318,51 @@
}
+/* The directory last visited by load or save operations. */
+static gchar *last_directory;
+
+
+static gchar *
+get_load_file_name (GtkWidget *parent, const gchar *title)
+{
+ static GtkWidget *dialog;
+ GtkResponseType response;
+ gchar *filename = NULL;
+
+ if (! dialog)
+ {
+ dialog = gtk_file_chooser_dialog_new
+ (title, GTK_WINDOW (parent), GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+ }
+ if (last_directory)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+ last_directory);
+ gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
+
+ /* Run the dialog until there is a valid response. */
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == GTK_RESPONSE_OK)
+ {
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename)
+ filename = g_strdup (filename);
+ }
+
+ if (last_directory)
+ g_free (last_directory);
+ last_directory
+ = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+ if (last_directory)
+ last_directory = g_strdup (last_directory);
+
+ gtk_widget_hide (dialog);
+
+ return filename;
+}
+
+
/* Handle menu item "File/Open". */
static void
file_open (gpointer param)
@@ -332,8 +377,7 @@
GError *err = NULL;
const gchar *end;
- filename = gpa_get_load_file_name (GTK_WIDGET (clipboard),
- _("Open File"), NULL);
+ filename = get_load_file_name (GTK_WIDGET (clipboard), _("Open File"));
if (! filename)
return;
@@ -433,6 +477,58 @@
}
+/* Run the modal file selection dialog and return a new copy of the
+ filename if the user pressed OK and NULL otherwise. */
+static gchar *
+get_save_file_name (GtkWidget *parent, const gchar *title)
+{
+ static GtkWidget *dialog;
+ GtkResponseType response;
+ gchar *filename = NULL;
+
+ if (! dialog)
+ {
+ dialog = gtk_file_chooser_dialog_new
+ (title, GTK_WINDOW (parent), GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+ gtk_file_chooser_set_do_overwrite_confirmation
+ (GTK_FILE_CHOOSER (dialog), TRUE);
+ }
+ if (last_directory)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+ last_directory);
+ gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
+
+ /* Run the dialog until there is a valid response. */
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == GTK_RESPONSE_OK)
+ {
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename)
+ filename = g_strdup (filename);
+ }
+
+ if (last_directory)
+ g_free (last_directory);
+ last_directory
+ = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+ if (last_directory)
+ last_directory = g_strdup (last_directory);
+
+ if (last_directory)
+ g_free (last_directory);
+ last_directory
+ = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+ if (last_directory)
+ last_directory = g_strdup (last_directory);
+
+ gtk_widget_hide (dialog);
+
+ return filename;
+}
+
+
/* Handle menu item "File/Save As...". */
static void
file_save_as (gpointer param)
@@ -446,8 +542,7 @@
GtkTextIter begin;
GtkTextIter end;
- filename = gpa_get_save_file_name (GTK_WIDGET (clipboard),
- _("Save As..."), NULL);
+ filename = get_save_file_name (GTK_WIDGET (clipboard), _("Save As..."));
if (! filename)
return;
@@ -992,7 +1087,6 @@
clipboard->text_buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (clipboard->text_view));
- g_print ("text buffer: %p\n", clipboard->text_buffer);
#ifndef MY_GTK_TEXT_BUFFER_NO_HAS_SELECTION
/* A change in selection status causes a property change, which we
Modified: trunk/src/fileman.c
===================================================================
--- trunk/src/fileman.c 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/fileman.c 2008-03-19 02:18:22 UTC (rev 854)
@@ -1,31 +1,28 @@
/* fileman.c - The GNU Privacy Assistant
- * Copyright (C) 2000, 2001 G-N-U GmbH.
- * Copyright (C) 2007, 2008 g10 Code GmbH
- *
- * This file is part of GPA
- *
- * GPA 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.
- *
- * GPA 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.
- */
+ Copyright (C) 2000, 2001 G-N-U GmbH.
+ Copyright (C) 2007, 2008 g10 Code GmbH
-/*
- * The file encryption/decryption/sign window
- */
+ This file is part of GPA.
-#include <config.h>
+ GPA 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 3 of the License, or
+ (at your option) any later version.
+ GPA 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, see <http://www.gnu.org/licenses/>. */
+
+/* The file encryption/decryption/sign window. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -333,12 +330,43 @@
-/*
- Actions as called by the menu items.
+/* Actions as called by the menu items. */
-*/
+static gchar *
+get_load_file_name (GtkWidget *parent, const gchar *title,
+ const gchar *directory)
+{
+ static GtkWidget *dialog;
+ GtkResponseType response;
+ gchar *filename = NULL;
+ if (! dialog)
+ {
+ dialog = gtk_file_chooser_dialog_new
+ (title, GTK_WINDOW (parent), GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+ }
+ if (directory)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), directory);
+ gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
+
+ /* Run the dialog until there is a valid response. */
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == GTK_RESPONSE_OK)
+ {
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename)
+ filename = g_strdup (filename);
+ }
+
+ gtk_widget_hide (dialog);
+
+ return filename;
+}
+
+
/* Handle menu item "File/Open". */
static void
open_file (gpointer param)
@@ -346,18 +374,17 @@
GpaFileManager * fileman = param;
gchar * filename;
- filename = gpa_get_load_file_name (GTK_WIDGET (fileman),
- _("Open File"), NULL);
- if (filename)
- {
+ filename = get_load_file_name (GTK_WIDGET (fileman), _("Open File"), NULL);
+ if (! filename)
+ return;
- if (!add_file (fileman, filename))
- gpa_window_error (_("The file is already open."),
- GTK_WIDGET (fileman));
- g_free (filename);
- }
+ if (! add_file (fileman, filename))
+ gpa_window_error (_("The file is already open."),
+ GTK_WIDGET (fileman));
+ g_free (filename);
}
+
/* Handle menu item "File/Clear". */
static void
close_all_files (gpointer param)
@@ -739,7 +766,7 @@
/* Check that we got a format we can use. */
if (target_type == DND_TARGET_URI_LIST)
{
- char *p = selection_data->data;
+ char *p = (char *) selection_data->data;
char **list;
int i;
@@ -892,7 +919,6 @@
file_frame = file_list_new (fileman);
gtk_box_pack_start (GTK_BOX (file_box), file_frame, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (align), file_box);
- gtk_box_pack_end (GTK_BOX (vbox), align, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (fileman), vbox);
Modified: trunk/src/gpabackupop.c
===================================================================
--- trunk/src/gpabackupop.c 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/gpabackupop.c 2008-03-19 02:18:22 UTC (rev 854)
@@ -1,6 +1,6 @@
/* gpabackupop.c - The GpaBackupOperation object.
Copyright (C) 2003 Miguel Coca.
- Copyright (C) 2005 g10 Code GmbH.
+ Copyright (C) 2005, 2008 g10 Code GmbH.
This file is part of GPA.
@@ -248,102 +248,53 @@
}
}
-/* Handler for the browse button. Run a modal file dialog and set the
- * text of the file entry widget accordingly.
- */
-static void
-export_browse (gpointer param)
-{
- GtkWidget *entry = param;
- gchar *filename;
- filename = gpa_get_save_file_name (entry, _("Backup key to file"), NULL);
- if (filename)
- {
- gchar *utf8_filename = g_filename_to_utf8 (filename, -1, NULL, NULL,
- NULL);
- gtk_entry_set_text (GTK_ENTRY (entry),
- utf8_filename);
- g_free (utf8_filename);
- g_free (filename);
- }
-} /* export_browse */
-
+/* Return the filename in filename encoding. */
static gchar*
gpa_backup_operation_dialog_run (GtkWidget *parent, const gchar *key_id)
{
- GtkAccelGroup *accel_group;
-
- GtkWidget *window;
- GtkWidget *vbox;
- GtkWidget *table;
+ GtkWidget *dialog;
+ GtkResponseType response;
+ gchar *default_comp;
+ gchar *default_file;
+ gchar *id_text;
GtkWidget *id_label;
- GtkWidget *label;
- GtkWidget *entry;
- GtkWidget *button;
+ gchar *filename = NULL;
- gchar *id_text, *default_file;
+ dialog = gtk_file_chooser_dialog_new
+ (_("Backup key to file"), GTK_WINDOW (parent),
+ GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
+ TRUE);
- window = gtk_dialog_new_with_buttons (_("Backup Keys"),
- GTK_WINDOW (parent),
- GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- _("_Cancel"),
- GTK_RESPONSE_CANCEL,
- NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_OK);
- gtk_container_set_border_width (GTK_CONTAINER (window), 5);
- accel_group = gtk_accel_group_new ();
- gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
+ /* Set the default file name. */
+ default_comp = g_strdup_printf ("secret-key-%s.asc", key_id);
+ default_file = g_build_filename (g_get_home_dir (), default_comp, NULL);
+ g_free (default_comp);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+ g_get_home_dir ());
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_file);
+ g_free (default_file);
- vbox = GTK_DIALOG (window)->vbox;
- gtk_container_add (GTK_CONTAINER (window), vbox);
-
- table = gtk_table_new (3, 2, FALSE);
- gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
- gtk_table_set_row_spacing (GTK_TABLE (table), 0, 5);
- gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2);
- gtk_table_set_row_spacing (GTK_TABLE (table), 2, 2);
- gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
-
- /* Show the ID */
+ /* Set the label with more explanations. */
id_text = g_strdup_printf (_("Generating backup of key: %s"), key_id);
id_label = gtk_label_new (id_text);
- gtk_table_attach (GTK_TABLE (table), id_label, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
g_free (id_text);
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), id_label);
- /* File name entry */
- label = gtk_label_new_with_mnemonic (_("_Backup to file:"));
- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
-
- entry = gtk_entry_new ();
- gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
- GTK_FILL|GTK_EXPAND, 0, 0, 0);
- gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
- default_file = g_build_filename (g_get_home_dir (), "sec_key.asc", NULL);
- gtk_entry_set_text (GTK_ENTRY (entry), default_file);
- g_free (default_file);
- gtk_widget_grab_focus (entry);
-
- button = gpa_button_new (accel_group, _("B_rowse..."));
- gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2, GTK_FILL, 0, 0, 0);
- gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
- GTK_SIGNAL_FUNC (export_browse),
- (gpointer) entry);
-
- gtk_widget_show_all (window);
- if (gtk_dialog_run (GTK_DIALOG (window)) == GTK_RESPONSE_OK)
+ /* Run the dialog until there is a valid response. */
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (response == GTK_RESPONSE_OK)
{
- gchar *filename = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
- gtk_widget_destroy (window);
- return filename;
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename)
+ g_strdup (filename);
}
- else
- {
- gtk_widget_destroy (window);
- return NULL;
- }
+
+ gtk_widget_destroy (dialog);
+
+ return filename;
}
static gboolean
Modified: trunk/src/gpaexportfileop.c
===================================================================
--- trunk/src/gpaexportfileop.c 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/gpaexportfileop.c 2008-03-19 02:18:22 UTC (rev 854)
@@ -138,7 +138,7 @@
dialog = gtk_file_chooser_dialog_new
(_("Export public keys to file"), GTK_WINDOW (GPA_OPERATION (op)->window),
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
TRUE);
@@ -174,6 +174,7 @@
return (response == GTK_RESPONSE_OK);
}
+
static void
gpa_export_file_operation_complete_export (GpaExportOperation *operation)
{
Modified: trunk/src/gtktools.c
===================================================================
--- trunk/src/gtktools.c 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/gtktools.c 2008-03-19 02:18:22 UTC (rev 854)
@@ -376,62 +376,6 @@
} /* gpa_window_message */
-/* Run the modal file selection dialog and return a new copy of the
- filename if the user pressed OK and NULL otherwise. */
-gchar *
-gpa_get_save_file_name (GtkWidget *parent, const gchar *title,
- const gchar *directory)
-{
- GtkWidget *dialog;
- GtkResponseType response;
- gchar *filename = NULL;
-
- dialog = gtk_file_chooser_dialog_new
- (title, parent, GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
-
- /* Run the dialog until there is a valid response. */
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response == GTK_RESPONSE_OK)
- {
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (filename)
- filename = g_strdup (filename);
- }
-
- gtk_widget_destroy (dialog);
- return filename;
-}
-
-
-gchar *
-gpa_get_load_file_name (GtkWidget *parent, const gchar *title,
- const gchar *directory)
-{
- GtkWidget *dialog;
- GtkResponseType response;
- gchar *filename = NULL;
-
- dialog = gtk_file_chooser_dialog_new
- (title, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
-
- /* Run the dialog until there is a valid response. */
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response == GTK_RESPONSE_OK)
- {
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (filename)
- filename = g_strdup (filename);
- }
-
- gtk_widget_destroy (dialog);
- return filename;
-}
-
-
/* END of old unchecked code (wk 2008-03-07) */
Modified: trunk/src/gtktools.h
===================================================================
--- trunk/src/gtktools.h 2008-03-18 23:12:21 UTC (rev 853)
+++ trunk/src/gtktools.h 2008-03-19 02:18:22 UTC (rev 854)
@@ -55,13 +55,8 @@
extern void gpa_window_show_centered (GtkWidget * widget, GtkWidget * parent);
extern void gpa_window_error (const gchar * message, GtkWidget * messenger);
extern void gpa_window_message (gchar * message, GtkWidget * messenger);
-gchar * gpa_get_save_file_name (GtkWidget * parent, const gchar * title,
- const gchar * directory);
-gchar * gpa_get_load_file_name (GtkWidget * parent, const gchar * title,
- const gchar * directory);
-
/* Set a tooltip TEXT to WIDGET. TEXT and WIDGET may both be NULL.
This function is useful so that GPA can be build with older GTK+
versions. */
More information about the Gpa-commits
mailing list