"Fossies" - the Fresh Open Source Software Archive

Member "jpilot-2_0_1/utils.h" (3 Apr 2021, 18259 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. For more information about "utils.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.8.2_vs_2_0_1.

    1 /*******************************************************************************
    2  * utils.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 __UTILS_H__
   22 #define __UTILS_H__
   23 
   24 #include <time.h>
   25 #include <stdio.h>
   26 #include <unistd.h>
   27 #include <sys/types.h>
   28 #include <gtk/gtk.h>
   29 
   30 #include <pi-datebook.h>
   31 #include <pi-address.h>
   32 #include <pi-todo.h>
   33 #include <pi-memo.h>
   34 #include <pi-file.h>
   35 #include <pi-calendar.h>
   36 #include "jp-pi-contact.h"
   37 
   38 #include "libplugin.h"
   39 #include "japanese.h"
   40 #include "cp1250.h"
   41 #include "russian.h"
   42 
   43 #define PRINT_FILE_LINE printf("%s line %d\n", __FILE__, __LINE__)
   44 
   45 #ifdef ENABLE_PROMETHEON
   46 #  define PN "CoPilot"
   47 #  define EPN "copilot"
   48 #else
   49 #  define PN "J-Pilot"
   50 #  define EPN "jpilot"
   51 #endif
   52 
   53 /* PRODID string for ical export */
   54 #define FPI_STRING "-//Judd Montgomery//NONSGML "PN" "VERSION"//EN"
   55 
   56 /* This is how often the clock updates in milliseconds */
   57 #define CLOCK_TICK 1000
   58 
   59 /* How treeView widget should appear for main apps */
   60 #define SHADOW GTK_SHADOW_ETCHED_OUT
   61 
   62 /*  Define the maximum length of a category name
   63  *  when expressed in Pilot character set (assuming 15
   64  *  character plus a delimiter) or in host character
   65  *  set (might be 50 or more if UTF-8).
   66  *  Note : host length is temporarily kept as 16 until all
   67  *  consequences are identified.  In the meantime category
   68  *  names may be (hopefully safely) truncated.  */
   69 
   70 #define NUM_CATEGORIES 16 
   71 #define HOSTCAT_NAME_SZ 16
   72 #define PILOTCAT_NAME_SZ 16
   73 
   74 /* Constant used by J-Pilot to indicate "All" category */
   75 #define CATEGORY_ALL 300
   76 #define CATEGORY_EDIT 301
   77 
   78 /* Used to mark the entry in the treeView to add a record */
   79 #define LIST_NEW_ENTRY_DATA 100
   80 #define LIST_ADDING_ENTRY_DATA 101
   81 #define LIST_MIN_DATA 199
   82 
   83 #define DIALOG_SAID_1           454
   84 #define DIALOG_SAID_PRINT       454
   85 #define DIALOG_SAID_FOURTH      454
   86 #define DIALOG_SAID_2           455
   87 #define DIALOG_SAID_LAST        455
   88 #define DIALOG_SAID_3           456
   89 #define DIALOG_SAID_CANCEL      456
   90 #define DIALOG_SAID_4           457
   91 
   92 /* Repeat event dialog */
   93 #define DIALOG_SAID_RPT_CURRENT 454
   94 #define DIALOG_SAID_RPT_FUTURE  455
   95 #define DIALOG_SAID_RPT_ALL     456
   96 #define DIALOG_SAID_RPT_CANCEL  457
   97 
   98 /* Import dialog */
   99 #define DIALOG_SAID_IMPORT_YES  455
  100 #define DIALOG_SAID_IMPORT_ALL  456
  101 #define DIALOG_SAID_IMPORT_SKIP 457
  102 #define DIALOG_SAID_IMPORT_QUIT 458
  103 
  104 #define DIALOG_INFO     1
  105 #define DIALOG_QUESTION 2
  106 #define DIALOG_ERROR    3
  107 #define DIALOG_WARNING  4
  108 
  109 #define CAL_DONE   100
  110 #define CAL_CANCEL 101
  111 
  112 #define PIXMAP_NOTE          100
  113 #define PIXMAP_ALARM         101
  114 #define PIXMAP_BOX_CHECK     102
  115 #define PIXMAP_BOX_CHECKED   103
  116 #define PIXMAP_FLOAT_CHECK   104
  117 #define PIXMAP_FLOAT_CHECKED 105
  118 #define PIXMAP_SDCARD        106
  119 
  120 #define SORT_ASCENDING       100
  121 #define SORT_DESCENDING      101
  122 
  123 /* Import defines */
  124 #define MAX_IMPORT_TYPES     10 /* Must be more than the following types */
  125 #define IMPORT_TYPE_UNKNOWN  99
  126 #define IMPORT_TYPE_TEXT    100
  127 #define IMPORT_TYPE_DAT     101
  128 #define IMPORT_TYPE_CSV     102
  129 #define IMPORT_TYPE_XML     103
  130 
  131 /* Export defines */
  132 #define EXPORT_TYPE_UNKNOWN      99
  133 #define EXPORT_TYPE_TEXT        100
  134 #define EXPORT_TYPE_DAT         101
  135 #define EXPORT_TYPE_CSV         102
  136 #define EXPORT_TYPE_XML         103
  137 #define EXPORT_TYPE_VCARD       104
  138 #define EXPORT_TYPE_VCARD_GMAIL 105
  139 #define EXPORT_TYPE_ICALENDAR   106
  140 #define EXPORT_TYPE_LDIF        107
  141 #define EXPORT_TYPE_BFOLDERS    108
  142 #define EXPORT_TYPE_KEEPASSX    109
  143 
  144 /* DAT file types */
  145 #define DAT_DATEBOOK_FILE    10
  146 #define DAT_ADDRESS_FILE     11
  147 #define DAT_TODO_FILE        12
  148 #define DAT_MEMO_FILE        13
  149 
  150 /* Pilot-link 0.12 is broken and missing pi_uid_t */
  151 typedef recordid_t pi_uid_t;
  152 
  153 /* Unique ID used to locate a record, say after a search or GUI update */
  154 extern unsigned int glob_find_id;
  155 
  156 typedef enum {
  157    DATEBOOK = 100L,
  158    ADDRESS,
  159    TODO,
  160    MEMO,
  161    CALENDAR,
  162    CONTACTS,
  163    TASKS,
  164    MEMOS,
  165    REDRAW
  166 } AppType;
  167 
  168 typedef struct {
  169    PCRecType rt;
  170    unsigned int unique_id;
  171    unsigned char attrib;
  172    struct Appointment appt;
  173 } MyAppointment;
  174 
  175 typedef struct AppointmentList_s {
  176    AppType app_type;
  177    struct AppointmentList_s *next;
  178    MyAppointment mappt;
  179 } AppointmentList;
  180 
  181 typedef struct {
  182    PCRecType rt;
  183    unsigned int unique_id;
  184    unsigned char attrib;
  185    struct Address addr;
  186 } MyAddress;
  187 
  188 typedef struct AddressList_s {
  189    AppType app_type;
  190    struct AddressList_s *next;
  191    MyAddress maddr;
  192 } AddressList;
  193 
  194 typedef struct {
  195    PCRecType rt;
  196    unsigned int unique_id;
  197    unsigned char attrib;
  198    struct ToDo todo;
  199 } MyToDo;
  200 
  201 typedef struct ToDoList_s {
  202    AppType app_type;
  203    struct ToDoList_s *next;
  204    MyToDo mtodo;
  205 } ToDoList;
  206 
  207 typedef struct {
  208    PCRecType rt;
  209    unsigned int unique_id;
  210    unsigned char attrib;
  211    struct Memo memo;
  212 } MyMemo;
  213 
  214 typedef struct MemoList_s {
  215    AppType app_type;
  216    struct MemoList_s *next;
  217    MyMemo mmemo;
  218 } MemoList;
  219 
  220 /* New OS PIM applications in OS 5.x */
  221 
  222 /* Contacts */
  223 typedef struct {
  224    PCRecType rt;
  225    unsigned int unique_id;
  226    unsigned char attrib;
  227    struct Contact cont;
  228 } MyContact;
  229 
  230 typedef struct ContactList_s {
  231    AppType app_type;
  232    struct ContactList_s *next;
  233    MyContact mcont;
  234 } ContactList;
  235 
  236 /* Calendar */
  237 typedef struct {
  238    PCRecType rt;
  239    unsigned int unique_id;
  240    unsigned char attrib;
  241    struct CalendarEvent cale;
  242 } MyCalendarEvent;
  243 
  244 typedef struct CalendarEventList_s {
  245    AppType app_type;
  246    struct CalendarEventList_s *next;
  247    MyCalendarEvent mcale;
  248 } CalendarEventList;
  249 
  250 
  251 struct search_record
  252 {
  253    AppType app_type;
  254    int plugin_flag;
  255    unsigned int unique_id;
  256    struct search_record *next;
  257 };
  258 
  259 struct sorted_cats
  260 {
  261    char Pcat[32];
  262    int cat_num;
  263 };
  264 typedef struct {
  265     int found;
  266     char* textToSearch;
  267 } RestoreDataSearchElement;
  268 
  269 struct name_list {
  270     char *name;
  271     struct name_list *next;
  272 };
  273 
  274 
  275 /* utils.c: The subroutines below are all from utils.c */
  276 
  277 /* Takes an array of database names and changes the names
  278  * to the new PIM names */
  279 void rename_dbnames(char dbname[][32]);
  280 
  281 /* Return usage string that must be freed by the caller */
  282 void fprint_usage_string(FILE *out);
  283 
  284 int cat_compare(const void *v1, const void *v2);
  285 
  286 int get_timeout_interval(void);
  287 
  288 gint timeout_sync_up(gpointer data);
  289 gint timeout_date(gpointer data);
  290 
  291 int get_pixbufs(int which_one,
  292                 GdkPixbuf **out_pixbuf);
  293 int get_rcfile_name(int n, char *rc_copy);
  294 int check_hidden_dir(void);
  295 
  296 int read_gtkrc_file(void);
  297 
  298 int get_home_file_name(const char *file, char *full_name, int max_size);
  299 
  300 int unpack_db_header(DBHeader *dbh, unsigned char *buffer);
  301 
  302 int find_next_offset(mem_rec_header *mem_rh, long fpos,
  303                      unsigned int *next_offset,
  304                      unsigned char *attrib, unsigned int *unique_id);
  305 
  306 /*The VP is a pointer to MyAddress, MyAppointment, etc. */
  307 int delete_pc_record(AppType app_type, void *VP, int flag);
  308 int undelete_pc_record(AppType app_type, void *VP, int flag);
  309 gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event);
  310 gboolean button_pressed_for_motion (GtkWidget *widget, GdkEvent  *event, gpointer   user_data);
  311 gboolean button_released_for_motion (GtkWidget *widget, GdkEvent  *event, gpointer   user_data);
  312 void button_set_for_motion(int x);
  313 void get_month_info(int month, int day, int year, int *dow, int *ndim);
  314 
  315 void free_mem_rec_header(mem_rec_header **mem_rh);
  316 
  317 void print_string(char *str, int len);
  318 
  319 int get_app_info(char *DB_name, unsigned char **buf, int *buf_size);
  320 
  321 int cleanup_pc_files(void);
  322 
  323 int setup_sync(unsigned int flags);
  324 
  325 /* Returns the number of the button that was pressed */
  326 int dialog_generic(GtkWindow *main_window,
  327                    char *title, int type,
  328                    char *text, int nob, char *button_text[]);
  329 
  330 /*
  331  * Widget must be some widget used to get the main window from.
  332  * The main window passed in would be fastest.
  333  * This just calls dialog_generic with an OK button.
  334  */
  335 int dialog_generic_ok(GtkWidget *widget,
  336                       char *title, int type, char *text);
  337 
  338 /*
  339  * Widget must be some widget used to get the main window from.
  340  * The main window passed in would be fastest.
  341  * changed is MODIFY_FLAG, or NEW_FLAG
  342  */
  343 int dialog_save_changed_record(GtkWidget *widget, int changed);
  344 int dialog_save_changed_record_with_cancel(GtkWidget *widget, int changed);
  345 
  346 /* mon 0-11
  347  * day 1-31
  348  * year (year - 1900)
  349  * This function will bring up the cal at mon, day, year
  350  * After a new date is selected it will return mon, day, year
  351  */
  352 int cal_dialog(GtkWindow *main_window,
  353                const char *title, int monday_is_fdow,
  354                int *mon, int *day, int *year);
  355 
  356 
  357 GdkRGBA get_color(int r, int g, int b);
  358 
  359 
  360 void entry_set_multiline_truncate(GtkEntry *entry, gboolean value);
  361 
  362 void set_tooltip(int show_tooltip,
  363                         GtkWidget *widget,
  364                         const gchar *tip_text);
  365 
  366 
  367 int check_copy_DBs_to_home(void);
  368 
  369 
  370 int verify_csv_header(const char *header, int num_fields, const char *file_name);
  371 
  372 void free_search_record_list(struct search_record **sr);
  373 
  374 /* Copy src string into dest while escaping quotes with double quotes.
  375  * dest could be as long as strlen(src)*2.
  376  * Return value is the number of chars written to dest. */
  377 int str_to_csv_str(char *dest, char *src);
  378 
  379 /*
  380  * Copy src string into dest while escaping carriage returns with <br/>
  381  * dest could be as long as strlen(src)*5.
  382  * Return value is the number of chars written to dest.
  383  */
  384 int str_to_keepass_str(char *dest, char *src);
  385 
  386 /* Copy src string into dest while escaping carriage returns,
  387  * backslashes, commas and semicolons.  Also do line wrapping.
  388  * dest could be as long as strlen(src) * 2 + strlen(src) / 30.
  389  * Return value is the number of chars written to dest. */
  390 int str_to_ical_str(char *, int, char *);
  391 
  392 /* Same as str_to_ical_str() except doesn't escape semicolons. */
  393 int str_to_vcard_str(char *, int, char *);
  394 
  395 /* Parse the string and replace CR and LFs with spaces */
  396 void remove_cr_lfs(char *str);
  397 
  398 /* Parse the string and replace CR and LFs with spaces
  399  * a null is written if len is reached */
  400 void lstrncpy_remove_cr_lfs(char *dest, char *src, int len);
  401 
  402 /* Output LDIF format (RFC 2849) to file.
  403  * Name is name of item (e.g. "cn")
  404  * fmt ... is like printf. */
  405 void ldif_out(FILE *f, const char *name, const char *fmt, ...);
  406 
  407 void cleanup_path(char *path);
  408 
  409 int add_days_to_date(struct tm *date, int n);
  410 
  411 int sub_days_from_date(struct tm *date, int n);
  412 
  413 int add_months_to_date(struct tm *date, int n);
  414 
  415 int sub_months_from_date(struct tm *date, int n);
  416 
  417 int add_years_to_date(struct tm *date, int n);
  418 
  419 int sub_years_from_date(struct tm *date, int n);
  420 
  421 time_t mktime_dst_adj(struct tm *tm);
  422 
  423 int dateToDays(struct tm *tm1);
  424 
  425 int find_prev_next(struct CalendarEvent *cale,
  426                    time_t adv,
  427                    struct tm *date1,
  428                    struct tm *date2,
  429                    struct tm *tm_prev,
  430                    struct tm *tm_next,
  431                    int *prev_found,
  432                    int *next_found);
  433 
  434 int find_next_rpt_event(struct CalendarEvent *cale,
  435                         struct tm *srch_start_tm,
  436                         struct tm *next_tm);
  437 
  438 /* These are in utils.c for now */
  439 /*
  440  * DB_name should be without filename ext, e.g. MemoDB
  441  * num is the number of records counted returned. */
  442 int pdb_file_count_recs(char *DB_name, int *num);
  443 /* DB_name should be without filename ext, e.g. MemoDB
  444  * uid_in the the unique ID to remove from the pdb file */
  445 int pdb_file_delete_record_by_id(char *DB_name, pi_uid_t uid_in);
  446 /* DB_name should be without filename ext, e.g. MemoDB
  447  * uid_in the the unique ID to modify from the pdb file
  448  * the other parameters are set in the pdb file for this record.  */
  449 int pdb_file_modify_record(char *DB_name, void *record_in, int size_in,
  450                            int attr_in, int cat_in, pi_uid_t uid_in);
  451 /* DB_name should be without filename ext, e.g. MemoDB
  452  * uid is unique id in
  453  * bufp is a copy of the raw record (unpacked) and should be freed by caller
  454  * sizep is size of bufp returned
  455  * idxp is the index in the file rec was found
  456  * attrp is the attributes
  457  * catp is the category (index) */
  458 int pdb_file_read_record_by_id(char *DB_name, 
  459                                pi_uid_t uid,
  460                                void **bufp, size_t *sizep, int *idxp,
  461                                int *attrp, int * catp);
  462 /* DB_name should be without filename ext, e.g. MemoDB
  463  * bufp is the packed app info block
  464  * size_in is the size of bufp */
  465 int pdb_file_write_app_block(char *DB_name, void *bufp, size_t size_in);
  466 
  467 /* This copies the database (pdb, or prc) and writes the DBInfo privided
  468  * since there is no other way to set it in a file. */
  469 int pdb_file_write_dbinfo(char *DB_name, struct DBInfo *Pinfo_in);
  470 
  471 void append_anni_years(char *desc, int max, struct tm *date,
  472                        struct Appointment *a, struct CalendarEvent *cale);
  473 int get_highlighted_today(struct tm *date);
  474 
  475 int make_category_menu(GtkWidget **category_menu,
  476                        struct sorted_cats *sort_l,
  477                        void (*selection_callback)
  478                                (GtkComboBox *item, int selection),
  479                        int add_an_all_item,
  480                        int add_edit_cat_item);
  481 int get_selected_category_from_combo_box(GtkComboBox * box);
  482 int findSortedPostion(int sorted_position,GtkComboBox * box);
  483 
  484 int jp_copy_file(char *src, char *dest);
  485 FILE *jp_open_home_file(const char *filename, const char *mode);
  486 int jp_close_home_file(FILE *pc_in);
  487 
  488 /* Routines used for i18n string manipulation */
  489 void multibyte_safe_strncpy(char *dst, char *src, size_t len);
  490 char *multibyte_safe_memccpy(char *dst, const char *src, int c, size_t len);
  491 
  492 /* host character set of J-Pilot (j) to Palm character set (p) */
  493 void charset_j2p(char *buf, int max_len, long char_set);
  494 
  495 /* Palm character set (p) to host character set of J-Pilot (j) */
  496 void charset_p2j(char *buf, int max_len, int char_set);
  497 char *charset_p2newj(const char *buf, int max_len, int char_set);
  498 
  499 /* Versions of character conversion routines for plugins */
  500 void jp_charset_j2p(char *buf, int max_len);
  501 void jp_charset_p2j(char *buf, int max_len);
  502 char* jp_charset_p2newj(const char *buf, int max_len);
  503 size_t jp_strftime(char *s, size_t max, const char *format, const struct tm *tm);
  504 
  505 /******************************************************************************/
  506 /* search_gui.c */
  507 void cb_search_gui(GtkWidget *widget, gpointer data);
  508 
  509 /* install_gui.c */
  510 int install_gui(GtkWidget *main_window, int w, int h, int x, int y);
  511 int install_append_line(const char *line);
  512 
  513 /* import_gui.c */
  514 void import_gui(GtkWidget *main_window, GtkWidget *main_pane,
  515                 char *type_desc[], int type_int[],
  516                 int (*import_callback)(GtkWidget *parent_window,
  517                                        const char *file_path, int type));
  518 int import_record_ask(GtkWidget *main_window, GtkWidget *pane,
  519                       char *text, struct CategoryAppInfo *cai,
  520                       char *old_cat_name,
  521                       int priv, int suggested_cat_num, int *new_cat_num);
  522 
  523 /* dat.c */
  524 /* Returns a dat type, or 0 */
  525 int dat_check_if_dat_file(FILE *in);
  526 int dat_get_appointments(FILE *in, AppointmentList **alist, struct CategoryAppInfo *ai);
  527 int dat_get_addresses(FILE *in, AddressList **addrlist, struct CategoryAppInfo *ai);
  528 int dat_get_todos(FILE *in, ToDoList **todolist, struct CategoryAppInfo *ai);
  529 int dat_get_memos(FILE *in, MemoList **memolist, struct CategoryAppInfo *ai);
  530 
  531 /* jpilot.c */
  532 void cb_app_button(GtkWidget *widget, gpointer data);
  533 void get_compile_options(char *string, int len);
  534 
  535 void call_plugin_gui(int number, int unique_id);
  536 void plugin_gui_refresh(int unique_id);
  537 
  538 /* datebook_gui.c */
  539 int datebook_gui(GtkWidget *vbox, GtkWidget *hbox);
  540 int datebook_gui_cleanup(void);
  541 int datebook_refresh(int first, int do_init);
  542 void datebook_gui_setdate(int year, int month, int day);
  543 
  544 /* address_gui.c */
  545 int address_gui(GtkWidget *vbox, GtkWidget *hbox);
  546 int address_gui_cleanup(void);
  547 int address_refresh(void);
  548 int address_cycle_cat(void);
  549  
  550 /* todo_gui.c */
  551 int todo_gui(GtkWidget *vbox, GtkWidget *hbox);
  552 int todo_gui_cleanup(void);
  553 int todo_refresh(void);
  554 int todo_cycle_cat(void);
  555 
  556 /* memo_gui.c */
  557 int memo_gui(GtkWidget *vbox, GtkWidget *hbox);
  558 int memo_gui_cleanup(void);
  559 int memo_refresh(void);
  560 int memo_cycle_cat(void);
  561 
  562 /* monthview_gui.c */
  563 void monthview_gui(struct tm *date);
  564 
  565 /* weekview_gui.c */
  566 void weekview_gui(struct tm *date_in);
  567 
  568 /* dialer.c */
  569 int dialog_dial(GtkWindow *main_window, char *string, char *ext);
  570 
  571 /* category.c */
  572 /*
  573  * widget is a widget inside the main window used to get main window handle
  574  * db_name should be without filename ext, e.g. MemoDB
  575  * cai is the category app info.  This should be unpacked by the user since
  576  * category unpack functions are database specific.  */
  577 int edit_cats(GtkWidget *widget, char *db_name, struct CategoryAppInfo *cai);
  578 /* This changes every record with index old_index and changes it to new_index
  579  * returns the number of record's categories changed.  */
  580 int pdb_file_change_indexes(char *DB_name, int old_index, int new_index);
  581 int pdb_file_swap_indexes(char *DB_name, int old_cat, int new_cat);
  582 int edit_cats_change_cats_pc3(char *DB_name, int old_cat, int new_cat);
  583 int edit_cats_swap_cats_pc3(char *DB_name, int old_cat, int new_cat);
  584 int edit_cats_change_cats_pdb(char *DB_name, int old_cat, int new_cat);
  585 
  586 #endif