Data Structures | |
struct | PilotPack_s |
Packing function wrapper. More... | |
struct | PQExp_s |
struct | PQContext_s |
The pilot-qof context struct, extends qof_main_context. More... | |
Files | |
file | pilot-qof.c |
Executable interface to the QOF external framework. | |
file | pilot-qof.h |
Executable interface to the QOF external framework. | |
Defines | |
#define | _GNU_SOURCE |
#define | ARGUMENT_BAD_OPTION 17227 |
#define | EXCLUDE_REPEATER_SQL |
#define | ENUM_LIST_Q(_) |
#define | PQ_MOD_PILOT "pilotqof-objects" |
#define | PQ_MOD_PILOT "pilotqof-objects" |
#define | PILOT_QOF_LOG "pilot-qof.trace" |
#define | PQ_MOD_CLI "pilotqof-cli" |
#define | PQ_DLP_CARD 0 |
#define | PQ_DLP_OFFSET 0 |
#define | PQ_DLP_RECORD 0 |
#define | PQ_DLP_NEW_REC 0 |
#define | PQ_DLP_SET_ID 0 |
#define | PQ_DLP_APPREAD -1 |
#define | PQ_DLP_APPREAD -1 |
#define | PQ_DLP_REC_ATTR 0 |
#define | PQ_DEF_BUFSZ 0xffff |
#define | PILOT_LINK_SUPPORT "0.12" |
#define | PQ_PREF_USE_BACKUP 1 |
#define | PQ_PREF_USE_SIZE 0 |
#define | PQ_PREF_VERSION 0 |
Typedefs | |
typedef struct PQExp_s | PQExpensePref |
typedef struct PQContext_s | PQContext |
The pilot-qof context struct, extends qof_main_context. | |
Enumerations | |
enum | qof_op_type { qof_op_noop = 0, qof_op_offline, qof_op_list, qof_op_hotsync, qof_op_empty, qof_op_category, qof_op_database, qof_op_time, qof_op_exclude, qof_op_sql, qof_op_sql_file, qof_op_write, qof_op_upload, qof_op_explain, qof_op_vers, qof_op_compress, qof_op_debug, qof_op_inv_city, qof_op_inv_vendor, qof_op_use_locale } |
enum | plu_findcategory_flags_t { PLU_CAT_NOFLAGS = 0, PLU_CAT_CASE_INSENSITIVE = 0x0001, PLU_CAT_DEFAULT_UNFILED = 0x0002, PLU_CAT_MATCH_NUMBERS = 0x0004, PLU_CAT_WARN_UNKNOWN = 0x0008 } |
Functions | |
static PQContext * | pilot_qof_create (void) |
PQContext * | pilot_qof_init (void) |
Register all QOF objects. | |
static gint | plu_connect (gchar *plu_port, gint plu_quiet) |
static gint | pq_findcategory (PQContext *context, const gchar *name, gint flags) |
static void | pilot_entity_free (QofEntity *ent, gpointer user_data) |
static void | pilot_object_free (QofObject *obj, gpointer user_data) |
static void | pilot_qof_free (PQContext *data) |
static void | write_ent_cb (QofEntity *ent, gpointer user_data) |
static void | pilot_database_open (QofObject *obj, gpointer user_data) |
static void | pilot_error (PQContext *context, const gchar *message) |
static void | find_invoice_contact (QofEntity *ent, gpointer data) |
static void | check_invoice_handler (PQContext *context) |
void | qof_cmd_hotsync (PQContext *context) |
Activate/HotSync and query the Palm, ignoring the offline storage. | |
static void | pq_invoice_xmlfile (PQContext *context) |
int | main (int argc, const char *argv[]) |
void | pilot_qof_close (void) |
Shutdown the QOF framework. | |
Variables | |
static QofLogModule | log_module = "pilotqof-cli" |
static GList * | pilot_modules = NULL |
static const gchar * | env_pilotport = "PILOTPORT" |
Packing, unpacking and freeing wrapped objects. | |
QOF is wrapped around existing pilot-link structs. These objects have their own methods for writing to and reading from the Palm databases. Objects are packed before being written to the Palm, and unpacked to create new objects when the database is read. Packing and unpacking are only used when connecting to the Palm.
The free_ent_func routines are used whenever any QofBook created from this framework is closed. | |
typedef gint(* | QofPack )(QofEntity *ent, gpointer user_data) |
Packing function pointer type. | |
typedef struct PilotPack_s | PQPack |
Packing function wrapper. | |
void | pilot_qof_pack (QofEntity *ent, gpointer user_data) |
Pack this object. | |
void | pilot_qof_unpack (QofEntity *ent, gpointer user_data) |
Unpack this object. | |
void | pilot_app_unpack (QofIdTypeConst e_type, gpointer user_data) |
Unpack the database information. | |
void | pilot_entity_finaliser (QofBook *book, gpointer key, gpointer data) |
Free the wrapped object. | |
gboolean | pilot_qof_pack_register (const PQPack *p) |
Shamelessly copied from QOF. | |
const PQPack * | pilot_qof_pack_lookup (QofIdTypeConst object_type) |
provide for looking up an object |
The types of SQL queries that are allowed at this point are a little limited. In general, only the following types of queries are supported:
SELECT * FROM SomeObj WHERE (param_a < 10.0) AND (param_b = "asdf") SORT BY param_c DESC;
INSERT INTO SomeObj (param_a, param_b, param_c) VALUES ("value_a", true, "0/1");
Joins are not supported directly.
SELECT * FROM ObjA,ObjB WHERE (ObjA.param_id = ObjB.param_other_id);
The problem with the above is that the search requires a nested search loop, aka a 'join', which is not currently supported in the underlying QofQuery code.
However, by repeating queries and adding the entities to a new session using qof_entity_copy_list, a series of queries can be added to a single book. e.g. You can insert multiple entities and save out as a QSF XML file or use multiple SELECT queries to build a precise list - this can be used to replicate most of the functionality of a SQL join.
SELECT * from ObjA where param_id = value; SELECT * from ObjB where param_other_id = value;
Equivalent to:
SELECT * from ObjA,ObjB where param_id = param_other_id and param_id = value;
When combined with a foreach callback on the value of param_id for each entity in the QofBook, you can produce the effect of a join from running the two SELECT queries for each value of param_id held in 'value'.
See QofEntityForeachCB and qof_object_foreach.
SELECT a,b,c FROM ...
Used to convert QOF objects between applications by using the returned parameter values to create a second object. One application using QOF could register objects from two applications and convert data from one to the other by using
SELECT a,b,c FROM ObjA; SELECT d,f,k FROM ObjB; qof_object_new_instance(); ObjC_set_a(value_c); ObjC_set_b(value_k) etc.
What's needed is for the SELECT to return a complete object that only contains the parameters selected.
Unsupported: UPDATE, DELETE.
It will not be possible to support CREATE, AMEND or DROP for understandable reasons.
#define ENUM_LIST_Q | ( | _ | ) |
Value:
_(qof_op_noop, = 0) \ _(qof_op_offline, ) \ _(qof_op_list,) \ _(qof_op_hotsync,) \ _(qof_op_empty,) \ _(qof_op_category,) \ _(qof_op_database,) \ _(qof_op_time,) \ _(qof_op_exclude,) \ _(qof_op_sql,) \ _(qof_op_sql_file,) \ _(qof_op_write, ) \ _(qof_op_upload, ) \ _(qof_op_explain,) \ _(qof_op_vers,) \ _(qof_op_compress,) \ _(qof_op_debug,) \ _(qof_op_inv_city,) \ _(qof_op_inv_vendor,) \ _(qof_op_use_locale,)
Definition at line 75 of file pilot-qof.c.
#define EXCLUDE_REPEATER_SQL |
Value:
"SELECT * from pilot_datebook " \ "where DATEBOOK_REPEATER == TRUE;"
Definition at line 72 of file pilot-qof.c.
#define PILOT_LINK_SUPPORT "0.12" |
This is the 0.1.x series of pilot-qof
Definition at line 143 of file pilot-qof.h.
Referenced by main().
#define PILOT_QOF_LOG "pilot-qof.trace" |
#define PQ_DEF_BUFSZ 0xffff |
#define PQ_DLP_APPREAD -1 |
The number of bytes to read from the AppBlock.
Specify negative one for all available bytes.
Definition at line 131 of file pilot-qof.h.
#define PQ_DLP_APPREAD -1 |
The number of bytes to read from the AppBlock.
Specify negative one for all available bytes.
Definition at line 131 of file pilot-qof.h.
#define PQ_DLP_CARD 0 |
The DLP Card Number reference
Definition at line 108 of file pilot-qof.h.
#define PQ_DLP_NEW_REC 0 |
The DLP Record ID - 0 for a new record
Definition at line 117 of file pilot-qof.h.
Referenced by pilot_qof_pack().
#define PQ_DLP_OFFSET 0 |
The DLP Offset
Definition at line 111 of file pilot-qof.h.
#define PQ_DLP_REC_ATTR 0 |
The DLP Record attributes - not currently used.
See dlpRecAttributes in pilot-link, includes/pi-dlp.h
Definition at line 137 of file pilot-qof.h.
Referenced by pilot_qof_pack().
#define PQ_DLP_RECORD 0 |
The DLP Record Index
Definition at line 114 of file pilot-qof.h.
#define PQ_DLP_SET_ID 0 |
The DLP Record ID value, after writing - currently ignored.
Definition at line 120 of file pilot-qof.h.
Referenced by pilot_qof_pack().
#define PQ_MOD_CLI "pilotqof-cli" |
#define PQ_MOD_PILOT "pilotqof-objects" |
default log module for objects
Definition at line 99 of file pilot-qof.h.
#define PQ_MOD_PILOT "pilotqof-objects" |
#define PQ_PREF_USE_BACKUP 1 |
If set, read from backup preferences
(see Palm OS documentation). This flag is ignored on Palm OS 1.x.
Definition at line 149 of file pilot-qof.h.
#define PQ_PREF_USE_SIZE 0 |
Preference read datasize.
If not NULL, on return contains the size of the preference data block.
Definition at line 155 of file pilot-qof.h.
#define PQ_PREF_VERSION 0 |
Preferences version if not NULL.
Definition at line 158 of file pilot-qof.h.
typedef struct PilotPack_s PQPack |
Packing function wrapper.
The pack routines are linked to the QOF object using the qof_pack function pointer and the pilot_pack wrapper. The wrapper also includes the name of the database as held on the Palm.
The e_type must be the same as the e_type of the QofObject, as defined in the object_def definition.
typedef gint(* QofPack)(QofEntity *ent, gpointer user_data) |
Packing function pointer type.
The pack routines are built into the QOF object using the qof_pack function pointer and the pilot_pack wrapper. The same type is used for the free object memory function, free_pack_func.
Definition at line 239 of file pilot-qof.h.
int main | ( | int | argc, | |
const char * | argv[] | |||
) |
Definition at line 827 of file pilot-qof.c.
References QofMain_s::database, ERR_INDENT, QofMain_s::error, QofMain_s::filename, QofMain_s::gz_level, QofMain_s::input_file, QofMain_s::input_session, PQContext_s::invoice_city, PQContext_s::invoice_vendor, PILOT_LINK_SUPPORT, pilot_qof_init(), PILOT_QOF_LOG, PQContext_s::port, PQ_MOD_CLI, PQ_MOD_PILOT, PQContext_s::qof, QOF_CLI_OPTIONS, qof_cmd_explain(), qof_cmd_hotsync(), qof_cmd_list(), qof_cmd_xmlfile(), QOF_MAIN_CLI, qof_main_wrap_line(), qof_mod_category(), qof_mod_convert_deprecated(), qof_mod_database(), qof_mod_encoding(), qof_mod_exclude(), qof_mod_sql(), qof_mod_sql_file(), qof_mod_time(), qof_mod_write(), QOF_OP_INIT, QOF_OP_VARS, and PQContext_s::quiet.
00828 { 00829 const gchar *help_header_text, *input_file, *plu_port; 00830 gint plu_quiet, optc; 00831 PQContext *pilot_qof_context; 00832 gboolean debug_on; 00833 poptContext pc; 00834 gint64 gz_level; 00835 qof_op_type palm_command; 00836 00837 QOF_OP_VARS struct poptOption options[] = { 00838 {"port", 'p', POPT_ARG_STRING, &plu_port, 0, 00839 _("Use the device <port> to communicate with Palm"), 00840 "<port>"}, 00841 { "quiet", 'q', POPT_ARG_NONE, &plu_quiet, 0 , 00842 _("Suppress HotSync connection messages"), NULL}, 00843 {"input-file", 'i', POPT_ARG_STRING, &filename, qof_op_offline, 00844 _("Query the data in <filename>"), _("filename")}, 00845 QOF_CLI_OPTIONS 00846 {"hot-query", 'a', POPT_ARG_NONE, 00847 NULL, qof_op_hotsync, 00848 _("Activate/HotSync and query the Palm."), NULL}, 00849 {"upload", 'u', POPT_ARG_STRING, &input_file, qof_op_upload, 00850 _("Upload data from <filename> to the Palm. Requires -a"), 00851 "filename"}, 00852 {"invoice-vendor", 0, POPT_ARG_NONE, NULL, qof_op_inv_vendor, 00853 _ 00854 ("Shorthand to relate an event or expense to a contact, by vendor. " 00855 "Requires -t."), NULL}, 00856 {"invoice-city", 0, POPT_ARG_NONE, NULL, qof_op_inv_city, 00857 _ 00858 ("Shorthand to relate an event or expense to a contact, by city. " 00859 "Requires -t."), NULL}, 00860 {"use-locale", 0, POPT_ARG_NONE, NULL, qof_op_use_locale, 00861 _ 00862 ("Write XML using the current locale encoding instead of UTF-8."), 00863 NULL}, 00864 POPT_TABLEEND 00865 }; 00866 00867 palm_command = qof_op_noop; 00868 debug_on = FALSE; 00869 QOF_OP_INIT; 00870 input_file = NULL; 00871 plu_quiet = 0; 00872 plu_port = NULL; 00873 00874 #ifdef ENABLE_NLS 00875 setlocale (LC_ALL, ""); 00876 bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); 00877 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); 00878 textdomain (GETTEXT_PACKAGE); 00879 #endif 00880 00881 help_header_text = _("\n" 00882 " Query Palm databases as objects and save to XML.\n" 00883 00884 " pilot-qof provides a query interface to data on a Palm device,\n" 00885 " using pilot-link and QOF - the Query Object Framework.\n\n" 00886 " pilot-qof supports reading addressbook, datebook, expenses and\n" 00887 " ToDo data from a Palm device to XML files. pilot-qof runs SQL-type\n" 00888 " queries on the live data or a QSF XML file and results can be imported\n" 00889 " into other QOF applications or converted to other text based formats,\n" 00890 " including non-XML formats like vcard.\n" 00891 " See http://pilot-qof.sourceforge.net/\n\n" 00892 " Commands are -x -a -l --explain -s or -f.\n" 00893 " Options are -c -t -w, -d or -e.\n" 00894 " option -u requires -a\n\n"); 00895 00896 pc = poptGetContext (PACKAGE, argc, argv, options, 0); 00897 00898 poptSetOtherOptionHelp (pc, help_header_text); 00899 00900 if (argc < 2) 00901 { 00902 poptPrintUsage (pc, stderr, 0); 00903 return EXIT_FAILURE; 00904 } 00905 pilot_qof_context = pilot_qof_init (); 00906 if (!pilot_qof_context) 00907 { 00908 qof_main_wrap_line (stderr, ERR_INDENT, 00909 _("%s: Failed to initialise " 00910 "the query object framework."), PACKAGE); 00911 return EXIT_FAILURE; 00912 } 00913 /* convert deprecated date fields into the newly supported 00914 time values. */ 00915 qof_mod_convert_deprecated (1, &pilot_qof_context->qof); 00916 while ((optc = poptGetNextOpt (pc)) >= 0) 00917 { 00918 switch (optc) 00919 { 00920 /* commands - mutually exclusive */ 00921 case qof_op_offline: 00922 case qof_op_list: 00923 case qof_op_explain: 00924 case qof_op_hotsync: 00925 { 00926 palm_command = optc; 00927 break; 00928 } 00929 case qof_op_sql: 00930 { 00931 qof_mod_sql (sql_query, &pilot_qof_context->qof); 00932 if (!filename) 00933 { 00934 filename = g_strdup (QOF_STDOUT); 00935 } 00936 palm_command = qof_op_empty; 00937 break; 00938 } 00939 case qof_op_sql_file: 00940 { 00941 qof_mod_sql_file (sql_file, &pilot_qof_context->qof); 00942 palm_command = qof_op_empty; 00943 break; 00944 } 00945 case qof_op_vers: 00946 { 00947 fprintf (stdout, _("\n This is %s v%s\n"), PACKAGE, 00948 VERSION); 00949 fprintf (stdout, 00950 _ 00951 (" Query interface for Palm databases as objects.\n")); 00952 fprintf (stdout, 00953 "\n Copyright (c) 2005-2006 " 00954 "Neil Williams <linux@codehelp.co.uk>\n"); 00955 fprintf (stdout, 00956 _(" For %s support, join the QOF-devel " 00957 "mailing list at\n"), PACKAGE); 00958 fprintf (stdout, 00959 " http://lists.sourceforge.net/mailman/listinfo/qof-devel\n\n"); 00960 /* Translators: Add or subtract dots to keep the translated lines aligned vertically */ 00961 fprintf (stdout, _(" Build target............: %s\n"), 00962 HOST_OS); 00963 /* Translators: Add or subtract dots to keep the translated lines aligned vertically */ 00964 fprintf (stdout, _(" Build date..............: %s %s\n"), 00965 __DATE__, __TIME__); 00966 /* Translators: Add or subtract dots to keep the translated lines aligned vertically */ 00967 fprintf (stdout, _(" Built for pilot-link ...: %s\n"), 00968 PILOT_LINK_SUPPORT); 00969 /* Translators: Add or subtract dots to keep the translated lines aligned vertically */ 00970 fprintf (stdout, _(" --debug logs to.........: %s/%s\n\n"), 00971 g_get_tmp_dir (), PILOT_QOF_LOG); 00972 fprintf (stdout, 00973 _ 00974 (" Please use --help for more detailed options.\n\n")); 00975 return EXIT_SUCCESS; 00976 } 00977 /* optional modifiers - store to act on later. */ 00978 case qof_op_category: 00979 { 00980 qof_mod_category (category, &pilot_qof_context->qof); 00981 break; 00982 } 00983 case qof_op_database: 00984 { 00985 qof_mod_database (database, &pilot_qof_context->qof); 00986 break; 00987 } 00988 case qof_op_time: 00989 { 00990 qof_mod_time (date_time, &pilot_qof_context->qof); 00991 break; 00992 } 00993 case qof_op_exclude: 00994 { 00995 qof_mod_exclude (exclude, &pilot_qof_context->qof); 00996 break; 00997 } 00998 case qof_op_write: 00999 { 01000 qof_mod_write (write_file, &pilot_qof_context->qof); 01001 break; 01002 } 01003 case qof_op_upload: 01004 { 01005 if (palm_command != qof_op_hotsync) 01006 { 01007 fprintf (stderr, 01008 _("%s: Error: Please specify -a if you use -u\n"), 01009 PACKAGE); 01010 poptPrintUsage (pc, stderr, 0); 01011 return EXIT_FAILURE; 01012 } 01013 pilot_qof_context->qof.input_file = g_strdup (input_file); 01014 break; 01015 } 01016 case qof_op_debug: 01017 { 01018 gchar *log; 01019 01020 log = 01021 g_strconcat (g_get_tmp_dir (), "/", PILOT_QOF_LOG, 01022 NULL); 01023 qof_log_init_filename (log); 01024 g_free (log); 01025 qof_log_set_default (QOF_LOG_DETAIL); 01026 qof_log_set_level (PQ_MOD_CLI, QOF_LOG_DETAIL); 01027 qof_log_set_level (PQ_MOD_PILOT, QOF_LOG_DETAIL); 01028 qof_log_set_level (QOF_MAIN_CLI, QOF_LOG_DETAIL); 01029 qof_log_set_level (QOF_MOD_QSF, QOF_LOG_DETAIL); 01030 qof_log_set_level ("qof-sqlite-module", QOF_LOG_DETAIL); 01031 debug_on = TRUE; 01033 break; 01034 } 01035 case qof_op_compress: 01036 { 01037 pilot_qof_context->qof.gz_level = gz_level; 01038 break; 01039 } 01040 case qof_op_inv_vendor: 01041 { 01042 if (!pilot_qof_context->invoice_city) 01043 pilot_qof_context->invoice_vendor = TRUE; 01044 break; 01045 } 01046 case qof_op_inv_city: 01047 { 01048 pilot_qof_context->invoice_city = TRUE; 01049 pilot_qof_context->invoice_vendor = FALSE; 01050 break; 01051 } 01052 case qof_op_use_locale: 01053 { 01054 const gchar *locale_encoding; 01055 gboolean test; 01056 locale_encoding = NULL; 01057 test = g_get_charset (&locale_encoding); 01058 if (!test) 01059 qof_mod_encoding (locale_encoding, 01060 &pilot_qof_context->qof); 01061 break; 01062 } 01063 default: 01064 { 01065 fprintf (stderr, _("%s: ERROR: got option %d, arg %s\n"), 01066 PACKAGE, optc, poptGetOptArg (pc)); 01067 return EXIT_FAILURE; 01068 } 01069 } 01070 } 01071 if (qof_op_noop == palm_command) 01072 { 01073 qof_main_wrap_line (stderr, ERR_INDENT, 01074 _("%s: ERROR: specify a command " 01075 "-x, -a, -l, -s or -f, or --explain.\n"), PACKAGE); 01076 poptPrintUsage (pc, stderr, 0); 01077 return EXIT_FAILURE; 01078 } 01079 if (qof_op_noop == palm_command) 01080 { 01081 fprintf (stderr, _("%s: ERROR: specify a command " 01082 "-x, -a, -l, -s or -f, or --explain.\n"), PACKAGE); 01083 poptPrintUsage(pc, stderr, 0); 01084 return EXIT_FAILURE; 01085 } 01086 if (optc < -1) 01087 { 01088 fprintf (stderr, "%s: %s %s\n\n", PACKAGE, 01089 poptBadOption (pc, POPT_BADOPTION_NOALIAS), 01090 poptStrerror (optc)); 01091 poptPrintUsage (pc, stderr, 0); 01092 return EXIT_FAILURE; 01093 } 01094 /* If we get this far, we should have sensible options: start the work. */ 01095 pilot_qof_context->qof.input_session = qof_session_new (); 01096 switch (palm_command) 01097 { 01098 case qof_op_empty: 01099 { 01100 pilot_qof_context->qof.filename = g_strdup (filename); 01101 if ((pilot_qof_context->invoice_city) 01102 || (pilot_qof_context->invoice_vendor)) 01103 { 01104 check_invoice_handler (pilot_qof_context); 01105 if (pilot_qof_context->qof.error) 01106 return EXIT_FAILURE; 01107 pq_invoice_xmlfile (pilot_qof_context); 01108 } 01109 else 01110 qof_cmd_xmlfile (&pilot_qof_context->qof); 01111 break; 01112 } 01113 case qof_op_offline: 01114 { 01115 pilot_qof_context->qof.filename = g_strdup (filename); 01116 if ((pilot_qof_context->invoice_city) 01117 || (pilot_qof_context->invoice_vendor)) 01118 { 01119 check_invoice_handler (pilot_qof_context); 01120 if (pilot_qof_context->qof.error) 01121 return EXIT_FAILURE; 01122 pq_invoice_xmlfile (pilot_qof_context); 01123 } 01124 else 01125 qof_cmd_xmlfile (&pilot_qof_context->qof); 01126 break; 01127 } 01128 case qof_op_list: 01129 { 01130 DEBUG (" list mode"); 01131 qof_cmd_list (); 01132 break; 01133 } 01134 case qof_op_explain: 01135 { 01136 if (!pilot_qof_context->qof.database) 01137 { 01138 qof_main_wrap_line (stderr, ERR_INDENT, 01139 _("%s: Error: please specify which database " 01140 "you would like explained.\n\n"), PACKAGE); 01141 break; 01142 } 01143 DEBUG (" explain mode"); 01144 qof_cmd_explain (&pilot_qof_context->qof); 01145 break; 01146 } 01147 case qof_op_hotsync: 01148 { 01149 DEBUG (" hotsync mode"); 01150 pilot_qof_context->port = g_strdup (plu_port); 01151 pilot_qof_context->quiet = plu_quiet; 01152 qof_cmd_hotsync (pilot_qof_context); 01153 break; 01154 } 01155 case qof_op_noop: 01156 case qof_op_category: 01157 case qof_op_database: 01158 case qof_op_time: 01159 case qof_op_exclude: 01160 case qof_op_sql: 01161 case qof_op_sql_file: 01162 case qof_op_write: 01163 case qof_op_upload: 01164 case qof_op_vers: 01165 case qof_op_compress: 01166 case qof_op_debug: 01167 case qof_op_inv_city: 01168 case qof_op_inv_vendor: 01169 case qof_op_use_locale: 01170 default: 01171 break; 01172 } 01173 poptFreeContext (pc); 01174 pilot_qof_free (pilot_qof_context); 01175 if (debug_on) 01176 qof_log_shutdown (); 01177 qof_close (); 01178 return EXIT_SUCCESS; 01179 }
void pilot_app_unpack | ( | QofIdTypeConst | e_type, | |
gpointer | user_data | |||
) |
Unpack the database information.
The Palm uses a separate structure for information about the current database, including the list of available categories.
This is a per-database structure, not per record. The records only contain an integer - the value of the category in the index of the CategoryAppInfo. QOF converts this into a string value for the category name for portability.
It does not call any qof_pack routines as there is no QofEntity at this stage.
e_type | - determines the type of application information to unpack from the pilot_pack wrapper. | |
user_data | - gpointer to the pqd context. |
Definition at line 344 of file pilot-qof.c.
References PilotPack_s::app_info_unpack, QofMain_s::error, pilot_qof_pack_lookup(), and PQContext_s::qof.
00345 { 00346 PQContext *context; 00347 QofPack app_unpack; 00348 const PQPack *p; 00349 00350 context = (PQContext *) user_data; 00351 g_return_if_fail (context != NULL); 00352 p = pilot_qof_pack_lookup (e_type); 00353 if (!p) 00354 return; 00355 app_unpack = p->app_info_unpack; 00356 if (app_unpack == NULL) 00357 { 00358 context->qof.error = TRUE; 00359 PERR (" no app_info_unpack routine for %s", e_type); 00360 return; 00361 } 00362 /* no entity available for the appInfo, pass NULL and work only in the context. */ 00363 app_unpack (NULL, context); 00364 }
void pilot_entity_finaliser | ( | QofBook * | book, | |
gpointer | key, | |||
gpointer | data | |||
) |
Free the wrapped object.
Set the pointer to the free function for the object within this entity. The function itself is called automatically by QOF when the QofBook is being closed.
Definition at line 389 of file pilot-qof.c.
PQContext * pilot_qof_init | ( | void | ) |
Register all QOF objects.
If new objects are added, call the register func() here. Ensure you have the pack routines for your object.
Follow the template of other objects to create your own callbacks.
pilot_qof_init must be called by any program wanting to use the QOF framework with pilot-link objects.
Definition at line 114 of file pilot-qof.c.
References AddressRegister(), DateBookRegister(), and PQExpensesRegister().
Referenced by main().
00115 { 00116 qof_init (); 00117 g_return_val_if_fail (AddressRegister (), NULL); 00120 #ifdef HAVE_QOFEXPENSES 00121 g_return_val_if_fail (ExpensesRegister (), NULL); 00122 #endif 00123 g_return_val_if_fail (PQExpensesRegister (), NULL); 00124 g_return_val_if_fail (DateBookRegister (), NULL); 00125 g_return_val_if_fail (ToDoRegister (), NULL); 00126 g_return_val_if_fail (packing_registration(), NULL); 00127 return pilot_qof_create (); 00128 }
void pilot_qof_pack | ( | QofEntity * | ent, | |
gpointer | user_data | |||
) |
Pack this object.
Retrieve the pointer to the pack function for the object within this entity. Entity objects are packed prior to being written to a Palm database. Although upload is available for new records, merge and sync are not yet implemented in the pilot-qof Although upload is available for new records, merge and sync are not yet implemented in the pilot-qof application. Functionality to merge two QofBooks to handle the merge and sync does exist in QOF.
Definition at line 271 of file pilot-qof.c.
References CATEGORY_NAME, PQContext_s::db, PQContext_s::ent_category, QofMain_s::error, PilotPack_s::pack_func, PQContext_s::pi_buf, pilot_qof_pack_lookup(), PQ_DEF_BUFSZ, PQ_DLP_NEW_REC, PQ_DLP_REC_ATTR, PQ_DLP_SET_ID, PQContext_s::qof, and PQContext_s::sd.
00272 { 00273 const gchar *category_name; 00274 const QofParam *param; 00275 gint size, result; 00276 QofPack pack_func; 00277 PQContext *context; 00278 const PQPack *p; 00279 00280 context = (PQContext *) user_data; 00281 size = result = 0; 00282 g_return_if_fail (context != NULL); 00283 p = pilot_qof_pack_lookup (ent->e_type); 00284 if (!p) 00285 return; 00286 context->pi_buf = pi_buffer_new (PQ_DEF_BUFSZ); 00287 pack_func = p->pack_func; 00288 if (pack_func == NULL) 00289 { 00290 context->qof.error = TRUE; 00291 return; 00292 } 00293 size = pack_func (ent, context); 00294 if (size == -1) 00295 return; 00296 param = qof_class_get_parameter (ent->e_type, CATEGORY_NAME); 00297 category_name = (const gchar *) param->param_getfcn (ent, param); 00298 context->ent_category = pq_findcategory(context, 00299 category_name, PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED); 00300 /* context->ent_category = plu_findcategory (context->pi_cat, 00301 category_name, PLU_CAT_CASE_INSENSITIVE | PLU_CAT_DEFAULT_UNFILED);*/ 00302 if (context->ent_category == 0) 00303 PWARN (" Category: '%s' not found or not set, using 'Unfiled'", 00304 category_name); 00305 result = dlp_WriteRecord (context->sd, context->db, 00306 PQ_DLP_REC_ATTR, PQ_DLP_NEW_REC, context->ent_category, 00307 context->pi_buf->data, size, PQ_DLP_SET_ID); 00308 if (result < 0) 00309 { 00310 PERR (" record could not be written: error %d", result); 00311 return; 00312 } 00313 }
const PQPack * pilot_qof_pack_lookup | ( | QofIdTypeConst | object_type | ) |
provide for looking up an object
Returns the pilot_pack that matches this object type. Uses the same object type as the QofObject->e_type.
Definition at line 405 of file pilot-qof.c.
References PilotPack_s::e_type, and pilot_modules.
Referenced by pilot_app_unpack(), pilot_qof_pack(), and pilot_qof_unpack().
00406 { 00407 GList *piter; 00408 PQPack *p; 00409 00410 if (!object_type) 00411 return NULL; 00412 for (piter = pilot_modules; piter; piter = piter->next) 00413 { 00414 p = piter->data; 00415 if (0 == safe_strcmp (p->e_type, object_type)) 00416 return p; 00417 } 00418 return NULL; 00419 }
gboolean pilot_qof_pack_register | ( | const PQPack * | p | ) |
Shamelessly copied from QOF.
Pilot-link requires a few functions to pack and unpack the database records prior to / post HotSync. These are specific to each object and to allow new objects to be added easily, need to be referenced generically.
pilot-qof implements a mini-QofObject alongside QOF that just contains this pilot-link data.
Definition at line 395 of file pilot-qof.c.
References pilot_modules.
00396 { 00397 if (g_list_index (pilot_modules, (gpointer) p) == -1) 00398 pilot_modules = g_list_prepend (pilot_modules, (gpointer) p); 00399 else 00400 return FALSE; 00401 return TRUE; 00402 }
void pilot_qof_unpack | ( | QofEntity * | ent, | |
gpointer | user_data | |||
) |
Unpack this object.
Retrieve the pointer to the unpack function for this entity and the object it contains. Entities are unpacked after being read from the Palm during a HotSync. The unpack routine populates the object with the Palm data in a usable form. The QOF framework then accesses this data through QOF wrappers.
Definition at line 316 of file pilot-qof.c.
References QofMain_s::error, pilot_qof_pack_lookup(), PQContext_s::qof, and PilotPack_s::unpack_func.
00317 { 00318 QofPack unpack_func; 00319 const PQPack *p; 00320 PQContext *context; 00321 gint result; 00322 00323 context = (PQContext *) user_data; 00324 g_return_if_fail (context && ent); 00325 p = pilot_qof_pack_lookup (ent->e_type); 00326 g_return_if_fail (p); 00327 unpack_func = p->unpack_func; 00328 if (unpack_func == NULL) 00329 { 00330 context->qof.error = TRUE; 00331 PERR ("No unpack routine was defined for the %s object!", 00332 ent->e_type); 00333 return; 00334 } 00335 result = unpack_func (ent, context); 00336 if (result < 0) 00337 { 00338 qof_entity_release (ent); 00339 g_free (ent); 00340 } 00341 }
void qof_cmd_hotsync | ( | PQContext * | context | ) |
Activate/HotSync and query the Palm, ignoring the offline storage.
Connects the the Palm and queries the live database. If -d or -e are not used, query all supported databases in one HotSync operation.
Definition at line 695 of file pilot-qof.c.
References QofMain_s::database, ERR_INDENT, QofMain_s::error, QofMain_s::exclude, QofMain_s::export_session, QofMain_s::gz_level, QofMain_s::input_file, QofMain_s::input_session, PQContext_s::invoice_city, PQContext_s::invoice_vendor, PQContext_s::port, PQContext_s::qof, qof_main_moderate_query(), qof_main_show_error(), qof_main_wrap_line(), qof_mod_compression(), QofMain_s::query, PQContext_s::quiet, PQContext_s::sd, and QofMain_s::write_file.
Referenced by main().
00696 { 00697 struct PilotUser QUser; 00698 QofBook *book; 00699 gchar *log_msg; 00700 00701 if (0 == safe_strcmp (context->qof.exclude, context->qof.database) 00702 && (context->qof.exclude != NULL)) 00703 { 00704 /* Translators: The first string is the package name. 00705 The second and third are database names. */ 00706 qof_main_wrap_line (stderr, ERR_INDENT, 00707 _("%s: Error: Cannot exclude " 00708 "database \"%s\" with option -e because option -d is set to the " 00709 "same database: \"%s\""), PACKAGE, context->qof.exclude, 00710 context->qof.database); 00711 qof_session_end (context->qof.input_session); 00712 return; 00713 } 00714 if ((context->invoice_city) || (context->invoice_vendor)) 00715 check_invoice_handler (context); 00716 if (context->qof.error) 00717 return; 00718 if (context->qof.input_file) 00719 { 00720 PINFO (" Trying to upload %s", context->qof.input_file); 00721 qof_session_begin (context->qof.input_session, 00722 context->qof.input_file, TRUE, FALSE); 00723 qof_session_load (context->qof.input_session, NULL); 00724 } 00725 else 00726 qof_session_begin (context->qof.input_session, QOF_STDOUT, TRUE, 00727 FALSE); 00728 context->qof.export_session = qof_session_new (); 00729 00730 context->sd = plu_connect (context->port, context->quiet); 00731 00732 if (context->sd < 0) 00733 { 00734 pilot_error (context, _("Unable to connect to the Palm")); 00735 return; 00736 } 00737 if (dlp_ReadUserInfo (context->sd, &QUser) < 0) 00738 { 00739 pilot_error (context, _("Unable to read Palm user info")); 00740 return; 00741 } 00742 context->qof.error = FALSE; 00743 qof_object_foreach_type (pilot_database_open, context); 00744 QUser.lastSyncPC = 0x00010000; 00745 QUser.lastSyncDate = QUser.successfulSyncDate = time (0); 00746 if (dlp_WriteUserInfo (context->sd, &QUser) < 0) 00747 { 00748 pilot_error (context, _("Unable to write user info")); 00749 return; 00750 } 00751 /* Translators: each string is the package name. */ 00752 log_msg = g_strdup_printf (_("%s hotsync\n\n" 00753 "Thank you for using %s.\n"), PACKAGE, PACKAGE); 00754 dlp_AddSyncLogEntry (context->sd, log_msg); 00755 g_free (log_msg); 00756 dlp_EndOfSync (context->sd, 0); 00757 pi_close (context->sd); 00758 /* Now run the query, copy the objects, destroy the input session */ 00759 /*and write out export_session */ 00760 if (context->qof.write_file) 00761 { 00762 qof_session_begin (context->qof.export_session, 00763 context->qof.write_file, TRUE, TRUE); 00764 qof_mod_compression (context->qof.gz_level, &context->qof); 00765 } 00766 else 00767 qof_session_begin (context->qof.export_session, QOF_STDOUT, TRUE, 00768 FALSE); 00769 /* Note if no query is given, ignore repeater clones? 00770 Nice idea, but in practice, difficult. It also makes recursive 00771 queries of the XML harder as the XML needs to understand datebook 00772 repeats. Instead, we simply ignore all repeater clones when it comes 00773 to write data to the Palm by a simple check in datebook_pack. 00774 */ 00775 qof_main_moderate_query (&context->qof); 00776 /* if invoice_hook, create a second query and lookup in contacts */ 00777 if ((context->invoice_city) || (context->invoice_vendor)) 00778 { 00779 book = qof_session_get_book (context->qof.export_session); 00780 context->qof.query = qof_query_create_for (PILOT_LINK_QOF_ADDRESS); 00781 qof_object_foreach (PILOT_LINK_QOF_DATEBOOK, book, 00782 find_invoice_contact, context); 00783 qof_object_foreach (PILOT_LINK_QOF_EXPENSES, book, 00784 find_invoice_contact, context); 00785 } 00786 qof_session_save (context->qof.export_session, NULL); 00787 qof_main_show_error (context->qof.export_session); 00788 qof_session_end (context->qof.input_session); 00789 qof_session_end (context->qof.export_session); 00790 }
QofLogModule log_module = "pilotqof-cli" [static] |
used to print debug logs.
Definition at line 64 of file pilot-qof.c.
GList* pilot_modules = NULL [static] |
pack routines for communication with pilot
Definition at line 66 of file pilot-qof.c.
Referenced by pilot_qof_pack_lookup(), and pilot_qof_pack_register().