xref: /aoo41x/main/padmin/source/cmddlg.cxx (revision 466d5a0b)
1*466d5a0bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*466d5a0bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*466d5a0bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*466d5a0bSAndrew Rist  * distributed with this work for additional information
6*466d5a0bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*466d5a0bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*466d5a0bSAndrew Rist  * "License"); you may not use this file except in compliance
9*466d5a0bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*466d5a0bSAndrew Rist  *
11*466d5a0bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*466d5a0bSAndrew Rist  *
13*466d5a0bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*466d5a0bSAndrew Rist  * software distributed under the License is distributed on an
15*466d5a0bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*466d5a0bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*466d5a0bSAndrew Rist  * specific language governing permissions and limitations
18*466d5a0bSAndrew Rist  * under the License.
19*466d5a0bSAndrew Rist  *
20*466d5a0bSAndrew Rist  *************************************************************/
21*466d5a0bSAndrew Rist 
22*466d5a0bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir #include <vcl/msgbox.hxx>
26cdf0e10cSrcweir #include <vcl/svapp.hxx>
27cdf0e10cSrcweir #ifndef _PAD_RTSETUP_HRC_
28cdf0e10cSrcweir #include <rtsetup.hrc>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <cmddlg.hxx>
31cdf0e10cSrcweir #include <padialog.hxx>
32cdf0e10cSrcweir #include <helper.hxx>
33cdf0e10cSrcweir #include <prtsetup.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace psp;
36cdf0e10cSrcweir using namespace rtl;
37cdf0e10cSrcweir using namespace padmin;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define PRINTER_PERSISTENCE_GROUP "KnownPrinterCommands"
40cdf0e10cSrcweir #define FAX_PERSISTENCE_GROUP "KnownFaxCommands"
41cdf0e10cSrcweir #define PDF_PERSISTENCE_GROUP "KnowPdfCommands"
42cdf0e10cSrcweir #define MAX_COMMANDS 50
43cdf0e10cSrcweir 
getSystemPrintCommands(::std::list<String> & rCommands)44cdf0e10cSrcweir void CommandStore::getSystemPrintCommands( ::std::list< String >& rCommands )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 	static ::std::list< OUString > aSysCommands;
47cdf0e10cSrcweir 	static bool bOnce = false;
48cdf0e10cSrcweir 	if( ! bOnce )
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		bOnce = true;
51cdf0e10cSrcweir 		PrinterInfoManager::get().getSystemPrintCommands( aSysCommands );
52cdf0e10cSrcweir 	}
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	::std::list< OUString >::const_iterator it;
55cdf0e10cSrcweir 	for( it = aSysCommands.begin(); it != aSysCommands.end(); ++it )
56cdf0e10cSrcweir 		rCommands.push_back( *it );
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
getSystemPdfCommands(::std::list<String> & rCommands)59cdf0e10cSrcweir void CommandStore::getSystemPdfCommands( ::std::list< String >& rCommands )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	static bool bOnce = false;
62cdf0e10cSrcweir 	static ::std::list< String > aSysCommands;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	if( ! bOnce )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		bOnce = true;
67cdf0e10cSrcweir 		char pBuffer[1024];
68cdf0e10cSrcweir 		FILE* pPipe;
69cdf0e10cSrcweir 		String aCommand;
70cdf0e10cSrcweir 		rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 		pPipe = popen( "which gs 2>/dev/null", "r" );
73cdf0e10cSrcweir 		if( pPipe )
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			if (fgets( pBuffer, sizeof( pBuffer ), pPipe ) != NULL)
76cdf0e10cSrcweir 			{
77cdf0e10cSrcweir 				int nLen = strlen( pBuffer );
78cdf0e10cSrcweir 	            if( pBuffer[nLen-1] == '\n' ) // strip newline
79cdf0e10cSrcweir 	                pBuffer[--nLen] = 0;
80cdf0e10cSrcweir 	            aCommand = String( ByteString( pBuffer ), aEncoding );
81cdf0e10cSrcweir 	            if( ( ( aCommand.GetChar( 0 ) == '/' )
82cdf0e10cSrcweir 	                  || ( aCommand.GetChar( 0 ) == '.' && aCommand.GetChar( 1 ) == '/' )
83cdf0e10cSrcweir 	                  || ( aCommand.GetChar( 0 ) == '.' && aCommand.GetChar( 1 ) == '.' && aCommand.GetChar( 2 ) == '/' ) )
84cdf0e10cSrcweir 	                && nLen > 2
85cdf0e10cSrcweir 	                && aCommand.GetChar( nLen-2 ) == 'g'
86cdf0e10cSrcweir 	                && aCommand.GetChar( nLen-1 ) == 's' )
87cdf0e10cSrcweir 	            {
88cdf0e10cSrcweir 					aCommand.AppendAscii( " -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=\"(OUTFILE)\" -" );
89cdf0e10cSrcweir 					aSysCommands.push_back( aCommand );
90cdf0e10cSrcweir 				}
91cdf0e10cSrcweir 			}
92cdf0e10cSrcweir 			pclose( pPipe );
93cdf0e10cSrcweir 		}
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		pPipe = popen( "which distill 2>/dev/null", "r" );
96cdf0e10cSrcweir 		if( pPipe )
97cdf0e10cSrcweir 		{
98cdf0e10cSrcweir 			if (fgets( pBuffer, sizeof( pBuffer ), pPipe ) != NULL)
99cdf0e10cSrcweir 			{
100cdf0e10cSrcweir 				int nLen = strlen( pBuffer );
101cdf0e10cSrcweir 	            if( pBuffer[nLen-1] == '\n' ) // strip newline
102cdf0e10cSrcweir 	                pBuffer[--nLen] = 0;
103cdf0e10cSrcweir 	            aCommand = String( ByteString( pBuffer ), aEncoding );
104cdf0e10cSrcweir 	            if( ( ( aCommand.GetChar( 0 ) == '/' )
105cdf0e10cSrcweir 	                  || ( aCommand.GetChar( 0 ) == '.' && aCommand.GetChar( 1 ) == '/' )
106cdf0e10cSrcweir 	                  || ( aCommand.GetChar( 0 ) == '.' && aCommand.GetChar( 1 ) == '.' && aCommand.GetChar( 2 ) == '/' ) )
107cdf0e10cSrcweir 	                && nLen > 7
108cdf0e10cSrcweir 	                && aCommand.Copy( nLen - 8 ).EqualsAscii( "/distill" ) )
109cdf0e10cSrcweir 				{
110cdf0e10cSrcweir 					aCommand.AppendAscii( " (TMP) ; mv `echo (TMP) | sed s/\\.ps\\$/.pdf/` \"(OUTFILE)\"" );
111cdf0e10cSrcweir 					aSysCommands.push_back( aCommand );
112cdf0e10cSrcweir 				}
113cdf0e10cSrcweir 			}
114cdf0e10cSrcweir 			pclose( pPipe );
115cdf0e10cSrcweir 		}
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 	::std::list< String >::const_iterator it;
118cdf0e10cSrcweir 	for( it = aSysCommands.begin(); it != aSysCommands.end(); ++it )
119cdf0e10cSrcweir 		rCommands.push_back( *it );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
getStoredCommands(const char * pGroup,::std::list<String> & rCommands)124cdf0e10cSrcweir void CommandStore::getStoredCommands( const char* pGroup, ::std::list< String >& rCommands )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	Config& rConfig( getPadminRC() );
127cdf0e10cSrcweir 	rConfig.SetGroup( pGroup );
128cdf0e10cSrcweir 	int nKeys = rConfig.GetKeyCount();
129cdf0e10cSrcweir 	::std::list< String >::const_iterator it;
130cdf0e10cSrcweir 	while( nKeys-- )
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		String aCommand( rConfig.ReadKey( ByteString::CreateFromInt32( nKeys ), RTL_TEXTENCODING_UTF8 ) );
133cdf0e10cSrcweir         if( aCommand.Len() )
134cdf0e10cSrcweir         {
135cdf0e10cSrcweir             for( it = rCommands.begin(); it != rCommands.end() && *it != aCommand; ++it )
136cdf0e10cSrcweir                 ;
137cdf0e10cSrcweir             if( it == rCommands.end() )
138cdf0e10cSrcweir                 rCommands.push_back( aCommand );
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
setCommands(const char * pGroup,const::std::list<String> & rCommands,const::std::list<String> & rSysCommands)143cdf0e10cSrcweir void CommandStore::setCommands(
144cdf0e10cSrcweir 							   const char* pGroup,
145cdf0e10cSrcweir 							   const ::std::list< String >& rCommands,
146cdf0e10cSrcweir 							   const ::std::list< String >& rSysCommands
147cdf0e10cSrcweir 							   )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	Config& rConfig( getPadminRC() );
150cdf0e10cSrcweir 	rConfig.DeleteGroup( pGroup );
151cdf0e10cSrcweir 	rConfig.SetGroup( pGroup );
152cdf0e10cSrcweir 	::std::list< String >::const_iterator it, loop;
153cdf0e10cSrcweir 	::std::list< String > aWriteList;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	int nWritten = 0;
156cdf0e10cSrcweir 	for( it = rCommands.begin(); it != rCommands.end(); ++it )
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir         if( it->Len() )
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             for( loop = rSysCommands.begin(); loop != rSysCommands.end() && *loop != *it; ++loop )
161cdf0e10cSrcweir                 ;
162cdf0e10cSrcweir             if( loop == rSysCommands.end() )
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 aWriteList.push_back( *it );
165cdf0e10cSrcweir                 nWritten++;
166cdf0e10cSrcweir             }
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 	while( nWritten > MAX_COMMANDS )
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		aWriteList.pop_front();
172cdf0e10cSrcweir 		nWritten--;
173cdf0e10cSrcweir 	}
174cdf0e10cSrcweir 	for( nWritten = 0, it = aWriteList.begin(); it != aWriteList.end(); ++it, ++nWritten )
175cdf0e10cSrcweir 		rConfig.WriteKey( ByteString::CreateFromInt32( nWritten ), ByteString( *it, RTL_TEXTENCODING_UTF8 ) );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
getPrintCommands(::std::list<String> & rCommands)179cdf0e10cSrcweir void CommandStore::getPrintCommands( ::std::list< String >& rCommands )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	rCommands.clear();
182cdf0e10cSrcweir 	getSystemPrintCommands( rCommands );
183cdf0e10cSrcweir 	getStoredCommands( PRINTER_PERSISTENCE_GROUP, rCommands );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
getPdfCommands(::std::list<String> & rCommands)186cdf0e10cSrcweir void CommandStore::getPdfCommands( ::std::list< String >& rCommands )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	rCommands.clear();
189cdf0e10cSrcweir 	getSystemPdfCommands( rCommands );
190cdf0e10cSrcweir 	getStoredCommands( PDF_PERSISTENCE_GROUP, rCommands );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
getFaxCommands(::std::list<String> & rCommands)193cdf0e10cSrcweir void CommandStore::getFaxCommands( ::std::list< String >& rCommands )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	rCommands.clear();
196cdf0e10cSrcweir 	getStoredCommands( FAX_PERSISTENCE_GROUP, rCommands );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
setPrintCommands(const::std::list<String> & rCommands)199cdf0e10cSrcweir void CommandStore::setPrintCommands( const ::std::list< String >& rCommands )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	::std::list< String > aSysCmds;
202cdf0e10cSrcweir 	getSystemPrintCommands( aSysCmds );
203cdf0e10cSrcweir 	setCommands( PRINTER_PERSISTENCE_GROUP, rCommands, aSysCmds );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
setPdfCommands(const::std::list<String> & rCommands)206cdf0e10cSrcweir void CommandStore::setPdfCommands( const ::std::list< String >& rCommands )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	::std::list< String > aSysCmds;
209cdf0e10cSrcweir 	getSystemPdfCommands( aSysCmds );
210cdf0e10cSrcweir 	setCommands( PDF_PERSISTENCE_GROUP, rCommands, aSysCmds );
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
setFaxCommands(const::std::list<String> & rCommands)213cdf0e10cSrcweir void CommandStore::setFaxCommands( const ::std::list< String >& rCommands )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir 	::std::list< String > aSysCmds;
216cdf0e10cSrcweir 	setCommands( FAX_PERSISTENCE_GROUP, rCommands, aSysCmds );
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
RTSCommandPage(RTSDialog * pParent)220cdf0e10cSrcweir RTSCommandPage::RTSCommandPage( RTSDialog* pParent ) :
221cdf0e10cSrcweir 		TabPage( &pParent->m_aTabControl, PaResId( RID_RTS_COMMANDPAGE ) ),
222cdf0e10cSrcweir 		m_pParent( pParent ),
223cdf0e10cSrcweir 		m_aCommandsCB( this, PaResId( RID_RTS_CMD_CB_COMMANDS ) ),
224cdf0e10cSrcweir         m_aExternalCB( this, PaResId( RID_RTS_CMD_CB_EXTERNAL ) ),
225cdf0e10cSrcweir         m_aQuickFT( this, PaResId( RID_RTS_CMD_FT_QUICKCMD ) ),
226cdf0e10cSrcweir         m_aQuickCB( this, PaResId( RIT_RTS_CMD_CB_QUICKCMD ) ),
227cdf0e10cSrcweir 		m_aCommandTitle( this, PaResId( RID_RTS_CMD_FL_INSTALL ) ),
228cdf0e10cSrcweir 		m_aPrinterName( this, PaResId( RID_RTS_CMD_TXT_PRTNAME ) ),
229cdf0e10cSrcweir 		m_aConnectedTo( this, PaResId( RID_RTS_CMD_TXT_CONNECT ) ),
230cdf0e10cSrcweir 		m_aPrinterFL( this, PaResId( RID_RTS_CMD_FL_DEFAULT ) ),
231cdf0e10cSrcweir 		m_aConfigureText( this, PaResId( RID_RTS_CMD_TXT_CONFIGURE ) ),
232cdf0e10cSrcweir 		m_aConfigureBox( this, PaResId( RID_RTS_CMD_LB_CONFIGURE ) ),
233cdf0e10cSrcweir 		m_aPdfDirectoryText( this, PaResId( RID_RTS_CMD_TXT_PDFDIR ) ),
234cdf0e10cSrcweir 		m_aPdfDirectoryButton( this, PaResId( RID_RTS_CMD_BTN_PDFDIR ) ),
235cdf0e10cSrcweir 		m_aPdfDirectoryEdit( this, PaResId( RID_RTS_CMD_EDT_PDFDIR ) ),
236cdf0e10cSrcweir 		m_aFaxSwallowBox( this, PaResId( RID_RTS_CMD_BOX_SWALLOWFAXNO ) ),
237cdf0e10cSrcweir 		m_aHelpButton( this, PaResId( RID_RTS_CMD_BTN_HELP ) ),
238cdf0e10cSrcweir 		m_aRemovePB( this, PaResId( RID_RTS_CMD_BTN_REMOVE ) ),
239cdf0e10cSrcweir 		m_aFaxHelp( PaResId( RID_RTS_CMD_STR_FAXHELP ) ),
240cdf0e10cSrcweir 		m_aPrinterHelp( PaResId( RID_RTS_CMD_STR_PRINTERHELP ) ),
241cdf0e10cSrcweir 		m_aPdfHelp( PaResId( RID_RTS_CMD_STR_PDFHELP ) )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     // configuring as printer is only sensible in default print system
244cdf0e10cSrcweir     PrinterInfoManager& rMgr( PrinterInfoManager::get() );
245cdf0e10cSrcweir     if( rMgr.getType() == PrinterInfoManager::Default || rMgr.isCUPSDisabled() )
246cdf0e10cSrcweir         m_nPrinterEntry = m_aConfigureBox.InsertEntry( String( PaResId( RID_RTS_CMD_STR_CONFIGURE_PRINTER ) ) );
247cdf0e10cSrcweir     else
248cdf0e10cSrcweir         m_nPrinterEntry = ~0;
249cdf0e10cSrcweir 	m_nFaxEntry = m_aConfigureBox.InsertEntry( String( PaResId( RID_RTS_CMD_STR_CONFIGURE_FAX ) ) );
250cdf0e10cSrcweir 	m_nPdfEntry = m_aConfigureBox.InsertEntry( String( PaResId( RID_RTS_CMD_STR_CONFIGURE_PDF ) ) );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	FreeResource();
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	CommandStore::getPrintCommands( m_aPrinterCommands );
255cdf0e10cSrcweir 	CommandStore::getFaxCommands( m_aFaxCommands );
256cdf0e10cSrcweir 	CommandStore::getPdfCommands( m_aPdfCommands );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	m_aPrinterName.SetText( m_pParent->m_aPrinter );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	m_aCommandsCB.SetDoubleClickHdl( LINK( this, RTSCommandPage, DoubleClickHdl ) );
261cdf0e10cSrcweir 	m_aCommandsCB.SetSelectHdl( LINK( this, RTSCommandPage, SelectHdl ) );
262cdf0e10cSrcweir 	m_aCommandsCB.SetModifyHdl( LINK( this, RTSCommandPage, ModifyHdl ) );
263cdf0e10cSrcweir 	m_aConfigureBox.SetSelectHdl( LINK( this, RTSCommandPage, SelectHdl ) );
264cdf0e10cSrcweir 	m_aHelpButton.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
265cdf0e10cSrcweir 	m_aRemovePB.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
266cdf0e10cSrcweir 	m_aPdfDirectoryButton.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
267cdf0e10cSrcweir     m_aExternalCB.SetToggleHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 	m_aPdfDirectoryButton.Show( sal_False );
270cdf0e10cSrcweir 	m_aPdfDirectoryEdit.Show( sal_False );
271cdf0e10cSrcweir 	m_aPdfDirectoryText.Show( sal_False );
272cdf0e10cSrcweir 	m_aFaxSwallowBox.Show( sal_False );
273cdf0e10cSrcweir 	m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
274cdf0e10cSrcweir     m_aQuickCB.SetText( m_pParent->m_aJobData.m_aQuickCommand );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	m_bWasFax = false;
277cdf0e10cSrcweir 	m_bWasPdf = false;
278cdf0e10cSrcweir 	m_aConfigureBox.SelectEntryPos( m_nPrinterEntry );
279cdf0e10cSrcweir     sal_Int32 nIndex = 0;
280cdf0e10cSrcweir     while( nIndex != -1 )
281cdf0e10cSrcweir 	{
282cdf0e10cSrcweir 		OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
283cdf0e10cSrcweir 		if( ! aToken.compareToAscii( "fax", 3 ) )
284cdf0e10cSrcweir 		{
285cdf0e10cSrcweir 			m_bWasFax = true;
286cdf0e10cSrcweir 			m_aFaxSwallowBox.Show( sal_True );
287cdf0e10cSrcweir             sal_Int32 nPos = 0;
288cdf0e10cSrcweir 			m_aFaxSwallowBox.Check( ! aToken.getToken( 1, '=', nPos ).compareToAscii( "swallow", 7 ) ? sal_True : sal_False );
289cdf0e10cSrcweir 			m_aConfigureBox.SelectEntryPos( m_nFaxEntry );
290cdf0e10cSrcweir 		}
291cdf0e10cSrcweir 		else if( ! aToken.compareToAscii( "pdf=", 4 ) )
292cdf0e10cSrcweir 		{
293cdf0e10cSrcweir 			m_bWasPdf = true;
294cdf0e10cSrcweir             sal_Int32 nPos = 0;
295cdf0e10cSrcweir 			m_aPdfDirectoryEdit.SetText( aToken.getToken( 1, '=', nPos ) );
296cdf0e10cSrcweir 			m_aPdfDirectoryEdit.Show( sal_True );
297cdf0e10cSrcweir 			m_aPdfDirectoryButton.Show( sal_True );
298cdf0e10cSrcweir 			m_aPdfDirectoryText.Show( sal_True );
299cdf0e10cSrcweir 			m_aConfigureBox.SelectEntryPos( m_nPdfEntry );
300cdf0e10cSrcweir 		}
301cdf0e10cSrcweir         else if( ! aToken.compareToAscii( "external_dialog" ) )
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir             m_aExternalCB.Check();
304cdf0e10cSrcweir             m_bWasExternalDialog = true;
305cdf0e10cSrcweir         }
306cdf0e10cSrcweir 	}
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     m_aQuickCB.Enable( m_aExternalCB.IsChecked() );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	String aString( m_aConnectedTo.GetText() );
311cdf0e10cSrcweir 	aString += String( m_pParent->m_aJobData.m_aCommand );
312cdf0e10cSrcweir 	m_aConnectedTo.SetText( aString );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	UpdateCommands();
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
~RTSCommandPage()317cdf0e10cSrcweir RTSCommandPage::~RTSCommandPage()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
save()321cdf0e10cSrcweir void RTSCommandPage::save()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	String aCommand,aQuickCommand;
324cdf0e10cSrcweir 	bool bHaveFax = m_aConfigureBox.GetSelectEntryPos() == m_nFaxEntry ? true : false;
325cdf0e10cSrcweir 	bool bHavePdf = m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry ? true : false;
326cdf0e10cSrcweir 	::std::list< String >::iterator it;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	String aFeatures;
329cdf0e10cSrcweir     sal_Int32 nIndex = 0;
330cdf0e10cSrcweir 	String aOldPdfPath;
331cdf0e10cSrcweir 	bool bOldFaxSwallow = false;
332cdf0e10cSrcweir 	bool bFaxSwallow = m_aFaxSwallowBox.IsChecked() ? true : false;
333cdf0e10cSrcweir     bool bOldExternalDialog = false, bExternalDialog = m_aExternalCB.IsChecked() ? true : false;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     while( nIndex != -1 )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
338cdf0e10cSrcweir 		if( aToken.compareToAscii( "fax", 3 ) &&
339cdf0e10cSrcweir 			aToken.compareToAscii( "pdf", 3 ) &&
340cdf0e10cSrcweir             aToken.compareToAscii( "external_dialog" )
341cdf0e10cSrcweir           )
342cdf0e10cSrcweir 		{
343cdf0e10cSrcweir 			if( aToken.getLength() )
344cdf0e10cSrcweir 			{
345cdf0e10cSrcweir 				if( aFeatures.Len() )
346cdf0e10cSrcweir 					aFeatures += ',';
347cdf0e10cSrcweir 				aFeatures += String( aToken );
348cdf0e10cSrcweir 			}
349cdf0e10cSrcweir 		}
350cdf0e10cSrcweir 		else if( ! aToken.compareToAscii( "pdf=", 4 ) )
351cdf0e10cSrcweir         {
352cdf0e10cSrcweir             sal_Int32 nPos = 0;
353cdf0e10cSrcweir 			aOldPdfPath = aToken.getToken( 1, '=', nPos );
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir 		else if( ! aToken.compareToAscii( "fax=", 4 ) )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             sal_Int32 nPos = 0;
358cdf0e10cSrcweir 			bOldFaxSwallow = aToken.getToken( 1, '=', nPos ).compareToAscii( "swallow", 7 ) ? false : true;
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir         else if( ! aToken.compareToAscii( "external_dialog" ) )
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             bOldExternalDialog = true;
363cdf0e10cSrcweir         }
364cdf0e10cSrcweir 	}
365cdf0e10cSrcweir 	::std::list< String >* pList = &m_aPrinterCommands;
366cdf0e10cSrcweir     if( bExternalDialog )
367cdf0e10cSrcweir 	{
368cdf0e10cSrcweir 		if( aFeatures.Len() )
369cdf0e10cSrcweir 			aFeatures += ',';
370cdf0e10cSrcweir 		aFeatures.AppendAscii( "external_dialog" );
371cdf0e10cSrcweir 	}
372cdf0e10cSrcweir 	if( bHaveFax )
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		if( aFeatures.Len() )
375cdf0e10cSrcweir 			aFeatures += ',';
376cdf0e10cSrcweir 		aFeatures.AppendAscii( "fax=" );
377cdf0e10cSrcweir 		if( bFaxSwallow )
378cdf0e10cSrcweir 			aFeatures.AppendAscii( "swallow" );
379cdf0e10cSrcweir 		pList = &m_aFaxCommands;
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir 	if( bHavePdf )
382cdf0e10cSrcweir 	{
383cdf0e10cSrcweir 		if( aFeatures.Len() )
384cdf0e10cSrcweir 			aFeatures += ',';
385cdf0e10cSrcweir 		aFeatures.AppendAscii( "pdf=" );
386cdf0e10cSrcweir 		aFeatures.Append( m_aPdfDirectoryEdit.GetText() );
387cdf0e10cSrcweir 		pList = &m_aPdfCommands;
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir 	aCommand = m_aCommandsCB.GetText();
390cdf0e10cSrcweir     aQuickCommand = m_aQuickCB.GetText();
391cdf0e10cSrcweir 	for( it = pList->begin(); it != pList->end() && *it != aCommand; ++it )
392cdf0e10cSrcweir 		;
393cdf0e10cSrcweir 	if( it == pList->end() )
394cdf0e10cSrcweir 		pList->push_back( aCommand );
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	if( aCommand != String( m_pParent->m_aJobData.m_aCommand )		        ||
397cdf0e10cSrcweir         aQuickCommand != String( m_pParent->m_aJobData.m_aQuickCommand )    ||
398cdf0e10cSrcweir 		( m_bWasFax && ! bHaveFax )									        ||
399cdf0e10cSrcweir 		( ! m_bWasFax && bHaveFax )									        ||
400cdf0e10cSrcweir 		( m_bWasPdf && ! bHavePdf )									        ||
401cdf0e10cSrcweir 		( ! m_bWasPdf && bHavePdf )									        ||
402cdf0e10cSrcweir 		( bHavePdf && aOldPdfPath != m_aPdfDirectoryEdit.GetText() )        ||
403cdf0e10cSrcweir 		( bHaveFax && bFaxSwallow != bOldFaxSwallow )                       ||
404cdf0e10cSrcweir         ( m_bWasExternalDialog && ! bExternalDialog )                       ||
405cdf0e10cSrcweir         ( ! m_bWasExternalDialog && bExternalDialog )
406cdf0e10cSrcweir 		)
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		m_pParent->m_aJobData.m_aCommand	    = aCommand;
409cdf0e10cSrcweir         m_pParent->m_aJobData.m_aQuickCommand   = aQuickCommand;
410cdf0e10cSrcweir 		m_pParent->m_aJobData.m_aFeatures	    = aFeatures;
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 		PrinterInfoManager::get().changePrinterInfo( m_pParent->m_aPrinter, m_pParent->m_aJobData );
413cdf0e10cSrcweir 	}
414cdf0e10cSrcweir 	CommandStore::setPrintCommands( m_aPrinterCommands );
415cdf0e10cSrcweir 	CommandStore::setFaxCommands( m_aFaxCommands );
416cdf0e10cSrcweir 	CommandStore::setPdfCommands( m_aPdfCommands );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 
IMPL_LINK(RTSCommandPage,SelectHdl,Control *,pBox)420cdf0e10cSrcweir IMPL_LINK( RTSCommandPage, SelectHdl, Control*, pBox )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	if( pBox == &m_aConfigureBox )
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		sal_Bool bEnable = m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry ? sal_True : sal_False;
425cdf0e10cSrcweir 		m_aPdfDirectoryButton.Show( bEnable );
426cdf0e10cSrcweir 		m_aPdfDirectoryEdit.Show( bEnable );
427cdf0e10cSrcweir 		m_aPdfDirectoryText.Show( bEnable );
428cdf0e10cSrcweir 		bEnable = m_aConfigureBox.GetSelectEntryPos() == m_nFaxEntry ? sal_True : sal_False;
429cdf0e10cSrcweir 		m_aFaxSwallowBox.Show( bEnable );
430cdf0e10cSrcweir 		UpdateCommands();
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 	else if( pBox == &m_aCommandsCB )
433cdf0e10cSrcweir 	{
434cdf0e10cSrcweir 		m_aRemovePB.Enable( sal_True );
435cdf0e10cSrcweir 	}
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	return 0;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
IMPL_LINK(RTSCommandPage,ClickBtnHdl,Button *,pButton)440cdf0e10cSrcweir IMPL_LINK( RTSCommandPage, ClickBtnHdl, Button*, pButton )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	if( pButton == & m_aPdfDirectoryButton )
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir         String aPath( m_aPdfDirectoryEdit.GetText() );
445cdf0e10cSrcweir         if( chooseDirectory( aPath ) )
446cdf0e10cSrcweir 			m_aPdfDirectoryEdit.SetText( aPath );
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir 	else if( pButton == &m_aRemovePB )
449cdf0e10cSrcweir 	{
450cdf0e10cSrcweir 		String aEntry( m_aCommandsCB.GetText() );
451cdf0e10cSrcweir 		::std::list< String >* pList;
452cdf0e10cSrcweir 		if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
453cdf0e10cSrcweir 			pList = &m_aPrinterCommands;
454cdf0e10cSrcweir 		else if( m_aConfigureBox.GetSelectEntryPos() == m_nFaxEntry )
455cdf0e10cSrcweir 			pList = &m_aFaxCommands;
456cdf0e10cSrcweir 		else
457cdf0e10cSrcweir 			pList = &m_aPdfCommands;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 		pList->remove( aEntry );
460cdf0e10cSrcweir 		m_aCommandsCB.RemoveEntry( aEntry );
461cdf0e10cSrcweir         m_aQuickCB.RemoveEntry( aEntry );
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir 	else if( pButton == &m_aHelpButton )
464cdf0e10cSrcweir 	{
465cdf0e10cSrcweir 		String aHelpText;
466cdf0e10cSrcweir 		if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
467cdf0e10cSrcweir 			aHelpText = m_aPrinterHelp;
468cdf0e10cSrcweir 		else if( m_aConfigureBox.GetSelectEntryPos() == m_nFaxEntry )
469cdf0e10cSrcweir 			aHelpText = m_aFaxHelp;
470cdf0e10cSrcweir 		else if( m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry )
471cdf0e10cSrcweir 			aHelpText = m_aPdfHelp;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 		InfoBox aBox( this, aHelpText );
474cdf0e10cSrcweir 		aBox.Execute();
475cdf0e10cSrcweir 	}
476cdf0e10cSrcweir     else if( pButton == &m_aExternalCB )
477cdf0e10cSrcweir     {
478cdf0e10cSrcweir         m_aQuickCB.Enable( m_aExternalCB.IsChecked() );
479cdf0e10cSrcweir     }
480cdf0e10cSrcweir 	return 0;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
IMPL_LINK(RTSCommandPage,DoubleClickHdl,ComboBox *,pComboBox)483cdf0e10cSrcweir IMPL_LINK( RTSCommandPage, DoubleClickHdl, ComboBox*, pComboBox )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	if( pComboBox == &m_aCommandsCB )
486cdf0e10cSrcweir 		ConnectCommand();
487cdf0e10cSrcweir 	return 0;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
IMPL_LINK(RTSCommandPage,ModifyHdl,Edit *,pEdit)490cdf0e10cSrcweir IMPL_LINK( RTSCommandPage, ModifyHdl, Edit*, pEdit )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir 	if( pEdit == &m_aCommandsCB )
493cdf0e10cSrcweir 		m_aRemovePB.Enable( m_aCommandsCB.GetEntryPos( m_aCommandsCB.GetText() ) != LISTBOX_ENTRY_NOTFOUND );
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	return 0;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
UpdateCommands()498cdf0e10cSrcweir void RTSCommandPage::UpdateCommands()
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	m_aCommandsCB.Clear();
501cdf0e10cSrcweir 	::std::list< String >::iterator it;
502cdf0e10cSrcweir 	if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir 		for( it = m_aPrinterCommands.begin(); it != m_aPrinterCommands.end(); ++it )
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir 			m_aCommandsCB.InsertEntry( *it );
507cdf0e10cSrcweir             m_aQuickCB.InsertEntry( *it );
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir 		if( ! m_bWasFax )
510cdf0e10cSrcweir 			m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
511cdf0e10cSrcweir 		else
512cdf0e10cSrcweir 			m_aCommandsCB.SetText( String() );
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 	else if( m_aConfigureBox.GetSelectEntryPos() == m_nFaxEntry )
515cdf0e10cSrcweir 	{
516cdf0e10cSrcweir 		for( it = m_aFaxCommands.begin(); it != m_aFaxCommands.end(); ++it )
517cdf0e10cSrcweir         {
518cdf0e10cSrcweir 			m_aCommandsCB.InsertEntry( *it );
519cdf0e10cSrcweir             m_aQuickCB.InsertEntry( *it );
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir 		if( m_bWasFax )
522cdf0e10cSrcweir 			m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
523cdf0e10cSrcweir 		else
524cdf0e10cSrcweir 			m_aCommandsCB.SetText( String() );
525cdf0e10cSrcweir 	}
526cdf0e10cSrcweir 	else if( m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry )
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		for( it = m_aPdfCommands.begin(); it != m_aPdfCommands.end(); ++it )
529cdf0e10cSrcweir         {
530cdf0e10cSrcweir 			m_aCommandsCB.InsertEntry( *it );
531cdf0e10cSrcweir             m_aQuickCB.InsertEntry( *it );
532cdf0e10cSrcweir         }
533cdf0e10cSrcweir 		if( m_bWasPdf )
534cdf0e10cSrcweir 			m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
535cdf0e10cSrcweir 		else
536cdf0e10cSrcweir 			m_aCommandsCB.SetText( String() );
537cdf0e10cSrcweir 	}
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
ConnectCommand()540cdf0e10cSrcweir void RTSCommandPage::ConnectCommand()
541cdf0e10cSrcweir {
542cdf0e10cSrcweir 	String aString( m_aConnectedTo.GetText().GetToken( 0, ':' ) );
543cdf0e10cSrcweir 	aString.AppendAscii( ": " );
544cdf0e10cSrcweir 	aString += m_aCommandsCB.GetText();
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 	m_aConnectedTo.SetText( aString );
547cdf0e10cSrcweir }
548