r20767 - gnucash/trunk/src/gnome - Convert Autoclear dialog to gtkbuilder with some additional code cleanups

Geert Janssens gjanssens at code.gnucash.org
Sat Jun 18 11:18:23 EDT 2011


Author: gjanssens
Date: 2011-06-18 11:18:22 -0400 (Sat, 18 Jun 2011)
New Revision: 20767
Trac: http://svn.gnucash.org/trac/changeset/20767

Removed:
   gnucash/trunk/src/gnome/glade/autoclear.glade
Modified:
   gnucash/trunk/src/gnome/glade/Makefile.am
   gnucash/trunk/src/gnome/gtkbuilder/autoclear.glade
   gnucash/trunk/src/gnome/window-autoclear.c
Log:
Convert Autoclear dialog to gtkbuilder with some additional code cleanups

Modified: gnucash/trunk/src/gnome/glade/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome/glade/Makefile.am	2011-06-18 12:59:36 UTC (rev 20766)
+++ gnucash/trunk/src/gnome/glade/Makefile.am	2011-06-18 15:18:22 UTC (rev 20767)
@@ -1,6 +1,5 @@
 gladedir = $(GNC_GLADE_DIR)
 glade_DATA = \
-	autoclear.glade \
 	budget.glade \
 	commodities.glade \
 	fincalc.glade \

Deleted: gnucash/trunk/src/gnome/glade/autoclear.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/autoclear.glade	2011-06-18 12:59:36 UTC (rev 20766)
+++ gnucash/trunk/src/gnome/glade/autoclear.glade	2011-06-18 15:18:22 UTC (rev 20767)
@@ -1,136 +0,0 @@
-<?xml version="1.0"?>
-<glade-interface>
-  <!-- interface-requires gtk+ 2.10 -->
-  <!-- interface-naming-policy toplevel-contextual -->
-  <widget class="GtkDialog" id="Auto-clear Start Dialog">
-    <property name="visible">True</property>
-    <property name="resizable">False</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <widget class="GtkVBox" id="dialog-vbox6">
-        <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
-        <child>
-          <widget class="GtkVBox" id="vbox1">
-            <property name="visible">True</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">6</property>
-            <child>
-              <widget class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes"><b>Auto-Clear Information</b></property>
-                <property name="use_markup">True</property>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkAlignment" id="alignment1">
-                <property name="visible">True</property>
-                <property name="left_padding">12</property>
-                <child>
-                  <widget class="GtkTable" id="table1">
-                    <property name="visible">True</property>
-                    <property name="border_width">10</property>
-                    <property name="n_rows">2</property>
-                    <property name="n_columns">2</property>
-                    <property name="column_spacing">4</property>
-                    <property name="row_spacing">6</property>
-                    <child>
-                      <widget class="GtkLabel" id="end_label">
-                        <property name="visible">True</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_Ending Balance:</property>
-                        <property name="use_underline">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkHBox" id="end_value_box">
-                        <property name="visible">True</property>
-                        <child>
-                          <placeholder/>
-                        </child>
-                      </widget>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="right_attach">2</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <widget class="GtkLabel" id="status_label">
-                        <property name="visible">True</property>
-                      </widget>
-                      <packing>
-                        <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                      </packing>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="padding">5</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="dialog-action_area6">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <widget class="GtkButton" id="cancel_button">
-                <property name="label">gtk-cancel</property>
-                <property name="response_id">-6</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkButton" id="ok_button">
-                <property name="label">gtk-ok</property>
-                <property name="response_id">-5</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
-</glade-interface>

Modified: gnucash/trunk/src/gnome/gtkbuilder/autoclear.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/autoclear.glade	2011-06-18 12:59:36 UTC (rev 20766)
+++ gnucash/trunk/src/gnome/gtkbuilder/autoclear.glade	2011-06-18 15:18:22 UTC (rev 20767)
@@ -98,6 +98,7 @@
                 <property name="can_default">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_stock">True</property>
+                <signal name="clicked" handler="gnc_autoclear_window_cancel_cb"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -114,6 +115,7 @@
                 <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
+                <signal name="clicked" handler="gnc_autoclear_window_ok_cb"/>
               </object>
               <packing>
                 <property name="expand">False</property>

Modified: gnucash/trunk/src/gnome/window-autoclear.c
===================================================================
--- gnucash/trunk/src/gnome/window-autoclear.c	2011-06-18 12:59:36 UTC (rev 20766)
+++ gnucash/trunk/src/gnome/window-autoclear.c	2011-06-18 15:18:22 UTC (rev 20767)
@@ -44,6 +44,7 @@
 
 #define WINDOW_AUTOCLEAR_CM_CLASS "window-autoclear"
 
+static QofLogModule log_module = GNC_MOD_GUI;
 
 /** STRUCTS *********************************************************/
 struct _AutoClearWindow
