"Fossies" - the Fresh Open Source Software Archive

Member "jpilot-2_0_1/libplugin.h" (3 Apr 2021, 11324 Bytes) of package /linux/privat/jpilot-2_0_1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*******************************************************************************
    2  * libplugin.h
    3  * A module of J-Pilot http://jpilot.org
    4  *
    5  * Copyright (C) 1999-2014 by Judd Montgomery
    6  *
    7  * This program is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; version 2 of the License.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19  ******************************************************************************/
   20 
   21 #ifndef __LIBPLUGIN_H__
   22 #define __LIBPLUGIN_H__
   23 
   24 #include "config.h"
   25 #include <gtk/gtk.h>
   26 #include <time.h>
   27 #include <pi-appinfo.h>
   28 #include "log.h"
   29 
   30 /*
   31  * PLUGIN API for J-Pilot
   32  */
   33 
   34 #ifdef ENABLE_PROMETHEON
   35 #define PN "CoPilot"
   36 #else
   37 #define PN "J-Pilot"
   38 #endif
   39 
   40 #ifdef ENABLE_PROMETHEON
   41 #define EPN "copilot"
   42 #else
   43 #define EPN "jpilot"
   44 #endif
   45 
   46 /*
   47  * For versioning of files
   48  */
   49 #define FILE_VERSION     "version"
   50 #define FILE_VERSION2    "version2"
   51 #define FILE_VERSION2_CR "version2\n"
   52 
   53 
   54 typedef struct {
   55    unsigned char Offset[4];  /*4 bytes offset from BOF to record */
   56    unsigned char attrib;
   57    unsigned char unique_ID[3];
   58 } record_header;
   59 
   60 typedef struct {
   61    unsigned long header_len;
   62    unsigned long header_version;
   63    unsigned long rec_len;
   64    unsigned long unique_id;
   65    unsigned long rt; /* Record Type */
   66    unsigned char attrib;
   67 } PC3RecordHeader;
   68 
   69 typedef struct mem_rec_header_s {
   70    unsigned int rec_num;
   71    unsigned int offset;
   72    unsigned int unique_id;
   73    unsigned char attrib;
   74    struct mem_rec_header_s *next;
   75 } mem_rec_header;
   76 
   77 typedef struct {
   78             char db_name[32];
   79    unsigned char flags[2];
   80    unsigned char version[2];
   81    unsigned char creation_time[4];
   82    unsigned char modification_time[4];
   83    unsigned char backup_time[4];
   84    unsigned char modification_number[4];
   85    unsigned char app_info_offset[4];
   86    unsigned char sort_info_offset[4];
   87             char type[4]; /* Database ID */
   88             char creator_id[4]; /* Application ID */
   89             char unique_id_seed[4];
   90    unsigned char next_record_list_id[4];
   91    unsigned char number_of_records[2];
   92 } RawDBHeader;
   93 
   94 #define LEN_RAW_DB_HEADER 78
   95 
   96 typedef struct {
   97    char db_name[32];
   98    unsigned int flags;
   99    unsigned int version;
  100    time_t creation_time;
  101    time_t modification_time;
  102    time_t backup_time;
  103    unsigned int modification_number;
  104    unsigned int app_info_offset;
  105    unsigned int sort_info_offset;
  106    char type[5];/*Database ID */
  107    char creator_id[5];/*Application ID */
  108    char unique_id_seed[5];
  109    unsigned int next_record_list_id;
  110    unsigned int number_of_records;
  111 } DBHeader;
  112 
  113 int get_next_unique_pc_id(unsigned int *next_unique_id);
  114 
  115 /* used for jp_delete_record */
  116 #define CLEAR_FLAG    1
  117 #define CANCEL_FLAG   2
  118 #define DELETE_FLAG   3
  119 #define MODIFY_FLAG   4
  120 #define NEW_FLAG      5
  121 #define COPY_FLAG     6
  122 #define UNDELETE_FLAG 7
  123 
  124 #define LIST_DEL_RED 204
  125 #define LIST_DEL_GREEN 204
  126 #define LIST_DEL_BLUE 204
  127 #define LIST_NEW_RED 214
  128 #define LIST_NEW_GREEN 214
  129 #define LIST_NEW_BLUE 255
  130 #define LIST_MOD_RED 214
  131 #define LIST_MOD_GREEN 255
  132 #define LIST_MOD_BLUE 255
  133 #define LIST_PRIVATE_RED 234
  134 #define LIST_PRIVATE_GREEN 214
  135 #define LIST_PRIVATE_BLUE 214
  136 #define LIST_OVERDUE_RED 217
  137 #define LIST_OVERDUE_GREEN 0
  138 #define LIST_OVERDUE_BLUE 0
  139 #define LIST_DUENOW_RED 17
  140 #define LIST_DUENOW_GREEN 159
  141 #define LIST_DUENOW_BLUE 138
  142 
  143 #define DIALOG_SAID_1        454
  144 #define DIALOG_SAID_PRINT    454
  145 #define DIALOG_SAID_FOURTH   454
  146 #define DIALOG_SAID_2        455
  147 #define DIALOG_SAID_LAST     455
  148 #define DIALOG_SAID_3        456
  149 #define DIALOG_SAID_CANCEL   456
  150 #define DIALOG_SAID_4        457
  151 
  152 #define JP_LOG_DEBUG  1    /*debugging info for programmers, and bug reports */
  153 #define JP_LOG_INFO   2    /*info, and misc messages */
  154 #define JP_LOG_WARN   4    /*worse messages */
  155 #define JP_LOG_FATAL  8    /*even worse messages */
  156 #define JP_LOG_STDOUT 256  /*messages always go to stdout */
  157 #define JP_LOG_FILE   512  /*messages always go to the log file */
  158 #define JP_LOG_GUI    1024 /*messages always go to the gui window */
  159 
  160 #define JPILOT_EOF -7
  161 
  162 /* This bit means that this record is of no importance anymore */
  163 #define SPENT_PC_RECORD_BIT 256
  164 
  165 typedef enum {
  166    PALM_REC = 100L,
  167    MODIFIED_PALM_REC = 101L,
  168    DELETED_PALM_REC = 102L,
  169    NEW_PC_REC = 103L,
  170    DELETED_PC_REC =  SPENT_PC_RECORD_BIT | 104L,
  171    DELETED_DELETED_PALM_REC =  SPENT_PC_RECORD_BIT | 105L,
  172    REPLACEMENT_PALM_REC = 106L
  173 } PCRecType;
  174 
  175 typedef struct
  176 {
  177    PCRecType rt;
  178    unsigned int unique_id;
  179    unsigned char attrib;
  180    void *buf;
  181    int size;
  182 } buf_rec;
  183 
  184 typedef struct
  185 {
  186    char *base_dir;
  187    int *major_version;
  188    int *minor_version;
  189 } jp_startup_info;
  190 
  191 struct search_result
  192 {
  193    char *line;
  194    unsigned int unique_id;
  195    struct search_result *next;
  196 };
  197 
  198 
  199 void plugin_version(int *major_version, int *minor_version);
  200 int plugin_get_name(char *name, int len);
  201 int plugin_get_menu_name(char *name, int len);
  202 int plugin_get_help_name(char *name, int len);
  203 int plugin_get_db_name(char *db_name, int len);
  204 int plugin_startup(jp_startup_info *info);
  205 int plugin_gui(GtkWidget *vbox, GtkWidget *hbox, unsigned int unique_id);
  206 int plugin_help(char **text, int *width, int *height);
  207 int plugin_print(void);
  208 int plugin_import(GtkWidget *window);
  209 int plugin_export(GtkWidget *window);
  210 int plugin_gui_cleanup(void);
  211 int plugin_pre_sync_pre_connect(void);
  212 int plugin_pre_sync(void);
  213 int plugin_sync(int sd);
  214 int plugin_search(const char *search_string, int case_sense, struct search_result **sr);
  215 int plugin_post_sync(void);
  216 int plugin_exit_cleanup(void);
  217 int plugin_unpack_cai_from_ai(struct CategoryAppInfo *cai,
  218                               unsigned char *ai_raw, int len);
  219 int plugin_pack_cai_into_ai(struct CategoryAppInfo *cai,
  220                             unsigned char *ai_raw, int len);
  221 /* callbacks are needed for print */
  222 
  223 void jp_init(void);
  224 
  225 /* This takes the value of $JPILOT_HOME and appends /.jpilot/ and {file}
  226  * onto it and puts it into full_name.  max_size is the size if the
  227  * supplied buffer full_name
  228  */
  229 int jp_get_home_file_name(const char *file, char *full_name, int max_size);
  230 
  231 /*
  232  * DB_name should be without filename ext, e.g. MemoDB
  233  * bufp is the packed app info block
  234  * size_in is the size of bufp
  235  */
  236 int jp_pdb_file_write_app_block(const char *DB_name, void *bufp, int size_in);
  237 
  238 /*
  239  * widget is a widget inside the main window used to get main window handle
  240  * db_name should be without filename ext, e.g. MemoDB
  241  * cai is the category app info.  This should be unpacked by the user since
  242  * category unpack functions are database specific.
  243  */
  244 int jp_edit_cats(GtkWidget *widget, char *db_name, struct CategoryAppInfo *cai);
  245 
  246 /* file must not be open elsewhere when this is called, the first line is 0 */
  247 int jp_install_remove_line(int deleted_line);
  248 
  249 int jp_install_append_line(char *line);
  250 
  251 /*
  252  * Get the application info block
  253  */
  254 int jp_get_app_info(const char *DB_name, unsigned char **buf, int *buf_size);
  255 /*
  256  * Read a pdb file out of the $(JPILOT_HOME || HOME)/.jpilot/ directory
  257  * It also reads the PC file
  258  */
  259 int jp_read_DB_files(const char *DB_name, GList **records);
  260 
  261 /*
  262  *This deletes a record from the appropriate Datafile
  263  */
  264 int jp_delete_record(const char *DB_name, buf_rec *br, int flag);
  265 /*
  266  *This undeletes a record from the appropriate Datafile
  267  */
  268 int jp_undelete_record(const char *DB_name, buf_rec *br, int flag);
  269 /*
  270  * Free the record list
  271  */
  272 int jp_free_DB_records(GList **records);
  273 
  274 int jp_pc_write(const char *DB_name, buf_rec *br);
  275 
  276 const char *jp_strstr(const char *haystack, const char *needle, int case_sense);
  277 
  278 int pc_read_next_rec(FILE *in, buf_rec *br);
  279 
  280 int read_header(FILE *pc_in, PC3RecordHeader *header);
  281 
  282 int write_header(FILE *pc_out, PC3RecordHeader *header);
  283 
  284 /*
  285  * These 2 functions don't take full path names.
  286  * They are relative to $JPILOT_HOME/.jpilot/
  287  */
  288 int rename_file(char *old_filename, char *new_filename);
  289 int unlink_file(char *filename);
  290 
  291 /* */
  292 /*Warning, this function will move the file pointer */
  293 /* */
  294 int get_app_info_size(FILE *in, int *size);
  295 
  296 /* mon 0-11
  297  * day 1-31
  298  * year (year - 1900)
  299  * This function will bring up the cal at mon, day, year
  300  * After a new date is selected it will return mon, day, year
  301  */
  302 int jp_cal_dialog(GtkWindow *main_window,
  303                   const char *title, int monday_is_fdow,
  304                   int *mon, int *day, int *year);
  305 
  306 /*
  307  * The preferences interface makes it easy to read and write name/value pairs
  308  * to a file.  Also access them efficiently.
  309  */
  310 
  311 #define INTTYPE 1
  312 #define CHARTYPE 2
  313 
  314 /* I explain these below */
  315 typedef struct {
  316    const char *name;
  317    int usertype;
  318    int filetype;
  319    long ivalue;
  320    char *svalue;
  321    int svalue_size;
  322 } prefType;
  323 
  324 /* char *name; */
  325 /*   The name of the preference, will be written to column 1 of the rc file
  326  *   This needs to be set before reading the rc file.
  327  */
  328 /* int usertype; */
  329 /*   INTTYPE or CHARTYPE, this is the type of value that the pref is.
  330  *   This type of value will be returned and set by pref calls.
  331  */
  332 /* int filetype; */
  333 /*   INTTYPE or CHARTYPE, this is the type of value that the pref is when
  334  *   it is read from, or written to a file.
  335  *   i.e., For some of my menus I have file type of int and usertype
  336  *   of char.  I want to use char, except I don't store the char because
  337  *   of translations, so I store 3 for the 3rd option.  It also allows
  338  *   predefined allowed values for strings instead of anything goes. */
  339 /* long ivalue; */
  340 /*   The long value to be returned if of type INT
  341  */
  342 /* char *svalue; */
  343 /*   The long value to be returned if of type CHAR
  344  */
  345 /* int svalue_size; */
  346 /*   The size of the memory allocated for the string, Do not change. */
  347 
  348 /*
  349  * To use prefs you must allocate an array of prefType and call this function
  350  * before any others.
  351  *  count is how many preferences in the array.
  352  */
  353 void jp_pref_init(prefType prefs[], int count);
  354 /*
  355  * This function can be called to free strings allocated by preferences.
  356  * It should be called in the cleanup routine.
  357  */
  358 void jp_free_prefs(prefType prefs[], int count);
  359 /*
  360  * This function retrieves a long value and a pointer to a string of a
  361  * preference structure.  *string can be passed in as a NULL and NULL can
  362  * be returned if the preference is of type INT.
  363  */
  364 int jp_get_pref(prefType prefs[], int which, long *n, const char **string);
  365 /*
  366  * This function sets a long value and a string of a preference structure.
  367  *  string can be NULL if the preference is type INT.
  368  *  string can be any length, memory will be allocated.
  369  */
  370 int jp_set_pref(prefType prefs[], int which, long n, const char *string);
  371 /*
  372  * This function reads an rc file and sets the preferences from it.
  373  */
  374 int jp_pref_read_rc_file(char *filename, prefType prefs[], int num_prefs);
  375 /*
  376  * This function writes preferences to an rc file.
  377  */
  378 int jp_pref_write_rc_file(char *filename, prefType prefs[], int num_prefs);
  379 #endif