drop spadmin

Change-Id: Ie10ee80f1d35b40c0baf9d7ba5c1181b52405b5f
diff --git a/Repository.mk b/Repository.mk
index eb7a55f..4e1e379 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -86,7 +86,6 @@ $(eval $(call gb_Helper_register_executables,OOO, \
	$(if $(filter-out ANDROID IOS MACOSX WNT,$(OS)),oosplash) \
	$(if $(ENABLE_NPAPI_FROM_BROWSER),pluginapp.bin) \
	soffice_bin \
	spadmin.bin \
	$(if $(filter $(GUIBASE)$(ENABLE_GTK),unxTRUE), \
		xid-fullscreen-on-all-monitors \
	) \
diff --git a/bin/distro-install-desktop-integration b/bin/distro-install-desktop-integration
index 0379ffa..18107e0 100755
--- a/bin/distro-install-desktop-integration
+++ b/bin/distro-install-desktop-integration
@@ -121,8 +121,6 @@ cd -
rm -rf $sysui_temp

# we do not want some stuff from the plain packages
rm -f $DESTDIR/$PREFIXDIR/bin/$INSTALLDIRNAME-printeradmin
rm -f $DESTDIR$PREFIXDIR/share/applications/libreoffice-printeradmin.desktop
if test -d $DESTDIR/opt ; then
    rm -f $DESTDIR/opt/$INSTALLDIRNAME
    rmdir --ignore-fail-on-non-empty $DESTDIR/opt
diff --git a/bin/distro-install-file-lists b/bin/distro-install-file-lists
index b0d962ac..ada7295 100755
--- a/bin/distro-install-file-lists
+++ b/bin/distro-install-file-lists
@@ -343,7 +343,6 @@ if test "z$OOO_VENDOR" != "zDebian" ; then
            program/pluginapp.bin \
            program/setofficelang.bin \
            program/soffice.bin \
            program/spadmin.bin \
            program/uno.bin \
            program/unopkg.bin \
            program/uri-encode
diff --git a/extras/Module_extras.mk b/extras/Module_extras.mk
index a2c25b4..5b5678a 100644
--- a/extras/Module_extras.mk
+++ b/extras/Module_extras.mk
@@ -14,7 +14,6 @@ $(eval $(call gb_Module_add_targets,extras,\
	CustomTarget_glade \
	Package_autocorr \
	Package_autotextuser \
	Package_cfgsrvbitmapunx \
	Package_cfgsrvnolang \
	Package_cfgusr \
	Package_database \
diff --git a/extras/Package_cfgsrvbitmapunx.mk b/extras/Package_cfgsrvbitmapunx.mk
deleted file mode 100644
index 250b7c1..0000000
--- a/extras/Package_cfgsrvbitmapunx.mk
+++ /dev/null
@@ -1,17 +0,0 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call gb_Package_Package,extras_cfgsrvbitmapunx,$(SRCDIR)/extras/unx/source/bitmaps))

$(eval $(call gb_Package_add_files,extras_cfgsrvbitmapunx,$(LIBO_SHARE_FOLDER)/config,\
	psetupl.xpm \
	psetup.xpm \
))

# vim: set noet sw=4 ts=4:
diff --git a/extras/unx/source/bitmaps/psetup.xpm b/extras/unx/source/bitmaps/psetup.xpm
deleted file mode 100644
index f512975..0000000
--- a/extras/unx/source/bitmaps/psetup.xpm
+++ /dev/null
@@ -1,31 +0,0 @@
/* XPM */
static char * L3PSetup_t_pm[] = {
/* width height ncolors cpp [x_hot y_hot] */
"16 16 9 1 0 0",
/* colors */
" 	s none	m none	c none",
".	c #861782078617",
"X	s iconColor1	m black	c black",
"o	c #000000008617",
"O	s iconColor2	m white	c white",
"+	c #C71BC30BC71B",
"@	s iconColor6	m white	c yellow",
"#	c #00000000FFFF",
"$	c #861700000000",
/* pixels */
"                ",
"     ..  XXXXX o",
"   ..OO+XO.OO@Xo",
" ..OOOOX@.@.OOOo",
"XXOOOOXOXO.O.@Oo",
"  XOOX@XOX@.OXXo",
"   XOOXOO+XXX  o",
" XX+XOO..+++O+. ",
"X.++X..+++##++O.",
"X...++++$$++OOO.",
"X.....++++OO++O.",
"X.......OO++++..",
"XX......+++++.X.",
"  XX....+++.XX  ",
"    XX..+.XX    ",
"      XXXX      "};
diff --git a/extras/unx/source/bitmaps/psetupl.xpm b/extras/unx/source/bitmaps/psetupl.xpm
deleted file mode 100644
index f9cca89..0000000
--- a/extras/unx/source/bitmaps/psetupl.xpm
+++ /dev/null
@@ -1,49 +0,0 @@
/* XPM */
static char * L3PSetup_m_pm[] = {
/* width height ncolors cpp [x_hot y_hot] */
"32 32 11 1 0 0",
/* colors */
" 	s none	m none	c none",
".	s iconColor1	m black	c black",
"X	c #000000008617",
"o	c #861782078617",
"O	s iconColor2	m white	c white",
"+	c #C71BC30BC71B",
"@	s iconColor6	m white	c yellow",
"#	c #00000000FFFF",
"$	c #861782070000",
"%	c #000082078617",
"&	c #861700000000",
/* pixels */
"                                ",
"                  ........  XXXX",
"           .o..oo.OOOOOOO+..X+OX",
"          .+ooOO.@OO@OOOO@OOXOOX",
"         .+oo+O.OO.OOOOOOOOOXXXX",
"        .+oo+O.O@.OOO@OOOO@OXXXX",
"       .+oo+O.@O.O@O.OO@OOOOXXXX",
"      .+oo+O.OO.+.O.OOOOOOOOXXXX",
"     .+oo+O.O@.+O+.O@O.OOO..X.X.",
"    .+oo+O+...+O++o.O.OO@.  .X. ",
"   .+oo+O+O+O+O++++o.@O..o  ... ",
"  .ooo+O+O+O+O++++ooo..         ",
" .ooo+O+O+O+O++++o..+Oo         ",
" .oo+O+O+O+O++++o....OO.        ",
" ..+O+O+O+O++++o......OO.       ",
" .o+OO+O+O++#+o....$o..OO.      ",
" .oo+OO+O++%+o....$$$...Oo.     ",
" .ooo+OO++&+o...$$$+$+...o.     ",
" .oooo+O+++o...$$$+$+++..o.     ",
" .oooooOO+o.o.$$++$+OoOO..o     ",
" .ooooo+Oo..O.$++$OOoOO$O.o     ",
"o.ooooooO.o.OO.+$OOoOOoOOO.     ",
"oo.ooooo.O.O.OO.OOoOO$OOoOO.    ",
" oo.oooo+O.OO.OO.OOOoOOoOO.o    ",
"  oo.ooo+O.oOo.Oo.O$OO$OO.o     ",
"   oo.oo+O.o+o.+o.OOOoOO.o      ",
"    oo.o+O.o+o.+o.OOoOO.o       ",
"     oo.+..o+o.+o..OOO.o        ",
"      oo.oo.+..+o.o.O.o         ",
"       ooooo.o.o.ooo.o          ",
"           oooo.o  oo           ",
"              oo                "};
diff --git a/include/tools/config.hxx b/include/tools/config.hxx
index 751114d..0b472b9 100644
--- a/include/tools/config.hxx
+++ b/include/tools/config.hxx
@@ -53,7 +53,6 @@ public:
    bool HasGroup(const OString& rGroup) const;

    OString ReadKey(const OString& rKey) const;
    OUString ReadKey(const OString& rKey, rtl_TextEncoding eEncoding) const;
    OString ReadKey(const OString& rKey, const OString& rDefault) const;
    void                WriteKey(const OString& rKey, const OString& rValue);
    void DeleteKey(const OString& rKey);
diff --git a/include/vcl/ppdparser.hxx b/include/vcl/ppdparser.hxx
index a4df86d..9ac90ce 100644
--- a/include/vcl/ppdparser.hxx
+++ b/include/vcl/ppdparser.hxx
@@ -190,9 +190,7 @@ private:
    static OUString getPPDFile( const OUString& rFile );
public:
    static const PPDParser* getParser( const OUString& rFile );
    static OUString getPPDPrinterName( const OUString& rFile );
    static void freeAll();
    static void getKnownPPDDrivers( std::list< OUString >& o_rDrivers, bool bRefresh = false );

    const OUString& getFilename() const { return m_aFile; }

diff --git a/padmin/AllLangResTarget_spa.mk b/padmin/AllLangResTarget_spa.mk
index 12eab22..31d2608 100644
--- a/padmin/AllLangResTarget_spa.mk
+++ b/padmin/AllLangResTarget_spa.mk
@@ -28,7 +28,6 @@ $(eval $(call gb_AllLangResTarget_add_srs,spa,\
$(eval $(call gb_SrsTarget_SrsTarget,padmin/source))

$(eval $(call gb_SrsTarget_add_files,padmin/source,\
    padmin/source/padialog.src \
    padmin/source/rtsetup.src \
))

diff --git a/padmin/Executable_spadmin.bin.mk b/padmin/Executable_spadmin.bin.mk
deleted file mode 100644
index 5ea6a3a..0000000
--- a/padmin/Executable_spadmin.bin.mk
+++ /dev/null
@@ -1,61 +0,0 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements. See the NOTICE file distributed
#   with this work for additional information regarding copyright
#   ownership. The ASF licenses this file to you under the Apache
#   License, Version 2.0 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
#

$(eval $(call gb_Executable_Executable,spadmin.bin))

$(eval $(call gb_Executable_use_external,spadmin.bin,boost_headers))

$(eval $(call gb_Executable_use_static_libraries,spadmin.bin,\
    vclmain \
))

$(eval $(call gb_Executable_use_sdk_api,spadmin.bin))

$(eval $(call gb_Executable_use_libraries,spadmin.bin,\
    spa \
    svt \
    vcl \
    utl \
    ucbhelper \
    comphelper \
    tl \
    cppuhelper \
    cppu \
    sal \
	$(gb_UWINAPI) \
))

$(eval $(call gb_Executable_add_exception_objects,spadmin.bin,\
    padmin/source/desktopcontext \
    padmin/source/pamain \
))

ifneq (,$(filter LINUX DRAGONFLY OPENBSD FREEBSD NETBSD, $(OS)))
$(eval $(call gb_Executable_add_libs,spadmin.bin,\
    -lpthread \
))
endif

ifeq ($(OS),LINUX)
$(eval $(call gb_Executable_add_libs,spadmin.bin,\
    -ldl \
))
endif

# vim: set noet sw=4 ts=4:
diff --git a/padmin/Library_spa.mk b/padmin/Library_spa.mk
index c4588a5..57961cd 100644
--- a/padmin/Library_spa.mk
+++ b/padmin/Library_spa.mk
@@ -45,14 +45,8 @@ $(eval $(call gb_Library_use_libraries,spa,\
))

$(eval $(call gb_Library_add_exception_objects,spa,\
    padmin/source/adddlg \
    padmin/source/cmddlg \
    padmin/source/helper \
    padmin/source/newppdlg \
    padmin/source/padialog \
    padmin/source/progress \
    padmin/source/prtsetup \
    padmin/source/titlectrl \
))

ifneq (,$(filter LINUX DRAGONFLY OPENBSD FREEBSD NETBSD, $(OS)))
diff --git a/padmin/Module_padmin.mk b/padmin/Module_padmin.mk
index 45db7aa..6ea23d9 100644
--- a/padmin/Module_padmin.mk
+++ b/padmin/Module_padmin.mk
@@ -23,9 +23,7 @@ $(eval $(call gb_Module_Module,padmin))
ifeq ($(GUIBASE),unx)

$(eval $(call gb_Module_add_targets,padmin,\
    Executable_spadmin.bin \
    Library_spa \
    Package_padmin \
))

$(eval $(call gb_Module_add_l10n_targets,padmin,\
diff --git a/padmin/Package_padmin.mk b/padmin/Package_padmin.mk
deleted file mode 100644
index e706f3f..0000000
--- a/padmin/Package_padmin.mk
+++ /dev/null
@@ -1,24 +0,0 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements. See the NOTICE file distributed
#   with this work for additional information regarding copyright
#   ownership. The ASF licenses this file to you under the Apache
#   License, Version 2.0 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
#

$(eval $(call gb_Package_Package,padmin,$(SRCDIR)/padmin/source))

$(eval $(call gb_Package_add_file,padmin,$(LIBO_BIN_FOLDER)/spadmin,spadmin.sh))

# vim: set noet sw=4 ts=4:
diff --git a/padmin/source/adddlg.cxx b/padmin/source/adddlg.cxx
deleted file mode 100644
index 7e775df..0000000
--- a/padmin/source/adddlg.cxx
+++ /dev/null
@@ -1,661 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <unistd.h>

#include "adddlg.hxx"
#include "newppdlg.hxx"
#include "cmddlg.hxx"
#include "padialog.hrc"

#include "vcl/msgbox.hxx"
#include "vcl/strhelper.hxx"
#include <vcl/settings.hxx>

#include <tools/config.hxx>
#include <osl/thread.h>
#include <rtl/strbuf.hxx>
#include <boost/unordered_set.hpp>

using namespace psp;
using namespace padmin;
using namespace std;



APTabPage::APTabPage( AddPrinterDialog* pParent, const ResId& rResId )
            : TabPage( pParent, rResId ),
              m_aTitle( PaResId( RID_ADDP_STR_TITLE ) ),
              m_pParent( pParent )
{
}

APChooseDriverPage::APChooseDriverPage( AddPrinterDialog* pParent )
        : APTabPage( pParent, PaResId( RID_ADDP_PAGE_CHOOSEDRIVER ) ),
          m_aDriverTxt( this, PaResId( RID_ADDP_CHDRV_TXT_DRIVER ) ),
          m_aDriverBox( this, PaResId( RID_ADDP_CHDRV_BOX_DRIVER ) ),
          m_aAddBtn( this, PaResId( RID_ADDP_CHDRV_BTN_ADD ) ),
          m_aRemBtn( this, PaResId( RID_ADDP_CHDRV_BTN_REMOVE ) ),
          m_aRemStr( PaResId( RID_ADDP_CHDRV_STR_REMOVE ) )
{
    FreeResource();
    m_aAddBtn.SetClickHdl( LINK( this, APChooseDriverPage, ClickBtnHdl ) );
    m_aRemBtn.SetClickHdl( LINK( this, APChooseDriverPage, ClickBtnHdl ) );
    m_aDriverBox.setDelPressedLink( LINK( this, APChooseDriverPage, DelPressedHdl ) );
    updateDrivers();
}

APChooseDriverPage::~APChooseDriverPage()
{
    for( int i = 0; i < m_aDriverBox.GetEntryCount(); i++ )
        delete (OUString*)m_aDriverBox.GetEntryData( i );
}

bool APChooseDriverPage::check()
{
    return m_aDriverBox.GetSelectEntryCount() > 0;
}

void APChooseDriverPage::fill( PrinterInfo& rInfo )
{
    sal_uInt16 nPos = m_aDriverBox.GetSelectEntryPos();
    OUString* pDriver = (OUString*)m_aDriverBox.GetEntryData( nPos );
    rInfo.m_aDriverName = *pDriver;
#if OSL_DEBUG_LEVEL > 1
    fprintf( stderr, "m_aLastPrinterName = \"%s\", rInfo.m_aPrinterName = \"%s\"\n",
             OUStringToOString( m_aLastPrinterName, RTL_TEXTENCODING_ISO_8859_1 ).getStr(),
             OUStringToOString( rInfo.m_aPrinterName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
#endif
    if( rInfo.m_aPrinterName.equals( m_aLastPrinterName ) )
    {
        OUString aPrinter( AddPrinterDialog::uniquePrinterName( m_aDriverBox.GetEntry( nPos ) ) );
        rInfo.m_aPrinterName = m_aLastPrinterName = aPrinter;
    }
}

void APChooseDriverPage::updateDrivers( bool bRefresh, const OUString& rSelectDriver )
{
    for( int k = 0; k < m_aDriverBox.GetEntryCount(); k++ )
        delete (OUString*)m_aDriverBox.GetEntryData( k );
    m_aDriverBox.Clear();

    std::list< OUString > aDrivers;
    psp::PPDParser::getKnownPPDDrivers( aDrivers, bRefresh );

    OUString aSelectDriver( psp::PPDParser::getPPDPrinterName( rSelectDriver ) );

    OUString aSelectedEntry;
    for( std::list< OUString >::const_iterator it = aDrivers.begin(); it != aDrivers.end(); ++it )
    {
        OUString aDriver( psp::PPDParser::getPPDPrinterName( *it ) );
        if( !aDriver.isEmpty() )
        {
            int nPos = m_aDriverBox.InsertEntry( aDriver );
            m_aDriverBox.SetEntryData( nPos, new OUString( *it ) );
            if( aDriver == aSelectDriver )
                aSelectedEntry = aDriver;
        }
    }

    m_aDriverBox.SelectEntry( aSelectedEntry );
    m_aRemBtn.Enable( m_aDriverBox.GetEntryCount() > 0 );
}

IMPL_LINK( APChooseDriverPage, DelPressedHdl, ListBox*, pListBox )
{
    if( pListBox == &m_aDriverBox )
        ClickBtnHdl( &m_aRemBtn );

    return 0;
}

IMPL_LINK( APChooseDriverPage, ClickBtnHdl, PushButton*, pButton )
{
    if( pButton == &m_aAddBtn )
    {
        PPDImportDialog aDlg( this );
        if( aDlg.Execute() )
        {
            const std::list< OUString >& rImported( aDlg.getImportedFiles() );
            if( rImported.empty() )
                updateDrivers( true );
            else
                updateDrivers( true, rImported.front() );
        }
    }
    else if( pButton == &m_aRemBtn )
    {
        rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
        PrinterInfoManager& rPIManager( PrinterInfoManager::get() );

        for( int i = 0; i < m_aDriverBox.GetSelectEntryCount(); i++ )
        {
            int nSelect = m_aDriverBox.GetSelectEntryPos(i);
            OUString aDriver( *(OUString*)m_aDriverBox.GetEntryData( nSelect ) );
            if( !aDriver.isEmpty() )
            {
                // never delete the default driver
                if( aDriver.equalsIgnoreAsciiCase( "SGENPRT" ) )
                {
                    OUString aText( PaResId( RID_ERR_REMOVESGENPRT ) );
                    aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
                    ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
                    aErrorBox.SetText( m_aRemStr );
                    aErrorBox.Execute();
                    continue;
                }

                PrinterInfo aDefInfo( rPIManager.getPrinterInfo( rPIManager.getDefaultPrinter() ) );
                // for comparisons convert to a OUString
                OUString aPPD( aDriver );
                if( aDefInfo.m_aDriverName == aPPD )
                {
                    OUString aText( PaResId( RID_ERR_REMOVEDEFAULTDRIVER ) );
                    aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
                    ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
                    aErrorBox.SetText( m_aRemStr );
                    aErrorBox.Execute();
                    continue;
                }

                ::std::list< OUString > aPrinters;
                ::std::list< OUString >::iterator it;
                rPIManager.listPrinters( aPrinters );
                for( it = aPrinters.begin(); it != aPrinters.end(); ++it )
                {
                    PrinterInfo aInfo( rPIManager.getPrinterInfo( *it ) );
                    if( aInfo.m_aDriverName == aPPD )
                        break;
                }

                if( it != aPrinters.end() )
                {
                    OUString aText( PaResId( RID_QUERY_DRIVERUSED ) );
                    aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
                    QueryBox aBox( this, WB_YES_NO | WB_DEF_NO, aText );
                    aBox.SetText( m_aRemStr );
                    if( aBox.Execute() == RET_NO )
                        continue;
                }
                else
                {
                    OUString aText( PaResId( RID_QUERY_REMOVEDRIVER ) );
                    aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
                    QueryBox aBox( this, WB_YES_NO | WB_DEF_NO, aText );
                    aBox.SetText( m_aRemStr );
                    if( aBox.Execute() == RET_NO )
                        continue;
                }

                // remove the printers using this driver
                for( it = aPrinters.begin(); it != aPrinters.end(); ++it )
                {
                    PrinterInfo aInfo( rPIManager.getPrinterInfo( *it ) );
                    if( aInfo.m_aDriverName == aPPD )
                        rPIManager.removePrinter( *it );
                }

                std::list< OUString > aDirs;
                // get only psprint's directories, not eventual system dirs
                psp::getPrinterPathList( aDirs, NULL );
                std::list< OUString >::iterator dir;
                for( dir = aDirs.begin(); dir != aDirs.end(); ++dir )
                {
                    ::std::list< OUString > aFiles;
                    ::std::list< OUString >::iterator file;
                    OUStringBuffer aDir( *dir );
                    aDir.append( '/' );
                    aDir.appendAscii( PRINTER_PPDDIR );
                    OUString aPPDDir( aDir.makeStringAndClear() );
                    FindFiles( aPPDDir, aFiles, OUString(  "PS;PPD;PS.GZ;PPD.GZ"  ), true );
                    for( file = aFiles.begin(); file != aFiles.end(); ++file )
                    {
                        OUString aFile( aPPDDir );
                        if( !aFile.endsWith( "/" ) )
                            aFile += "/";
                        aFile += *file;

                        sal_Int32 nPos = file->lastIndexOf( '.' );
                        OUString sCopy = nPos == -1 ? *file : file->copy(0, nPos);
                        if( sCopy == aPPD )
                        {
                            OString aSysPath(OUStringToOString(aFile, aEncoding));
                            if (unlink(aSysPath.getStr()))
                            {
                                OUString aText( PaResId( RID_ERR_REMOVEDRIVERFAILED ) );
                                aText = aText.replaceFirst( OUString( "%s1" ), m_aDriverBox.GetSelectEntry( i ) );
                                aText = aText.replaceFirst( OUString( "%s2" ), aFile );
                                ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
                                aErrorBox.SetText( m_aRemStr );
                                aErrorBox.Execute();
                            }
                        }
                    }
                }
            }
        }
        updateDrivers();
    }
    return 0;
}



APNamePage::APNamePage( AddPrinterDialog* pParent, const OUString& rInitName, DeviceKind::type eKind )
        : APTabPage( pParent, PaResId( RID_ADDP_PAGE_NAME ) ),
          m_aNameTxt(
                     this,
                     PaResId(
                             eKind == DeviceKind::Printer ? RID_ADDP_NAME_TXT_NAME : RID_ADDP_NAME_TXT_PDFNAME
                             )
                     ),
          m_aNameEdt(
                     this,
                     PaResId(
                             eKind == DeviceKind::Printer ? RID_ADDP_NAME_EDT_NAME : RID_ADDP_NAME_EDT_PDFNAME
                             )
                     ),
          m_aDefaultBox( this, PaResId( RID_ADDP_NAME_BOX_DEFAULT ) )
{
    FreeResource();
    if( eKind != DeviceKind::Printer )
        m_aDefaultBox.Show( false );
    else
        m_aNameEdt.SetText( rInitName );

    m_aNameEdt.SetText( AddPrinterDialog::uniquePrinterName( m_aNameEdt.GetText() ) );
    m_aDefaultBox.Check( false );
}

APNamePage::~APNamePage()
{
}

bool APNamePage::check()
{
    return !m_aNameEdt.GetText().isEmpty();
}

void APNamePage::fill( PrinterInfo& rInfo )
{
    rInfo.m_aPrinterName = m_aNameEdt.GetText();
}



APCommandPage::APCommandPage( AddPrinterDialog* pParent, DeviceKind::type eKind )
        : APTabPage( pParent, PaResId( RID_ADDP_PAGE_COMMAND ) ),
          m_aCommandTxt( this, PaResId( RID_ADDP_CMD_TXT_COMMAND ) ),
          m_aCommandBox( this, PaResId( eKind == DeviceKind::Pdf ? RID_ADDP_CMD_BOX_PDFCOMMAND : RID_ADDP_CMD_BOX_COMMAND ) ),
          m_aHelpBtn( this, PaResId( RID_ADDP_CMD_BTN_HELP ) ),
          m_aHelpTxt( PaResId( RID_ADDP_CMD_STR_PDFHELP ) ),
          m_aPdfDirTxt( this, PaResId( RID_ADDP_CMD_TXT_PDFDIR ) ),
          m_aPdfDirEdt( this, PaResId( RID_ADDP_CMD_EDT_PDFDIR ) ),
          m_aPdfDirBtn( this, PaResId( RID_ADDP_CMD_BTN_PDFDIR ) ),
          m_eKind( eKind )
{
    FreeResource();
    ::std::list< OUString > aCommands;
    if( m_eKind == DeviceKind::Printer )
    {
        m_aHelpBtn.Show( false );
        Size aSize = m_aCommandTxt.GetSizePixel();
        aSize.Width() = m_aCommandBox.GetSizePixel().Width();
        m_aCommandTxt.SetSizePixel( aSize );
    }
    if( m_eKind != DeviceKind::Pdf )
    {
        m_aPdfDirBtn.Show( false );
        m_aPdfDirEdt.Show( false );
        m_aPdfDirTxt.Show( false );
    }
    switch( m_eKind )
    {
        case DeviceKind::Printer:   CommandStore::getPrintCommands( aCommands );break;
        case DeviceKind::Pdf:       CommandStore::getPdfCommands( aCommands );break;
    }
    // adjust height of command text and help button
    Rectangle aPosSize( m_aCommandTxt.GetPosPixel(), m_aCommandTxt.GetSizePixel() );
    Rectangle aTextSize = m_aCommandTxt.GetTextRect( Rectangle( Point(), aPosSize.GetSize() ), m_aCommandTxt.GetText() );
    if( aTextSize.GetWidth() <= 2*(aPosSize.GetWidth()+1) )
    {
        Size aNewSize( aPosSize.GetWidth(), aPosSize.GetHeight()*2/3 );
        if( aNewSize.Height() < m_aHelpBtn.GetSizePixel().Height()+2 )
            aNewSize.Height() = m_aHelpBtn.GetSizePixel().Height()+2;
        Point aNewPos( aPosSize.Left(), aPosSize.Top() + aPosSize.GetHeight() - aNewSize.Height() );
        m_aCommandTxt.SetPosSizePixel( aNewPos, aNewSize );
        aNewPos.X() = m_aHelpBtn.GetPosPixel().X();
        m_aHelpBtn.SetPosPixel( aNewPos );
    }

    // fill in commands
    ::std::list< OUString >::iterator it;
    for( it = aCommands.begin(); it != aCommands.end(); ++it )
        m_aCommandBox.InsertEntry( *it );

    m_aHelpBtn.SetClickHdl( LINK( this, APCommandPage, ClickBtnHdl ) );
    m_aPdfDirBtn.SetClickHdl( LINK( this, APCommandPage, ClickBtnHdl ) );
    if( m_eKind != DeviceKind::Printer )
    {
        m_aCommandBox.SetModifyHdl( LINK( this, APCommandPage, ModifyHdl ) );
        m_pParent->enableNext( false );
    }
}

APCommandPage::~APCommandPage()
{
    ::std::list< OUString > aCommands;
    OUString aLastCommand( m_aCommandBox.GetText() );
    for( int i = 0; i < m_aCommandBox.GetEntryCount(); i++ )
    {
        OUString aCommand( m_aCommandBox.GetEntry( i ) );
        if( aCommand != aLastCommand )
            aCommands.push_back( aCommand );
    }
    aCommands.push_back( aLastCommand );
    switch( m_eKind )
    {
        case DeviceKind::Printer:   CommandStore::setPrintCommands( aCommands );break;
        case DeviceKind::Pdf:       CommandStore::setPdfCommands( aCommands );break;
    }
}

IMPL_LINK( APCommandPage, ClickBtnHdl, PushButton*, pButton )
{
    if( pButton == &m_aHelpBtn )
    {
        InfoBox aBox( this, m_aHelpTxt );
        aBox.Execute();
    }
    else if( pButton == &m_aPdfDirBtn )
    {
        OUString aPath( m_aPdfDirEdt.GetText() );
        if( chooseDirectory( aPath ) )
            m_aPdfDirEdt.SetText( aPath );
    }
    return 0;
}

IMPL_LINK( APCommandPage, ModifyHdl, ComboBox*, pBox )
{
    if( pBox == &m_aCommandBox )
    {
        m_pParent->enableNext( !m_aCommandBox.GetText().isEmpty() );
    }
    return 0;
}

bool APCommandPage::check()
{
    return true;
}

void APCommandPage::fill( PrinterInfo& rInfo )
{
    rInfo.m_aCommand = m_aCommandBox.GetText();
}

APPdfDriverPage::APPdfDriverPage( AddPrinterDialog* pParent )
        : APTabPage( pParent, PaResId( RID_ADDP_PAGE_PDFDRIVER ) ),
          m_aPdfTxt( this, PaResId( RID_ADDP_PDFDRV_TXT_DRIVER ) ),
          m_aDefBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_DEFAULT ) ),
          m_aDistBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_DIST ) ),
          m_aSelectBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_SELECT ) )
{
    FreeResource();

    m_aDefBtn.Check( true );
    m_aDistBtn.Check( false );
    m_aSelectBtn.Check( false );
    m_aSelectBtn.SetStyle( m_aSelectBtn.GetStyle() | WB_WORDBREAK );
}

APPdfDriverPage::~APPdfDriverPage()
{
}

bool APPdfDriverPage::check()
{
    return true;
}

void APPdfDriverPage::fill( PrinterInfo& rInfo )
{
    if( isDefault() )
        rInfo.m_aDriverName = "SGENPRT";
    else if( isDist() )
        rInfo.m_aDriverName = "ADISTILL";
}



AddPrinterDialog::AddPrinterDialog( Window* pParent )
        : ModalDialog( pParent, PaResId( RID_ADD_PRINTER_DIALOG ) ),
          m_aCancelPB( this, PaResId( RID_ADDP_BTN_CANCEL ) ),
          m_aPrevPB( this, PaResId( RID_ADDP_BTN_PREV ) ),
          m_aNextPB( this, PaResId( RID_ADDP_BTN_NEXT ) ),
          m_aFinishPB( this, PaResId( RID_ADDP_BTN_FINISH ) ),
          m_aLine( this, PaResId( RID_ADDP_LINE ) ),
          m_aTitleImage( this, PaResId( RID_ADDP_CTRL_TITLE ) ),
          m_pCurrentPage( NULL ),
          m_pCommandPage( NULL ),
          m_pChooseDriverPage( NULL ),
          m_pNamePage( NULL ),
          m_pPdfDriverPage( NULL ),
          m_pPdfSelectDriverPage( NULL ),
          m_pPdfNamePage( NULL ),
          m_pPdfCommandPage( NULL )
{
    FreeResource();
    m_pCurrentPage = m_pPdfDriverPage = new APPdfDriverPage( this );

    m_pCurrentPage->Show( true );
    m_aFinishPB.Enable( false );
    m_aPrevPB.Enable( false );

    m_aNextPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
    m_aPrevPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
    m_aFinishPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
    m_aCancelPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );

    m_aTitleImage.SetBackgroundColor( Color( 0xff, 0xff, 0xff ) );
    m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
    updateSettings();
}

AddPrinterDialog::~AddPrinterDialog()
{
    delete m_pChooseDriverPage;
    delete m_pNamePage;
    delete m_pCommandPage;
    delete m_pPdfDriverPage;
    delete m_pPdfSelectDriverPage;
    delete m_pPdfNamePage;
    delete m_pPdfCommandPage;
}

void AddPrinterDialog::updateSettings()
{
    m_aTitleImage.SetImage( Image( BitmapEx( PaResId( RID_BMP_PRINTER ) ) ) );
}

void AddPrinterDialog::DataChanged( const DataChangedEvent& rEv )
{
    ModalDialog::DataChanged( rEv );
    if( (rEv.GetType() == DATACHANGED_SETTINGS) &&
        (rEv.GetFlags() & SETTINGS_STYLE) )
    {
        updateSettings();
    }
}

void AddPrinterDialog::advance()
{
    m_pCurrentPage->Show( false );
    if( m_pCurrentPage == m_pChooseDriverPage )
    {
        if( ! m_pCommandPage )
            m_pCommandPage = new APCommandPage( this, DeviceKind::Printer );
        m_pCurrentPage = m_pCommandPage;
    }
    else if( m_pCurrentPage == m_pCommandPage )
    {
        if( ! m_pNamePage )
            m_pNamePage = new APNamePage( this, m_aPrinter.m_aPrinterName, DeviceKind::Printer );
        else
            m_pNamePage->setText( m_aPrinter.m_aPrinterName );
        m_pCurrentPage = m_pNamePage;
        m_aFinishPB.Enable( true );
        m_aNextPB.Enable( false );
    }
    else if( m_pCurrentPage == m_pPdfDriverPage )
    {
        if( ! m_pPdfDriverPage->isDefault() && ! m_pPdfDriverPage->isDist() )
        {
            if( ! m_pPdfSelectDriverPage )
                m_pPdfSelectDriverPage = new APChooseDriverPage( this );
            m_pCurrentPage = m_pPdfSelectDriverPage;
        }
        else
        {
            if( ! m_pPdfCommandPage )
                m_pPdfCommandPage = new APCommandPage( this, DeviceKind::Pdf );
            m_pCurrentPage = m_pPdfCommandPage;
        }
        m_aPrevPB.Enable( true );
    }
    else if( m_pCurrentPage == m_pPdfSelectDriverPage )
    {
        if( ! m_pPdfCommandPage )
            m_pPdfCommandPage = new APCommandPage( this, DeviceKind::Pdf );
        m_pCurrentPage = m_pPdfCommandPage;
    }
    else if( m_pCurrentPage == m_pPdfCommandPage )
    {
        if( ! m_pPdfNamePage )
            m_pPdfNamePage = new APNamePage( this, OUString(), DeviceKind::Pdf );
        m_pCurrentPage = m_pPdfNamePage;
        m_aNextPB.Enable( false );
        m_aFinishPB.Enable( true );
    }

    m_pCurrentPage->Show( true );
    m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
}

void AddPrinterDialog::back()
{
    m_pCurrentPage->Show( false );
    if( m_pCurrentPage == m_pNamePage )
    {
        m_pCurrentPage = m_pCommandPage;
        m_aNextPB.Enable( true );
    }
    else if( m_pCurrentPage == m_pCommandPage )
    {
        m_pCurrentPage = m_pChooseDriverPage;
    }
    else if( m_pCurrentPage == m_pPdfSelectDriverPage )
    {
        m_pCurrentPage = m_pPdfDriverPage;
    }
    else if( m_pCurrentPage == m_pPdfNamePage )
    {
        m_pCurrentPage = m_pPdfCommandPage;
        m_aNextPB.Enable( true );
    }
    else if( m_pCurrentPage == m_pPdfCommandPage )
    {
        m_pCurrentPage = m_pPdfDriverPage->isDefault() || m_pPdfDriverPage->isDist() ? (APTabPage*)m_pPdfDriverPage : (APTabPage*)m_pPdfSelectDriverPage;
        m_aNextPB.Enable( true );
    }
    m_pCurrentPage->Show( true );
    m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
}

void AddPrinterDialog::addPrinter()
{
    PrinterInfoManager& rManager( PrinterInfoManager::get() );
    m_aPrinter.m_aPrinterName = uniquePrinterName( m_aPrinter.m_aPrinterName );
    if( rManager.addPrinter( m_aPrinter.m_aPrinterName, m_aPrinter.m_aDriverName ) )
    {
        PrinterInfo aInfo( rManager.getPrinterInfo( m_aPrinter.m_aPrinterName ) );
        aInfo.m_aCommand = m_aPrinter.m_aCommand;
        OUString aPdf( "pdf=" );
        aPdf += m_pPdfCommandPage->getPdfDir();
        aInfo.m_aFeatures = aPdf;
        rManager.changePrinterInfo( m_aPrinter.m_aPrinterName, aInfo );
    }
}

IMPL_LINK( AddPrinterDialog, ClickBtnHdl, PushButton*, pButton )
{
    if( pButton == &m_aNextPB )
    {
        if( m_pCurrentPage->check() )
        {
            m_pCurrentPage->fill( m_aPrinter );
            advance();
        }
    }
    else if( pButton == &m_aPrevPB )
    {
        if( m_pCurrentPage->check() )
            m_pCurrentPage->fill( m_aPrinter );
        back();
    }
    else if( pButton == &m_aFinishPB )
    {
        if( m_pCurrentPage->check() )
        {
            m_pCurrentPage->fill( m_aPrinter );
            addPrinter();
            PrinterInfoManager::get().writePrinterConfig();
            EndDialog( 1 );
        }
    }
    else if( pButton == &m_aCancelPB )
        EndDialog( 0 );

    return 0;
}

OUString AddPrinterDialog::uniquePrinterName( const OUString& rBase )
{
    OUString aResult( rBase );

    PrinterInfoManager& rManager( PrinterInfoManager::get() );

    sal_Int32 nVersion = 1;
    list< OUString > aPrinterList;
    rManager.listPrinters( aPrinterList );
    boost::unordered_set< OUString, OUStringHash > aPrinters;
    for( list< OUString >::const_iterator it = aPrinterList.begin(); it != aPrinterList.end(); ++it )
        aPrinters.insert( *it );
    while( aPrinters.find( aResult ) != aPrinters.end() )
    {
        aResult = rBase;
        aResult +=  "_"  ;
        aResult += OUString::number(nVersion++);
    }

    return aResult;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/adddlg.hxx b/padmin/source/adddlg.hxx
deleted file mode 100644
index c0b54e0..0000000
--- a/padmin/source/adddlg.hxx
+++ /dev/null
@@ -1,209 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_ADDDLG_HXX_
#define _PAD_ADDDLG_HXX_

#include "helper.hxx"
#include "titlectrl.hxx"

#include "vcl/dialog.hxx"
#include "vcl/tabpage.hxx"
#include "vcl/button.hxx"
#include "vcl/fixed.hxx"
#include "vcl/combobox.hxx"
#include "vcl/printerinfomanager.hxx"

namespace padmin
{

class AddPrinterDialog;

namespace DeviceKind { enum type { Printer, Pdf }; }

class APTabPage : public TabPage
{
    OUString            m_aTitle;
protected:
    AddPrinterDialog*   m_pParent;
public:
    APTabPage( AddPrinterDialog* pParent, const ResId& rResId );

    // returns false if information is incomplete or invalid
    virtual bool check() = 0;
    virtual void fill( ::psp::PrinterInfo& rInfo ) = 0;
    const OUString& getTitle() const { return m_aTitle; }
};

class APChooseDevicePage : public APTabPage
{
    RadioButton             m_aPDFBtn;
    FixedText               m_aOverTxt;
public:
    APChooseDevicePage( AddPrinterDialog* pParent );
    ~APChooseDevicePage();

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );
};

class APChooseDriverPage : public APTabPage
{
    FixedText               m_aDriverTxt;
    DelListBox              m_aDriverBox;
    PushButton              m_aAddBtn;
    PushButton              m_aRemBtn;

    OUString                m_aRemStr;
    OUString                m_aLastPrinterName;

    DECL_LINK( ClickBtnHdl, PushButton* );
    DECL_LINK( DelPressedHdl, ListBox* );

    void updateDrivers( bool bRefresh = false, const OUString& rSelectDriver = OUString( "SGENPRT" ) );
public:
    APChooseDriverPage( AddPrinterDialog* pParent );
    ~APChooseDriverPage();

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );
};

class APNamePage : public APTabPage
{
    FixedText               m_aNameTxt;
    Edit                    m_aNameEdt;
    CheckBox                m_aDefaultBox;
public:
    APNamePage( AddPrinterDialog* pParent, const OUString& rInitName, DeviceKind::type eKind );
    ~APNamePage();

    bool isDefault() { return m_aDefaultBox.IsChecked(); }

    void setText( const OUString& rText ) { m_aNameEdt.SetText( rText ); }

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );
};

