"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "category.c" between
jpilot-1.8.2.tar.gz and jpilot-2_0_1.tar.gz

About: J-Pilot is a desktop organizer application for Palm Pilot (PalmOS) devices. Ported to GTK3.

category.c  (jpilot-1.8.2):category.c  (jpilot-2_0_1)
skipping to change at line 50 skipping to change at line 50
#define EDIT_CAT_NEW 101 #define EDIT_CAT_NEW 101
#define EDIT_CAT_RENAME 102 #define EDIT_CAT_RENAME 102
#define EDIT_CAT_DELETE 103 #define EDIT_CAT_DELETE 103
#define EDIT_CAT_ENTRY_OK 104 #define EDIT_CAT_ENTRY_OK 104
#define EDIT_CAT_ENTRY_CANCEL 105 #define EDIT_CAT_ENTRY_CANCEL 105
/* #define EDIT_CATS_DEBUG 1 */ /* #define EDIT_CATS_DEBUG 1 */
/****************************** Prototypes ************************************/ /****************************** Prototypes ************************************/
struct dialog_cats_data { struct dialog_cats_data {
int button_hit; int button_hit;
int selected; int selected;
int state; int state;
GtkWidget *clist; GtkTreeView *treeView;
GtkWidget *button_box; GtkListStore *listStore;
GtkWidget *entry_box; GtkWidget *button_box;
GtkWidget *entry; GtkWidget *entry_box;
GtkWidget *label; GtkWidget *entry;
char db_name[16]; GtkWidget *label;
struct CategoryAppInfo cai1; char *entryText;
struct CategoryAppInfo cai2; char db_name[16];
struct CategoryAppInfo cai1;
struct CategoryAppInfo cai2;
}; };
/****************************** Main Code *************************************/ enum {
static int count_records_in_cat(char *db_name, int cat_index) CATEGORY_TITLE_COLUMN_ENUM,
{ CATEGORY_DATA_COLUMN_ENUM,
GList *records; CATEGORY_NUM_COLS
GList *temp_list; };
int count, num;
buf_rec *br;
jp_logf(JP_LOG_DEBUG, "count_records_in_cat\n");
count = 0;
num = jp_read_DB_files(db_name, &records);
if (-1 == num)
return 0;
for (temp_list = records; temp_list; temp_list = temp_list->next) {
if (temp_list->data) {
br=temp_list->data;
} else {
continue;
}
if (!br->buf) continue;
if ((br->rt==DELETED_PALM_REC) ||
(br->rt==DELETED_PC_REC) ||
(br->rt==MODIFIED_PALM_REC))
continue;
if ((br->attrib & 0x0F) != cat_index) continue;
count++;
}
jp_free_DB_records(&records);
jp_logf(JP_LOG_DEBUG, "Leaving count_records_in_cat()\n");
return count;
}
static int edit_cats_delete_cats_pc3(char *DB_name, int cat)
{
char local_pc_file[FILENAME_MAX];
FILE *pc_in;
PC3RecordHeader header;
int num;
int rec_len;
int count=0;
g_snprintf(local_pc_file, sizeof(local_pc_file), "%s.pc3", DB_name);
pc_in = jp_open_home_file(local_pc_file, "r+");
if (pc_in==NULL) {
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), local_pc_file);
return EXIT_FAILURE;
}
while (!feof(pc_in)) { /****************************** Main Code *************************************/
num = read_header(pc_in, &header); static int count_records_in_cat(char *db_name, int cat_index) {
if (num!=1) { GList *records;
if (ferror(pc_in)) break; GList *temp_list;
if (feof(pc_in)) break; int count, num;
} buf_rec *br;
rec_len = header.rec_len; jp_logf(JP_LOG_DEBUG, "count_records_in_cat\n");
if (rec_len > 0x10000) {
jp_logf(JP_LOG_WARN, _("PC file corrupt?\n")); count = 0;
fclose(pc_in);
return EXIT_FAILURE; num = jp_read_DB_files(db_name, &records);
} if (-1 == num)
if (((header.rt==NEW_PC_REC) || (header.rt==REPLACEMENT_PALM_REC)) && return 0;
((header.attrib&0x0F)==cat)) {
if (fseek(pc_in, -(header.header_len), SEEK_CUR)) { for (temp_list = records; temp_list; temp_list = temp_list->next) {
if (temp_list->data) {
br = temp_list->data;
} else {
continue;
}
if (!br->buf) continue;
if ((br->rt == DELETED_PALM_REC) ||
(br->rt == DELETED_PC_REC) ||
(br->rt == MODIFIED_PALM_REC))
continue;
if ((br->attrib & 0x0F) != cat_index) continue;
count++;
}
jp_free_DB_records(&records);
jp_logf(JP_LOG_DEBUG, "Leaving count_records_in_cat()\n");
return count;
}
static int edit_cats_delete_cats_pc3(char *DB_name, int cat) {
char local_pc_file[FILENAME_MAX];
FILE *pc_in;
PC3RecordHeader header;
int num;
int rec_len;
int count = 0;
g_snprintf(local_pc_file, sizeof(local_pc_file), "%s.pc3", DB_name);
pc_in = jp_open_home_file(local_pc_file, "r+");
if (pc_in == NULL) {
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), local_pc_file);
return EXIT_FAILURE;
}
while (!feof(pc_in)) {
num = read_header(pc_in, &header);
if (num != 1) {
if (ferror(pc_in)) break;
if (feof(pc_in)) break;
}
rec_len = (int) header.rec_len;
if (rec_len > 0x10000) {
jp_logf(JP_LOG_WARN, _("PC file corrupt?\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
if (((header.rt == NEW_PC_REC) || (header.rt == REPLACEMENT_PALM_REC)) &
&
((header.attrib & 0x0F) == cat)) {
if (fseek(pc_in, -(header.header_len), SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
header.rt = DELETED_PC_REC;
write_header(pc_in, &header);
count++;
}
/* Skip this record now that we are done with it */
if (fseek(pc_in, rec_len, SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n")); jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in); fclose(pc_in);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
header.rt=DELETED_PC_REC; }
write_header(pc_in, &header);
count++;
}
/* Skip this record now that we are done with it */
if (fseek(pc_in, rec_len, SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
}
fclose(pc_in); fclose(pc_in);
return count; return count;
} }
/* Helper routine to change categories. /* Helper routine to change categories.
* Function changes category regardless of record type */ * Function changes category regardless of record type */
static int _edit_cats_change_cats_pc3(char *DB_name, static int _edit_cats_change_cats_pc3(char *DB_name,
int old_cat, int new_cat, int old_cat, int new_cat,
int swap) int swap) {
{ char local_pc_file[FILENAME_MAX];
char local_pc_file[FILENAME_MAX]; FILE *pc_in;
FILE *pc_in; PC3RecordHeader header;
PC3RecordHeader header; int rec_len;
int rec_len; int num;
int num; int current_cat;
int current_cat; int count = 0;
int count=0;
g_snprintf(local_pc_file, sizeof(local_pc_file), "%s.pc3", DB_name);
g_snprintf(local_pc_file, sizeof(local_pc_file), "%s.pc3", DB_name);
pc_in = jp_open_home_file(local_pc_file, "r+");
pc_in = jp_open_home_file(local_pc_file, "r+"); if (pc_in == NULL) {
if (pc_in==NULL) { jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), local_pc_file);
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), local_pc_file); return EXIT_FAILURE;
return EXIT_FAILURE; }
}
while (!feof(pc_in)) {
while (!feof(pc_in)) { num = read_header(pc_in, &header);
num = read_header(pc_in, &header); if (num != 1) {
if (num!=1) { if (ferror(pc_in)) break;
if (ferror(pc_in)) break; if (feof(pc_in)) break;
if (feof(pc_in)) break; }
} rec_len = (int) header.rec_len;
rec_len = header.rec_len; if (rec_len > 0x10000) {
if (rec_len > 0x10000) { jp_logf(JP_LOG_WARN, _("PC file corrupt?\n"));
jp_logf(JP_LOG_WARN, _("PC file corrupt?\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
current_cat = header.attrib & 0x0F;
if (current_cat==old_cat) {
if (fseek(pc_in, -(header.header_len), SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in); fclose(pc_in);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
header.attrib=(header.attrib&0xFFFFFFF0) | new_cat;
write_header(pc_in, &header); current_cat = header.attrib & 0x0F;
count++; if (current_cat == old_cat) {
} if (fseek(pc_in, -(header.header_len), SEEK_CUR)) {
if ((swap) && (current_cat==new_cat)) { jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
if (fseek(pc_in, -(header.header_len), SEEK_CUR)) { fclose(pc_in);
return EXIT_FAILURE;
}
header.attrib = (unsigned char) ((header.attrib & 0xFFFFFFF0) | new_
cat);
write_header(pc_in, &header);
count++;
}
if ((swap) && (current_cat == new_cat)) {
if (fseek(pc_in, -(header.header_len), SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
header.attrib = (unsigned char) ((header.attrib & 0xFFFFFFF0) | old_
cat);
write_header(pc_in, &header);
count++;
}
/* Skip the rest of the record now that we are done with it */
if (fseek(pc_in, rec_len, SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n")); jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in); fclose(pc_in);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
header.attrib=(header.attrib&0xFFFFFFF0) | old_cat; }
write_header(pc_in, &header);
count++;
}
/* Skip the rest of the record now that we are done with it */
if (fseek(pc_in, rec_len, SEEK_CUR)) {
jp_logf(JP_LOG_WARN, _("fseek failed - fatal error\n"));
fclose(pc_in);
return EXIT_FAILURE;
}
}
fclose(pc_in); fclose(pc_in);
return count; return count;
} }
/* Exported routine to change categories in PC3 file */ /* Exported routine to change categories in PC3 file */
int edit_cats_change_cats_pc3(char *DB_name, int old_cat, int new_cat) int edit_cats_change_cats_pc3(char *DB_name, int old_cat, int new_cat) {
{ return _edit_cats_change_cats_pc3(DB_name, old_cat, new_cat, FALSE);
return _edit_cats_change_cats_pc3(DB_name, old_cat, new_cat, FALSE);
} }
/* Exported routine to swap categories in PC3 file */ /* Exported routine to swap categories in PC3 file */
int edit_cats_swap_cats_pc3(char *DB_name, int old_cat, int new_cat) int edit_cats_swap_cats_pc3(char *DB_name, int old_cat, int new_cat) {
{ return _edit_cats_change_cats_pc3(DB_name, old_cat, new_cat, TRUE);
return _edit_cats_change_cats_pc3(DB_name, old_cat, new_cat, TRUE);
} }
/* /*
* This routine changes records from old_cat to new_cat. * This routine changes records from old_cat to new_cat.
* It does not modify the local pdb file. * It does not modify the local pdb file.
* It does this by writing a modified record to the pc3 file. * It does this by writing a modified record to the pc3 file.
*/ */
int edit_cats_change_cats_pdb(char *DB_name, int old_cat, int new_cat) int edit_cats_change_cats_pdb(char *DB_name, int old_cat, int new_cat) {
{ GList *temp_list;
GList *temp_list; GList *records;
GList *records; buf_rec *br;
buf_rec *br; int num, count;
int num, count;
jp_logf(JP_LOG_DEBUG, "edit_cats_change_cats_pdb\n");
jp_logf(JP_LOG_DEBUG, "edit_cats_change_cats_pdb\n");
count = 0;
count=0; num = jp_read_DB_files(DB_name, &records);
num = jp_read_DB_files(DB_name, &records); if (-1 == num)
if (-1 == num) return 0;
return 0;
for (temp_list = records; temp_list; temp_list = temp_list->next) {
for (temp_list = records; temp_list; temp_list = temp_list->next) { if (temp_list->data) {
if (temp_list->data) { br = temp_list->data;
br=temp_list->data; } else {
} else { continue;
continue; }
}
if (!br->buf) continue;
if (!br->buf) continue; if ((br->rt == DELETED_PALM_REC) || (br->rt == MODIFIED_PALM_REC)) conti
if ((br->rt==DELETED_PALM_REC) || (br->rt==MODIFIED_PALM_REC)) continue; nue;
if ((br->attrib & 0x0F) == old_cat) { if ((br->attrib & 0x0F) == old_cat) {
if (new_cat==-1) { if (new_cat == -1) {
/* write a deleted rec */ /* write a deleted rec */
jp_delete_record(DB_name, br, DELETE_FLAG); jp_delete_record(DB_name, br, DELETE_FLAG);
count++; count++;
} else { } else {
/* write a deleted rec */ /* write a deleted rec */
br->attrib=(br->attrib&0xFFFFFFF0) | (new_cat&0x0F); br->attrib = (unsigned char) ((br->attrib & 0xFFFFFFF0) | (new_c
jp_delete_record(DB_name, br, MODIFY_FLAG); at & 0x0F));
br->rt=REPLACEMENT_PALM_REC; jp_delete_record(DB_name, br, MODIFY_FLAG);
jp_pc_write(DB_name, br); br->rt = REPLACEMENT_PALM_REC;
count++; jp_pc_write(DB_name, br);
} count++;
} }
} }
}
jp_free_DB_records(&records); jp_free_DB_records(&records);
return count; return count;
} }
/* /*
* This helper routine changes the category index of records in the pdb file. * This helper routine changes the category index of records in the pdb file.
* It will change all old_index records to new_index and with the swap * It will change all old_index records to new_index and with the swap
* option will also change new_index records to old_index ones. * option will also change new_index records to old_index ones.
* Returns the number of records where the category was changed. * Returns the number of records where the category was changed.
*/ */
static int _change_cat_pdb(char *DB_name, static int _change_cat_pdb(char *DB_name,
int old_index, int new_index, int old_index, int new_index,
int swap) int swap) {
{ char local_pdb_file[FILENAME_MAX];
char local_pdb_file[FILENAME_MAX]; char full_local_pdb_file[FILENAME_MAX];
char full_local_pdb_file[FILENAME_MAX]; char full_local_pdb_file2[FILENAME_MAX];
char full_local_pdb_file2[FILENAME_MAX]; pi_file_t *pf1, *pf2;
pi_file_t *pf1, *pf2; struct DBInfo infop;
struct DBInfo infop; void *app_info;
void *app_info; void *sort_info;
void *sort_info; void *record;
void *record; size_t size;
size_t size; pi_uid_t uid;
pi_uid_t uid; struct stat statb;
struct stat statb; struct utimbuf times;
struct utimbuf times; int idx;
int idx; int attr;
int attr; int cat;
int cat; int count;
int count;
jp_logf(JP_LOG_DEBUG, "_change_cat_pdb\n");
jp_logf(JP_LOG_DEBUG, "_change_cat_pdb\n");
g_snprintf(local_pdb_file, sizeof(local_pdb_file), "%s.pdb", DB_name);
g_snprintf(local_pdb_file, sizeof(local_pdb_file), "%s.pdb", DB_name); get_home_file_name(local_pdb_file, full_local_pdb_file, sizeof(full_local_pd
get_home_file_name(local_pdb_file, full_local_pdb_file, sizeof(full_local_pdb b_file));
_file)); strcpy(full_local_pdb_file2, full_local_pdb_file);
strcpy(full_local_pdb_file2, full_local_pdb_file); strcat(full_local_pdb_file2, "2");
strcat(full_local_pdb_file2, "2");
/* After we are finished, set the create and modify times of new file
/* After we are finished, set the create and modify times of new file to the same as the old */
to the same as the old */ stat(full_local_pdb_file, &statb);
stat(full_local_pdb_file, &statb); times.actime = statb.st_atime;
times.actime = statb.st_atime; times.modtime = statb.st_mtime;
times.modtime = statb.st_mtime;
pf1 = pi_file_open(full_local_pdb_file);
pf1 = pi_file_open(full_local_pdb_file); if (!pf1) {
if (!pf1) { jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), full_local_pdb_file
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), full_local_pdb_file); );
return EXIT_FAILURE; return EXIT_FAILURE;
} }
pi_file_get_info(pf1, &infop); pi_file_get_info(pf1, &infop);
pf2 = pi_file_create(full_local_pdb_file2, &infop); pf2 = pi_file_create(full_local_pdb_file2, &infop);
if (!pf2) { if (!pf2) {
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), full_local_pdb_file2) jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), full_local_pdb_file
; 2);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
pi_file_get_app_info(pf1, &app_info, &size); pi_file_get_app_info(pf1, &app_info, &size);
pi_file_set_app_info(pf2, app_info, size); pi_file_set_app_info(pf2, app_info, size);
pi_file_get_sort_info(pf1, &sort_info, &size); pi_file_get_sort_info(pf1, &sort_info, &size);
pi_file_set_sort_info(pf2, sort_info, size); pi_file_set_sort_info(pf2, sort_info, size);
idx = 0; idx = 0;
count = 0; count = 0;
while((pi_file_read_record(pf1, idx, &record, &size, &attr, &cat, &uid)) > 0) while ((pi_file_read_record(pf1, idx, &record, &size, &attr, &cat, &uid)) >
{ 0) {
if (cat==old_index) { if (cat == old_index) {
cat=new_index; cat = new_index;
count++; count++;
} else if ((swap) && (cat==new_index)) { } else if ((swap) && (cat == new_index)) {
cat=old_index; cat = old_index;
count++; count++;
} }
pi_file_append_record(pf2, record, size, attr, cat, uid); pi_file_append_record(pf2, record, size, attr, cat, uid);
idx++; idx++;
} }
pi_file_close(pf1); pi_file_close(pf1);
pi_file_close(pf2); pi_file_close(pf2);
if (rename(full_local_pdb_file2, full_local_pdb_file) < 0) { if (rename(full_local_pdb_file2, full_local_pdb_file) < 0) {
jp_logf(JP_LOG_WARN, "pdb_file_change_indexes(): %s\n, ", _("rename failed jp_logf(JP_LOG_WARN, "pdb_file_change_indexes(): %s\n, ", _("rename fail
")); ed"));
} }
utime(full_local_pdb_file, &times); utime(full_local_pdb_file, &times);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* Exported routine to change categories in pdb file */ /* Exported routine to change categories in pdb file */
int pdb_file_change_indexes(char *DB_name, int old_cat, int new_cat) int pdb_file_change_indexes(char *DB_name, int old_cat, int new_cat) {
{ return _change_cat_pdb(DB_name, old_cat, new_cat, FALSE);
return _change_cat_pdb(DB_name, old_cat, new_cat, FALSE);
} }
/* Exported routine to swap categories in pdb file */ /* Exported routine to swap categories in pdb file */
int pdb_file_swap_indexes(char *DB_name, int old_cat, int new_cat) int pdb_file_swap_indexes(char *DB_name, int old_cat, int new_cat) {
{ return _change_cat_pdb(DB_name, old_cat, new_cat, TRUE);
return _change_cat_pdb(DB_name, old_cat, new_cat, TRUE);
} }
/* /*
* This routine changes deletes records in category cat. * This routine changes deletes records in category cat.
* It does not modify a local pdb file. * It does not modify a local pdb file.
* It does this by writing a modified record to the pc3 file. * It does this by writing a modified record to the pc3 file.
*/ */
static int edit_cats_delete_cats_pdb(char *DB_name, int cat) static int edit_cats_delete_cats_pdb(char *DB_name, int cat) {
{ jp_logf(JP_LOG_DEBUG, "edit_cats_delete_cats_pdb\n");
jp_logf(JP_LOG_DEBUG, "edit_cats_delete_cats_pdb\n");
return edit_cats_change_cats_pdb(DB_name, cat, -1);
}
static void cb_edit_button(GtkWidget *widget, gpointer data)
{
struct dialog_cats_data *Pdata;
int i, r, count;
int j;
long char_set;
int id;
int button;
int catnum;
char currentname[HOSTCAT_NAME_SZ]; /* current category name */
char previousname[HOSTCAT_NAME_SZ]; /* previous category name */
char pilotentry[HOSTCAT_NAME_SZ]; /* entry text, in Pilot character set */
char *button_text[]={N_("OK")};
char *move_text[]={N_("Move"), N_("Delete"), N_("Cancel")};
char *text;
const char *entry_text;
char temp[256];
get_pref(PREF_CHAR_SET, &char_set, NULL); /* JPA be prepared to make conversi
ons */
button = GPOINTER_TO_INT(data);
Pdata = gtk_object_get_data(GTK_OBJECT(gtk_widget_get_toplevel(widget)), "dia
log_cats_data");
/* JPA get the selected category number */
catnum = 0;
i = 0;
while ((i <= Pdata->selected) && (catnum < NUM_CATEGORIES)) {
if (Pdata->cai2.name[++catnum][0]) i++;
}
if (catnum >= NUM_CATEGORIES) catnum = -1; /* not found */
if (Pdata) { return edit_cats_change_cats_pdb(DB_name, cat, -1);
switch (button) {
case EDIT_CAT_NEW:
count=0;
for (i=0; i<NUM_CATEGORIES-1; i++) {
r = gtk_clist_get_text(GTK_CLIST(Pdata->clist), i, 0, &text);
if ((r) && (text[0])) {
count++;
}
}
if (count>NUM_CATEGORIES-2) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories"), DIALOG_ERROR,
_("The maximum number of categories (16) are already
used"), 1, button_text);
return;
}
gtk_label_set_text(GTK_LABEL(Pdata->label), _("Enter New Category"));
gtk_entry_set_text(GTK_ENTRY(Pdata->entry), "");
gtk_widget_show(Pdata->entry_box);
gtk_widget_hide(Pdata->button_box);
gtk_widget_grab_focus(GTK_WIDGET(Pdata->entry));
Pdata->state=EDIT_CAT_NEW;
break;
case EDIT_CAT_RENAME:
if ((catnum<0) || (Pdata->cai2.name[catnum][0]=='\0')) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories Error"), DIALOG_ERROR,
_("You must select a category to rename"), 1, button_
text);
return;
}
#ifdef EDIT_CATS_DEBUG
if (catnum == 0) {
printf("Trying to rename category 0!\n");
}
#endif
gtk_clist_get_text(GTK_CLIST(Pdata->clist), Pdata->selected, 0, &text);
gtk_label_set_text(GTK_LABEL(Pdata->label), _("Enter New Category Name"
));
gtk_entry_set_text(GTK_ENTRY(Pdata->entry), text);
gtk_widget_show(Pdata->entry_box);
gtk_widget_hide(Pdata->button_box);
gtk_widget_grab_focus(GTK_WIDGET(Pdata->entry));
Pdata->state=EDIT_CAT_RENAME;
break;
case EDIT_CAT_DELETE:
#ifdef EDIT_CATS_DEBUG
printf("delete cat\n");
#endif
if (catnum<0) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories Error"), DIALOG_ERROR,
_("You must select a category to delete"), 1, button_
text);
return;
}
#ifdef EDIT_CATS_DEBUG
if (catnum == 0) {
printf("Trying to delete category 0!\n");
}
#endif
/* Check if category is empty */
if (Pdata->cai2.name[catnum][0]=='\0') {
return;
}
/* Check to see if there are records are in this category */
count = count_records_in_cat(Pdata->db_name, catnum);
#ifdef EDIT_CATS_DEBUG
printf("count=%d\n", count);
#endif
if (count>0) {
g_snprintf(temp, sizeof(temp), _("There are %d records in %s.\n"
"Do you want to move them to %s, or delete them?"),
count, Pdata->cai1.name[catnum], Pdata->cai1.name[0]);
r = dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories"), DIALOG_QUESTION,
temp, 3, move_text);
switch (r) {
case DIALOG_SAID_1:
#ifdef EDIT_CATS_DEBUG
printf("MOVE THEM\n");
#endif
r = edit_cats_change_cats_pc3(Pdata->db_name, catnum, 0);
#ifdef EDIT_CATS_DEBUG
printf("moved %d pc records\n", r);
#endif
r = edit_cats_change_cats_pdb(Pdata->db_name, catnum, 0);
#ifdef EDIT_CATS_DEBUG
printf("moved %d pdb->pc records\n", r);
#endif
break;
case DIALOG_SAID_2:
#ifdef EDIT_CATS_DEBUG
printf("DELETE THEM\n");
#endif
r = edit_cats_delete_cats_pc3(Pdata->db_name, catnum);
#ifdef EDIT_CATS_DEBUG
printf("deleted %d pc records\n", r);
#endif
r = edit_cats_delete_cats_pdb(Pdata->db_name, catnum);
#ifdef EDIT_CATS_DEBUG
printf("deleted %d pdb->pc records\n", r);
#endif
break;
case DIALOG_SAID_3:
#ifdef EDIT_CATS_DEBUG
printf("Delete Canceled\n");
#endif
return;
}
}
/* delete the category */
#ifdef EDIT_CATS_DEBUG
printf("DELETE category\n");
#endif
Pdata->cai2.name[catnum][0]='\0';
Pdata->cai2.ID[catnum]=Pdata->cai1.ID[catnum];
Pdata->cai2.renamed[catnum]=0;
/* JPA move category names upward in listbox */
/* we get the old text from listbox, to avoid making */
/* character set conversions */
for (i=Pdata->selected; i<NUM_CATEGORIES-2; i++) {
r = gtk_clist_get_text(GTK_CLIST(Pdata->clist), i+1, 0, &text);
if (r) gtk_clist_set_text(GTK_CLIST(Pdata->clist), i, 0, text);
}
/* JPA now clear the last category */
gtk_clist_set_text(GTK_CLIST(Pdata->clist), NUM_CATEGORIES-2, 0, "");
break;
case EDIT_CAT_ENTRY_OK:
if ((Pdata->state!=EDIT_CAT_RENAME) && (Pdata->state!=EDIT_CAT_NEW)) {
jp_logf(JP_LOG_WARN, _("invalid state file %s line %d\n"), __FILE__,
__LINE__);
return;
}
entry_text = gtk_entry_get_text(GTK_ENTRY(Pdata->entry));
/* Can't make an empty category, could do a dialog telling user */
if ((!entry_text) || (!entry_text[0])) {
return;
}
if ((Pdata->state==EDIT_CAT_RENAME) || (Pdata->state==EDIT_CAT_NEW)) {
/* Check for category being used more than once */
/* moved here by JPA for use in both new and rename cases */
/* JPA convert entry to Pilot character set before checking */
/* note : don't know Pilot size until converted */
g_strlcpy(pilotentry, entry_text, HOSTCAT_NAME_SZ);
charset_j2p(pilotentry, HOSTCAT_NAME_SZ, char_set);
pilotentry[PILOTCAT_NAME_SZ-1] = '\0';
for (i=0; i<NUM_CATEGORIES; i++) {
/* JPA allow a category to be renamed to its previous name */
if (((i != catnum) || (Pdata->state != EDIT_CAT_RENAME))
&& !strcmp(pilotentry, Pdata->cai2.name[i])) {
sprintf(temp, _("The category %s can't be used more than once"
), entry_text);
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories"), DIALOG_ERROR,
temp, 1, button_text);
return;
}
}
}
if (Pdata->state==EDIT_CAT_RENAME) {
#ifdef EDIT_CATS_DEBUG
printf("rename cat\n");
#endif
i=Pdata->selected;
/* JPA assuming gtk makes a copy */
gtk_clist_set_text(GTK_CLIST(Pdata->clist), i, 0, entry_text);
/* JPA enter new category name in Palm Pilot character set */
charset_j2p((char *)entry_text, HOSTCAT_NAME_SZ, char_set);
g_strlcpy(Pdata->cai2.name[catnum], entry_text, PILOTCAT_NAME_SZ);
Pdata->cai2.renamed[catnum]=1;
}
if (Pdata->state==EDIT_CAT_NEW) {
#ifdef EDIT_CATS_DEBUG
printf("new cat\n");
#endif
/* JPA have already checked category is not being used more than onc
e */
/* Find a new category ID */
id=128;
for (i=1; i<NUM_CATEGORIES; i++) {
if (Pdata->cai2.ID[i]==id) {
id++;
i=1;
}
}
/* Find an empty slot */
/* When the new button was pressed we already checked for an empty s
lot */
for (i=1; i<NUM_CATEGORIES; i++) {
if (Pdata->cai2.name[i][0]=='\0') {
#ifdef EDIT_CATS_DEBUG
printf("slot %d is empty\n", i);
#endif
/* JPA get the old text from listbox, to avoid making */
/* character set conversions */
r = gtk_clist_get_text(GTK_CLIST(Pdata->clist), i-1, 0, &text)
;
if (r)
g_strlcpy(currentname, text, HOSTCAT_NAME_SZ);
strcpy(Pdata->cai2.name[i], pilotentry);
Pdata->cai2.ID[i]=id;
Pdata->cai2.renamed[i]=1;
gtk_clist_set_text(GTK_CLIST(Pdata->clist), i-1, 0, entry_text
);
/* JPA relabel category labels beyond the change */
j = ++i;
while (r && (i < NUM_CATEGORIES)) {
while ((j < NUM_CATEGORIES) && (Pdata->cai2.name[j][0] == '
\0')) j++;
if (j < NUM_CATEGORIES) {
strcpy(previousname, currentname);
r = gtk_clist_get_text(GTK_CLIST(Pdata->clist), i-1, 0,
&text);
if (r)
g_strlcpy(currentname, text, HOSTCAT_NAME_SZ);
gtk_clist_set_text(GTK_CLIST(Pdata->clist), i-1, 0, prev
iousname);
j++;
}
i++;
}
break;
}
}
}
gtk_widget_hide(Pdata->entry_box);
gtk_widget_show(Pdata->button_box);
Pdata->state=EDIT_CAT_START;
break;
case EDIT_CAT_ENTRY_CANCEL:
gtk_widget_hide(Pdata->entry_box);
gtk_widget_show(Pdata->button_box);
Pdata->state=EDIT_CAT_START;
break;
default:
jp_logf(JP_LOG_WARN, "cb_edit_button(): %s\n", "unknown button");
}
}
} }
static void cb_clist_edit_cats(GtkWidget *widget, gboolean
gint row, gint column, deleteCategory(GtkTreeModel *model,
GdkEventButton *event, gpointer data) GtkTreePath *path,
{ GtkTreeIter *iter,
struct dialog_cats_data *Pdata; gpointer data) {
struct dialog_cats_data *Pdata;
Pdata=data; Pdata = data;
#ifdef EDIT_CATS_DEBUG int *i = gtk_tree_path_get_indices(path);
printf("row=%d\n", row); if (Pdata->selected == i[0]) {
#endif gtk_list_store_remove(GTK_LIST_STORE(Pdata->listStore), iter);
return TRUE;
if (Pdata->state==EDIT_CAT_START) { }
Pdata->selected=row; return FALSE;
} else { }
#ifdef EDIT_CATS_DEBUG
printf("cb_clist_edit_cats not in start state\n"); gboolean
#endif renameCategory(GtkTreeModel *model,
if (Pdata->selected!=row) { GtkTreePath *path,
clist_select_row(GTK_CLIST(Pdata->clist), Pdata->selected, 0); GtkTreeIter *iter,
} gpointer data) {
} struct dialog_cats_data *Pdata;
char *text;
Pdata = data;
int *i = gtk_tree_path_get_indices(path);
if (Pdata->selected == i[0]) {
text = Pdata->entryText;
gtk_list_store_set(GTK_LIST_STORE(Pdata->listStore), iter, CATEGORY_TITL
E_COLUMN_ENUM, text, -1);
return TRUE;
}
return FALSE;
}
gboolean
editCategoryRename(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
struct dialog_cats_data *Pdata;
char *text;
Pdata = data;
int *i = gtk_tree_path_get_indices(path);
if (Pdata->selected == i[0]) {
gtk_tree_model_get(GTK_TREE_MODEL(Pdata->listStore), iter, CATEGORY_TITL
E_COLUMN_ENUM, &text,-1);
gtk_label_set_text(GTK_LABEL(Pdata->label), _("Enter New Category Name")
);
gtk_entry_set_text(GTK_ENTRY(Pdata->entry), text);
gtk_widget_show(Pdata->entry_box);
gtk_widget_hide(Pdata->button_box);
gtk_widget_grab_focus(GTK_WIDGET(Pdata->entry));
Pdata->state = EDIT_CAT_RENAME;
return TRUE;
}
return FALSE;
}
gboolean
selectCategoryRecordByRow(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
struct dialog_cats_data *Pdata;
Pdata = data;
int *i = gtk_tree_path_get_indices(path);
int rowToCheck = Pdata->selected;
//rowToCheck is > than number of rows, so select the last row.
if (Pdata->selected >= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(model),
NULL)) {
rowToCheck--;
}
if (i[0] == rowToCheck) {
GtkTreeSelection *selection = NULL;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(Pdata->treeView));
gtk_tree_selection_select_path(selection, path);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(Pdata->treeView), path, CATEG
ORY_TITLE_COLUMN_ENUM, FALSE, 1.0, 0.0);
return TRUE;
}
return FALSE;
}
static void cb_edit_button(GtkWidget *widget, gpointer data) {
struct dialog_cats_data *Pdata;
int i, r, count;
long char_set;
int id;
int button;
int catnum;
char pilotentry[HOSTCAT_NAME_SZ]; /* entry text, in Pilot character set */
char *button_text[] = {N_("OK")};
char *move_text[] = {N_("Move"), N_("Delete"), N_("Cancel")};
const char *entry_text;
char temp[256];
get_pref(PREF_CHAR_SET, &char_set, NULL); /* JPA be prepared to make convers
ions */
button = GPOINTER_TO_INT(data);
Pdata = g_object_get_data(G_OBJECT(gtk_widget_get_toplevel(widget)), "dialo
g_cats_data");
/* JPA get the selected category number */
catnum = 0;
i = 0;
while ((i <= Pdata->selected) && (catnum < NUM_CATEGORIES)) {
if (Pdata->cai2.name[++catnum][0]) i++;
}
if (catnum >= NUM_CATEGORIES) catnum = -1; /* not found */
if (Pdata) {
switch (button) {
case EDIT_CAT_NEW:
count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(Pdata->lis
tStore), NULL);
if (count > NUM_CATEGORIES - 2) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories"), DIALOG_ERROR,
_("The maximum number of categories (16) are
already used"), 1, button_text);
return;
}
gtk_label_set_text(GTK_LABEL(Pdata->label), _("Enter New Categor
y"));
gtk_entry_set_text(GTK_ENTRY(Pdata->entry), "");
gtk_widget_show(Pdata->entry_box);
gtk_widget_hide(Pdata->button_box);
gtk_widget_grab_focus(GTK_WIDGET(Pdata->entry));
Pdata->state = EDIT_CAT_NEW;
break;
case EDIT_CAT_RENAME:
if ((catnum < 0) || (Pdata->cai2.name[catnum][0] == '\0')) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories Error"), DIALOG_ERROR,
_("You must select a category to rename"), 1,
button_text);
return;
}
#ifdef EDIT_CATS_DEBUG
if (catnum == 0) {
printf("Trying to rename category 0!\n");
}
#endif
gtk_tree_model_foreach(GTK_TREE_MODEL(Pdata->listStore), editCat
egoryRename, Pdata);
break;
case EDIT_CAT_DELETE:
#ifdef EDIT_CATS_DEBUG
printf("delete cat\n");
#endif
if (catnum < 0) {
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
_("Edit Categories Error"), DIALOG_ERROR,
_("You must select a category to delete"), 1,
button_text);
return;
}
#ifdef EDIT_CATS_DEBUG
if (catnum == 0) {
printf("Trying to delete category 0!\n");
}
#endif
/* Check if category is empty */
if (Pdata->cai2.name[catnum][0] == '\0') {
return;
}
/* Check to see if there are records are in this category */
count = count_records_in_cat(Pdata->db_name, catnum);
#ifdef EDIT_CATS_DEBUG
printf("count=%d\n", count);
#endif
if (count > 0) {
g_snprintf(temp, sizeof(temp), _("There are %d records in %s
.\n"
"Do you want to move them t
o %s, or delete them?"),
count, Pdata->cai1.name[catnum], Pdata->cai1.name
[0]);
r = dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(widget
)),
_("Edit Categories"), DIALOG_QUESTION,
temp, 3, move_text);
switch (r) {
case DIALOG_SAID_1:
#ifdef EDIT_CATS_DEBUG
printf("MOVE THEM\n");
#endif
r = edit_cats_change_cats_pc3(Pdata->db_name, catnum
, 0);
#ifdef EDIT_CATS_DEBUG
printf("moved %d pc records\n", r);
#endif
r = edit_cats_change_cats_pdb(Pdata->db_name, catnum
, 0);
#ifdef EDIT_CATS_DEBUG
printf("moved %d pdb->pc records\n", r);
#endif
break;
case DIALOG_SAID_2:
#ifdef EDIT_CATS_DEBUG
printf("DELETE THEM\n");
#endif
r = edit_cats_delete_cats_pc3(Pdata->db_name, catnum
);
#ifdef EDIT_CATS_DEBUG
printf("deleted %d pc records\n", r);
#endif
r = edit_cats_delete_cats_pdb(Pdata->db_name, catnum
);
#ifdef EDIT_CATS_DEBUG
printf("deleted %d pdb->pc records\n", r);
#endif
break;
case DIALOG_SAID_3:
#ifdef EDIT_CATS_DEBUG
printf("Delete Canceled\n");
#endif
return;
default:
return;
}
}
/* delete the category */
#ifdef EDIT_CATS_DEBUG
printf("DELETE category\n");
#endif
Pdata->cai2.name[catnum][0] = '\0';
Pdata->cai2.ID[catnum] = Pdata->cai1.ID[catnum];
Pdata->cai2.renamed[catnum] = 0;
/* JPA move category names upward in listbox */
/* we get the old text from listbox, to avoid making */
/* character set conversions */
gtk_tree_model_foreach(GTK_TREE_MODEL(Pdata->listStore), deleteC
ategory, Pdata);
gtk_tree_model_foreach(GTK_TREE_MODEL(Pdata->listStore), selectC
ategoryRecordByRow, Pdata);
break;
case EDIT_CAT_ENTRY_OK:
if ((Pdata->state != EDIT_CAT_RENAME) && (Pdata->state != EDIT_C
AT_NEW)) {
jp_logf(JP_LOG_WARN, _("invalid state file %s line %d\n"), _
_FILE__, __LINE__);
return;
}
entry_text = gtk_entry_get_text(GTK_ENTRY(Pdata->entry));
/* Can't make an empty category, could do a dialog telling user
*/
if ((!entry_text) || (!entry_text[0])) {
return;
}
if ((Pdata->state == EDIT_CAT_RENAME) || (Pdata->state == EDIT_C
AT_NEW)) {
/* Check for category being used more than once */
/* moved here by JPA for use in both new and rename cases */
/* JPA convert entry to Pilot character set before checking
*/
/* note : don't know Pilot size until converted */
g_strlcpy(pilotentry, entry_text, HOSTCAT_NAME_SZ);
charset_j2p(pilotentry, HOSTCAT_NAME_SZ, char_set);
pilotentry[PILOTCAT_NAME_SZ - 1] = '\0';
for (i = 0; i < NUM_CATEGORIES; i++) {
/* JPA allow a category to be renamed to its previous na
me */
if (((i != catnum) || (Pdata->state != EDIT_CAT_RENAME))
&& !strcmp(pilotentry, Pdata->cai2.name[i])) {
sprintf(temp, _("The category %s can't be used more
than once"), entry_text);
dialog_generic(GTK_WINDOW(gtk_widget_get_toplevel(wi
dget)),
_("Edit Categories"), DIALOG_ERROR,
temp, 1, button_text);
return;
}
}
}
if (Pdata->state == EDIT_CAT_RENAME) {
#ifdef EDIT_CATS_DEBUG
printf("rename cat\n");
#endif
Pdata->entryText = (char *) entry_text;
gtk_tree_model_foreach(GTK_TREE_MODEL(Pdata->listStore), ren
ameCategory, Pdata);
/* JPA enter new category name in Palm Pilot character set *
/
charset_j2p((char *) entry_text, HOSTCAT_NAME_SZ, char_set);
g_strlcpy(Pdata->cai2.name[catnum], entry_text, PILOTCAT_NAM
E_SZ);
Pdata->cai2.renamed[catnum] = 1;
}
if (Pdata->state == EDIT_CAT_NEW) {
#ifdef EDIT_CATS_DEBUG
printf("new cat\n");
#endif
/* JPA have already checked category is not being used more
than once */
/* Find a new category ID */
id = 128;
for (i = 1; i < NUM_CATEGORIES; i++) {
if (Pdata->cai2.ID[i] == id) {
id++;
i = 1;
}
}
/* Find an empty slot */
/* When the new button was pressed we already checked for an
empty slot */
GtkTreeIter iter;
gtk_list_store_append(Pdata->listStore, &iter);
gtk_list_store_set(Pdata->listStore, &iter, CATEGORY_TITLE_C
OLUMN_ENUM, entry_text, -1);
for (i = 1; i < NUM_CATEGORIES; i++) {
if (Pdata->cai2.name[i][0] == '\0') {
#ifdef EDIT_CATS_DEBUG
printf("slot %d is empty\n", i);
#endif
/* JPA get the old text from listbox, to avoid makin
g */
/* character set conversions */
strcpy(Pdata->cai2.name[i], pilotentry);
Pdata->cai2.ID[i] = (unsigned char) id;
Pdata->cai2.renamed[i] = 1;
break;
}
}
}
gtk_widget_hide(Pdata->entry_box);
gtk_widget_show(Pdata->button_box);
Pdata->state = EDIT_CAT_START;
break;
case EDIT_CAT_ENTRY_CANCEL:
gtk_widget_hide(Pdata->entry_box);
gtk_widget_show(Pdata->button_box);
Pdata->state = EDIT_CAT_START;
break;
default:
jp_logf(JP_LOG_WARN, "cb_edit_button(): %s\n", "unknown button")
;
}
}
}
static gboolean handleCategorySelection(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer data) {
struct dialog_cats_data *Pdata;
GtkTreeIter iter;
Pdata = data;
if ((gtk_tree_model_get_iter(model, &iter, path)) && (!path_currently_select
ed)) {
int *i = gtk_tree_path_get_indices(path);
if (Pdata->state == EDIT_CAT_START) {
Pdata->selected = i[0];
}
}
return TRUE;
} }
#ifdef EDIT_CATS_DEBUG #ifdef EDIT_CATS_DEBUG
static void cb_edit_cats_debug(GtkWidget *widget, gpointer data) static void cb_edit_cats_debug(GtkWidget *widget, gpointer data)
{ {
struct dialog_cats_data *Pdata; struct dialog_cats_data *Pdata;
int i; int i;
Pdata=data; Pdata=data;
for (i=0; i<NUM_CATEGORIES; i++) { for (i=0; i<NUM_CATEGORIES; i++) {
printf("cai %2d [%16s] ID %3d %d: [%16s] ID %3d %d\n", i, printf("cai %2d [%16s] ID %3d %d: [%16s] ID %3d %d\n", i,
Pdata->cai1.name[i], Pdata->cai1.ID[i], Pdata->cai1.renamed[i], Pdata->cai1.name[i], Pdata->cai1.ID[i], Pdata->cai1.renamed[i],
Pdata->cai2.name[i], Pdata->cai2.ID[i], Pdata->cai2.renamed[i]); Pdata->cai2.name[i], Pdata->cai2.ID[i], Pdata->cai2.renamed[i]);
} }
} }
#endif #endif
static void cb_dialog_button(GtkWidget *widget, gpointer data) static void cb_dialog_button(GtkWidget *widget, gpointer data) {
{ struct dialog_cats_data *Pdata;
struct dialog_cats_data *Pdata; GtkWidget *w;
GtkWidget *w;
w = gtk_widget_get_toplevel(widget);
w = gtk_widget_get_toplevel(widget); Pdata = g_object_get_data(G_OBJECT(w), "dialog_cats_data");
Pdata = gtk_object_get_data(GTK_OBJECT(w), "dialog_cats_data"); Pdata->button_hit = GPOINTER_TO_INT(data);
Pdata->button_hit=GPOINTER_TO_INT(data);
gtk_widget_destroy(GTK_WIDGET(w));
gtk_widget_destroy(GTK_WIDGET(w)); }
}
static gboolean cb_destroy_dialog(GtkWidget *widget) {
static gboolean cb_destroy_dialog(GtkWidget *widget) gtk_main_quit();
{
gtk_main_quit(); return TRUE;
}
return TRUE;
} int edit_cats(GtkWidget *widget, char *db_name, struct CategoryAppInfo *cai) {
GtkWidget *button;
int edit_cats(GtkWidget *widget, char *db_name, struct CategoryAppInfo *cai) GtkWidget *hbox, *vbox;
{ GtkWidget *vbox1, *vbox2, *vbox3;
GtkWidget *button; GtkWidget *dialog;
GtkWidget *hbox, *vbox; GtkListStore *listStore;
GtkWidget *vbox1, *vbox2, *vbox3; GtkWidget *treeView;
GtkWidget *dialog; GtkWidget *entry;
GtkWidget *clist; GtkWidget *label;
GtkWidget *entry; GtkWidget *separator;
GtkWidget *label; struct dialog_cats_data Pdata;
GtkWidget *separator; int i, j;
struct dialog_cats_data Pdata; long char_set;
int i, j; char *catname_hchar; /* Category names in host character set */
long char_set;
char *catname_hchar; /* Category names in host character set */ jp_logf(JP_LOG_DEBUG, "edit_cats\n");
char *titles[2] = {_("Category")};
gchar *empty_line[] = {""}; Pdata.selected = -1;
Pdata.state = EDIT_CAT_START;
jp_logf(JP_LOG_DEBUG, "edit_cats\n"); g_strlcpy(Pdata.db_name, db_name, 16);
#ifdef EDIT_CATS_DEBUG
Pdata.selected=-1; for (i = 0; i < NUM_CATEGORIES; i++) {
Pdata.state=EDIT_CAT_START; if (cai->name[i][0] != '\0') {
g_strlcpy(Pdata.db_name, db_name, 16); printf("cat %d [%s] ID %d renamed %d\n", i, cai->name[i],
#ifdef EDIT_CATS_DEBUG cai->ID[i], cai->renamed[i]);
for (i = 0; i < NUM_CATEGORIES; i++) { }
if (cai->name[i][0] != '\0') { }
printf("cat %d [%s] ID %d renamed %d\n", i, cai->name[i],
cai->ID[i], cai->renamed[i]);
}
}
#endif #endif
/* removed by JPA : do not change category names as they will /* removed by JPA : do not change category names as they will
* be written back to file. * be written back to file.
* We will however have to make a conversion for host dialog display * We will however have to make a conversion for host dialog display
* *
* get_pref(PREF_CHAR_SET, &char_set, NULL); * get_pref(PREF_CHAR_SET, &char_set, NULL);
* if (char_set != CHAR_SET_LATIN1) { * if (char_set != CHAR_SET_LATIN1) {
* for (i = 0; i < 16; i++) { * for (i = 0; i < 16; i++) {
* if (cai->name[i][0] != '\0') { * if (cai->name[i][0] != '\0') {
* charset_p2j((unsigned char*)cai->name[i], 16, char_set); * charset_p2j((unsigned char*)cai->name[i], 16, char_set);
* } * }
* } * }
* } * }
* *
*/ */
dialog = gtk_widget_new(GTK_TYPE_WINDOW, dialog = gtk_widget_new(GTK_TYPE_WINDOW,
"type", GTK_WINDOW_TOPLEVEL, "type", GTK_WINDOW_TOPLEVEL,
"title", _("Edit Categories"), "title", _("Edit Categories"),
NULL); NULL);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE); gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_widget_get_to gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_widget_get_t
plevel(widget))); oplevel(widget)));
gtk_signal_connect(GTK_OBJECT(dialog), "destroy", g_signal_connect(G_OBJECT(dialog), "destroy",
GTK_SIGNAL_FUNC(cb_destroy_dialog), dialog); G_CALLBACK(cb_destroy_dialog), dialog);
vbox3 = gtk_vbox_new(FALSE, 0); vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(dialog), vbox3); gtk_container_add(GTK_CONTAINER(dialog), vbox3);
hbox = gtk_hbox_new(FALSE, 0); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 5); gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
gtk_container_add(GTK_CONTAINER(vbox3), hbox); gtk_container_add(GTK_CONTAINER(vbox3), hbox);
vbox1 = gtk_vbox_new(FALSE, 0); vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox1, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(hbox), vbox1, FALSE, FALSE, 1);
vbox2 = gtk_vbox_new(FALSE, 0); vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 1);
listStore = gtk_list_store_new(CATEGORY_NUM_COLS, G_TYPE_STRING, G_TYPE_INT)
clist = gtk_clist_new_with_titles(1, titles); ;
treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(listStore));
gtk_clist_column_titles_passive(GTK_CLIST(clist)); GtkCellRenderer *titleRenderer = gtk_cell_renderer_text_new();
gtk_clist_set_column_min_width(GTK_CLIST(clist), 0, 100); GtkTreeViewColumn *titleColumn = gtk_tree_view_column_new_with_attributes("C
gtk_clist_set_column_auto_resize(GTK_CLIST(clist), 0, TRUE); ategory",
gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE); ti
tleRenderer,
gtk_signal_connect(GTK_OBJECT(clist), "select_row", "t
GTK_SIGNAL_FUNC(cb_clist_edit_cats), &Pdata); ext", CATEGORY_TITLE_COLUMN_ENUM,
gtk_box_pack_start(GTK_BOX(vbox1), clist, TRUE, TRUE, 1); NU
LL);
/* Fill clist with categories except for category 0, Unfiled, gtk_tree_view_column_set_clickable(titleColumn, gtk_false());
* which is not editable */ gtk_tree_view_column_set_min_width(titleColumn, 100);
get_pref(PREF_CHAR_SET, &char_set, NULL); gtk_tree_view_column_set_sizing(titleColumn, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
for (i=j=1; i<NUM_CATEGORIES; i++,j++) { gtk_tree_view_insert_column(GTK_TREE_VIEW(treeView), titleColumn, CATEGORY_T
gtk_clist_append(GTK_CLIST(clist), empty_line); ITLE_COLUMN_ENUM);
/* Hide void category names */ gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeVi
while ((j < NUM_CATEGORIES) && ((cai->name[j][0] == '\0') || (!cai->ID[j]) ew)),
)) { GTK_SELECTION_BROWSE);
/* Remove categories which have a null ID
* to facilitate recovering from errors, */ gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_
/* however we cannot synchronize them to the Palm Pilot */ VIEW(treeView)),
if (!cai->ID[j]) cai->name[j][0] = '\0'; handleCategorySelection, &Pdata, NULL
j++; );
} gtk_widget_set_events(treeView, GDK_BUTTON1_MOTION_MASK);
if (j < NUM_CATEGORIES) { g_signal_connect (G_OBJECT(treeView), "motion_notify_event",
/* Must do character set conversion from Palm to Host */ G_CALLBACK(motion_notify_event), NULL);
catname_hchar = charset_p2newj(cai->name[j], PILOTCAT_NAME_SZ, char_set g_signal_connect (G_OBJECT(treeView), "button-press-event",
); G_CALLBACK(button_pressed_for_motion), NULL);
gtk_clist_set_text(GTK_CLIST(clist), i-1, 0, catname_hchar); g_signal_connect (G_OBJECT(treeView), "button-release-event",
free(catname_hchar); G_CALLBACK(button_released_for_motion), NULL);
} gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(treeView), TRUE, TRUE, 1);
}
/* Fill list with categories except for category 0, Unfiled,
Pdata.clist = clist; * which is not editable */
get_pref(PREF_CHAR_SET, &char_set, NULL);
/* Buttons */ GtkTreeIter iter;
hbox = gtk_hbutton_box_new(); for (i = j = 1; i < NUM_CATEGORIES; i++, j++) {
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); /* Hide void category names */
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 6); while ((j < NUM_CATEGORIES) && ((cai->name[j][0] == '\0') || (!cai->ID[j
gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 1); ]))) {
/* Remove categories which have a null ID
* to facilitate recovering from errors, */
/* however we cannot synchronize them to the Palm Pilot */
if (!cai->ID[j]) cai->name[j][0] = '\0';
j++;
}
if (j < NUM_CATEGORIES) {
/* Must do character set conversion from Palm to Host */
catname_hchar = charset_p2newj(cai->name[j], PILOTCAT_NAME_SZ, (int)
char_set);
gtk_list_store_append(listStore, &iter);
gtk_list_store_set(listStore, &iter, CATEGORY_TITLE_COLUMN_ENUM, cat
name_hchar, CATEGORY_DATA_COLUMN_ENUM,
j, -1);
free(catname_hchar);
}
}
Pdata.treeView = GTK_TREE_VIEW(treeView);
Pdata.listStore = listStore;
/* Buttons */
hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 1);
#ifdef ENABLE_STOCK_BUTTONS #ifdef ENABLE_STOCK_BUTTONS
button = gtk_button_new_from_stock(GTK_STOCK_NEW); button = gtk_button_new_with_label("_New");
#else #else
button = gtk_button_new_with_label(_("New")); button = gtk_button_new_with_label(_("New"));
#endif #endif
gtk_signal_connect(GTK_OBJECT(button), "clicked", g_signal_connect(G_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_button), G_CALLBACK(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_NEW)); GINT_TO_POINTER(EDIT_CAT_NEW));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
button = gtk_button_new_with_label(_("Rename")); button = gtk_button_new_with_label(_("Rename"));
gtk_signal_connect(GTK_OBJECT(button), "clicked", g_signal_connect(G_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_button), G_CALLBACK(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_RENAME)); GINT_TO_POINTER(EDIT_CAT_RENAME));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
#ifdef ENABLE_STOCK_BUTTONS #ifdef ENABLE_STOCK_BUTTONS
button = gtk_button_new_from_stock(GTK_STOCK_DELETE); button = gtk_button_new_with_label("_Delete");
#else #else
button = gtk_button_new_with_label(_("Delete")); button = gtk_button_new_with_label(_("Delete"));
#endif
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_DELETE));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
Pdata.button_box = hbox;
/* Edit entry and boxes, etc */
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox2), vbox, FALSE, FALSE, 10);
separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
label = gtk_label_new("");
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
Pdata.label = label;
entry = gtk_entry_new_with_max_length(HOSTCAT_NAME_SZ-1);
gtk_signal_connect(GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_OK));
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
hbox = gtk_hbutton_box_new();
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 1);
button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_CANCEL));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
button = gtk_button_new_from_stock(GTK_STOCK_OK);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_OK));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
Pdata.entry_box = vbox;
Pdata.entry = entry;
/* Button Box */
hbox = gtk_hbutton_box_new();
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox3), hbox, FALSE, FALSE, 2);
/* Buttons */
button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_dialog_button),
GINT_TO_POINTER(DIALOG_SAID_2));
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
button = gtk_button_new_from_stock(GTK_STOCK_OK);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_dialog_button),
GINT_TO_POINTER(DIALOG_SAID_1));
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
#ifdef EDIT_CATS_DEBUG
button = gtk_button_new_with_label("DEBUG");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_edit_cats_debug), &Pdata);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
#endif
/* Set the default button pressed to CANCEL */
Pdata.button_hit = DIALOG_SAID_2;
/* Initialize data structures */
memcpy(&(Pdata.cai1), cai, sizeof(struct CategoryAppInfo));
memcpy(&(Pdata.cai2), cai, sizeof(struct CategoryAppInfo));
gtk_object_set_data(GTK_OBJECT(dialog), "dialog_cats_data", &Pdata);
gtk_widget_show_all(dialog);
gtk_widget_hide(Pdata.entry_box);
gtk_main();
/* OK, back from gtk_main loop */
#ifdef EDIT_CATS_DEBUG
if (Pdata.button_hit==DIALOG_SAID_1) {
printf("pressed 1\n");
}
#endif #endif
if (Pdata.button_hit==DIALOG_SAID_2) { g_signal_connect(G_OBJECT(button), "clicked",
#ifdef EDIT_CATS_DEBUG G_CALLBACK(cb_edit_button),
printf("pressed 2\n"); GINT_TO_POINTER(EDIT_CAT_DELETE));
#endif gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
return DIALOG_SAID_2;
} Pdata.button_box = hbox;
#ifdef EDIT_CATS_DEBUG
for (i=0; i<NUM_CATEGORIES; i++) { /* Edit entry and boxes, etc */
printf("name %d [%s] ID %d [%s] ID %d\n", i, vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
Pdata.cai1.name[i], Pdata.cai1.ID[i], gtk_box_pack_start(GTK_BOX(vbox2), vbox, FALSE, FALSE, 10);
Pdata.cai2.name[i], Pdata.cai2.ID[i]); separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
} gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
label = gtk_label_new("");
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
Pdata.label = label;
entry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(entry), HOSTCAT_NAME_SZ - 1);
g_signal_connect(G_OBJECT(entry), "activate",
G_CALLBACK(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_OK));
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 1);
button = gtk_button_new_with_label("Cancel");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_CANCEL));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
button = gtk_button_new_with_label("OK");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_edit_button),
GINT_TO_POINTER(EDIT_CAT_ENTRY_OK));
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1);
separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
Pdata.entry_box = vbox;
Pdata.entry = entry;
/* Button Box */
hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 12);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox3), hbox, FALSE, FALSE, 2);
/* Buttons */
button = gtk_button_new_with_label("Cancel");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_dialog_button),
GINT_TO_POINTER(DIALOG_SAID_2));
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
button = gtk_button_new_with_label("OK");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_dialog_button),
GINT_TO_POINTER(DIALOG_SAID_1));
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
#ifdef EDIT_CATS_DEBUG
button = gtk_button_new_with_label("DEBUG");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_edit_cats_debug), &Pdata);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
#endif
/* Set the default button pressed to CANCEL */
Pdata.button_hit = DIALOG_SAID_2;
/* Initialize data structures */
memcpy(&(Pdata.cai1), cai, sizeof(struct CategoryAppInfo));
memcpy(&(Pdata.cai2), cai, sizeof(struct CategoryAppInfo));
g_object_set_data(G_OBJECT(dialog), "dialog_cats_data", &Pdata);
gtk_widget_show_all(dialog);
gtk_widget_hide(Pdata.entry_box);
gtk_main();
/* OK, back from gtk_main loop */
#ifdef EDIT_CATS_DEBUG
if (Pdata.button_hit==DIALOG_SAID_1) {
printf("pressed 1\n");
}
#endif
if (Pdata.button_hit == DIALOG_SAID_2) {
#ifdef EDIT_CATS_DEBUG
printf("pressed 2\n");
#endif
return DIALOG_SAID_2;
}
#ifdef EDIT_CATS_DEBUG
for (i=0; i<NUM_CATEGORIES; i++) {
printf("name %d [%s] ID %d [%s] ID %d\n", i,
Pdata.cai1.name[i], Pdata.cai1.ID[i],
Pdata.cai2.name[i], Pdata.cai2.ID[i]);
}
#endif #endif
memcpy(cai, &(Pdata.cai2), sizeof(struct CategoryAppInfo)); memcpy(cai, &(Pdata.cai2), sizeof(struct CategoryAppInfo));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
 End of changes. 34 change blocks. 
824 lines changed or deleted 921 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)