aboutsummaryrefslogtreecommitdiffstats
path: root/apps/X11/cheatah/cheatsig.cpp
blob: 3b23b0dc6b5bda3246a8befa1027af71183b6b26 (plain) (blame)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*  Note: You are free to use whatever license you want.
    Eventually you will be able to edit it within Glade. */

/*  cheatah
 *  Copyright (C) <YEAR> <AUTHORS>
 *
 *  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 2 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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <gtk/gtk.h>
#include "cheatah.h"
#include "cheatsig.h"

using namespace std;

int
main (int argc, char *argv[])
{
  GtkWidget *mainWindow;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  /*
   * The following code was added by Glade to create one of each component
   * (except popup menus), just so that you see something after building
   * the project. Delete any components that you don't want shown initially.
   */
  mainWindow = create_mainWindow ();
  gtk_widget_show (mainWindow);

  gtk_main ();

  destroy_mainWindow();		
  return 0;
}


void
on_Exit3_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_View3_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_Help_activate                       (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_viewMod_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
	cheatahWindow->viewModActivate(menuitem, (gchar *)user_data);
}


/* 
* This function is used to do a quick and dirty translation of the formating
* commands in the module descriptions into reasonable equivalents in
* plain ascii.  (The descriptions look like .rtf-lite, perhaps?)
* It takes a character pointer to the module description and
* returns a pointer to a new string that's been fixed up.  Ultimately, 
* a better solution should be developed, but this improves the 
* appearance of the descriptions significantly for now.
*
* Perhaps this could serve as the basis for a function that would take
* an input string and a text widget, then insert the string into the 
* widget in a formatted manner (good next step?);
*/

char *
str_fixup_format		(const char *string)
{
	char	*strNew;	
	int 	i,j;

	assert(string!=NULL);
	strNew = (char *) malloc(strlen(string));	// First, allocate space for the new string 
	assert(strNew!=NULL);
	if(strNew==NULL) return ((char *)NULL);	// Make sure we actually got it 

	for (i=0,j=0;i<strlen(string);i++) {		// Work through input string char at a time
	    if (string[i]=='\\') {			// Found backslash, probably a command
                           if (string[i+1]=='q') {			// Looks like an alignment command
                               if(string[i+2]=='c') {			// Want to center text 
		strNew[j]='\n';			// - make do with a new line	
		j++;	
		strNew[j]='\t';			//  - and a tab for now
		j++;
	             }
	              i=i+2;				// Assume command and skip past q and ?
	              continue;
	      }
	      else {					// if string[i+1] != 'q'
                             if(string[i+1]=='p' && string[i+2]=='a' && string[i+3]=='r') {	 // "\par" or "\pard"command?
		if(string[i+4]=='d') {		 // "\pard" command - ignore for now
		    i=i+4;				// Skip past the "pard"
		    continue;
                                     }
		else {				// "\par" command
		    strNew[j]='\n';			// - use a new line for now
		    j++;
		    i=i+3;				// Skip past the "par"
		    continue;
		}
	           }
	       }					// End of "else"
	    }					// End of "if(string[i]=='\\')
	    strNew[j]=string[i];			// Don't know what it is, so copy it
	    j++;	
	}					// End of "for"
	strNew[j]='\0';				// Terminate new string

//	fprintf(stderr, "strlen(string) = %i, strlen(strNew) = %i \n", strlen(string), strlen(strNew));	// Used for debugging
//	fprintf(stderr, "string = \"%s\"\n",string);						// Used for debugging
//	fprintf(stderr, "strNew = \"%s\"\n",strNew);						// Used for debugging

	assert(strlen(strNew)<=strlen(string));	// Nothing we have done should have lengthend it
	return(strNew);				// Return fixed-up string		
}

