r23397 - gnucash/trunk/src - Bug 336843: Attach images/files/urls to transactions.

John Ralls jralls at code.gnucash.org
Fri Nov 15 17:02:35 EST 2013


Author: jralls
Date: 2013-11-15 17:02:34 -0500 (Fri, 15 Nov 2013)
New Revision: 23397
Trac: http://svn.gnucash.org/trac/changeset/23397

Modified:
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/Transaction.h
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
   gnucash/trunk/src/gnome-utils/gnc-tree-view.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
   gnucash/trunk/src/gnome/gnc-split-reg.c
   gnucash/trunk/src/gnome/gnc-split-reg.h
   gnucash/trunk/src/gnome/ui/gnc-plugin-page-register-ui.xml
Log:
Bug 336843: Attach images/files/urls to transactions.

Author: Patrick <patrick at setsuid.net>

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/engine/Transaction.c	2013-11-15 22:02:34 UTC (rev 23397)
@@ -177,6 +177,7 @@
 const char *void_time_str = "void-time";
 const char *void_former_notes_str = "void-former-notes";
 const char *trans_is_closing_str = "book_closing";
+const char *assoc_uri_str = "assoc_uri";
 
 /* KVP entry for date-due value */
 #define TRANS_DATE_DUE_KVP       "trans-date-due"
@@ -2006,6 +2007,17 @@
     xaccTransCommitEdit(trans);
 }
 
+void
+xaccTransSetAssociation (Transaction *trans, const char *assoc)
+{
+    if (!trans || !assoc) return;
+    xaccTransBeginEdit(trans);
+
+    kvp_frame_set_str (trans->inst.kvp_data, assoc_uri_str, assoc);
+    qof_instance_set_dirty(QOF_INSTANCE(trans));
+    xaccTransCommitEdit(trans);
+}
+
 static void
 qofTransSetNotes (Transaction *trans, const char *notes)
 {
@@ -2090,6 +2102,13 @@
 }
 
 const char *
+xaccTransGetAssociation (const Transaction *trans)
+{
+    return trans ?
+           kvp_frame_get_string (trans->inst.kvp_data, assoc_uri_str) : NULL;
+}
+
+const char *
 xaccTransGetNotes (const Transaction *trans)
 {
     return trans ?
@@ -2688,6 +2707,11 @@
             (QofSetterFunc)qofTransSetNotes
         },
         {
+            TRANS_ASSOCIATION, QOF_TYPE_STRING,
+            (QofAccessFunc)xaccTransGetAssociation,
+            (QofSetterFunc)xaccTransSetAssociation
+        },
+        {
             TRANS_IS_CLOSING, QOF_TYPE_BOOLEAN,
             (QofAccessFunc)xaccTransGetIsClosingTxn, NULL
         },

Modified: gnucash/trunk/src/engine/Transaction.h
===================================================================
--- gnucash/trunk/src/engine/Transaction.h	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/engine/Transaction.h	2013-11-15 22:02:34 UTC (rev 23397)
@@ -310,6 +310,9 @@
 /** Sets the transaction Description */
 void          xaccTransSetDescription (Transaction *trans, const char *desc);
 
+/** Sets the transaction Association */
+void          xaccTransSetAssociation (Transaction *trans, const char *assoc);
+
 /** Sets the transaction Notes
  *
  The Notes field is only visible in the register in double-line mode */
@@ -323,6 +326,8 @@
 const char *  xaccTransGetNum (const Transaction *trans);
 /** Gets the transaction Description */
 const char *  xaccTransGetDescription (const Transaction *trans);
+/** Gets the transaction association */
+const char *  xaccTransGetAssociation(const Transaction *trans);
 /** Gets the transaction Notes
  *
  The Notes field is only visible in the register in double-line mode */
@@ -724,6 +729,7 @@
 #define TRANS_IS_BALANCED	"trans-balanced?"
 #define TRANS_IS_CLOSING        "trans-is-closing?"
 #define TRANS_NOTES		"notes"