class APCommandPage : public APTabPage
{
    FixedText               m_aCommandTxt;
    ComboBox                m_aCommandBox;
    PushButton              m_aHelpBtn;
    OUString                m_aHelpTxt;
    FixedText               m_aPdfDirTxt;
    Edit                    m_aPdfDirEdt;
    PushButton              m_aPdfDirBtn;

    DeviceKind::type        m_eKind;

    DECL_LINK( ClickBtnHdl, PushButton* );
    DECL_LINK( ModifyHdl, ComboBox* );
public:

    APCommandPage( AddPrinterDialog* pParent, DeviceKind::type eKind );
    ~APCommandPage();

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );

    OUString getPdfDir() { return m_aPdfDirEdt.GetText(); }
};

class APOldPrinterPage : public APTabPage
{
    FixedText                           m_aOldPrinterTxt;
    MultiListBox                        m_aOldPrinterBox;
    PushButton                          m_aSelectAllBtn;

    ::std::list< ::psp::PrinterInfo >   m_aOldPrinters;

    DECL_LINK( ClickBtnHdl, PushButton* );
public:
    APOldPrinterPage( AddPrinterDialog* pParent );
    ~APOldPrinterPage();

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );

    void addOldPrinters();
};

class APPdfDriverPage : public APTabPage
{
    FixedText               m_aPdfTxt;
    RadioButton             m_aDefBtn;
    RadioButton             m_aDistBtn;
    RadioButton             m_aSelectBtn;
public:
    APPdfDriverPage( AddPrinterDialog* pParent );
    ~APPdfDriverPage();

    virtual bool check();
    virtual void fill( ::psp::PrinterInfo& rInfo );

    bool isDefault() { return m_aDefBtn.IsChecked(); }
    bool isDist() { return m_aDistBtn.IsChecked(); }
};

class AddPrinterDialog : public ModalDialog
{
    CancelButton            m_aCancelPB;
    PushButton              m_aPrevPB;
    PushButton              m_aNextPB;
    OKButton                m_aFinishPB;
    FixedLine               m_aLine;
    TitleImage              m_aTitleImage;

    ::psp::PrinterInfo      m_aPrinter;

    APTabPage*              m_pCurrentPage;

    APCommandPage*          m_pCommandPage;
    APChooseDriverPage*     m_pChooseDriverPage;
    APNamePage*             m_pNamePage;
    APPdfDriverPage*        m_pPdfDriverPage;
    APChooseDriverPage*     m_pPdfSelectDriverPage;
    APNamePage*             m_pPdfNamePage;
    APCommandPage*          m_pPdfCommandPage;

    DECL_LINK( ClickBtnHdl, PushButton* );

    void advance();
    void back();
    void addPrinter();

    void updateSettings();
    virtual void DataChanged( const DataChangedEvent& rEv );

public:
    AddPrinterDialog( Window* pParent );
    ~AddPrinterDialog();

    static OUString uniquePrinterName( const OUString& rString );

    void enableNext( bool bEnable ) { m_aNextPB.Enable( bEnable ); }
};

} // namespace

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/cmddlg.cxx b/padmin/source/cmddlg.cxx
deleted file mode 100644
index 89908af..0000000
--- a/padmin/source/cmddlg.cxx
+++ /dev/null
@@ -1,468 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdio.h>
#include <tools/config.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <rtsetup.hrc>
#include <cmddlg.hxx>
#include <padialog.hxx>
#include <helper.hxx>
#include <prtsetup.hxx>

using namespace psp;
using namespace padmin;

#define PRINTER_PERSISTENCE_GROUP "KnownPrinterCommands"
#define PDF_PERSISTENCE_GROUP "KnowPdfCommands"
#define MAX_COMMANDS 50

void CommandStore::getSystemPrintCommands( ::std::list< OUString >& rCommands )
{
    static ::std::list< OUString > aSysCommands;
    static bool bOnce = false;
    if( ! bOnce )
    {
        bOnce = true;
        PrinterInfoManager::get().getSystemPrintCommands( aSysCommands );
    }

    ::std::list< OUString >::const_iterator it;
    for( it = aSysCommands.begin(); it != aSysCommands.end(); ++it )
        rCommands.push_back( *it );
}

void CommandStore::getSystemPdfCommands( ::std::list< OUString >& rCommands )
{
    static bool bOnce = false;
    static ::std::list< OUString > aSysCommands;

    if( ! bOnce )
    {
        bOnce = true;
        char pBuffer[1024];
        FILE* pPipe;
        OUString aCommand;
        rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();

        pPipe = popen( "which gs 2>/dev/null", "r" );
        if( pPipe )
        {
            if (fgets( pBuffer, sizeof( pBuffer ), pPipe ) != NULL)
            {
                int nLen = strlen( pBuffer );
                if( pBuffer[nLen-1] == '\n' ) // strip newline
                    pBuffer[--nLen] = 0;
                aCommand = OUString(pBuffer, nLen, aEncoding);
                if( ( ( aCommand[ 0 ] == '/' )
                      || ( aCommand[ 0 ] == '.' && aCommand[ 1 ] == '/' )
                      || ( aCommand[ 0 ] == '.' && aCommand[ 1 ] == '.' && aCommand[ 2 ] == '/' ) )
                    && nLen > 2
                    && aCommand[ nLen-2 ] == 'g'
                    && aCommand[ nLen-1 ] == 's' )
                {
                    aCommand += " -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=\"(OUTFILE)\" -" ;
                    aSysCommands.push_back( aCommand );
                }
            }
            pclose( pPipe );
        }

        pPipe = popen( "which distill 2>/dev/null", "r" );
        if( pPipe )
        {
            if (fgets( pBuffer, sizeof( pBuffer ), pPipe ) != NULL)
            {
                int nLen = strlen( pBuffer );
                if( pBuffer[nLen-1] == '\n' ) // strip newline
                    pBuffer[--nLen] = 0;
                aCommand = OUString(pBuffer, nLen, aEncoding);
                if( ( ( aCommand[ 0 ] == '/' )
                      || ( aCommand[ 0 ] == '.' && aCommand[ 1 ] == '/' )
                      || ( aCommand[ 0 ] == '.' && aCommand[ 1 ] == '.' && aCommand[ 2 ] == '/' ) )
                    && nLen > 7
                    && aCommand.copy( nLen - 8 ).equalsAscii( "/distill" ) )
                {
                    aCommand += " (TMP) ; mv `echo (TMP) | sed s/\\.ps\\$/.pdf/` \"(OUTFILE)\"" ;
                    aSysCommands.push_back( aCommand );
                }
            }
            pclose( pPipe );
        }
    }
    ::std::list< OUString >::const_iterator it;
    for( it = aSysCommands.begin(); it != aSysCommands.end(); ++it )
        rCommands.push_back( *it );
}



void CommandStore::getStoredCommands( const char* pGroup, ::std::list< OUString >& rCommands )
{
    Config& rConfig( getPadminRC() );
    rConfig.SetGroup( pGroup );
    sal_Int32 nKeys = rConfig.GetKeyCount();
    ::std::list< OUString >::const_iterator it;
    while( nKeys-- )
    {
        OUString aCommand( rConfig.ReadKey(OString::number(nKeys), RTL_TEXTENCODING_UTF8 ) );
        if( !aCommand.isEmpty() )
        {
            for( it = rCommands.begin(); it != rCommands.end() && *it != aCommand; ++it )
                ;
            if( it == rCommands.end() )
                rCommands.push_back( aCommand );
        }
    }
}

void CommandStore::setCommands(
                               const char* pGroup,
                               const ::std::list< OUString >& rCommands,
                               const ::std::list< OUString >& rSysCommands
                               )
{
    Config& rConfig( getPadminRC() );
    rConfig.DeleteGroup( pGroup );
    rConfig.SetGroup( pGroup );
    ::std::list< OUString >::const_iterator it, loop;
    ::std::list< OUString > aWriteList;

    sal_Int32 nWritten = 0;
    for( it = rCommands.begin(); it != rCommands.end(); ++it )
    {
        if( !it->isEmpty() )
        {
            for( loop = rSysCommands.begin(); loop != rSysCommands.end() && *loop != *it; ++loop )
                ;
            if( loop == rSysCommands.end() )
            {
                aWriteList.push_back( *it );
                nWritten++;
            }
        }
    }
    while( nWritten > MAX_COMMANDS )
    {
        aWriteList.pop_front();
        nWritten--;
    }
    for( nWritten = 0, it = aWriteList.begin(); it != aWriteList.end(); ++it, ++nWritten )
        rConfig.WriteKey( OString::number(nWritten), OUStringToOString(*it, RTL_TEXTENCODING_UTF8) );
}


