1 /*
2  *    TTTTTTTTTTTTTT  EEEEEEEEEEEEEE  OOOOOOOOOOOOOO
3  *    TTTTTTTTTTTTTT  EEEEEEEEEEEEEE  OOOOOOOOOOOOOO
4  *          TT        EE              OO          OO
5  *          TT        EE              OO          OO
6  *          TT        EE              OO          OO
7  *          TT        EEEEEEEEEE      OO          OO
8  *          TT        EEEEEEEEEE      OO          OO
9  *          TT        EE              OO          OO
10  *          TT        EE              OO          OO
11  *          TT        EE              OO          OO
12  *          TT        EEEEEEEEEEEEEE  OOOOOOOOOOOOOO
13  *          TT        EEEEEEEEEEEEEE  OOOOOOOOOOOOOO
14  *
15  *                  L'�mulateur Thomson TO8
16  *
17  *  Copyright (C) 1997-2017 Gilles F�tis, Eric Botcazou, Alexandre Pukall,
18  *                          J�r�mie Guillaume, Fran�ois Mouret
19  *
20  *  This program is free software; you can redistribute it and/or modify
21  *  it under the terms of the GNU General Public License as published by
22  *  the Free Software Foundation; either version 2 of the License, or
23  *  (at your option) any later version.
24  *
25  *  This program is distributed in the hope that it will be useful,
26  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *  GNU General Public License for more details.
29  *
30  *  You should have received a copy of the GNU General Public License
31  *  along with this program; if not, write to the Free Software
32  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33  */
34 
35 /*
36  *  Module     : linux/ugui/uprinter.c
37  *  Version    : 1.8.4
38  *  Cr�� par   : Fran�ois Mouret 18/04/2012
39  *  Modifi� par: Fran�ois Mouret 29/10/2012 13/04/2014 31/05/2015
40  *
41  *  Gestion des imprimantes.
42  */
43 
44 
45 #ifndef SCAN_DEPEND
46    #include <stdio.h>
47    #include <unistd.h>
48    #include <string.h>
49    #include <libgen.h>
50    #include <gtk/gtk.h>
51 #endif
52 
53 #include "teo.h"
54 #include "std.h"
55 #include "media/printer.h"
56 #include "linux/gui.h"
57 
58 GtkWidget *widget_nlq = NULL;
59 GtkWidget *widget_dip = NULL;
60 
61 
62 
63 /* folder_changed:
64  *  Callback pour le changement de r�pertoire.
65  */
folder_changed(GtkFileChooser * chooser,gpointer user_data)66 static void folder_changed (GtkFileChooser *chooser, gpointer user_data)
67 {
68     gchar *filename = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(chooser));
69     teo.lprt.folder = std_free (teo.lprt.folder);
70     teo.lprt.folder = std_strdup_printf ("%s", filename);
71     g_free (filename);
72     (void)user_data;
73 }
74 
75 
76 
77 /* check_button_toggled:
78  *  Callback commun pour un changement d'�tat de checkbox.
79  */
check_button_toggled(GtkToggleButton * button,int * reg)80 static void check_button_toggled (GtkToggleButton *button, int *reg)
81 {
82     *reg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
83 }
84 
85 
86 
87 /* combo_changed:
88  *  Callback pour le changement de combo.
89  */
combo_changed(GtkComboBox * combo,gpointer user_data)90 static void combo_changed (GtkComboBox *combo, gpointer user_data)
91 {
92     int combo_index = gtk_combo_box_get_active (GTK_COMBO_BOX(combo));
93 
94     teo.lprt.number = (printer_code_list[combo_index].number);
95     if (teo.lprt.number < 600)
96     {
97         gtk_widget_set_sensitive (widget_nlq, FALSE);
98         gtk_widget_set_sensitive (widget_dip, FALSE);
99     }
100     else
101     {
102         gtk_widget_set_sensitive (widget_nlq, TRUE);
103         gtk_widget_set_sensitive (widget_dip, TRUE);
104     }
105 
106     (void)user_data;
107 }
108 
109 
110 
create_new_frame(GtkWidget * mainbox,const char * title)111 static GtkWidget *create_new_frame (GtkWidget *mainbox, const char *title)
112 {
113     GtkWidget *vbox;
114     GtkWidget *frame;
115 
116     /* frame */
117     frame=gtk_frame_new (title);
118     gtk_box_pack_start (GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
119 
120     /* vertical box */
121     vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
122     gtk_container_set_border_width (GTK_CONTAINER(vbox), 5);
123     gtk_container_add( GTK_CONTAINER(frame), vbox);
124 
125     return vbox;
126 }
127 
128 
129 
create_new_hbox(GtkWidget * mainbox)130 static GtkWidget *create_new_hbox (GtkWidget *mainbox)
131 {
132     GtkWidget *hbox;
133 
134     hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
135     gtk_container_add( GTK_CONTAINER(mainbox), hbox);
136 
137     return hbox;
138 }
139 
140 
141 /* ------------------------------------------------------------------------- */
142 
143 
144 /* uprinter_Init:
145  *  Initialise la frame du notebook pour la cartouche.
146  */
uprinter_Init(GtkWidget * notebook)147 void uprinter_Init (GtkWidget *notebook)
148 {
149     int i;
150     int combo_index = 0;
151     GtkWidget *vbox, *vbox2;
152     GtkWidget *hbox, *hbox2;
153     GtkWidget *widget;
154     GtkWidget *combo;
155     GtkWidget *dialog;
156     GtkWidget *frame;
157 
158     /* frame de la cartouche */
159     frame=gtk_frame_new("");
160     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_NONE);
161     gtk_frame_set_label_align( GTK_FRAME(frame), 0.985, 0.0);
162     widget=gtk_label_new((is_fr?"Imprimante":"Printer"));
163     gtk_notebook_append_page( GTK_NOTEBOOK(notebook), frame, widget);
164 
165     /* bo�te verticale associ�e � la frame */
166     vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
167     gtk_container_set_border_width( GTK_CONTAINER(vbox), 0);
168     gtk_container_add( GTK_CONTAINER(frame), vbox);
169 
170     hbox2 = create_new_hbox (vbox);
171     widget=gtk_label_new(is_fr?"Ecrire les fichiers de sortie dans"
172                               :"Write output files in");
173     gtk_box_pack_start( GTK_BOX(hbox2), widget, FALSE, FALSE, 0);
174 
175     /* dialog pour le r�pertoire */
176     dialog = gtk_file_chooser_dialog_new (
177              is_fr?"Sélectionner un répertoire de sauvegarde"
178                   :"Select the folder to save in",
179              (GtkWindow *) wControl,
180              GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
181              is_fr?"_Annuler":"_Cancel", GTK_RESPONSE_CANCEL,
182              is_fr?"_Ouvrir":"_Open", GTK_RESPONSE_ACCEPT, NULL);
183     gtk_file_chooser_set_current_folder(
184                      (GtkFileChooser *)dialog,
185                      (teo.lprt.folder == NULL)?"":teo.lprt.folder);
186     g_signal_connect(G_OBJECT(dialog),
187                      "current-folder-changed",
188                      G_CALLBACK(folder_changed),
189                      (gpointer) NULL);
190     widget = gtk_file_chooser_button_new_with_dialog (dialog);
191     gtk_box_pack_start( GTK_BOX(hbox2), widget, FALSE, FALSE, 0);
192 
193     /* ---------------- Options ------------------- */
194 
195     /* bo�te horizontale */
196     hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
197     gtk_container_set_border_width( GTK_CONTAINER(hbox), 5);
198     gtk_box_set_homogeneous (GTK_BOX(hbox), FALSE);
199     gtk_container_add( GTK_CONTAINER(vbox), hbox);
200 
201     /* Cr�ation de la frame */
202     vbox2 = create_new_frame (hbox, is_fr?"Imprimante":"Printer");
203 
204     /* label pour l'imprimante */
205     hbox2 = create_new_hbox (vbox2);
206     widget=gtk_label_new("Type ");
207     gtk_box_pack_start( GTK_BOX(hbox2), widget, FALSE, FALSE, 0);
208 
209     /* combo pour les imprimantes */
210     combo=gtk_combo_box_text_new();
211     for (i=0; i<PRINTER_NUMBER; i++)
212     {
213         gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(combo),
214                                    NULL,
215                                    printer_code_list[i].name);
216         if (teo.lprt.number == printer_code_list[i].number)
217             combo_index = i;
218     }
219     g_signal_connect(G_OBJECT(combo),
220                      "changed",
221                      G_CALLBACK(combo_changed),
222                      (gpointer) NULL);
223     gtk_box_pack_start( GTK_BOX(hbox2), combo, TRUE, TRUE, 0);
224 
225     /* bouton check pour le dip */
226     hbox2 = create_new_hbox (vbox2);
227     widget_dip=gtk_check_button_new_with_label(
228                         is_fr?"Double interligne"
229                              :"Double spacing");
230     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget_dip),
231                                  teo.lprt.dip);
232     g_signal_connect(G_OBJECT(widget_dip),
233                      "toggled",
234                      G_CALLBACK(check_button_toggled),
235                      (gpointer) &teo.lprt.dip);
236     gtk_box_pack_start( GTK_BOX(hbox2), widget_dip, TRUE, TRUE, 0);
237 
238     /* bouton check pour le nlq */
239     hbox2 = create_new_hbox (vbox2);
240     widget_nlq=gtk_check_button_new_with_label(
241                         is_fr?"Imprime en haute qualité"
242                              :"High-quality print");
243     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget_nlq),
244                                  teo.lprt.nlq);
245     g_signal_connect(G_OBJECT(widget_nlq),
246                      "toggled",
247                      G_CALLBACK(check_button_toggled),
248                      (gpointer) &teo.lprt.nlq);
249     gtk_box_pack_start( GTK_BOX(hbox2), widget_nlq, TRUE, TRUE, 0);
250 
251     /* ---------------- Output ------------------- */
252 
253     /* Cr�ation de la frame */
254     vbox2 = create_new_frame (hbox, is_fr?"Sortie":"Output");
255 
256     /* label pour le r�pertoire */
257     /* bouton check pour la sortie brute */
258     hbox2 = create_new_hbox (vbox2);
259     widget=gtk_check_button_new_with_label(is_fr?"brute":"raw");
260     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
261                                  teo.lprt.raw_output);
262     g_signal_connect(G_OBJECT(widget),
263                      "toggled",
264                      G_CALLBACK(check_button_toggled),
265                      (gpointer) &teo.lprt.raw_output);
266     gtk_box_pack_start( GTK_BOX(hbox2), widget, TRUE, TRUE, 0);
267 
268     /* bouton check pour la sortie texte */
269     hbox2 = create_new_hbox (vbox2);
270     widget=gtk_check_button_new_with_label(is_fr?"texte":"text");
271     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
272                                  teo.lprt.txt_output);
273     g_signal_connect(G_OBJECT(widget),
274                      "toggled",
275                      G_CALLBACK(check_button_toggled),
276                      (gpointer) &teo.lprt.txt_output);
277     gtk_box_pack_start( GTK_BOX(hbox2), widget, TRUE, TRUE, 0);
278 
279     /* bouton check pour la sortie graphique */
280     hbox2 = create_new_hbox (vbox2);
281     widget=gtk_check_button_new_with_label(is_fr?"graphique":"graphic");
282     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
283                                  teo.lprt.gfx_output);
284     g_signal_connect(G_OBJECT(widget),
285                      "toggled",
286                      G_CALLBACK(check_button_toggled),
287                      (gpointer) &teo.lprt.gfx_output);
288     gtk_box_pack_start( GTK_BOX(hbox2), widget, TRUE, TRUE, 0);
289 
290     /* actualize the combo */
291     gtk_combo_box_set_active (GTK_COMBO_BOX(combo), combo_index);
292 }
293 
294