Read-only mode: Add "Read-only" checkbox when opening a file/database.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21807 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming
2011-12-31 10:41:44 +00:00
parent 9ab50b259a
commit 29aa98e460
6 changed files with 35 additions and 10 deletions

View File

@@ -719,7 +719,7 @@ inner_main (void *closure, int argc, char **argv)
if (!nofile && (fn = get_file_to_load()))
{
gnc_update_splash_screen(_("Loading data..."), GNC_SPLASH_PERCENTAGE_UNKNOWN);
gnc_file_open_file(fn);
gnc_file_open_file(fn, /*open_readonly*/ FALSE);
g_free(fn);
}
else if (gnc_gconf_get_bool("dialogs/new_user", "first_startup", &error)

View File

@@ -52,6 +52,7 @@ typedef struct FileAccessWindow
GtkWidget* dialog;
GtkWidget* frame_file;
GtkWidget* frame_database;
GtkWidget* readonly_checkbutton;
GtkFileChooser* fileChooser;
gchar *starting_dir;
GtkComboBox* cb_uri_type;
@@ -140,7 +141,10 @@ gnc_ui_file_access_response_cb(GtkDialog *dialog, gint response, GtkDialog *unus
}
if ( faw->type == FILE_ACCESS_OPEN )
{
gnc_file_open_file( url );
gboolean open_readonly = faw->readonly_checkbutton
? gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(faw->readonly_checkbutton))
: FALSE;
gnc_file_open_file( url, open_readonly );
}
else if ( faw->type == FILE_ACCESS_SAVE_AS )
{
@@ -278,6 +282,7 @@ gnc_ui_file_access( int type )
faw->frame_file = GTK_WIDGET(gtk_builder_get_object (builder, "frame_file" ));
faw->frame_database = GTK_WIDGET(gtk_builder_get_object (builder, "frame_database" ));
faw->readonly_checkbutton = GTK_WIDGET(gtk_builder_get_object (builder, "readonly_checkbutton"));
faw->tf_host = GTK_ENTRY(gtk_builder_get_object (builder, "tf_host" ));
gtk_entry_set_text( faw->tf_host, DEFAULT_HOST );
faw->tf_database = GTK_ENTRY(gtk_builder_get_object (builder, "tf_database" ));
@@ -300,6 +305,8 @@ gnc_ui_file_access( int type )
button_label = "gtk-save-as";
fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
gconf_section = GCONF_DIR_OPEN_SAVE;
gtk_widget_destroy(faw->readonly_checkbutton);
faw->readonly_checkbutton = NULL;
break;
case FILE_ACCESS_EXPORT:
@@ -307,6 +314,8 @@ gnc_ui_file_access( int type )
button_label = "gtk-save-as";
fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
gconf_section = GCONF_DIR_EXPORT;
gtk_widget_destroy(faw->readonly_checkbutton);
faw->readonly_checkbutton = NULL;
break;
}

View File

@@ -686,7 +686,7 @@ static gboolean test_unknown_features(QofSession* new_session)
#define RESPONSE_READONLY 4
static gboolean
gnc_post_file_open (const char * filename)
gnc_post_file_open (const char * filename, gboolean is_readonly)
{
QofSession *current_session, *new_session;
QofBook *new_book;
@@ -701,7 +701,6 @@ gnc_post_file_open (const char * filename)
gchar *password = NULL;
gchar *path = NULL;
gint32 port = 0;
gboolean is_readonly = FALSE;
ENTER(" ");
@@ -1069,7 +1068,7 @@ gnc_file_open (void)
g_free ( last );
g_free ( default_dir );
result = gnc_post_file_open ( newfile );
result = gnc_post_file_open ( newfile, /*is_readonly*/ FALSE );
/* This dialogue can show up early in the startup process. If the
* user fails to pick a file (by e.g. hitting the cancel button), we
@@ -1081,14 +1080,14 @@ gnc_file_open (void)
}
gboolean
gnc_file_open_file (const char * newfile)
gnc_file_open_file (const char * newfile, gboolean open_readonly)
{
if (!newfile) return FALSE;
if (!gnc_file_query_save (TRUE))
return FALSE;
return gnc_post_file_open (newfile);
return gnc_post_file_open (newfile, open_readonly);
}
/* Note: this dialog will only be used when dbi is not enabled

View File

@@ -143,7 +143,7 @@ char * gnc_file_dialog (const char * title,
const char * starting_dir,
GNCFileDialogType type);
gboolean gnc_file_open_file (const char *filename);
gboolean gnc_file_open_file (const char *filename, gboolean open_readonly);
gboolean gnc_file_query_save (gboolean can_cancel);

View File

@@ -725,7 +725,7 @@ gnc_plugin_file_history_cmd_open_file (GtkAction *action,
filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
/* also opens new account page */
gnc_file_open_file (filename);
gnc_file_open_file (filename, /*open_readonly*/ FALSE);
gnc_window_set_progressbar_window (NULL);
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
@@ -93,6 +93,23 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="readonly_checkbutton">
<property name="label" translatable="yes">Open _Read-Only</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>