void CommandStore::getPrintCommands( ::std::list< OUString >& rCommands )
{
    rCommands.clear();
    getSystemPrintCommands( rCommands );
    getStoredCommands( PRINTER_PERSISTENCE_GROUP, rCommands );
}

void CommandStore::getPdfCommands( ::std::list< OUString >& rCommands )
{
    rCommands.clear();
    getSystemPdfCommands( rCommands );
    getStoredCommands( PDF_PERSISTENCE_GROUP, rCommands );
}

void CommandStore::setPrintCommands( const ::std::list< OUString >& rCommands )
{
    ::std::list< OUString > aSysCmds;
    getSystemPrintCommands( aSysCmds );
    setCommands( PRINTER_PERSISTENCE_GROUP, rCommands, aSysCmds );
}

void CommandStore::setPdfCommands( const ::std::list< OUString >& rCommands )
{
    ::std::list< OUString > aSysCmds;
    getSystemPdfCommands( aSysCmds );
    setCommands( PDF_PERSISTENCE_GROUP, rCommands, aSysCmds );
}

RTSCommandPage::RTSCommandPage( RTSDialog* pParent ) :
        TabPage( pParent->m_pTabControl, PaResId( RID_RTS_COMMANDPAGE ) ),
        m_pParent( pParent ),
        m_aCommandsCB( this, PaResId( RID_RTS_CMD_CB_COMMANDS ) ),
        m_aExternalCB( this, PaResId( RID_RTS_CMD_CB_EXTERNAL ) ),
        m_aQuickFT( this, PaResId( RID_RTS_CMD_FT_QUICKCMD ) ),
        m_aQuickCB( this, PaResId( RIT_RTS_CMD_CB_QUICKCMD ) ),
        m_aCommandTitle( this, PaResId( RID_RTS_CMD_FL_INSTALL ) ),
        m_aPrinterName( this, PaResId( RID_RTS_CMD_TXT_PRTNAME ) ),
        m_aConnectedTo( this, PaResId( RID_RTS_CMD_TXT_CONNECT ) ),
        m_aPrinterFL( this, PaResId( RID_RTS_CMD_FL_DEFAULT ) ),
        m_aConfigureText( this, PaResId( RID_RTS_CMD_TXT_CONFIGURE ) ),
        m_aConfigureBox( this, PaResId( RID_RTS_CMD_LB_CONFIGURE ) ),
        m_aPdfDirectoryText( this, PaResId( RID_RTS_CMD_TXT_PDFDIR ) ),
        m_aPdfDirectoryButton( this, PaResId( RID_RTS_CMD_BTN_PDFDIR ) ),
        m_aPdfDirectoryEdit( this, PaResId( RID_RTS_CMD_EDT_PDFDIR ) ),
        m_aHelpButton( this, PaResId( RID_RTS_CMD_BTN_HELP ) ),
        m_aRemovePB( this, PaResId( RID_RTS_CMD_BTN_REMOVE ) ),
        m_aPrinterHelp( PaResId( RID_RTS_CMD_STR_PRINTERHELP ) ),
        m_aPdfHelp( PaResId( RID_RTS_CMD_STR_PDFHELP ) ),
        m_bWasExternalDialog(false)
{
    // configuring as printer is only sensible in default print system
    PrinterInfoManager& rMgr( PrinterInfoManager::get() );
    if( rMgr.getType() == PrinterInfoManager::Default )
        m_nPrinterEntry = m_aConfigureBox.InsertEntry( OUString( PaResId( RID_RTS_CMD_STR_CONFIGURE_PRINTER ) ) );
    else
        m_nPrinterEntry = ~0;
    m_nPdfEntry = m_aConfigureBox.InsertEntry( OUString( PaResId( RID_RTS_CMD_STR_CONFIGURE_PDF ) ) );

    FreeResource();

    CommandStore::getPrintCommands( m_aPrinterCommands );
    CommandStore::getPdfCommands( m_aPdfCommands );

    m_aPrinterName.SetText( m_pParent->m_aPrinter );

    m_aCommandsCB.SetDoubleClickHdl( LINK( this, RTSCommandPage, DoubleClickHdl ) );
    m_aCommandsCB.SetSelectHdl( LINK( this, RTSCommandPage, SelectHdl ) );
    m_aCommandsCB.SetModifyHdl( LINK( this, RTSCommandPage, ModifyHdl ) );
    m_aConfigureBox.SetSelectHdl( LINK( this, RTSCommandPage, SelectHdl ) );
    m_aHelpButton.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
    m_aRemovePB.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
    m_aPdfDirectoryButton.SetClickHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );
    m_aExternalCB.SetToggleHdl( LINK( this, RTSCommandPage, ClickBtnHdl ) );

    m_aPdfDirectoryButton.Show( false );
    m_aPdfDirectoryEdit.Show( false );
    m_aPdfDirectoryText.Show( false );
    m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
    m_aQuickCB.SetText( m_pParent->m_aJobData.m_aQuickCommand );

    m_bWasPdf = false;
    m_aConfigureBox.SelectEntryPos( m_nPrinterEntry );
    sal_Int32 nIndex = 0;
    while( nIndex != -1 )
    {
        OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
        if( aToken.startsWith( "pdf=" ) )
        {
            m_bWasPdf = true;
            sal_Int32 nPos = 0;
            m_aPdfDirectoryEdit.SetText( aToken.getToken( 1, '=', nPos ) );
            m_aPdfDirectoryEdit.Show( true );
            m_aPdfDirectoryButton.Show( true );
            m_aPdfDirectoryText.Show( true );
            m_aConfigureBox.SelectEntryPos( m_nPdfEntry );
        }
        else if( aToken.equalsAscii( "external_dialog" ) )
        {
            m_aExternalCB.Check();
            m_bWasExternalDialog = true;
        }
    }

    m_aQuickCB.Enable( m_aExternalCB.IsChecked() );

    OUString aString( m_aConnectedTo.GetText() );
    aString += m_pParent->m_aJobData.m_aCommand;
    m_aConnectedTo.SetText( aString );

    UpdateCommands();
}

RTSCommandPage::~RTSCommandPage()
{
}

void RTSCommandPage::save()
{
    OUString aCommand,aQuickCommand;
    bool bHavePdf = m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry ? true : false;
    ::std::list< OUString >::iterator it;

    OUString aFeatures;
    sal_Int32 nIndex = 0;
    OUString aOldPdfPath;
    bool bExternalDialog = m_aExternalCB.IsChecked() ? true : false;

    while( nIndex != -1 )
    {
        OUString aToken( m_pParent->m_aJobData.m_aFeatures.getToken( 0, ',', nIndex ) );
        if( !aToken.startsWith( "pdf" ) &&
            aToken.compareToAscii( "external_dialog" )
          )
        {
            if( !aToken.isEmpty() )
            {
                if( !aFeatures.isEmpty() )
                    aFeatures += ",";
                aFeatures += OUString( aToken );
            }
        }
        else if( aToken.startsWith( "pdf=" ) )
        {
            sal_Int32 nPos = 0;
            aOldPdfPath = aToken.getToken( 1, '=', nPos );
        }
    }
    ::std::list< OUString >* pList = &m_aPrinterCommands;
    if( bExternalDialog )
    {
        if( !aFeatures.isEmpty() )
            aFeatures += ",";
        aFeatures += "external_dialog" ;
    }
    if( bHavePdf )
    {
        if( !aFeatures.isEmpty() )
            aFeatures += ",";
        aFeatures += "pdf=" ;
        aFeatures += m_aPdfDirectoryEdit.GetText() ;
        pList = &m_aPdfCommands;
    }
    aCommand = m_aCommandsCB.GetText();
    aQuickCommand = m_aQuickCB.GetText();
    for( it = pList->begin(); it != pList->end() && *it != aCommand; ++it )
        ;
    if( it == pList->end() )
        pList->push_back( aCommand );

    if( aCommand != m_pParent->m_aJobData.m_aCommand                        ||
        aQuickCommand != m_pParent->m_aJobData.m_aQuickCommand              ||
        ( m_bWasPdf && ! bHavePdf )                                         ||
        ( ! m_bWasPdf && bHavePdf )                                         ||
        ( bHavePdf && aOldPdfPath != m_aPdfDirectoryEdit.GetText() )        ||
        ( m_bWasExternalDialog && ! bExternalDialog )                       ||
        ( ! m_bWasExternalDialog && bExternalDialog )
        )
    {
        m_pParent->m_aJobData.m_aCommand        = aCommand;
        m_pParent->m_aJobData.m_aQuickCommand   = aQuickCommand;
        m_pParent->m_aJobData.m_aFeatures       = aFeatures;

        PrinterInfoManager::get().changePrinterInfo( m_pParent->m_aPrinter, m_pParent->m_aJobData );
    }
    CommandStore::setPrintCommands( m_aPrinterCommands );
    CommandStore::setPdfCommands( m_aPdfCommands );
}


IMPL_LINK( RTSCommandPage, SelectHdl, Control*, pBox )
{
    if( pBox == &m_aConfigureBox )
    {
        sal_Bool bEnable = m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry ? sal_True : sal_False;
        m_aPdfDirectoryButton.Show( bEnable );
        m_aPdfDirectoryEdit.Show( bEnable );
        m_aPdfDirectoryText.Show( bEnable );
        UpdateCommands();
    }
    else if( pBox == &m_aCommandsCB )
    {
        m_aRemovePB.Enable( true );
    }

    return 0;
}

IMPL_LINK( RTSCommandPage, ClickBtnHdl, Button*, pButton )
{
    if( pButton == & m_aPdfDirectoryButton )
    {
        OUString aPath( m_aPdfDirectoryEdit.GetText() );
        if( chooseDirectory( aPath ) )
            m_aPdfDirectoryEdit.SetText( aPath );
    }
    else if( pButton == &m_aRemovePB )
    {
        OUString aEntry( m_aCommandsCB.GetText() );
        ::std::list< OUString >* pList;
        if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
            pList = &m_aPrinterCommands;
        else
            pList = &m_aPdfCommands;

        pList->remove( aEntry );
        m_aCommandsCB.RemoveEntry( aEntry );
        m_aQuickCB.RemoveEntry( aEntry );
    }
    else if( pButton == &m_aHelpButton )
    {
        OUString aHelpText;
        if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
            aHelpText = m_aPrinterHelp;
        else if( m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry )
            aHelpText = m_aPdfHelp;

        InfoBox aBox( this, aHelpText );
        aBox.Execute();
    }
    else if( pButton == &m_aExternalCB )
    {
        m_aQuickCB.Enable( m_aExternalCB.IsChecked() );
    }
    return 0;
}

IMPL_LINK( RTSCommandPage, DoubleClickHdl, ComboBox*, pComboBox )
{
    if( pComboBox == &m_aCommandsCB )
        ConnectCommand();
    return 0;
}

IMPL_LINK( RTSCommandPage, ModifyHdl, Edit*, pEdit )
{
    if( pEdit == &m_aCommandsCB )
        m_aRemovePB.Enable( m_aCommandsCB.GetEntryPos( m_aCommandsCB.GetText() ) != LISTBOX_ENTRY_NOTFOUND );

    return 0;
}

void RTSCommandPage::UpdateCommands()
{
    m_aCommandsCB.Clear();
    ::std::list< OUString >::iterator it;
    if( m_aConfigureBox.GetSelectEntryPos() == m_nPrinterEntry )
    {
        for( it = m_aPrinterCommands.begin(); it != m_aPrinterCommands.end(); ++it )
        {
            m_aCommandsCB.InsertEntry( *it );
            m_aQuickCB.InsertEntry( *it );
        }
        m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
    }
    else if( m_aConfigureBox.GetSelectEntryPos() == m_nPdfEntry )
    {
        for( it = m_aPdfCommands.begin(); it != m_aPdfCommands.end(); ++it )
        {
            m_aCommandsCB.InsertEntry( *it );
            m_aQuickCB.InsertEntry( *it );
        }
        if( m_bWasPdf )
            m_aCommandsCB.SetText( m_pParent->m_aJobData.m_aCommand );
        else
            m_aCommandsCB.SetText( OUString() );
    }
}

