File: tab_history.c

package info (click to toggle)
xiphos 4.1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,572 kB
  • sloc: ansic: 25,543; cpp: 13,223; python: 12,684; xml: 2,951; sh: 144; makefile: 42
file content (410 lines) | stat: -rw-r--r-- 10,241 bytes parent folder | download
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*
 * Xiphos Bible Study Tool
 * tab_history.c - add, remove and navigate history
 *
 * Copyright (C) 2005-2017 Xiphos Developer Team
 *
 * 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 Library 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>

#include "gui/main_menu.h"
#include "gui/main_window.h"
#include "gui/tabbed_browser.h"
//#include "gui/toolbar_nav.h"
#include "gui/utilities.h"
#include "gui/xiphos.h"
#include "gui/widgets.h"

#include "main/tab_history.h"
#include "main/settings.h"
#include "main/sidebar.h"
#include "main/sword.h"
#include "main/url.hh"
#include "main/xml.h"
#include "main/navbar_versekey.h"

/* de-uglify all references to button sensitivitiy */
#define BUTTON_BACK navbar_versekey.button_history_back
#define BUTTON_FORW navbar_versekey.button_history_next

/******************************************************************************
 * Name
 *  on_menu_historyitem_activate
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void on_menu_historyitem_activate(GtkMenuItem * menuitem,
 *						gpointer user_data)
 *
 * Description
 *   change text module to chosen histor item
 *
 * Return value
 *   void
 */

void
on_menu_historyitem_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	main_change_verse_tab_history(GPOINTER_TO_INT(user_data));
}

/******************************************************************************
 * Name
 *   main_clear_tab_history
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_clear_tab_history(void)
 *
 * Description
 *
 *
 * Return value
 *   void
 */

void main_clear_tab_history(void)
{
	PASSAGE_TAB_INFO *tab = cur_passage_tab;

	//gui_remove_menu_items(_("H_istory/<Separator>"),
	//                    tab->history_items + 1);
	//gui_add_separator2menu(widgets.app, _("H_istory/C_lear"));

	/* set sensitivity of history buttons */
	gtk_widget_set_sensitive(BUTTON_BACK, FALSE);
	gtk_widget_set_sensitive(BUTTON_FORW, FALSE);

	tab->history_items = 0;
	tab->current_history_item = 0;
	tab->first_back_click = TRUE;
}

/******************************************************************************
 * Name
 *   main_update_tab_history_menu
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_update_tab_history_menu(gpointer data)
 *
 * Description
 *
 *
 * Return value
 *   void
 */

void main_update_tab_history_menu(gpointer data)
{
	PASSAGE_TAB_INFO *tab = (PASSAGE_TAB_INFO *)data;

	/* set sensitivity of history buttons */
	gtk_widget_set_sensitive(BUTTON_BACK,
				 (tab->current_history_item > 0));

	gtk_widget_set_sensitive(BUTTON_FORW,
				 (tab->current_history_item <
				  (tab->history_items - 1)));
}

/******************************************************************************
 * Name
 *   main_add_tab_history_item
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_add_tab_history_item(gpointer data)
 *
 * Description
 *    add an item to the history menu
 *
 * Return value
 *   void
 */
void main_add_tab_history_item(gpointer data)
{
	gint i;
	PASSAGE_TAB_INFO *tab = (PASSAGE_TAB_INFO *)data;

	/* check to see if item is already in list
	   if so do nothing except set button sensitivity */
	for (i = 0; i < tab->history_items; ++i) {
		if (!strcmp(tab->history_list[i].verseref,
			    tab->text_commentary_key)) {
			tab->current_history_item = i;
			main_update_tab_history_menu(data);
			return;
		}
	}

	/* if we have hit max length, dispose of oldest */
	if (tab->history_items == TABHISTORYLENGTH) {
		for (i = 0; i < (TABHISTORYLENGTH - 1); ++i) {
			tab->history_list[i] = tab->history_list[i + 1];
		}
		--tab->history_items;
	}

	/* add item to history menu */
	strcpy(tab->history_list[tab->history_items].verseref,
	       tab->text_commentary_key);
	if (tab->text_mod)
		strcpy(tab->history_list[tab->history_items].textmod,
		       tab->text_mod);
	if (tab->commentary_mod)
		strcpy(tab->history_list[tab->history_items].commod,
		       tab->commentary_mod);

	tab->current_history_item = tab->history_items;
	++tab->history_items;

	main_update_tab_history_menu(data);
	tab->first_back_click = TRUE;
}

/******************************************************************************
 * Name
 *   main_fake_tab_history_item
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_fake_tab_history_item(char *reference)
 *
 * Description
 *    fake an unreal history item into the history menu
 *
 * Return value
 *   void
 */
void main_fake_tab_history_item(char *reference)
{
	PASSAGE_TAB_INFO *tab = cur_passage_tab;

	/* if we have hit max length, dispose of oldest */
	if (tab->history_items == TABHISTORYLENGTH) {
		int i;
		for (i = 0; i < (TABHISTORYLENGTH - 1); ++i) {
			tab->history_list[i] = tab->history_list[i + 1];
		}
		--tab->history_items;
	}

	/* add item to history menu */
	strcpy(tab->history_list[tab->history_items].verseref, reference);
	if (tab->text_mod)
		strcpy(tab->history_list[tab->history_items].textmod,
		       tab->text_mod);
	if (tab->commentary_mod)
		strcpy(tab->history_list[tab->history_items].commod,
		       tab->commentary_mod);

	++tab->history_items;
	/* do not update what's current in history list. */
	main_update_tab_history_menu(tab);
}

