GnuCash  5.6-150-g038405b370+
gnc-plugin-csv-export.c
1 /*
2  * gnc-plugin-csv-export.c -- csv export plugin
3  * Copyright (C) 2012 Robert Fewell
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, contact:
17  *
18  * Free Software Foundation Voice: +1-617-542-5942
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
20  * Boston, MA 02110-1301, USA gnu@gnu.org
21  */
22 
23 #include <config.h>
24 
25 #include <gtk/gtk.h>
26 #include <glib/gi18n.h>
27 
28 #include "gnc-plugin-csv-export.h"
29 #include "gnc-plugin-manager.h"
30 
31 #include "assistant-csv-export.h"
32 
34 #include "Query.h"
35 
36 static void gnc_plugin_csv_export_finalize (GObject *object);
37 
38 /* Command callbacks */
39 static void gnc_plugin_csv_export_tree_cmd (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
40 static void gnc_plugin_csv_export_trans_cmd (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
41 static void gnc_plugin_csv_export_register_cmd (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
42 
43 #define PLUGIN_ACTIONS_NAME "gnc-plugin-csv-export-actions"
44 #define PLUGIN_UI_FILENAME "gnc-plugin-csv-export.ui"
45 
46 static GActionEntry gnc_plugin_actions [] =
47 {
48  { "CsvExportTreeAction", gnc_plugin_csv_export_tree_cmd, NULL, NULL, NULL },
49  { "CsvExportTransAction", gnc_plugin_csv_export_trans_cmd, NULL, NULL, NULL },
50  { "CsvExportRegisterAction", gnc_plugin_csv_export_register_cmd, NULL, NULL, NULL },
51 };
53 static guint gnc_plugin_n_actions = G_N_ELEMENTS(gnc_plugin_actions);
54 
56 static const gchar *gnc_plugin_load_ui_items [] =
57 {
58  "FilePlaceholder5",
59  NULL,
60 };
61 
63 {
64  GncPlugin gnc_plugin;
65 };
66 
67 G_DEFINE_TYPE(GncPluginCsvExport, gnc_plugin_csv_export, GNC_TYPE_PLUGIN)
68 
69 GncPlugin *
70 gnc_plugin_csv_export_new (void)
71 {
72  return GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_CSV_EXPORT, NULL));
73 }
74 
75 static void
76 gnc_plugin_csv_export_class_init (GncPluginCsvExportClass *klass)
77 {
78  GObjectClass *object_class = G_OBJECT_CLASS (klass);
79  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
80 
81  object_class->finalize = gnc_plugin_csv_export_finalize;
82 
83  /* plugin info */
84  plugin_class->plugin_name = GNC_PLUGIN_CSV_EXPORT_NAME;
85 
86  /* widget addition/removal */
87  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
88  plugin_class->actions = gnc_plugin_actions;
89  plugin_class->n_actions = gnc_plugin_n_actions;
90  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
91  plugin_class->ui_updates = gnc_plugin_load_ui_items;
92 }
93 
94 static void
95 gnc_plugin_csv_export_init (GncPluginCsvExport *plugin)
96 {
97 }
98 
99 static void
100 gnc_plugin_csv_export_finalize (GObject *object)
101 {
102  g_return_if_fail (GNC_IS_PLUGIN_CSV_EXPORT (object));
103 
104  G_OBJECT_CLASS (gnc_plugin_csv_export_parent_class)->finalize (object);
105 }
106 
107 /************************************************************
108  * Plugin Function Implementation *
109  ************************************************************/
110 
111 /************************************************************
112  * Command Callbacks *
113  ************************************************************/
114 static void
115 gnc_plugin_csv_export_tree_cmd (GSimpleAction *simple,
116  GVariant *parameter,
117  gpointer user_data)
118 {
119  gnc_file_csv_export(XML_EXPORT_TREE);
120 }
121 
122 static void
123 gnc_plugin_csv_export_trans_cmd (GSimpleAction *simple,
124  GVariant *parameter,
125  gpointer user_data)
126 {
127  gnc_file_csv_export(XML_EXPORT_TRANS);
128 }
129 
130 static void
131 gnc_plugin_csv_export_register_cmd (GSimpleAction *simple,
132  GVariant *parameter,
133  gpointer user_data)
134 {
135  GncMainWindowActionData *data = user_data;
136  Query *query;
137  Account *acc;
138 
139  GncPluginPage *page = gnc_main_window_get_current_page (data->window);
140 
141  if (GNC_IS_PLUGIN_PAGE_REGISTER(page))
142  {
143  query = gnc_plugin_page_register_get_query (page);
144  acc = gnc_plugin_page_register_get_account (GNC_PLUGIN_PAGE_REGISTER(page));
145  gnc_file_csv_export_register (XML_EXPORT_REGISTER, query, acc);
146  }
147 }
148 
149 /************************************************************
150  * Plugin Bootstrapping *
151  ************************************************************/
152 void
153 gnc_plugin_csv_export_create_plugin (void)
154 {
155  GncPlugin *plugin = gnc_plugin_csv_export_new ();
156 
158 }
The instance data structure for a content plugin.
STRUCTS.
Plugin management functions for the GnuCash UI.
void gnc_plugin_manager_add_plugin(GncPluginManager *manager, GncPlugin *plugin)
Add a plugin to the list maintained by the plugin manager.
GncPluginPage * gnc_main_window_get_current_page(GncMainWindow *window)
Retrieve a pointer to the page that is currently at the front of the specified window.
CSV Export Assistant.
Functions providing a register page for the GnuCash UI.
GncPluginManager * gnc_plugin_manager_get(void)
Retrieve a pointer to the plugin manager.
void gnc_file_csv_export_register(CsvExportType export_type, Query *q, Account *acc)
The gnc_file_csv_export_register() will let the user export the active register transactions to a del...
void gnc_file_csv_export(CsvExportType export_type)
The gnc_file_csv_export() will let the user export the account tree or transactions to a delimited fi...
Query * gnc_plugin_page_register_get_query(GncPluginPage *plugin_page)
This function is called to get the query associated with this plugin page.
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
Account * gnc_plugin_page_register_get_account(GncPluginPageRegister *page)
Get the Account associated with this register page.
A Query.
Definition: qofquery.cpp:74
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.