void RTSCommandPage::ConnectCommand()
{
    OUString aString = ( m_aConnectedTo.GetText().getToken( 0, ':' ) )
        + ": " + m_aCommandsCB.GetText();

    m_aConnectedTo.SetText( aString );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/cmddlg.hxx b/padmin/source/cmddlg.hxx
deleted file mode 100644
index 1fdb0aa..0000000
--- a/padmin/source/cmddlg.hxx
+++ /dev/null
@@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_COMMANDDLG_HXX_
#define _PAD_COMMANDDLG_HXX_

#include <vcl/dialog.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>
#include <vcl/combobox.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/field.hxx>
#include <vcl/tabpage.hxx>

#include <list>

namespace padmin {

class RTSDialog;

class CommandStore
{
    static void getStoredCommands( const char* pGroup, ::std::list< OUString >& rCommands );
    static void getSystemPrintCommands( ::std::list< OUString >& rCommands );
    static void getSystemPdfCommands( ::std::list< OUString >& rCommands );
    static void setCommands( const char* pGroup, const ::std::list< OUString >& rCommands, const ::std::list< OUString >& rSysCommands );

public:
    static void getPrintCommands( ::std::list< OUString >& rCommands );
    static void getPdfCommands( ::std::list< OUString >& rCommands );

    static void setPrintCommands( const ::std::list< OUString >& rCommands );
    static void setPdfCommands( const ::std::list< OUString >& rCommands );
};

class RTSCommandPage : public TabPage
{
private:
    RTSDialog*                      m_pParent;

    ComboBox                        m_aCommandsCB;
    CheckBox                        m_aExternalCB;
    FixedText                       m_aQuickFT;
    ComboBox                        m_aQuickCB;
    FixedLine                       m_aCommandTitle;
    FixedText                       m_aPrinterName;
    FixedText                       m_aConnectedTo;
    FixedLine                       m_aPrinterFL;

    FixedText                       m_aConfigureText;
    ListBox                         m_aConfigureBox;
    sal_uInt16                          m_nPrinterEntry;
    sal_uInt16                          m_nPdfEntry;
    FixedText                       m_aPdfDirectoryText;
    PushButton                      m_aPdfDirectoryButton;
    Edit                            m_aPdfDirectoryEdit;

    PushButton                      m_aHelpButton;
    PushButton                      m_aRemovePB;

    ::std::list< OUString >         m_aPrinterCommands;
    ::std::list< OUString >         m_aPdfCommands;

    OUString                        m_aPrinterHelp;
    OUString                        m_aPdfHelp;

    bool                            m_bWasPdf;
    bool                            m_bWasExternalDialog;

    DECL_LINK( DoubleClickHdl, ComboBox* );
    DECL_LINK( ClickBtnHdl, Button* );
    DECL_LINK( SelectHdl, Control* );
    DECL_LINK( ModifyHdl, Edit* );

    void ConnectCommand();
    void UpdateCommands();

public:
    RTSCommandPage( RTSDialog* );
    ~RTSCommandPage();

    void save();
};

} // namespace

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/desktopcontext.cxx b/padmin/source/desktopcontext.cxx
deleted file mode 100644
index fe58759..0000000
--- a/padmin/source/desktopcontext.cxx
+++ /dev/null
@@ -1,53 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "desktopcontext.hxx"

#include <vcl/svapp.hxx>

using namespace com::sun::star::uno;


namespace padmin
{

DesktopContext::DesktopContext( const Reference< XCurrentContext > & ctx )
    : m_xNextContext( ctx )
{
}

Any SAL_CALL DesktopContext::getValueByName( const OUString& Name) throw (RuntimeException, std::exception)
{
    Any retVal;

    if ( Name.equalsAscii( DESKTOP_ENVIRONMENT_NAME ) )
    {
        retVal = makeAny( Application::GetDesktopEnvironment() );
    }
    else if( m_xNextContext.is() )
    {
        // Call next context in chain if found
        retVal = m_xNextContext->getValueByName( Name );
    }
    return retVal;
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/desktopcontext.hxx b/padmin/source/desktopcontext.hxx
deleted file mode 100644
index cf46700..0000000
--- a/padmin/source/desktopcontext.hxx
+++ /dev/null
@@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PADMIN_DESKTOPCONTEXT_HXX_
#define _PADMIN_DESKTOPCONTEXT_HXX_

#include <cppuhelper/implbase1.hxx>
#include <uno/current_context.hxx>

#define DESKTOP_ENVIRONMENT_NAME "system.desktop-environment"

namespace padmin
{
    class DesktopContext: public cppu::WeakImplHelper1< com::sun::star::uno::XCurrentContext >
    {
    public:
    DesktopContext( const com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > & ctx);

        // XCurrentContext
        virtual com::sun::star::uno::Any SAL_CALL getValueByName( const OUString& Name )
            throw (com::sun::star::uno::RuntimeException, std::exception);

    private:
            com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > m_xNextContext;
    };
}

#endif // _PADMIN_DESKTOPCONTEXT_HXX_

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/helper.cxx b/padmin/source/helper.cxx
index fdb974cd..d0e2a51 100644
--- a/padmin/source/helper.cxx
+++ b/padmin/source/helper.cxx
@@ -19,7 +19,6 @@

#include <unistd.h>
#include <helper.hxx>
#include <padialog.hrc>
#include <osl/file.hxx>
#include <tools/urlobj.hxx>
#include <vcl/svapp.hxx>
@@ -77,110 +76,8 @@ ResId padmin::PaResId( sal_uInt32 nId )
}

/*
 *  FindFiles
 */

void padmin::FindFiles( const OUString& rDirectory, ::std::list< OUString >& rResult, const OUString& rSuffixes, bool bRecursive )
{
    rResult.clear();

    OUString aDirPath;
    ::osl::FileBase::getFileURLFromSystemPath( rDirectory, aDirPath );
    Directory aDir( aDirPath );
    if( aDir.open() != FileBase::E_None )
        return;
    DirectoryItem aItem;
    while( aDir.getNextItem( aItem ) == FileBase::E_None )
    {
        FileStatus aStatus( osl_FileStatus_Mask_FileName            |
                            osl_FileStatus_Mask_Type
                            );
        if( aItem.getFileStatus( aStatus ) == FileBase::E_None )
        {
            if( aStatus.getFileType() == FileStatus::Regular ||
                aStatus.getFileType() == FileStatus::Link )
            {
                OUString aFileName = aStatus.getFileName();
                int nToken = comphelper::string::getTokenCount(rSuffixes, ';');
                while( nToken-- )
                {
                    OUString aSuffix = rSuffixes.getToken( nToken, ';' );
                    if( aFileName.getLength() > aSuffix.getLength()+1 )
                    {
                        OUString aExtension = aFileName.copy( aFileName.getLength()-aSuffix.getLength() );
                        if( aFileName[ aFileName.getLength()-aSuffix.getLength()-1 ] == '.' &&
                            aExtension.equalsIgnoreAsciiCase( aSuffix ) )
                        {
                            rResult.push_back( aFileName );
                            break;
                        }
                    }
                }
            }
            else if( bRecursive && aStatus.getFileType() == FileStatus::Directory )
            {
                OUStringBuffer aSubDir( rDirectory );
                aSubDir.appendAscii( "/", 1 );
                aSubDir.append( aStatus.getFileName() );
                std::list< OUString > subfiles;
                FindFiles( aSubDir.makeStringAndClear(), subfiles, rSuffixes, bRecursive );
                for( std::list< OUString >::const_iterator it = subfiles.begin(); it != subfiles.end(); ++it )
                {
                    OUStringBuffer aSubFile( aStatus.getFileName() );
                    aSubFile.appendAscii( "/", 1 );
                    aSubFile.append( *it );
                    rResult.push_back( aSubFile.makeStringAndClear() );
                }
            }
        }
    }
    aDir.close();
}

/*
 *  DelMultiListBox
 */

bool DelMultiListBox::Notify( NotifyEvent& rEvent )
{
    bool nRet = false;

    if( rEvent.GetType() == EVENT_KEYINPUT &&
        rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
    {
        m_aDelPressedLink.Call( this );
        nRet = true;
    }
    else
        nRet = MultiListBox::Notify( rEvent );

    return nRet;
}

/*
 *  DelListBox
 */

bool DelListBox::Notify( NotifyEvent& rEvent )
{
    bool nRet = false;

    if( rEvent.GetType() == EVENT_KEYINPUT &&
        rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
    {
        m_aDelPressedLink.Call( this );
        nRet = true;
    }
    else
        nRet = ListBox::Notify( rEvent );

    return nRet;
}

/*
 *  QueryString
 */

QueryString::QueryString(Window* pParent, OUString& rQuery, OUString& rRet)
    : ModalDialog(pParent, "QueryDialog",
        "spa/ui/querydialog.ui" )
@@ -212,81 +109,4 @@ IMPL_LINK( QueryString, ClickBtnHdl, Button*, pButton )
    return 0;
}

/*
 *  AreYouSure
 */

sal_Bool padmin::AreYouSure( Window* pParent, int nRid )
{
    if( nRid == -1 )
        nRid = RID_YOU_SURE;
    QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_NO,
                        OUString( PaResId( nRid ) ) );
    return aQueryBox.Execute() == RET_NO ? sal_False : sal_True;
}

/*
 *  getPadminRC
 */

static Config* pRC = NULL;

Config& padmin::getPadminRC()
{
    if( ! pRC )
    {
        static const char* pEnv = getenv( "HOME" );
        OUString aFileName;
        if( pEnv )
            aFileName = OUString::createFromAscii( pEnv ) + "/.padminrc";
        else
            aFileName += OStringToOUString( "", osl_getThreadTextEncoding() ) + "/.padminrc";

        pRC = new Config( aFileName );
    }
    return *pRC;
}

void padmin::freePadminRC()
{
    if( pRC )
        delete pRC, pRC = NULL;
}

bool padmin::chooseDirectory( OUString& rInOutPath )
{
    bool bRet = false;
    Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);;
    Reference< XControlAccess > xCA( xFolderPicker, UNO_QUERY );
    if( xCA.is() )
    {
        try
        {
            Any aState;
            aState <<= sal_False;
            xCA->setControlProperty( OUString(  "HelpButton"  ),
                                     OUString(  "Visible"  ),
                                     aState );

        }
        catch( ... )
        {
        }
    }
    INetURLObject aObj( rInOutPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
    xFolderPicker->setDisplayDirectory( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
    if( xFolderPicker->execute() == ExecutableDialogResults::OK )
    {
        aObj = INetURLObject( xFolderPicker->getDirectory() );
        rInOutPath = aObj.PathToFileName();
        bRet = true;
    }
#if OSL_DEBUG_LEVEL > 1
    else
        fprintf( stderr, "could not get FolderPicker service\n" );
#endif
    return bRet;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/helper.hxx b/padmin/source/helper.hxx
index 5a1279aa..1e491d2 100644
--- a/padmin/source/helper.hxx
+++ b/padmin/source/helper.hxx
@@ -36,49 +36,8 @@
#define SPA_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
#endif


class Config;

namespace padmin
{
class DelMultiListBox : public MultiListBox
{
    Link            m_aDelPressedLink;
public:
    DelMultiListBox( Window* pParent, const ResId& rResId ) :
            MultiListBox( pParent, rResId ) {}
    ~DelMultiListBox() {}

    virtual bool Notify( NotifyEvent& rEvent );

    Link setDelPressedLink( const Link& rLink )
    {
        Link aOldLink( m_aDelPressedLink );
                m_aDelPressedLink = rLink;
                return aOldLink;
    }
    const Link& getDelPressedLink() const { return m_aDelPressedLink; }
};

class DelListBox : public ListBox
{
    Link            m_aDelPressedLink;
public:
    DelListBox( Window* pParent, const ResId& rResId ) :
                ListBox( pParent, rResId ) {}
    ~DelListBox() {}

    virtual bool Notify( NotifyEvent& rEvent );

    Link setDelPressedLink( const Link& rLink )
    {
        Link aOldLink( m_aDelPressedLink );
        m_aDelPressedLink = rLink;
        return aOldLink;
    }
    const Link& getDelPressedLink() const { return m_aDelPressedLink; }
};

class QueryString : public ModalDialog
{
private:
@@ -95,16 +54,8 @@ public:
    ~QueryString();
};

sal_Bool AreYouSure( Window*, int nRid = -1 );

ResId PaResId( sal_uInt32 nId );

void FindFiles( const OUString& rDirectory, ::std::list< OUString >& rResult, const OUString& rSuffixes, bool bRecursive = false );
Config& getPadminRC();
void freePadminRC();

bool chooseDirectory( OUString& rInOutPath );

} // namespace padmin

#endif
diff --git a/padmin/source/newppdlg.cxx b/padmin/source/newppdlg.cxx
deleted file mode 100644
index 81171ee..0000000
--- a/padmin/source/newppdlg.cxx
+++ /dev/null
@@ -1,221 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdio.h>
#include <unistd.h>

#include "helper.hxx"
#include "padialog.hrc"
#include "newppdlg.hxx"
#include "padialog.hxx"
#include "progress.hxx"

#include "vcl/ppdparser.hxx"
#include "vcl/helper.hxx"
#include "vcl/svapp.hxx"
#include "vcl/mnemonic.hxx"

#include "tools/config.hxx"
#include "tools/urlobj.hxx"

#include "osl/file.hxx"

#include <list>

#define PPDIMPORT_GROUP "PPDImport"

using namespace padmin;
using namespace psp;
using namespace osl;


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 ) ),
        m_aPathTxt( this, PaResId( RID_PPDIMP_TXT_PATH ) ),
        m_aPathBox( this, PaResId( RID_PPDIMP_LB_PATH ) ),
        m_aSearchBtn( this, PaResId( RID_PPDIMP_BTN_SEARCH ) ),
        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();

    OUString aText( m_aDriverTxt.GetText() );
    aText = aText.replaceFirst( "%s", Button::GetStandardText( BUTTON_OK ) );
    m_aDriverTxt.SetText( MnemonicGenerator::EraseAllMnemonicChars( aText ) );

    Config& rConfig = getPadminRC();
    rConfig.SetGroup( PPDIMPORT_GROUP );
    m_aPathBox.SetText( OStringToOUString(rConfig.ReadKey("LastDir"), RTL_TEXTENCODING_UTF8) );
    for (sal_Int32 i = 0; i < 11; ++i)
    {
        OString aEntry(rConfig.ReadKey(OString::number(i)));
        if (!aEntry.isEmpty())
            m_aPathBox.InsertEntry(OStringToOUString(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 ) );

    if( !m_aPathBox.GetText().isEmpty() )
        Import();
}

PPDImportDialog::~PPDImportDialog()
{
    while( m_aDriverLB.GetEntryCount() )
    {
        delete (OUString*)m_aDriverLB.GetEntryData( 0 );
        m_aDriverLB.RemoveEntry( 0 );
    }
}

void PPDImportDialog::Import()
{
    OUString aImportPath( m_aPathBox.GetText() );

    Config& rConfig = getPadminRC();
    rConfig.SetGroup( PPDIMPORT_GROUP );
    rConfig.WriteKey( "LastDir", OUStringToOString(aImportPath, RTL_TEXTENCODING_UTF8) );

    int nEntries = m_aPathBox.GetEntryCount();
    while( nEntries-- )
        if( aImportPath == m_aPathBox.GetEntry( nEntries ) )
            break;
    if( nEntries < 0 )
    {
        sal_Int32 nNextEntry = rConfig.ReadKey("NextEntry").toInt32();
        rConfig.WriteKey( OString::number(nNextEntry), OUStringToOString(aImportPath, RTL_TEXTENCODING_UTF8) );
        nNextEntry = nNextEntry < 10 ? nNextEntry+1 : 0;
        rConfig.WriteKey( "NextEntry", OString::number(nNextEntry) );
        m_aPathBox.InsertEntry( aImportPath );
    }
    while( m_aDriverLB.GetEntryCount() )
    {
        delete (OUString*)m_aDriverLB.GetEntryData( 0 );
        m_aDriverLB.RemoveEntry( 0 );
    }

    ProgressDialog aProgress( Application::GetFocusWindow() );
    aProgress.startOperation( m_aLoadingPPD );

    ::std::list< OUString > aFiles;
    FindFiles( aImportPath, aFiles, OUString( "PS;PPD;PS.GZ;PPD.GZ" ), true );

    int i = 0;
    aProgress.setRange( 0, aFiles.size() );
    while( !aFiles.empty() )
    {
        aProgress.setValue( ++i );
        aProgress.setFilename( aFiles.front() );
        INetURLObject aPath( aImportPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
        aPath.Append( aFiles.front() );
        OUString aPrinterName = PPDParser::getPPDPrinterName( aPath.PathToFileName() );
        aFiles.pop_front();

        if( aPrinterName.isEmpty() )
        {
#if OSL_DEBUG_LEVEL > 1
            fprintf( stderr, "Warning: File %s has empty printer name.\n",
                     OUStringToOString( aPath.PathToFileName(), osl_getThreadTextEncoding() ).getStr() );
#endif
            continue;
        }

        sal_uInt16 nPos = m_aDriverLB.InsertEntry( aPrinterName );
        m_aDriverLB.SetEntryData( nPos, new OUString( aPath.PathToFileName() ) );
    }
}

IMPL_LINK( PPDImportDialog, ClickBtnHdl, PushButton*, pButton )
{
    if( pButton == &m_aCancelBtn )
    {
        EndDialog( 0 );
    }
    else if( pButton == &m_aOKBtn )
    {
        // copy the files
        ::std::list< OUString > aToDirs;
        psp::getPrinterPathList( aToDirs, PRINTER_PPDDIR );
        ::std::list< OUString >::iterator writeDir = aToDirs.begin();
        m_aImportedFiles.clear();

        for( int i = 0; i < m_aDriverLB.GetSelectEntryCount(); i++ )
        {
            INetURLObject aFile( *(OUString*)m_aDriverLB.GetEntryData(
                m_aDriverLB.GetSelectEntryPos( i )
                ), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
            OUString aFromUni( aFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );

            do
            {
                INetURLObject aToFile( *writeDir, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
                aToFile.Append( aFile.GetName() );
                OUString aToUni( aToFile.GetMainURL(INetURLObject::DECODE_TO_IURI) );
                if( ! File::copy( aFromUni, aToUni ) )
                {
                    m_aImportedFiles.push_back( aToUni );
                    break;
                }
                ++writeDir;
            } while( writeDir != aToDirs.end() );
        }
        EndDialog( 1 );
    }
    else if( pButton == &m_aSearchBtn )
    {
        OUString aPath( m_aPathBox.GetText() );
        if( chooseDirectory( aPath ) )
        {
            m_aPathBox.SetText( aPath );
            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 )
    {
        OString aDir(OUStringToOString(m_aPathBox.GetText(), osl_getThreadTextEncoding()));
        if (!access( aDir.getStr(), F_OK))
            Import();
    }
    return 0;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/newppdlg.hxx b/padmin/source/newppdlg.hxx
deleted file mode 100644
index f222ef2..0000000
--- a/padmin/source/newppdlg.hxx
+++ /dev/null
@@ -1,68 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_NEWPPDLG_HXX_
#define _PAD_NEWPPDLG_HXX_

#include <vcl/dialog.hxx>
#include <vcl/button.hxx>
#include <vcl/combobox.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>

namespace psp { class PPDParser; }

namespace padmin {

    class PPDImportDialog : public ModalDialog
    {
        OKButton            m_aOKBtn;
        CancelButton        m_aCancelBtn;
        FixedText           m_aPathTxt;
        ComboBox            m_aPathBox;
        PushButton          m_aSearchBtn;
        FixedText           m_aDriverTxt;
        MultiListBox        m_aDriverLB;

        FixedLine           m_aPathGroup;
        FixedLine           m_aDriverGroup;

        OUString            m_aLoadingPPD;

        DECL_LINK( ClickBtnHdl, PushButton* );
        DECL_LINK( SelectHdl, ComboBox* );
        DECL_LINK( ModifyHdl, ComboBox* );

        void Import();

        std::list< OUString >  m_aImportedFiles;
    public:
        PPDImportDialog( Window* pParent );
        ~PPDImportDialog();

        const std::list< OUString >& getImportedFiles() const
        { return m_aImportedFiles; }
    };

} // namespace

#endif // _NEWPPDLG_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/padialog.cxx b/padmin/source/padialog.cxx
deleted file mode 100644
index 82a54bf..0000000
--- a/padmin/source/padialog.cxx
+++ /dev/null
@@ -1,711 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>

#include "padialog.hrc"
#include "helper.hxx"
#include "padialog.hxx"
#include "adddlg.hxx"
#include "prtsetup.hxx"

#include "vcl/msgbox.hxx"
#include "vcl/print.hxx"
#include "vcl/gradient.hxx"
#include "vcl/bitmap.hxx"
#include "vcl/lineinfo.hxx"
#include "vcl/svapp.hxx"
#include "vcl/event.hxx"
#include "vcl/printerinfomanager.hxx"
#include <vcl/settings.hxx>

#include "tools/stream.hxx"
#include "tools/color.hxx"
#include "tools/urlobj.hxx"

#include "osl/file.hxx"

#include "rtl/ustrbuf.hxx"
#include <sal/macros.h>

#include "unotools/localedatawrapper.hxx"
#include "unotools/configitem.hxx"
#include "unotools/configmgr.hxx"

#include "com/sun/star/awt/Size.hpp"

using namespace psp;
using namespace padmin;
using namespace osl;
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;


PADialog* PADialog::Create( Window* pParent, sal_Bool bAdmin )
{
    return new PADialog( pParent, bAdmin );
}

PADialog::PADialog( Window* pParent, sal_Bool /*bAdmin*/ ) :
        ModalDialog( pParent, PaResId( RID_PADIALOG ) ),
        m_aDevicesLB( this, PaResId( RID_PA_LB_DEV ) ),
        m_aConfPB( this, PaResId( RID_PA_BTN_CONF ) ),
        m_aRenamePB( this, PaResId( RID_PA_BTN_RENAME ) ),
        m_aStdPB( this, PaResId( RID_PA_BTN_STD ) ),
        m_aRemPB( this, PaResId( RID_PA_BTN_DEL ) ),
        m_aTestPagePB( this, PaResId( RID_PA_TESTPAGE ) ),
        m_aPrintersFL( this, PaResId( RID_PA_FL_PRINTERS ) ),
        m_aDriverTxt( this, PaResId( RID_PA_TXT_DRIVER ) ),
        m_aDriver( this, PaResId( RID_PA_TXT_DRIVER_STRING ) ),
        m_aLocationTxt( this, PaResId( RID_PA_TXT_LOCATION ) ),
        m_aLocation( this, PaResId( RID_PA_TXT_LOCATION_STRING ) ),
        m_aCommandTxt( this, PaResId( RID_PA_TXT_COMMAND ) ),
        m_aCommand( this, PaResId( RID_PA_TXT_COMMAND_STRING ) ),
        m_aCommentTxt( this, PaResId( RID_PA_TXT_COMMENT ) ),
        m_aComment( this, PaResId( RID_PA_TXT_COMMENT_STRING ) ),
        m_aSepButtonFL( this, PaResId( RID_PA_FL_SEPBUTTON ) ),
        m_aAddPB( this, PaResId( RID_PA_BTN_ADD ) ),
        m_aCancelButton( this, PaResId( RID_PA_BTN_CANCEL ) ),
        m_aDefPrt( PaResId( RID_PA_STR_DEFPRT ) ),
        m_aRenameStr( PaResId( RID_PA_STR_RENAME ) ),
        m_rPIManager( PrinterInfoManager::get() )
{
    FreeResource();
    updateSettings();
    Init();
}

void PADialog::updateSettings()
{
    m_aPrinterImg = Image( BitmapEx( PaResId( RID_BMP_SMALL_PRINTER ) ) );
    m_aPdfImg     = Image( BitmapEx( PaResId( RID_BMP_SMALL_PDF     ) ) );
}

void PADialog::Init()
{
    // #i79787# initially ensure printer discovery has ended
    m_rPIManager.checkPrintersChanged( true );

    UpdateDevice();
    UpdateText();

    m_aRemPB.Enable( false );

    m_aDevicesLB.SetDoubleClickHdl( LINK( this, PADialog, DoubleClickHdl ) );
    m_aDevicesLB.SetSelectHdl( LINK( this, PADialog, SelectHdl ) );
    m_aStdPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aRemPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aConfPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aRenamePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aTestPagePB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aAddPB.SetClickHdl( LINK( this, PADialog, ClickBtnHdl ) );
    m_aDevicesLB.setDelPressedLink( LINK( this, PADialog, DelPressedHdl ) );

    // at this point no actual changes will be  written
    // but the write will have checked whether any writeable config exists
    if( ! m_rPIManager.writePrinterConfig() )
    {
        m_aAddPB.Enable( false );
        m_aRemPB.Enable( false );
        m_aConfPB.Enable( false );
        m_aRenamePB.Enable( false );
        m_aStdPB.Enable( false );
        ErrorBox aBox( GetParent(), WB_OK | WB_DEF_OK, OUString( PaResId( RID_ERR_NOWRITE ) ) );
        aBox.Execute();
    }
}

PADialog::~PADialog()
{
    m_rPIManager.writePrinterConfig();
    freePadminRC();
}

bool PADialog::Notify( NotifyEvent& rEv )
{
    if( IsVisible() &&
        (rEv.GetType() == EVENT_GETFOCUS || rEv.GetType() == EVENT_LOSEFOCUS )
      )
    {
        if( m_rPIManager.checkPrintersChanged( true ) )
        {
            OUString aSelectEntry = m_aDevicesLB.GetSelectEntry();
            UpdateDevice();
            UpdateText();
            m_aDevicesLB.SelectEntry( aSelectEntry );
        }
    }
    return ModalDialog::Notify( rEv );
}

void PADialog::DataChanged( const DataChangedEvent& rEv )
{
    ModalDialog::DataChanged( rEv );
    if( (rEv.GetType() == DATACHANGED_SETTINGS) &&
        (rEv.GetFlags() & SETTINGS_STYLE) )
    {
        updateSettings();
        // push the new images into the listbox
        UpdateDevice();
    }
}

OUString PADialog::getSelectedDevice()
{
    int nPos = m_aDevicesLB.GetSelectEntryPos();
    int nLen = (int)(sal_IntPtr)m_aDevicesLB.GetEntryData( nPos );
    return m_aDevicesLB.GetEntry( nPos ).copy( 0, nLen );
}

IMPL_LINK( PADialog, DelPressedHdl, ListBox*, pBox )
{
    if( pBox == &m_aDevicesLB && m_aRemPB.IsEnabled() )
        ClickBtnHdl( &m_aRemPB );
    return 0;
}

IMPL_LINK( PADialog, ClickBtnHdl, PushButton*, pButton )
{
    if( pButton == &m_aStdPB )
        UpdateDefPrt();
    else if( pButton == &m_aRemPB && AreYouSure( this, RID_QUERY_REMOVEPRINTER ) )
        RemDevice();
    else if( pButton == &m_aConfPB )
        ConfigureDevice();
    else if( pButton == &m_aRenamePB )
        RenameDevice();
    else if( pButton == &m_aTestPagePB )
        PrintTestPage();
    else if( pButton == &m_aAddPB )
        AddDevice();

    return 0;
}

IMPL_LINK( PADialog, DoubleClickHdl, ListBox*, pListBox )
{
    if( pListBox == &m_aDevicesLB )
        UpdateDefPrt();
    return 0;
}

IMPL_LINK( PADialog, SelectHdl, ListBox*, pListBox )
{
    if( pListBox == &m_aDevicesLB )
    {
        OUString sSelect = getSelectedDevice();
        OUString sDefPrt = m_rPIManager.getDefaultPrinter();
        if( sDefPrt == sSelect || ! m_rPIManager.removePrinter( sSelect, true ) )
            m_aRemPB.Enable( false );
        else
            m_aRemPB.Enable( true );
        UpdateText();
    }
    return 0;
}

void PADialog::UpdateDefPrt()
{
    m_rPIManager.setDefaultPrinter( getSelectedDevice() );

    UpdateDevice();
    UpdateText();

    if( m_aRemPB.HasFocus() )
        m_aDevicesLB.GetFocus();
    m_aRemPB.Enable( false );
}

void PADialog::UpdateText()
{
    OUString aDev( getSelectedDevice() );
    if( !aDev.isEmpty() )
    {
        const PrinterInfo& rInfo = m_rPIManager.getPrinterInfo( aDev );

        OUString aDriver = rInfo.m_aPrinterName + " (" + rInfo.m_aDriverName + ")";

        m_aDriver.SetText( aDriver );
        m_aCommand.SetText( rInfo.m_aCommand );
        m_aComment.SetText( rInfo.m_aComment );
        m_aLocation.SetText( rInfo.m_aLocation );
    }
    else // nothing selected
    {
        OUString aEmpty;
        m_aDriver.SetText( aEmpty );
        m_aCommand.SetText( aEmpty );
        m_aComment.SetText( aEmpty );
        m_aLocation.SetText( aEmpty );
    }
}

static Point project( const Point& rPoint )
{
    const double angle_x = M_PI / 6.0;
    const double angle_z = M_PI / 6.0;

    // transform planar coordinates to 3d
    double x = rPoint.X();
    double y = rPoint.Y();
    //double z = 0;

    // rotate around X axis
    double x1 = x;
    double y1 = y * cos( angle_x );
    double z1 = y * sin( angle_x );

    // rotate around Z axis
    double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
    //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
    double z2 = z1;

    return Point( (sal_Int32)x2, (sal_Int32)z2 );
}

static Color approachColor( const Color& rFrom, const Color& rTo )
{
    Color aColor;
    sal_uInt8 nDiff;
    // approach red
    if( rFrom.GetRed() < rTo.GetRed() )
    {
        nDiff = rTo.GetRed() - rFrom.GetRed();
        aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
    }
    else if( rFrom.GetRed() > rTo.GetRed() )
    {
        nDiff = rFrom.GetRed() - rTo.GetRed();
        aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
    }
    else
        aColor.SetRed( rFrom.GetRed() );

    // approach Green
    if( rFrom.GetGreen() < rTo.GetGreen() )
    {
        nDiff = rTo.GetGreen() - rFrom.GetGreen();
        aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
    }
    else if( rFrom.GetGreen() > rTo.GetGreen() )
    {
        nDiff = rFrom.GetGreen() - rTo.GetGreen();
        aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
    }
    else
        aColor.SetGreen( rFrom.GetGreen() );

    // approach blue
    if( rFrom.GetBlue() < rTo.GetBlue() )
    {
        nDiff = rTo.GetBlue() - rFrom.GetBlue();
        aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
    }
    else if( rFrom.GetBlue() > rTo.GetBlue() )
    {
        nDiff = rFrom.GetBlue() - rTo.GetBlue();
        aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
    }
    else
        aColor.SetBlue( rFrom.GetBlue() );

    return aColor;
}

class SpaPrinterController : public vcl::PrinterController
{
public:
    SpaPrinterController( const boost::shared_ptr<Printer>& i_pPrinter )
    : vcl::PrinterController( i_pPrinter )
    {}
    virtual ~SpaPrinterController()
    {}

    virtual int getPageCount() const { return 1; }
    virtual Sequence< PropertyValue > getPageParameters( int i_nPage ) const;
    virtual void printPage( int i_nPage ) const;
    virtual void jobFinished( com::sun::star::view::PrintableState );
};

Sequence< PropertyValue > SpaPrinterController::getPageParameters( int ) const
{
    Sequence< PropertyValue > aRet( 1 );

    Size aPageSize( getPrinter()->GetPaperSizePixel() );
    aPageSize = getPrinter()->PixelToLogic( aPageSize, MapMode( MAP_100TH_MM ) );

    awt::Size aSize;
    aSize.Width = aPageSize.Width();
    aSize.Height = aPageSize.Height();
    aRet[0].Value = makeAny(aSize);

    return aRet;
}

void SpaPrinterController::printPage( int ) const
{
    const double DELTA = 5.0;

    boost::shared_ptr<Printer> pPrinter( getPrinter() );

    PrinterInfo aInfo( psp::PrinterInfoManager::get().getPrinterInfo( pPrinter->GetName() ) );
    const PPDParser* pPrintParser = aInfo.m_pParser;

    MapMode aMapMode( MAP_100TH_MM );

    Bitmap aButterfly( PaResId( RID_BUTTERFLY ) );

    pPrinter->SetMapMode( aMapMode );

    Size aPaperSize=pPrinter->GetOutputSize();
    Point aCenter( aPaperSize.Width()/2-300,
                   aPaperSize.Height() - aPaperSize.Width()/2 );
    Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;

    pPrinter->DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
    pPrinter->DrawRect( Rectangle( Point( 100,100 ),
                                    Size( aPaperSize.Width()-200,
                                          aPaperSize.Height()-200 ) ) );
    pPrinter->DrawRect( Rectangle( Point( 200,200 ),
                                    Size( aPaperSize.Width()-400,
                                          aPaperSize.Height()-400 ) ) );
    pPrinter->DrawRect( Rectangle( Point( 300,300 ),
                                    Size( aPaperSize.Width()-600,
                                          aPaperSize.Height()-600 ) ) );

    Font aFont( "Courier", Size( 0, 400 ) );
    aFont.SetWeight( WEIGHT_NORMAL );
    aFont.SetItalic( ITALIC_NONE );
    pPrinter->SetFont( aFont );

    OUStringBuffer aPrintText(1024);
    long nWidth = 0, nMaxWidth = 0;
    OUString aToken;

    static const struct
    {
            const char* const pDirect;
            sal_uInt16 nResId;
    } aResIds[] =
        {
            { NULL, RID_TXT_TESTPAGE_NAME },
            { NULL, RID_TXT_TESTPAGE_MODEL },
            { "PPD", 0 },
            { NULL, RID_TXT_TESTPAGE_QUEUE },
            { NULL, RID_TXT_TESTPAGE_COMMENT },
            { NULL, RID_TXT_TESTPAGE_DATE },
            { NULL, RID_TXT_TESTPAGE_TIME }
        };

    for( unsigned int i = 0; i < SAL_N_ELEMENTS(aResIds); i++ )
    {
        if( aResIds[i].pDirect )
            aToken = OUString::createFromAscii(aResIds[i].pDirect);
        else
            aToken = PaResId( aResIds[i].nResId );
        nMaxWidth = ( nWidth = pPrinter->GetTextWidth( aToken ) ) > nMaxWidth ? nWidth : nMaxWidth;
        aPrintText.append( aToken );
        aPrintText.append( '\n' );
    };

    pPrinter->DrawText( Rectangle( Point( 1000, 1000 ),
                                    Size( aPaperSize.Width() - 2000,
                                          aPaperSize.Height() - 4000 ) ),
                          aPrintText.makeStringAndClear(),
                          TEXT_DRAW_MULTILINE );

    AllSettings aSettings( Application::GetSettings() );
    const LocaleDataWrapper& rLocaleWrapper( aSettings.GetLocaleDataWrapper() );

    aPrintText.appendAscii( ": " );
    aPrintText.append( pPrinter->GetName() );
    aPrintText.appendAscii( "\n: " );
    if( pPrintParser )
        aPrintText.append( pPrintParser->getPrinterName() );
    aPrintText.appendAscii( "\n: " );
    INetURLObject aDriverPath( pPrintParser ? pPrintParser->getFilename() : OUString( "<undef>" ),
                               INET_PROT_FILE, INetURLObject::ENCODE_ALL );
    aPrintText.append( aDriverPath.GetName() );
    aPrintText.appendAscii( "\n: " );
    aPrintText.append( aInfo.m_aCommand );
    aPrintText.appendAscii( "\n: " );
    aPrintText.append( aInfo.m_aComment );
    aPrintText.appendAscii( "\n: " );
    aPrintText.append( rLocaleWrapper.getDate( Date( Date::SYSTEM ) ) );
    aPrintText.appendAscii( "\n: " );
    aPrintText.append( rLocaleWrapper.getTime( Time( Time::SYSTEM ) ) );

    pPrinter->DrawText( Rectangle( Point( 1100 + nMaxWidth, 1000 ),
                                    Size( aPaperSize.Width() - 2100 - nMaxWidth,
                                          aPaperSize.Height() - 4000 ) ),
                         aPrintText.makeStringAndClear(),
                         TEXT_DRAW_MULTILINE );

    pPrinter->DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
                           Size( 3000,3000 ),
                           aButterfly );
    pPrinter->SetFillColor();
    pPrinter->DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
                                     Size( 3000,3000 ) ) );

    Color aWhite( 0xff, 0xff, 0xff );
    Color aBlack( 0, 0, 0 );
    Color aLightRed( 0xff, 0, 0 );
    Color aDarkRed( 0x40, 0, 0 );
    Color aLightBlue( 0, 0, 0xff );
    Color aDarkBlue( 0,0,0x40 );
    Color aLightGreen( 0, 0xff, 0 );
    Color aDarkGreen( 0, 0x40, 0 );

    Gradient aGradient( GradientStyle_LINEAR, aBlack, aWhite );
    aGradient.SetAngle( 900 );
    pPrinter->DrawGradient( Rectangle( Point( 1000, 5500 ),
                                        Size( aPaperSize.Width() - 2000,
                                              500 ) ), aGradient );
    aGradient.SetStartColor( aDarkRed );
    aGradient.SetEndColor( aLightBlue );
    pPrinter->DrawGradient( Rectangle( Point( 1000, 6300 ),
                                        Size( aPaperSize.Width() - 2000,
                                              500 ) ), aGradient );
    aGradient.SetStartColor( aDarkBlue );
    aGradient.SetEndColor( aLightGreen );
    pPrinter->DrawGradient( Rectangle( Point( 1000, 7100 ),
                                        Size( aPaperSize.Width() - 2000,
                                              500 ) ), aGradient );
    aGradient.SetStartColor( aDarkGreen );
    aGradient.SetEndColor( aLightRed );
    pPrinter->DrawGradient( Rectangle( Point( 1000, 7900 ),
                                        Size( aPaperSize.Width() - 2000,
                                              500 ) ), aGradient );



    LineInfo aLineInfo( LINE_SOLID, 200 );
    double sind = sin( DELTA*M_PI/180.0 );
    double cosd = cos( DELTA*M_PI/180.0 );
    double factor = 1 + (DELTA/1000.0);
    int n=0;
    Color aLineColor( 0, 0, 0 );
    Color aApproachColor( 0, 0, 200 );
    while ( aP2.X() < aCenter.X() && n++ < 680 )
    {
        aLineInfo.SetWidth( n/3 );
        aLineColor = approachColor( aLineColor, aApproachColor );
        pPrinter->SetLineColor( aLineColor );

        // switch aproach color
        if( aApproachColor.IsRGBEqual( aLineColor ) )
        {
            if( aApproachColor.GetRed() )
                aApproachColor = Color( 0, 0, 200 );
            else if( aApproachColor.GetGreen() )
                aApproachColor = Color( 200, 0, 0 );
            else
                aApproachColor = Color( 0, 200, 0 );
        }

        pPrinter->DrawLine( project( aP1 ) + aCenter,
                             project( aP2 ) + aCenter,
                             aLineInfo );
        aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
        aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
        aP1 = aPoint;
        aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
        aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
        aP2 = aPoint;
    }
#if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
    fprintf( stderr, "%d lines\n",n );
#endif
}

void SpaPrinterController::jobFinished( com::sun::star::view::PrintableState )
{
    OUString aInfoString( PaResId( RID_PA_TXT_TESTPAGE_PRINTED ) );
    InfoBox aInfoBox( NULL, aInfoString );
    aInfoBox.SetText( OUString( PaResId( RID_BXT_TESTPAGE ) ) );
    aInfoBox.Execute();
}

void PADialog::PrintTestPage()
{
    const OUString sPrinter( getSelectedDevice() );

    boost::shared_ptr<Printer> pPrinter( new Printer( sPrinter ) );

    if( pPrinter->GetName() != sPrinter )
    {
        OUString aString( PaResId( RID_ERR_NOPRINTER ) );
        aString = aString.replaceFirst( "%s", sPrinter );

        ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aString );
        aErrorBox.SetText( PaResId( RID_BXT_ENVIRONMENT ) );
        aErrorBox.Execute();
        return;
    }

    boost::shared_ptr<vcl::PrinterController> pController( new SpaPrinterController( pPrinter ) );
    JobSetup aJobSetup( pPrinter->GetJobSetup() );
    Printer::PrintJob( pController, aJobSetup );
}

void PADialog::AddDevice()
{
    AddPrinterDialog aDlg( this );

    if( aDlg.Execute() )
        UpdateDevice();
}

void PADialog::RemDevice()
{
    OUString aPrinter( getSelectedDevice() );
    OUString aDefPrinter( m_rPIManager.getDefaultPrinter() );
    // do not remove the default printer
    if( aPrinter.equals( aDefPrinter ) )
        return;

    if( ! m_rPIManager.removePrinter( aPrinter ) )
    {
        OUString aText( PaResId( RID_ERR_PRINTERNOTREMOVABLE ) );
        aText = aText.replaceFirst( "%s", aPrinter );
        ErrorBox aBox( this, WB_OK | WB_DEF_OK, aText );
        aBox.Execute();
        return;
    }
    m_aPrinters.remove( aPrinter );

    m_aDevicesLB.RemoveEntry( m_aDevicesLB.GetSelectEntryPos() );
    for (int i=0; i < m_aDevicesLB.GetEntryCount(); ++i)
    {
        if (m_aDevicesLB.GetEntry(i).equals(aDefPrinter))
        {
            m_aDevicesLB.SelectEntryPos( i, true );
            UpdateText();
            break;
        }
    }

    m_aDevicesLB.GetFocus();

    if( m_aDevicesLB.GetEntryCount() < 2 )
        m_aRemPB.Enable( false );
}

void PADialog::ConfigureDevice()
{
    OUString aPrinter(getSelectedDevice());

    if (aPrinter.isEmpty())
        return;

    PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aPrinter ) );
    RTSDialog aDialog( aInfo, aPrinter, true, this );

    if( aDialog.Execute() )
        m_rPIManager.changePrinterInfo( aPrinter, aDialog.getSetup() );

    UpdateText();
}

void PADialog::RenameDevice()
{
    OUString aPrinter( getSelectedDevice() );
    OUString aOldPrinter( aPrinter );

    if( aPrinter.isEmpty() )
        return;

    OUString aTmpString( PaResId( RID_QRY_PRTNAME ) );
    QueryString aQuery( this,
                        aTmpString,
                        aPrinter );
    aQuery.SetText( m_aRenameStr );
    aQuery.Execute();

    if( !aPrinter.isEmpty() )
    {
        PrinterInfo aInfo( m_rPIManager.getPrinterInfo( aOldPrinter ) );
        aInfo.m_aPrinterName = aPrinter;
        if( m_rPIManager.addPrinter( aPrinter, aInfo.m_aDriverName ) )
        {
            bool bWasDefault = m_rPIManager.getDefaultPrinter() == aOldPrinter;
            m_aPrinters.push_back( aPrinter );
            if( m_rPIManager.removePrinter( aOldPrinter ) )
                m_aPrinters.remove( aOldPrinter );
            m_rPIManager.changePrinterInfo( aPrinter, aInfo );
            if( bWasDefault )
            {
                m_rPIManager.setDefaultPrinter( aPrinter );
                UpdateDefPrt();
            }
            UpdateDevice();
        }
    }
}

void PADialog::UpdateDevice()
{
    m_aDevicesLB.Clear();

    m_rPIManager.listPrinters( m_aPrinters );
    ::std::list< OUString >::iterator it;
    for( it = m_aPrinters.begin(); it != m_aPrinters.end(); ++it )
    {
        const PrinterInfo& rInfo( m_rPIManager.getPrinterInfo( *it ) );
        sal_Int32 nIndex = 0;
        bool bAutoQueue = false;
        bool bPdf = false;
        while( nIndex != -1 && ! bAutoQueue )
        {
            OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
            if( !aToken.isEmpty() )
            {
                if( aToken.equalsAscii( "autoqueue" ) )
                    bAutoQueue = true;
                else if( aToken.startsWith("pdf=") )
                    bPdf = true;
            }
        }
        if( bAutoQueue )
            continue;

        OUString aEntry( *it );
        if( *it == m_rPIManager.getDefaultPrinter() )
        {
            aEntry += " (" + OUString( m_aDefPrt ) + ")";
        }
        int nPos =
            m_aDevicesLB.InsertEntry( aEntry,
                                      bPdf ? m_aPdfImg : m_aPrinterImg );
        m_aDevicesLB.SetEntryData( nPos, (void*)(sal_IntPtr)it->getLength() );
        if( *it == m_rPIManager.getDefaultPrinter() )
        {
            m_aDevicesLB.SelectEntryPos( nPos );
            UpdateText();
        }
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/padialog.hrc b/padmin/source/padialog.hrc
deleted file mode 100644
index cda3f2d..0000000
--- a/padmin/source/padialog.hrc
+++ /dev/null
@@ -1,139 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_PADIALOG_HRC_
#define _PAD_PADIALOG_HRC_

#define RID_PADIALOG                        1000
#define RID_PA_BTN_CANCEL                   1
#define RID_PA_BTN_STD                      2
#define RID_PA_BTN_DEL                      3
#define RID_PA_LB_DEV                       4
#define RID_PA_FL_PRINTERS                  5
#define RID_PA_BTN_CONF                     6
#define RID_PA_BTN_RENAME                   7
#define RID_PA_TESTPAGE                     8

#define RID_PA_TXT_DRIVER                   10
#define RID_PA_TXT_DRIVER_STRING            11
#define RID_PA_TXT_LOCATION                 12
#define RID_PA_TXT_LOCATION_STRING          13
#define RID_PA_TXT_COMMAND                  14
#define RID_PA_TXT_COMMAND_STRING           15
#define RID_PA_TXT_COMMENT                  16
#define RID_PA_TXT_COMMENT_STRING           17
#define RID_PA_STR_DEFPRT                   18
#define RID_PA_BTN_ADD                      19

#define RID_PA_STR_RENAME                   21
#define RID_PA_FL_SEPBUTTON                 22

#define RID_PPDIMPORT_DLG          1004
#define RID_PPDIMP_BTN_OK             1
#define RID_PPDIMP_BTN_CANCEL         2
#define RID_PPDIMP_BTN_SEARCH         3
#define RID_PPDIMP_TXT_DRIVER         4
#define RID_PPDIMP_LB_DRIVER          5
#define RID_PPDIMP_LB_PATH            6
#define RID_PPDIMP_GROUP_PATH         7
#define RID_PPDIMP_GROUP_DRIVER       8
#define RID_PPDIMP_TXT_PATH           9
#define RID_PPDIMP_STR_LOADINGPPD    10

#define RID_PA_TXT_TESTPAGE_PRINTED 1005

#define RID_ERR_PRINTERNOTREMOVABLE    1006
#define RID_ERR_NOWRITE            1009
#define RID_ERR_NOPRINTER          1013
#define RID_QRY_PRTNAME            1022

#define RID_BXT_TESTPAGE                1034
#define RID_BXT_ENVIRONMENT             1035

#define RID_YOU_SURE                    1040
#define RID_ERR_REMOVEDRIVERFAILED          1041
#define RID_BUTTERFLY                   1047
#define RID_ERR_REMOVESGENPRT               1051

#define RID_QUERY_REMOVEDRIVER          1058
#define RID_QUERY_REMOVEPRINTER         1059
#define RID_QUERY_DRIVERUSED            1062
#define RID_ERR_REMOVEDEFAULTDRIVER         1063

#define RID_TXT_TESTPAGE_MODEL                   1068
#define RID_TXT_TESTPAGE_QUEUE                   1069
#define RID_TXT_TESTPAGE_DATE                    1070
#define RID_TXT_TESTPAGE_TIME                    1071
#define RID_TXT_PRINTERALREADYEXISTS            1072
#define RID_TXT_TESTPAGE_COMMENT                1076
#define RID_TXT_TESTPAGE_NAME                    1077

#define RID_BMP_SMALL_PRINTER                    1096
#define RID_BMP_SMALL_PDF                        1100
#define RID_BMP_PRINTER                          1102

#define RID_PROGRESS_DLG                        1400
#define RID_PROGRESS_BTN_CANCEL                 1
#define RID_PROGRESS_OPERATION_TXT              2
#define RID_PROGRESS_PROGRESS_TXT               3
#define RID_PROGRESS_STATUSBAR                  5
#define RID_PROGRESS_FILENAME_TXT               6

#define RID_ADD_PRINTER_DIALOG                  2000
#define RID_ADDP_BTN_FINISH                     1
#define RID_ADDP_BTN_CANCEL                     2
#define RID_ADDP_BTN_NEXT                       3
#define RID_ADDP_BTN_PREV                       4
#define RID_ADDP_LINE                           5
#define RID_ADDP_CTRL_TITLE                     6
#define RID_ADDP_STR_TITLE                       127

#define RID_ADDP_PAGE_CHOOSEDRIVER              2002
#define RID_ADDP_CHDRV_TXT_DRIVER               1
#define RID_ADDP_CHDRV_BOX_DRIVER               2
#define RID_ADDP_CHDRV_BTN_ADD                  3
#define RID_ADDP_CHDRV_BTN_REMOVE               4
#define RID_ADDP_CHDRV_STR_REMOVE               5

#define RID_ADDP_PAGE_NAME                      2003
#define RID_ADDP_NAME_TXT_NAME                  1
#define RID_ADDP_NAME_TXT_PDFNAME               3
#define RID_ADDP_NAME_EDT_NAME                  4
#define RID_ADDP_NAME_EDT_PDFNAME               6
#define RID_ADDP_NAME_BOX_DEFAULT               7

#define RID_ADDP_PAGE_COMMAND                   2004
#define RID_ADDP_CMD_TXT_COMMAND                1
#define RID_ADDP_CMD_BOX_COMMAND                2
#define RID_ADDP_CMD_BTN_HELP                   3
#define RID_ADDP_CMD_STR_PDFHELP                5
#define RID_ADDP_CMD_TXT_PDFDIR                 6
#define RID_ADDP_CMD_EDT_PDFDIR                 7
#define RID_ADDP_CMD_BTN_PDFDIR                 8
#define RID_ADDP_CMD_BOX_PDFCOMMAND             9

#define RID_ADDP_PAGE_PDFDRIVER                 2007
#define RID_ADDP_PDFDRV_TXT_DRIVER              1
#define RID_ADDP_PDFDRV_BTN_DEFAULT             2
#define RID_ADDP_PDFDRV_BTN_DIST                3
#define RID_ADDP_PDFDRV_BTN_SELECT              4

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/padialog.hxx b/padmin/source/padialog.hxx
deleted file mode 100644
index 0f38ffd..0000000
--- a/padmin/source/padialog.hxx
+++ /dev/null
@@ -1,101 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_PADIALOG_HXX_
#define _PAD_PADIALOG_HXX_
#include <list>
#include <rtl/ustring.hxx>
#include <vcl/dialog.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>
#include <vcl/edit.hxx>
#include <helper.hxx>

// forward declaration
namespace psp { class PrinterInfoManager; }

namespace padmin {

    class SPA_DLLPUBLIC PADialog : public ModalDialog
    {
    private:
        DelListBox                          m_aDevicesLB;
        PushButton                          m_aConfPB;
        PushButton                          m_aRenamePB;
        PushButton                          m_aStdPB;
        PushButton                          m_aRemPB;
        PushButton                          m_aTestPagePB;
        FixedLine                           m_aPrintersFL;
        FixedText                           m_aDriverTxt;
        FixedText                           m_aDriver;
        FixedText                           m_aLocationTxt;
        FixedText                           m_aLocation;
        FixedText                           m_aCommandTxt;
        FixedText                           m_aCommand;
        FixedText                           m_aCommentTxt;
        FixedText                           m_aComment;

        FixedLine                           m_aSepButtonFL;
        PushButton                          m_aAddPB;
        CancelButton                        m_aCancelButton;

        OUString                            m_aDefPrt;
        OUString                            m_aRenameStr;

        ::psp::PrinterInfoManager&          m_rPIManager;
        ::std::list< OUString >      m_aPrinters;

        Image                               m_aPrinterImg;
        Image                               m_aPdfImg;

        DECL_LINK( ClickBtnHdl, PushButton* );
        DECL_LINK( DoubleClickHdl, ListBox* );
        DECL_LINK( SelectHdl, ListBox* );
        DECL_LINK( DelPressedHdl, ListBox* );

        PADialog( Window*,  sal_Bool );
        void Init();

        void UpdateDefPrt();
        void UpdateText();
        void UpdateDevice();
        void AddDevice();
        void RemDevice();
        void ConfigureDevice();
        void RenameDevice();
        void PrintTestPage();
        void updateSettings();

        virtual bool Notify( NotifyEvent& rEv );
        virtual void DataChanged( const DataChangedEvent& rEv );

        OUString getSelectedDevice();
    public:
        ~PADialog();

        static PADialog* Create( Window*,  sal_Bool );
    };

} // namespace

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/padialog.src b/padmin/source/padialog.src
deleted file mode 100644
index 74b2d09..0000000
--- a/padmin/source/padialog.src
+++ /dev/null
@@ -1,645 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "padialog.hrc"

ModalDialog RID_PADIALOG
{
    HelpID = "padmin:ModalDialog:RID_PADIALOG";
    OutputSize = TRUE ;
    SVLook = TRUE ;
    Size = MAP_APPFONT ( 260 , 198 ) ;
    Moveable = TRUE ;
    Closeable = TRUE ;

    FixedLine RID_PA_FL_SEPBUTTON
    {
        Pos = MAP_APPFONT( 0, 176 );
        Size = MAP_APPFONT( 260, 2 );
    };
    CancelButton RID_PA_BTN_CANCEL
    {
        DefButton = TRUE;
        Pos = MAP_APPFONT( 190, 181 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "Close";
    };

    FixedLine RID_PA_FL_PRINTERS
    {
        Pos = MAP_APPFONT( 6, 5 );
        Size = MAP_APPFONT( 248, 8 );
        Text [ en-US ] = "Installed ~printers";
    };
    ListBox RID_PA_LB_DEV
    {
        HelpID = "padmin:ListBox:RID_PADIALOG:RID_PA_LB_DEV";
        Pos = MAP_APPFONT( 12, 15 );
        Size = MAP_APPFONT( 168, 80 );
        Border = TRUE;
        Sort = TRUE;
    };
    FixedText RID_PA_TXT_COMMAND
    {
        Pos = MAP_APPFONT( 10, 100 );
        Size = MAP_APPFONT( 40, 8 );
        Text [ en-US ] = "Command:";
    };
    FixedText RID_PA_TXT_COMMAND_STRING
    {
        Pos = MAP_APPFONT( 55, 100 );
        Size = MAP_APPFONT( 135, 8 );
    };
    FixedText RID_PA_TXT_DRIVER
    {
        Pos = MAP_APPFONT( 10, 110 );
        Size = MAP_APPFONT( 40, 8 );
        Text [ en-US ] = "Driver:";
    };
    FixedText RID_PA_TXT_DRIVER_STRING
    {
        Pos = MAP_APPFONT( 55, 110 );
        Size = MAP_APPFONT( 135, 8 );
    };
    FixedText RID_PA_TXT_LOCATION
    {
        Pos = MAP_APPFONT( 10, 120 );
        Size = MAP_APPFONT( 40, 8 );
        Text [ en-US ] = "Location:";
    };
    FixedText RID_PA_TXT_LOCATION_STRING
    {
        Pos = MAP_APPFONT( 55, 120 );
        Size = MAP_APPFONT( 135, 8 );
    };
    FixedText RID_PA_TXT_COMMENT
    {
        Pos = MAP_APPFONT( 10, 130 );
        Size = MAP_APPFONT( 40, 8 );
        Text [ en-US ] = "Comment:";
    };
    FixedText RID_PA_TXT_COMMENT_STRING
    {
        Pos = MAP_APPFONT( 55, 130 );
        Size = MAP_APPFONT( 135, 8 );
    };
    PushButton RID_PA_BTN_CONF
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_BTN_CONF";
        Pos = MAP_APPFONT( 190, 15 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "Properties...";
    };
    PushButton RID_PA_BTN_RENAME
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_BTN_RENAME";
        Pos = MAP_APPFONT( 190, 32 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "R~ename...";
    };
    PushButton RID_PA_BTN_STD
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_BTN_STD";
        Pos = MAP_APPFONT( 190, 49 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "~Default";
    };
    PushButton RID_PA_BTN_DEL
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_BTN_DEL";
        Pos = MAP_APPFONT( 190, 66 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "Remo~ve...";
    };
    PushButton RID_PA_TESTPAGE
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_TESTPAGE";
        Pos = MAP_APPFONT( 190, 83 );
        Size = MAP_APPFONT( 60, 12 );
        Text [ en-US ] = "Test ~Page";
    };

    PushButton RID_PA_BTN_ADD
    {
        HelpID = "padmin:PushButton:RID_PADIALOG:RID_PA_BTN_ADD";
        Pos = MAP_APPFONT( 5, 181 );
        Size = MAP_APPFONT( 70, 12 );
        Text [ en-US ] = "New PDF Converter...";
    };

    String RID_PA_STR_DEFPRT
    {
        Text [ en-US ] = "Default printer";
    };
    String RID_PA_STR_RENAME
    {
        Text [ en-US ] = "Rename";
    };
    Text [ en-US ] = "Printer Administration";
};

String RID_ERR_NOPRINTER
{
    Text [ en-US ] = "Could not open printer %s.";
};

String RID_PA_TXT_TESTPAGE_PRINTED
{
    Text [ en-US ] = "The test page was printed successfully. Please check the result.";
};

String RID_ERR_NOWRITE
{
    Text [en-US] = "No printers can be installed, because the file system is read-only.\nPlease contact your system administrator.";
};

String RID_QRY_PRTNAME
{
    Text [ en-US ] = "~New printer name";
};

String RID_TXT_TESTPAGE_MODEL
{
    Text [ en-US ] = "Model";
};

String RID_TXT_TESTPAGE_NAME
{
    Text [ en-US ] = "Name";
};

String RID_TXT_TESTPAGE_COMMENT
{
    Text [ en-US ] = "Comment";
};

String RID_TXT_TESTPAGE_QUEUE
{
    Text [ en-US ] = "Queue";
};

String RID_TXT_TESTPAGE_DATE
{
    Text [ en-US ] = "Date";
};

String RID_TXT_TESTPAGE_TIME
{
    Text [ en-US ] = "Time";
};


String RID_BXT_TESTPAGE
{
    Text [ en-US ] = "Test page";
};

String RID_BXT_ENVIRONMENT
{
    Text [ en-US ] = "Wrong environment";
};

String RID_YOU_SURE
{
    Text [ en-US ] = "Are you sure ?";
};

Bitmap RID_BUTTERFLY
{
    File = "source/butter.png" ;
};

Bitmap RID_BMP_SMALL_PRINTER
{
    File = "source/print.png";
};

Bitmap RID_BMP_SMALL_PDF
{
    File = "source/pdf.png";
};

Bitmap RID_BMP_PRINTER
{
    File = "source/printer_large.png";
};

ModelessDialog RID_PROGRESS_DLG
{
    HelpID = "padmin:ModelessDialog:RID_PROGRESS_DLG";
    OutputSize = TRUE ;
    SVLook = TRUE ;
    Pos = MAP_APPFONT ( 10 , 10 ) ;
    Size = MAP_APPFONT ( 150 , 90 ) ;
    Moveable = TRUE ;
    Closeable = FALSE ;
    CancelButton RID_PROGRESS_BTN_CANCEL
    {
        Pos = MAP_APPFONT ( 50 , 71 ) ;
        Size = MAP_APPFONT ( 50 , 14 ) ;
    };
    FixedText RID_PROGRESS_OPERATION_TXT
    {
        Pos = MAP_APPFONT ( 6 , 6 ) ;
        Size = MAP_APPFONT ( 140 , 18 ) ;
    };
    FixedText RID_PROGRESS_PROGRESS_TXT
    {
        Pos = MAP_APPFONT( 6, 48 );
        Size = MAP_APPFONT( 140, 8 );
        Text [ en-US ] = "Progress";
    };
    Window RID_PROGRESS_STATUSBAR
    {
        SVLook = TRUE;
        Border = TRUE;
        Pos = MAP_APPFONT ( 6 , 58 ) ;
        Size = MAP_APPFONT( 140, 8 );
    };
    FixedText RID_PROGRESS_FILENAME_TXT
    {
        Pos = MAP_APPFONT ( 6 , 28 ) ;
        Size = MAP_APPFONT ( 140 , 8 ) ;
    };
    Text [ en-US ] = "Please wait";
};

ModalDialog RID_PPDIMPORT_DLG
{
    HelpID = "padmin:ModalDialog:RID_PPDIMPORT_DLG";
    OutputSize = TRUE ;
    SVLook = TRUE ;
    Size = MAP_APPFONT ( 265 , 225 ) ;
    Moveable = TRUE ;
    Closeable = TRUE ;

    FixedLine RID_PPDIMP_GROUP_PATH
    {
        Pos = MAP_APPFONT( 5, 5 );
        Size = MAP_APPFONT( 200, 8 );
        Text [ en-US ] = "Dri~ver directory";
    };
    FixedText RID_PPDIMP_TXT_PATH
    {
        Pos = MAP_APPFONT( 10, 33 );
        Size = MAP_APPFONT( 190, 8 );
        Text [ en-US ] = "Please select the driver directory.";
    };
    ComboBox RID_PPDIMP_LB_PATH
    {
        HelpID = "padmin:ComboBox:RID_PPDIMPORT_DLG:RID_PPDIMP_LB_PATH";
        Dropdown = TRUE;
        Border = TRUE;
        Sort = TRUE;

        Pos = MAP_APPFONT( 10, 15 );
        Size = MAP_APPFONT( 130, 80 );
    };
    PushButton RID_PPDIMP_BTN_SEARCH
    {
        HelpID = "padmin:PushButton:RID_PPDIMPORT_DLG:RID_PPDIMP_BTN_SEARCH";
        Pos = MAP_APPFONT( 145, 15 );
        Size = MAP_APPFONT( 50, 14 );
        Text [ en-US ] = "Browse...";
    };

    FixedLine RID_PPDIMP_GROUP_DRIVER
    {
        Pos = MAP_APPFONT( 5, 60 );
        Size = MAP_APPFONT( 200, 8 );
        Text [ en-US ] = "~Selection of drivers";
    };
    MultiListBox RID_PPDIMP_LB_DRIVER
    {
        HelpID = "padmin:MultiListBox:RID_PPDIMPORT_DLG:RID_PPDIMP_LB_DRIVER";
        Border = TRUE;
        Sort = TRUE;
        SimpleMode = TRUE;
        AutoHScroll = TRUE;
        Pos = MAP_APPFONT( 10, 70 );
        Size = MAP_APPFONT( 190, 120 );
    };
    FixedText RID_PPDIMP_TXT_DRIVER
    {
        Pos = MAP_APPFONT( 10, 195 );
        Size = MAP_APPFONT( 190, 60 );
        WordBreak = TRUE;
        Text [ en-US ] = "Please select the drivers to install and press \"%s\".";
    };
    String RID_PPDIMP_STR_LOADINGPPD
    {
        Text [ en-US ] = "Searching for drivers";
    };
    OKButton RID_PPDIMP_BTN_OK
    {
        DefButton = TRUE;
        Pos = MAP_APPFONT( 210, 10 );
        Size = MAP_APPFONT( 50, 14 );
    };
    CancelButton RID_PPDIMP_BTN_CANCEL
    {
        Pos = MAP_APPFONT( 210, 29 );
        Size = MAP_APPFONT( 50, 14 );
    };

    Text [ en-US ] = "Driver Installation";
};

String RID_QUERY_REMOVEDRIVER
{
    Text [ en-US ] = "Do you really want to remove the driver \"%s\"?";
};

String RID_QUERY_REMOVEPRINTER
{
    Text [ en-US ] = "Do you really want to remove this printer ?";
};

String RID_QUERY_DRIVERUSED
{
    Text [ en-US ] = "There are still printers using the driver \"%s\". Do you really want to remove it? The corresponding printers will also be removed.";
};

String RID_ERR_REMOVESGENPRT
{
    Text [ en-US ] = "The driver \"%s\" is always needed and can therefore not be removed.";
};

String RID_ERR_REMOVEDRIVERFAILED
{
    Text [ en-US ] = "The driver \"%s1\" could not be removed. It was not possible to remove the file\n\n%s2.";
};

String RID_ERR_REMOVEDEFAULTDRIVER
{
    Text [ en-US ] = "The driver \"%s\" is used by your default printer. Therefore, it cannot be removed.";
};

String RID_ERR_PRINTERNOTREMOVABLE
{
    Text [ en-US ] = "The printer %s cannot be removed.";
};

String RID_TXT_PRINTERALREADYEXISTS
{
    Text [ en-US ] = "A printer named \"%s\" already exists. This printer will not be imported.";
};

ModalDialog RID_ADD_PRINTER_DIALOG
{
    HelpID = "padmin:ModalDialog:RID_ADD_PRINTER_DIALOG";
    OutputSize = TRUE ;
    SVLook = TRUE ;
    Size = MAP_APPFONT ( 240 , 172 ) ;
    Moveable = TRUE ;
    Closeable = TRUE ;

    Control RID_ADDP_CTRL_TITLE
    {
        Pos = MAP_APPFONT( 0, 0 );
        Size = MAP_APPFONT( 240, 26 );
    };
    FixedLine RID_ADDP_LINE
    {
        Pos = MAP_APPFONT( 0, 150 );
        Size = MAP_APPFONT( 240, 2 );
    };
    OKButton RID_ADDP_BTN_FINISH
    {
        Pos = MAP_APPFONT( 185, 155 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Finish";
    };
    CancelButton RID_ADDP_BTN_CANCEL
    {
        Pos = MAP_APPFONT( 5, 155 );
        Size = MAP_APPFONT( 50, 12 );
    };
    PushButton RID_ADDP_BTN_NEXT
    {
        HelpID = "padmin:PushButton:RID_ADD_PRINTER_DIALOG:RID_ADDP_BTN_NEXT";
        Pos = MAP_APPFONT( 130, 155 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Next >>";
    };
    PushButton RID_ADDP_BTN_PREV
    {
        HelpID = "padmin:PushButton:RID_ADD_PRINTER_DIALOG:RID_ADDP_BTN_PREV";
        Pos = MAP_APPFONT( 75, 155 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "<< ~Back";
    };
    Text [ en-US ] = "Add Printer";
};

TabPage RID_ADDP_PAGE_CHOOSEDRIVER
{
    HelpID = "padmin:TabPage:RID_ADDP_PAGE_CHOOSEDRIVER";
    Hide = TRUE;
    Pos = MAP_APPFONT( 0, 30 );
    Size = MAP_APPFONT( 240, 120 );
    String RID_ADDP_STR_TITLE
    {
        Text [ en-US ] = "Choose a driver";
    };
    FixedText RID_ADDP_CHDRV_TXT_DRIVER
    {
        Pos = MAP_APPFONT( 5, 5 );
        Size = MAP_APPFONT( 230, 8 );
        Text [ en-US ] = "Please select a s~uitable driver.";
    };
    ListBox RID_ADDP_CHDRV_BOX_DRIVER
    {
        HelpID = "padmin:ListBox:RID_ADDP_PAGE_CHOOSEDRIVER:RID_ADDP_CHDRV_BOX_DRIVER";
        Pos = MAP_APPFONT( 5, 15 );
        Size = MAP_APPFONT( 175, 100 );
        Border = TRUE;
        Sort = TRUE;
    };
    PushButton RID_ADDP_CHDRV_BTN_ADD
    {
        HelpID = "padmin:PushButton:RID_ADDP_PAGE_CHOOSEDRIVER:RID_ADDP_CHDRV_BTN_ADD";
        Pos = MAP_APPFONT( 185, 15 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Import...";
    };
    PushButton RID_ADDP_CHDRV_BTN_REMOVE
    {
        HelpID = "padmin:PushButton:RID_ADDP_PAGE_CHOOSEDRIVER:RID_ADDP_CHDRV_BTN_REMOVE";
        Pos = MAP_APPFONT( 185, 32 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Delete";
    };
    String RID_ADDP_CHDRV_STR_REMOVE
    {
        Text [ en-US ] = "Delete driver";
    };
};

TabPage RID_ADDP_PAGE_NAME
{
    HelpID = "padmin:TabPage:RID_ADDP_PAGE_NAME";
    Hide = TRUE;
    Pos = MAP_APPFONT( 0, 30 );
    Size = MAP_APPFONT( 240, 120 );
    String RID_ADDP_STR_TITLE
    {
        Text [ en-US ] = "Choose a name";
    };
    FixedText RID_ADDP_NAME_TXT_NAME
    {
        Pos = MAP_APPFONT( 40, 25 );
        Size = MAP_APPFONT( 220, 8 );
        Text [ en-US ] = "Please enter a name for the printer.";
    };
    FixedText RID_ADDP_NAME_TXT_PDFNAME
    {
        Pos = MAP_APPFONT( 40, 25 );
        Size = MAP_APPFONT( 220, 8 );
        Text [ en-US ] = "Please enter a name for the PDF connection.";
    };
    Edit RID_ADDP_NAME_EDT_NAME
    {
        HelpID = "padmin:Edit:RID_ADDP_PAGE_NAME:RID_ADDP_NAME_EDT_NAME";
        Pos = MAP_APPFONT( 40, 35 );
        Size = MAP_APPFONT( 160, 12 );
        Border = TRUE;
    };
    Edit RID_ADDP_NAME_EDT_PDFNAME
    {
        HelpID = "padmin:Edit:RID_ADDP_PAGE_NAME:RID_ADDP_NAME_EDT_PDFNAME";
        Pos = MAP_APPFONT( 40, 35 );
        Size = MAP_APPFONT( 160, 12 );
        Border = TRUE;
        Text [ en-US ] = "PDF converter";
    };
    CheckBox RID_ADDP_NAME_BOX_DEFAULT
    {
        HelpID = "padmin:CheckBox:RID_ADDP_PAGE_NAME:RID_ADDP_NAME_BOX_DEFAULT";
        Pos = MAP_APPFONT( 40, 50 );
        Size = MAP_APPFONT( 160, 12 );
        Text [ en-US ] = "~Use as default printer";
    };
};

TabPage RID_ADDP_PAGE_COMMAND
{
    HelpID = "padmin:TabPage:RID_ADDP_PAGE_COMMAND";
    Hide = TRUE;
    Pos = MAP_APPFONT( 0, 30 );
    Size = MAP_APPFONT( 240, 120 );
    String RID_ADDP_STR_TITLE
    {
        Text [ en-US ] = "Choose a command line";
    };
    FixedText RID_ADDP_CMD_TXT_COMMAND
    {
        Pos = MAP_APPFONT( 10, 2 );
        Size = MAP_APPFONT( 160, 24 );
        WordBreak = TRUE;
        Text [ en-US ] = "Please enter a c~ommand line appropriate for this device.";
    };
    ComboBox RID_ADDP_CMD_BOX_COMMAND
    {
        HelpID = "padmin:ComboBox:RID_ADDP_PAGE_COMMAND:RID_ADDP_CMD_BOX_COMMAND";
        Pos = MAP_APPFONT( 10, 30);
        Size = MAP_APPFONT( 220, 85 );
        Border = TRUE;
    };
    ComboBox RID_ADDP_CMD_BOX_PDFCOMMAND
    {
        HelpID = "padmin:ComboBox:RID_ADDP_PAGE_COMMAND:RID_ADDP_CMD_BOX_PDFCOMMAND";
        Pos = MAP_APPFONT( 10, 30);
        Size = MAP_APPFONT( 220, 60 );
        Border = TRUE;
    };
    FixedText RID_ADDP_CMD_TXT_PDFDIR
    {
        Pos = MAP_APPFONT( 10, 95 );
        Size = MAP_APPFONT( 220, 8 );
        Text [ en-US ] = "PDF ~target directory";
    };
    Edit RID_ADDP_CMD_EDT_PDFDIR
    {
        HelpID = "padmin:Edit:RID_ADDP_PAGE_COMMAND:RID_ADDP_CMD_EDT_PDFDIR";
        Border = TRUE;
        Pos = MAP_APPFONT( 10, 104 );
        Size = MAP_APPFONT( 190, 12 );
    };
    PushButton RID_ADDP_CMD_BTN_PDFDIR
    {
        HelpID = "padmin:PushButton:RID_ADDP_PAGE_COMMAND:RID_ADDP_CMD_BTN_PDFDIR";
        Pos = MAP_APPFONT( 205, 104 );
        Size = MAP_APPFONT( 25, 12 );
        Text = "~...";
    };
    PushButton RID_ADDP_CMD_BTN_HELP
    {
        HelpID = "padmin:PushButton:RID_ADDP_PAGE_COMMAND:RID_ADDP_CMD_BTN_HELP";
        Pos = MAP_APPFONT( 180, 2 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Help";
    };
    String RID_ADDP_CMD_STR_PDFHELP
    {
        Text [ en-US ] = "The command line for PDF converters is executed as follows: for each document printed, \"(TMP)\" in the command line is replaced by a temporary file and \"(OUTFILE)\" in the command line is replaced by the target PDF file name. If \"(TMP)\" is in the command line, the PostScript code will be supplied via a file, otherwise via standard input (i.e. as a pipe).";
    };
};

TabPage RID_ADDP_PAGE_PDFDRIVER
{
    HelpID = "padmin:TabPage:RID_ADDP_PAGE_PDFDRIVER";
    Hide = TRUE;
    Pos = MAP_APPFONT( 0, 30 );
    Size = MAP_APPFONT( 240, 120 );
    String RID_ADDP_STR_TITLE
    {
        Text [ en-US ] = "Choose a driver";
    };
    FixedText RID_ADDP_PDFDRV_TXT_DRIVER
    {
        Pos = MAP_APPFONT( 40, 20 );
        Size = MAP_APPFONT( 160, 19 );
        WordBreak = TRUE;
        Text [ en-US ] = "Use the following driver for this PDF converter";
    };
    RadioButton RID_ADDP_PDFDRV_BTN_DEFAULT
    {
        HelpID = "padmin:RadioButton:RID_ADDP_PAGE_PDFDRIVER:RID_ADDP_PDFDRV_BTN_DEFAULT";
        Pos = MAP_APPFONT( 40, 40 );
        Size = MAP_APPFONT( 160, 10 );
        Text [ en-US ] = "T~he default driver";
    };
    RadioButton RID_ADDP_PDFDRV_BTN_DIST
    {
        HelpID = "padmin:RadioButton:RID_ADDP_PAGE_PDFDRIVER:RID_ADDP_PDFDRV_BTN_DIST";
        Pos = MAP_APPFONT( 40,50 );
        Size = MAP_APPFONT( 160, 10 );
        Text [ en-US ] = "The Adobe D~istiller(tm) driver";
    };
    RadioButton RID_ADDP_PDFDRV_BTN_SELECT
    {
        HelpID = "padmin:RadioButton:RID_ADDP_PAGE_PDFDRIVER:RID_ADDP_PDFDRV_BTN_SELECT";
        Pos = MAP_APPFONT( 40, 60 );
        Size = MAP_APPFONT( 160, 24 );
        Text [ en-US ] = "A spec~ific driver, to adapt the format to another printer";
    };
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/pamain.cxx b/padmin/source/pamain.cxx
deleted file mode 100644
index a1f6c31..0000000
--- a/padmin/source/pamain.cxx
+++ /dev/null
@@ -1,157 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <stdio.h>
#include <unistd.h>

#include "vcl/svapp.hxx"
#include "vcl/vclmain.hxx"
#include "vcl/wrkwin.hxx"
#include "vcl/unowrap.hxx"
#include <vcl/settings.hxx>

#include "padialog.hxx"
#include "helper.hxx"
#include "desktopcontext.hxx"

#include "cppuhelper/bootstrap.hxx"
#include "comphelper/processfactory.hxx"
#include "unotools/configmgr.hxx"

#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/lang/XComponent.hpp"
#include "com/sun/star/ucb/UniversalContentBroker.hpp"

using namespace padmin;
using namespace cppu;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace comphelper;


class MyApp : public Application
{
public:
    int Main();
    virtual sal_uInt16  Exception( sal_uInt16 nError );

    static OUString ReadStringHook( const OUString& );

private:
    virtual void Init() SAL_OVERRIDE;

    Reference< XComponentContext > xCtx_;
};

void vclmain::createApplication()
{
    static MyApp aMyApp;
}

OUString MyApp::ReadStringHook( const OUString& rStr )
{
    return rStr.replaceAll(
        OUString("%PRODUCTNAME"), utl::ConfigManager::getProductName() );
};




sal_uInt16 MyApp::Exception( sal_uInt16 nError )
{
    switch( nError & EXC_MAJORTYPE )
    {
        case EXC_RSCNOTLOADED:
            Abort( OUString( "Error: could not load language resources.\nPlease check your installation.\n" ) );
            break;
    }
    return 0;
}

int MyApp::Main()
{
    PADialog* pPADialog;

    EnableAutoHelpId();

    // Detect desktop environment - need to do this as early as possible
    com::sun::star::uno::setCurrentContext(
        new DesktopContext( com::sun::star::uno::getCurrentContext() ) );

    // Create UCB (for backwards compatibility, in case some code still uses
    // plain createInstance w/o args directly to obtain an instance):
    com::sun::star::ucb::UniversalContentBroker::create(xCtx_);

    /*
     * Initialize the MSAA UNO AccessBridge if accessibility is turned on
     */

    if( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() )
    {
        if( !InitAccessBridge() )
            return EXIT_FAILURE;
    }

    ResMgr::SetReadStringHook( MyApp::ReadStringHook );

    pPADialog = PADialog::Create( NULL , sal_False );
    Application::SetDisplayName( pPADialog->GetText() );
    pPADialog->SetIcon(501);
    pPADialog->Execute();
    delete pPADialog;

    /*
     *  clean up UNO
     */
    try
    {
        Reference<XComponent> xComp(xCtx_, UNO_QUERY_THROW);
        xComp->dispose();
    }
    catch(...)
    {
    }

    return EXIT_SUCCESS;
}

void MyApp::Init()
{
    // create the global service-manager

    Reference< XMultiServiceFactory > xFactory;
    try
    {
        xCtx_ = defaultBootstrap_InitialComponentContext();
        xFactory = Reference< XMultiServiceFactory >(  xCtx_->getServiceManager(), UNO_QUERY );
        if( xFactory.is() )
            setProcessServiceFactory( xFactory );
    }
    catch( const com::sun::star::uno::Exception& )
    {
    }

    if( ! xFactory.is() )
    {
        fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
        exit( 1 );
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/progress.cxx b/padmin/source/progress.cxx
deleted file mode 100644
index 8c7f7d0..0000000
--- a/padmin/source/progress.cxx
+++ /dev/null
@@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <ctype.h>
#include <stdio.h>
#include <rtl/ustring.hxx>
#include <tools/stream.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <progress.hxx>
#include <helper.hxx>
#include <padialog.hrc>

using namespace padmin;

ProgressDialog::ProgressDialog( Window* pParent,
                                sal_Bool bCancelable,
                                int nMin, int nMax ) :
        ModelessDialog( pParent, PaResId( RID_PROGRESS_DLG ) ),
        maOperation( this, PaResId( RID_PROGRESS_OPERATION_TXT ) ),
        maFilename( this, PaResId( RID_PROGRESS_FILENAME_TXT ) ),
        maProgressTxt( this, PaResId( RID_PROGRESS_PROGRESS_TXT ) ),
        maCancelButton( this, PaResId( RID_PROGRESS_BTN_CANCEL ) ),
        maProgressBar( this, PaResId( RID_PROGRESS_STATUSBAR ) ),
        mnMax( nMax ),
        mnMin( nMin ),
        mbCanceled( false )
{
    maFilename.SetStyle( maFilename.GetStyle() | WB_PATHELLIPSIS );
    if( ! bCancelable )
    {
        Point aPos = maProgressBar.GetPosPixel();
        Size aSize = maProgressBar.GetSizePixel();
        Size aMySize = GetOutputSizePixel();
        aMySize.Height() = aPos.Y() + aSize.Height() + 5;
        SetOutputSizePixel( aMySize );
    }
    else
        maCancelButton.SetClickHdl( LINK( this, ProgressDialog, ClickBtnHdl ) );
    FreeResource();
}

ProgressDialog::~ProgressDialog()
{
}

void ProgressDialog::startOperation( const OUString& rOperation )
{
    maOperation.SetText( rOperation );
    maProgressBar.SetValue( 0 );
    mbCanceled = false;
    if( ! IsVisible() )
        Show( true );
}

void ProgressDialog::setValue( int nValue )
{
    maProgressBar.SetValue( nValue * 100 / ( mnMax - mnMin ) );
    Application::Reschedule();
}

void ProgressDialog::setFilename( const OUString& rFilename )
{
    maFilename.SetText( rFilename );
    maFilename.Update();
    Flush();
}

IMPL_LINK( ProgressDialog, ClickBtnHdl, Button*, pButton )
{
    if( pButton == &maCancelButton )
    {
        mbCanceled = true;
    }
    return 0;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/progress.hxx b/padmin/source/progress.hxx
deleted file mode 100644
index 9b3db6c..0000000
--- a/padmin/source/progress.hxx
+++ /dev/null
@@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_PROGRESS_HXX_
#define _PAD_PROGRESS_HXX_

#include "vcl/dialog.hxx"
#include "vcl/fixed.hxx"
#include "vcl/button.hxx"
#include "vcl/prgsbar.hxx"

namespace padmin {

    class ProgressDialog : public ModelessDialog
    {
        FixedText                       maOperation;
        FixedText                       maFilename;
        FixedText                       maProgressTxt;
        CancelButton                    maCancelButton;
        ProgressBar                     maProgressBar;

        int mnMax, mnMin;
        bool mbCanceled;

    public:
        ProgressDialog( Window*, sal_Bool bCancelable = sal_True, int nMin = 0, int nMax = 100 );
        ~ProgressDialog();

        DECL_LINK( ClickBtnHdl, Button* );

        void setValue( int nValue );
        void setRange( int nMin, int nMax ) { mnMin = nMin; mnMax = nMax; }
        void startOperation( const OUString& );
        void setFilename( const OUString& );

        bool isCanceled() { return mbCanceled; }
    };

} // namespace

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/prtsetup.cxx b/padmin/source/prtsetup.cxx
index 39911b5..bda0d01 100644
--- a/padmin/source/prtsetup.cxx
+++ b/padmin/source/prtsetup.cxx
@@ -20,7 +20,6 @@
#include "prtsetup.hxx"
#include "helper.hxx"
#include "rtsetup.hrc"
#include "cmddlg.hxx"

#include "osl/thread.h"

@@ -74,14 +73,12 @@ void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, con
 * RTSDialog
 */

RTSDialog::RTSDialog( const PrinterInfo& rJobData, const OUString& rPrinter, bool bAllPages, Window* pParent )
    : TabDialog(pParent, "PrinterPropertiesDialog", "spa/ui/printerpropertiesdialog.ui" )
RTSDialog::RTSDialog(const PrinterInfo& rJobData, const OUString& rPrinter, Window* pParent)
    : TabDialog(pParent, "PrinterPropertiesDialog", "spa/ui/printerpropertiesdialog.ui")
    , m_aJobData(rJobData)
    , m_aPrinter(rPrinter)
    , m_pPaperPage(NULL)
    , m_pDevicePage(NULL)
    , m_pOtherPage(NULL)
    , m_pCommandPage(NULL)
    , m_aInvalidString(PaResId(RID_RTS_RTSDIALOG_INVALID_TXT).toString())
{
    get(m_pOKButton, "ok");
@@ -91,35 +88,18 @@ RTSDialog::RTSDialog( const PrinterInfo& rJobData, const OUString& rPrinter, boo
    OUString aTitle(GetText());
    SetText(aTitle.replaceAll("%s", m_aJobData.m_aPrinterName));

    if( ! bAllPages )
    {
        m_pTabControl->RemovePage(m_pTabControl->GetPageId("other"));
        m_pTabControl->RemovePage(m_pTabControl->GetPageId("command"));
    }
    else if (m_aJobData.m_aDriverName.startsWith("CUPS:"))
    {
        // command page makes no sense for CUPS printers
        m_pTabControl->RemovePage(m_pTabControl->GetPageId("command"));
    }

    m_pTabControl->SetActivatePageHdl( LINK( this, RTSDialog, ActivatePage ) );
    m_pOKButton->SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
    m_pCancelButton->SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
    ActivatePage(m_pTabControl);
}



RTSDialog::~RTSDialog()
{
    delete m_pPaperPage;
    delete m_pDevicePage;
    delete m_pOtherPage;
    delete m_pCommandPage;
}



IMPL_LINK( RTSDialog, ActivatePage, TabControl*, pTabCtrl )
{
    if( pTabCtrl != m_pTabControl )
@@ -134,10 +114,6 @@ IMPL_LINK( RTSDialog, ActivatePage, TabControl*, pTabCtrl )
            pPage = m_pPaperPage = new RTSPaperPage( this );
        else if (sPage == "device")
            pPage = m_pDevicePage = new RTSDevicePage( this );
        else if (sPage == "other")
            pPage = m_pOtherPage = new RTSOtherPage( this );
        else if (sPage == "command")
            pPage = m_pCommandPage = new RTSCommandPage( this );
        if( pPage )
            m_pTabControl->SetTabPage( nId, pPage );
    }
@@ -172,13 +148,6 @@ IMPL_LINK( RTSDialog, ClickButton, Button*, pButton )
            m_aJobData.m_nPSLevel       = m_pDevicePage->getLevel();
            m_aJobData.m_nPDFDevice     = m_pDevicePage->getPDFDevice();
        }
        if( m_pOtherPage )
            // write other settings
            m_pOtherPage->save();
        if( m_pCommandPage )
            // write command settings
            m_pCommandPage->save();

        EndDialog( 1 );
    }
    else if( pButton == m_pCancelButton )
@@ -194,7 +163,7 @@ IMPL_LINK( RTSDialog, ClickButton, Button*, pButton )
 */

RTSPaperPage::RTSPaperPage(RTSDialog* pParent)
    : TabPage(pParent->m_pTabControl, "PrinterPaperPage", "spa/ui/printerpaperpage.ui" )
    : TabPage(pParent->m_pTabControl, "PrinterPaperPage", "spa/ui/printerpaperpage.ui")
    , m_pParent( pParent )
{
    get(m_pPaperText, "paperft");
@@ -503,119 +472,6 @@ void RTSDevicePage::FillValueBox( const PPDKey* pKey )
    m_pPPDValueBox->SelectEntryPos( m_pPPDValueBox->GetEntryPos( (void*)pValue ) );
}



/*
 * RTSOtherPage
 */

RTSOtherPage::RTSOtherPage( RTSDialog* pParent ) :
        TabPage( pParent->m_pTabControl, PaResId( RID_RTS_OTHERPAGE ) ),
        m_pParent( pParent ),
        m_aLeftTxt( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_TXT ) ),
        m_aLeftLB( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_BOX ) ),
        m_aTopTxt( this, PaResId( RID_RTS_OTHER_TOPMARGIN_TXT ) ),
        m_aTopLB( this, PaResId( RID_RTS_OTHER_TOPMARGIN_BOX ) ),
        m_aRightTxt( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_TXT ) ),
        m_aRightLB( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_BOX ) ),
        m_aBottomTxt( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_TXT ) ),
        m_aBottomLB( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_BOX ) ),
        m_aCommentTxt( this, PaResId( RID_RTS_OTHER_COMMENT_TXT ) ),
        m_aCommentEdt( this, PaResId( RID_RTS_OTHER_COMMENT_EDT ) ),
        m_aDefaultBtn( this, PaResId( RID_RTS_OTHER_DEFAULT_BTN ) )
{
    FreeResource();

    m_aTopLB.EnableEmptyFieldValue( true );
    m_aBottomLB.EnableEmptyFieldValue( true );
    m_aLeftLB.EnableEmptyFieldValue( true );
    m_aRightLB.EnableEmptyFieldValue( true );

    m_aDefaultBtn.SetClickHdl( LINK( this, RTSOtherPage, ClickBtnHdl ) );

    initValues();
}



RTSOtherPage::~RTSOtherPage()
{
}



void RTSOtherPage::initValues()
{
    int nMarginLeft = 0;
    int nMarginTop = 0;
    int nMarginRight = 0;
    int nMarginBottom = 0;

    if( m_pParent->m_aJobData.m_pParser )
    {
        m_pParent->m_aJobData.m_pParser->
            getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
                        nMarginLeft,
                        nMarginRight,
                        nMarginTop,
                        nMarginBottom );
    }

    nMarginLeft     += m_pParent->m_aJobData.m_nLeftMarginAdjust;
    nMarginRight    += m_pParent->m_aJobData.m_nRightMarginAdjust;
    nMarginTop      += m_pParent->m_aJobData.m_nTopMarginAdjust;
    nMarginBottom   += m_pParent->m_aJobData.m_nBottomMarginAdjust;

    m_aLeftLB.SetValue( nMarginLeft, FUNIT_POINT );
    m_aRightLB.SetValue( nMarginRight, FUNIT_POINT );
    m_aTopLB.SetValue( nMarginTop, FUNIT_POINT );
    m_aBottomLB.SetValue( nMarginBottom, FUNIT_POINT );
    m_aCommentEdt.SetText( m_pParent->m_aJobData.m_aComment );
}



void RTSOtherPage::save()
{
    int nMarginLeft = 0;
    int nMarginTop = 0;
    int nMarginRight = 0;
    int nMarginBottom = 0;

    if( m_pParent->m_aJobData.m_pParser )
    {
        m_pParent->m_aJobData.m_pParser->
            getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
                        nMarginLeft,
                        nMarginRight,
                        nMarginTop,
                        nMarginBottom );
    }

    m_pParent->m_aJobData.m_nLeftMarginAdjust   = m_aLeftLB.GetValue( FUNIT_POINT ) - nMarginLeft;
    m_pParent->m_aJobData.m_nRightMarginAdjust  = m_aRightLB.GetValue( FUNIT_POINT ) - nMarginRight;
    m_pParent->m_aJobData.m_nTopMarginAdjust    = m_aTopLB.GetValue( FUNIT_POINT ) - nMarginTop;
    m_pParent->m_aJobData.m_nBottomMarginAdjust = m_aBottomLB.GetValue( FUNIT_POINT ) - nMarginBottom;
    m_pParent->m_aJobData.m_aComment = m_aCommentEdt.GetText();
}



IMPL_LINK( RTSOtherPage, ClickBtnHdl, Button*, pButton )
{
    if( pButton == &m_aDefaultBtn )
    {
        m_pParent->m_aJobData.m_nLeftMarginAdjust =
            m_pParent->m_aJobData.m_nRightMarginAdjust =
            m_pParent->m_aJobData.m_nTopMarginAdjust =
            m_pParent->m_aJobData.m_nBottomMarginAdjust = 0;

        initValues();
    }
    return 0;
}


class RTSPWDialog : public ModalDialog
{
    FixedText       m_aText;
diff --git a/padmin/source/prtsetup.hxx b/padmin/source/prtsetup.hxx
index c939386..f5638c7 100644
--- a/padmin/source/prtsetup.hxx
+++ b/padmin/source/prtsetup.hxx
@@ -39,15 +39,11 @@ namespace padmin {

class RTSPaperPage;
class RTSDevicePage;
class RTSOtherPage;
class RTSCommandPage;

class RTSDialog : public TabDialog
{
    friend class RTSPaperPage;
    friend class RTSDevicePage;
    friend class RTSOtherPage;
    friend class RTSCommandPage;

    ::psp::PrinterInfo      m_aJobData;
    OUString                m_aPrinter;
@@ -60,8 +56,6 @@ class RTSDialog : public TabDialog
    // pages
    RTSPaperPage*           m_pPaperPage;
    RTSDevicePage*          m_pDevicePage;
    RTSOtherPage*           m_pOtherPage;
    RTSCommandPage*         m_pCommandPage;

    // some resources
    OUString                m_aInvalidString;
@@ -72,7 +66,7 @@ class RTSDialog : public TabDialog
    // helper functions
    void insertAllPPDValues( ListBox&, const psp::PPDParser*, const psp::PPDKey* );
public:
    RTSDialog( const ::psp::PrinterInfo& rJobData, const OUString& rPrinter, bool bAllPages, Window* pParent = NULL );
    RTSDialog(const ::psp::PrinterInfo& rJobData, const OUString& rPrinter, Window* pParent = NULL);
    ~RTSDialog();

    const ::psp::PrinterInfo& getSetup() const { return m_aJobData; }
@@ -132,33 +126,6 @@ public:
    sal_uLong getColorDevice();
};

class RTSOtherPage : public TabPage
{
    RTSDialog*          m_pParent;

    FixedText           m_aLeftTxt;
    MetricField         m_aLeftLB;
    FixedText           m_aTopTxt;
    MetricField         m_aTopLB;
    FixedText           m_aRightTxt;
    MetricField         m_aRightLB;
    FixedText           m_aBottomTxt;
    MetricField         m_aBottomLB;
    FixedText           m_aCommentTxt;
    Edit                m_aCommentEdt;
    PushButton          m_aDefaultBtn;

    void initValues();

    DECL_LINK( ClickBtnHdl, Button *);

public:
    RTSOtherPage( RTSDialog* );
    ~RTSOtherPage();

    void save();
};

} // namespace

#endif // _PAD_PRTSETUP_HXX
diff --git a/padmin/source/psetupl.xpm b/padmin/source/psetupl.xpm
deleted file mode 100644
index ffad105..0000000
--- a/padmin/source/psetupl.xpm
+++ /dev/null
@@ -1,67 +0,0 @@
/* XPM */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

static char * L3PSetup_m_pm[] = {
/* width height ncolors cpp [x_hot y_hot] */
"32 32 11 1 0 0",
/* colors */
" 	s none	m none	c none",
".	s iconColor1	m black	c black",
"X	c #000000008617",
"o	c #861782078617",
"O	s iconColor2	m white	c white",
"+	c #C71BC30BC71B",
"@	s iconColor6	m white	c yellow",
"#	c #00000000FFFF",
"$	c #861782070000",
"%	c #000082078617",
"&	c #861700000000",
/* pixels */
"                                ",
"                  ........  XXXX",
"           .o..oo.OOOOOOO+..X+OX",
"          .+ooOO.@OO@OOOO@OOXOOX",
"         .+oo+O.OO.OOOOOOOOOXXXX",
"        .+oo+O.O@.OOO@OOOO@OXXXX",
"       .+oo+O.@O.O@O.OO@OOOOXXXX",
"      .+oo+O.OO.+.O.OOOOOOOOXXXX",
"     .+oo+O.O@.+O+.O@O.OOO..X.X.",
"    .+oo+O+...+O++o.O.OO@.  .X. ",
"   .+oo+O+O+O+O++++o.@O..o  ... ",
"  .ooo+O+O+O+O++++ooo..         ",
" .ooo+O+O+O+O++++o..+Oo         ",
" .oo+O+O+O+O++++o....OO.        ",
" ..+O+O+O+O++++o......OO.       ",
" .o+OO+O+O++#+o....$o..OO.      ",
" .oo+OO+O++%+o....$$$...Oo.     ",
" .ooo+OO++&+o...$$$+$+...o.     ",
" .oooo+O+++o...$$$+$+++..o.     ",
" .oooooOO+o.o.$$++$+OoOO..o     ",
" .ooooo+Oo..O.$++$OOoOO$O.o     ",
"o.ooooooO.o.OO.+$OOoOOoOOO.     ",
"oo.ooooo.O.O.OO.OOoOO$OOoOO.    ",
" oo.oooo+O.OO.OO.OOOoOOoOO.o    ",
"  oo.ooo+O.oOo.Oo.O$OO$OO.o     ",
"   oo.oo+O.o+o.+o.OOOoOO.o      ",
"    oo.o+O.o+o.+o.OOoOO.o       ",
"     oo.+..o+o.+o..OOO.o        ",
"      oo.oo.+..+o.o.O.o         ",
"       ooooo.o.o.ooo.o          ",
"           oooo.o  oo           ",
"              oo                "};
diff --git a/padmin/source/rtsetup.hrc b/padmin/source/rtsetup.hrc
index 11bf334..aab206a 100644
--- a/padmin/source/rtsetup.hrc
+++ b/padmin/source/rtsetup.hrc
@@ -22,40 +22,6 @@

#define RID_RTS_RTSDIALOG_INVALID_TXT       4001

#define RID_RTS_OTHERPAGE                   4002
#define RID_RTS_OTHER_LEFTMARGIN_TXT        1
#define RID_RTS_OTHER_LEFTMARGIN_BOX        2
#define RID_RTS_OTHER_TOPMARGIN_TXT     3
#define RID_RTS_OTHER_TOPMARGIN_BOX     4
#define RID_RTS_OTHER_RIGHTMARGIN_TXT       5
#define RID_RTS_OTHER_RIGHTMARGIN_BOX       6
#define RID_RTS_OTHER_BOTTOMMARGIN_TXT      7
#define RID_RTS_OTHER_BOTTOMMARGIN_BOX      8
#define RID_RTS_OTHER_COMMENT_TXT           9
#define RID_RTS_OTHER_COMMENT_EDT           10
#define RID_RTS_OTHER_DEFAULT_BTN           11

#define RID_RTS_COMMANDPAGE                4006
#define RID_RTS_CMD_TXT_PRTNAME         1
#define RID_RTS_CMD_TXT_CONNECT         2
#define RID_RTS_CMD_FL_DEFAULT              3
#define RID_RTS_CMD_BTN_HELP                4
#define RID_RTS_CMD_CB_COMMANDS         5
#define RID_RTS_CMD_FL_INSTALL              6
#define RID_RTS_CMD_TXT_CONFIGURE           7
#define RID_RTS_CMD_LB_CONFIGURE            8
#define RID_RTS_CMD_STR_CONFIGURE_PRINTER   9
#define RID_RTS_CMD_STR_CONFIGURE_PDF       11
#define RID_RTS_CMD_STR_PRINTERHELP     12
#define RID_RTS_CMD_STR_PDFHELP         14
#define RID_RTS_CMD_BTN_REMOVE              15
#define RID_RTS_CMD_EDT_PDFDIR              16
#define RID_RTS_CMD_BTN_PDFDIR              17
#define RID_RTS_CMD_TXT_PDFDIR              18
#define RID_RTS_CMD_CB_EXTERNAL             20
#define RID_RTS_CMD_FT_QUICKCMD             21
#define RIT_RTS_CMD_CB_QUICKCMD             22

#define RID_TXT_QUERYFAXNUMBER              4007

#define RID_RTS_PWDIALOG                    4008
diff --git a/padmin/source/rtsetup.src b/padmin/source/rtsetup.src
index f95a009..74953c9 100644
--- a/padmin/source/rtsetup.src
+++ b/padmin/source/rtsetup.src
@@ -24,231 +24,6 @@ String RID_RTS_RTSDIALOG_INVALID_TXT
    Text [ en-US ] = "<ignore>";
};

TabPage RID_RTS_COMMANDPAGE
{
    HelpID = "padmin:TabPage:RID_RTS_COMMANDPAGE";
    Hide = TRUE;
    Size = MAP_APPFONT( 230, 175 );

    ComboBox RID_RTS_CMD_CB_COMMANDS
    {
        HelpID = "padmin:ComboBox:RID_RTS_COMMANDPAGE:RID_RTS_CMD_CB_COMMANDS";
        Border = TRUE ;
        Sort = TRUE ;
        Dropdown = TRUE;
        Pos = MAP_APPFONT ( 11 , 75 ) ;
        Size = MAP_APPFONT ( 150 , 65 ) ;
    };
    CheckBox RID_RTS_CMD_CB_EXTERNAL
    {
        HelpID = "padmin:CheckBox:RID_RTS_COMMANDPAGE:RID_RTS_CMD_CB_EXTERNAL";
        Pos = MAP_APPFONT( 11, 95 );
        Size = MAP_APPFONT( 220, 10 );
        Text [ en-US ] = "~Use system print dialog, disable %PRODUCTNAME's print dialog";
    };
    FixedText RID_RTS_CMD_FT_QUICKCMD
    {
        Pos = MAP_APPFONT( 11, 110 );
        Size = MAP_APPFONT( 150, 20 );
        WordBreak = TRUE;
        Text [ en-US ] = "Command for quick printing without dialog (optional)";
    };
    ComboBox RIT_RTS_CMD_CB_QUICKCMD
    {
        HelpID = "padmin:ComboBox:RID_RTS_COMMANDPAGE:RIT_RTS_CMD_CB_QUICKCMD";
        Border = TRUE;
        Sort = TRUE;
        Dropdown = TRUE;
        Pos = MAP_APPFONT( 11, 130 );
        Size = MAP_APPFONT( 150, 65 );
    };
    FixedLine RID_RTS_CMD_FL_INSTALL
    {
        Pos = MAP_APPFONT ( 6 , 44 ) ;
        Size = MAP_APPFONT ( 220 , 8 ) ;
        Text [ en-US ] = "Select command";
    };
    String RID_RTS_CMD_STR_CONFIGURE_PRINTER
    {
        Text [ en-US ] = "Printer";
    };
    String RID_RTS_CMD_STR_CONFIGURE_PDF
    {
        Text [ en-US ] = "PDF converter";
    };

    ListBox RID_RTS_CMD_LB_CONFIGURE
    {
        HelpID = "padmin:ListBox:RID_RTS_COMMANDPAGE:RID_RTS_CMD_LB_CONFIGURE";
        DropDown = true;
        Border = true;
        Pos = MAP_APPFONT( 101, 56 );
        Size = MAP_APPFONT( 60, 200 );
    };
    FixedText RID_RTS_CMD_TXT_CONFIGURE
    {
        Pos = MAP_APPFONT( 11, 56 );
        Size = MAP_APPFONT( 85, 10 );
        Text [ en-US ] = "~Configure as";
    };

    FixedText RID_RTS_CMD_TXT_PDFDIR
    {
        Pos = MAP_APPFONT( 11, 146 );
        Size = MAP_APPFONT( 130, 8 );
        Text [ en-US ] = "PDF target directory :";
    };
    Edit RID_RTS_CMD_EDT_PDFDIR
    {
        HelpID = "padmin:Edit:RID_RTS_COMMANDPAGE:RID_RTS_CMD_EDT_PDFDIR";
        Border = TRUE;
        Pos = MAP_APPFONT( 11, 155 );
        Size = MAP_APPFONT( 130, 12 );
    };
    PushButton RID_RTS_CMD_BTN_PDFDIR
    {
        HelpID = "padmin:PushButton:RID_RTS_COMMANDPAGE:RID_RTS_CMD_BTN_PDFDIR";
        Pos = MAP_APPFONT( 146, 155 );
        Size = MAP_APPFONT( 15, 12 );
        Text = "...";
    };
    FixedText RID_RTS_CMD_TXT_PRTNAME
    {
        Pos = MAP_APPFONT ( 11 , 16 ) ;
        Size = MAP_APPFONT ( 210 , 8 ) ;
    };
    FixedText RID_RTS_CMD_TXT_CONNECT
    {
        Pos = MAP_APPFONT ( 11 , 26 ) ;
        Size = MAP_APPFONT ( 210 , 8 ) ;
        Text [ en-US ] = "Command: ";
    };
    FixedLine RID_RTS_CMD_FL_DEFAULT
    {
        Pos = MAP_APPFONT ( 6 , 6 ) ;
        Size = MAP_APPFONT ( 220 , 8 ) ;
        Text [ en-US ] = "Printer";
    };
    PushButton RID_RTS_CMD_BTN_HELP
    {
        HelpID = "padmin:PushButton:RID_RTS_COMMANDPAGE:RID_RTS_CMD_BTN_HELP";
        Pos = MAP_APPFONT( 170, 55 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Help";
    };
    PushButton RID_RTS_CMD_BTN_REMOVE
    {
        HelpID = "padmin:PushButton:RID_RTS_COMMANDPAGE:RID_RTS_CMD_BTN_REMOVE";
        Pos = MAP_APPFONT( 170, 72 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Remove";
    };
    String RID_RTS_CMD_STR_PDFHELP
    {
        Text [ en-US ] = "The command line for PDF converters is executed as follows: for each document printed, \"(TMP)\" in the command line is replaced by a temporary file and \"(OUTFILE)\" in the command line is replaced by the target PDF file name. If \"(TMP)\" is in the command line, the PostScript code will be supplied via a file, otherwise via standard input (i.e. as a pipe).";
    };
    String RID_RTS_CMD_STR_PRINTERHELP
    {
        Text [ en-US ] = "The command line for printer devices is executed as follows: the generated PostScript code is supplied as standard input (i.e. as a pipe) to the command line.";
    };
};

TabPage RID_RTS_OTHERPAGE
{
    HelpID = "padmin:TabPage:RID_RTS_OTHERPAGE";
    Hide = TRUE;
    Size = MAP_APPFONT( 230, 175 );

    FixedText RID_RTS_OTHER_LEFTMARGIN_TXT
    {
        Pos = MAP_APPFONT( 5, 5 );
        Size = MAP_APPFONT( 85, 8 );
        Text [ en-US ] = "~Left margin";
    };
    MetricField RID_RTS_OTHER_LEFTMARGIN_BOX
    {
        HelpID = "padmin:MetricField:RID_RTS_OTHERPAGE:RID_RTS_OTHER_LEFTMARGIN_BOX";
        Border = TRUE ;
        Pos = MAP_APPFONT ( 100 , 5 ) ;
        Size = MAP_APPFONT ( 50 , 12 ) ;
        StrictFormat = TRUE ;
        Spin = TRUE;
        Repeat = TRUE;
        Unit = FUNIT_MM;
    };
    FixedText RID_RTS_OTHER_TOPMARGIN_TXT
    {
        Pos = MAP_APPFONT( 5, 20 );
        Size = MAP_APPFONT( 85, 8 );
        Text [ en-US ] = "~Top margin";
    };
    MetricField RID_RTS_OTHER_TOPMARGIN_BOX
    {
        HelpID = "padmin:MetricField:RID_RTS_OTHERPAGE:RID_RTS_OTHER_TOPMARGIN_BOX";
        Border = TRUE ;
        Pos = MAP_APPFONT ( 100 , 20 ) ;
        Size = MAP_APPFONT ( 50 , 12 ) ;
        StrictFormat = TRUE ;
        Spin = TRUE;
        Repeat = TRUE;
        Unit = FUNIT_MM;
    };
    FixedText RID_RTS_OTHER_RIGHTMARGIN_TXT
    {
        Pos = MAP_APPFONT( 5, 35 );
        Size = MAP_APPFONT( 85, 8 );
        Text [ en-US ] = "~Right margin";
    };
    MetricField RID_RTS_OTHER_RIGHTMARGIN_BOX
    {
        HelpID = "padmin:MetricField:RID_RTS_OTHERPAGE:RID_RTS_OTHER_RIGHTMARGIN_BOX";
        Border = TRUE ;
        Pos = MAP_APPFONT ( 100 , 35 ) ;
        Size = MAP_APPFONT ( 50 , 12 ) ;
        StrictFormat = TRUE ;
        Spin = TRUE;
        Repeat = TRUE;
        Unit = FUNIT_MM;
    };
    FixedText RID_RTS_OTHER_BOTTOMMARGIN_TXT
    {
        Pos = MAP_APPFONT( 5, 50 );
        Size = MAP_APPFONT( 85, 8 );
        Text [ en-US ] = "~Bottom margin";
    };
    MetricField RID_RTS_OTHER_BOTTOMMARGIN_BOX
    {
        HelpID = "padmin:MetricField:RID_RTS_OTHERPAGE:RID_RTS_OTHER_BOTTOMMARGIN_BOX";
        Border = TRUE ;
        Pos = MAP_APPFONT ( 100 , 50 ) ;
        Size = MAP_APPFONT ( 50 , 12 ) ;
        StrictFormat = TRUE ;
        Spin = TRUE;
        Repeat = TRUE;
        Unit = FUNIT_MM;
    };
    FixedText RID_RTS_OTHER_COMMENT_TXT
    {
        Pos = MAP_APPFONT( 5, 65 );
        Size = MAP_APPFONT( 85, 8 );
        Text [ en-US ] = "~Comment";
    };
    Edit RID_RTS_OTHER_COMMENT_EDT
    {
        HelpID = "padmin:Edit:RID_RTS_OTHERPAGE:RID_RTS_OTHER_COMMENT_EDT";
        Border = TRUE ;
        Pos = MAP_APPFONT ( 5 , 75 ) ;
        Size = MAP_APPFONT ( 220 , 12 ) ;
    };
    PushButton RID_RTS_OTHER_DEFAULT_BTN
    {
        HelpID = "padmin:PushButton:RID_RTS_OTHERPAGE:RID_RTS_OTHER_DEFAULT_BTN";
        Pos = MAP_APPFONT( 175, 5 );
        Size = MAP_APPFONT( 50, 12 );
        Text [ en-US ] = "~Default";
    };
};

String RID_TXT_QUERYFAXNUMBER
{
    Text [ en-US ] = "Please enter the fax number.";
diff --git a/padmin/source/spadmin.sh b/padmin/source/spadmin.sh
deleted file mode 100755
index 74339395..0000000
--- a/padmin/source/spadmin.sh
+++ /dev/null
@@ -1,89 +0,0 @@
#!/bin/sh
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements. See the NOTICE file distributed
#   with this work for additional information regarding copyright
#   ownership. The ASF licenses this file to you under the Apache
#   License, Version 2.0 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
#

# enable file locking
SAL_ENABLE_FILE_LOCKING=1
export SAL_ENABLE_FILE_LOCKING

# resolve installation directory
sd_cwd="`pwd`"
if [ -h "$0" ] ; then
    sd_basename=`basename "$0"`
     sd_script=`ls -l "$0" | sed "s/.*${sd_basename} -> //g"`
    cd "`dirname "$0"`"
    cd "`dirname "$sd_script"`"
else
    cd "`dirname "$0"`"
fi
sd_prog=`pwd`
cd "$sd_cwd"

case "`uname -s`" in
    FreeBSD)
        sd_prog1="$sd_prog"
        sd_prog2="$sd_prog/../ure-link/lib"
        LD_LIBRARY_PATH=$sd_prog1:$sd_prog2${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
        export LD_LIBRARY_PATH
        ;;
    AIX)
        sd_prog1="$sd_prog"
        sd_prog2="$sd_prog/../ure-link/lib"
        LIBPATH=$sd_prog1:$sd_prog2${LIBPATH:+:$LIBPATH}
        export LIBPATH
        ;;
esac

#collect all bootstrap variables specified on the command line
#so that they can be passed as arguments to javaldx later on
for arg in $@
do
  case "$arg" in
       -env:*) BOOTSTRAPVARS=$BOOTSTRAPVARS" ""$arg";;
  esac
done

# extend the ld_library_path for java: javaldx checks the sofficerc for us
if [ -x "$sd_prog/../ure-link/bin/javaldx" ] ; then
    my_path=`"$sd_prog/../ure-link/bin/javaldx" $BOOTSTRAPVARS \
        "-env:INIFILENAME=vnd.sun.star.pathname:$sd_prog/redirectrc"`
    if [ -n "$my_path" ] ; then
        sd_platform=`uname -s`
        case $sd_platform in
          AIX)
            LIBPATH=$my_path${LIBPATH:+:$LIBPATH}
            export LIBPATH
            ;;
          *)
            LD_LIBRARY_PATH=$my_path${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
            export LD_LIBRARY_PATH
            ;;
        esac
    fi
fi

# uncomment line below to disable anti aliasing of fonts
# SAL_ANTIALIAS_DISABLE=true; export SAL_ANTIALIAS_DISABLE

# Set PATH so that crash_report is found:
PATH=$sd_prog${PATH+:$PATH}
export PATH

# execute binary
exec "$sd_prog/spadmin.bin" "$@" \
    "-env:INIFILENAME=vnd.sun.star.pathname:$sd_prog/redirectrc"
diff --git a/padmin/source/titlectrl.cxx b/padmin/source/titlectrl.cxx
deleted file mode 100644
index 5185d4a..0000000
--- a/padmin/source/titlectrl.cxx
+++ /dev/null
@@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <titlectrl.hxx>

using namespace padmin;

TitleImage::TitleImage( Window* pParent, const ResId& rResId ) :
        Control( pParent, rResId ),
        m_bArranged( false )
{
    Font aFont = GetFont();
    aFont.SetHeight( aFont.GetHeight()*3/2 );
    SetFont( aFont );
}



TitleImage::~TitleImage()
{
}



void TitleImage::arrange()
{
    m_bArranged = true;
    Size aCtrlSize( GetSizePixel() );
    Size aImageSize( m_aImage.GetSizePixel() );
    Size aTextSize( GetTextWidth( m_aText ), GetTextHeight() );

    m_aImagePos.Y() = ( aCtrlSize.Height() - aImageSize.Height() ) / 2;
    m_aImagePos.X() = m_aImagePos.Y() < 0 ? -m_aImagePos.Y() : m_aImagePos.Y();
    m_aTextPos.X() = m_aImagePos.X() + aImageSize.Width() + aTextSize.Height()/2;
    m_aTextPos.Y() = ( aCtrlSize.Height() - aTextSize.Height() ) / 2;
}



void TitleImage::Paint( const Rectangle& )
{
    if( ! m_bArranged )
        arrange();

    SetLineColor( m_aBGColor );
    SetFillColor( m_aBGColor );
    DrawRect( Rectangle( Point( 0, 0 ), Size( GetSizePixel() ) ) );
    DrawImage( m_aImagePos, m_aImage );
    DrawText( m_aTextPos, m_aText );
}



void TitleImage::SetText( const OUString& rText )
{
    m_aText = rText;
    m_bArranged = false;
    Invalidate();
}



void TitleImage::SetImage( const Image& rImage )
{
    m_aImage = rImage;
    m_bArranged = false;
    Invalidate();
}



void TitleImage::SetBackgroundColor( const Color& rColor )
{
    m_aBGColor = rColor;
    Invalidate();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/source/titlectrl.hxx b/padmin/source/titlectrl.hxx
deleted file mode 100644
index a470ac2..0000000
--- a/padmin/source/titlectrl.hxx
+++ /dev/null
@@ -1,60 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef _PAD_TITLECTRL_HXX_
#define _PAD_TITLECTRL_HXX_

#include <vcl/ctrl.hxx>
#include <vcl/image.hxx>

namespace padmin
{

class TitleImage : public Control
{
    Image               m_aImage;
    OUString            m_aText;
    Color               m_aBGColor;
    Point               m_aImagePos;
    Point               m_aTextPos;

    bool                m_bArranged;

    void arrange();
public:
    TitleImage( Window* pParent, const ResId& rResId );
    ~TitleImage();

    virtual void Paint( const Rectangle& rRect );

    void SetImage( const Image& rImage );
    const Image& GetImage() const { return m_aImage; }

    virtual void SetText( const OUString& rText );
    virtual OUString GetText() const { return m_aText; }

    void SetBackgroundColor( const Color& rColor );
    const Color& GetBackgroundColor() const { return m_aBGColor; }
};

}

#endif // _PAD_TITLECTRL_HXX_

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/padmin/uiconfig/ui/printerpropertiesdialog.ui b/padmin/uiconfig/ui/printerpropertiesdialog.ui
index b84184a..0df264d 100644
--- a/padmin/uiconfig/ui/printerpropertiesdialog.ui
+++ b/padmin/uiconfig/ui/printerpropertiesdialog.ui
@@ -63,19 +63,6 @@
              <placeholder/>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="command">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">Command</property>
              </object>
              <packing>
                <property name="tab_fill">False</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="paper">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
@@ -100,20 +87,6 @@
                <property name="tab_fill">False</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
            <child type="tab">
              <object class="GtkLabel" id="other">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">Other Settings</property>
              </object>
              <packing>
                <property name="position">4</property>
                <property name="tab_fill">False</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">True</property>
diff --git a/scp2/source/ooo/file_extra_ooo.scp b/scp2/source/ooo/file_extra_ooo.scp
index 62714c7..ced1389 100644
--- a/scp2/source/ooo/file_extra_ooo.scp
+++ b/scp2/source/ooo/file_extra_ooo.scp
@@ -39,17 +39,6 @@ File gid_File_Extra_Autotextuser
    Name = "extras_autotextuser.filelist";
End

#ifdef UNX

File gid_File_Extra_Cfgsrv_Bitmap_Unx
    Dir = FILELIST_DIR;
    TXT_FILE_BODY;
    Styles = (FILELIST);
    Name = "extras_cfgsrvbitmapunx.filelist";
End

#endif

File gid_File_Extra_Cfgusr
    Dir = FILELIST_DIR;
    USER_FILE_BODY;
diff --git a/scp2/source/ooo/file_ooo.scp b/scp2/source/ooo/file_ooo.scp
index 00b6e3d..a88907c 100644
--- a/scp2/source/ooo/file_ooo.scp
+++ b/scp2/source/ooo/file_ooo.scp
@@ -227,17 +227,6 @@ File gid_File_Bin_Senddoc
End
#endif

#if defined(UNX) && !defined(MACOSX) && !defined(LIBO_HEADLESS)

File gid_File_Bin_Spadmin_Bin
    BIN_FILE_BODY;
    Dir = gid_Brand_Dir_Program;
    Styles = (PACKED);
    Name = "spadmin.bin";
End

#endif

File gid_File_framework_dtd
    TXT_FILE_BODY;
    Styles = (FILELIST, PACKED);
diff --git a/scp2/source/ooo/module_hidden_ooo.scp b/scp2/source/ooo/module_hidden_ooo.scp
index 0d91f6e..024a347e 100644
--- a/scp2/source/ooo/module_hidden_ooo.scp
+++ b/scp2/source/ooo/module_hidden_ooo.scp
@@ -86,7 +86,6 @@ Module gid_Module_Root_Files_2
	gid_File_Bin_Pluginapp,
	gid_File_Bin_Senddoc,
	gid_File_Script_Gengal,
	gid_File_Bin_Spadmin_Bin,
	gid_File_Bin_Uri_Encode,
	gid_File_Bin_UIPreviewer,
	gid_File_Exe_Nsplugin,
@@ -238,7 +237,6 @@ Module gid_Module_Root_Files_6
	gid_File_Basic_Tools,
	gid_File_Basic_Tutorials,
	gid_File_Extra_Cfgsrv,
	gid_File_Extra_Cfgsrv_Bitmap_Unx,
	gid_File_sd_web,
        gid_File_Share_Config_Sofficecfg_uiconfig_basicide,
        gid_File_Share_Config_Sofficecfg_uiconfig_cui,
diff --git a/sysui/CustomTarget_share.mk b/sysui/CustomTarget_share.mk
index 7851156..862e57f 100644
--- a/sysui/CustomTarget_share.mk
+++ b/sysui/CustomTarget_share.mk
@@ -130,7 +130,6 @@ $(eval $(call gb_CustomTarget_register_targets,sysui/share,\
		$(product)/openoffice.applications \
		$(product)/openoffice.keys \
		$(product)/openoffice.sh \
		$(product)/printeradmin.sh \
		$(product)/create_tree.sh \
		$(product)/mimelnklist \
		$(product)/launcherlist) \
@@ -172,12 +171,7 @@ $(share_WORKDIR)/%/openoffice.sh: $(share_SRCDIR)/share/openoffice.sh
	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,1)
	cat $< | tr -d "\015" | sed -e "s/%PREFIX/$(UNIXFILENAME.$*)/g" > $@

$(share_WORKDIR)/%/printeradmin.sh: $(share_SRCDIR)/share/printeradmin.sh
	mkdir -p $(dir $@)
	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),CAT,1)
	cat $< | tr -d "\015" | sed -e "s/%PREFIX/$(UNIXFILENAME.$*)/g" > $@

$(share_WORKDIR)/%/create_tree.sh: $(share_SRCDIR)/share/create_tree.sh $(share_WORKDIR)/%/mimelnklist $(share_WORKDIR)/%/printeradmin.sh \
$(share_WORKDIR)/%/create_tree.sh: $(share_SRCDIR)/share/create_tree.sh $(share_WORKDIR)/%/mimelnklist \
	$(share_WORKDIR)/%/openoffice.org.xml $(share_WORKDIR)/%/openoffice.applications $(share_WORKDIR)/%/openoffice.mime \
	$(share_WORKDIR)/%/openoffice.keys $(share_WORKDIR)/%/launcherlist
	mkdir -p $(dir $@)
diff --git a/sysui/desktop/man/libreoffice.1 b/sysui/desktop/man/libreoffice.1
index 68793ff..8847d53 100644
--- a/sysui/desktop/man/libreoffice.1
+++ b/sysui/desktop/man/libreoffice.1
@@ -43,7 +43,7 @@ passes the command line arguments to the \fBsoffice.bin\fR binary.

Alternatively, the following helper scripts start the respective module:

sbase, scalc, sdraw, simpress, smath, sofficerc, spadmin, swriter
sbase, scalc, sdraw, simpress, smath, sofficerc, swriter

.SH OPTIONS
.TP
diff --git a/sysui/desktop/share/create_tree.sh b/sysui/desktop/share/create_tree.sh
index 0843f2e..2221a46 100755
--- a/sysui/desktop/share/create_tree.sh
+++ b/sysui/desktop/share/create_tree.sh
@@ -65,15 +65,11 @@ office_root=${office_prefix}/${PREFIX}
#this symlink is needed to have the API boostrap functions running right
ln -sf "${office_root}/program/soffice" "${DESTDIR}/usr/bin/${PREFIX}"

cp printeradmin.sh "${DESTDIR}/usr/bin/${PREFIX}-printeradmin"
chmod 0755 "${DESTDIR}/usr/bin/${PREFIX}-printeradmin"

if test "${PREFIX}" != libreoffice${PRODUCTVERSION} -a "${PREFIX}" != libreofficedev${PRODUCTVERSION}  ; then
    # compat symlinks
    mkdir -p "${DESTDIR}${office_prefix}"
    ln -sf libreoffice${PRODUCTVERSION} "${DESTDIR}${office_root}"
    ln -sf /usr/bin/${PREFIX} "${DESTDIR}/usr/bin/libreoffice${PRODUCTVERSION}"
    ln -sf /usr/bin/${PREFIX}-printeradmin "${DESTDIR}/usr/bin/libreoffice${PRODUCTVERSION}-printeradmin"
fi

test "${PREFIX}" = libreofficedev${PRODUCTVERSION} && mime_def_file="libreofficedev${PRODUCTVERSION}.xml" || mime_def_file="libreoffice${PRODUCTVERSION}.xml"
diff --git a/sysui/desktop/share/printeradmin.sh b/sysui/desktop/share/printeradmin.sh
deleted file mode 100755
index 0eb631f..0000000
--- a/sysui/desktop/share/printeradmin.sh
+++ /dev/null
@@ -1,3 +0,0 @@
#!/bin/sh

exec /opt/%PREFIX/program/spadmin
diff --git a/sysui/desktop/solaris/prototype b/sysui/desktop/solaris/prototype
index 6b1360a..145c76e 100755
--- a/sysui/desktop/solaris/prototype
+++ b/sysui/desktop/solaris/prototype
@@ -8,7 +8,6 @@ d none usr 0755 root sys
d none usr/bin 0755 root bin
s none usr/bin/soffice=../../opt/%PREFIX/program/soffice
f none usr/bin/%PREFIX=%SOURCE/openoffice.sh 0755 root bin
f none usr/bin/%PREFIX-printeradmin=%SOURCE/printeradmin.sh 0755 root bin
d none usr/share 0755 root sys
d none usr/share/applications 0755 root other
d none usr/share/mime 0755 root root
@@ -37,7 +36,6 @@ f none usr/share/pixmaps/%ICONPREFIX-draw.png=../icons/hicolor/48x48/apps/draw.p
f none usr/share/pixmaps/%ICONPREFIX-impress.png=../icons/hicolor/48x48/apps/impress.png
f none usr/share/pixmaps/%ICONPREFIX-math.png=../icons/hicolor/48x48/apps/math.png
f none usr/share/pixmaps/%ICONPREFIX-base.png=../icons/hicolor/48x48/apps/base.png
f none usr/share/pixmaps/%ICONPREFIX-printeradmin.png=../icons/hicolor/48x48/apps/printeradmin.png
f none usr/share/pixmaps/%ICONPREFIX-text.png=../icons/hicolor/48x48/mimetypes/text.png
f none usr/share/pixmaps/%ICONPREFIX-text-template.png=../icons/hicolor/48x48/mimetypes/text-template.png
f none usr/share/pixmaps/%ICONPREFIX-spreadsheet.png=../icons/hicolor/48x48/mimetypes/spreadsheet.png
diff --git a/test/Package_unittest.mk b/test/Package_unittest.mk
index a21388a..3c0aad7 100644
--- a/test/Package_unittest.mk
+++ b/test/Package_unittest.mk
@@ -19,8 +19,6 @@ $(eval $(call gb_Package_add_file,test_unittest,unittest/user/wordbook/en-GB.dic
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/template.bau,user/autotext/en-US/template.bau))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/standard.bau,user/autotext/en-US/standard.bau))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/crdbus50.bau,user/autotext/en-US/crdbus50.bau))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/psetup.xpm,user/config/psetup.xpm))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/.dummy,empty-directory-dummy))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/psetupl.xpm,user/config/psetupl.xpm))

