-
Notifications
You must be signed in to change notification settings - Fork 1
/
parish_search_main.c
127 lines (104 loc) · 3.98 KB
/
parish_search_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*Implements callbacks for search window*/
/* Copyright (C) 2009 Arun S.A.G.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "parish_search_main.h"
void on_search_main_cancel_button_clicked(GtkButton *button,gpointer user_data)
{
GtkWidget *widget;
widget = (GtkWidget *) gtk_builder_get_object(build,"search_main");
gtk_widget_hide(widget);
}
void on_search_main_query_insert_text(GtkEditable *editable,gchar *new_text,gint new_text_length,gint *position,gpointer user_data)
{
if(!g_regex_match_simple("[a-zA-Z0-9 /.]+",new_text,0,0))
{
g_signal_stop_emission_by_name (editable,"insert-text");
}
}
void on_search_main_search_button_clicked(GtkButton *button,gpointer user_data)
{
GtkWidget *widget,*view;
GString *result;
GtkTextBuffer *textbuf;
gchar querystring[30];
gchar *searchby[2][4] = {{"name","dad","mom","date_birth"},{"bride_name","groom_name","date_marriage",""}};
gchar *table[] = {"baptism_cert","marriage_cert"};
int radio=0;
int cbox_index=-1;
int cols;
result=g_string_new("");
if( !is_valid_search(querystring,&cbox_index,&radio))
{
return;
}
do_search(querystring,searchby[radio][cbox_index],table[radio]);
widget = (GtkWidget *) gtk_builder_get_object(build,"search_main");
gtk_widget_hide(widget);
cols = sqlite3_column_count(stmt);
prepare_results(result,cols,radio);
view = (GtkWidget *)gtk_builder_get_object(build,"search_results_text");
textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
gtk_text_buffer_set_text(textbuf,result->str,-1);
widget = (GtkWidget *)gtk_builder_get_object(build,"search_results");
gtk_widget_show(widget);
}
gboolean is_valid_search(gchar *querystring,int *cbox_index,int *index)
{
GtkWidget *widget;
GtkComboBox *cbox;
GtkToggleButton *tb;
tb =(GtkToggleButton *)gtk_builder_get_object(build,"search_main_radio2");
if(gtk_toggle_button_get_active(tb))
{
*index = 1;
}
widget = (GtkWidget *) gtk_builder_get_object(build,"search_main_query");
g_strlcpy(querystring,gtk_entry_get_text(GTK_ENTRY(widget)),30);
if(g_strcmp0(querystring,"") == 0)
{
quick_message("please enter a phrase to search");
return FALSE;
}
cbox = (GtkComboBox *) gtk_builder_get_object(build,"search_main_searchby_combobox");
*cbox_index = gtk_combo_box_get_active(cbox);
if(*cbox_index == -1)
{
quick_message("please select one filed to search with");
return FALSE;
}
if(*cbox_index == 3 || (*cbox_index==2 && *index==1))
{
/*The user input must be a date so validate it*/
if(!g_regex_match_simple("^[0-9]{1,2}[/][0-9]{1,2}[/][0-9]{4}$",querystring,0,0))
{
quick_message("Invalid Date entry to search");
return FALSE;
}
}
return TRUE;
}
void on_search_main_radio2_clicked(GtkButton *button,gpointer user_data)
{
GtkListStore *store;
GtkComboBox *cbox;
store = GTK_LIST_STORE(gtk_builder_get_object(build,"liststore6"));
cbox = (GtkComboBox *)gtk_builder_get_object(build,"search_main_searchby_combobox");
gtk_combo_box_set_model(cbox,GTK_TREE_MODEL(store));
}
void on_search_main_radio1_clicked(GtkButton *button,gpointer user_data)
{
GtkListStore *store;
GtkComboBox *cbox;
store = GTK_LIST_STORE(gtk_builder_get_object(build,"liststore2"));
cbox = (GtkComboBox *)gtk_builder_get_object(build,"search_main_searchby_combobox");
gtk_combo_box_set_model(cbox,GTK_TREE_MODEL(store));
}