forked from juddmon/jpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_gui.c
354 lines (300 loc) · 11.5 KB
/
print_gui.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
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
/*******************************************************************************
* print_gui.c
* A module of J-Pilot http://jpilot.org
*
* Copyright (C) 2000-2014 by Judd Montgomery
*
* 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; version 2 of the License.
*
* 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
******************************************************************************/
/********************************* Includes ***********************************/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "i18n.h"
#include "utils.h"
#include "prefs.h"
#include "prefs_gui.h"
#include "log.h"
#include "print.h"
/******************************* Global vars **********************************/
static GtkWidget *lines_entry;
static GtkWidget *print_command_entry;
static GtkWidget *one_record_checkbutton;
static GtkWidget *window;
static GtkWidget *radio_button_one;
static GtkWidget *radio_button_shown;
static GtkWidget *radio_button_all;
static GtkWidget *radio_button_daily;
static GtkWidget *radio_button_weekly;
static GtkWidget *radio_button_monthly;
static int print_dialog;
/* This is a temporary hack */
int print_day_week_month;
/****************************** Main Code *************************************/
static gboolean cb_destroy(GtkWidget *widget)
{
const char *entry_text;
const char *lines_text;
int num_lines;
jp_logf(JP_LOG_DEBUG, "Cleanup print_gui\n");
/* Get radio button prefs */
if (radio_button_one) {
if (GTK_TOGGLE_BUTTON(radio_button_one)->active) {
jp_logf(JP_LOG_DEBUG, "print one");
set_pref(PREF_PRINT_THIS_MANY, 1, NULL, FALSE);
}
if (GTK_TOGGLE_BUTTON(radio_button_shown)->active) {
jp_logf(JP_LOG_DEBUG, "print shown");
set_pref(PREF_PRINT_THIS_MANY, 2, NULL, FALSE);
}
if (GTK_TOGGLE_BUTTON(radio_button_all)->active) {
jp_logf(JP_LOG_DEBUG, "print all");
set_pref(PREF_PRINT_THIS_MANY, 3, NULL, FALSE);
}
}
/* Get radio button prefs */
if (radio_button_daily) {
if (GTK_TOGGLE_BUTTON(radio_button_daily)->active) {
jp_logf(JP_LOG_DEBUG, "print daily");
print_day_week_month=1;
}
if (GTK_TOGGLE_BUTTON(radio_button_weekly)->active) {
jp_logf(JP_LOG_DEBUG, "print weekly");
print_day_week_month=2;
}
if (GTK_TOGGLE_BUTTON(radio_button_monthly)->active) {
jp_logf(JP_LOG_DEBUG, "print monthly");
print_day_week_month=3;
}
}
/* Get one record per page pref */
if (one_record_checkbutton) {
if (GTK_TOGGLE_BUTTON(one_record_checkbutton)->active) {
jp_logf(JP_LOG_DEBUG, "one record per page");
set_pref(PREF_PRINT_ONE_PER_PAGE, 1, NULL, FALSE);
} else {
set_pref(PREF_PRINT_ONE_PER_PAGE, 0, NULL, FALSE);
}
}
/* Get number of blank lines */
if (lines_entry) {
lines_text = gtk_entry_get_text(GTK_ENTRY(lines_entry));
jp_logf(JP_LOG_DEBUG, "lines_entry = [%s]\n", lines_text);
num_lines = atoi(lines_text);
if (num_lines < 0) {
num_lines = 0;
}
if (num_lines > 99) {
num_lines = 99;
}
set_pref(PREF_NUM_BLANK_LINES, num_lines, NULL, FALSE);
}
/* Get print command */
entry_text = gtk_entry_get_text(GTK_ENTRY(print_command_entry));
jp_logf(JP_LOG_DEBUG, "print_command_entry = [%s]\n", entry_text);
set_pref(PREF_PRINT_COMMAND, 0, entry_text, TRUE);
window = NULL;
gtk_main_quit();
return FALSE;
}
static void cb_print(GtkWidget *widget, gpointer data)
{
jp_logf(JP_LOG_DEBUG, "cb_print\n");
if (GTK_IS_WIDGET(data)) {
gtk_widget_destroy(data);
}
print_dialog=DIALOG_SAID_PRINT;
}
static void cb_cancel(GtkWidget *widget, gpointer data)
{
jp_logf(JP_LOG_DEBUG, "cb_cancel\n");
if (GTK_IS_WIDGET(data)) {
gtk_widget_destroy(data);
}
print_dialog=DIALOG_SAID_CANCEL;
}
/* mon_week_day is a binary flag to choose which radio buttons appear for
* datebook printing.
* 1 = daily
* 2 = weekly
* 4 = monthly
*/
int print_gui(GtkWidget *main_window, int app, int date_button, int mon_week_day)
{
GtkWidget *label;
GtkWidget *button;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *pref_menu;
long ivalue;
char temp_str[10];
char temp[256];
const char *svalue;
GSList *group;
jp_logf(JP_LOG_DEBUG, "print_gui\n");
if (GTK_IS_WINDOW(window)) {
jp_logf(JP_LOG_DEBUG, "print_gui window is already up\n");
gdk_window_raise(window->window);
return EXIT_SUCCESS;
}
print_dialog=0;
radio_button_one=NULL;
radio_button_daily=NULL;
one_record_checkbutton=NULL;
lines_entry=NULL;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(main_window));
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_snprintf(temp, sizeof(temp), "%s %s", PN, _("Print Options"));
gtk_window_set_title(GTK_WINDOW(window), temp);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(cb_destroy), window);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
/* Paper Size */
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new(_("Paper Size"));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
make_pref_menu(&pref_menu, PREF_PAPER_SIZE);
gtk_box_pack_start(GTK_BOX(hbox), pref_menu, FALSE, FALSE, 0);
get_pref(PREF_PAPER_SIZE, &ivalue, NULL);
gtk_option_menu_set_history(GTK_OPTION_MENU(pref_menu), ivalue);
/* Radio buttons for Datebook */
radio_button_daily=radio_button_weekly=radio_button_monthly=NULL;
if (app == DATEBOOK) {
group = NULL;
if (mon_week_day & 0x01) {
radio_button_daily = gtk_radio_button_new_with_label
(group, _("Daily Printout"));
group = gtk_radio_button_group(GTK_RADIO_BUTTON(radio_button_daily));
}
if (mon_week_day & 0x02) {
radio_button_weekly = gtk_radio_button_new_with_label
(group, _("Weekly Printout"));
group = gtk_radio_button_group(GTK_RADIO_BUTTON(radio_button_weekly));
}
if (mon_week_day & 0x04) {
radio_button_monthly = gtk_radio_button_new_with_label
(group, _("Monthly Printout"));
}
switch (date_button) {
case 1:
if (mon_week_day & 0x01) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_daily), TRUE);
}
break;
case 2:
if (mon_week_day & 0x02) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_weekly), TRUE);
}
break;
case 3:
if (mon_week_day & 0x04) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_monthly), TRUE);
}
break;
default:
if (mon_week_day & 0x01) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_daily), TRUE);
}
}
if (mon_week_day & 0x01) {
gtk_box_pack_start(GTK_BOX(vbox), radio_button_daily, FALSE, FALSE, 0);
}
if (mon_week_day & 0x02) {
gtk_box_pack_start(GTK_BOX(vbox), radio_button_weekly, FALSE, FALSE, 0);
}
if (mon_week_day & 0x04) {
gtk_box_pack_start(GTK_BOX(vbox), radio_button_monthly, FALSE, FALSE, 0);
}
}
if (app != DATEBOOK) {
/* Radio buttons for number of records to print */
group = NULL;
radio_button_one = gtk_radio_button_new_with_label
(group, _("Selected record"));
group = gtk_radio_button_group(GTK_RADIO_BUTTON(radio_button_one));
radio_button_shown = gtk_radio_button_new_with_label
(group, _("All records in this category"));
group = gtk_radio_button_group(GTK_RADIO_BUTTON(radio_button_shown));
radio_button_all = gtk_radio_button_new_with_label
(group, _("Print all records"));
get_pref(PREF_PRINT_THIS_MANY, &ivalue, NULL);
switch (ivalue) {
case 1:
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_one), TRUE);
break;
case 2:
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_shown), TRUE);
break;
case 3:
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button_all), TRUE);
}
gtk_box_pack_start(GTK_BOX(vbox), radio_button_one, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), radio_button_shown, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), radio_button_all, FALSE, FALSE, 0);
}
if (app != DATEBOOK) {
/* One record per page check box */
one_record_checkbutton = gtk_check_button_new_with_label
(_("One record per page"));
gtk_box_pack_start(GTK_BOX(vbox), one_record_checkbutton, FALSE, FALSE, 0);
get_pref(PREF_PRINT_ONE_PER_PAGE, &ivalue, NULL);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(one_record_checkbutton), ivalue);
}
if (app != DATEBOOK) {
/* Number of blank lines */
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
lines_entry = gtk_entry_new_with_max_length(2);
entry_set_multiline_truncate(GTK_ENTRY(lines_entry), TRUE);
gtk_widget_set_usize(lines_entry, 30, 0);
gtk_box_pack_start(GTK_BOX(hbox), lines_entry, FALSE, FALSE, 0);
label = gtk_label_new(_("Blank lines between each record"));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
get_pref(PREF_NUM_BLANK_LINES, &ivalue, NULL);
sprintf(temp_str, "%ld", ivalue);
gtk_entry_set_text(GTK_ENTRY(lines_entry), temp_str);
}
/* Print Command */
label = gtk_label_new(_("Print Command (e.g. lpr, or cat > file.ps)"));
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
print_command_entry = gtk_entry_new_with_max_length(250);
gtk_box_pack_start(GTK_BOX(vbox), print_command_entry, FALSE, FALSE, 0);
get_pref(PREF_PRINT_COMMAND, NULL, &svalue);
gtk_entry_set_text(GTK_ENTRY(print_command_entry), svalue);
/* Dialog button box */
hbox = gtk_hbutton_box_new();
gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 6);
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
/* Cancel button */
button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_cancel), window);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
/* Print button */
button = gtk_button_new_from_stock(GTK_STOCK_PRINT);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(cb_print), window);
gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
gtk_widget_show_all(window);
gtk_main();
return print_dialog;
}