"Fossies" - the Fresh Open Source Software Archive  

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

search_gui.c  (jpilot-1.8.2):search_gui.c  (jpilot-2_0_1)
skipping to change at line 43 skipping to change at line 43
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "prefs.h" #include "prefs.h"
#include "log.h" #include "log.h"
#include "datebook.h" #include "datebook.h"
#include "calendar.h" #include "calendar.h"
#include "address.h" #include "address.h"
#include "todo.h" #include "todo.h"
#include "memo.h" #include "memo.h"
#ifdef ENABLE_PLUGINS #ifdef ENABLE_PLUGINS
# include "plugins.h" # include "plugins.h"
#endif #endif
/********************************* Constants **********************************/ /********************************* Constants **********************************/
#define SEARCH_MAX_COLUMN_LEN 80 #define SEARCH_MAX_COLUMN_LEN 80
/******************************* Global vars **********************************/ /******************************* Global vars **********************************/
static struct search_record *search_rl = NULL; static struct search_record *search_rl = NULL;
static GtkWidget *case_sense_checkbox; static GtkWidget *case_sense_checkbox;
static GtkWidget *window = NULL; static GtkWidget *window = NULL;
static GtkWidget *entry = NULL; static GtkWidget *entry = NULL;
static GtkAccelGroup *accel_group = NULL; static GtkAccelGroup *accel_group = NULL;
static int clist_row_selected; static int row_selected;
/****************************** Prototypes ************************************/ /****************************** Prototypes ************************************/
static void cb_clist_selection(GtkWidget *clist, gint row, gint column,
GdkEventButton *event, gpointer data); void selectFirstRow(const GtkTreeView *treeView);
enum {
SEARCH_APP_NAME_COLUMN_ENUM = 0,
SEARCH_TEXT_COLUMN_ENUM,
SEARCH_DATA_ENUM,
SEARCH_NUM_COLS
};
/****************************** Main Code *************************************/ /****************************** Main Code *************************************/
static int datebook_search_sort_compare(const void *v1, const void *v2) static int datebook_search_sort_compare(const void *v1, const void *v2) {
{ CalendarEventList **cel1, **cel2;
CalendarEventList **cel1, **cel2; struct CalendarEvent *ce1, *ce2;
struct CalendarEvent *ce1, *ce2; time_t time1, time2;
time_t time1, time2;
cel1 = (CalendarEventList **) v1;
cel1=(CalendarEventList **)v1; cel2 = (CalendarEventList **) v2;
cel2=(CalendarEventList **)v2;
ce1 = &((*cel1)->mcale.cale);
ce1=&((*cel1)->mcale.cale); ce2 = &((*cel2)->mcale.cale);
ce2=&((*cel2)->mcale.cale);
time1 = mktime(&(ce1->begin));
time1 = mktime(&(ce1->begin)); time2 = mktime(&(ce2->begin));
time2 = mktime(&(ce2->begin));
return (time2 - time1);
return(time2 - time1); }
}
static int search_datebook(const char *needle, GtkListStore *listStore, GtkTreeI
static int search_datebook(const char *needle, GtkWidget *clist) ter *iter) {
{ CalendarEventList *ce_list;
gchar *empty_line[] = { "","" }; CalendarEventList *temp_cel;
CalendarEventList *ce_list; int found, count;
CalendarEventList *temp_cel; int case_sense;
int found, count; char str[202];
int case_sense; char str2[SEARCH_MAX_COLUMN_LEN + 2];
char str[202]; char date_str[52];
char str2[SEARCH_MAX_COLUMN_LEN+2]; char datef[52];
char date_str[52]; const char *svalue1;
char datef[52]; struct search_record *new_sr;
const char *svalue1; long datebook_version = 0;
struct search_record *new_sr; char *appName;
long datebook_version=0; char *text;
get_pref(PREF_DATEBOOK_VERSION, &datebook_version, NULL); get_pref(PREF_DATEBOOK_VERSION, &datebook_version, NULL);
/* Search Appointments */ /* Search Appointments */
ce_list = NULL; ce_list = NULL;
get_days_calendar_events2(&ce_list, NULL, 2, 2, 2, CATEGORY_ALL, NULL); get_days_calendar_events2(&ce_list, NULL, 2, 2, 2, CATEGORY_ALL, NULL);
if (ce_list==NULL) { if (ce_list == NULL) {
return 0; return 0;
} }
/* Sort returned results according to date rather than just HH:MM */ /* Sort returned results according to date rather than just HH:MM */
calendar_sort(&ce_list, datebook_search_sort_compare); calendar_sort(&ce_list, datebook_search_sort_compare);
count = 0; count = 0;
case_sense = GTK_TOGGLE_BUTTON(case_sense_checkbox)->active; case_sense = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(case_sense_check
box));
for (temp_cel = ce_list; temp_cel; temp_cel=temp_cel->next) {
found = 0; for (temp_cel = ce_list; temp_cel; temp_cel = temp_cel->next) {
if ( (temp_cel->mcale.cale.description) && found = 0;
(temp_cel->mcale.cale.description[0]) ) { if ((temp_cel->mcale.cale.description) &&
if (jp_strstr(temp_cel->mcale.cale.description, needle, case_sense)) { (temp_cel->mcale.cale.description[0])) {
found = 1; if (jp_strstr(temp_cel->mcale.cale.description, needle, case_sense))
} {
} found = 1;
if ( !found && }
(temp_cel->mcale.cale.note) && }
(temp_cel->mcale.cale.note[0]) ) { if (!found &&
if (jp_strstr(temp_cel->mcale.cale.note, needle, case_sense )) { (temp_cel->mcale.cale.note) &&
found = 2; (temp_cel->mcale.cale.note[0])) {
} if (jp_strstr(temp_cel->mcale.cale.note, needle, case_sense)) {
} found = 2;
if (datebook_version) { }
if ( !found && }
(temp_cel->mcale.cale.location) && if (datebook_version) {
(temp_cel->mcale.cale.location[0]) ) { if (!found &&
if (jp_strstr(temp_cel->mcale.cale.location, needle, case_sense )) { (temp_cel->mcale.cale.location) &&
found = 3; (temp_cel->mcale.cale.location[0])) {
} if (jp_strstr(temp_cel->mcale.cale.location, needle, case_sense)
} ) {
} found = 3;
}
if (found) { }
gtk_clist_prepend(GTK_CLIST(clist), empty_line); }
if (datebook_version==0) {
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("datebook")); if (found) {
} else { text = NULL;
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("calendar")); gtk_list_store_append(listStore, iter);
} if (datebook_version == 0) {
appName = _("datebook");
/* get the date */ } else {
get_pref(PREF_SHORTDATE, NULL, &svalue1); appName = _("calendar");
if (svalue1 == NULL) { }
strcpy(datef, "%x");
} else {
strncpy(datef, svalue1, sizeof(datef));
}
strftime(date_str, sizeof(date_str), datef, &temp_cel->mcale.cale.begin
);
date_str[sizeof(date_str)-1]='\0';
if (found == 1) {
g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.description);
} else if (found == 2) {
g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.note);
} else {
g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.location);
}
lstrncpy_remove_cr_lfs(str2, str, SEARCH_MAX_COLUMN_LEN);
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, str2);
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = DATEBOOK;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_cel->mcale.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_clist_set_row_data(GTK_CLIST(clist), 0, new_sr);
count++;
}
}
jp_logf(JP_LOG_DEBUG, "calling free_CalendarEventList\n");
free_CalendarEventList(&ce_list);
return count;
}
static int search_address_or_contacts(const char *needle, GtkWidget *clist)
{
gchar *empty_line[] = { "","" };
char str2[SEARCH_MAX_COLUMN_LEN+2];
AddressList *addr_list;
ContactList *cont_list;
ContactList *temp_cl;
struct search_record *new_sr;
int i, count;
int case_sense;
long address_version=0;
get_pref(PREF_ADDRESS_VERSION, &address_version, NULL);
/* Get addresses and move to a contacts structure, or get contacts directly *
/
if (address_version==0) {
addr_list = NULL;
get_addresses2(&addr_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
copy_addresses_to_contacts(addr_list, &cont_list);
free_AddressList(&addr_list);
} else {
cont_list = NULL;
get_contacts2(&cont_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
}
if (cont_list==NULL) {
return 0;
}
count = 0;
case_sense = GTK_TOGGLE_BUTTON(case_sense_checkbox)->active;
for (temp_cl = cont_list; temp_cl; temp_cl=temp_cl->next) {
for (i=0; i<NUM_CONTACT_ENTRIES; i++) {
if (temp_cl->mcont.cont.entry[i]) {
if ( jp_strstr(temp_cl->mcont.cont.entry[i], needle, case_sense) ) {
gtk_clist_prepend(GTK_CLIST(clist), empty_line);
if (address_version==0) {
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("address"));
} else {
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("contact"));
}
lstrncpy_remove_cr_lfs(str2, temp_cl->mcont.cont.entry[i], SEARCH
_MAX_COLUMN_LEN);
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, str2);
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = ADDRESS;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_cl->mcont.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_clist_set_row_data(GTK_CLIST(clist), 0, new_sr);
count++;
break;
}
}
}
}
jp_logf(JP_LOG_DEBUG, "calling free_ContactList\n");
free_ContactList(&cont_list);
return count;
}
static int search_todo(const char *needle, GtkWidget *clist)
{
gchar *empty_line[] = { "","" };
char str2[SEARCH_MAX_COLUMN_LEN+2];
ToDoList *todo_list;
ToDoList *temp_todo;
struct search_record *new_sr;
int found, count;
int case_sense;
/* Search Appointments */
todo_list = NULL;
get_todos2(&todo_list, SORT_DESCENDING, 2, 2, 2, 1, CATEGORY_ALL);
if (todo_list==NULL) {
return 0;
}
count = 0;
case_sense = GTK_TOGGLE_BUTTON(case_sense_checkbox)->active;
for (temp_todo = todo_list; temp_todo; temp_todo=temp_todo->next) {
found = 0;
if ( (temp_todo->mtodo.todo.description) &&
(temp_todo->mtodo.todo.description[0]) ) {
if ( jp_strstr(temp_todo->mtodo.todo.description, needle, case_sense) )
{
found = 1;
}
}
if ( !found &&
(temp_todo->mtodo.todo.note) &&
(temp_todo->mtodo.todo.note[0]) ) {
if ( jp_strstr(temp_todo->mtodo.todo.note, needle, case_sense) ) {
found = 2;
}
}
if (found) {
gtk_clist_prepend(GTK_CLIST(clist), empty_line);
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("todo"));
if (found == 1) {
lstrncpy_remove_cr_lfs(str2, temp_todo->mtodo.todo.description, SEAR
CH_MAX_COLUMN_LEN);
} else {
lstrncpy_remove_cr_lfs(str2, temp_todo->mtodo.todo.note, SEARCH_MAX_
COLUMN_LEN);
}
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, str2);
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = TODO;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_todo->mtodo.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_clist_set_row_data(GTK_CLIST(clist), 0, new_sr);
count++;
}
}
jp_logf(JP_LOG_DEBUG, "calling free_ToDoList\n");
free_ToDoList(&todo_list);
return count;
}
static int search_memo(const char *needle, GtkWidget *clist)
{
gchar *empty_line[] = { "","" };
char str2[SEARCH_MAX_COLUMN_LEN+2];
MemoList *memo_list;
MemoList *temp_memo;
struct search_record *new_sr;
int count;
int case_sense;
long memo_version=0;
get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
/* Search Memos */
memo_list = NULL;
get_memos2(&memo_list, SORT_DESCENDING, 2, 2, 2, CATEGORY_ALL);
if (memo_list==NULL) {
return 0;
}
count = 0;
case_sense = GTK_TOGGLE_BUTTON(case_sense_checkbox)->active;
for (temp_memo = memo_list; temp_memo; temp_memo=temp_memo->next) {
if (jp_strstr(temp_memo->mmemo.memo.text, needle, case_sense) ) {
gtk_clist_prepend(GTK_CLIST(clist), empty_line);
if (memo_version==0) {
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("memo"));
} else {
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("memos"));
}
if (temp_memo->mmemo.memo.text) {
lstrncpy_remove_cr_lfs(str2, temp_memo->mmemo.memo.text, SEARCH_MAX_
COLUMN_LEN);
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, str2);
}
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = MEMO;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_memo->mmemo.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_clist_set_row_data(GTK_CLIST(clist), 0, new_sr);
count++;
}
}
jp_logf(JP_LOG_DEBUG, "calling free_MemoList\n"); /* get the date */
free_MemoList(&memo_list); get_pref(PREF_SHORTDATE, NULL, &svalue1);
if (svalue1 == NULL) {
strcpy(datef, "%x");
} else {
strncpy(datef, svalue1, sizeof(datef));
}
strftime(date_str, sizeof(date_str), datef, &temp_cel->mcale.cale.be
gin);
date_str[sizeof(date_str) - 1] = '\0';
return count; if (found == 1) {
} g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.description);
} else if (found == 2) {
g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.note);
} else {
g_snprintf(str, sizeof(str), "%s\t%s",
date_str,
temp_cel->mcale.cale.location);
}
lstrncpy_remove_cr_lfs(str2, str, SEARCH_MAX_COLUMN_LEN);
text = str2;
#ifdef ENABLE_PLUGINS /* Add to the search list */
static int search_plugins(const char *needle, const GtkWidget *clist) new_sr = malloc(sizeof(struct search_record));
{ new_sr->app_type = DATEBOOK;
GList *plugin_list, *temp_list; new_sr->plugin_flag = 0;
gchar *empty_line[] = { "","" }; new_sr->unique_id = temp_cel->mcale.unique_id;
char str2[SEARCH_MAX_COLUMN_LEN+2]; new_sr->next = search_rl;
int found; search_rl = new_sr;
int count;
int case_sense; gtk_list_store_set(listStore, iter,
struct search_result *sr, *temp_sr; SEARCH_APP_NAME_COLUMN_ENUM, appName,
struct plugin_s *plugin; SEARCH_TEXT_COLUMN_ENUM, text,
struct search_record *new_sr; SEARCH_DATA_ENUM, new_sr, -1);
plugin_list = NULL; count++;
plugin_list = get_plugin_list(); }
}
found = 0;
case_sense = GTK_TOGGLE_BUTTON(case_sense_checkbox)->active; jp_logf(JP_LOG_DEBUG, "calling free_CalendarEventList\n");
free_CalendarEventList(&ce_list);
count = 0;
for (temp_list = plugin_list; temp_list; temp_list = temp_list->next) { return count;
plugin = (struct plugin_s *)temp_list->data; }
if (plugin) {
sr = NULL; static int search_address_or_contacts(const char *needle, GtkListStore *listStor
if (plugin->plugin_search) { e, GtkTreeIter *iter) {
if (plugin->plugin_search(needle, case_sense, &sr) > 0) { char str2[SEARCH_MAX_COLUMN_LEN + 2];
for (temp_sr=sr; temp_sr; temp_sr=temp_sr->next) { AddressList *addr_list;
gtk_clist_prepend(GTK_CLIST(clist), empty_line); ContactList *cont_list;
if (plugin->menu_name) { ContactList *temp_cl;
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, plugin->menu_nam char *appName;
e); char *text;
} else { struct search_record *new_sr;
gtk_clist_set_text(GTK_CLIST(clist), 0, 0, _("plugin ?")); int i, count;
} int case_sense;
if (temp_sr->line) { long address_version = 0;
lstrncpy_remove_cr_lfs(str2, temp_sr->line, SEARCH_MAX_COLU
MN_LEN); get_pref(PREF_ADDRESS_VERSION, &address_version, NULL);
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, str2);
} /* Get addresses and move to a contacts structure, or get contacts directly
*/
/* Add to the search list */ if (address_version == 0) {
new_sr = malloc(sizeof(struct search_record)); addr_list = NULL;
new_sr->app_type = plugin->number; get_addresses2(&addr_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
new_sr->plugin_flag = 1; copy_addresses_to_contacts(addr_list, &cont_list);
new_sr->unique_id = temp_sr->unique_id; free_AddressList(&addr_list);
new_sr->next = search_rl; } else {
search_rl = new_sr; cont_list = NULL;
get_contacts2(&cont_list, SORT_ASCENDING, 2, 2, 2, CATEGORY_ALL);
gtk_clist_set_row_data(GTK_CLIST(clist), 0, new_sr); }
count++; if (cont_list == NULL) {
} return 0;
free_search_result(&sr); }
}
} count = 0;
} case_sense = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(case_sense_check
} box));
for (temp_cl = cont_list; temp_cl; temp_cl = temp_cl->next) {
for (i = 0; i < NUM_CONTACT_ENTRIES; i++) {
if (temp_cl->mcont.cont.entry[i]) {
if (jp_strstr(temp_cl->mcont.cont.entry[i], needle, case_sense))
{
gtk_list_store_append(listStore, iter);
if (address_version == 0) {
appName = _("address");
} else {
appName = _("contact");
}
lstrncpy_remove_cr_lfs(str2, temp_cl->mcont.cont.entry[i], S
EARCH_MAX_COLUMN_LEN);
text = str2;
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = ADDRESS;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_cl->mcont.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_list_store_set(listStore, iter,
SEARCH_APP_NAME_COLUMN_ENUM, appName,
SEARCH_TEXT_COLUMN_ENUM, text,
SEARCH_DATA_ENUM, new_sr, -1);
return count; count++;
}
#endif
static gboolean cb_destroy(GtkWidget *widget) break;
{ }
if (search_rl) { }
free_search_record_list(&search_rl); }
search_rl = NULL; }
}
window = NULL;
return FALSE; jp_logf(JP_LOG_DEBUG, "calling free_ContactList\n");
} free_ContactList(&cont_list);
static void cb_quit(GtkWidget *widget, gpointer data) return count;
{
gtk_widget_destroy(data);
} }
static void cb_entry(GtkWidget *widget, gpointer data) static int search_todo(const char *needle, GtkListStore *listStore, GtkTreeIter
{ *iter) {
gchar *empty_line[] = { "","" }; char str2[SEARCH_MAX_COLUMN_LEN + 2];
GtkWidget *clist; char *appName = _("todo");
const char *entry_text; ToDoList *todo_list;
int count = 0; ToDoList *temp_todo;
struct search_record *new_sr;
int found, count;
int case_sense;
/* Search Appointments */
todo_list = NULL;
get_todos2(&todo_list, SORT_DESCENDING, 2, 2, 2, 1, CATEGORY_ALL);
if (todo_list == NULL) {
return 0;
}
count = 0;
case_sense = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(case_sense_check
box));
for (temp_todo = todo_list; temp_todo; temp_todo = temp_todo->next) {
found = 0;
if ((temp_todo->mtodo.todo.description) &&
(temp_todo->mtodo.todo.description[0])) {
if (jp_strstr(temp_todo->mtodo.todo.description, needle, case_sense)
) {
found = 1;
}
}
if (!found &&
(temp_todo->mtodo.todo.note) &&
(temp_todo->mtodo.todo.note[0])) {
if (jp_strstr(temp_todo->mtodo.todo.note, needle, case_sense)) {
found = 2;
}
}
if (found) {
gtk_list_store_append(listStore, iter);
if (found == 1) {
lstrncpy_remove_cr_lfs(str2, temp_todo->mtodo.todo.description,
SEARCH_MAX_COLUMN_LEN);
} else {
lstrncpy_remove_cr_lfs(str2, temp_todo->mtodo.todo.note, SEARCH_
MAX_COLUMN_LEN);
}
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = TODO;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_todo->mtodo.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_list_store_set(listStore, iter,
SEARCH_APP_NAME_COLUMN_ENUM, appName,
SEARCH_TEXT_COLUMN_ENUM, str2,
SEARCH_DATA_ENUM, new_sr, -1);
count++;
}
}
jp_logf(JP_LOG_DEBUG, "calling free_ToDoList\n");
free_ToDoList(&todo_list);
return count;
}
static int search_memo(const char *needle, GtkListStore *listStore, GtkTreeIter
*iter) {
char str2[SEARCH_MAX_COLUMN_LEN + 2];
MemoList *memo_list;
MemoList *temp_memo;
struct search_record *new_sr;
int count;
int case_sense;
long memo_version = 0;
char *appName;
char *text;
get_pref(PREF_MEMO_VERSION, &memo_version, NULL);
/* Search Memos */
memo_list = NULL;
get_memos2(&memo_list, SORT_DESCENDING, 2, 2, 2, CATEGORY_ALL);
if (memo_list == NULL) {
return 0;
}
count = 0;
case_sense = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(case_sense_check
box));
for (temp_memo = memo_list; temp_memo; temp_memo = temp_memo->next) {
if (jp_strstr(temp_memo->mmemo.memo.text, needle, case_sense)) {
text = NULL;
gtk_list_store_append(listStore, iter);
if (memo_version == 0) {
appName = _("memo");
} else {
appName = _("memos");
}
if (temp_memo->mmemo.memo.text) {
lstrncpy_remove_cr_lfs(str2, temp_memo->mmemo.memo.text, SEARCH_
MAX_COLUMN_LEN);
text = str2;
}
jp_logf(JP_LOG_DEBUG, "enter cb_entry\n"); /* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = MEMO;
new_sr->plugin_flag = 0;
new_sr->unique_id = temp_memo->mmemo.unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_list_store_set(listStore, iter,
SEARCH_APP_NAME_COLUMN_ENUM, appName,
SEARCH_TEXT_COLUMN_ENUM, text,
SEARCH_DATA_ENUM, new_sr, -1);
count++;
}
}
entry_text = gtk_entry_get_text(GTK_ENTRY(widget)); jp_logf(JP_LOG_DEBUG, "calling free_MemoList\n");
if (!entry_text || !strlen(entry_text)) { free_MemoList(&memo_list);
return;
}
jp_logf(JP_LOG_DEBUG, "entry text = %s\n", entry_text); return count;
}
clist = data; #ifdef ENABLE_PLUGINS
gtk_clist_clear(GTK_CLIST(clist));
count += search_address_or_contacts(entry_text, clist); static int search_plugins(const char *needle, GtkListStore *listStore, GtkTreeIt
count += search_todo(entry_text, clist); er *iter) {
count += search_memo(entry_text, clist); GList *plugin_list, *temp_list;
char str2[SEARCH_MAX_COLUMN_LEN + 2];
int count;
int case_sense;
struct search_result *sr, *temp_sr;
struct plugin_s *plugin;
struct search_record *new_sr;
char *appName;
char *text;
plugin_list = NULL;
plugin_list = get_plugin_list();
case_sense = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(case_sense_check
box));
count = 0;
for (temp_list = plugin_list; temp_list; temp_list = temp_list->next) {
plugin = (struct plugin_s *) temp_list->data;
if (plugin) {
sr = NULL;
if (plugin->plugin_search) {
if (plugin->plugin_search(needle, case_sense, &sr) > 0) {
for (temp_sr = sr; temp_sr; temp_sr = temp_sr->next) {
text = NULL;
gtk_list_store_append(listStore, iter);
if (plugin->menu_name) {
appName = plugin->menu_name;
} else {
appName = _("plugin ?");
}
if (temp_sr->line) {
lstrncpy_remove_cr_lfs(str2, temp_sr->line, SEARCH_M
AX_COLUMN_LEN);
text = str2;
}
/* Add to the search list */
new_sr = malloc(sizeof(struct search_record));
new_sr->app_type = plugin->number;
new_sr->plugin_flag = 1;
new_sr->unique_id = temp_sr->unique_id;
new_sr->next = search_rl;
search_rl = new_sr;
gtk_list_store_set(listStore, iter,
SEARCH_APP_NAME_COLUMN_ENUM, appName,
SEARCH_TEXT_COLUMN_ENUM, text,
SEARCH_DATA_ENUM, new_sr, -1);
count++;
}
free_search_result(&sr);
}
}
}
}
return count;
}
#endif
static gboolean cb_destroy(GtkWidget *widget) {
if (search_rl) {
free_search_record_list(&search_rl);
search_rl = NULL;
}
window = NULL;
return FALSE;
}
static void cb_quit(GtkWidget *widget, gpointer data) {
gtk_widget_destroy(data);
}
static void cb_entry(GtkWidget *widget, gpointer data) {
GtkListStore *listStore;
GtkTreeView *treeView;
GtkTreeIter iter;
const char *entry_text;
int count = 0;
jp_logf(JP_LOG_DEBUG, "enter cb_entry\n");
entry_text = gtk_entry_get_text(GTK_ENTRY(widget));
if (!entry_text || !strlen(entry_text)) {
return;
}
jp_logf(JP_LOG_DEBUG, "entry text = %s\n", entry_text);
treeView = data;
listStore = GTK_LIST_STORE(gtk_tree_view_get_model(treeView));
gtk_list_store_clear(listStore);
count += search_address_or_contacts(entry_text, listStore, &iter);
count += search_todo(entry_text, listStore, &iter);
count += search_memo(entry_text, listStore, &iter);
#ifdef ENABLE_PLUGINS #ifdef ENABLE_PLUGINS
count += search_plugins(entry_text, clist); count += search_plugins(entry_text, listStore, &iter);
#endif #endif
/* sort the results */ /* sort the results */
gtk_clist_set_sort_column(GTK_CLIST(clist), 1); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(listStore), SEARCH_TE
gtk_clist_sort(GTK_CLIST(clist)); XT_COLUMN_ENUM, GTK_SORT_ASCENDING);
/* the datebook events are already sorted by date */ /* the datebook events are already sorted by date */
count += search_datebook(entry_text, clist); count += search_datebook(entry_text, listStore, &iter);
if (count == 0) { if (count == 0) {
gtk_clist_prepend(GTK_CLIST(clist), empty_line); gtk_list_store_append(listStore, &iter);
gtk_clist_set_text(GTK_CLIST(clist), 0, 1, _("No records found")); gtk_list_store_set(listStore, &iter,
} SEARCH_TEXT_COLUMN_ENUM,("No records found"),-1);
/* Highlight the first row in the list of returned items. }
* This does NOT cause the main window to jump to the selected record. */
clist_select_row(GTK_CLIST(clist), 0, 0); /* Highlight the first row in the list of returned items.
* This does NOT cause the main window to jump to the selected record. */
/* select the first record found */
cb_clist_selection(clist, 0, 0, (GdkEventButton *)1, NULL); /* select the first record found */
selectFirstRow(treeView);
return;
} return;
}
static void cb_search(GtkWidget *widget, gpointer data)
{ void selectFirstRow(const GtkTreeView *treeView) {
cb_entry(entry, data); GtkTreeSelection * selection = NULL;
} selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
GtkTreePath *path = NULL;
static void cb_clist_selection(GtkWidget *clist, GtkTreeIter firstIter;
gint row, gtk_tree_model_get_iter_first(gtk_tree_view_get_model(GTK_TREE_VIEW(treeView
gint column, )), &firstIter);
GdkEventButton *event, path = gtk_tree_model_get_path(gtk_tree_view_get_model(GTK_TREE_VIEW(treeVie
gpointer data) w)), &firstIter);
{ gtk_tree_selection_select_path(selection, path);
struct search_record *sr; gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeView), path, NULL, FALSE, 1.0
, 0.0);
clist_row_selected = row; gtk_tree_path_free(path);
}
if (!event) return;
static void cb_search(GtkWidget *widget, gpointer data) {
sr = gtk_clist_get_row_data(GTK_CLIST(clist), row); cb_entry(entry, data);
if (sr == NULL) { }
return;
} static gboolean handleSearchRowSelection(GtkTreeSelection *selection,
switch (sr->app_type) { GtkTreeModel *model,
case DATEBOOK: GtkTreePath *path,
glob_find_id = sr->unique_id; gboolean path_currently_selected,
cb_app_button(NULL, GINT_TO_POINTER(DATEBOOK)); gpointer userdata) {
break; GtkTreeIter iter;
case ADDRESS: struct search_record *sr;
glob_find_id = sr->unique_id;
cb_app_button(NULL, GINT_TO_POINTER(ADDRESS)); if ((gtk_tree_model_get_iter(model, &iter, path)) && (!path_currently_select
break; ed)) {
case TODO: int * i = gtk_tree_path_get_indices ( path ) ;
glob_find_id = sr->unique_id; row_selected = i[0];
cb_app_button(NULL, GINT_TO_POINTER(TODO)); gtk_tree_model_get(model, &iter, SEARCH_DATA_ENUM, &sr, -1);
break; if(sr == NULL){
case MEMO: return TRUE;
glob_find_id = sr->unique_id; }switch (sr->app_type) {
cb_app_button(NULL, GINT_TO_POINTER(MEMO)); case DATEBOOK:
break; glob_find_id = sr->unique_id;
default: cb_app_button(NULL, GINT_TO_POINTER(DATEBOOK));
break;
case ADDRESS:
glob_find_id = sr->unique_id;
cb_app_button(NULL, GINT_TO_POINTER(ADDRESS));
break;
case TODO:
glob_find_id = sr->unique_id;
cb_app_button(NULL, GINT_TO_POINTER(TODO));
break;
case MEMO:
glob_find_id = sr->unique_id;
cb_app_button(NULL, GINT_TO_POINTER(MEMO));
break;
default:
#ifdef ENABLE_PLUGINS #ifdef ENABLE_PLUGINS
/* Not one of the main 4 apps so it must be a plugin */ /* Not one of the main 4 apps so it must be a plugin */
jp_logf(JP_LOG_DEBUG, "choosing search result from plugin %d\n", sr->app_t jp_logf(JP_LOG_DEBUG, "choosing search result from plugin %d\n",
ype); sr->app_type);
call_plugin_gui(sr->app_type, sr->unique_id); call_plugin_gui(sr->app_type, sr->unique_id);
#endif #endif
break; break;
} }
}
return TRUE;
} }
static gboolean cb_key_pressed_in_clist(GtkWidget *widget, static gboolean cb_key_pressed_in_list(GtkWidget *widget,
GdkEventKey *event, GdkEventKey *event,
gpointer data) gpointer data) {
{ 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"); return TRUE;
cb_clist_selection(widget, clist_row_selected, 0, (GdkEventButton *)1, NUL }
L);
return FALSE;
return TRUE; }
}
void cb_search_gui(GtkWidget *widget, gpointer data) {
return FALSE; GtkWidget *scrolled_window;
} GtkWidget *treeView;
GtkListStore *listStore;
void cb_search_gui(GtkWidget *widget, gpointer data) GtkWidget *label;
{ GtkWidget *button;
GtkWidget *scrolled_window; GtkWidget *vbox, *hbox;
GtkWidget *clist; char temp[256];
GtkWidget *label;
GtkWidget *button; if (GTK_IS_WIDGET(window)) {
GtkWidget *vbox, *hbox; /* Shift focus to existing window if called again
char temp[256]; and window is still alive. */
gtk_window_present(GTK_WINDOW(window));
if (GTK_IS_WIDGET(window)) { gtk_widget_grab_focus(GTK_WIDGET(entry));
/* Shift focus to existing window if called again return;
and window is still alive. */ }
gtk_window_present(GTK_WINDOW(window));
gtk_widget_grab_focus(GTK_WIDGET(entry)); if (search_rl) {
return; free_search_record_list(&search_rl);
} search_rl = NULL;
}
if (search_rl) {
free_search_record_list(&search_rl); window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
search_rl = NULL; gtk_window_set_default_size(GTK_WINDOW(window), 500, 300);
} g_snprintf(temp, sizeof(temp), "%s %s", PN, _("Search"));
gtk_window_set_title(GTK_WINDOW(window), temp);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 300); g_signal_connect(G_OBJECT(window), "destroy",
g_snprintf(temp, sizeof(temp), "%s %s", PN, _("Search")); G_CALLBACK(cb_destroy), window);
gtk_window_set_title(GTK_WINDOW(window), temp);
accel_group = gtk_accel_group_new();
gtk_signal_connect(GTK_OBJECT(window), "destroy", gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
GTK_SIGNAL_FUNC(cb_destroy), window);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
accel_group = gtk_accel_group_new(); gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
vbox = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
gtk_container_add(GTK_CONTAINER(window), vbox); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
hbox = gtk_hbox_new(FALSE, 0); /* Search label */
gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); label = gtk_label_new(_("Search for: "));
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
/* Search label */ /* Search entry */
label = gtk_label_new(_("Search for: ")); entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
gtk_widget_grab_focus(GTK_WIDGET(entry));
/* Search entry */
entry = gtk_entry_new(); /* Case Sensitive checkbox */
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); case_sense_checkbox = gtk_check_button_new_with_label(_("Case Sensitive"));
gtk_widget_grab_focus(GTK_WIDGET(entry)); gtk_box_pack_start(GTK_BOX(hbox), case_sense_checkbox, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(case_sense_checkbox),
/* Case Sensitive checkbox */ FALSE);
case_sense_checkbox = gtk_check_button_new_with_label(_("Case Sensitive"));
gtk_box_pack_start(GTK_BOX(hbox), case_sense_checkbox, FALSE, FALSE, 0); /* Scrolled window for search results */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(case_sense_checkbox), scrolled_window = gtk_scrolled_window_new(NULL, NULL);
FALSE); gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 3);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
/* Scrolled window for search results */ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 3); listStore = gtk_list_store_new(SEARCH_NUM_COLS, G_TYPE_STRING, G_TYPE_STRING
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), , G_TYPE_POINTER);
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(listStore));
gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); GtkCellRenderer *appNameRenderer = gtk_cell_renderer_text_new();
clist = gtk_clist_new(2); GtkTreeViewColumn *appNameColumn = gtk_tree_view_column_new_with_attributes(
gtk_signal_connect(GTK_OBJECT(clist), "select_row", "",
GTK_SIGNAL_FUNC(cb_clist_selection),
NULL); appNameRenderer,
gtk_signal_connect(GTK_OBJECT(clist), "key_press_event",
GTK_SIGNAL_FUNC(cb_key_pressed_in_clist), "text", SEARCH_APP_NAME_COLUMN_ENUM,
NULL);
gtk_clist_set_shadow_type(GTK_CLIST(clist), SHADOW); NULL);
gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE); gtk_tree_view_column_set_sort_column_id(appNameColumn, SEARCH_APP_NAME_COLUM
gtk_clist_set_column_auto_resize(GTK_CLIST(clist), 0, TRUE); N_ENUM);
gtk_clist_set_column_auto_resize(GTK_CLIST(clist), 1, TRUE); GtkCellRenderer *textRenderer = gtk_cell_renderer_text_new();
gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(clist)); GtkTreeViewColumn *textColumn = gtk_tree_view_column_new_with_attributes("",
tex
gtk_signal_connect(GTK_OBJECT(entry), "activate", tRenderer,
GTK_SIGNAL_FUNC(cb_entry), "te
clist); xt", SEARCH_TEXT_COLUMN_ENUM,
NUL
hbox = gtk_hbutton_box_new(); L);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); gtk_tree_view_column_set_sort_column_id(textColumn, SEARCH_TEXT_COLUMN_ENUM)
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); ;
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 6); gtk_tree_view_insert_column(GTK_TREE_VIEW (treeView), appNameColumn, SEARCH_
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); APP_NAME_COLUMN_ENUM);
gtk_tree_view_insert_column(GTK_TREE_VIEW (treeView), textColumn, SEARCH_TEX
/* Search button */ T_COLUMN_ENUM);
button = gtk_button_new_from_stock(GTK_STOCK_FIND); gtk_tree_view_column_set_clickable(appNameColumn, gtk_false());
gtk_signal_connect(GTK_OBJECT(button), "clicked", gtk_tree_view_column_set_clickable(textColumn, gtk_false());
GTK_SIGNAL_FUNC(cb_search), clist); gtk_tree_view_column_set_sizing(appNameColumn, GTK_TREE_VIEW_COLUMN_AUTOSIZE
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); );
gtk_tree_view_column_set_sizing(textColumn, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
/* clicking on "Case Sensitive" also starts a search */ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), gtk_false());
gtk_signal_connect(GTK_OBJECT(case_sense_checkbox), "clicked", gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeVi
GTK_SIGNAL_FUNC(cb_search), clist); ew)), GTK_SELECTION_BROWSE);
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_
/* Done button */ VIEW(treeView)), handleSearchRowSelection, NULL, NULL);
button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); gtk_widget_set_events(GTK_WIDGET(treeView), GDK_BUTTON1_MOTION_MASK);
gtk_signal_connect(GTK_OBJECT(button), "clicked", g_signal_connect (G_OBJECT(treeView), "motion_notify_event",
GTK_SIGNAL_FUNC(cb_quit), window); G_CALLBACK(motion_notify_event), NULL);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); g_signal_connect (G_OBJECT(treeView), "button-press-event",
gtk_widget_add_accelerator(button, "clicked", accel_group, GDK_Escape, 0, 0); G_CALLBACK(button_pressed_for_motion), NULL);
g_signal_connect (G_OBJECT(treeView), "button-release-event",
G_CALLBACK(button_released_for_motion), NULL);
g_signal_connect(G_OBJECT(treeView), "key_press_event",
G_CALLBACK(cb_key_pressed_in_list),
NULL);
gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(treeView));
g_signal_connect(G_OBJECT(entry), "activate",
G_CALLBACK(cb_entry),
treeView);
hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
/* Search button */
button = gtk_button_new_with_label("Search");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_search), treeView);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
/* clicking on "Case Sensitive" also starts a search */
g_signal_connect(G_OBJECT(case_sense_checkbox), "clicked",
G_CALLBACK(cb_search), treeView);
/* Done button */
button = gtk_button_new_with_label("Done");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(cb_quit), window);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
gtk_widget_add_accelerator(button, "clicked", accel_group, GDK_KEY_Escape, 0
, 0);
gtk_widget_show_all(window); gtk_widget_show_all(window);
} }
 End of changes. 27 change blocks. 
603 lines changed or deleted 690 lines changed or added

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