+#define TRANS_ASSOCIATION	"assoc"
 #define TRANS_TYPE		"type"
 #define TRANS_VOID_STATUS	"void-p"
 #define TRANS_VOID_REASON	"void-reason"

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2013-11-15 22:02:34 UTC (rev 23397)
@@ -169,6 +169,9 @@
 static void gnc_plugin_page_register_cmd_scrub_current (GtkAction *action, GncPluginPageRegister *plugin_page);
 static void gnc_plugin_page_register_cmd_account_report (GtkAction *action, GncPluginPageRegister *plugin_page);
 static void gnc_plugin_page_register_cmd_transaction_report (GtkAction *action, GncPluginPageRegister *plugin_page);
+static void gnc_plugin_page_register_cmd_associate_file_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
+static void gnc_plugin_page_register_cmd_associate_location_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
+static void gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
 
 static void gnc_plugin_page_help_changed_cb( GNCSplitReg *gsr, GncPluginPageRegister *register_page );
 static void gnc_plugin_page_register_refresh_cb (GHashTable *changes, gpointer user_data);
@@ -185,26 +188,32 @@
 /*                          Actions                         */
 /************************************************************/
 
-#define CUT_TRANSACTION_LABEL         N_("Cu_t Transaction")
-#define COPY_TRANSACTION_LABEL        N_("_Copy Transaction")
-#define PASTE_TRANSACTION_LABEL       N_("_Paste Transaction")
-#define DUPLICATE_TRANSACTION_LABEL   N_("Dup_licate Transaction")
-#define DELETE_TRANSACTION_LABEL      N_("_Delete Transaction")
-#define CUT_SPLIT_LABEL               N_("Cu_t Split")
-#define COPY_SPLIT_LABEL              N_("_Copy Split")
-#define PASTE_SPLIT_LABEL             N_("_Paste Split")
-#define DUPLICATE_SPLIT_LABEL         N_("Dup_licate Split")
-#define DELETE_SPLIT_LABEL            N_("_Delete Split")
-#define CUT_TRANSACTION_TIP           N_("Cut the selected transaction into clipboard")
-#define COPY_TRANSACTION_TIP          N_("Copy the selected transaction into clipboard")
-#define PASTE_TRANSACTION_TIP         N_("Paste the transaction from the clipboard")
-#define DUPLICATE_TRANSACTION_TIP     N_("Make a copy of the current transaction")
-#define DELETE_TRANSACTION_TIP        N_("Delete the current transaction")
-#define CUT_SPLIT_TIP                 N_("Cut the selected split into clipboard")
-#define COPY_SPLIT_TIP                N_("Copy the selected split into clipboard")
-#define PASTE_SPLIT_TIP               N_("Paste the split from the clipboard")
-#define DUPLICATE_SPLIT_TIP           N_("Make a copy of the current split")
-#define DELETE_SPLIT_TIP              N_("Delete the current split")
+#define CUT_TRANSACTION_LABEL            N_("Cu_t Transaction")
+#define COPY_TRANSACTION_LABEL           N_("_Copy Transaction")
+#define PASTE_TRANSACTION_LABEL          N_("_Paste Transaction")
+#define DUPLICATE_TRANSACTION_LABEL      N_("Dup_licate Transaction")
+#define DELETE_TRANSACTION_LABEL         N_("_Delete Transaction")
+#define ASSOCIATE_TRANSACTION_FILE_LABEL      N_("_Associate File with Transaction")
+#define ASSOCIATE_TRANSACTION_LOCATION_LABEL  N_("_Associate Location with Transaction")
+#define EXECASSOCIATED_TRANSACTION_LABEL N_("_Open Associated File/Location")
+#define CUT_SPLIT_LABEL                  N_("Cu_t Split")
+#define COPY_SPLIT_LABEL                 N_("_Copy Split")
+#define PASTE_SPLIT_LABEL                N_("_Paste Split")
+#define DUPLICATE_SPLIT_LABEL            N_("Dup_licate Split")
+#define DELETE_SPLIT_LABEL               N_("_Delete Split")
+#define CUT_TRANSACTION_TIP              N_("Cut the selected transaction into clipboard")
+#define COPY_TRANSACTION_TIP             N_("Copy the selected transaction into clipboard")
+#define PASTE_TRANSACTION_TIP            N_("Paste the transaction from the clipboard")
+#define DUPLICATE_TRANSACTION_TIP        N_("Make a copy of the current transaction")
+#define DELETE_TRANSACTION_TIP           N_("Delete the current transaction")
+#define ASSOCIATE_TRANSACTION_FILE_TIP   N_("Associate a file with the current transaction")
+#define ASSOCIATE_TRANSACTION_LOCATION_TIP    N_("Associate a location with the current transaction")
+#define EXECASSOCIATED_TRANSACTION_TIP   N_("Open the associated file or location with the current transaction")
+#define CUT_SPLIT_TIP                    N_("Cut the selected split into clipboard")
+#define COPY_SPLIT_TIP                   N_("Copy the selected split into clipboard")
+#define PASTE_SPLIT_TIP                  N_("Paste the split from the clipboard")
+#define DUPLICATE_SPLIT_TIP              N_("Make a copy of the current split")
+#define DELETE_SPLIT_TIP                 N_("Delete the current split")
 
 static GtkActionEntry gnc_plugin_page_register_actions [] =
 {
@@ -297,6 +306,21 @@
         "ReverseTransactionAction", NULL, N_("Add _Reversing Transaction"), NULL, NULL,
         G_CALLBACK (gnc_plugin_page_register_cmd_reverse_transaction)
     },
