r17989 - gnucash/trunk/src/gnome-utils - Replace radio buttons with a combo box. A bit ugly because I haven't figured out how to keep

Phil Longstaff plongstaff at cvs.gnucash.org
Tue Mar 10 13:41:53 EDT 2009


Author: plongstaff
Date: 2009-03-10 13:41:52 -0400 (Tue, 10 Mar 2009)
New Revision: 17989
Trac: http://svn.gnucash.org/trac/changeset/17989

Modified:
   gnucash/trunk/src/gnome-utils/dialog-file-access.c
   gnucash/trunk/src/gnome-utils/glade/dialog-file-access.glade
Log:
Replace radio buttons with a combo box.  A bit ugly because I haven't figured out how to keep
the combo box from expanding to fill the space.



Modified: gnucash/trunk/src/gnome-utils/dialog-file-access.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-file-access.c	2009-03-09 20:14:46 UTC (rev 17988)
+++ gnucash/trunk/src/gnome-utils/dialog-file-access.c	2009-03-10 17:41:52 UTC (rev 17989)
@@ -42,10 +42,7 @@
 #define FILE_ACCESS_SAVE_AS 1
 
 void gnc_ui_file_access_response_cb( GtkDialog *, gint, GtkDialog * );
-void gnc_ui_file_access_rb_xml_clicked_cb( GtkToggleButton* tb );
-void gnc_ui_file_access_rb_sqlite3_clicked_cb( GtkToggleButton* tb );
-void gnc_ui_file_access_rb_mysql_clicked_cb( GtkToggleButton* tb );
-void gnc_ui_file_access_rb_pgsql_clicked_cb( GtkToggleButton* tb );
+static void cb_uri_type_changed_cb( GtkComboBox* cb );
 
 typedef struct FileAccessWindow
 {
@@ -56,14 +53,11 @@
   GtkWidget* frame_file;
   GtkWidget* frame_database;
   GtkFileChooser* fileChooser;
-  GtkWidget* rb_xml;
-  GtkWidget* rb_sqlite3;
-  GtkWidget* rb_mysql;
-  GtkWidget* rb_pgsql;
-  GtkWidget* tf_host;
-  GtkWidget* tf_database;
-  GtkWidget* tf_username;
-  GtkWidget* tf_password;
+  GtkComboBox* cb_uri_type;
+  GtkEntry* tf_host;
+  GtkEntry* tf_database;
+  GtkEntry* tf_username;
+  GtkEntry* tf_password;
 } FileAccessWindow;
 
 static gchar*
@@ -77,24 +71,25 @@
 	const gchar* type;
 	const gchar* file;
 
-	host = gtk_entry_get_text( GTK_ENTRY(faw->tf_host) );
-	database = gtk_entry_get_text( GTK_ENTRY(faw->tf_database) );
-	username = gtk_entry_get_text( GTK_ENTRY(faw->tf_username) );
-	password = gtk_entry_get_text( GTK_ENTRY(faw->tf_password) );
+	host = gtk_entry_get_text( faw->tf_host );
+	database = gtk_entry_get_text( faw->tf_database );
+	username = gtk_entry_get_text( faw->tf_username );
+	password = gtk_entry_get_text( faw->tf_password );
 	file = gtk_file_chooser_get_filename( faw->fileChooser );
 
-	if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_xml) ) ) {
+	type = gtk_combo_box_get_active_text( faw->cb_uri_type );
+	if( strcmp( type, "xml" ) == 0 ) {
 		type = "xml";
 		url = g_strdup_printf( "%s://%s", type, file );
-	} else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_sqlite3) ) ) {
+	} else if( strcmp( type, "sqlite3" ) == 0 ) {
 		type = "sqlite3";
 		url = g_strdup_printf( "%s://%s", type, file );
-	} else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_mysql) ) ) {
+	} else if( strcmp( type, "mysql" ) == 0 ) {
 		type = "mysql";
 		url = g_strdup_printf( "%s://%s:%s:%s:%s",
 							type, host, database, username, password );
 	} else {
-		g_assert( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_pgsql) ) );
+		g_assert( strcmp( type, "postgres" ) == 0 );
 		type = "postgres";
 		url = g_strdup_printf( "%s://%s:%s:%s:%s",
 							type, host, database, username, password );