void
on_About_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
 	SWMgr *mainMgr;

	mainMgr=cheatahWindow->getSwordManager();
	int i;
	char *tempString;
	static char *modtypes[] = {"Biblical Texts", "Commentaries", "Lexicons / Dictionaries"};
	string newtext, tmptext;
	ModMap::iterator it;
	SectionMap::iterator sit;
	ConfigEntMap::iterator eit;

 	GtkWidget *dialogAbout;
	GtkWidget *hBoxModDesc;
	GtkWidget *textAboutMods;
	GtkWidget *textScrollbarMods;
	GtkWidget *hBoxAbout;
	GtkWidget *textAbout;
	GtkWidget *textScrollbar;
	GtkWidget *buttonOK;

	dialogAbout=gtk_dialog_new();
	gtk_object_set_data (GTK_OBJECT (dialogAbout), "dialogAbout", dialogAbout);
	gtk_window_set_title (GTK_WINDOW (dialogAbout), "About Cheatah");
	gtk_window_set_policy (GTK_WINDOW (dialogAbout), FALSE, TRUE, FALSE);
	gtk_widget_set_usize(GTK_WIDGET(dialogAbout), 360, 360);
	gtk_window_position(GTK_WINDOW(dialogAbout),GTK_WIN_POS_CENTER);

	buttonOK = gtk_button_new_with_label("O.k.");

/*								*/
/*	Set it up so that the dialog box and all it's children are automatically	*/	
/*	destroyed when the user is done looking at it.			*/
/*	Note: Use gtk_signal_connect_object() rather than		*/
/*	gtk_signal_connect(), because we want the "destroy" 		*/
/*	connected to the dialog box, not just the button.			*/
/*								*/
 	gtk_signal_connect_object(GTK_OBJECT(buttonOK),
		       "clicked",
		       GTK_SIGNAL_FUNC(gtk_widget_destroy),
		       GTK_OBJECT(dialogAbout));

	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialogAbout)->action_area), buttonOK);

 	hBoxModDesc = gtk_hbox_new (FALSE,0);
  	gtk_object_set_data (GTK_OBJECT (dialogAbout), "hBoxModDesc", hBoxModDesc);
  	gtk_box_pack_end (GTK_BOX (GTK_DIALOG(dialogAbout)->vbox), hBoxModDesc, TRUE, TRUE, 0);
	textAboutMods = gtk_text_new (NULL, NULL);
 	gtk_object_set_data (GTK_OBJECT (dialogAbout), "textAboutMods", textAboutMods);
   	gtk_box_pack_start (GTK_BOX (hBoxModDesc), textAboutMods, TRUE, TRUE, 0);
  	gtk_text_set_editable (GTK_TEXT (textAboutMods), FALSE);
  	gtk_text_set_word_wrap (GTK_TEXT (textAboutMods), TRUE);

	gtk_text_freeze (GTK_TEXT(textAboutMods));
	gtk_text_set_point(GTK_TEXT(textAboutMods), 0);
	gtk_text_forward_delete (GTK_TEXT (textAboutMods), gtk_text_get_length((GTK_TEXT(textAboutMods))));

	if (mainMgr->Modules.empty()==TRUE) {
		gtk_text_freeze (GTK_TEXT(textAboutMods));
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\nCheatah was unable to find any books installed!\n\n", -1);
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "They should be listed in a configuration file named either: ", -1);
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "'mods.conf' or 'mods.d'. \n\n", -1);
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\t",-1);
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "Or see the README file for a full description of setup options.\n", -1);
	}
	else {
		gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\tInstalled Book Modules", -1);
		for (i = 0; i < 3; i++) {
			gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\n\n\t", -1);
			gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, modtypes[i], -1);
			gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\n\n", -1);
			for (it = mainMgr->Modules.begin(); it != mainMgr->Modules.end(); it++) {
				if (!strcmp((*it).second->Type(), modtypes[i])) {
					sit = mainMgr->config->Sections.find((*it).second->Name());
					if (sit != mainMgr->config->Sections.end()) {
						gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, (*it).second->Name() ,-1);
						gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, ": " ,-1);
						gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, (*it).second->Description() ,-1);
						gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\n\n", -1);
						eit = (*sit).second.find("About");
						if (eit != (*sit).second.end()) {
//							gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, (*eit).second.c_str() ,-1);
							tempString=str_fixup_format((*eit).second.c_str() );
							gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, tempString, -1);
							free(tempString);
							gtk_text_insert(GTK_TEXT(textAboutMods), NULL, &textAboutMods->style->black, NULL, "\n\n" ,-1);
						}