+    {
+        "AssociateTransactionFileAction", NULL, ASSOCIATE_TRANSACTION_FILE_LABEL, NULL,
+        ASSOCIATE_TRANSACTION_FILE_TIP,
+        G_CALLBACK (gnc_plugin_page_register_cmd_associate_file_transaction)
+    },
+    {
+        "AssociateTransactionLocationAction", NULL, ASSOCIATE_TRANSACTION_LOCATION_LABEL, NULL,
+        ASSOCIATE_TRANSACTION_LOCATION_TIP,
+        G_CALLBACK (gnc_plugin_page_register_cmd_associate_location_transaction)
+    },
+    {
+        "ExecAssociatedTransactionAction", NULL, EXECASSOCIATED_TRANSACTION_LABEL, NULL,
+        EXECASSOCIATED_TRANSACTION_TIP,
+        G_CALLBACK (gnc_plugin_page_register_cmd_execassociated_transaction)
+    },
 
     /* View menu */
 
@@ -451,16 +475,19 @@
 /** Short labels for use on the toolbar buttons. */
 static action_toolbar_labels toolbar_labels[] =
 {
-    { "ActionsTransferAction", 	  N_("Transfer") },
-    { "RecordTransactionAction", 	  N_("Enter") },
-    { "CancelTransactionAction", 	  N_("Cancel") },
-    { "DeleteTransactionAction", 	  N_("Delete") },
-    { "DuplicateTransactionAction", N_("Duplicate") },
-    { "SplitTransactionAction",     N_("Split") },
-    { "ScheduleTransactionAction",  N_("Schedule") },
-    { "BlankTransactionAction",     N_("Blank") },
-    { "ActionsReconcileAction",     N_("Reconcile") },
-    { "ActionsAutoClearAction",     N_("Auto-clear") },
+    { "ActionsTransferAction", 	            N_("Transfer") },
+    { "RecordTransactionAction", 	        N_("Enter") },
+    { "CancelTransactionAction", 	        N_("Cancel") },
+    { "DeleteTransactionAction", 	        N_("Delete") },
+	{ "DuplicateTransactionAction",         N_("Duplicate") },
+    { "SplitTransactionAction",             N_("Split") },
+    { "ScheduleTransactionAction",          N_("Schedule") },
+    { "BlankTransactionAction",             N_("Blank") },
+    { "ActionsReconcileAction",             N_("Reconcile") },
+    { "ActionsAutoClearAction",             N_("Auto-clear") },
+    { "AssociateTransactionFileAction",     N_("Associate File") },
+    { "AssociateTransactionLocationAction", N_("Associate Location") },
+    { "ExecAssociatedTransactionAction",    N_("Open File/Location") },
     { NULL, NULL },
 };
 
