r21684 - gnucash/trunk/src - Move dialog-dup-trans.c from ledger-core to gnome-utils.

Christian Stimming cstim at code.gnucash.org
Wed Dec 7 03:38:00 EST 2011


Author: cstim
Date: 2011-12-07 03:38:00 -0500 (Wed, 07 Dec 2011)
New Revision: 21684
Trac: http://svn.gnucash.org/trac/changeset/21684

Added:
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
Removed:
   gnucash/trunk/src/register/ledger-core/dialog-dup-trans.c
Modified:
   gnucash/trunk/src/gnome-utils/Makefile.am
   gnucash/trunk/src/gnome-utils/gnc-ui.h
   gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade
   gnucash/trunk/src/register/ledger-core/Makefile.am
   gnucash/trunk/src/register/ledger-core/split-register.c
Log:
Move dialog-dup-trans.c from ledger-core to gnome-utils.

Add gnc_dup_date_dialog() variant that can ask for a date without
the "num" field.

On pressing the Enter key, the widget closes but logs the following
warning:
 CRIT <Gtk> IA__gtk_widget_event: assertion `WIDGET_REALIZED_FOR_EVENT (widget, event)' failed
However, this problem already existed with the old code - the behaviour
and warning was unchanged by this commit.

Modified: gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade	2011-12-07 08:38:00 UTC (rev 21684)
@@ -62,7 +62,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="label1">
+          <object class="GtkLabel" id="duplicate_title_label">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
@@ -81,7 +81,7 @@
             <property name="can_focus">False</property>
             <property name="left_padding">12</property>
             <child>
-              <object class="GtkTable" id="table2">
+              <object class="GtkTable" id="duplicate_table">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="n_rows">2</property>
@@ -103,7 +103,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="label847670">
+                  <object class="GtkLabel" id="num_label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2011-12-07 08:38:00 UTC (rev 21684)
@@ -32,6 +32,7 @@
   dialog-account.c \
   dialog-book-close.c \
   dialog-commodity.c \
+  dialog-dup-trans.c \
   dialog-file-access.c \
   dialog-object-references.c \
   dialog-options.c \
@@ -113,6 +114,7 @@
   dialog-account.h \
   dialog-book-close.h \
   dialog-commodity.h \
+  dialog-dup-trans.h \
   dialog-file-access.h \
   dialog-preferences.h \
   dialog-object-references.h \

Copied: gnucash/trunk/src/gnome-utils/dialog-dup-trans.c (from rev 21683, gnucash/trunk/src/register/ledger-core/dialog-dup-trans.c)
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	2011-12-07 08:38:00 UTC (rev 21684)
@@ -0,0 +1,217 @@
+/********************************************************************\
+ * dialog-dup-trans.c -- duplicate transaction dialog               *
+ * Copyright (C) 2001 Gnumatic, Inc.                                *
+ * Author: Dave Peticolas <dave at krondo.com>                         *
+ *                                                                  *
+ * This program 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.              *
+ *                                                                  *
+ * This program 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <time.h>
+#include <stdlib.h>
+
+#include "dialog-dup-trans.h"
+#include "dialog-utils.h"
+#include "gnc-date-edit.h"
+#include "qof.h"
+
+/* This static indicates the debugging module that this .o belongs to.  */
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+typedef struct
+{
+    GtkWidget * dialog;
+
+    gboolean focus_out;
+
+    GtkWidget * date_edit;
+    GtkWidget * num_edit;
+
+    GtkWidget *duplicate_title_label; // GtkLabel
+    GtkWidget *duplicate_table; // GtkTable
+    GtkWidget *num_label; // GtkLabel
+} DupTransDialog;
+
+/* Parses the string value and returns true if it is a
+ * number. In that case, *num is set to the value parsed.
+ * Copied from numcell.c */
+static gboolean
+parse_num (const char *string, long int *num)
+{
+    long int number;
+
+    if (string == NULL)
+        return FALSE;
+
+    if (!gnc_strisnum(string))
+        return FALSE;
+
+    number = strtol(string, NULL, 10);
+
+    if ((number == LONG_MIN) || (number == LONG_MAX))
+        return FALSE;
+
+    if (num != NULL)
+        *num = number;
+
+    return TRUE;
+}
+
+static gboolean
+gnc_dup_trans_output_cb(GtkSpinButton *spinbutton,
+                        gpointer user_data)
+{
+    gboolean is_number;
+    long int num;
+    gchar *txt = gtk_editable_get_chars(GTK_EDITABLE(spinbutton), 0, -1);
+    is_number = parse_num(txt, &num);
+    g_free(txt);
+    if (!is_number)
+        gtk_entry_set_text(GTK_ENTRY(spinbutton), "");
+    return !is_number;
+}
+
+static void
+gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
+                             time_t date, const char *num_str)
+{
+    GtkWidget *dialog;
+    GtkBuilder  *builder;
+
+    builder = gtk_builder_new();
+    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "adjustment1");
+    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "Duplicate Transaction Dialog");
+
+    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Duplicate Transaction Dialog"));
+    dt_dialog->dialog = dialog;
+
+    /* parent */
+    if (parent != NULL)
+        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+
+    /* date widget */
+    {
+        GtkWidget *date_edit;
+        GtkWidget *hbox;
+        GtkWidget *label;
+
+        date_edit = gnc_date_edit_new (date, FALSE, FALSE);
+        gnc_date_activates_default(GNC_DATE_EDIT(date_edit), TRUE);
+        hbox = GTK_WIDGET(gtk_builder_get_object (builder, "date_hbox"));
+        gtk_widget_show (date_edit);
+
+        label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
+        gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), label);
+
+        gtk_box_pack_end (GTK_BOX (hbox), date_edit, TRUE, TRUE, 0);
+        dt_dialog->date_edit = date_edit;
+    }
+
+    dt_dialog->duplicate_title_label = GTK_WIDGET(gtk_builder_get_object (builder, "duplicate_title_label"));
+    dt_dialog->duplicate_table = GTK_WIDGET(gtk_builder_get_object (builder, "duplicate_table"));
+    dt_dialog->num_label = GTK_WIDGET(gtk_builder_get_object (builder, "num_label"));
+
+    {
+        GtkWidget *num_spin;
+        long int num;
+
+        num_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_spin"));
+        dt_dialog->num_edit = num_spin;
+
+        gtk_entry_set_activates_default(GTK_ENTRY(num_spin), TRUE);
+        g_signal_connect(num_spin, "output",
+                         G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
+
+        if (num_str && parse_num (num_str, &num))
+            gtk_spin_button_set_value (GTK_SPIN_BUTTON (num_spin), num + 1);
+        else
+            gtk_entry_set_text (GTK_ENTRY (num_spin), "");
+    }
+
+    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dt_dialog);
+
+    g_object_unref(G_OBJECT(builder));
+}
+
+static gboolean
+gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title, time_t *date_p,
+                               const char *num, char **out_num)
+{
+    DupTransDialog *dt_dialog;
+    GNCDateEdit *gde;
+    GtkWidget *entry;
+    gboolean ok;
+    gint result;
+
+    if (!date_p)
+        return FALSE;
+
+    dt_dialog = g_new0 (DupTransDialog, 1);
+
+    gnc_dup_trans_dialog_create (parent, dt_dialog, *date_p, num);
+
+    gde = GNC_DATE_EDIT (dt_dialog->date_edit);
+    entry = gde->date_entry;
+
+    gtk_widget_grab_focus (entry);
+
+    if (title)
+    {
+        gtk_label_set_text(GTK_LABEL (dt_dialog->duplicate_title_label), title);
+    }
+
+    if (!out_num)
+    {
+        // The "num" field isn't being asked for, so we make the widgets invisible
+        gtk_widget_set_visible(dt_dialog->num_label, FALSE);
+        gtk_widget_set_visible(dt_dialog->num_edit, FALSE);
+    }
+
+    result = gtk_dialog_run (GTK_DIALOG (dt_dialog->dialog));
+
+    if (result == GTK_RESPONSE_OK)
+    {
+        *date_p = gnc_date_edit_get_date (GNC_DATE_EDIT (dt_dialog->date_edit));
+        if (out_num)
+            *out_num = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->num_edit)));
+        ok = TRUE;
+    }
+    else
+        ok = FALSE;
+
+    gtk_widget_destroy(GTK_WIDGET(dt_dialog->dialog));
+    g_free (dt_dialog);
+
+    return ok;
+}
+
+gboolean
+gnc_dup_trans_dialog (GtkWidget * parent, time_t *date_p,
+                      const char *num, char **out_num)
+{
+    return gnc_dup_trans_dialog_internal(parent, NULL, date_p, num, out_num);
+}
+
+gboolean
+gnc_dup_date_dialog (GtkWidget * parent, const char* title, time_t *date_p)
+{
+    return gnc_dup_trans_dialog_internal(parent, title, date_p, NULL, NULL);
+}


Property changes on: gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + LF

Added: gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	2011-12-07 08:38:00 UTC (rev 21684)
@@ -0,0 +1,62 @@
+/********************************************************************\
+ * dialog-dup-trans.h -- duplicate transaction dialog               *
+ * Copyright (C) 2001 Gnumatic, Inc.                                *
+ * Author: Dave Peticolas <dave at krondo.com>                         *
+ * Copyright (C) 2011, Christian Stimming                           *
+ * Author: Christian Stimming
+ *                                                                  *
+ * This program 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.              *
+ *                                                                  *
+ * This program 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+
+#ifndef DIALOGDUPTRANS_H
+#define DIALOGDUPTRANS_H
+
+#include <gtk/gtk.h>
+
+
+/********************************************************************\
+ * gnc_dup_trans_dialog                                             *
+ *   opens up a window to do an automatic transfer between accounts *
+ *                                                                  *
+ * Args:   parent  - the parent of the window to be created         *
+ *         date    - the initial date to use, and the output        *
+ *                   parameter for the new date                     *
+ *         num     - input num field                                *
+ *         out_num - output num field, g_newed string               *
+ * Return: TRUE if user closes dialog with 'OK'                     *
+\********************************************************************/
+gboolean
+gnc_dup_trans_dialog (GtkWidget * parent, time_t *date_p,
+                      const char *num, char **out_num);
+
+
+/**
+ * Opens up a window to ask for a date for the duplicated element
+ *
+ * \param parent The parent of the window to be created
+ * \param title The text of the title label
+ * \param date  The initial date to use, and the output
+ *                   parameter for the new date
+ *
+ * \return TRUE if user closes dialog with 'OK', otherwise FALSE
+ */
+gboolean
+gnc_dup_date_dialog (GtkWidget * parent, const char* title, time_t *date_p);
+
+#endif // DIALOGDUPTRANS_H


Property changes on: gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
___________________________________________________________________
Added: svn:eol-style
   + LF

Modified: gnucash/trunk/src/gnome-utils/gnc-ui.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-ui.h	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/gnome-utils/gnc-ui.h	2011-12-07 08:38:00 UTC (rev 21684)
@@ -103,8 +103,6 @@
         int default_value,
         GList *radio_list);
 
-gboolean gnc_dup_trans_dialog (GtkWidget *parent, time_t *date_p,
-                               const char *num, char **out_num);
 void     gnc_tax_info_dialog (GtkWidget *parent);
 void     gnc_stock_split_dialog (GtkWidget *parent, Account * initial);
 

Modified: gnucash/trunk/src/register/ledger-core/Makefile.am
===================================================================
--- gnucash/trunk/src/register/ledger-core/Makefile.am	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/register/ledger-core/Makefile.am	2011-12-07 08:38:00 UTC (rev 21684)
@@ -3,7 +3,6 @@
 pkglib_LTLIBRARIES = libgncmod-ledger-core.la
 
 libgncmod_ledger_core_la_SOURCES = \
-  dialog-dup-trans.c \
   gnc-ledger-display.c \
   gncmod-ledger-core.c \
   split-register.c \

Deleted: gnucash/trunk/src/register/ledger-core/dialog-dup-trans.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/dialog-dup-trans.c	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/register/ledger-core/dialog-dup-trans.c	2011-12-07 08:38:00 UTC (rev 21684)
@@ -1,194 +0,0 @@
-/********************************************************************\
- * dialog-dup-trans.c -- duplicate transaction dialog               *
- * Copyright (C) 2001 Gnumatic, Inc.                                *
- * Author: Dave Peticolas <dave at krondo.com>                         *
- *                                                                  *
- * This program 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.              *
- *                                                                  *
- * This program 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, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
-\********************************************************************/
-
-#include "config.h"
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <time.h>
-#include <stdlib.h>
-
-#include "dialog-utils.h"
-#include "gnc-date-edit.h"
-#include "qof.h"
-#include "gnc-ui.h"
-
-/* This static indicates the debugging module that this .o belongs to.  */
-static QofLogModule log_module = GNC_MOD_GUI;
-
-typedef struct
-{
-    GtkWidget * dialog;
-
-    gboolean focus_out;
-
-    GtkWidget * date_edit;
-    GtkWidget * num_edit;
-} DupTransDialog;
-
-/* Parses the string value and returns true if it is a
- * number. In that case, *num is set to the value parsed.
- * Copied from numcell.c */
-static gboolean
-parse_num (const char *string, long int *num)
-{
-    long int number;
-
-    if (string == NULL)
-        return FALSE;
-
-    if (!gnc_strisnum(string))
-        return FALSE;
-
-    number = strtol(string, NULL, 10);
-
-    if ((number == LONG_MIN) || (number == LONG_MAX))
-        return FALSE;
-
-    if (num != NULL)
-        *num = number;
-
-    return TRUE;
-}
-
-static gboolean
-gnc_dup_trans_output_cb(GtkSpinButton *spinbutton,
-                        gpointer user_data)
-{
-    gboolean is_number;
-    long int num;
-    gchar *txt = gtk_editable_get_chars(GTK_EDITABLE(spinbutton), 0, -1);
-    is_number = parse_num(txt, &num);
-    g_free(txt);
-    if (!is_number)
-        gtk_entry_set_text(GTK_ENTRY(spinbutton), "");
-    return !is_number;
-}
-
-static void
-gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
-                             time_t date, const char *num_str)
-{
-    GtkWidget *dialog;
-    GtkBuilder  *builder;
-
-    builder = gtk_builder_new();
-    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "adjustment1");
-    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "Duplicate Transaction Dialog");
-
-    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Duplicate Transaction Dialog"));
-    dt_dialog->dialog = dialog;
-
-    /* parent */
-    if (parent != NULL)
-        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
-
-    /* date widget */
-    {
-        GtkWidget *date_edit;
-        GtkWidget *hbox;
-        GtkWidget *label;
-
-        date_edit = gnc_date_edit_new (date, FALSE, FALSE);
-        gnc_date_activates_default(GNC_DATE_EDIT(date_edit), TRUE);
-        hbox = GTK_WIDGET(gtk_builder_get_object (builder, "date_hbox"));
-        gtk_widget_show (date_edit);
-
-        label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
-        gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), label);
-
-        gtk_box_pack_end (GTK_BOX (hbox), date_edit, TRUE, TRUE, 0);
-        dt_dialog->date_edit = date_edit;
-    }
-
-    {
-        GtkWidget *num_spin;
-        long int num;
-
-        num_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_spin"));
-        dt_dialog->num_edit = num_spin;
-
-        gtk_entry_set_activates_default(GTK_ENTRY(num_spin), TRUE);
-        g_signal_connect(num_spin, "output",
-                         G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
-
-        if (num_str && parse_num (num_str, &num))
-            gtk_spin_button_set_value (GTK_SPIN_BUTTON (num_spin), num + 1);
-        else
-            gtk_entry_set_text (GTK_ENTRY (num_spin), "");
-    }
-
-    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dt_dialog);
-
-    g_object_unref(G_OBJECT(builder));
-}
-
-/********************************************************************\
- * gnc_dup_trans_dialog                                             *
- *   opens up a window to do an automatic transfer between accounts *
- *                                                                  *
- * Args:   parent  - the parent of the window to be created         *
- *         date    - the initial date to use, and the output        *
- *                   parameter for the new date                     *
- *         num     - input num field                                *
- *         out_num - output num field, g_newed string               *
- * Return: TRUE if user closes dialog with 'OK'                     *
-\********************************************************************/
-gboolean
-gnc_dup_trans_dialog (GtkWidget * parent, time_t *date_p,
-                      const char *num, char **out_num)
-{
-    DupTransDialog *dt_dialog;
-    GNCDateEdit *gde;
-    GtkWidget *entry;
-    gboolean ok;
-    gint result;
-
-    if (!date_p || !out_num)
-        return FALSE;
-
-    dt_dialog = g_new0 (DupTransDialog, 1);
-
-    gnc_dup_trans_dialog_create (parent, dt_dialog, *date_p, num);
-
-    gde = GNC_DATE_EDIT (dt_dialog->date_edit);
-    entry = gde->date_entry;
-
-    gtk_widget_grab_focus (entry);
-
-    result = gtk_dialog_run (GTK_DIALOG (dt_dialog->dialog));
-
-    if (result == GTK_RESPONSE_OK)
-    {
-        *date_p = gnc_date_edit_get_date (GNC_DATE_EDIT (dt_dialog->date_edit));
-        *out_num = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->num_edit)));
-        ok = TRUE;
-    }
-    else
-        ok = FALSE;
-
-    gtk_widget_destroy(GTK_WIDGET(dt_dialog->dialog));
-    g_free (dt_dialog);
-
-    return ok;
-}

Modified: gnucash/trunk/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.c	2011-12-05 22:13:07 UTC (rev 21683)
+++ gnucash/trunk/src/register/ledger-core/split-register.c	2011-12-07 08:38:00 UTC (rev 21684)
@@ -48,6 +48,7 @@
 #include "split-register-model-save.h"
 #include "table-allgui.h"
 #include "dialog-account.h"
+#include "dialog-dup-trans.h"
 
 
 /** static variables ******************************************************/



More information about the gnucash-changes mailing list