@@ -59,6 +60,12 @@
     GtkLabel *status_label;
 };
 
+/** Callback prototypes************************************************/
+void gnc_autoclear_window_ok_cb     (GtkWidget *widget,
+                                     AutoClearWindow *data);
+void gnc_autoclear_window_cancel_cb (GtkWidget *widget,
+                                     AutoClearWindow *data);
+
 /********************************************************************\
  * gnc_ui_autoclear_window_raise                                    *
  *   shows and raises an auto-clear window                          *
@@ -119,10 +126,10 @@
 
     gnc_numeric reachable_value = gnc_numeric_add_fixed(thisvalue, data->split_value);
     data->reachable_list = g_list_append(data->reachable_list, g_memdup(&reachable_value, sizeof(gnc_numeric)));
-    printf("    Sack: found %s, added %s\n", gnc_numeric_to_string(thisvalue), gnc_numeric_to_string(reachable_value));
+    PINFO("    Sack: found %s, added %s\n", gnc_numeric_to_string(thisvalue), gnc_numeric_to_string(reachable_value));
 }
 
-static void
+void
 gnc_autoclear_window_ok_cb (GtkWidget *widget,
                             AutoClearWindow *data)
 {
@@ -153,13 +160,13 @@
     }
 
     /* Pretty print information */
-    printf("Amount to clear: %s\n", gnc_numeric_to_string(toclear_value));
-    printf("Available splits:\n");
+    PINFO("Amount to clear: %s\n", gnc_numeric_to_string(toclear_value));
+    PINFO("Available splits:\n");
     for (node = nc_list; node; node = node->next)
     {
         Split *split = (Split *)node->data;
         gnc_numeric value = xaccSplitGetAmount (split);
-        printf("  %s\n", gnc_numeric_to_string(value));
+        PINFO("  %s\n", gnc_numeric_to_string(value));
     }
 
     /* Run knapsack */
@@ -167,7 +174,7 @@
      *  - key   = amount to which we know how to clear (freed by GHashTable)
      *  - value = last split we used to clear this amount (not managed by GHashTable)
      */
-    printf("Knapsacking ...\n");
+    PINFO("Knapsacking ...\n");
     sack = g_hash_table_new_full (ght_gnc_numeric_hash, ght_gnc_numeric_equal, g_free, NULL);
     for (node = nc_list; node; node = node->next)
     {
@@ -179,7 +186,7 @@
         data->split_value = split_value;
         data->reachable_list = 0;
 
-        printf("  Split value: %s\n", gnc_numeric_to_string(split_value));
+        PINFO("  Split value: %s\n", gnc_numeric_to_string(split_value));
 
         /* For each value in the sack, compute a new reachable value */
         g_hash_table_foreach (sack, sack_foreach_func, data);
@@ -193,28 +200,28 @@
             gnc_numeric *reachable_value = node->data;
             Split *toinsert_split = split;
 
-            printf("    Reachable value: %s ", gnc_numeric_to_string(*reachable_value));
+            PINFO("    Reachable value: %s ", gnc_numeric_to_string(*reachable_value));
 
             /* Check if it already exists */
             if (g_hash_table_lookup_extended(sack, reachable_value, NULL, NULL))
             {
                 /* If yes, we are in trouble, we reached an amount using two solutions */
                 toinsert_split = NULL;
-                printf("dup");
+                PINFO("dup");
             }
             g_hash_table_insert (sack, reachable_value, toinsert_split);
-            printf("\n");
+            PINFO("\n");
         }
         g_list_free(data->reachable_list);
     }
 
     /* Check solution */
-    printf("Rebuilding solution ...\n");
+    PINFO("Rebuilding solution ...\n");
     while (!gnc_numeric_zero_p(toclear_value))
     {
         gpointer psplit = NULL;
 
-        printf("  Left to clear: %s\n", gnc_numeric_to_string(toclear_value));
+        PINFO("  Left to clear: %s\n", gnc_numeric_to_string(toclear_value));
         if (g_hash_table_lookup_extended(sack, &toclear_value, NULL, &psplit))
         {
             if (psplit != NULL)
@@ -224,21 +231,21 @@
                 toclear_list = g_list_prepend(toclear_list, split);
                 toclear_value = gnc_numeric_sub_fixed(toclear_value,
                                                       xaccSplitGetAmount(split));
-                printf("    Cleared: %s -> %s\n",
+                PINFO("    Cleared: %s -> %s\n",
                        gnc_numeric_to_string(xaccSplitGetAmount(split)),
                        gnc_numeric_to_string(toclear_value));
             }
             else
             {
                 /* We couldn't reconstruct the solution */
-                printf("    Solution not unique.\n");
+                PINFO("    Solution not unique.\n");
                 gtk_label_set_text(data->status_label, "Cannot uniquely clear splits. Found multiple possibilities.");
                 return;
             }
         }
         else
         {
-            printf("    No solution found.\n");
+            PINFO("    No solution found.\n");
             gtk_label_set_text(data->status_label, "The selected amount cannot be cleared.");
             return;
         }
@@ -246,7 +253,7 @@
     g_hash_table_destroy (sack);
 
     /* Show solution */
-    printf("Clearing splits:\n");
+    PINFO("Clearing splits:\n");
     for (node = toclear_list; node; node = node->next)
     {
         Split *split = node->data;
@@ -256,12 +263,12 @@
         recn = xaccSplitGetReconcile (split);
         value = xaccSplitGetAmount (split);
 
-        printf("  %c %s\n", recn, gnc_numeric_to_string(value));
+        PINFO("  %c %s\n", recn, gnc_numeric_to_string(value));
 
         xaccSplitSetReconcile (split, CREC);
     }
     if (toclear_list == 0)
-        printf("  None\n");
+        PINFO("  None\n");
 
     /* Free lists */
     g_list_free(nc_list);
@@ -272,7 +279,7 @@
     g_free(data);
 }
 