@@ -804,6 +831,8 @@
     "ScheduleTransactionAction",
     "ScrubAllAction",
     "ScrubCurrentAction",
+    "AssociateTransactionFileAction",
+    "AssociateTransactionLocationAction",
     NULL
 };
 
@@ -827,6 +856,9 @@
     PASTE_TRANSACTION_LABEL,
     DUPLICATE_TRANSACTION_LABEL,
     DELETE_TRANSACTION_LABEL,
+    ASSOCIATE_TRANSACTION_FILE_LABEL,
+    ASSOCIATE_TRANSACTION_LOCATION_LABEL,
+    EXECASSOCIATED_TRANSACTION_LABEL,
     NULL
 };
 
@@ -838,6 +870,9 @@
     PASTE_TRANSACTION_TIP,
     DUPLICATE_TRANSACTION_TIP,
     DELETE_TRANSACTION_TIP,
+    ASSOCIATE_TRANSACTION_FILE_TIP,
+    ASSOCIATE_TRANSACTION_LOCATION_TIP,
+    EXECASSOCIATED_TRANSACTION_TIP,
     NULL
 };
 
@@ -3393,6 +3428,54 @@
 }
 
 static void
+gnc_plugin_page_register_cmd_associate_file_transaction (GtkAction *action,
+        GncPluginPageRegister *plugin_page)
+{
+    GncPluginPageRegisterPrivate *priv;
+
+    ENTER("(action %p, plugin_page %p)", action, plugin_page);
+
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+    gsr_default_associate_handler_file(priv->gsr, NULL);
+    LEAVE(" ");
+
+}
+
+static void
+gnc_plugin_page_register_cmd_associate_location_transaction (GtkAction *action,
+        GncPluginPageRegister *plugin_page)
+{
+    GncPluginPageRegisterPrivate *priv;
+
+    ENTER("(action %p, plugin_page %p)", action, plugin_page);
+
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+    gsr_default_associate_handler_location(priv->gsr, NULL);
+    LEAVE(" ");
+
+}
+
+static void
+gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action,
+        GncPluginPageRegister *plugin_page)
+{
+    GncPluginPageRegisterPrivate *priv;
+
+    ENTER("(action %p, plugin_page %p)", action, plugin_page);
+
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+    gsr_default_execassociated_handler(priv->gsr, NULL);
+    LEAVE(" ");
+
+}
+
+static void
 gnc_plugin_page_register_cmd_blank_transaction (GtkAction *action,
         GncPluginPageRegister *plugin_page)
 {

Modified: gnucash/trunk/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.c	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome/gnc-split-reg.c	2013-11-15 22:02:34 UTC (rev 23397)
@@ -45,6 +45,7 @@
 #include "gnc-euro.h"
 #include "gnc-prefs.h"
 #include "gnc-gui-query.h"
+#include "gnc-gnome-utils.h"
 #include "gnc-ledger-display.h"
 #include "gnc-pricedb.h"
 #include "gnc-ui-util.h"
@@ -106,6 +107,9 @@
 void gsr_default_void_txn_handler ( GNCSplitReg *w, gpointer ud );
 void gsr_default_unvoid_txn_handler  ( GNCSplitReg *w, gpointer ud );
 void gsr_default_reverse_txn_handler ( GNCSplitReg *w, gpointer ud );
+void gsr_default_associate_handler_file   ( GNCSplitReg *w, gpointer ud );
+void gsr_default_associate_handler_location   ( GNCSplitReg *w, gpointer ud );
+void gsr_default_execassociated_handler   ( GNCSplitReg *w, gpointer ud );
 
 static void gsr_emit_simple_signal( GNCSplitReg *gsr, const char *sigName );
 static void gsr_emit_help_changed( GnucashRegister *reg, gpointer user_data );
@@ -1006,7 +1010,182 @@
     gsr_emit_simple_signal( gsr, "reinit_ent" );
 }
 
