"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "memo_gui.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.

memo_gui.c  (jpilot-1.8.2):memo_gui.c  (jpilot-2_0_1)
skipping to change at line 26 skipping to change at line 26
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/ ******************************************************************************/
/********************************* Includes ***********************************/ /********************************* Includes ***********************************/
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <pi-dlp.h> #include <pi-dlp.h>
#include "memo.h" #include "memo.h"
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "log.h" #include "log.h"
#include "prefs.h" #include "prefs.h"
#include "password.h" #include "password.h"
#include "print.h" #include "print.h"
#include "export.h" #include "export.h"
#include "stock_buttons.h" #include "stock_buttons.h"
/********************************* Constants **********************************/ /********************************* Constants **********************************/
#define NUM_MEMO_CAT_ITEMS 16 #define NUM_MEMO_CAT_ITEMS 16
#define MEMO_MAX_COLUMN_LEN 80 #define MEMO_MAX_COLUMN_LEN 80
#define MEMO_CLIST_CHAR_WIDTH 50 #define MEMO_LIST_CHAR_WIDTH 50
#define NUM_MEMO_CSV_FIELDS 3 #define NUM_MEMO_CSV_FIELDS 3
#define CONNECT_SIGNALS 400 #define CONNECT_SIGNALS 400
#define DISCONNECT_SIGNALS 401 #define DISCONNECT_SIGNALS 401
/******************************* Global vars **********************************/ /******************************* Global vars **********************************/
/* Keeps track of whether code is using Memo, or Memos database /* Keeps track of whether code is using Memo, or Memos database
* 0 is Memo, 1 is Memos */ * 0 is Memo, 1 is Memos */
static long memo_version=0; static long memo_version = 0;
extern GtkWidget *glob_date_label; extern GtkWidget *glob_date_label;
extern int glob_date_timer_tag; extern int glob_date_timer_tag;
static struct MemoAppInfo memo_app_info; static struct MemoAppInfo memo_app_info;
static int memo_category = CATEGORY_ALL; static int memo_category = CATEGORY_ALL;
static int clist_row_selected; static int row_selected;
static GtkWidget *clist;
static GtkWidget *treeView;
static GtkListStore *listStore;
static GtkWidget *memo_text; static GtkWidget *memo_text;
static GObject *memo_text_buffer; static GObject *memo_text_buffer;
static GtkWidget *private_checkbox; static GtkWidget *private_checkbox;
/* Need two extra slots for the ALL category and Edit Categories... */
static GtkWidget *memo_cat_menu_item1[NUM_MEMO_CAT_ITEMS+2];
static GtkWidget *memo_cat_menu_item2[NUM_MEMO_CAT_ITEMS];
static GtkWidget *category_menu1; static GtkWidget *category_menu1;
static GtkWidget *category_menu2; static GtkWidget *category_menu2;
static GtkWidget *pane; static GtkWidget *pane;
static struct sorted_cats sort_l[NUM_MEMO_CAT_ITEMS]; static struct sorted_cats sort_l[NUM_MEMO_CAT_ITEMS];
static GtkWidget *new_record_button; static GtkWidget *new_record_button;
static GtkWidget *apply_record_button; static GtkWidget *apply_record_button;
static GtkWidget *add_record_button; static GtkWidget *add_record_button;
static GtkWidget *delete_record_button; static GtkWidget *delete_record_button;
static GtkWidget *undelete_record_button; static GtkWidget *undelete_record_button;
static GtkWidget *copy_record_button; static GtkWidget *copy_record_button;
static GtkWidget *cancel_record_button; static GtkWidget *cancel_record_button;
static int record_changed; static int record_changed;
static MemoList *glob_memo_list=NULL; static MemoList *glob_memo_list = NULL;
static MemoList *export_memo_list=NULL; static MemoList *export_memo_list = NULL;
/****************************** Prototypes ************************************/ /****************************** Prototypes ************************************/
static int memo_clear_details(void); static int memo_clear_details(void);
static int memo_clist_redraw(void);
static int memo_redraw(void);
static void connect_changed_signals(int con_or_dis); static void connect_changed_signals(int con_or_dis);
static int memo_find(void); static int memo_find(void);
static int memo_get_details(struct Memo *new_memo, unsigned char *attrib); static int memo_get_details(struct Memo *new_memo, unsigned char *attrib);
static void memo_update_clist(GtkWidget *clist, GtkWidget *tooltip_widget,
MemoList **memo_list, int category, int main); static void memo_update_liststore(GtkListStore *listStore, GtkWidget *tooltip_wi
dget,
MemoList **memo_list, int category, int main);
static void cb_add_new_record(GtkWidget *widget, gpointer data); static void cb_add_new_record(GtkWidget *widget, gpointer data);
static void cb_edit_cats(GtkWidget *widget, gpointer data); static void cb_edit_cats(GtkWidget *widget, gpointer data);
void initializeTreeView();
gboolean handleRowSelectionForMemo(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata);
gboolean
addNewRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
gboolean deleteRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
void delete_memo(MyMemo *mmemo, gpointer data);
void undelete_memo(MyMemo *mmemo, gpointer data);
gboolean undeleteRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
gboolean printRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
gboolean
findRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
enum {
MEMO_COLUMN_ENUM = 0,
MEMO_DATA_COLUMN_ENUM,
MEMO_BACKGROUND_COLOR_ENUM,
MEMO_BACKGROUND_COLOR_ENABLED_ENUM,
MEMO_NUM_COLS
};
gboolean
selectRecordByRowMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
int print_memo(MyMemo *mmemo);
gboolean addNewMemo(MyMemo *mmemo, const void *data);
/****************************** Main Code *************************************/ /****************************** Main Code *************************************/
static void set_new_button_to(int new_state) static void set_new_button_to(int new_state) {
{ jp_logf(JP_LOG_DEBUG, "set_new_button_to new %d old %d\n", new_state, record
jp_logf(JP_LOG_DEBUG, "set_new_button_to new %d old %d\n", new_state, record_ _changed);
changed);
if (record_changed == new_state) {
if (record_changed==new_state) { return;
return; }
}
switch (new_state) {
switch (new_state) { case MODIFY_FLAG:
case MODIFY_FLAG: gtk_widget_show(cancel_record_button);
gtk_widget_show(cancel_record_button); gtk_widget_show(copy_record_button);
gtk_widget_show(copy_record_button); gtk_widget_show(apply_record_button);
gtk_widget_show(apply_record_button);
gtk_widget_hide(add_record_button);
gtk_widget_hide(add_record_button); gtk_widget_hide(delete_record_button);
gtk_widget_hide(delete_record_button); gtk_widget_hide(new_record_button);
gtk_widget_hide(new_record_button); gtk_widget_hide(undelete_record_button);
gtk_widget_hide(undelete_record_button);
break;
break; case NEW_FLAG:
case NEW_FLAG: gtk_widget_show(cancel_record_button);
gtk_widget_show(cancel_record_button); gtk_widget_show(add_record_button);
gtk_widget_show(add_record_button);
gtk_widget_hide(apply_record_button);
gtk_widget_hide(apply_record_button); gtk_widget_hide(copy_record_button);
gtk_widget_hide(copy_record_button); gtk_widget_hide(delete_record_button);
gtk_widget_hide(delete_record_button); gtk_widget_hide(new_record_button);
gtk_widget_hide(new_record_button); gtk_widget_hide(undelete_record_button);
gtk_widget_hide(undelete_record_button);
break;
break; case CLEAR_FLAG:
case CLEAR_FLAG: gtk_widget_show(delete_record_button);
gtk_widget_show(delete_record_button); gtk_widget_show(copy_record_button);
gtk_widget_show(copy_record_button); gtk_widget_show(new_record_button);
gtk_widget_show(new_record_button);
gtk_widget_hide(add_record_button);
gtk_widget_hide(add_record_button); gtk_widget_hide(apply_record_button);
gtk_widget_hide(apply_record_button); gtk_widget_hide(cancel_record_button);
gtk_widget_hide(cancel_record_button); gtk_widget_hide(undelete_record_button);
gtk_widget_hide(undelete_record_button);
break;
break; case UNDELETE_FLAG:
case UNDELETE_FLAG: gtk_widget_show(undelete_record_button);
gtk_widget_show(undelete_record_button); gtk_widget_show(copy_record_button);
gtk_widget_show(copy_record_button); gtk_widget_show(new_record_button);
gtk_widget_show(new_record_button);
gtk_widget_hide(add_record_button);
gtk_widget_hide(add_record_button); gtk_widget_hide(apply_record_button);
gtk_widget_hide(apply_record_button); gtk_widget_hide(cancel_record_button);
gtk_widget_hide(cancel_record_button); gtk_widget_hide(delete_record_button);
gtk_widget_hide(delete_record_button); break;
break;
default:
return;
}
record_changed=new_state;
}
static void cb_record_changed(GtkWidget *widget, gpointer data)
{
jp_logf(JP_LOG_DEBUG, "cb_record_changed\n");
if (record_changed==CLEAR_FLAG) {
connect_changed_signals(DISCONNECT_SIGNALS);
if (GTK_CLIST(clist)->rows > 0) {
set_new_button_to(MODIFY_FLAG);
} else {
set_new_button_to(NEW_FLAG);
}
}
else if (record_changed==UNDELETE_FLAG)
{
jp_logf(JP_LOG_INFO|JP_LOG_GUI,
_("This record is deleted.\n"
"Undelete it or copy it to make changes.\n"));
}
}
static void connect_changed_signals(int con_or_dis)
{
int i;
static int connected=0;
/* CONNECT */
if ((con_or_dis==CONNECT_SIGNALS) && (!connected)) {
connected=1;
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) {
if (memo_cat_menu_item2[i]) {
gtk_signal_connect(GTK_OBJECT(memo_cat_menu_item2[i]), "toggled",
GTK_SIGNAL_FUNC(cb_record_changed), NULL);
}
}
g_signal_connect(memo_text_buffer, "changed",
GTK_SIGNAL_FUNC(cb_record_changed), NULL);
gtk_signal_connect(GTK_OBJECT(private_checkbox), "toggled",
GTK_SIGNAL_FUNC(cb_record_changed), NULL);
}
/* DISCONNECT */
if ((con_or_dis==DISCONNECT_SIGNALS) && (connected)) {
connected=0;
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) {
if (memo_cat_menu_item2[i]) {
gtk_signal_disconnect_by_func(GTK_OBJECT(memo_cat_menu_item2[i]),
GTK_SIGNAL_FUNC(cb_record_changed), NU
LL);
}
}
g_signal_handlers_disconnect_by_func(memo_text_buffer,
GTK_SIGNAL_FUNC(cb_record_changed), N
ULL);
gtk_signal_disconnect_by_func(GTK_OBJECT(private_checkbox),
GTK_SIGNAL_FUNC(cb_record_changed), NULL);
}
}
int memo_print(void)
{
long this_many;
MyMemo *mmemo;
MemoList *memo_list;
MemoList memo_list1;
get_pref(PREF_PRINT_THIS_MANY, &this_many, NULL);
memo_list=NULL;
if (this_many==1) {
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), clist_row_selected);
if (mmemo < (MyMemo *)CLIST_MIN_DATA) {
return EXIT_FAILURE;
}
memcpy(&(memo_list1.mmemo), mmemo, sizeof(MyMemo));
memo_list1.next=NULL;
memo_list = &memo_list1;
}
if (this_many==2) {
get_memos2(&memo_list, SORT_ASCENDING, 2, 2, 2, memo_category);
}
if (this_many==3) {
get_memos2(&memo_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
}
print_memos(memo_list);
if ((this_many==2) || (this_many==3)) {
free_MemoList(&memo_list);
}
return EXIT_SUCCESS; default:
return;
}
record_changed = new_state;
}
static void cb_record_changed(GtkWidget *widget, gpointer data) {
jp_logf(JP_LOG_DEBUG, "cb_record_changed\n");
if (record_changed == CLEAR_FLAG) {
connect_changed_signals(DISCONNECT_SIGNALS);
if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(listStore), NULL) > 0)
{
set_new_button_to(MODIFY_FLAG);
} else {
set_new_button_to(NEW_FLAG);
}
} else if (record_changed == UNDELETE_FLAG) {
jp_logf(JP_LOG_INFO | JP_LOG_GUI,
_("This record is deleted.\n"
"Undelete it or copy it to make changes.\n"));
}
}
static void connect_changed_signals(int con_or_dis) {
static int connected = 0;
/* CONNECT */
if ((con_or_dis == CONNECT_SIGNALS) && (!connected)) {
connected = 1;
if(category_menu2){
g_signal_connect(G_OBJECT(category_menu2),"changed",G_CALLBACK(cb_re
cord_changed),NULL);
}
g_signal_connect(memo_text_buffer, "changed",
G_CALLBACK(cb_record_changed), NULL);
g_signal_connect(G_OBJECT(private_checkbox), "toggled",
G_CALLBACK(cb_record_changed), NULL);
}
/* DISCONNECT */
if ((con_or_dis == DISCONNECT_SIGNALS) && (connected)) {
connected = 0;
if(category_menu2) {
g_signal_handlers_disconnect_by_func(G_OBJECT(category_menu2), G_CAL
LBACK(cb_record_changed), NULL);
}
g_signal_handlers_disconnect_by_func(memo_text_buffer,
G_CALLBACK(cb_record_changed), NULL
);
g_signal_handlers_disconnect_by_func(G_OBJECT(private_checkbox),
G_CALLBACK(cb_record_changed), NULL);
}
}
int print_memo(MyMemo *mmemo) {
long this_many;
MemoList *memo_list;
MemoList memo_list1;
get_pref(PREF_PRINT_THIS_MANY, &this_many, NULL);
memo_list = NULL;
if (this_many == 1) {
if (mmemo < (MyMemo *) LIST_MIN_DATA) {
return EXIT_FAILURE;
}
memcpy(&(memo_list1.mmemo), mmemo, sizeof(MyMemo));
memo_list1.next = NULL;
memo_list = &memo_list1;
}
if (this_many == 2) {
get_memos2(&memo_list, SORT_ASCENDING, 2, 2, 2, memo_category);
}
if (this_many == 3) {
get_memos2(&memo_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
}
print_memos(memo_list);
if ((this_many == 2) || (this_many == 3)) {
free_MemoList(&memo_list);
}
return EXIT_SUCCESS;
}
gboolean printRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
int *i = gtk_tree_path_get_indices(path);
if (i[0] == row_selected) {
MyMemo *mmemo = NULL;
gtk_tree_model_get(model, iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
print_memo(mmemo);
return TRUE;
}
return FALSE;
}
int memo_print(void) {
gtk_tree_model_foreach(GTK_TREE_MODEL(listStore), printRecordMemo, NULL);
return EXIT_SUCCESS;
} }
/* Start Import Code */ /* Start Import Code */
static int cb_memo_import(GtkWidget *parent_window, static int cb_memo_import(GtkWidget *parent_window,
const char *file_path, const char *file_path,
int type) int type) {
{ FILE *in;
FILE *in; char line[256];
char line[256]; char text[65536];
char text[65536]; struct Memo new_memo;
struct Memo new_memo; unsigned char attrib;
unsigned char attrib; unsigned int len;
unsigned int len; unsigned int text_len;
unsigned int text_len; int i, ret, index;
int i, ret, index; int import_all;
int import_all; MemoList *memolist;
MemoList *memolist; MemoList *temp_memolist;
MemoList *temp_memolist; struct CategoryAppInfo cai;
struct CategoryAppInfo cai; char old_cat_name[32];
char old_cat_name[32]; int suggested_cat_num;
int suggested_cat_num; int new_cat_num;
int new_cat_num; int priv;
int priv;
in = fopen(file_path, "r");
in=fopen(file_path, "r"); if (!in) {
if (!in) { jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), file_path);
jp_logf(JP_LOG_WARN, _("Unable to open file: %s\n"), file_path); return EXIT_FAILURE;
return EXIT_FAILURE; }
}
/* TEXT */
/* TEXT */ if (type == IMPORT_TYPE_TEXT) {
if (type==IMPORT_TYPE_TEXT) { jp_logf(JP_LOG_DEBUG, "Memo import text [%s]\n", file_path);
jp_logf(JP_LOG_DEBUG, "Memo import text [%s]\n", file_path);
/* Trick to get currently selected category into attrib */
/* Trick to get currently selected category into attrib */ memo_get_details(&new_memo, &attrib);
memo_get_details(&new_memo, &attrib); free_Memo(&new_memo);
free_Memo(&new_memo);
text_len = 0;
text_len=0; text[0] = '\0';
text[0]='\0'; while (!feof(in)) {
while (!feof(in)) { line[0] = '\0';
line[0]='\0'; if (fgets(line, 255, in) == NULL) {
if (fgets(line, 255, in) == NULL) { jp_logf(JP_LOG_WARN, "write failed %s %d\n", __FILE__, __LINE__)
jp_logf(JP_LOG_WARN, "write failed %s %d\n", __FILE__, __LINE__); ;
} }
line[255] = '\0'; line[255] = '\0';
len=strlen(line); len = (unsigned int) strlen(line);
if (text_len+len>65534) { if (text_len + len > 65534) {
len=65534-text_len; len = 65534 - text_len;
line[len]='\0'; line[len] = '\0';
jp_logf(JP_LOG_WARN, _("Memo text > 65535, truncating\n")); jp_logf(JP_LOG_WARN, _("Memo text > 65535, truncating\n"));
strcat(text, line);
break;
}
text_len += len;
strcat(text, line); strcat(text, line);
break; }
}
text_len+=len; /* convert to valid UTF-8 and recalculate the length */
strcat(text, line); jp_charset_p2j(text, sizeof(text));
} text_len = (unsigned int) strlen(text);
/* convert to valid UTF-8 and recalculate the length */
jp_charset_p2j(text, sizeof(text));
text_len = strlen(text);
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
printf("text=[%s]\n", text); printf("text=[%s]\n", text);
printf("text_len=%d\n", text_len); printf("text_len=%d\n", text_len);
printf("strlen(text)=%d\n", strlen(text)); printf("strlen(text)=%d\n", strlen(text));
#endif #endif
new_memo.text=text; new_memo.text = text;
ret=import_record_ask(parent_window, pane, ret = import_record_ask(parent_window, pane,
new_memo.text, new_memo.text,
&(memo_app_info.category), &(memo_app_info.category),
_("Unfiled"), _("Unfiled"),
0, 0,
attrib & 0x0F, attrib & 0x0F,
&new_cat_num); &new_cat_num);
if ((ret==DIALOG_SAID_IMPORT_ALL) || (ret==DIALOG_SAID_IMPORT_YES)) { if ((ret == DIALOG_SAID_IMPORT_ALL) || (ret == DIALOG_SAID_IMPORT_YES))
pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL); {
jp_logf(JP_LOG_WARN, _("Imported Memo %s\n"), file_path); pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL);
} jp_logf(JP_LOG_WARN, _("Imported Memo %s\n"), file_path);
} }
}
/* CSV */
if (type==IMPORT_TYPE_CSV) { /* CSV */
jp_logf(JP_LOG_DEBUG, "Memo import CSV [%s]\n", file_path); if (type == IMPORT_TYPE_CSV) {
/* Get the first line containing the format and check for reasonableness * jp_logf(JP_LOG_DEBUG, "Memo import CSV [%s]\n", file_path);
/ /* Get the first line containing the format and check for reasonableness
if (fgets(text, sizeof(text), in) == NULL) { */
jp_logf(JP_LOG_WARN, "fgets failed %s %d\n", __FILE__, __LINE__); if (fgets(text, sizeof(text), in) == NULL) {
} jp_logf(JP_LOG_WARN, "fgets failed %s %d\n", __FILE__, __LINE__);
ret = verify_csv_header(text, NUM_MEMO_CSV_FIELDS, file_path); }
if (EXIT_FAILURE == ret) return EXIT_FAILURE; ret = verify_csv_header(text, NUM_MEMO_CSV_FIELDS, file_path);
if (EXIT_FAILURE == ret) return EXIT_FAILURE;
import_all=FALSE;
while (1) { import_all = FALSE;
/* Read the category field */ while (1) {
ret = read_csv_field(in, text, sizeof(text)); /* Read the category field */
if (feof(in)) break; ret = read_csv_field(in, text, sizeof(text));
if (feof(in)) break;
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
printf("category is [%s]\n", text); printf("category is [%s]\n", text);
#endif #endif
g_strlcpy(old_cat_name, text, 16); g_strlcpy(old_cat_name, text, 16);
/* Figure out what the best category number is */ /* Figure out what the best category number is */
suggested_cat_num=0; suggested_cat_num = 0;
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { for (i = 0; i < NUM_MEMO_CAT_ITEMS; i++) {
if (!memo_app_info.category.name[i][0]) continue; if (!memo_app_info.category.name[i][0]) continue;
if (!strcmp(memo_app_info.category.name[i], old_cat_name)) { if (!strcmp(memo_app_info.category.name[i], old_cat_name)) {
suggested_cat_num=i; suggested_cat_num = i;
break; break;
}
} }
}
/* Read the private field */ /* Read the private field */
ret = read_csv_field(in, text, sizeof(text)); ret = read_csv_field(in, text, sizeof(text));
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
printf("private is [%s]\n", text); printf("private is [%s]\n", text);
#endif #endif
sscanf(text, "%d", &priv); sscanf(text, "%d", &priv);
ret = read_csv_field(in, text, sizeof(text)); ret = read_csv_field(in, text, sizeof(text));
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
printf("memo text is [%s]\n", text); printf("memo text is [%s]\n", text);
#endif #endif
new_memo.text=text; new_memo.text = text;
if (!import_all) { if (!import_all) {
ret=import_record_ask(parent_window, pane, ret = import_record_ask(parent_window, pane,
new_memo.text, new_memo.text,
&(memo_app_info.category), &(memo_app_info.category),
old_cat_name, old_cat_name,
priv, priv,
suggested_cat_num, suggested_cat_num,
&new_cat_num); &new_cat_num);
} else { } else {
new_cat_num=suggested_cat_num; new_cat_num = suggested_cat_num;
} }
if (ret==DIALOG_SAID_IMPORT_QUIT) break; if (ret == DIALOG_SAID_IMPORT_QUIT) break;
if (ret==DIALOG_SAID_IMPORT_SKIP) continue; if (ret == DIALOG_SAID_IMPORT_SKIP) continue;
if (ret==DIALOG_SAID_IMPORT_ALL) import_all=TRUE; if (ret == DIALOG_SAID_IMPORT_ALL) import_all = TRUE;
attrib = (new_cat_num & 0x0F) | attrib = (unsigned char) ((new_cat_num & 0x0F) |
(priv ? dlpRecAttrSecret : 0); (priv ? dlpRecAttrSecret : 0));
if ((ret==DIALOG_SAID_IMPORT_YES) || (import_all)) { if ((ret == DIALOG_SAID_IMPORT_YES) || (import_all)) {
pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL); pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL);
} }
} }
} }
/* Palm Desktop DAT format */ /* Palm Desktop DAT format */
if (type==IMPORT_TYPE_DAT) { if (type == IMPORT_TYPE_DAT) {
jp_logf(JP_LOG_DEBUG, "Memo import DAT [%s]\n", file_path); jp_logf(JP_LOG_DEBUG, "Memo import DAT [%s]\n", file_path);
if (dat_check_if_dat_file(in)!=DAT_MEMO_FILE) { if (dat_check_if_dat_file(in) != DAT_MEMO_FILE) {
jp_logf(JP_LOG_WARN, _("File doesn't appear to be memopad.dat format\n" jp_logf(JP_LOG_WARN, _("File doesn't appear to be memopad.dat format
)); \n"));
fclose(in); fclose(in);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
memolist=NULL; memolist = NULL;
dat_get_memos(in, &memolist, &cai); dat_get_memos(in, &memolist, &cai);
import_all=FALSE; import_all = FALSE;
for (temp_memolist=memolist; temp_memolist; temp_memolist=temp_memolist->n for (temp_memolist = memolist; temp_memolist; temp_memolist = temp_memol
ext) { ist->next) {
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
printf("category=%d\n", temp_memolist->mmemo.unique_id); printf("category=%d\n", temp_memolist->mmemo.unique_id);
printf("attrib=%d\n", temp_memolist->mmemo.attrib); printf("attrib=%d\n", temp_memolist->mmemo.attrib);
printf("private=%d\n", temp_memolist->mmemo.attrib & 0x10); printf("private=%d\n", temp_memolist->mmemo.attrib & 0x10);
printf("memo=[%s]\n", temp_memolist->mmemo.memo.text); printf("memo=[%s]\n", temp_memolist->mmemo.memo.text);
#endif #endif
new_memo.text=temp_memolist->mmemo.memo.text; new_memo.text = temp_memolist->mmemo.memo.text;
index=temp_memolist->mmemo.unique_id-1; index = temp_memolist->mmemo.unique_id - 1;
if (index<0) { if (index < 0) {
g_strlcpy(old_cat_name, _("Unfiled"), 16); g_strlcpy(old_cat_name, _("Unfiled"), 16);
index=0; index = 0;
} else { } else {
g_strlcpy(old_cat_name, cai.name[index], 16); g_strlcpy(old_cat_name, cai.name[index], 16);
} }
attrib=0; attrib = 0;
/* Figure out what category it was in the dat file */ /* Figure out what category it was in the dat file */
index=temp_memolist->mmemo.unique_id-1; index = temp_memolist->mmemo.unique_id - 1;
suggested_cat_num=0; suggested_cat_num = 0;
if (index>-1) { if (index > -1) {
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { for (i = 0; i < NUM_MEMO_CAT_ITEMS; i++) {
if (memo_app_info.category.name[i][0]=='\0') continue; if (memo_app_info.category.name[i][0] == '\0') continue;
if (!strcmp(memo_app_info.category.name[i], old_cat_name)) { if (!strcmp(memo_app_info.category.name[i], old_cat_name)) {
suggested_cat_num=i; suggested_cat_num = i;
break; break;
} }
}
} }
}
ret=0; ret = 0;
if (!import_all) { if (!import_all) {
ret=import_record_ask(parent_window, pane, ret = import_record_ask(parent_window, pane,
new_memo.text, new_memo.text,
&(memo_app_info.category), &(memo_app_info.category),
old_cat_name, old_cat_name,
(temp_memolist->mmemo.attrib & 0x10), (temp_memolist->mmemo.attrib & 0x10),
suggested_cat_num, suggested_cat_num,
&new_cat_num); &new_cat_num);
} else { } else {
new_cat_num=suggested_cat_num; new_cat_num = suggested_cat_num;
} }
if (ret==DIALOG_SAID_IMPORT_QUIT) break; if (ret == DIALOG_SAID_IMPORT_QUIT) break;
if (ret==DIALOG_SAID_IMPORT_SKIP) continue; if (ret == DIALOG_SAID_IMPORT_SKIP) continue;
if (ret==DIALOG_SAID_IMPORT_ALL) import_all=TRUE; if (ret == DIALOG_SAID_IMPORT_ALL) import_all = TRUE;
attrib = (new_cat_num & 0x0F) | attrib = (unsigned char) ((new_cat_num & 0x0F) |
((temp_memolist->mmemo.attrib & 0x10) ? dlpRecAttrSecret : 0); ((temp_memolist->mmemo.attrib & 0x10) ? dl
if ((ret==DIALOG_SAID_IMPORT_YES) || (import_all)) { pRecAttrSecret : 0));
pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL); if ((ret == DIALOG_SAID_IMPORT_YES) || (import_all)) {
} pc_memo_write(&new_memo, NEW_PC_REC, attrib, NULL);
} }
free_MemoList(&memolist); }
} free_MemoList(&memolist);
}
memo_refresh();
fclose(in); memo_refresh();
return EXIT_SUCCESS; fclose(in);
} return EXIT_SUCCESS;
}
int memo_import(GtkWidget *window)
{ int memo_import(GtkWidget *window) {
char *type_desc[] = { char *type_desc[] = {
N_("Text"), N_("Text"),
N_("CSV (Comma Separated Values)"), N_("CSV (Comma Separated Values)"),
N_("DAT/MPA (Palm Archive Formats)"), N_("DAT/MPA (Palm Archive Formats)"),
NULL NULL
}; };
int type_int[] = { int type_int[] = {
IMPORT_TYPE_TEXT, IMPORT_TYPE_TEXT,
IMPORT_TYPE_CSV, IMPORT_TYPE_CSV,
IMPORT_TYPE_DAT, IMPORT_TYPE_DAT,
0 0
}; };
/* Hide ABA import of Memos until file format has been decoded */ /* Hide ABA import of Memos until file format has been decoded */
if (memo_version==1) { if (memo_version == 1) {
type_desc[2] = NULL; type_desc[2] = NULL;
type_int[2] = 0; type_int[2] = 0;
} }
import_gui(window, pane, type_desc, type_int, cb_memo_import); import_gui(window, pane, type_desc, type_int, cb_memo_import);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* End Import Code */ /* End Import Code */
/* Start Export code */ /* Start Export code */
static void cb_memo_export_ok(GtkWidget *export_window, GtkWidget *clist, static void cb_memo_export_ok(GtkWidget *export_window, GtkWidget *treeView,
int type, const char *filename) int type, const char *filename) {
{ MyMemo *mmemo;
MyMemo *mmemo; GList *list, *temp_list;
GList *list, *temp_list; FILE *out;
FILE *out; struct stat statb;
struct stat statb; int i, r, len;
int i, r, len; const char *short_date;
const char *short_date; time_t ltime;
time_t ltime; struct tm *now;
struct tm *now; char *button_text[] = {N_("OK")};
char *button_text[]={N_("OK")}; char *button_overwrite_text[] = {N_("No"), N_("Yes")};
char *button_overwrite_text[]={N_("No"), N_("Yes")}; char text[1024];
char text[1024]; char str1[256], str2[256];
char str1[256], str2[256]; char date_string[1024];
char date_string[1024]; char pref_time[40];
char pref_time[40]; char csv_text[65550];
char csv_text[65550]; long char_set;
long char_set; char *utf;
char *utf; int cat;
int cat; int j;
int j;
/* Open file for export, including corner cases where file exists or
/* Open file for export, including corner cases where file exists or * can't be opened */
* can't be opened */ if (!stat(filename, &statb)) {
if (!stat(filename, &statb)) { if (S_ISDIR(statb.st_mode)) {
if (S_ISDIR(statb.st_mode)) { g_snprintf(text, sizeof(text), _("%s is a directory"), filename);
g_snprintf(text, sizeof(text), _("%s is a directory"), filename); dialog_generic(GTK_WINDOW(export_window),
dialog_generic(GTK_WINDOW(export_window), _("Error Opening File"),
_("Error Opening File"), DIALOG_ERROR, text, 1, button_text);
DIALOG_ERROR, text, 1, button_text); return;
return; }
} g_snprintf(text, sizeof(text), _("Do you want to overwrite file %s?"), f
g_snprintf(text,sizeof(text), _("Do you want to overwrite file %s?"), file ilename);
name); r = dialog_generic(GTK_WINDOW(export_window),
r = dialog_generic(GTK_WINDOW(export_window), _("Overwrite File?"),
_("Overwrite File?"), DIALOG_ERROR, text, 2, button_overwrite_text);
DIALOG_ERROR, text, 2, button_overwrite_text); if (r != DIALOG_SAID_2) {
if (r!=DIALOG_SAID_2) { return;
return; }
} }
}
out = fopen(filename, "w");
out = fopen(filename, "w"); if (!out) {
if (!out) { g_snprintf(text, sizeof(text), _("Error opening file: %s"), filename);
g_snprintf(text,sizeof(text), _("Error opening file: %s"), filename); dialog_generic(GTK_WINDOW(export_window),
dialog_generic(GTK_WINDOW(export_window), _("Error Opening File"),
_("Error Opening File"), DIALOG_ERROR, text, 1, button_text);
DIALOG_ERROR, text, 1, button_text); return;
return; }
}
/* Write a header for TEXT file */
/* Write a header for TEXT file */ if (type == EXPORT_TYPE_TEXT) {
if (type == EXPORT_TYPE_TEXT) { get_pref(PREF_SHORTDATE, NULL, &short_date);
get_pref(PREF_SHORTDATE, NULL, &short_date); get_pref_time_no_secs(pref_time);
get_pref_time_no_secs(pref_time); time(&ltime);
time(&ltime); now = localtime(&ltime);
now = localtime(&ltime); strftime(str1, sizeof(str1), short_date, now);
strftime(str1, sizeof(str1), short_date, now); strftime(str2, sizeof(str2), pref_time, now);
strftime(str2, sizeof(str2), pref_time, now); g_snprintf(date_string, sizeof(date_string), "%s %s", str1, str2);
g_snprintf(date_string, sizeof(date_string), "%s %s", str1, str2); if (memo_version == 0) {
if (memo_version==0) { fprintf(out, _("Memo exported from %s %s on %s\n\n"),
fprintf(out, _("Memo exported from %s %s on %s\n\n"), PN, VERSION, date_string);
PN,VERSION,date_string); } else {
} else { fprintf(out, _("Memos exported from %s %s on %s\n\n"),
fprintf(out, _("Memos exported from %s %s on %s\n\n"), PN, VERSION, date_string);
PN,VERSION,date_string); }
} }
}
/* Write a header to the CSV file */
/* Write a header to the CSV file */ if (type == EXPORT_TYPE_CSV) {
if (type == EXPORT_TYPE_CSV) { if (memo_version == 0) {
if (memo_version==0) { fprintf(out, "CSV memo version "VERSION": Category, Private, Memo Te
fprintf(out, "CSV memo version "VERSION": Category, Private, Memo Text\ xt\n");
n"); } else {
} else { fprintf(out, "CSV memos version "VERSION": Category, Private, Memo T
fprintf(out, "CSV memos version "VERSION": Category, Private, Memo Text ext\n");
\n"); }
} }
}
/* Write a header to the BFOLDERS CSV file */
/* Write a header to the BFOLDERS CSV file */ if (type == EXPORT_TYPE_BFOLDERS) {
if (type == EXPORT_TYPE_BFOLDERS) { fprintf(out, "Notes:\n");
fprintf(out, "Notes:\n"); fprintf(out, "Note,Folder\n");
fprintf(out, "Note,Folder\n"); }
}
/* Write a header to the KeePassX XML file */
/* Write a header to the KeePassX XML file */ if (type == EXPORT_TYPE_KEEPASSX) {
if (type == EXPORT_TYPE_KEEPASSX) { fprintf(out, "<!DOCTYPE KEEPASSX_DATABASE>\n");
fprintf(out, "<!DOCTYPE KEEPASSX_DATABASE>\n"); fprintf(out, "<database>\n");
fprintf(out, "<database>\n"); fprintf(out, " <group>\n");
fprintf(out, " <group>\n"); fprintf(out, " <title>Memos</title>\n");
fprintf(out, " <title>Memos</title>\n"); fprintf(out, " <icon>7</icon>\n");
fprintf(out, " <icon>7</icon>\n"); }
}
get_pref(PREF_CHAR_SET, &char_set, NULL);
get_pref(PREF_CHAR_SET, &char_set, NULL); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree
list=GTK_CLIST(clist)->selection; View));
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeView));
for (i=0, temp_list=list; temp_list; temp_list = temp_list->next, i++) { list = gtk_tree_selection_get_selected_rows(selection, &model);
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_INT(temp_list
->data)); for (i = 0, temp_list = list; temp_list; temp_list = temp_list->next, i++) {
if (!mmemo) { GtkTreePath *path = temp_list->data;
continue; GtkTreeIter iter;
jp_logf(JP_LOG_WARN, _("Can't export memo %d\n"), (long) temp_list->dat if (gtk_tree_model_get_iter(model, &iter, path)) {
a + 1); gtk_tree_model_get(model, &iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
} if (!mmemo) {
switch (type) { continue;
case EXPORT_TYPE_CSV: jp_logf(JP_LOG_WARN, _("Can't export memo %d\n"), (long) temp_li
len=0; st->data + 1);
if (mmemo->memo.text) { }
len=strlen(mmemo->memo.text) * 2 + 4; switch (type) {
} case EXPORT_TYPE_CSV:
if (len<256) len=256; len = 0;
utf = charset_p2newj(memo_app_info.category.name[mmemo->attrib & 0x0F], if (mmemo->memo.text) {
16, char_set); len = (unsigned int) strlen(mmemo->memo.text) * 2 + 4;
str_to_csv_str(csv_text, utf); }
fprintf(out, "\"%s\",", csv_text); if (len < 256) len = 256;
g_free(utf); utf = charset_p2newj(memo_app_info.category.name[mmemo->attr
fprintf(out, "\"%s\",", (mmemo->attrib & dlpRecAttrSecret) ? "1":"0"); ib & 0x0F], 16, (int) char_set);
str_to_csv_str(csv_text, mmemo->memo.text); str_to_csv_str(csv_text, utf);
fprintf(out, "\"%s\"\n", csv_text); fprintf(out, "\"%s\",", csv_text);
break; g_free(utf);
fprintf(out, "\"%s\",", (mmemo->attrib & dlpRecAttrSecret) ?
case EXPORT_TYPE_BFOLDERS: "1" : "0");
len=0; str_to_csv_str(csv_text, mmemo->memo.text);
str_to_csv_str(csv_text, mmemo->memo.text); fprintf(out, "\"%s\"\n", csv_text);
fprintf(out, "\"%s\",", csv_text); break;
if (mmemo->memo.text) { case EXPORT_TYPE_BFOLDERS:
len=strlen(mmemo->memo.text) * 2 + 4; len = 0;
} str_to_csv_str(csv_text, mmemo->memo.text);
if (len<256) len=256; fprintf(out, "\"%s\",", csv_text);
printf("\"RAW %d %s\"\n", mmemo->attrib & 0x0F, memo_app_info.category.n
ame[mmemo->attrib & 0x0F]); if (mmemo->memo.text) {
utf = charset_p2newj(memo_app_info.category.name[mmemo->attrib & 0x0F], len = (unsigned int) strlen(mmemo->memo.text) * 2 + 4;
16, char_set); }
str_to_csv_str(csv_text, utf); if (len < 256) len = 256;
fprintf(out, "\"Memos > %s\"\n", csv_text); printf("\"RAW %d %s\"\n", mmemo->attrib & 0x0F, memo_app_inf
printf("\"Memos > %s\"\n", utf); o.category.name[mmemo->attrib & 0x0F]);
g_free(utf); utf = charset_p2newj(memo_app_info.category.name[mmemo->attr
break; ib & 0x0F], 16, (int) char_set);
str_to_csv_str(csv_text, utf);
case EXPORT_TYPE_TEXT: fprintf(out, "\"Memos > %s\"\n", csv_text);
get_pref(PREF_SHORTDATE, NULL, &short_date); printf("\"Memos > %s\"\n", utf);
get_pref_time_no_secs(pref_time); g_free(utf);
time(&ltime); break;
now = localtime(&ltime);
strftime(str1, sizeof(str1), short_date, now); case EXPORT_TYPE_TEXT:
strftime(str2, sizeof(str2), pref_time, now); get_pref(PREF_SHORTDATE, NULL, &short_date);
g_snprintf(text, sizeof(text), "%s %s", str1, str2); get_pref_time_no_secs(pref_time);
time(&ltime);
fprintf(out, _("Memo: %ld\n"), (long) temp_list->data + 1); now = localtime(&ltime);
utf = charset_p2newj(memo_app_info.category.name[mmemo->attrib & 0x0F], strftime(str1, sizeof(str1), short_date, now);
16, char_set); strftime(str2, sizeof(str2), pref_time, now);
fprintf(out, _("Category: %s\n"), utf); g_snprintf(text, sizeof(text), "%s %s", str1, str2);
g_free(utf);
fprintf(out, _("Private: %s\n"), fprintf(out, _("Memo: %ld\n"), (long) temp_list->data + 1);
(mmemo->attrib & dlpRecAttrSecret) ? _("Yes"):_("No")); utf = charset_p2newj(memo_app_info.category.name[mmemo->attr
fprintf(out, _("----- Start of Memo -----\n")); ib & 0x0F], 16, (int) char_set);
fprintf(out, "%s", mmemo->memo.text); fprintf(out, _("Category: %s\n"), utf);
fprintf(out, _("\n----- End of Memo -----\n\n")); g_free(utf);
break; fprintf(out, _("Private: %s\n"),
(mmemo->attrib & dlpRecAttrSecret) ? _("Yes") : _("N
case EXPORT_TYPE_KEEPASSX: o"));
break; fprintf(out, _("----- Start of Memo -----\n"));
fprintf(out, "%s", mmemo->memo.text);
default: fprintf(out, _("\n----- End of Memo -----\n\n"));
jp_logf(JP_LOG_WARN, _("Unknown export type\n")); break;
}
}
/* I'm writing a second loop for the KeePassX XML file because I want to
* put each category into a folder and we need to write the tag for a folder
* and then find each record in that category/folder
*/
if (type==EXPORT_TYPE_KEEPASSX) {
for (cat=0; cat < 16; cat++) {
if (memo_app_info.category.name[cat][0]=='\0') {
continue;
}
/* Write a folder XML tag */
utf = charset_p2newj(memo_app_info.category.name[cat], 16, char_set);
fprintf(out, " <group>\n");
fprintf(out, " <title>%s</title>\n", utf);
fprintf(out, " <icon>7</icon>\n");
g_free(utf);
for (i=0, temp_list=list; temp_list; temp_list = temp_list->next, i++) {
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_INT(temp
_list->data));
if (!mmemo) {
continue;
jp_logf(JP_LOG_WARN, _("Can't export memo %d\n"), (long) temp_list
->data + 1);
}
if ((mmemo->attrib & 0x0F) != cat) {
continue;
}
fprintf(out, " <entry>\n");
/* Create a title (which is the first line of the memo) */
for (j=0; j<100; j++) {
str1[j]=mmemo->memo.text[j];
if (str1[j] == '\0') {
break;
}
if (str1[j] == '\n') {
str1[j]='\0';
break;
}
}
str1[100]='\0';
str_to_keepass_str(csv_text, str1);
fprintf(out, " <title>%s</title>\n", csv_text);
/* No keyring field for username */
/* No keyring field for password */
/* No keyring field for url */
str_to_keepass_str(csv_text, mmemo->memo.text);
fprintf(out, " <comment>%s</comment>\n", csv_text);
fprintf(out, " <icon>7</icon>\n");
/* No keyring field for creation */
/* No keyring field for lastaccess */
/* No keyring field for lastmod */
/* No keyring field for expire */
fprintf(out, " <expire>Never</expire>\n");
fprintf(out, " </entry>\n");
}
fprintf(out, " </group>\n");
}
/* Write a footer to the KeePassX XML file */
if (type == EXPORT_TYPE_KEEPASSX) {
fprintf(out, " </group>\n");
fprintf(out, "</database>\n");
}
}
if (out) {
fclose(out);
}
}
static void cb_memo_update_clist(GtkWidget *clist, int category)
{
memo_update_clist(clist, NULL, &export_memo_list, category, FALSE);
}
static void cb_memo_export_done(GtkWidget *widget, const char *filename)
{
free_MemoList(&export_memo_list);
set_pref(PREF_MEMO_EXPORT_FILENAME, 0, filename, TRUE);
}
int memo_export(GtkWidget *window)
{
int w, h, x, y;
char *type_text[]={N_("Text"),
N_("CSV"),
N_("B-Folders CSV"),
N_("KeePassX XML"),
NULL};
int type_int[]={EXPORT_TYPE_TEXT, EXPORT_TYPE_CSV, EXPORT_TYPE_BFOLDERS, EXPO
RT_TYPE_KEEPASSX};
gdk_window_get_size(window->window, &w, &h);
gdk_window_get_root_origin(window->window, &x, &y);
w = gtk_paned_get_position(GTK_PANED(pane));
x+=40;
export_gui(window,
w, h, x, y, 1, sort_l,
PREF_MEMO_EXPORT_FILENAME,
type_text,
type_int,
cb_memo_update_clist,
cb_memo_export_done,
cb_memo_export_ok
);
return EXIT_SUCCESS; case EXPORT_TYPE_KEEPASSX:
break;
default:
jp_logf(JP_LOG_WARN, _("Unknown export type\n"));
}
}
}
/* I'm writing a second loop for the KeePassX XML file because I want to
* put each category into a folder and we need to write the tag for a folder
* and then find each record in that category/folder
*/
if (type == EXPORT_TYPE_KEEPASSX) {
for (cat = 0; cat < 16; cat++) {
if (memo_app_info.category.name[cat][0] == '\0') {
continue;
}
/* Write a folder XML tag */
utf = charset_p2newj(memo_app_info.category.name[cat], 16, (int) cha
r_set);
fprintf(out, " <group>\n");
fprintf(out, " <title>%s</title>\n", utf);
fprintf(out, " <icon>7</icon>\n");
g_free(utf);
for (i = 0, temp_list = list; temp_list; temp_list = temp_list->next
, i++) {
GtkTreePath *path = temp_list->data;
GtkTreeIter iter;
if (gtk_tree_model_get_iter(model, &iter, path)) {
gtk_tree_model_get(model, &iter, MEMO_DATA_COLUMN_ENUM, &mme
mo, -1);
if (!mmemo) {
continue;
jp_logf(JP_LOG_WARN, _("Can't export memo %d\n"), (long)
temp_list->data + 1);
}
if ((mmemo->attrib & 0x0F) != cat) {
continue;
}
fprintf(out, " <entry>\n");
/* Create a title (which is the first line of the memo) */
for (j = 0; j < 100; j++) {
str1[j] = mmemo->memo.text[j];
if (str1[j] == '\0') {
break;
}
if (str1[j] == '\n') {
str1[j] = '\0';
break;
}
}
str1[100] = '\0';
str_to_keepass_str(csv_text, str1);
fprintf(out, " <title>%s</title>\n", csv_text);
/* No keyring field for username */
/* No keyring field for password */
/* No keyring field for url */
str_to_keepass_str(csv_text, mmemo->memo.text);
fprintf(out, " <comment>%s</comment>\n", csv_text);
fprintf(out, " <icon>7</icon>\n");
/* No keyring field for creation */
/* No keyring field for lastaccess */
/* No keyring field for lastmod */
/* No keyring field for expire */
fprintf(out, " <expire>Never</expire>\n");
fprintf(out, " </entry>\n");
}
fprintf(out, " </group>\n");
}
}
/* Write a footer to the KeePassX XML file */
if (type == EXPORT_TYPE_KEEPASSX) {
fprintf(out, " </group>\n");
fprintf(out, "</database>\n");
}
}
if (out) {
fclose(out);
}
}
static void cb_memo_update_listStore(GtkWidget *treeView, int category) {
memo_update_liststore(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(t
reeView))), NULL, &export_memo_list,
category, FALSE);
}
static GtkWidget *cb_memo_init_export_treeView() {
GtkListStore *listStore = gtk_list_store_new(MEMO_NUM_COLS, G_TYPE_STRING, G
_TYPE_POINTER, GDK_TYPE_RGBA,
G_TYPE_BOOLEAN, G_TYPE_STRING,
G_TYPE_BOOLEAN);
GtkWidget *treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(listStore)
);
treeView = GTK_WIDGET(gtk_tree_view_new_with_model(GTK_TREE_MODEL(listStore)
));
GtkCellRenderer *columnRenderer = gtk_cell_renderer_text_new();
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes("", col
umnRenderer, "text", MEMO_COLUMN_ENUM,
"cell-b
ackground-rgba",
MEMO_BA
CKGROUND_COLOR_ENUM,
"cell-b
ackground-set",
MEMO_BA
CKGROUND_COLOR_ENABLED_ENUM, NULL);
gtk_tree_view_column_set_fixed_width(column, (gint) 50);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), FALSE);
gtk_tree_view_insert_column(GTK_TREE_VIEW(treeView), column, 0);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
return GTK_WIDGET(treeView);
}
static void cb_memo_export_done(GtkWidget *widget, const char *filename) {
free_MemoList(&export_memo_list);
set_pref(PREF_MEMO_EXPORT_FILENAME, 0, filename, TRUE);
}
int memo_export(GtkWidget *window) {
int w, h, x, y;
char *type_text[] = {N_("Text"),
N_("CSV"),
N_("B-Folders CSV"),
N_("KeePassX XML"),
NULL};
int type_int[] = {EXPORT_TYPE_TEXT, EXPORT_TYPE_CSV, EXPORT_TYPE_BFOLDERS, E
XPORT_TYPE_KEEPASSX};
w = gdk_window_get_width(gtk_widget_get_window(window));
h = gdk_window_get_height(gtk_widget_get_window(window));
gdk_window_get_root_origin(gtk_widget_get_window(window), &x, &y);
w = gtk_paned_get_position(GTK_PANED(pane));
x += 40;
export_gui(window,
w, h, x, y, 1, sort_l,
PREF_MEMO_EXPORT_FILENAME,
type_text,
type_int,
cb_memo_init_export_treeView,
cb_memo_update_listStore,
cb_memo_export_done,
cb_memo_export_ok
);
return EXIT_SUCCESS;
} }
/* End Export Code */ /* End Export Code */
/* Find position of category in sorted category array /* Find position of category in sorted category array
* via its assigned category number */ * via its assigned category number */
static int find_sort_cat_pos(int cat) static int find_sort_cat_pos(int cat) {
{ int i;
int i;
for (i = 0; i < NUM_MEMO_CAT_ITEMS; i++) {
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { if (sort_l[i].cat_num == cat) {
if (sort_l[i].cat_num==cat) { return i;
return i; }
} }
}
return -1; return -1;
} }
/* Find a category's position in the category menu. /* Find a category's position in the category menu.
* This is equal to the category number except for the Unfiled category. * This is equal to the category number except for the Unfiled category.
* The Unfiled category is always in the last position which changes as * The Unfiled category is always in the last position which changes as
* the number of categories changes */ * the number of categories changes */
static int find_menu_cat_pos(int cat) static int find_menu_cat_pos(int cat) {
{ int i;
int i;
if (cat != NUM_MEMO_CAT_ITEMS - 1) {
if (cat != NUM_MEMO_CAT_ITEMS-1) { return cat;
return cat; } else { /* Unfiled category */
} else { /* Unfiled category */ /* Count how many category entries are filled */
/* Count how many category entries are filled */ for (i = 0; i < NUM_MEMO_CAT_ITEMS; i++) {
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { if (!sort_l[i].Pcat[0]) {
if (!sort_l[i].Pcat[0]) { return i;
return i; }
} }
} return 0;
return 0; }
} }
gboolean deleteRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
int *i = gtk_tree_path_get_indices(path);
if (i[0] == row_selected) {
MyMemo *mmemo = NULL;
gtk_tree_model_get(model, iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
delete_memo(mmemo, data);
return TRUE;
}
return FALSE;
}
gboolean undeleteRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
int *i = gtk_tree_path_get_indices(path);
if (i[0] == row_selected) {
MyMemo *mmemo = NULL;
gtk_tree_model_get(model, iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
undelete_memo(mmemo, data);
return TRUE;
}
return FALSE;
}
void delete_memo(MyMemo *mmemo, gpointer data) {
int flag;
int show_priv;
long char_set;
if (mmemo < (MyMemo *) LIST_MIN_DATA) {
return;
}
/* Convert to Palm character set */
get_pref(PREF_CHAR_SET, &char_set, NULL);
if (char_set != CHAR_SET_LATIN1) {
if (mmemo->memo.text)
charset_j2p(mmemo->memo.text, strlen(mmemo->memo.text) + 1, (int) ch
ar_set);
}
/* Do masking like Palm OS 3.5 */
show_priv = show_privates(GET_PRIVATES);
if ((show_priv != SHOW_PRIVATES) &&
(mmemo->attrib & dlpRecAttrSecret)) {
return;
}
/* End Masking */
jp_logf(JP_LOG_DEBUG, "mmemo->unique_id = %d\n", mmemo->unique_id);
jp_logf(JP_LOG_DEBUG, "mmemo->rt = %d\n", mmemo->rt);
flag = GPOINTER_TO_INT(data);
if ((flag == MODIFY_FLAG) || (flag == DELETE_FLAG)) {
delete_pc_record(MEMO, mmemo, flag);
if (flag == DELETE_FLAG) {
/* when we redraw we want to go to the line above the deleted one */
if (row_selected > 0) {
row_selected--;
}
}
}
if (flag == DELETE_FLAG) {
memo_redraw();
}
} }
static void cb_delete_memo(GtkWidget *widget, static void cb_delete_memo(GtkWidget *widget,
gpointer data) const void *data) {
{ gtk_tree_model_foreach(GTK_TREE_MODEL(listStore), deleteRecordMemo, (gpointe
MyMemo *mmemo; r) data);
int flag; return;
int show_priv;
long char_set; }
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), clist_row_selected); void undelete_memo(MyMemo *mmemo, gpointer data) {
if (mmemo < (MyMemo *)CLIST_MIN_DATA) {
return; int flag;
} int show_priv;
/* Convert to Palm character set */
get_pref(PREF_CHAR_SET, &char_set, NULL); if (mmemo < (MyMemo *) LIST_MIN_DATA) {
if (char_set != CHAR_SET_LATIN1) { return;
if (mmemo->memo.text) }
charset_j2p(mmemo->memo.text, strlen(mmemo->memo.text)+1, char_set);
} /* Do masking like Palm OS 3.5 */
show_priv = show_privates(GET_PRIVATES);
/* Do masking like Palm OS 3.5 */ if ((show_priv != SHOW_PRIVATES) &&
show_priv = show_privates(GET_PRIVATES); (mmemo->attrib & dlpRecAttrSecret)) {
if ((show_priv != SHOW_PRIVATES) && return;
(mmemo->attrib & dlpRecAttrSecret)) { }
return; /* End Masking */
}
/* End Masking */ jp_logf(JP_LOG_DEBUG, "mmemo->unique_id = %d\n", mmemo->unique_id);
jp_logf(JP_LOG_DEBUG, "mmemo->unique_id = %d\n",mmemo->unique_id); jp_logf(JP_LOG_DEBUG, "mmemo->rt = %d\n", mmemo->rt);
jp_logf(JP_LOG_DEBUG, "mmemo->rt = %d\n",mmemo->rt);
flag = GPOINTER_TO_INT(data); flag = GPOINTER_TO_INT(data);
if ((flag==MODIFY_FLAG) || (flag==DELETE_FLAG)) { if (flag == UNDELETE_FLAG) {
delete_pc_record(MEMO, mmemo, flag); if (mmemo->rt == DELETED_PALM_REC ||
if (flag==DELETE_FLAG) { mmemo->rt == DELETED_PC_REC) {
/* when we redraw we want to go to the line above the deleted one */ undelete_pc_record(MEMO, mmemo, flag);
if (clist_row_selected>0) { }
clist_row_selected--; /* Possible later addition of undelete for modified records
} else if (mmemo->rt == MODIFIED_PALM_REC)
} {
} cb_add_new_record(widget, GINT_TO_POINTER(COPY_FLAG));
}
if (flag == DELETE_FLAG) { */
memo_clist_redraw(); }
}
memo_redraw();
} }
static void cb_undelete_memo(GtkWidget *widget, static void cb_undelete_memo(GtkWidget *widget,
gpointer data) gpointer data) {
{
MyMemo *mmemo; gtk_tree_model_foreach(GTK_TREE_MODEL(listStore), undeleteRecordMemo, data);
int flag; return;
int show_priv;
}
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), clist_row_selected);
if (mmemo < (MyMemo *)CLIST_MIN_DATA) { static void cb_cancel(GtkWidget *widget, gpointer data) {
return; set_new_button_to(CLEAR_FLAG);
} memo_refresh();
}
/* Do masking like Palm OS 3.5 */
show_priv = show_privates(GET_PRIVATES); static void cb_edit_cats(GtkWidget *widget, gpointer data) {
if ((show_priv != SHOW_PRIVATES) && struct MemoAppInfo ai;
(mmemo->attrib & dlpRecAttrSecret)) { char db_name[FILENAME_MAX];
return; char pdb_name[FILENAME_MAX];
} char full_name[FILENAME_MAX];
/* End Masking */ unsigned char buffer[65536];
int num;
jp_logf(JP_LOG_DEBUG, "mmemo->unique_id = %d\n",mmemo->unique_id); size_t size;
jp_logf(JP_LOG_DEBUG, "mmemo->rt = %d\n",mmemo->rt); void *buf;
struct pi_file *pf;
flag = GPOINTER_TO_INT(data); long memo_version;
if (flag==UNDELETE_FLAG) {
if (mmemo->rt == DELETED_PALM_REC || jp_logf(JP_LOG_DEBUG, "cb_edit_cats\n");
mmemo->rt == DELETED_PC_REC)
{ get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
undelete_pc_record(MEMO, mmemo, flag);
} switch (memo_version) {
/* Possible later addition of undelete for modified records case 0:
else if (mmemo->rt == MODIFIED_PALM_REC) default:
{ strcpy(pdb_name, "MemoDB.pdb");
cb_add_new_record(widget, GINT_TO_POINTER(COPY_FLAG)); strcpy(db_name, "MemoDB");
} break;
*/ case 1:
} strcpy(pdb_name, "MemosDB-PMem.pdb");
strcpy(db_name, "MemosDB-PMem");
memo_clist_redraw(); break;
} case 2:
strcpy(pdb_name, "Memo32DB.pdb");
static void cb_cancel(GtkWidget *widget, gpointer data) strcpy(db_name, "Memo32DB");
{ break;
set_new_button_to(CLEAR_FLAG); }
memo_refresh();
} get_home_file_name(pdb_name, full_name, sizeof(full_name));
static void cb_edit_cats(GtkWidget *widget, gpointer data) buf = NULL;
{ memset(&ai, 0, sizeof(ai));
struct MemoAppInfo ai;
char db_name[FILENAME_MAX]; pf = pi_file_open(full_name);
char pdb_name[FILENAME_MAX]; pi_file_get_app_info(pf, &buf, &size);
char full_name[FILENAME_MAX];
unsigned char buffer[65536]; num = unpack_MemoAppInfo(&ai, buf, size);
int num; if (num <= 0) {
size_t size; jp_logf(JP_LOG_WARN, _("Error reading file: %s\n"), pdb_name);
void *buf; return;
struct pi_file *pf; }
long memo_version;
pi_file_close(pf);
jp_logf(JP_LOG_DEBUG, "cb_edit_cats\n");
edit_cats(widget, db_name, &(ai.category));
get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
size = pack_MemoAppInfo(&ai, buffer, sizeof(buffer));
switch (memo_version) {
case 0: pdb_file_write_app_block(db_name, buffer, size);
default:
strcpy(pdb_name, "MemoDB.pdb"); cb_app_button(NULL, GINT_TO_POINTER(REDRAW));
strcpy(db_name, "MemoDB"); }
break;
case 1: static void cb_category(GtkComboBox *item, int selection) {
strcpy(pdb_name, "MemosDB-PMem.pdb"); int b;
strcpy(db_name, "MemosDB-PMem"); if (!item) return;
break; if (gtk_combo_box_get_active(GTK_COMBO_BOX(item)) < 0) {
case 2: return;
strcpy(pdb_name, "Memo32DB.pdb"); }
strcpy(db_name, "Memo32DB"); int selectedItem = get_selected_category_from_combo_box(item);
break; if (selectedItem == -1) {
} return;
}
get_home_file_name(pdb_name, full_name, sizeof(full_name));
buf=NULL;
memset(&ai, 0, sizeof(ai));
pf = pi_file_open(full_name);
pi_file_get_app_info(pf, &buf, &size);
num = unpack_MemoAppInfo(&ai, buf, size);
if (num <= 0) {
jp_logf(JP_LOG_WARN, _("Error reading file: %s\n"), pdb_name);
return;
}
pi_file_close(pf);
edit_cats(widget, db_name, &(ai.category));
size = pack_MemoAppInfo(&ai, buffer, sizeof(buffer));
pdb_file_write_app_block(db_name, buffer, size);
cb_app_button(NULL, GINT_TO_POINTER(REDRAW));
}
static void cb_category(GtkWidget *item, int selection)
{
int b;
if ((GTK_CHECK_MENU_ITEM(item))->active) {
if (memo_category == selection) { return; }
b=dialog_save_changed_record_with_cancel(pane, record_changed);
if (b==DIALOG_SAID_1) { /* Cancel */
int index, index2;
if (memo_category==CATEGORY_ALL) { if (memo_category == selectedItem) { return; }
index = 0;
b = dialog_save_changed_record_with_cancel(pane, record_changed);
if (b == DIALOG_SAID_1) { /* Cancel */
int index, index2;
if (memo_category == CATEGORY_ALL) {
index = 0;
index2 = 0; index2 = 0;
} else { } else {
index = find_sort_cat_pos(memo_category); index = find_sort_cat_pos(memo_category);
index2 = find_menu_cat_pos(index) + 1; index2 = find_menu_cat_pos(index) + 1;
index += 1; index += 1;
} }
if (index<0) { if (index < 0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n")); jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else { } else {
gtk_check_menu_item_set_active gtk_combo_box_set_active(GTK_COMBO_BOX(category_menu1), index2);
(GTK_CHECK_MENU_ITEM(memo_cat_menu_item1[index]), TRUE); }
gtk_option_menu_set_history(GTK_OPTION_MENU(category_menu1), index2)
; return;
} }
if (b == DIALOG_SAID_3) { /* Save */
return; cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
} }
if (b==DIALOG_SAID_3) { /* Save */
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed)); if (selectedItem == CATEGORY_EDIT) {
} cb_edit_cats(GTK_WIDGET(item), NULL);
} else {
if (selection==NUM_MEMO_CAT_ITEMS+1) { memo_category = selectedItem;
cb_edit_cats(item, NULL); }
} else { row_selected = 0;
memo_category = selection; jp_logf(JP_LOG_DEBUG, "cb_category() cat=%d\n", memo_category);
} memo_update_liststore(listStore, category_menu1, &glob_memo_list, memo_categ
clist_row_selected = 0; ory, TRUE);
jp_logf(JP_LOG_DEBUG, "cb_category() cat=%d\n", memo_category); jp_logf(JP_LOG_DEBUG, "Leaving cb_category()\n");
memo_update_clist(clist, category_menu1, &glob_memo_list, memo_category, T
RUE);
jp_logf(JP_LOG_DEBUG, "Leaving cb_category()\n");
}
}
static int memo_clear_details(void)
{
int new_cat;
int sorted_position;
jp_logf(JP_LOG_DEBUG, "memo_clear_details()\n");
/* Need to disconnect signals first */
connect_changed_signals(DISCONNECT_SIGNALS);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer), "", -1);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(private_checkbox), FALSE);
if (memo_category==CATEGORY_ALL) {
new_cat = 0;
} else {
new_cat = memo_category;
}
sorted_position = find_sort_cat_pos(new_cat);
if (sorted_position<0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else {
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(memo_cat_menu_item2[sorted_position]), TRUE);
gtk_option_menu_set_history(GTK_OPTION_MENU(category_menu2),
find_menu_cat_pos(sorted_position));
}
set_new_button_to(CLEAR_FLAG);
connect_changed_signals(CONNECT_SIGNALS);
jp_logf(JP_LOG_DEBUG, "Leaving memo_clear_details()\n");
return EXIT_SUCCESS;
}
static int memo_get_details(struct Memo *new_memo, unsigned char *attrib)
{
int i;
GtkTextIter start_iter;
GtkTextIter end_iter;
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(memo_text_buffer),&start_iter,&end
_iter);
new_memo->text = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(memo_text_buffer),&
start_iter,&end_iter,TRUE);
if (new_memo->text[0]=='\0') {
free(new_memo->text);
new_memo->text=NULL;
}
/* Get the category that is set from the menu */
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) {
if (GTK_IS_WIDGET(memo_cat_menu_item2[i])) {
if (GTK_CHECK_MENU_ITEM(memo_cat_menu_item2[i])->active) {
*attrib = sort_l[i].cat_num;
break;
}
}
}
if (GTK_TOGGLE_BUTTON(private_checkbox)->active) {
*attrib |= dlpRecAttrSecret;
}
return EXIT_SUCCESS;
}
static void cb_add_new_record(GtkWidget *widget, gpointer data)
{
MyMemo *mmemo;
struct Memo new_memo;
unsigned char attrib;
int flag;
unsigned int unique_id;
int show_priv;
flag=GPOINTER_TO_INT(data);
mmemo=NULL;
unique_id=0;
/* Do masking like Palm OS 3.5 */
if ((flag==COPY_FLAG) || (flag==MODIFY_FLAG)) {
show_priv = show_privates(GET_PRIVATES);
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), clist_row_selected);
if (mmemo < (MyMemo *)CLIST_MIN_DATA) {
return;
}
if ((show_priv != SHOW_PRIVATES) &&
(mmemo->attrib & dlpRecAttrSecret)) {
return;
}
}
/* End Masking */
if (flag==CLEAR_FLAG) {
/* Clear button was hit */
memo_clear_details();
connect_changed_signals(DISCONNECT_SIGNALS);
set_new_button_to(NEW_FLAG);
gtk_widget_grab_focus(GTK_WIDGET(memo_text));
return;
}
if ((flag!=NEW_FLAG) && (flag!=MODIFY_FLAG) && (flag!=COPY_FLAG)) {
return;
}
if (flag==MODIFY_FLAG) {
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), clist_row_selected);
unique_id = mmemo->unique_id;
if (mmemo < (MyMemo *)CLIST_MIN_DATA) {
return;
}
if ((mmemo->rt==DELETED_PALM_REC) ||
(mmemo->rt==DELETED_PC_REC) ||
(mmemo->rt==MODIFIED_PALM_REC)) {
jp_logf(JP_LOG_INFO, _("You can't modify a record that is deleted\n"));
return;
}
}
memo_get_details(&new_memo, &attrib);
set_new_button_to(CLEAR_FLAG);
/* Keep unique ID intact */
if (flag==MODIFY_FLAG) {
cb_delete_memo(NULL, data);
if ((mmemo->rt==PALM_REC) || (mmemo->rt==REPLACEMENT_PALM_REC)) {
pc_memo_write(&new_memo, REPLACEMENT_PALM_REC, attrib, &unique_id);
} else {
unique_id=0;
pc_memo_write(&new_memo, NEW_PC_REC, attrib, &unique_id);
}
} else {
unique_id=0;
pc_memo_write(&new_memo, NEW_PC_REC, attrib, &unique_id);
}
free_Memo(&new_memo);
/* Don't return to modified record if search gui active */
if (!glob_find_id) {
glob_find_id = unique_id;
}
memo_clist_redraw();
return;
} }
/* Do masking like Palm OS 3.5 */ static int memo_clear_details(void) {
static void clear_mymemo(MyMemo *mmemo) int new_cat;
{ int sorted_position;
mmemo->unique_id=0;
mmemo->attrib=mmemo->attrib & 0xF8; jp_logf(JP_LOG_DEBUG, "memo_clear_details()\n");
if (mmemo->memo.text) {
free(mmemo->memo.text); /* Need to disconnect signals first */
mmemo->memo.text=strdup(""); connect_changed_signals(DISCONNECT_SIGNALS);
}
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer), "", -1);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(private_checkbox), FALSE);
return; if (memo_category == CATEGORY_ALL) {
new_cat = 0;
} else {
new_cat = memo_category;
}
sorted_position = find_sort_cat_pos(new_cat);
if (sorted_position < 0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else {
gtk_combo_box_set_active(GTK_COMBO_BOX(category_menu2),find_menu_cat_pos
(sorted_position));
}
set_new_button_to(CLEAR_FLAG);
connect_changed_signals(CONNECT_SIGNALS);
jp_logf(JP_LOG_DEBUG, "Leaving memo_clear_details()\n");
return EXIT_SUCCESS;
} }
/* End Masking */
static void cb_clist_selection(GtkWidget *clist, static int memo_get_details(struct Memo *new_memo, unsigned char *attrib) {
gint row, GtkTextIter start_iter;
gint column, GtkTextIter end_iter;
GdkEventButton *event,
gpointer data) gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(memo_text_buffer), &start_iter, &
{ end_iter);
struct Memo *memo; new_memo->text = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(memo_text_buffer),
MyMemo *mmemo; &start_iter, &end_iter, TRUE);
int b; if (new_memo->text[0] == '\0') {
int index, sorted_position; free(new_memo->text);
unsigned int unique_id = 0; new_memo->text = NULL;
}
if ((record_changed==MODIFY_FLAG) || (record_changed==NEW_FLAG)) {
if (clist_row_selected == row) { return; } /* Get the category that is set from the menu */
if (GTK_IS_WIDGET(category_menu2)) {
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), row); *attrib = get_selected_category_from_combo_box(GTK_COMBO_BOX(category_me
if (mmemo!=NULL) { nu2));
unique_id = mmemo->unique_id; }
} if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(private_checkbox))) {
*attrib |= dlpRecAttrSecret;
b=dialog_save_changed_record_with_cancel(pane, record_changed); }
if (b==DIALOG_SAID_1) { /* Cancel */ return EXIT_SUCCESS;
if (clist_row_selected >=0) }
{
clist_select_row(GTK_CLIST(clist), clist_row_selected, 0); gboolean
} else { addNewRecordMemo(GtkTreeModel *model,
clist_row_selected = 0; GtkTreePath *path,
clist_select_row(GTK_CLIST(clist), 0, 0); GtkTreeIter *iter,
} gpointer data) {
return;
} int *i = gtk_tree_path_get_indices(path);
if (b==DIALOG_SAID_3) { /* Save */
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed)); if (i[0] == row_selected) {
} MyMemo *mmemo = NULL;
gtk_tree_model_get(model, iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
set_new_button_to(CLEAR_FLAG); return addNewMemo(mmemo, data);
if (unique_id)
{
glob_find_id = unique_id;
memo_find();
} else {
clist_select_row(GTK_CLIST(clist), row, column);
}
return;
}
clist_row_selected=row;
mmemo = gtk_clist_get_row_data(GTK_CLIST(clist), row);
if (mmemo==NULL) {
return;
}
if (mmemo->rt == DELETED_PALM_REC ||
(mmemo->rt == DELETED_PC_REC))
/* Possible later addition of undelete code for modified deleted records
|| mmemo->rt == MODIFIED_PALM_REC
*/
{
set_new_button_to(UNDELETE_FLAG);
} else {
set_new_button_to(CLEAR_FLAG);
}
connect_changed_signals(DISCONNECT_SIGNALS);
memo=&(mmemo->memo);
index = mmemo->attrib & 0x0F;
sorted_position = find_sort_cat_pos(index);
if (memo_cat_menu_item2[sorted_position]==NULL) {
/* Illegal category */
jp_logf(JP_LOG_DEBUG, "Category is not legal\n");
index = sorted_position = 0;
}
if (sorted_position<0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else {
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(memo_cat_menu_item2[sorted_position]), TRUE);
}
gtk_option_menu_set_history(GTK_OPTION_MENU(category_menu2),
find_menu_cat_pos(sorted_position));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer), memo->text, -1);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(private_checkbox), }
mmemo->attrib & dlpRecAttrSecret);
return FALSE;
connect_changed_signals(CONNECT_SIGNALS);
} }
static gboolean cb_key_pressed_left_side(GtkWidget *widget, gboolean addNewMemo(MyMemo *mmemo, const void *data) {
struct Memo new_memo;
unsigned char attrib;
int flag;
unsigned int unique_id;
int show_priv;
flag = GPOINTER_TO_INT(data);
unique_id = 0;
/* Do masking like Palm OS 3.5 */
if ((flag == COPY_FLAG) || (flag == MODIFY_FLAG)) {
show_priv = show_privates(GET_PRIVATES);
if (mmemo < (MyMemo *) LIST_MIN_DATA) {
return TRUE;
}
if ((show_priv != SHOW_PRIVATES) &&
(mmemo->attrib & dlpRecAttrSecret)) {
return TRUE;
}
}
/* End Masking */
if (flag == CLEAR_FLAG) {
/* Clear button was hit */
memo_clear_details();
connect_changed_signals(DISCONNECT_SIGNALS);
set_new_button_to(NEW_FLAG);
gtk_widget_grab_focus(GTK_WIDGET(memo_text));
return TRUE;
}
if ((flag != NEW_FLAG) && (flag != MODIFY_FLAG) && (flag != COPY_FLAG)) {
return TRUE;
}
if (flag == MODIFY_FLAG) {
unique_id = mmemo->unique_id;
if (mmemo < (MyMemo *) LIST_MIN_DATA) {
return TRUE;
}
if ((mmemo->rt == DELETED_PALM_REC) ||
(mmemo->rt == DELETED_PC_REC) ||
(mmemo->rt == MODIFIED_PALM_REC)) {
jp_logf(JP_LOG_INFO, _("You can't modify a record that is deleted\n"
));
return TRUE;
}
}
memo_get_details(&new_memo, &attrib);
set_new_button_to(CLEAR_FLAG);
/* Keep unique ID intact */
if (flag == MODIFY_FLAG) {
cb_delete_memo(NULL, data);
if ((mmemo->rt == PALM_REC) || (mmemo->rt == REPLACEMENT_PALM_REC)) {
pc_memo_write(&new_memo, REPLACEMENT_PALM_REC, attrib, &unique_id);
} else {
unique_id = 0;
pc_memo_write(&new_memo, NEW_PC_REC, attrib, &unique_id);
}
} else {
unique_id = 0;
pc_memo_write(&new_memo, NEW_PC_REC, attrib, &unique_id);
}
free_Memo(&new_memo);
/* Don't return to modified record if search gui active */
if (!glob_find_id) {
glob_find_id = unique_id;
}
memo_redraw();
return TRUE;
}
static void cb_add_new_record(GtkWidget *widget, gpointer data) {
if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(listStore), NULL) != 0) {
gtk_tree_model_foreach(GTK_TREE_MODEL(listStore), addNewRecordMemo, data
);
} else {
//no records exist in category yet.
addNewMemo(NULL, data);
}
}
/* Do masking like Palm OS 3.5 */
static void clear_mymemo(MyMemo *mmemo) {
mmemo->unique_id = 0;
mmemo->attrib = (unsigned char) (mmemo->attrib & 0xF8);
if (mmemo->memo.text) {
free(mmemo->memo.text);
mmemo->memo.text = strdup("");
}
return;
}
/* End Masking */
static gboolean cb_key_pressed_left_side(GtkWidget *widget,
GdkEventKey *event, GdkEventKey *event,
gpointer next_widget) gpointer next_widget) {
{ GtkTextBuffer *text_buffer;
GtkTextBuffer *text_buffer; GtkTextIter iter;
GtkTextIter iter;
if (event->keyval == GDK_KEY_Return) {
if (event->keyval == GDK_Return) { g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event"); gtk_widget_grab_focus(GTK_WIDGET(next_widget));
gtk_widget_grab_focus(GTK_WIDGET(next_widget)); /* Position cursor at start of text */
/* Position cursor at start of text */ text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(next_widget));
text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(next_widget)); gtk_text_buffer_get_start_iter(text_buffer, &iter);
gtk_text_buffer_get_start_iter(text_buffer, &iter); gtk_text_buffer_place_cursor(text_buffer, &iter);
gtk_text_buffer_place_cursor(text_buffer, &iter); return TRUE;
return TRUE; }
}
return FALSE; return FALSE;
} }
static gboolean cb_key_pressed_right_side(GtkWidget *widget, static gboolean cb_key_pressed_right_side(GtkWidget *widget,
GdkEventKey *event, GdkEventKey *event,
gpointer next_widget) gpointer next_widget) {
{ /* Switch to treeView */
/* Switch to clist */ if ((event->keyval == GDK_KEY_Return) && (event->state & GDK_SHIFT_MASK)) {
if ((event->keyval == GDK_Return) && (event->state & GDK_SHIFT_MASK)) { g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event"); gtk_widget_grab_focus(GTK_WIDGET(next_widget));
/* Call clist_selection to handle any cleanup such as a modified record */ return TRUE;
cb_clist_selection(clist, clist_row_selected, 0, GINT_TO_POINTER(1), NULL) }
; /* Call external editor for memo_text */
gtk_widget_grab_focus(GTK_WIDGET(next_widget)); if ((event->keyval == GDK_KEY_e) && (event->state & GDK_CONTROL_MASK)) {
return TRUE; g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
}
/* Call external editor for memo_text */ /* Get current text and place in temporary file */
if ((event->keyval == GDK_e) && (event->state & GDK_CONTROL_MASK)) { GtkTextIter start_iter;
gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event"); GtkTextIter end_iter;
char *text_out;
/* Get current text and place in temporary file */
GtkTextIter start_iter; gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(memo_text_buffer),
GtkTextIter end_iter; &start_iter, &end_iter);
char *text_out; text_out = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(memo_text_buffer),
&start_iter, &end_iter, TRUE);
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(memo_text_buffer),
&start_iter, &end_iter); char tmp_fname[] = "jpilot.XXXXXX";
text_out = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(memo_text_buffer), int tmpfd = mkstemp(tmp_fname);
&start_iter, &end_iter, TRUE); if (tmpfd < 0) {
jp_logf(JP_LOG_WARN, _("Could not get temporary file name\n"));
char tmp_fname[] = "jpilot.XXXXXX"; if (text_out)
int tmpfd = mkstemp(tmp_fname); free(text_out);
if (tmpfd < 0) return TRUE;
{ }
jp_logf(JP_LOG_WARN, _("Could not get temporary file name\n"));
if (text_out)
free(text_out);
return TRUE;
}
FILE *fptr = fdopen(tmpfd, "w"); FILE *fptr = fdopen(tmpfd, "w");
if (!fptr) { if (!fptr) {
jp_logf(JP_LOG_WARN, _("Could not open temporary file for external edit jp_logf(JP_LOG_WARN, _("Could not open temporary file for external e
or\n")); ditor\n"));
if (text_out) if (text_out)
free(text_out); free(text_out);
return TRUE; return TRUE;
} }
fwrite(text_out, strlen(text_out), 1, fptr); fwrite(text_out, strlen(text_out), 1, fptr);
fwrite("\n", 1, 1, fptr); fwrite("\n", 1, 1, fptr);
fclose(fptr); fclose(fptr);
/* Call external editor */ /* Call external editor */
char command[1024]; char command[1024];
const char *ext_editor; const char *ext_editor;
get_pref(PREF_EXTERNAL_EDITOR, NULL, &ext_editor); get_pref(PREF_EXTERNAL_EDITOR, NULL, &ext_editor);
if (!ext_editor) { if (!ext_editor) {
jp_logf(JP_LOG_INFO, "External Editor command empty\n"); jp_logf(JP_LOG_INFO, "External Editor command empty\n");
if (text_out) if (text_out)
free(text_out); free(text_out);
return TRUE; return TRUE;
} }
if ((strlen(ext_editor) + strlen(tmp_fname) + 1) > sizeof(command)) {
jp_logf(JP_LOG_WARN, _("External editor command too long to execute\
n"));
if (text_out)
free(text_out);
return TRUE;
}
g_snprintf(command, sizeof(command), "%s %s", ext_editor, tmp_fname);
/* jp_logf(JP_LOG_STDOUT|JP_LOG_FILE, _("executing command = [%s]\n"), c
ommand); */
if (system(command) == -1) {
/* Read data back from temporary file into memo */
char text_in[0xFFFF];
size_t bytes_read;
fptr = fopen(tmp_fname, "rb");
if (!fptr) {
jp_logf(JP_LOG_WARN, _("Could not open temporary file from exter
nal editor\n"));
return TRUE;
}
bytes_read = fread(text_in, 1, 0xFFFF, fptr);
fclose(fptr);
unlink(tmp_fname);
text_in[--bytes_read] = '\0'; /* Strip final newline */
/* Only update text if it has changed */
if (strcmp(text_out, text_in)) {
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer),
text_in, -1);
}
}
if ((strlen(ext_editor) + strlen(tmp_fname) + 1) > sizeof(command)) if (text_out)
{
jp_logf(JP_LOG_WARN, _("External editor command too long to execute\n")
);
if (text_out)
free(text_out); free(text_out);
return TRUE;
} return TRUE;
g_snprintf(command, sizeof(command), "%s %s", ext_editor, tmp_fname); } /* End of external editor if */
/* jp_logf(JP_LOG_STDOUT|JP_LOG_FILE, _("executing command = [%s]\n"), com return FALSE;
mand); */ }
if (system(command) == -1) {
/* Read data back from temporary file into memo */ gboolean
char text_in[0xFFFF]; selectRecordByRowMemo(GtkTreeModel *model,
size_t bytes_read; GtkTreePath *path,
GtkTreeIter *iter,
fptr = fopen(tmp_fname, "rb"); gpointer data) {
if (!fptr) { int *i = gtk_tree_path_get_indices(path);
jp_logf(JP_LOG_WARN, _("Could not open temporary file from external if (i[0] == row_selected) {
editor\n")); GtkTreeSelection *selection = NULL;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
gtk_tree_selection_select_path(selection, path);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeView), path,
gtk_tree_view_get_column(GTK_TREE_VIEW(tree
View), MEMO_COLUMN_ENUM),
FALSE, 1.0, 0.0);
return TRUE;
}
return FALSE;
}
static void memo_update_liststore(GtkListStore *pListStore, GtkWidget *tooltip_w
idget,
MemoList **memo_list, int category, int main)
{
int num_entries, entries_shown;
GtkTreeIter iter;
size_t copy_max_length;
char *last;
char str2[MEMO_MAX_COLUMN_LEN];
MemoList *temp_memo;
char str[MEMO_LIST_CHAR_WIDTH + 10];
int len, len1;
int show_priv;
long show_tooltips;
jp_logf(JP_LOG_DEBUG, "memo_update_liststore()\n");
free_MemoList(memo_list);
/* Need to get all records including private ones for the tooltips calculati
on */
num_entries = get_memos2(memo_list, SORT_ASCENDING, 2, 2, 1, CATEGORY_ALL);
/* Start by clearing existing entry if in main window */
if (main) {
memo_clear_details();
}
GtkTreeSelection* treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(
treeView));
gtk_tree_selection_set_select_function(treeSelection, NULL, NULL, NULL);
gtk_list_store_clear(GTK_LIST_STORE(pListStore));
show_priv = show_privates(GET_PRIVATES);
entries_shown = 0;
for (temp_memo = *memo_list; temp_memo; temp_memo = temp_memo->next) {
if (((temp_memo->mmemo.attrib & 0x0F) != category) &&
category != CATEGORY_ALL) {
continue;
}
/* Do masking like Palm OS 3.5 */
if ((show_priv == MASK_PRIVATES) &&
(temp_memo->mmemo.attrib & dlpRecAttrSecret)) {
clear_mymemo(&temp_memo->mmemo);
gtk_list_store_append(pListStore, &iter);
gtk_list_store_set(pListStore, &iter,
MEMO_COLUMN_ENUM, "------------------------------
----------",
MEMO_DATA_COLUMN_ENUM, &(temp_memo->mmemo),
-1);
entries_shown++;
continue;
}
/* End Masking */
/* Hide the private records if need be */
if ((show_priv != SHOW_PRIVATES) &&
(temp_memo->mmemo.attrib & dlpRecAttrSecret)) {
continue;
}
sprintf(str, "%d. ", entries_shown + 1);
len1 = (int) strlen(str);
len = ((int) strlen(temp_memo->mmemo.memo.text)) + 1;
/* ..memo treeView does not display '/n' */
if ((copy_max_length = (size_t) len) > MEMO_LIST_CHAR_WIDTH) {
copy_max_length = MEMO_LIST_CHAR_WIDTH;
}
last = multibyte_safe_memccpy(str + len1, temp_memo->mmemo.memo.text, '\
n', copy_max_length);
if (last) {
*(last - 1) = '\0';
} else {
str[copy_max_length + len1] = '\0';
}
lstrncpy_remove_cr_lfs(str2, str, MEMO_MAX_COLUMN_LEN);
gtk_list_store_append(pListStore, &iter);
/* Highlight row background depending on status */
GdkRGBA bgColor;
gboolean showBgColor = FALSE;
switch (temp_memo->mmemo.rt) {
case NEW_PC_REC:
case REPLACEMENT_PALM_REC:
bgColor = get_color(LIST_NEW_RED, LIST_NEW_GREEN, LIST_NEW_BLUE)
;
showBgColor = TRUE;
break;
case DELETED_PALM_REC:
case DELETED_PC_REC:
bgColor = get_color(LIST_DEL_RED, LIST_DEL_GREEN, LIST_DEL_BLUE)
;
showBgColor = TRUE;
break;
case MODIFIED_PALM_REC:
bgColor = get_color(LIST_MOD_RED, LIST_MOD_GREEN, LIST_MOD_BLUE)
;
showBgColor = TRUE;
break;
default:
if (temp_memo->mmemo.attrib & dlpRecAttrSecret) {
bgColor = get_color(LIST_PRIVATE_RED, LIST_PRIVATE_GREEN, LI
ST_PRIVATE_BLUE);
showBgColor = TRUE;
} else {
showBgColor = FALSE;
}
}
gtk_list_store_set(pListStore, &iter,
MEMO_COLUMN_ENUM, str2,
MEMO_DATA_COLUMN_ENUM, &(temp_memo->mmemo),
MEMO_BACKGROUND_COLOR_ENUM, showBgColor ? &bgColor :
NULL,
MEMO_BACKGROUND_COLOR_ENABLED_ENUM, showBgColor,
-1);
entries_shown++;
}
jp_logf(JP_LOG_DEBUG, "entries_shown=%d\n", entries_shown);
// Set callback for a row selected
gtk_tree_selection_set_select_function(treeSelection, handleRowSelectionForM
emo, NULL, NULL);
/* If there are items in the list, highlight the selected row */
if ((main) && (entries_shown > 0)) {
/* First, select any record being searched for */
if (glob_find_id) {
memo_find();
}
/* Second, try the currently selected row */
else if (row_selected < entries_shown) {
gtk_tree_model_foreach(GTK_TREE_MODEL(pListStore), selectRecordByRow
Memo, NULL);
}
/* Third, select row 0 if nothing else is possible */
else {
row_selected = 0;
gtk_tree_model_foreach(GTK_TREE_MODEL(pListStore), selectRecordByRow
Memo, NULL);
}
}
if (tooltip_widget) {
get_pref(PREF_SHOW_TOOLTIPS, &show_tooltips, NULL);
if (memo_list == NULL) {
set_tooltip((int) show_tooltips, tooltip_widget, _("0 records"));
} else {
sprintf(str, _("%d of %d records"), entries_shown, num_entries);
set_tooltip((int) show_tooltips, tooltip_widget, str);
}
}
if (main) {
connect_changed_signals(CONNECT_SIGNALS);
}
/* return focus to treeView after any big operation which requires a redraw
*/
gtk_widget_grab_focus(GTK_WIDGET(treeView));
jp_logf(JP_LOG_DEBUG, "Leaving memo_update_liststore()\n");
}
gboolean
findRecordMemo(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data) {
if (glob_find_id) {
MyMemo *mmemo = NULL;
gtk_tree_model_get(model, iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
if (mmemo->unique_id == glob_find_id) {
GtkTreeSelection *selection = NULL;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
gtk_tree_selection_set_select_function(selection, handleRowSelection
ForMemo, NULL, NULL);
gtk_tree_selection_select_path(selection, path);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeView), path,
gtk_tree_view_get_column(GTK_TREE_VIEW(
treeView), MEMO_DATA_COLUMN_ENUM),
FALSE, 1.0, 0.0);
glob_find_id = 0;
return TRUE; return TRUE;
} }
bytes_read = fread(text_in, 1, 0xFFFF, fptr); }
fclose(fptr); return FALSE;
unlink(tmp_fname); }
text_in[--bytes_read] = '\0'; /* Strip final newline */ static int memo_find(void) {
/* Only update text if it has changed */ gtk_tree_model_foreach(GTK_TREE_MODEL(listStore), findRecordMemo, NULL);
if (strcmp(text_out, text_in)) { return EXIT_SUCCESS;
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer), }
text_in, -1);
}
}
if (text_out)
free(text_out);
return TRUE;
} /* End of external editor if */
return FALSE;
}
static void memo_update_clist(GtkWidget *clist, GtkWidget *tooltip_widget,
MemoList **memo_list, int category, int main)
{
int num_entries, entries_shown;
size_t copy_max_length;
char *last;
gchar *empty_line[] = { "" };
char str2[MEMO_MAX_COLUMN_LEN];
MemoList *temp_memo;
char str[MEMO_CLIST_CHAR_WIDTH+10];
int len, len1;
int show_priv;
long show_tooltips;
jp_logf(JP_LOG_DEBUG, "memo_update_clist()\n");
free_MemoList(memo_list);
/* Need to get all records including private ones for the tooltips calculatio
n */
num_entries = get_memos2(memo_list, SORT_ASCENDING, 2, 2, 1, CATEGORY_ALL);
/* Start by clearing existing entry if in main window */
if (main) {
memo_clear_details();
}
/* Freeze clist to prevent flicker during updating */
gtk_clist_freeze(GTK_CLIST(clist));
if (main) {
gtk_signal_disconnect_by_func(GTK_OBJECT(clist),
GTK_SIGNAL_FUNC(cb_clist_selection), NULL);
}
clist_clear(GTK_CLIST(clist));
#ifdef __APPLE__
gtk_clist_thaw(GTK_CLIST(clist));
gtk_widget_hide(clist);
gtk_widget_show_all(clist);
gtk_clist_freeze(GTK_CLIST(clist));
#endif
show_priv = show_privates(GET_PRIVATES); static int memo_redraw(void) {
memo_update_liststore(listStore, category_menu1, &glob_memo_list, memo_categ
ory, TRUE);
return EXIT_SUCCESS;
}
entries_shown=0; int memo_cycle_cat(void) {
for (temp_memo = *memo_list; temp_memo; temp_memo=temp_memo->next) { int b;
if ( ((temp_memo->mmemo.attrib & 0x0F) != category) && int i, new_cat;
category != CATEGORY_ALL) {
continue;
}
/* Do masking like Palm OS 3.5 */
if ((show_priv == MASK_PRIVATES) &&
(temp_memo->mmemo.attrib & dlpRecAttrSecret)) {
gtk_clist_append(GTK_CLIST(clist), empty_line);
gtk_clist_set_text(GTK_CLIST(clist), entries_shown, 0,
"----------------------------------------");
clear_mymemo(&temp_memo->mmemo);
gtk_clist_set_row_data(GTK_CLIST(clist), entries_shown, &(temp_memo->mm
emo));
gtk_clist_set_row_style(GTK_CLIST(clist), entries_shown, NULL);
entries_shown++;
continue;
}
/* End Masking */
/* Hide the private records if need be */
if ((show_priv != SHOW_PRIVATES) &&
(temp_memo->mmemo.attrib & dlpRecAttrSecret)) {
continue;
}
/* Add entry to clist */
gtk_clist_append(GTK_CLIST(clist), empty_line);
sprintf(str, "%d. ", entries_shown + 1);
len1 = strlen(str);
len = strlen(temp_memo->mmemo.memo.text)+1;
/* ..memo clist does not display '/n' */
if ((copy_max_length = len) > MEMO_CLIST_CHAR_WIDTH) {
copy_max_length = MEMO_CLIST_CHAR_WIDTH;
}
last = (char *)multibyte_safe_memccpy(str+len1, temp_memo->mmemo.memo.text
,'\n', copy_max_length);
if (last) {
*(last-1)='\0';
} else {
str[copy_max_length + len1]='\0';
}
lstrncpy_remove_cr_lfs(str2, str, MEMO_MAX_COLUMN_LEN);
gtk_clist_set_text(GTK_CLIST(clist), entries_shown, 0, str2);
gtk_clist_set_row_data(GTK_CLIST(clist), entries_shown, &(temp_memo->mmemo
));
/* Highlight row background depending on status */
switch (temp_memo->mmemo.rt) {
case NEW_PC_REC:
case REPLACEMENT_PALM_REC:
set_bg_rgb_clist_row(clist, entries_shown,
CLIST_NEW_RED, CLIST_NEW_GREEN, CLIST_NEW_BLUE);
break;
case DELETED_PALM_REC:
case DELETED_PC_REC:
set_bg_rgb_clist_row(clist, entries_shown,
CLIST_DEL_RED, CLIST_DEL_GREEN, CLIST_DEL_BLUE);
break;
case MODIFIED_PALM_REC:
set_bg_rgb_clist_row(clist, entries_shown,
CLIST_MOD_RED, CLIST_MOD_GREEN, CLIST_MOD_BLUE);
break;
default:
if (temp_memo->mmemo.attrib & dlpRecAttrSecret) {
set_bg_rgb_clist_row(clist, entries_shown,
CLIST_PRIVATE_RED, CLIST_PRIVATE_GREEN, CLIST_P
RIVATE_BLUE);
} else {
gtk_clist_set_row_style(GTK_CLIST(clist), entries_shown, NULL);
}
}
entries_shown++;
}
jp_logf(JP_LOG_DEBUG, "entries_shown=%d\n", entries_shown);
if (main) {
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(cb_clist_selection), NULL);
}
/* If there are items in the list, highlight the selected row */
if ((main) && (entries_shown>0)) {
/* First, select any record being searched for */
if (glob_find_id)
{
memo_find();
}
/* Second, try the currently selected row */
else if (clist_row_selected < entries_shown)
{
clist_select_row(GTK_CLIST(clist), clist_row_selected, 0);
if (!gtk_clist_row_is_visible(GTK_CLIST(clist), clist_row_selected)) {
gtk_clist_moveto(GTK_CLIST(clist), clist_row_selected, 0, 0.5, 0.0);
}
}
/* Third, select row 0 if nothing else is possible */
else
{
clist_select_row(GTK_CLIST(clist), 0, 0);
}
}
/* Unfreeze clist after all changes */
gtk_clist_thaw(GTK_CLIST(clist));
if (tooltip_widget) {
get_pref(PREF_SHOW_TOOLTIPS, &show_tooltips, NULL);
if (memo_list==NULL) {
set_tooltip(show_tooltips, glob_tooltips, tooltip_widget, _("0 records"
), NULL);
}
else {
sprintf(str, _("%d of %d records"), entries_shown, num_entries);
set_tooltip(show_tooltips, glob_tooltips, tooltip_widget, str, NULL);
}
}
if (main) {
connect_changed_signals(CONNECT_SIGNALS);
}
/* return focus to clist after any big operation which requires a redraw */
gtk_widget_grab_focus(GTK_WIDGET(clist));
jp_logf(JP_LOG_DEBUG, "Leaving memo_update_clist()\n");
}
static int memo_find(void)
{
int r, found_at;
if (glob_find_id) {
r = clist_find_id(clist,
glob_find_id,
&found_at);
if (r) {
clist_select_row(GTK_CLIST(clist), found_at, 0);
if (!gtk_clist_row_is_visible(GTK_CLIST(clist), found_at)) {
gtk_clist_moveto(GTK_CLIST(clist), found_at, 0, 0.5, 0.0);
}
}
glob_find_id = 0;
}
return EXIT_SUCCESS;
}
static int memo_clist_redraw(void)
{
memo_update_clist(clist, category_menu1, &glob_memo_list, memo_category, TRUE
);
return EXIT_SUCCESS;
}
int memo_cycle_cat(void)
{
int b;
int i, new_cat;
b=dialog_save_changed_record(pane, record_changed);
if (b==DIALOG_SAID_2) {
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
}
if (memo_category == CATEGORY_ALL) {
new_cat = -1;
} else {
new_cat = find_sort_cat_pos(memo_category);
}
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) {
new_cat++;
if (new_cat >= NUM_MEMO_CAT_ITEMS) {
memo_category = CATEGORY_ALL;
break;
}
if ((sort_l[new_cat].Pcat) && (sort_l[new_cat].Pcat[0])) {
memo_category = sort_l[new_cat].cat_num;
break;
}
}
clist_row_selected = 0;
return EXIT_SUCCESS;
}
int memo_refresh(void)
{
int index, index2;
if (glob_find_id) {
memo_category = CATEGORY_ALL;
}
if (memo_category==CATEGORY_ALL) {
index = 0;
index2 = 0;
} else {
index = find_sort_cat_pos(memo_category);
index2 = find_menu_cat_pos(index) + 1;
index += 1;
}
memo_update_clist(clist, category_menu1, &glob_memo_list, memo_category, TRUE
);
if (index<0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else {
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM(memo_cat_menu_item1[index]), TRUE);
gtk_option_menu_set_history(GTK_OPTION_MENU(category_menu1), index2);
}
return EXIT_SUCCESS;
}
int memo_gui_cleanup(void)
{
int b;
b=dialog_save_changed_record(pane, record_changed);
if (b==DIALOG_SAID_2) {
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
}
free_MemoList(&glob_memo_list);
connect_changed_signals(DISCONNECT_SIGNALS);
set_pref(PREF_MEMO_PANE, gtk_paned_get_position(GTK_PANED(pane)), NULL, TRUE)
;
set_pref(PREF_LAST_MEMO_CATEGORY, memo_category, NULL, TRUE);
clist_clear(GTK_CLIST(clist));
return EXIT_SUCCESS; b = dialog_save_changed_record(pane, record_changed);
if (b == DIALOG_SAID_2) {
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
}
if (memo_category == CATEGORY_ALL) {
new_cat = -1;
} else {
new_cat = find_sort_cat_pos(memo_category);
}
for (i = 0; i < NUM_MEMO_CAT_ITEMS; i++) {
new_cat++;
if (new_cat >= NUM_MEMO_CAT_ITEMS) {
memo_category = CATEGORY_ALL;
break;
}
if ((sort_l[new_cat].Pcat) && (sort_l[new_cat].Pcat[0])) {
memo_category = sort_l[new_cat].cat_num;
break;
}
}
row_selected = 0;
return EXIT_SUCCESS;
}
int memo_refresh(void) {
int index, index2;
if (glob_find_id) {
memo_category = CATEGORY_ALL;
}
if (memo_category == CATEGORY_ALL) {
index = 0;
index2 = 0;
} else {
index = find_sort_cat_pos(memo_category);
index2 = find_menu_cat_pos(index) + 1;
index += 1;
}
memo_update_liststore(listStore, category_menu1, &glob_memo_list, memo_categ
ory, TRUE);
if (index < 0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
} else {
gtk_combo_box_set_active(GTK_COMBO_BOX(category_menu1), index2);
}
return EXIT_SUCCESS;
}
int memo_gui_cleanup(void) {
int b;
b = dialog_save_changed_record(pane, record_changed);
if (b == DIALOG_SAID_2) {
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
}
free_MemoList(&glob_memo_list);
connect_changed_signals(DISCONNECT_SIGNALS);
set_pref(PREF_MEMO_PANE, gtk_paned_get_position(GTK_PANED(pane)), NULL, TRUE
);
set_pref(PREF_LAST_MEMO_CATEGORY, memo_category, NULL, TRUE);
GtkTreeSelection* treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(
treeView));
gtk_tree_selection_set_select_function(treeSelection, NULL, NULL, NULL);
gtk_list_store_clear(GTK_LIST_STORE(listStore));
return EXIT_SUCCESS;
} }
/* Main function */ /* Main function */
int memo_gui(GtkWidget *vbox, GtkWidget *hbox) int memo_gui(GtkWidget *vbox, GtkWidget *hbox) {
{ int i;
int i; GtkWidget *scrolled_window;
GtkWidget *scrolled_window; GtkWidget *vbox1, *vbox2, *hbox_temp;
GtkWidget *vbox1, *vbox2, *hbox_temp; GtkWidget *separator;
GtkWidget *separator; long ivalue;
long ivalue; GtkAccelGroup *accel_group;
GtkAccelGroup *accel_group; long char_set;
long char_set; long show_tooltips;
long show_tooltips; char *cat_name;
char *cat_name;
get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
/* Do some initialization */
/* Do some initialization */ row_selected = 0;
clist_row_selected=0;
record_changed = CLEAR_FLAG;
record_changed=CLEAR_FLAG;
get_memo_app_info(&memo_app_info);
get_memo_app_info(&memo_app_info); listStore = gtk_list_store_new(MEMO_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER,
GDK_TYPE_RGBA,
/* Initialize categories */ G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN
get_pref(PREF_CHAR_SET, &char_set, NULL); );
for (i=1; i<NUM_MEMO_CAT_ITEMS; i++) {
cat_name = charset_p2newj(memo_app_info.category.name[i], 31, char_set); /* Initialize categories */
strcpy(sort_l[i-1].Pcat, cat_name); get_pref(PREF_CHAR_SET, &char_set, NULL);
free(cat_name); for (i = 1; i < NUM_MEMO_CAT_ITEMS; i++) {
sort_l[i-1].cat_num = i; cat_name = charset_p2newj(memo_app_info.category.name[i], 31, (int) char
} _set);
/* put reserved 'Unfiled' category at end of list */ strcpy(sort_l[i - 1].Pcat, cat_name);
cat_name = charset_p2newj(memo_app_info.category.name[0], 31, char_set); free(cat_name);
strcpy(sort_l[NUM_MEMO_CAT_ITEMS-1].Pcat, cat_name); sort_l[i - 1].cat_num = i;
free(cat_name); }
sort_l[NUM_MEMO_CAT_ITEMS-1].cat_num = 0; /* put reserved 'Unfiled' category at end of list */
cat_name = charset_p2newj(memo_app_info.category.name[0], 31, (int) char_set
);
strcpy(sort_l[NUM_MEMO_CAT_ITEMS - 1].Pcat, cat_name);
free(cat_name);
sort_l[NUM_MEMO_CAT_ITEMS - 1].cat_num = 0;
qsort(sort_l, NUM_MEMO_CAT_ITEMS-1, sizeof(struct sorted_cats), cat_compare); qsort(sort_l, NUM_MEMO_CAT_ITEMS - 1, sizeof(struct sorted_cats), cat_compar e);
#ifdef JPILOT_DEBUG #ifdef JPILOT_DEBUG
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) {
printf("cat %d [%s]\n", sort_l[i].cat_num, sort_l[i].Pcat); printf("cat %d [%s]\n", sort_l[i].cat_num, sort_l[i].Pcat);
} }
#endif #endif
get_pref(PREF_LAST_MEMO_CATEGORY, &ivalue, NULL); get_pref(PREF_LAST_MEMO_CATEGORY, &ivalue, NULL);
memo_category = ivalue; memo_category = (int) ivalue;
if ((memo_category != CATEGORY_ALL) if ((memo_category != CATEGORY_ALL)
&& (memo_app_info.category.name[memo_category][0]=='\0')) { && (memo_app_info.category.name[memo_category][0] == '\0')) {
memo_category=CATEGORY_ALL; memo_category = CATEGORY_ALL;
} }
/* Create basic GUI with left and right boxes and sliding pane */ /* Create basic GUI with left and right boxes and sliding pane */
accel_group = gtk_accel_group_new(); accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(gtk_widget_get_toplevel(vbox)), gtk_window_add_accel_group(GTK_WINDOW(gtk_widget_get_toplevel(vbox)),
accel_group); accel_group);
get_pref(PREF_SHOW_TOOLTIPS, &show_tooltips, NULL); get_pref(PREF_SHOW_TOOLTIPS, &show_tooltips, NULL);
pane = gtk_hpaned_new(); pane = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
get_pref(PREF_MEMO_PANE, &ivalue, NULL); get_pref(PREF_MEMO_PANE, &ivalue, NULL);
gtk_paned_set_position(GTK_PANED(pane), ivalue); gtk_paned_set_position(GTK_PANED(pane), (gint) ivalue);
gtk_box_pack_start(GTK_BOX(hbox), pane, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(hbox), pane, TRUE, TRUE, 5);
vbox1 = gtk_vbox_new(FALSE, 0); vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
vbox2 = gtk_vbox_new(FALSE, 0); vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_paned_pack1(GTK_PANED(pane), vbox1, TRUE, FALSE); gtk_paned_pack1(GTK_PANED(pane), vbox1, TRUE, FALSE);
gtk_paned_pack2(GTK_PANED(pane), vbox2, TRUE, FALSE); gtk_paned_pack2(GTK_PANED(pane), vbox2, TRUE, FALSE);
/* Left side of GUI */ /* Left side of GUI */
/* Separator */ /* Separator */
separator = gtk_hseparator_new(); separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, FALSE, 5);
/* 'Today is:' label */ /* 'Today is:' label */
glob_date_label = gtk_label_new(" "); glob_date_label = gtk_label_new(" ");
gtk_box_pack_start(GTK_BOX(vbox1), glob_date_label, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox1), glob_date_label, FALSE, FALSE, 0);
timeout_date(NULL); timeout_date(NULL);
glob_date_timer_tag = gtk_timeout_add(CLOCK_TICK, timeout_sync_up, NULL); glob_date_timer_tag = g_timeout_add(CLOCK_TICK, timeout_sync_up, NULL);
/* Separator */ /* Separator */
separator = gtk_hseparator_new(); separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, FALSE, 5);
/* Left-side Category menu */ /* Left-side Category menu */
hbox_temp = gtk_hbox_new(FALSE, 0); hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(vbox1), hbox_temp, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox1), hbox_temp, FALSE, FALSE, 0);
make_category_menu(&category_menu1, memo_cat_menu_item1, make_category_menu(&category_menu1,
sort_l, cb_category, TRUE, TRUE); sort_l, cb_category, TRUE, TRUE);
gtk_box_pack_start(GTK_BOX(hbox_temp), category_menu1, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_temp), category_menu1, TRUE, TRUE, 0);
/* Memo list scrolled window */ /* Memo list scrolled window */
scrolled_window = gtk_scrolled_window_new(NULL, NULL); scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 0); gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(vbox1), scrolled_window, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox1), scrolled_window, TRUE, TRUE, 0);
clist = gtk_clist_new(1); initializeTreeView();
gtk_clist_set_shadow_type(GTK_CLIST(clist), SHADOW); gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(treeView));
gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE);
gtk_clist_set_column_width(GTK_CLIST(clist), 0, 50); /* Right side of GUI */
gtk_signal_connect(GTK_OBJECT(clist), "select_row", hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3);
GTK_SIGNAL_FUNC(cb_clist_selection), NULL); gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(clist)); /* Cancel button */
CREATE_BUTTON(cancel_record_button, _("Cancel"), CANCEL, _("Cancel the modif
/* Right side of GUI */ ications"), GDK_KEY_Escape, 0, "ESC")
g_signal_connect(G_OBJECT(cancel_record_button), "clicked",
hbox_temp = gtk_hbox_new(FALSE, 3); G_CALLBACK(cb_cancel), NULL);
gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0);
/* Delete Button */
/* Cancel button */ CREATE_BUTTON(delete_record_button, _("Delete"), DELETE, _("Delete the selec
CREATE_BUTTON(cancel_record_button, _("Cancel"), CANCEL, _("Cancel the modifi ted record"), GDK_d, GDK_CONTROL_MASK,
cations"), GDK_Escape, 0, "ESC") "Ctrl+D")
gtk_signal_connect(GTK_OBJECT(cancel_record_button), "clicked", g_signal_connect(G_OBJECT(delete_record_button), "clicked",
GTK_SIGNAL_FUNC(cb_cancel), NULL); G_CALLBACK(cb_delete_memo),
GINT_TO_POINTER(DELETE_FLAG));
/* Delete Button */
CREATE_BUTTON(delete_record_button, _("Delete"), DELETE, _("Delete the select /* Undelete Button */
ed record"), GDK_d, GDK_CONTROL_MASK, "Ctrl+D") CREATE_BUTTON(undelete_record_button, _("Undelete"), UNDELETE, _("Undelete t
gtk_signal_connect(GTK_OBJECT(delete_record_button), "clicked", he selected record"), 0, 0, "")
GTK_SIGNAL_FUNC(cb_delete_memo), g_signal_connect(G_OBJECT(undelete_record_button), "clicked",
GINT_TO_POINTER(DELETE_FLAG)); G_CALLBACK(cb_undelete_memo),
GINT_TO_POINTER(UNDELETE_FLAG));
/* Undelete Button */
CREATE_BUTTON(undelete_record_button, _("Undelete"), UNDELETE, _("Undelete th /* Copy button */
e selected record"), 0, 0, "") CREATE_BUTTON(copy_record_button, _("Copy"), COPY, _("Copy the selected reco
gtk_signal_connect(GTK_OBJECT(undelete_record_button), "clicked", rd"), GDK_c,
GTK_SIGNAL_FUNC(cb_undelete_memo), GDK_CONTROL_MASK | GDK_SHIFT_MASK, "Ctrl+Shift+C")
GINT_TO_POINTER(UNDELETE_FLAG)); g_signal_connect(G_OBJECT(copy_record_button), "clicked",
G_CALLBACK(cb_add_new_record),
/* Copy button */ GINT_TO_POINTER(COPY_FLAG));
CREATE_BUTTON(copy_record_button, _("Copy"), COPY, _("Copy the selected recor
d"), GDK_c, GDK_CONTROL_MASK|GDK_SHIFT_MASK, "Ctrl+Shift+C") /* New button */
gtk_signal_connect(GTK_OBJECT(copy_record_button), "clicked", CREATE_BUTTON(new_record_button, _("New Record"), NEW, _("Add a new record")
GTK_SIGNAL_FUNC(cb_add_new_record), , GDK_n, GDK_CONTROL_MASK, "Ctrl+N")
GINT_TO_POINTER(COPY_FLAG)); g_signal_connect(G_OBJECT(new_record_button), "clicked",
G_CALLBACK(cb_add_new_record),
/* New button */ GINT_TO_POINTER(CLEAR_FLAG));
CREATE_BUTTON(new_record_button, _("New Record"), NEW, _("Add a new record"),
GDK_n, GDK_CONTROL_MASK, "Ctrl+N") /* "Add Record" button */
gtk_signal_connect(GTK_OBJECT(new_record_button), "clicked", CREATE_BUTTON(add_record_button, _("Add Record"), ADD, _("Add the new record
GTK_SIGNAL_FUNC(cb_add_new_record), "), GDK_KEY_Return, GDK_CONTROL_MASK,
GINT_TO_POINTER(CLEAR_FLAG)); "Ctrl+Enter")
g_signal_connect(G_OBJECT(add_record_button), "clicked",
/* "Add Record" button */ G_CALLBACK(cb_add_new_record),
CREATE_BUTTON(add_record_button, _("Add Record"), ADD, _("Add the new record" GINT_TO_POINTER(NEW_FLAG));
), GDK_Return, GDK_CONTROL_MASK, "Ctrl+Enter")
gtk_signal_connect(GTK_OBJECT(add_record_button), "clicked",
GTK_SIGNAL_FUNC(cb_add_new_record),
GINT_TO_POINTER(NEW_FLAG));
#ifndef ENABLE_STOCK_BUTTONS #ifndef ENABLE_STOCK_BUTTONS
gtk_widget_set_name(GTK_WIDGET(GTK_LABEL(GTK_BIN(add_record_button)->child)), gtk_widget_set_name(GTK_WIDGET(GTK_LABEL(gtk_bin_get_child(GTK_BIN(add_recor
"label_high"); d_button)))),
"label_high");
#endif #endif
/* "Apply Changes" button */ /* "Apply Changes" button */
CREATE_BUTTON(apply_record_button, _("Apply Changes"), APPLY, _("Commit the m CREATE_BUTTON(apply_record_button, _("Apply Changes"), APPLY, _("Commit the
odifications"), GDK_Return, GDK_CONTROL_MASK, "Ctrl+Enter") modifications"), GDK_KEY_Return,
gtk_signal_connect(GTK_OBJECT(apply_record_button), "clicked", GDK_CONTROL_MASK, "Ctrl+Enter")
GTK_SIGNAL_FUNC(cb_add_new_record), g_signal_connect(G_OBJECT(apply_record_button), "clicked",
GINT_TO_POINTER(MODIFY_FLAG)); G_CALLBACK(cb_add_new_record),
GINT_TO_POINTER(MODIFY_FLAG));
#ifndef ENABLE_STOCK_BUTTONS #ifndef ENABLE_STOCK_BUTTONS
gtk_widget_set_name(GTK_WIDGET(GTK_LABEL(GTK_BIN(apply_record_button)->child) gtk_widget_set_name(GTK_WIDGET(GTK_LABEL(gtk_bin_get_child(GTK_BIN(apply_rec
), ord_button)))),
"label_high"); "label_high");
#endif #endif
/* Separator */ /* Separator */
separator = gtk_hseparator_new(); separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox2), separator, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox2), separator, FALSE, FALSE, 5);
/* Private check box */ /* Private check box */
hbox_temp = gtk_hbox_new(FALSE, 0); hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0);
private_checkbox = gtk_check_button_new_with_label(_("Private")); private_checkbox = gtk_check_button_new_with_label(_("Private"));
gtk_box_pack_end(GTK_BOX(hbox_temp), private_checkbox, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(hbox_temp), private_checkbox, FALSE, FALSE, 0);
/* Right-side Category menu */ /* Right-side Category menu */
/* Clear GTK option menus before use */ make_category_menu(&category_menu2,
for (i=0; i<NUM_MEMO_CAT_ITEMS; i++) { sort_l, NULL, FALSE, FALSE);
memo_cat_menu_item2[i] = NULL; gtk_box_pack_start(GTK_BOX(hbox_temp), category_menu2, TRUE, TRUE, 0);
}
make_category_menu(&category_menu2, memo_cat_menu_item2, /* Description text box */
sort_l, NULL, FALSE, FALSE); hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(hbox_temp), category_menu2, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0);
/* Description text box */ hbox_temp = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
hbox_temp = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, FALSE, FALSE, 0);
memo_text = gtk_text_view_new();
hbox_temp = gtk_hbox_new (FALSE, 0); memo_text_buffer = G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(memo_text
gtk_box_pack_start(GTK_BOX(vbox2), hbox_temp, TRUE, TRUE, 0); )));
gtk_text_view_set_editable(GTK_TEXT_VIEW(memo_text), TRUE);
memo_text = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(memo_text), GTK_WRAP_WORD);
memo_text_buffer = G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(memo_text)
)); scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_text_view_set_editable(GTK_TEXT_VIEW(memo_text), TRUE); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(memo_text), GTK_WRAP_WORD); GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 1);
scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scrolled_window), memo_text);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), gtk_box_pack_start(GTK_BOX(hbox_temp), scrolled_window,TRUE,TRUE,0);
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); /* Capture the Enter & Shift-Enter key combinations to move back and
gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 1); * forth between the left- and right-hand sides of the display. */
gtk_container_add(GTK_CONTAINER(scrolled_window), memo_text); g_signal_connect(G_OBJECT(treeView), "key_press_event",
gtk_box_pack_start_defaults(GTK_BOX(hbox_temp), scrolled_window); G_CALLBACK(cb_key_pressed_left_side), memo_text);
/* Capture the Enter & Shift-Enter key combinations to move back and g_signal_connect(G_OBJECT(memo_text), "key_press_event",
* forth between the left- and right-hand sides of the display. */ G_CALLBACK(cb_key_pressed_right_side), treeView);
gtk_signal_connect(GTK_OBJECT(clist), "key_press_event",
GTK_SIGNAL_FUNC(cb_key_pressed_left_side), memo_text); /**********************************************************************/
gtk_signal_connect(GTK_OBJECT(memo_text), "key_press_event", gtk_widget_show_all(vbox);
GTK_SIGNAL_FUNC(cb_key_pressed_right_side), clist); gtk_widget_show_all(hbox);
/**********************************************************************/ gtk_widget_hide(add_record_button);
gtk_widget_hide(apply_record_button);
gtk_widget_show_all(vbox); gtk_widget_hide(undelete_record_button);
gtk_widget_show_all(hbox); gtk_widget_hide(cancel_record_button);
gtk_widget_hide(add_record_button); memo_refresh();
gtk_widget_hide(apply_record_button);
gtk_widget_hide(undelete_record_button); return EXIT_SUCCESS;
gtk_widget_hide(cancel_record_button); }
void initializeTreeView() {
GtkTreeSelection *treeSelection = NULL;
treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(listStore));
GtkCellRenderer *columnRenderer = gtk_cell_renderer_text_new();
// gtk_cell_renderer_set_fixed_size(columnRenderer, -1, 1);
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes("", col
umnRenderer, "text", MEMO_COLUMN_ENUM,
"cell-b
ackground-rgba",
MEMO_BA
CKGROUND_COLOR_ENUM,
"cell-b
ackground-set",
MEMO_BA
CKGROUND_COLOR_ENABLED_ENUM, NULL);
gtk_tree_view_column_set_fixed_width(column, (gint) 50);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), FALSE);
gtk_tree_view_insert_column(GTK_TREE_VIEW(treeView), column, 0);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
gtk_tree_selection_set_select_function(treeSelection, handleRowSelectionForM
emo, NULL, NULL);
gtk_widget_set_events(treeView, GDK_BUTTON1_MOTION_MASK);
g_signal_connect (G_OBJECT(treeView), "motion_notify_event",
G_CALLBACK(motion_notify_event), NULL);
g_signal_connect (G_OBJECT(treeView), "button-press-event",
G_CALLBACK(button_pressed_for_motion), NULL);
g_signal_connect (G_OBJECT(treeView), "button-release-event",
G_CALLBACK(button_released_for_motion), NULL);
}
gboolean handleRowSelectionForMemo(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata) {
GtkTreeIter iter;
struct Memo *memo;
MyMemo *mmemo;
int b;
int index, sorted_position;
// int unique_id;
if ((gtk_tree_model_get_iter(model, &iter, path)) && (!path_currently_select
ed)) {
int *i = gtk_tree_path_get_indices(path);
row_selected = i[0];
gtk_tree_model_get(model, &iter, MEMO_DATA_COLUMN_ENUM, &mmemo, -1);
if ((record_changed == MODIFY_FLAG) || (record_changed == NEW_FLAG)) {
//if (mmemo != NULL) {
// unique_id = mmemo->unique_id;
//}
// We need to turn this "scroll with mouse held down" thing off
button_set_for_motion(0);
b = dialog_save_changed_record_with_cancel(pane, record_changed);
if (b == DIALOG_SAID_1) { /* Cancel */
return TRUE;
}
if (b == DIALOG_SAID_3) { /* Save */
cb_add_new_record(NULL, GINT_TO_POINTER(record_changed));
}
set_new_button_to(CLEAR_FLAG);
return TRUE;
}
if (mmemo == NULL) {
return TRUE;
}
if (mmemo->rt == DELETED_PALM_REC ||
(mmemo->rt == DELETED_PC_REC))
/* Possible later addition of undelete code for modified deleted rec
ords
|| mmemo->rt == MODIFIED_PALM_REC
*/
{
set_new_button_to(UNDELETE_FLAG);
} else {
set_new_button_to(CLEAR_FLAG);
}
connect_changed_signals(DISCONNECT_SIGNALS);
memo = &(mmemo->memo);
index = mmemo->attrib & 0x0F;
sorted_position = find_sort_cat_pos(index);
int pos = findSortedPostion(sorted_position, GTK_COMBO_BOX(category_menu
2));
if (pos != sorted_position && index != 0) {
/* Illegal category */
jp_logf(JP_LOG_DEBUG, "Category is not legal\n");
index = sorted_position = 0;
}
if (sorted_position < 0) {
jp_logf(JP_LOG_WARN, _("Category is not legal\n"));
}
gtk_combo_box_set_active(GTK_COMBO_BOX(category_menu2),find_menu_cat_pos
(sorted_position));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(memo_text_buffer), memo->text,
-1);
memo_refresh(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(private_checkbox),
mmemo->attrib & dlpRecAttrSecret);
return EXIT_SUCCESS; connect_changed_signals(CONNECT_SIGNALS);
return TRUE; /* allow selection state to change */
}
return TRUE; /* allow selection state to change */
} }
 End of changes. 76 change blocks. 
1733 lines changed or deleted 1935 lines changed or added

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