-static void
+void
 gnc_autoclear_window_cancel_cb (GtkWidget *widget,
                                 AutoClearWindow *data)
 {
@@ -292,8 +299,9 @@
 AutoClearWindow *
 autoClearWindow (GtkWidget *parent, Account *account)
 {
-    GtkWidget *dialog, *box, *label, *end_value;
-    GladeXML *xml;
+    GtkBox *box;
+    GtkLabel *label;
+    GtkBuilder *builder;
     AutoClearWindow *data;
     char *title;
 
@@ -301,35 +309,32 @@
     data->account = account;
 
     /* Create the dialog box */
-    xml = gnc_glade_xml_new ("autoclear.glade", "Auto-clear Start Dialog");
-    dialog = glade_xml_get_widget (xml, "Auto-clear Start Dialog");
+    builder = gtk_builder_new();
+    gnc_builder_add_from_file (builder, "autoclear.glade", "Auto-clear Start Dialog");
+    data->window = GTK_WIDGET(gtk_builder_get_object (builder, "Auto-clear Start Dialog"));
     title = gnc_autoclear_make_window_name (account);
-    gtk_window_set_title(GTK_WINDOW(dialog), title);
+    gtk_window_set_title(GTK_WINDOW(data->window), title);
     g_free (title);
 
     /* Add amount edit box */
-    end_value = gnc_amount_edit_new();
-    data->end_value = GNC_AMOUNT_EDIT(end_value);
-    box = glade_xml_get_widget(xml, "end_value_box");
-    gtk_box_pack_start(GTK_BOX(box), end_value, TRUE, TRUE, 0);
-    label = glade_xml_get_widget(xml, "end_label");
-    gtk_label_set_mnemonic_widget(GTK_LABEL(label), end_value);
-    gtk_widget_grab_focus(GTK_WIDGET(end_value));
+    data->end_value = GNC_AMOUNT_EDIT(gnc_amount_edit_new());
+    g_signal_connect(GTK_WIDGET(data->end_value), "activate",
+                     G_CALLBACK(gnc_autoclear_window_ok_cb), data);
 
-    data->window = GTK_WIDGET(dialog);
+    box   = GTK_BOX(gtk_builder_get_object (builder, "end_value_box"));
+    gtk_box_pack_start(box, GTK_WIDGET(data->end_value), TRUE, TRUE, 0);
 
+    label = GTK_LABEL(gtk_builder_get_object (builder, "end_label"));
+    gtk_label_set_mnemonic_widget(label, GTK_WIDGET(data->end_value));
+    gtk_widget_grab_focus(GTK_WIDGET(data->end_value));
+
+    data->status_label = GTK_LABEL(gtk_builder_get_object (builder, "status_label"));
+
     if (parent != NULL)
-        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
-    data->ok_button = glade_xml_get_widget(xml, "ok_button");
-    data->cancel_button = glade_xml_get_widget(xml, "cancel_button");
-    data->status_label = GTK_LABEL(glade_xml_get_widget(xml, "status_label"));
+        gtk_window_set_transient_for (GTK_WINDOW (data->window), GTK_WINDOW (parent));
 
-    g_signal_connect(data->ok_button, "clicked",
-                     G_CALLBACK(gnc_autoclear_window_ok_cb), data);
-    g_signal_connect(data->end_value, "activate",
-                     G_CALLBACK(gnc_autoclear_window_ok_cb), data);
-    g_signal_connect(data->cancel_button, "clicked",
-                     G_CALLBACK(gnc_autoclear_window_cancel_cb), data);
+    gtk_builder_connect_signals(builder, data);
+    g_object_unref(G_OBJECT(builder));
 
     return data;
 }



More information about the gnucash-changes mailing list