2001-05-08 05:56:39 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* $RCSfile: newppdlg.cxx,v $
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* $Revision: 1.12 $
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* last change: $Author: rt $ $Date: 2005-09-08 16:25:44 $
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2005-09-08 10:25:44 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#ifndef _PSPRINT_PPDPARSER_HXX_
|
|
|
|
#include <psprint/ppdparser.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PSPRINT_HELPER_HXX_
|
|
|
|
#include <psprint/helper.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SV_SVAPP_HXX
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#endif
|
2004-01-07 08:43:14 -06:00
|
|
|
#ifndef _SV_MNEMONIC_HXX
|
|
|
|
#include <vcl/mnemonic.hxx>
|
|
|
|
#endif
|
2001-05-08 05:56:39 -05:00
|
|
|
#ifndef _URLOBJ_HXX
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef __SGI_STL_LIST
|
|
|
|
#include <list>
|
|
|
|
#endif
|
|
|
|
#ifndef _OSL_FILE_HXX_
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _PAD_HELPER_HXX_
|
|
|
|
#include <helper.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PAD_PADIALOG_HRC_
|
|
|
|
#include <padialog.hrc>
|
|
|
|
#endif
|
|
|
|
#ifndef _PAD_NEWPPDLG_HXX_
|
|
|
|
#include <newppdlg.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PAD_PADIALOG_HXX_
|
|
|
|
#include <padialog.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PAD_PROGRESS_HXX_
|
|
|
|
#include <progress.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PPDIMPORT_GROUP "PPDImport"
|
|
|
|
|
|
|
|
using namespace padmin;
|
|
|
|
using namespace psp;
|
|
|
|
using namespace osl;
|
|
|
|
using namespace rtl;
|
|
|
|
|
|
|
|
PPDImportDialog::PPDImportDialog( Window* pParent ) :
|
|
|
|
ModalDialog( pParent, PaResId( RID_PPDIMPORT_DLG ) ),
|
|
|
|
m_aOKBtn( this, PaResId( RID_PPDIMP_BTN_OK ) ),
|
|
|
|
m_aCancelBtn( this, PaResId( RID_PPDIMP_BTN_CANCEL ) ),
|
2004-03-17 03:44:51 -06:00
|
|
|
m_aPathTxt( this, PaResId( RID_PPDIMP_TXT_PATH ) ),
|
2001-05-08 05:56:39 -05:00
|
|
|
m_aPathBox( this, PaResId( RID_PPDIMP_LB_PATH ) ),
|
2004-03-17 03:44:51 -06:00
|
|
|
m_aSearchBtn( this, PaResId( RID_PPDIMP_BTN_SEARCH ) ),
|
2001-05-08 05:56:39 -05:00
|
|
|
m_aDriverTxt( this, PaResId( RID_PPDIMP_TXT_DRIVER ) ),
|
|
|
|
m_aDriverLB( this, PaResId( RID_PPDIMP_LB_DRIVER ) ),
|
|
|
|
m_aPathGroup( this, PaResId( RID_PPDIMP_GROUP_PATH ) ),
|
|
|
|
m_aDriverGroup( this, PaResId( RID_PPDIMP_GROUP_DRIVER ) ),
|
|
|
|
m_aLoadingPPD( PaResId( RID_PPDIMP_STR_LOADINGPPD ) )
|
|
|
|
{
|
|
|
|
FreeResource();
|
|
|
|
|
|
|
|
String aText( m_aDriverTxt.GetText() );
|
|
|
|
aText.SearchAndReplaceAscii( "%s", Button::GetStandardText( BUTTON_OK ) );
|
2004-01-07 08:43:14 -06:00
|
|
|
m_aDriverTxt.SetText( MnemonicGenerator::EraseAllMnemonicChars( aText ) );
|
2001-05-08 05:56:39 -05:00
|
|
|
|
|
|
|
Config& rConfig = getPadminRC();
|
|
|
|
rConfig.SetGroup( PPDIMPORT_GROUP );
|
|
|
|
m_aPathBox.SetText( String( rConfig.ReadKey( "LastDir" ), RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
for( int i = 0; i < 11; i++ )
|
|
|
|
{
|
|
|
|
ByteString aEntry( rConfig.ReadKey( ByteString::CreateFromInt32( i ) ) );
|
|
|
|
if( aEntry.Len() )
|
|
|
|
m_aPathBox.InsertEntry( String( aEntry, RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_aOKBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
|
|
|
|
m_aCancelBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
|
|
|
|
m_aSearchBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
|
|
|
|
m_aPathBox.SetSelectHdl( LINK( this, PPDImportDialog, SelectHdl ) );
|
|
|
|
m_aPathBox.SetModifyHdl( LINK( this, PPDImportDialog, ModifyHdl ) );
|
2002-07-15 06:49:55 -05:00
|
|
|
|
|
|
|
if( m_aPathBox.GetText().Len() )
|
|
|
|
Import();
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PPDImportDialog::~PPDImportDialog()
|
|
|
|
{
|
|
|
|
while( m_aDriverLB.GetEntryCount() )
|
|
|
|
{
|
|
|
|
delete (String*)m_aDriverLB.GetEntryData( 0 );
|
|
|
|
m_aDriverLB.RemoveEntry( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PPDImportDialog::Import()
|
|
|
|
{
|
|
|
|
String aImportPath( m_aPathBox.GetText() );
|
|
|
|
|
|
|
|
Config& rConfig = getPadminRC();
|
|
|
|
rConfig.SetGroup( PPDIMPORT_GROUP );
|
|
|
|
rConfig.WriteKey( "LastDir", ByteString( aImportPath, RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
|
|
|
|
int nEntries = m_aPathBox.GetEntryCount();
|
|
|
|
while( nEntries-- )
|
|
|
|
if( aImportPath == m_aPathBox.GetEntry( nEntries ) )
|
|
|
|
break;
|
|
|
|
if( nEntries < 0 )
|
|
|
|
{
|
|
|
|
int nNextEntry = rConfig.ReadKey( "NextEntry" ).ToInt32();
|
|
|
|
rConfig.WriteKey( ByteString::CreateFromInt32( nNextEntry ), ByteString( aImportPath, RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
nNextEntry = nNextEntry < 10 ? nNextEntry+1 : 0;
|
|
|
|
rConfig.WriteKey( "NextEntry", ByteString::CreateFromInt32( nNextEntry ) );
|
|
|
|
m_aPathBox.InsertEntry( aImportPath );
|
|
|
|
}
|
|
|
|
while( m_aDriverLB.GetEntryCount() )
|
|
|
|
{
|
|
|
|
delete (String*)m_aDriverLB.GetEntryData( 0 );
|
|
|
|
m_aDriverLB.RemoveEntry( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressDialog aProgress( Application::GetFocusWindow() );
|
|
|
|
aProgress.startOperation( m_aLoadingPPD );
|
|
|
|
|
|
|
|
::std::list< String > aFiles;
|
|
|
|
FindFiles( aImportPath, aFiles, String::CreateFromAscii( "PS;PPD" ) );
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
aProgress.setRange( 0, aFiles.size() );
|
|
|
|
while( aFiles.size() )
|
|
|
|
{
|
|
|
|
aProgress.setValue( ++i );
|
|
|
|
aProgress.setFilename( aFiles.front() );
|
|
|
|
INetURLObject aPath( aImportPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
|
|
|
|
aPath.Append( aFiles.front() );
|
|
|
|
String aPrinterName = PPDParser::getPPDPrinterName( aPath.PathToFileName() );
|
|
|
|
aFiles.pop_front();
|
|
|
|
|
|
|
|
if( ! aPrinterName.Len() )
|
|
|
|
{
|
2003-04-15 11:21:55 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-05-08 05:56:39 -05:00
|
|
|
fprintf( stderr, "Warning: File %s has empty printer name.\n",
|
2005-03-18 10:55:41 -06:00
|
|
|
rtl::OUStringToOString( aPath.PathToFileName(), osl_getThreadTextEncoding() ).getStr() );
|
2001-05-08 05:56:39 -05:00
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
USHORT nPos = m_aDriverLB.InsertEntry( aPrinterName );
|
|
|
|
m_aDriverLB.SetEntryData( nPos, new String( aPath.PathToFileName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( PPDImportDialog, ClickBtnHdl, PushButton*, pButton )
|
|
|
|
{
|
|
|
|
if( pButton == &m_aCancelBtn )
|
|
|
|
{
|
|
|
|
EndDialog( 0 );
|
|
|
|
}
|
|
|
|
else if( pButton == &m_aOKBtn )
|
|
|
|
{
|
|
|
|
// copy the files
|
|
|
|
::std::list< String > aToDirs;
|
|
|
|
String aPathList( ::psp::getPrinterPath() );
|
|
|
|
int nTokens = aPathList.GetTokenCount( ':' );
|
|
|
|
for( int n = 0; n < nTokens; n++ )
|
|
|
|
{
|
|
|
|
String aPath = aPathList.GetToken( n, ':' );
|
|
|
|
aPath.AppendAscii( "/"PSPRINT_PPDDIR );
|
|
|
|
aToDirs.push_back( aPath );
|
|
|
|
}
|
|
|
|
::std::list< String >::iterator writeDir = aToDirs.begin();
|
|
|
|
|
|
|
|
for( int i = 0; i < m_aDriverLB.GetSelectEntryCount(); i++ )
|
|
|
|
{
|
|
|
|
INetURLObject aFile( *(String*)m_aDriverLB.GetEntryData(
|
|
|
|
m_aDriverLB.GetSelectEntryPos( i )
|
|
|
|
), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
|
2002-12-02 10:33:44 -06:00
|
|
|
OUString aFromUni( aFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );
|
2001-05-08 05:56:39 -05:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
INetURLObject aToFile( *writeDir, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
|
|
|
|
aToFile.Append( aFile.GetName() );
|
|
|
|
aToFile.setExtension( String::CreateFromAscii( "PPD" ) );
|
2002-12-02 10:33:44 -06:00
|
|
|
OUString aToUni( aToFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );
|
2001-05-08 05:56:39 -05:00
|
|
|
if( ! File::copy( aFromUni, aToUni ) )
|
|
|
|
break;
|
|
|
|
++writeDir;
|
|
|
|
} while( writeDir != aToDirs.end() );
|
|
|
|
}
|
|
|
|
EndDialog( 1 );
|
|
|
|
}
|
|
|
|
else if( pButton == &m_aSearchBtn )
|
|
|
|
{
|
2001-09-04 10:24:50 -05:00
|
|
|
String aPath( m_aPathBox.GetText() );
|
|
|
|
if( chooseDirectory( this, aPath ) )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
2001-09-04 10:24:50 -05:00
|
|
|
m_aPathBox.SetText( aPath );
|
2001-05-08 05:56:39 -05:00
|
|
|
Import();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( PPDImportDialog, SelectHdl, ComboBox*, pListBox )
|
|
|
|
{
|
|
|
|
if( pListBox == &m_aPathBox )
|
|
|
|
{
|
|
|
|
Import();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( PPDImportDialog, ModifyHdl, ComboBox*, pListBox )
|
|
|
|
{
|
|
|
|
if( pListBox == &m_aPathBox )
|
|
|
|
{
|
2002-09-03 07:33:01 -05:00
|
|
|
ByteString aDir( m_aPathBox.GetText(), osl_getThreadTextEncoding() );
|
2001-05-08 05:56:39 -05:00
|
|
|
if( ! access( aDir.GetBuffer(), F_OK ) )
|
|
|
|
Import();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|