1 /*
2    SANE EPSON backend
3    Copyright (C) 2001 SEIKO EPSON Corporation
4 
5    Date         Author      Reason
6    06/01/2001   N.Sasaki    New
7 
8    This file is part of the `iscan' program.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24    As a special exception, the copyright holders give permission
25    to link the code of this program with the esmod library and
26    distribute linked combinations including the two.  You must obey
27    the GNU General Public License in all respects for all of the
28    code used other then esmod.
29 */
30 
31 #include <config.h>
32 
33 #include "gettext.h"
34 #define  _(msg_id)	gettext (msg_id)
35 
36 /*------------------------------------------------------------*/
37 #include <stdio.h>
38 #include <string.h>
39 
40 /*------------------------------------------------------------*/
41 #include "pisa_configuration.h"
42 #include "pisa_view_manager.h"
43 #include "pisa_error.h"
44 #include "pisa_default_val.h"
45 
46 /*------------------------------------------------------------*/
delete_event(GtkWidget * widget,gpointer data)47 static gint delete_event ( GtkWidget * widget, gpointer data )
48 {
49   widget = widget;
50   data = data;
51 
52   ::g_view_manager->close_window ( ID_WINDOW_CONFIG, 1 );
53 
54   return TRUE;
55 }
56 
57 /*------------------------------------------------------------*/
click_ok(GtkWidget * widget,gpointer data)58 static void click_ok ( GtkWidget * widget, gpointer data )
59 {
60   config_window * cf_cls;
61 
62   widget = widget;
63 
64   cf_cls = ( config_window * ) data;
65 
66   cf_cls->m_ok = 1;
67 
68   cf_cls->update_filename ( );
69 
70   ::g_view_manager->close_window ( ID_WINDOW_CONFIG, 1 );
71 }
72 
73 /*------------------------------------------------------------*/
click_cancel(GtkWidget * widget,gpointer data)74 static void click_cancel ( GtkWidget * widget, gpointer data )
75 {
76   config_window * cf_cls;
77 
78   widget = widget;
79 
80   cf_cls = ( config_window * ) data;
81 
82   cf_cls->m_ok = 0;
83 
84   ::g_view_manager->close_window ( ID_WINDOW_CONFIG, 1 );
85 }
86 
87 
88 /*------------------------------------------------------------*/
init(void)89 int config_window::init ( void )
90 {
91   int i;
92 
93   for ( i = 0; i < WG_CONFIG_NUM; i++ )
94     m_widget [ i ] = 0;
95 
96   m_ok = 0;
97   ::strcpy ( m_cmd, "" );
98 
99   return PISA_ERR_SUCCESS;
100 }
101 
102 /*------------------------------------------------------------*/
create_window(GtkWidget * parent)103 GtkWidget * config_window::create_window ( GtkWidget * parent )
104 {
105   GtkWidget	* top;
106   GtkWidget	* widget;
107 
108   top = ::gtk_dialog_new ( );
109   ::gtk_window_set_policy ( GTK_WINDOW ( top ),
110 			    FALSE, FALSE, TRUE );
111   ::gtk_container_border_width ( GTK_CONTAINER ( GTK_DIALOG ( top )->vbox ),
112 				 5 );
113   ::gtk_window_set_title ( GTK_WINDOW ( top ), _( "Configuration" ) );
114   ::gtk_widget_set_uposition ( top, POS_CONFIG_X, POS_CONFIG_Y );
115   ::gtk_widget_realize ( top );
116 
117   ::gtk_signal_connect ( GTK_OBJECT ( top ), "delete_event",
118 			 GTK_SIGNAL_FUNC ( ::delete_event ), 0 );
119 
120   m_widget [ WG_CONFIG_TOP ] = top;
121 
122   widget = create_pips_path ( );
123   ::gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( top )->vbox ),
124 			 widget, FALSE, FALSE, 5 );
125   ::gtk_widget_show ( widget );
126 
127   create_action_area ( );
128 
129   ::gtk_window_set_modal ( GTK_WINDOW ( top ), TRUE );
130   ::gtk_window_set_transient_for ( GTK_WINDOW ( top ), GTK_WINDOW ( parent ) );
131   ::gtk_widget_show ( top );
132 
133   return top;
134 }
135 
136 /*------------------------------------------------------------*/
close_window(int destroy)137 int config_window::close_window ( int destroy )
138 {
139   if ( destroy && m_widget [ WG_CONFIG_TOP ] )
140     ::gtk_widget_destroy ( m_widget [ WG_CONFIG_TOP ] );
141 
142   m_widget [ WG_CONFIG_TOP ] = 0;
143 
144   return PISA_ERR_SUCCESS;
145 }
146 
147 /*------------------------------------------------------------*/
update_filename(void)148 void config_window::update_filename ( void )
149 {
150   ::strcpy ( m_cmd,
151 	     ::gtk_entry_get_text ( GTK_ENTRY ( m_widget [ WG_CONFIG_PATH ] ) ) );
152 }
153 
154 /*------------------------------------------------------------*/
create_pips_path(void)155 GtkWidget * config_window::create_pips_path ( void )
156 {
157   GtkWidget	* frame;
158   GtkWidget	* vbox;
159   GtkWidget	* hbox;
160   GtkWidget	* comment;
161   GtkWidget	* edit;
162 
163   frame = ::gtk_frame_new ( _( "Print Command" ) );
164   ::gtk_container_border_width ( GTK_CONTAINER ( frame ), 5 );
165 
166   vbox = ::gtk_vbox_new ( FALSE, 5 );
167   ::gtk_container_border_width ( GTK_CONTAINER ( vbox ), 5 );
168   ::gtk_container_add ( GTK_CONTAINER ( frame ), vbox );
169   ::gtk_widget_show ( vbox );
170 
171   hbox = ::gtk_hbox_new ( FALSE, 5 );
172   ::gtk_container_border_width ( GTK_CONTAINER ( hbox ), 5 );
173   ::gtk_box_pack_start ( GTK_BOX ( vbox ), hbox, FALSE, FALSE, 5 );
174   ::gtk_widget_show ( hbox );
175 
176   edit = ::gtk_entry_new ( );
177   ::gtk_widget_set_usize ( edit, 250, 0 );
178   ::gtk_box_pack_start ( GTK_BOX ( hbox ), edit, FALSE, FALSE, 5 );
179   ::gtk_widget_show ( edit );
180 
181   ::gtk_entry_set_max_length ( GTK_ENTRY ( edit ), 255 );
182   ::gtk_entry_set_text ( GTK_ENTRY ( edit ), m_cmd );
183 
184   m_widget [ WG_CONFIG_PATH ] = edit;
185 
186   comment = ::gtk_label_new (_("In order to print, your print system "
187 			       "must be able to handle the PNG file "
188 			       "format directly.  CUPS or Photo Image "
189 			       "Print System (versions 1.3.1 or later) "
190 			       "do this by default."));
191   ::gtk_label_set_line_wrap ( GTK_LABEL ( comment ), TRUE );
192   ::gtk_box_pack_start ( GTK_BOX ( vbox ), comment, FALSE, FALSE, 0 );
193   ::gtk_widget_show ( comment );
194 
195   return frame;
196 }
197 
198 /*------------------------------------------------------------*/
create_action_area(void)199 GtkWidget * config_window::create_action_area ( void )
200 {
201   GtkWidget	* button;
202 
203   // OK
204   button = ::gtk_button_new_with_label ( _( "  OK  " ) );
205   GTK_WIDGET_SET_FLAGS ( button, GTK_CAN_DEFAULT );
206   ::gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( m_widget [ WG_CONFIG_TOP ] )->action_area ),
207 			 button, FALSE, FALSE, 0 );
208   ::gtk_signal_connect ( GTK_OBJECT ( button ), "clicked",
209 			 GTK_SIGNAL_FUNC ( click_ok ), this );
210   ::gtk_widget_grab_default ( button );
211   ::gtk_widget_show ( button );
212 
213   // cancel
214   button = ::gtk_button_new_with_label ( _( "  Cancel  " ) );
215   ::gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( m_widget [ WG_CONFIG_TOP ] )->action_area ),
216 			 button, FALSE, FALSE, 0 );
217   ::gtk_signal_connect ( GTK_OBJECT ( button ), "clicked",
218 			 GTK_SIGNAL_FUNC ( click_cancel ), this );
219   ::gtk_widget_show ( button );
220 
221   return 0;
222 }
223 
224