# vim: set noet sw=4 ts=4:
diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx
index 1a17975..b90f7a9 100644
--- a/tools/source/generic/config.cxx
+++ b/tools/source/generic/config.cxx
@@ -815,13 +815,6 @@ OString Config::ReadKey(const OString& rKey) const
    return ReadKey(rKey, OString());
}

OUString Config::ReadKey(const OString& rKey, rtl_TextEncoding eEncoding) const
{
    if ( mpData->mbIsUTF8BOM )
        eEncoding = RTL_TEXTENCODING_UTF8;
    return OStringToOUString(ReadKey(rKey), eEncoding);
}

OString Config::ReadKey(const OString& rKey, const OString& rDefault) const
{
#ifdef DBG_UTIL
diff --git a/unusedcode.easy b/unusedcode.easy
index 8010406..8634a81 100644
--- a/unusedcode.easy
+++ b/unusedcode.easy
@@ -29,6 +29,9 @@ OutputDevice::PixelToLogic(Region const&, MapMode const&) const
SalGraphics::drawTransformedBitmap(basegfx::B2DPoint const&, basegfx::B2DPoint const&, basegfx::B2DPoint const&, SalBitmap const&, SalBitmap const*)
ScDocument::CreateFormatTable() const
ScExtIButton::GetSelected() const
ScFormulaCellGroup::scheduleCompilation()
ScTableProtection::getEnhancedProtection() const
ScTableProtection::updateReference(UpdateRefMode, ScDocument*, ScRange const&, short, int, short)
ScVbaFormat<ooo::vba::excel::XStyle>::getAddIndent()
ScVbaFormat<ooo::vba::excel::XStyle>::setAddIndent(com::sun::star::uno::Any const&)
SdrItemBrowser::ForceParent()
@@ -61,7 +64,6 @@ VCLXGraphics::getLineColor()
VCLXGraphics::getRasterOp()
VCLXGraphics::getTextColor()
VCLXGraphics::getTextFillColor()
XclRef8U::convertToScRange(short)
apitest::CellProperties::testRotateReference()
apitest::CellProperties::testVertJustify()
apitest::DataPilotField::testAutoShowInfo()
@@ -188,7 +190,9 @@ oglcanvas::CanvasHelper::flush() const
oglcanvas::TextLayout::draw(com::sun::star::rendering::ViewState const&, com::sun::star::rendering::RenderState const&, com::sun::star::uno::Reference<com::sun::star::rendering::XGraphicDevice> const&) const
oox::xls::BiffDrawingObjectBase::BiffDrawingObjectBase(oox::xls::WorksheetHelper const&)
rtl_OUString::convertFromString::test()
sc::CLBuildKernelThread::CLBuildKernelThread()
sc::CLBuildKernelThread::consume()
sc::CLBuildKernelThread::finish()
sc::CLBuildKernelThread::produce()
sd::LeftDrawPaneShell::RegisterInterface(SfxModule*)
sd::LeftImpressPaneShell::RegisterInterface(SfxModule*)
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index 121fa8f..7e56085 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -488,24 +488,6 @@ void PPDParser::initPPDFiles(PPDCache &rPPDCache)
    }
}

