LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/padmin/source - newppdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 105 0.0 %
Date: 2013-07-09 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : #include <unistd.h>
      22             : 
      23             : #include "helper.hxx"
      24             : #include "padialog.hrc"
      25             : #include "newppdlg.hxx"
      26             : #include "padialog.hxx"
      27             : #include "progress.hxx"
      28             : 
      29             : #include "vcl/ppdparser.hxx"
      30             : #include "vcl/helper.hxx"
      31             : #include "vcl/svapp.hxx"
      32             : #include "vcl/mnemonic.hxx"
      33             : 
      34             : #include "tools/config.hxx"
      35             : #include "tools/urlobj.hxx"
      36             : 
      37             : #include "osl/file.hxx"
      38             : 
      39             : #include <list>
      40             : 
      41             : #define PPDIMPORT_GROUP "PPDImport"
      42             : 
      43             : using namespace padmin;
      44             : using namespace psp;
      45             : using namespace osl;
      46             : 
      47             : 
      48           0 : PPDImportDialog::PPDImportDialog( Window* pParent ) :
      49             :         ModalDialog( pParent, PaResId( RID_PPDIMPORT_DLG ) ),
      50             :         m_aOKBtn( this, PaResId( RID_PPDIMP_BTN_OK ) ),
      51             :         m_aCancelBtn( this, PaResId( RID_PPDIMP_BTN_CANCEL ) ),
      52             :         m_aPathTxt( this, PaResId( RID_PPDIMP_TXT_PATH ) ),
      53             :         m_aPathBox( this, PaResId( RID_PPDIMP_LB_PATH ) ),
      54             :         m_aSearchBtn( this, PaResId( RID_PPDIMP_BTN_SEARCH ) ),
      55             :         m_aDriverTxt( this, PaResId( RID_PPDIMP_TXT_DRIVER ) ),
      56             :         m_aDriverLB( this, PaResId( RID_PPDIMP_LB_DRIVER ) ),
      57             :         m_aPathGroup( this, PaResId( RID_PPDIMP_GROUP_PATH ) ),
      58             :         m_aDriverGroup( this, PaResId( RID_PPDIMP_GROUP_DRIVER ) ),
      59           0 :         m_aLoadingPPD( PaResId( RID_PPDIMP_STR_LOADINGPPD ) )
      60             : {
      61           0 :     FreeResource();
      62             : 
      63           0 :     String aText( m_aDriverTxt.GetText() );
      64           0 :     aText.SearchAndReplaceAscii( "%s", Button::GetStandardText( BUTTON_OK ) );
      65           0 :     m_aDriverTxt.SetText( MnemonicGenerator::EraseAllMnemonicChars( aText ) );
      66             : 
      67           0 :     Config& rConfig = getPadminRC();
      68           0 :     rConfig.SetGroup( PPDIMPORT_GROUP );
      69           0 :     m_aPathBox.SetText( OStringToOUString(rConfig.ReadKey("LastDir"), RTL_TEXTENCODING_UTF8) );
      70           0 :     for (sal_Int32 i = 0; i < 11; ++i)
      71             :     {
      72           0 :         OString aEntry(rConfig.ReadKey(OString::valueOf(i)));
      73           0 :         if (!aEntry.isEmpty())
      74           0 :             m_aPathBox.InsertEntry(OStringToOUString(aEntry, RTL_TEXTENCODING_UTF8));
      75           0 :     }
      76             : 
      77           0 :     m_aOKBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
      78           0 :     m_aCancelBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
      79           0 :     m_aSearchBtn.SetClickHdl( LINK( this, PPDImportDialog, ClickBtnHdl ) );
      80           0 :     m_aPathBox.SetSelectHdl( LINK( this, PPDImportDialog, SelectHdl ) );
      81           0 :     m_aPathBox.SetModifyHdl( LINK( this, PPDImportDialog, ModifyHdl ) );
      82             : 
      83           0 :     if( !m_aPathBox.GetText().isEmpty() )
      84           0 :         Import();
      85           0 : }
      86             : 
      87           0 : PPDImportDialog::~PPDImportDialog()
      88             : {
      89           0 :     while( m_aDriverLB.GetEntryCount() )
      90             :     {
      91           0 :         delete (String*)m_aDriverLB.GetEntryData( 0 );
      92           0 :         m_aDriverLB.RemoveEntry( 0 );
      93             :     }
      94           0 : }
      95             : 
      96           0 : void PPDImportDialog::Import()
      97             : {
      98           0 :     OUString aImportPath( m_aPathBox.GetText() );
      99             : 
     100           0 :     Config& rConfig = getPadminRC();
     101           0 :     rConfig.SetGroup( PPDIMPORT_GROUP );
     102           0 :     rConfig.WriteKey( "LastDir", OUStringToOString(aImportPath, RTL_TEXTENCODING_UTF8) );
     103             : 
     104           0 :     int nEntries = m_aPathBox.GetEntryCount();
     105           0 :     while( nEntries-- )
     106           0 :         if( aImportPath == m_aPathBox.GetEntry( nEntries ) )
     107           0 :             break;
     108           0 :     if( nEntries < 0 )
     109             :     {
     110           0 :         sal_Int32 nNextEntry = rConfig.ReadKey("NextEntry").toInt32();
     111           0 :         rConfig.WriteKey( OString::valueOf(nNextEntry), OUStringToOString(aImportPath, RTL_TEXTENCODING_UTF8) );
     112           0 :         nNextEntry = nNextEntry < 10 ? nNextEntry+1 : 0;
     113           0 :         rConfig.WriteKey( "NextEntry", OString::valueOf(nNextEntry) );
     114           0 :         m_aPathBox.InsertEntry( aImportPath );
     115             :     }
     116           0 :     while( m_aDriverLB.GetEntryCount() )
     117             :     {
     118           0 :         delete (String*)m_aDriverLB.GetEntryData( 0 );
     119           0 :         m_aDriverLB.RemoveEntry( 0 );
     120             :     }
     121             : 
     122           0 :     ProgressDialog aProgress( Application::GetFocusWindow() );
     123           0 :     aProgress.startOperation( m_aLoadingPPD );
     124             : 
     125           0 :     ::std::list< String > aFiles;
     126           0 :     FindFiles( aImportPath, aFiles, OUString( "PS;PPD;PS.GZ;PPD.GZ" ), true );
     127             : 
     128           0 :     int i = 0;
     129           0 :     aProgress.setRange( 0, aFiles.size() );
     130           0 :     while( !aFiles.empty() )
     131             :     {
     132           0 :         aProgress.setValue( ++i );
     133           0 :         aProgress.setFilename( aFiles.front() );
     134           0 :         INetURLObject aPath( aImportPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
     135           0 :         aPath.Append( aFiles.front() );
     136           0 :         String aPrinterName = PPDParser::getPPDPrinterName( aPath.PathToFileName() );
     137           0 :         aFiles.pop_front();
     138             : 
     139           0 :         if( ! aPrinterName.Len() )
     140             :         {
     141             : #if OSL_DEBUG_LEVEL > 1
     142             :             fprintf( stderr, "Warning: File %s has empty printer name.\n",
     143             :                      OUStringToOString( aPath.PathToFileName(), osl_getThreadTextEncoding() ).getStr() );
     144             : #endif
     145           0 :             continue;
     146             :         }
     147             : 
     148           0 :         sal_uInt16 nPos = m_aDriverLB.InsertEntry( aPrinterName );
     149           0 :         m_aDriverLB.SetEntryData( nPos, new String( aPath.PathToFileName() ) );
     150           0 :     }
     151           0 : }
     152             : 
     153           0 : IMPL_LINK( PPDImportDialog, ClickBtnHdl, PushButton*, pButton )
     154             : {
     155           0 :     if( pButton == &m_aCancelBtn )
     156             :     {
     157           0 :         EndDialog( 0 );
     158             :     }
     159           0 :     else if( pButton == &m_aOKBtn )
     160             :     {
     161             :         // copy the files
     162           0 :         ::std::list< OUString > aToDirs;
     163           0 :         psp::getPrinterPathList( aToDirs, PRINTER_PPDDIR );
     164           0 :         ::std::list< OUString >::iterator writeDir = aToDirs.begin();
     165           0 :         m_aImportedFiles.clear();
     166             : 
     167           0 :         for( int i = 0; i < m_aDriverLB.GetSelectEntryCount(); i++ )
     168             :         {
     169             :             INetURLObject aFile( *(String*)m_aDriverLB.GetEntryData(
     170           0 :                 m_aDriverLB.GetSelectEntryPos( i )
     171           0 :                 ), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
     172           0 :             OUString aFromUni( aFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );
     173             : 
     174           0 :             do
     175             :             {
     176           0 :                 INetURLObject aToFile( *writeDir, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
     177           0 :                 aToFile.Append( aFile.GetName() );
     178           0 :                 OUString aToUni( aToFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );
     179           0 :                 if( ! File::copy( aFromUni, aToUni ) )
     180             :                 {
     181           0 :                     m_aImportedFiles.push_back( aToUni );
     182           0 :                     break;
     183             :                 }
     184           0 :                 ++writeDir;
     185           0 :             } while( writeDir != aToDirs.end() );
     186           0 :         }
     187           0 :         EndDialog( 1 );
     188             :     }
     189           0 :     else if( pButton == &m_aSearchBtn )
     190             :     {
     191           0 :         OUString aPath( m_aPathBox.GetText() );
     192           0 :         if( chooseDirectory( aPath ) )
     193             :         {
     194           0 :             m_aPathBox.SetText( aPath );
     195           0 :             Import();
     196           0 :         }
     197             :     }
     198           0 :     return 0;
     199             : }
     200             : 
     201           0 : IMPL_LINK( PPDImportDialog, SelectHdl, ComboBox*, pListBox )
     202             : {
     203           0 :     if( pListBox == &m_aPathBox )
     204             :     {
     205           0 :         Import();
     206             :     }
     207           0 :     return 0;
     208             : }
     209             : 
     210           0 : IMPL_LINK( PPDImportDialog, ModifyHdl, ComboBox*, pListBox )
     211             : {
     212           0 :     if( pListBox == &m_aPathBox )
     213             :     {
     214           0 :         OString aDir(OUStringToOString(m_aPathBox.GetText(), osl_getThreadTextEncoding()));
     215           0 :         if (!access( aDir.getStr(), F_OK))
     216           0 :             Import();
     217             :     }
     218           0 :     return 0;
     219           0 : }
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10