+/**
+ * Associates a file URI with the current transaction.
+ **/
 void
+gsr_default_associate_handler_file( GNCSplitReg *gsr, gpointer data )
+{
+    CursorClass cursor_class;
+    SplitRegister *reg;
+    Transaction *trans;
+    Split *split;
+    GtkWidget *dialog;
+
+    reg = gnc_ledger_display_get_split_register( gsr->ledger );
+
+    /* get the current split based on cursor position */
+    split = gnc_split_register_get_current_split(reg);
+    if (split == NULL)
+    {
+        gnc_split_register_cancel_cursor_split_changes (reg);
+        return;
+    }
+
+    trans = xaccSplitGetParent(split);
+    cursor_class = gnc_split_register_get_current_cursor_class (reg);
+
+    if (cursor_class == CURSOR_CLASS_NONE)
+        return;
+
+    if (is_trans_readonly_and_warn(trans))
+        return;
+
+	dialog = gtk_file_chooser_dialog_new ("Associate File with Transaction",
+                                     GTK_WINDOW(gsr->window),
+                                     GTK_FILE_CHOOSER_ACTION_OPEN,
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                     NULL);
+
+	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER(dialog), 0);
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ 	{
+		char *uri;
+
+	    uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+        DEBUG("File URI: %s\n", uri);
+	    xaccTransSetAssociation(trans, uri);
+    }
+
+	gtk_widget_destroy (dialog);
+
+}
+
+/**
+ * Associates a location URI with the current transaction.
+ **/
+void
+gsr_default_associate_handler_location( GNCSplitReg *gsr, gpointer data )
+{
+    CursorClass cursor_class;
+    SplitRegister *reg;
+    Transaction *trans;
+    Split *split;
+    GtkWidget *dialog, *entry, *label, *content_area;
+
+    reg = gnc_ledger_display_get_split_register( gsr->ledger );
+
+    /* get the current split based on cursor position */
+    split = gnc_split_register_get_current_split(reg);
+    if (split == NULL)
+    {
+        gnc_split_register_cancel_cursor_split_changes (reg);
+        return;
+    }
+
+    trans = xaccSplitGetParent(split);
+    cursor_class = gnc_split_register_get_current_cursor_class (reg);
+
+    if (cursor_class == CURSOR_CLASS_NONE)
+        return;
+
+    if (is_trans_readonly_and_warn(trans))
+        return;
+
+    dialog = gtk_file_chooser_dialog_new ("Associate Location with Transaction",
+                                     GTK_WINDOW(gsr->window),
+                                     GTK_FILE_CHOOSER_ACTION_OPEN,
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                     NULL);
+
+    content_area = GTK_DIALOG (dialog)->vbox;
+
+    // add a label
+    label = gtk_label_new ("Please enter URL:");
+    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
+    gtk_container_add (GTK_CONTAINER (content_area), label);
+
+    // add the entry text
+    entry = gtk_entry_new ();
+    gtk_entry_set_width_chars(GTK_ENTRY (entry), 80);
+    gtk_entry_set_activates_default(GTK_ENTRY (entry), TRUE);
+    gtk_container_add (GTK_CONTAINER (content_area), entry);
+
+    // set spacings
+    gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
+    gtk_container_set_border_width (GTK_CONTAINER (label), 5);
+    gtk_container_set_border_width (GTK_CONTAINER (content_area), 5);
+
+    // set the default response
+    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+
+    // run the dialog
+    gtk_widget_show_all (dialog);
+
+    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+    {
+		const char *uri;
+
+        uri = gtk_entry_get_text (GTK_ENTRY (entry));
+        DEBUG("Location URI: %s\n", uri);
+        xaccTransSetAssociation(trans, uri);
+    }
+
+     gtk_widget_destroy (dialog);
+
+}
+/**
+ * Executes the associated link with the current transaction.
+ **/
+void
+gsr_default_execassociated_handler( GNCSplitReg *gsr, gpointer data )
+{
+    CursorClass cursor_class;
+    SplitRegister *reg;
+    Transaction *trans;
+    Split *split;
+    GtkWidget *dialog;
+    const char *uri;
+
+    reg = gnc_ledger_display_get_split_register( gsr->ledger );
+
+    /* get the current split based on cursor position */
+    split = gnc_split_register_get_current_split(reg);
+    if (split == NULL)
+    {
+        gnc_split_register_cancel_cursor_split_changes (reg);
+        return;
+    }
+
+    trans = xaccSplitGetParent(split);
+    cursor_class = gnc_split_register_get_current_cursor_class (reg);
+
+    if (cursor_class == CURSOR_CLASS_NONE)
+        return;
+
+#ifdef DUMP_FUNCTIONS
+   xaccTransDump (trans, "ExecAssociated")
+#endif
+
+    uri = xaccTransGetAssociation(trans);
+    if (!uri)
+    {
+        const gchar *message =
+            _("This transaction is not associated with a URI.");
+        gnc_error_dialog(NULL, "%s", message);
+        return;
+    }
+    else
+    {
+        gnc_launch_assoc(uri);
+    }
+
+    return;
+}
+
+void
 gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data )
 {
     CursorClass cursor_class;

Modified: gnucash/trunk/src/gnome/gnc-split-reg.h
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.h	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome/gnc-split-reg.h	2013-11-15 22:02:34 UTC (rev 23397)
@@ -242,6 +242,9 @@
                                     time64 statement_date, gnc_numeric balancing_amount);
 
 void gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data );