void PPDParser::getKnownPPDDrivers( std::list< OUString >& o_rDrivers, bool bRefresh )
{
    PPDCache &rPPDCache = thePPDCache::get();

    if( bRefresh )
    {
        delete rPPDCache.pAllPPDFiles;
        rPPDCache.pAllPPDFiles = NULL;
    }

    initPPDFiles(rPPDCache);
    o_rDrivers.clear();

    boost::unordered_map< OUString, OUString, OUStringHash >::const_iterator it;
    for( it = rPPDCache.pAllPPDFiles->begin(); it != rPPDCache.pAllPPDFiles->end(); ++it )
        o_rDrivers.push_back( it->first );
}

OUString PPDParser::getPPDFile( const OUString& rFile )
{
    INetURLObject aPPD( rFile, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
@@ -569,47 +551,6 @@ OUString PPDParser::getPPDFile( const OUString& rFile )
    return aRet;
}

OUString PPDParser::getPPDPrinterName( const OUString& rFile )
{
    OUString aPath = getPPDFile( rFile );
    OUString aName;

    // read in the file
    PPDDecompressStream aStream( aPath );
    if( aStream.IsOpen() )
    {
        OUString aCurLine;
        while( ! aStream.IsEof() && aStream.IsOpen() )
        {
            OString aByteLine = aStream.ReadLine();
            aCurLine = OStringToOUString(aByteLine, RTL_TEXTENCODING_MS_1252);
            if( aCurLine.startsWithIgnoreAsciiCase( "*include:" ) )
            {
                aCurLine = aCurLine.replaceAt( 0, 9, "" );
                aCurLine = comphelper::string::stripStart(aCurLine, ' ');
                aCurLine = comphelper::string::stripEnd(aCurLine, ' ');
                aCurLine = comphelper::string::stripStart(aCurLine, '\t');
                aCurLine = comphelper::string::stripEnd(aCurLine, '\t');
                aCurLine = comphelper::string::stripEnd(aCurLine, '\r');
                aCurLine = comphelper::string::stripEnd(aCurLine, '\n');
                aCurLine = comphelper::string::stripStart(aCurLine, '"');
                aCurLine = comphelper::string::stripEnd(aCurLine, '"');
                aStream.Close();
                aStream.Open( getPPDFile( aCurLine ) );
                continue;
            }
            if( aCurLine.startsWith( "*ModelName:" ) )
            {
                aName = aCurLine.getToken( 1, '"' );
                break;
            }
            else if( aCurLine.startsWith( "*NickName:" ) )
                aName = aCurLine.getToken( 1, '"' );
        }
    }
    return aName;
}

const PPDParser* PPDParser::getParser( const OUString& rFile )
{
    static ::osl::Mutex aMutex;