@@ -143,86 +138,40 @@
 
 /* Activate the file chooser and deactivate the db selection fields */
 static void
-on_rb_filetype_clicked( FileAccessWindow* faw )
+set_widget_sensitivity( FileAccessWindow* faw, gboolean is_file_based_uri )
 {
-    gtk_widget_set_sensitive( faw->frame_file, TRUE );
-	gtk_widget_set_sensitive( faw->frame_database, FALSE );
+    gtk_widget_set_sensitive( faw->frame_file, is_file_based_uri );
+	gtk_widget_set_sensitive( faw->frame_database, !is_file_based_uri );
 }
 
-void
-gnc_ui_file_access_rb_xml_clicked_cb( GtkToggleButton* tb )
+static void
+set_widget_sensitivity_for_uri_type( FileAccessWindow* faw, const gchar* uri_type )
 {
-	GtkWidget* dialog;
-    FileAccessWindow* faw;
-
-	g_return_if_fail( tb != NULL );
-
-	if( gtk_toggle_button_get_active( tb ) ) {
-		dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
-		g_return_if_fail( dialog != NULL );
-    	faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
-    	g_return_if_fail( faw != NULL );
-
-    	on_rb_filetype_clicked( faw );
+	if( strcmp( uri_type, "xml" ) == 0 || strcmp( uri_type, "sqlite3" ) == 0 ) {
+		set_widget_sensitivity( faw, /* is_file_based_uri */ TRUE );
+	} else if( strcmp( uri_type, "mysql" ) == 0 || strcmp( uri_type, "postgres" ) == 0 ) {
+		set_widget_sensitivity( faw, /* is_file_based_uri */ FALSE );
+	} else {
+		g_assert( FALSE );
 	}
 }
 
-void
-gnc_ui_file_access_rb_sqlite3_clicked_cb( GtkToggleButton* tb )
-{
-	GtkWidget* dialog;
-    FileAccessWindow* faw;
-
-	if( gtk_toggle_button_get_active( tb ) ) {
-		dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
-		g_return_if_fail( dialog != NULL );
-    	faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
-    	g_return_if_fail( faw != NULL );
-
-    	on_rb_filetype_clicked( faw );
-	}
-}
-
-/* Deactivate the file chooser and activate the db selection fields */
 static void
-on_rb_databasetype_clicked( FileAccessWindow* faw )
+cb_uri_type_changed_cb( GtkComboBox* cb )
 {
-    gtk_widget_set_sensitive( faw->frame_file, FALSE );
-	gtk_widget_set_sensitive( faw->frame_database, TRUE );
-}
-
-void
-gnc_ui_file_access_rb_mysql_clicked_cb( GtkToggleButton* tb )
-{
 	GtkWidget* dialog;
     FileAccessWindow* faw;
+	const gchar* type;
 
-	if( gtk_toggle_button_get_active( tb ) ) {
-		g_return_if_fail( tb != NULL );
-		dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
-		g_return_if_fail( dialog != NULL );
-    	faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
-    	g_return_if_fail( faw != NULL );
+	g_return_if_fail( cb != NULL );
 
-    	on_rb_databasetype_clicked( faw );
-	}
-}
+	dialog = gtk_widget_get_toplevel( GTK_WIDGET(cb) );
+	g_return_if_fail( dialog != NULL );
+    faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
+    g_return_if_fail( faw != NULL );
 
-void
-gnc_ui_file_access_rb_pgsql_clicked_cb( GtkToggleButton* tb )
-{
-	GtkWidget* dialog;
-    FileAccessWindow* faw;
-
-	if( gtk_toggle_button_get_active( tb ) ) {
-		g_return_if_fail( tb != NULL );
-		dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
-		g_return_if_fail( dialog != NULL );
-    	faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
-    	g_return_if_fail( faw != NULL );
-
-    	on_rb_databasetype_clicked( faw );
-	}
+	type = gtk_combo_box_get_active_text( cb );
+	set_widget_sensitivity_for_uri_type( faw, type );
 }
 
 static void
@@ -238,6 +187,7 @@
 	GtkFileChooserAction fileChooserAction;
 	GList* list;
 	GList* node;
+	GtkWidget* uri_type_container;
 
 	g_return_if_fail( type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS );
 
@@ -252,16 +202,12 @@
 
 	faw->frame_file = glade_xml_get_widget( xml, "frame_file" );
 	faw->frame_database = glade_xml_get_widget( xml, "frame_database" );
-    faw->rb_xml = glade_xml_get_widget( xml, "rb_xml" );
-    faw->rb_sqlite3 = glade_xml_get_widget( xml, "rb_sqlite3" );
-    faw->rb_mysql = glade_xml_get_widget( xml, "rb_mysql" );
-    faw->rb_pgsql = glade_xml_get_widget( xml, "rb_pgsql" );
-    faw->tf_host = glade_xml_get_widget( xml, "tf_host" );
-	gtk_entry_set_text( GTK_ENTRY(faw->tf_host), DEFAULT_HOST );
-    faw->tf_database = glade_xml_get_widget( xml, "tf_database" );
-	gtk_entry_set_text( GTK_ENTRY(faw->tf_database), DEFAULT_DATABASE );
-    faw->tf_username = glade_xml_get_widget( xml, "tf_username" );
-    faw->tf_password = glade_xml_get_widget( xml, "tf_password" );
+    faw->tf_host = GTK_ENTRY(glade_xml_get_widget( xml, "tf_host" ));
+	gtk_entry_set_text( faw->tf_host, DEFAULT_HOST );
+    faw->tf_database = GTK_ENTRY(glade_xml_get_widget( xml, "tf_database" ));
+	gtk_entry_set_text( faw->tf_database, DEFAULT_DATABASE );
+    faw->tf_username = GTK_ENTRY(glade_xml_get_widget( xml, "tf_username" ));
+    faw->tf_password = GTK_ENTRY(glade_xml_get_widget( xml, "tf_password" ));
 	op = GTK_BUTTON(glade_xml_get_widget( xml, "pb_op" ));
 	if( op != NULL ) {
 		switch( type ) {
@@ -282,27 +228,29 @@
 	faw->fileChooser = GTK_FILE_CHOOSER(fileChooser);
 	gtk_container_add( GTK_CONTAINER(align), GTK_WIDGET(fileChooser) );
 
+	uri_type_container = glade_xml_get_widget( xml, "vb_uri_type_container" );
+	faw->cb_uri_type = GTK_COMBO_BOX(gtk_combo_box_new_text());
+	gtk_container_add( GTK_CONTAINER(uri_type_container), GTK_WIDGET(faw->cb_uri_type) );
+	g_object_connect( G_OBJECT(faw->cb_uri_type), "signal::changed", cb_uri_type_changed_cb, NULL );
+
     /* Autoconnect signals */
     glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func,
 				    					faw->dialog );
 
-	/* See what qof backends are available, and disable sqlite3, mysql and postgres if not
-	available */
-	gtk_widget_set_sensitive( faw->rb_sqlite3, FALSE );
-	gtk_widget_set_sensitive( faw->rb_mysql, FALSE );
-	gtk_widget_set_sensitive( faw->rb_pgsql, FALSE );
+	/* See what qof backends are available and add appropriate ones to the combo box */
 	list = qof_backend_get_registered_access_method_list();
 	for( node = list; node != NULL; node = node->next ) {
 		const gchar* access_method = node->data;
-		if( strcmp( access_method, "sqlite3" ) == 0 ) {
-			gtk_widget_set_sensitive( faw->rb_sqlite3, TRUE );
-		} else if( strcmp( access_method, "mysql" ) == 0 ) {
-			gtk_widget_set_sensitive( faw->rb_mysql, TRUE );
-		} else if( strcmp( access_method, "postgres" ) == 0 ) {
-			gtk_widget_set_sensitive( faw->rb_pgsql, TRUE );
+		if( strcmp( access_method, "xml" ) == 0 ||
+			strcmp( access_method, "sqlite3" ) == 0 ||
+			strcmp( access_method, "mysql" ) == 0 ||
+			strcmp( access_method, "postgres" ) == 0 ) {
+			gtk_combo_box_append_text( faw->cb_uri_type, access_method );
 		}
 	}
 	g_list_free(list);
+	gtk_combo_box_set_active( faw->cb_uri_type, 0 );
+	set_widget_sensitivity_for_uri_type( faw, gtk_combo_box_get_active_text( faw->cb_uri_type ) );
 
     /* Clean up the xml data structure when the dialog is destroyed */
     g_object_set_data_full( G_OBJECT(faw->dialog), "dialog-file-access.glade",
@@ -312,7 +260,6 @@
 
     /* Run the dialog */
     gtk_widget_show_all( faw->dialog );
-	on_rb_filetype_clicked( faw );
 }
 
 void

Modified: gnucash/trunk/src/gnome-utils/glade/dialog-file-access.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/glade/dialog-file-access.glade	2009-03-09 20:14:46 UTC (rev 17988)
+++ gnucash/trunk/src/gnome-utils/glade/dialog-file-access.glade	2009-03-10 17:41:52 UTC (rev 17989)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Thu Mar  5 16:47:47 2009 -->
+<!--Generated with glade3 3.4.5 on Tue Mar 10 13:32:06 2009 -->
 <glade-interface>
   <widget class="GtkDialog" id="File Access">
     <property name="border_width">5</property>
@@ -18,65 +18,16 @@
               <widget class="GtkHBox" id="hbox1">
                 <property name="visible">True</property>
                 <child>
-                  <widget class="GtkVBox" id="vbox2">
+                  <widget class="GtkVBox" id="vb_uri_type_container">
                     <property name="visible">True</property>
                     <child>
-                      <widget class="GtkRadioButton" id="rb_xml">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">XML</property>
-                        <property name="response_id">0</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">rb_sqlite3</property>
-                        <signal name="clicked" handler="gnc_ui_file_access_rb_xml_clicked_cb"/>
-                      </widget>
+                      <placeholder/>
                     </child>
-                    <child>
-                      <widget class="GtkRadioButton" id="rb_sqlite3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">SQLite3</property>
-                        <property name="response_id">0</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <signal name="clicked" handler="gnc_ui_file_access_rb_sqlite3_clicked_cb"/>
-                      </widget>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <widget class="GtkRadioButton" id="rb_mysql">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">MySQL</property>
-                        <property name="response_id">0</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">rb_xml</property>
-                        <signal name="clicked" handler="gnc_ui_file_access_rb_mysql_clicked_cb"/>
-                      </widget>
-                      <packing>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <widget class="GtkRadioButton" id="rb_pgsql">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">PostgreSQL</property>
-                        <property name="response_id">0</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">rb_xml</property>
-                        <signal name="clicked" handler="gnc_ui_file_access_rb_pgsql_clicked_cb"/>
-                      </widget>
-                      <packing>
-                        <property name="position">3</property>
-                      </packing>
-                    </child>
                   </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
                 </child>
                 <child>
                   <widget class="GtkFrame" id="frame_database">



More information about the gnucash-changes mailing list