//						eit = (*sit).second.find("SourceType");
//						if (eit != (*sit).second.end()) {
//							fprintf(stderr,"SourceType: %s\n", (*eit).second.c_str() );
//						}
					}
				}
			}
		}
	}

	gtk_text_set_point(GTK_TEXT(textAboutMods), 0);
	gtk_text_thaw(GTK_TEXT(textAboutMods));

	/* Add a vertical scrollbar to the textAboutMods GtkText widget */
	textScrollbarMods = gtk_vscrollbar_new (GTK_TEXT (textAboutMods)->vadj);
	gtk_box_pack_end (GTK_BOX (hBoxModDesc), textScrollbarMods, FALSE, FALSE, 0);
 
	hBoxAbout = gtk_hbox_new (FALSE,0);
  	gtk_object_set_data (GTK_OBJECT (dialogAbout), "hBoxAbout", hBoxAbout);
  	gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialogAbout)->vbox), hBoxAbout, FALSE, TRUE, 0);
	textAbout = gtk_text_new (NULL, NULL);
 	gtk_object_set_data (GTK_OBJECT (dialogAbout), "textAbout", textAbout);
   	gtk_box_pack_start (GTK_BOX (hBoxAbout), textAbout, TRUE, TRUE, 0);
  	gtk_text_set_editable (GTK_TEXT (textAbout), FALSE);
  	gtk_text_set_word_wrap (GTK_TEXT (textAbout), TRUE);

	gtk_text_freeze (GTK_TEXT(textAbout));
	gtk_text_set_point(GTK_TEXT(textAbout), 0);
	gtk_text_forward_delete (GTK_TEXT (textAbout), gtk_text_get_length((GTK_TEXT(textAbout))));
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "Cheatah is a quick and dirty GTK/Linux front end to the Sword software.", -1);
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "\n\nSword is developed by the CrossWire Software & Bible Society:",-1);
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "\n\tP. O. Box 2528",-1);
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "\n\tTempe, AZ  85280-2528 ", -1);
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "\n\thttp://www.crosswire.org ", -1);
	gtk_text_insert(GTK_TEXT(textAbout), NULL, &textAbout->style->black, NULL, "\n\nThis software is provided free for the study of God and His Word.",-1);

	gtk_text_set_point(GTK_TEXT(textAbout), 0);
	gtk_text_thaw(GTK_TEXT(textAbout));

	/* Add a vertical scrollbar to the textAbout GtkText widget */
	textScrollbar = gtk_vscrollbar_new (GTK_TEXT (textAbout)->vadj);
	gtk_box_pack_end (GTK_BOX (hBoxAbout), textScrollbar, FALSE, FALSE, 0);

	gtk_widget_show_all(dialogAbout);		// "show_all" makes all the children visable too

/*								*/
/*	No need to clean up the various widgets - we've arranged		*/
/*	for that to happen automatically when the user presses the		*/
/*	"o.k." button.						*/
/*								*/
  
	return;
}


void
on_lookupText_changed                  (GtkEditable     *editable,
                                        gpointer         user_data)
{
	cheatahWindow->lookupTextChanged();
}


void
on_searchButton_clicked                (GtkButton       *button,
                                        gpointer         user_data)
{
	cheatahWindow->searchButtonClicked();
}


void
on_resultList_selection_changed        (GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data)
{
	cheatahWindow->resultListSelectionChanged(clist, row, column, event, data);
}


void on_arrow1_button_press_event(GtkButton       *button, gpointer         user_data) {
	cheatahWindow->navigateButtonClicked(0);
}


void on_arrow2_button_press_event(GtkButton       *button, gpointer         user_data) {
	cheatahWindow->navigateButtonClicked(1);
}