/******************************************************************************
 * Name
 *  on_clear_activate
 *
 * Synopsis
 *   #include ".h"
 *
 *   void on_clear_activate(GtkMenuItem * menuitem,
 *			    gpointer user_data)
 *
 * Description
 *   remove all items from history list by calling
 *   gui_clear_history();
 *
 * Return value
 *   void
 */

void on_clear_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	main_clear_tab_history();
}

/******************************************************************************
 * Name
 *  on_history_to_verse_list_activate
 *
 * Synopsis
 *   #include ".h"
 *
 *   void on_history_to_verse_list_activate(GtkMenuItem * menuitem,
 *					    gpointer user_data)
 *
 * Description
 *   ship the history content to the verse list.
 *
 * Return value
 *   void
 */

void on_history_to_verse_list_activate(GtkMenuItem *menuitem,
				       gpointer user_data)
{
	int i;
	gboolean first = TRUE;
	GString *list = g_string_new("");

	for (i = 0; i < cur_passage_tab->history_items; ++i) {
		if (!first)
			g_string_append_c(list, ';');
		g_string_append(list,
				cur_passage_tab->history_list[i].verseref);
		first = FALSE;
	}

	main_display_verse_list_in_sidebar(settings.currentverse, settings.MainWindowModule, list->str);

	g_string_free(list, TRUE);
	return;
}

GtkWidget *main_versekey_drop_down_new(gpointer data)
{
	gint i;
	GtkWidget *menu;
	GtkWidget *item;
	PASSAGE_TAB_INFO *tab = NULL;

	tab = (PASSAGE_TAB_INFO *)data;
	menu = gtk_menu_new();

	item = gtk_menu_item_new_with_label(_("Clear History"));
	gtk_widget_show(item);
	g_signal_connect(G_OBJECT(item), "activate",
			 G_CALLBACK(on_clear_activate), NULL);
	gtk_container_add(GTK_CONTAINER(menu), item);

	item = gtk_menu_item_new_with_label(_("History ➛ Verse List"));
	gtk_widget_show(item);
	g_signal_connect(G_OBJECT(item), "activate",
			 G_CALLBACK(on_history_to_verse_list_activate),
			 NULL);
	gtk_container_add(GTK_CONTAINER(menu), item);

	for (i = 0; i < tab->history_items; ++i) {
		item =
		    gtk_menu_item_new_with_label(tab->history_list[i].verseref);
		gtk_widget_show(item);
		gtk_container_add(GTK_CONTAINER(menu), item);
		g_signal_connect(G_OBJECT(item), "activate",
				 G_CALLBACK(on_menu_historyitem_activate),
				 GINT_TO_POINTER(i));
		if (!strcmp(tab->history_list[i].verseref,
			    tab->text_commentary_key))
			gtk_widget_set_sensitive(item, FALSE);
	}
	return menu;
}

/******************************************************************************
 * Name
 *   main_change_verse_tab_history
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_change_verse_tab_history(gint historynum)
 *
 * Description
 *
 *
 * Return value
 *   void
 */

void main_change_verse_tab_history(gint historynum)
{
	PASSAGE_TAB_INFO *tab = cur_passage_tab;
	gchar *key;

	tab->current_history_item = historynum;
	settings.addhistoryitem = tab->first_back_click;

	XI_print(("commod = %s\n", tab->history_list[historynum].commod));
	XI_print(("textmod = %s\n",
		  tab->history_list[historynum].textmod));

	key =
	    main_update_nav_controls(tab->history_list[historynum].textmod,
				     tab->history_list[historynum].verseref);
	main_display_commentary(tab->history_list[historynum].commod, key);
	main_display_bible(tab->history_list[historynum].textmod, key);
	main_keep_bibletext_dialog_in_sync(key);
	if (key)
		g_free(key);
}

/******************************************************************************
 * Name
 *   main_navigate_tab_history
 *
 * Synopsis
 *   #include "main/tab_history.h"
 *
 *   void main_navigate_tab_history(gint direction)
 *
 * Description
 *
 *
 * Return value
 *   void
 */

void main_navigate_tab_history(gint direction)
{
	PASSAGE_TAB_INFO *tab = cur_passage_tab;

	settings.addhistoryitem = FALSE;
	if (direction) {
		if (tab->current_history_item < tab->history_items - 1) {
			++tab->current_history_item;
			main_change_verse_tab_history(tab->current_history_item);
		}
	} else {
		if (tab->current_history_item > 0) {
			--tab->current_history_item;
#if 0
			if (tab->first_back_click &&
			    (tab->current_history_item > 0))
				--tab->current_history_item;
#endif

			main_change_verse_tab_history(tab->current_history_item);
			tab->first_back_click = FALSE;
		}
	}

	main_update_tab_history_menu((gpointer)tab);
	settings.addhistoryitem = TRUE;
}