+void gsr_default_associate_handler_file( GNCSplitReg *gsr, gpointer data );
+void gsr_default_associate_handler_location( GNCSplitReg *gsr, gpointer data );
+void gsr_default_execassociated_handler( GNCSplitReg *gsr, gpointer data );
 void gnc_split_reg_enter( GNCSplitReg *gsr, gboolean next_transaction );
 void gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data );
 void gsr_default_reinit_handler( GNCSplitReg *gsr, gpointer data );

Modified: gnucash/trunk/src/gnome/ui/gnc-plugin-page-register-ui.xml
===================================================================
--- gnucash/trunk/src/gnome/ui/gnc-plugin-page-register-ui.xml	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome/ui/gnc-plugin-page-register-ui.xml	2013-11-15 22:02:34 UTC (rev 23397)
@@ -20,6 +20,10 @@
       <menuitem name="VoidTransaction"    	action="VoidTransactionAction"/>
       <menuitem name="UnvoidTransaction"  	action="UnvoidTransactionAction"/>
       <menuitem name="ReverseTransaction" 	action="ReverseTransactionAction"/>
+      <separator name="TransactionSep3"/>
+      <menuitem name="AssociateTransactionFile" action="AssociateTransactionFileAction"/>
+      <menuitem name="AssociateTransactionLocation" action="AssociateTransactionLocationAction"/>
+      <menuitem name="ExecAssociateTransaction" action="ExecAssociatedTransactionAction"/>
     </menu>
 
     <menu name="View" action="ViewAction">
@@ -92,6 +96,10 @@
       <menuitem name="RecordTransaction"       action="RecordTransactionAction"/>
       <menuitem name="CancelTransaction"       action="CancelTransactionAction"/>
       <separator name="PopupSep3"/>
