28 #include <glib/gi18n.h>
29 #include <glib/gprintf.h>
30 #include <glib/gstdio.h>
34 #include <gtk/gtkmain.h>
35 #include <gpe/pixmaps.h>
36 #include <gpe/pim-categories.h>
37 #include <gpe/errorbox.h>
46 static QofLogModule log_module = GPE_MOD_CLI;
47 #define EXPENSE_ICON PREFIX "/share/pixmaps/gpe-expenses.xpm"
48 #define GPE_EXPENSE_LOG "/tmp/gpe-expense.trace"
49 #define ARGUMENT_BAD_OPTION 17227
50 #define QOF_MOD_SQLITE "qof-sqlite-module"
51 #define SQLITE_DIR ".gpe/"
52 #define DEFAULT_FILE "expenses"
53 #define ACCESS_METHOD "sqlite"
55 #define ENUM_LIST_Q(_) \
70 DEFINE_ENUM(qof_op_type, ENUM_LIST_Q)
94 if (qof_error_check (session))
95 gpe_error_box (qof_error_get_message (session));
98 static struct gpe_icon my_icons[] = {
99 {
"icon", EXPENSE_ICON, 0 },
106 g_return_if_fail(context);
107 g_return_if_fail(gpe_application_init (&argc, &argv));
108 g_return_if_fail(gpe_load_icons (my_icons));
113 gboolean gpe_home_exists;
117 context->qof.
write_file = g_strconcat (g_get_home_dir(),
118 "/", SQLITE_DIR, NULL);
119 gpe_home_exists = g_file_test (context->qof.
write_file, G_FILE_TEST_IS_DIR);
120 if (!gpe_home_exists)
121 test = g_mkdir (context->qof.
write_file, 0700);
123 context->qof.
write_file = g_strconcat (ACCESS_METHOD,
124 ":", g_get_home_dir(),
"/", SQLITE_DIR, DEFAULT_FILE, NULL);
126 context->qof.
write_file = g_strconcat (ACCESS_METHOD,
127 ":", g_get_tmp_dir(),
"/", DEFAULT_FILE, NULL);
135 gtk_init (&argc, &argv);
145 main (
int argc,
char *argv[])
148 const gchar *help_header_text;
153 qof_op_type exp_command;
155 struct poptOption options[] = {
156 { NULL,
'\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptionsI18N,
157 0, _(
"Help options:"), NULL },
158 {
"list",
'l', POPT_ARG_NONE, NULL, qof_op_list,
159 _(
"List all databases supported by the current QOF framework and exit."), NULL},
160 {
"explain", 0, POPT_ARG_NONE, NULL, qof_op_explain,
161 _(
"List the fields within the specified database and exit, requires -d."), NULL},
162 {
"input-file",
'i', POPT_ARG_STRING, &filename, qof_op_input,
163 _(
"Query the QSF XML data in <filename>"), _(
"filename")},
164 {
"date",
't', POPT_ARG_STRING, &date_time, qof_op_time,
165 _(
"Shorthand to only query objects that contain the specified date."), _(
"string")},
166 {
"sql",
's', POPT_ARG_STRING, &sql_query, qof_op_sql,
167 _(
"Specify a SQL query on the command line."), _(
"string")},
168 {
"sql-file",
'f', POPT_ARG_STRING, &sql_file, qof_op_sql_file,
169 _(
"Specify one or more SQL queries contained in a file."), _(
"filename")},
170 {
"write",
'w', POPT_ARG_STRING, &write_file, qof_op_write,
171 _(
"Write the results of any query to the file"), _(
"filename")},
172 {
"gui", 0, POPT_ARG_NONE, NULL, qof_op_gui,
173 _(
"Use the Gtk graphic interface"), NULL},
174 {
"debug", 0, POPT_ARG_NONE, NULL, qof_op_debug,
175 _(
"Print debugging information to a temporary file."), NULL},
176 {
"version", 0, POPT_ARG_NONE, NULL, qof_op_vers,
177 _(
"Display version information"), NULL},
178 {
"category",
'c', POPT_ARG_STRING, &category, qof_op_category,
179 _(
"Shorthand to only query objects that are set to the specified category."),
183 exp_command = qof_op_noop;
186 database = g_strdup(
"gpe_expenses");
189 setlocale (LC_ALL,
"");
190 bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
191 bind_textdomain_codeset (GETTEXT_PACKAGE,
"UTF-8");
192 textdomain (GETTEXT_PACKAGE);
194 help_header_text = _(
201 " Expenses applet for GPE using QOF - \n"
202 " the Query Object Framework.\n"
203 " Supports writing iPAQ data to SQLite.\n"
204 " SQL-type queries on the live data or SQLite file.\n"
205 " SQLite data can be imported into other QOF applications.\n\n"
206 " Use exactly one of -i -l --gui or --explain;\n"
207 " options are -c -t -w, -s or -f.\n\n");
209 pc = poptGetContext (PACKAGE, argc, (
const char **)argv, options, 0);
211 poptSetOtherOptionHelp (pc, help_header_text);
215 poptPrintUsage (pc, stderr, 0);
219 g_return_val_if_fail (gpe_expense_context, 1);
220 while ((optc = poptGetNextOpt (pc)) >= 0)
230 if (qof_op_noop != exp_command)
232 fprintf (stderr, _(
"%s: ERROR: specify only one of"
233 "-i, -l, --gui or --explain.\n"), PACKAGE);
241 fprintf (stdout,
"\n Copyright (c) 2005-2007 Neil Williams <linux@codehelp.co.uk>\n");
242 fprintf (stdout, _(
" For gpe-expenses support, join the QOF-devel mailing list at\n"));
243 fprintf (stdout,
" http://lists.sourceforge.net/mailman/listinfo/qof-devel\n");
244 fprintf (stdout, _(
"\n This is gpe-expenses v%s\n"), VERSION);
245 fprintf (stdout, _(
" Expenses applet for GPE on iPAQ .\n"));
247 fprintf (stdout, _(
" Build target.........: %s\n"), HOST_OS);
249 fprintf (stdout, _(
" Build date...........: %s %s\n"), __DATE__, __TIME__);
251 fprintf (stdout, _(
" --debug logs to......: %s\n\n"), GPE_EXPENSE_LOG);
253 fprintf (stdout, _(
" Please use --help for more detailed options.\n\n"));
257 case qof_op_category:
269 qof_mod_sql (sql_query, &gpe_expense_context->qof);
272 case qof_op_sql_file:
284 qof_log_init_filename(GPE_EXPENSE_LOG);
285 qof_log_set_default(QOF_LOG_DETAIL);
286 qof_log_set_level (GPE_MOD_CLI, QOF_LOG_DETAIL);
288 qof_log_set_level (QOF_MOD_SQLITE, QOF_LOG_DETAIL);
289 qof_log_set_level (GPE_MOD_GUI, QOF_LOG_DETAIL);
295 fprintf (stderr, _(
"%s: ERROR: got option %d, arg %s\n"), PACKAGE,
296 optc, poptGetOptArg (pc));
303 fprintf(stderr,
"%s: %s %s\n\n", PACKAGE,
304 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
306 poptPrintUsage(pc, stderr, 0);
309 if (gpe_expense_context->qof.
error)
317 gpe_expense_context->qof.
filename = g_strdup(filename);
329 gpe_gui_start(argc, argv, gpe_expense_context);
335 if(!gpe_expense_context->qof.
database)
338 fprintf (stderr, _(
"%s: Error: please specify which "
339 "database you would like explained.\n\n"), PACKAGE);
352 if(debug_on) { qof_log_shutdown(); }