+      <menuitem name="AssociateTransactionFile" action="AssociateTransactionFileAction"/>
+      <menuitem name="AssociateTransactionLocation" action="AssociateTransactionLocationAction"/>
+      <menuitem name="ExecAssociateTransaction" action="ExecAssociatedTransactionAction"/>
+      <separator name="PopupSep4"/>
       <menuitem name="BlankTransaction"        action="BlankTransactionAction"/>
       <menuitem name="SplitTransaction"        action="SplitTransactionAction"/>
       <menuitem name="EditExchangeRate"        action="EditExchangeRateAction"/>

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2013-11-15 22:02:34 UTC (rev 23397)
@@ -398,6 +398,78 @@
 
 #endif
 
+#ifdef MAC_INTEGRATION
+
+/* Don't be alarmed if this function looks strange to you: It's
+ * written in Objective-C, the native language of the OSX Cocoa
+ * toolkit.
+ */
+void
+gnc_launch_assoc (const char *uri)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    NSString *uri_str = [NSString stringWithUTF8String: uri];
+    NSURL *url = [[[NSURL alloc] initWithString: uri_str] autorelease];
+    const gchar *message =
+        _("GnuCash could not find the associated file.");
+
+    if (url)
+    {
+        [[NSWorkspace sharedWorkspace] openURL: url];
+        [pool release];
+        return;
+    }
+
+    gnc_error_dialog(NULL, "%s", message);
+
+    [pool release];
+    return;
+}
+#elif defined G_OS_WIN32 /* G_OS_WIN32 */
+void
+gnc_launch_assoc (const char *uri)
+{
+    wchar_t *winuri = (wchar_t *)g_utf8_to_utf16(uri, -1, NULL, NULL, NULL);
+
+    if (winuri)
+    {
+        if ((INT_PTR)ShellExecuteW(NULL, "open", winuri, NULL, NULL, SW_SHOWNORMAL) <= 32)
+        {
+            const gchar *message =
+                _("GnuCash could not find the associated file.");
+            gnc_error_dialog(NULL, "%s", message);
+        }
+        free(winuri);
+    }
+}
+
+#else
+void
+gnc_launch_assoc (const char *uri)
+{
+    GError *error = NULL;
+    gboolean success;
+
+    if (!uri)
+        return;
+
+    DEBUG ("Attempting to open uri %s", uri);
+    success = gtk_show_uri (NULL, uri, gtk_get_current_event_time (), &error);
+    if (success)
+        return;
+
+    g_assert(error != NULL);
+    {
+        const gchar *message =
+            _("GnuCash could not open the associated URI:");
+        gnc_error_dialog(NULL, "%s\n%s", message, uri);
+    }
+    PERR ("%s", error->message);
+    g_error_free(error);
+}
+
+#endif
+
 /********************************************************************\
  * gnc_gnome_get_pixmap                                             *
  *   returns a GtkWidget given a pixmap filename                    *

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2013-11-15 22:02:34 UTC (rev 23397)
@@ -56,6 +56,9 @@
  */
 void gnc_gnome_help (const char *file_name,
                      const char *anchor);
+/** Launch the default gnome browser and open the provided URI.
+ */
+void gnc_launch_assoc (const char *uri);
 
 /** Set the help callback to 'gnc_book_options_help_cb' to open a help browser
  *  and point it to the Book Options link in the Help file.

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view.c	2013-11-15 19:17:30 UTC (rev 23396)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view.c	2013-11-15 22:02:34 UTC (rev 23397)
@@ -848,7 +848,7 @@
         }
         num_cols++;
     }
-    DEBUG ("got %lu columns: %s", num_cols, col_names);
+    //DEBUG ("got %lu columns: %s", num_cols, col_names);
     col_str_list = g_strsplit (col_names, ";", 0);
 
     /* Clean up */



More information about the gnucash-changes mailing list