2010-10-12 08:53:47 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-10-19 08:44:47 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-10-19 08:44:47 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2006-06-02 05:30:12 -05:00
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2006-06-02 05:30:12 -05:00
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2005-10-19 08:44:47 -05:00
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2005-10-19 08:44:47 -05:00
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2005-10-19 08:44:47 -05:00
|
|
|
*
|
2008-04-10 19:26:39 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2005-10-19 08:44:47 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 23:17:27 -05:00
|
|
|
|
2005-10-19 06:10:07 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2007-01-23 01:59:53 -06:00
|
|
|
#include <memory>
|
2005-10-19 06:10:07 -05:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
|
|
|
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
2009-10-30 18:36:06 -05:00
|
|
|
#include <com/sun/star/uno/Reference.h>
|
2005-10-19 06:10:07 -05:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
|
|
|
|
|
|
|
#include <ucbhelper/contentbroker.hxx>
|
|
|
|
#include <ucbhelper/configurationkeys.hxx>
|
|
|
|
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <tools/fsys.hxx>
|
|
|
|
|
|
|
|
#include <vcl/window.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/font.hxx>
|
|
|
|
#include <vcl/sound.hxx>
|
|
|
|
#include <vcl/print.hxx>
|
|
|
|
#include <vcl/toolbox.hxx>
|
|
|
|
#include <vcl/help.hxx>
|
|
|
|
#include <vcl/scrbar.hxx>
|
|
|
|
#include <vcl/wrkwin.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <osl/process.h>
|
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
|
|
|
|
#include <galtheme.hxx>
|
2009-11-04 05:06:36 -06:00
|
|
|
#include <svx/gallery1.hxx>
|
2005-10-19 06:10:07 -05:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::registry;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
|
|
|
|
typedef ::std::list<rtl::OUString> FileNameList;
|
|
|
|
|
|
|
|
class GalApp : public Application
|
|
|
|
{
|
|
|
|
public:
|
2010-12-10 10:12:01 -06:00
|
|
|
virtual int Main();
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2009-01-20 06:50:17 -06:00
|
|
|
protected:
|
|
|
|
Reference<XMultiServiceFactory> xMSF;
|
|
|
|
void Init();
|
|
|
|
void InitUCB();
|
|
|
|
};
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2007-01-23 01:59:53 -06:00
|
|
|
Gallery* createGallery( const rtl::OUString& aGalleryURL )
|
|
|
|
{
|
|
|
|
return new Gallery( aGalleryURL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void disposeGallery( Gallery* pGallery )
|
|
|
|
{
|
|
|
|
delete pGallery;
|
|
|
|
}
|
|
|
|
|
2005-10-19 06:10:07 -05:00
|
|
|
static void createTheme( rtl::OUString aThemeName,
|
|
|
|
rtl::OUString aGalleryURL,
|
|
|
|
rtl::OUString aDestDir,
|
|
|
|
UINT32 nNumFrom,
|
|
|
|
FileNameList &rFiles )
|
|
|
|
{
|
2007-01-23 01:59:53 -06:00
|
|
|
Gallery * pGallery( createGallery( aGalleryURL ) );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
|
|
|
if (!pGallery ) {
|
|
|
|
fprintf( stderr, "Could't acquire '%s'\n",
|
2011-03-01 06:18:52 -06:00
|
|
|
rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
|
2005-10-19 06:10:07 -05:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
fprintf( stderr, "Work on gallery '%s'\n",
|
2011-03-01 06:18:52 -06:00
|
|
|
rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2006-10-12 06:49:52 -05:00
|
|
|
fprintf( stderr, "Existing themes: %lu\n",
|
|
|
|
sal::static_int_cast< unsigned long >(
|
|
|
|
pGallery->GetThemeCount() ) );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
|
|
|
if( !pGallery->HasTheme( aThemeName) ) {
|
|
|
|
if( !pGallery->CreateTheme( aThemeName, nNumFrom ) ) {
|
|
|
|
fprintf( stderr, "Failed to create theme\n" );
|
2007-01-23 01:59:53 -06:00
|
|
|
disposeGallery( pGallery );
|
2005-10-19 06:10:07 -05:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-12 06:49:52 -05:00
|
|
|
fprintf( stderr, "Existing themes: %lu\n",
|
|
|
|
sal::static_int_cast< unsigned long >(
|
|
|
|
pGallery->GetThemeCount() ) );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
|
|
|
SfxListener aListener;
|
|
|
|
|
2006-10-12 06:49:52 -05:00
|
|
|
GalleryTheme *pGalTheme = pGallery->AcquireTheme( aThemeName, aListener );
|
|
|
|
if ( pGalTheme == NULL ) {
|
2005-10-19 06:10:07 -05:00
|
|
|
fprintf( stderr, "Failed to acquire theme\n" );
|
2007-01-23 01:59:53 -06:00
|
|
|
disposeGallery( pGallery );
|
2005-10-19 06:10:07 -05:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( stderr, "Using DestDir: %s\n",
|
2011-03-01 06:18:52 -06:00
|
|
|
rtl::OUStringToOString(aDestDir, RTL_TEXTENCODING_UTF8).getStr() );
|
2005-10-19 06:10:07 -05:00
|
|
|
pGalTheme->SetDestDir(String(aDestDir));
|
|
|
|
|
|
|
|
FileNameList::const_iterator aIter;
|
|
|
|
|
2011-07-30 18:17:59 -05:00
|
|
|
for( aIter = rFiles.begin(); aIter != rFiles.end(); ++aIter )
|
2005-10-19 06:10:07 -05:00
|
|
|
{
|
|
|
|
// Should/could use:
|
|
|
|
// if ( ! pGalTheme->InsertFileOrDirURL( aURL ) ) {
|
|
|
|
// Requires a load more components ...
|
|
|
|
|
|
|
|
Graphic aGraphic;
|
|
|
|
String aFormat;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
if ( ! pGalTheme->InsertURL( *aIter ) )
|
|
|
|
fprintf( stderr, "Failed to import '%s'\n",
|
2011-03-01 06:18:52 -06:00
|
|
|
rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr() );
|
2005-10-19 06:10:07 -05:00
|
|
|
else
|
2006-10-12 06:49:52 -05:00
|
|
|
fprintf( stderr, "Imported file '%s' (%lu)\n",
|
2011-03-01 06:18:52 -06:00
|
|
|
rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr(),
|
2006-10-12 06:49:52 -05:00
|
|
|
sal::static_int_cast< unsigned long >(
|
|
|
|
pGalTheme->GetObjectCount() ) );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
|
|
|
#else // only loads BMPs
|
|
|
|
SvStream *pStream = ::utl::UcbStreamHelper::CreateStream( *aIter, STREAM_READ );
|
|
|
|
if (!pStream) {
|
|
|
|
fprintf( stderr, "Can't find image to import\n" );
|
2007-01-23 01:59:53 -06:00
|
|
|
disposeGallery( pGallery );
|
2005-10-19 06:10:07 -05:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
*pStream >> aGraphic;
|
|
|
|
delete pStream;
|
|
|
|
if( aGraphic.GetType() == GRAPHIC_NONE )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Failed to load '%s'\n",
|
2011-10-05 08:00:00 -05:00
|
|
|
rtl::OUStringToOString( *aIter, RTL_TEXTENCODING_UTF8 ).getStr() );
|
2005-10-19 06:10:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SgaObjectBmp aObject( aGraphic, *aIter, aFormat );
|
|
|
|
if ( ! aObject.IsValid() ) {
|
|
|
|
fprintf( stderr, "Failed to create thumbnail for image\n" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! pGalTheme->InsertObject( aObject ) ) {
|
|
|
|
fprintf( stderr, "Failed to insert file or URL\n" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
pGallery->ReleaseTheme( pGalTheme, aListener );
|
2007-01-23 01:59:53 -06:00
|
|
|
disposeGallery( pGallery );
|
2005-10-19 06:10:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintHelp()
|
|
|
|
{
|
|
|
|
fprintf( stdout, "Utility to generate OO.o gallery files\n\n" );
|
|
|
|
|
|
|
|
fprintf( stdout, "using: gengal --name <name> --path <dir> [ --destdir <path> ]\n");
|
|
|
|
fprintf( stdout, " [ --number-from <num> ] [ files ... ]\n\n" );
|
|
|
|
|
|
|
|
fprintf( stdout, "options:\n");
|
|
|
|
fprintf( stdout, " --name <theme>\t\tdefines a name of the created or updated theme.\n");
|
|
|
|
fprintf( stdout, " --path <dir>\t\tdefines directory where the gallery files are created\n");
|
|
|
|
fprintf( stdout, "\t\t\tor updated.\n");
|
|
|
|
fprintf( stdout, " --destdir <dir>\tdefines a path prefix to be removed from the paths\n");
|
|
|
|
fprintf( stdout, "\t\t\tstored in the gallery files. It is useful to create\n");
|
|
|
|
fprintf( stdout, "\t\t\tRPM packages using the BuildRoot feature.\n");
|
|
|
|
fprintf( stdout, " --number-from <num>\tdefines minimal number for the newly created gallery\n");
|
|
|
|
fprintf( stdout, "\t\t\ttheme files.\n");
|
|
|
|
fprintf( stdout, " files\t\t\tlists files to be added to the gallery. Absolute paths\n");
|
|
|
|
fprintf( stdout, "\t\t\tare required.\n");
|
|
|
|
}
|
|
|
|
|
2009-10-30 18:36:06 -05:00
|
|
|
static rtl::OUString Smartify( const rtl::OUString &rPath )
|
2005-10-19 06:10:07 -05:00
|
|
|
{
|
|
|
|
INetURLObject aURL;
|
|
|
|
aURL.SetSmartURL( rPath );
|
|
|
|
return aURL.GetMainURL( INetURLObject::NO_DECODE );
|
|
|
|
}
|
|
|
|
|
2009-01-20 06:50:17 -06:00
|
|
|
#define OUSTRING_CSTR( str ) \
|
|
|
|
rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ).getStr()
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2009-01-20 06:50:17 -06:00
|
|
|
void GalApp::Init()
|
|
|
|
{
|
|
|
|
if( getenv( "OOO_INSTALL_PREFIX" ) == NULL ) {
|
2009-10-30 18:36:06 -05:00
|
|
|
rtl::OUString fileName = GetAppFileName();
|
2009-01-20 06:50:17 -06:00
|
|
|
int lastSlash = fileName.lastIndexOf( '/' );
|
|
|
|
#ifdef WNT
|
|
|
|
// Don't know which directory separators GetAppFileName() returns on Windows.
|
|
|
|
// Be safe and take into consideration they might be backslashes.
|
|
|
|
if( fileName.lastIndexOf( '\\' ) > lastSlash )
|
|
|
|
lastSlash = fileName.lastIndexOf( '\\' );
|
|
|
|
#endif
|
2009-10-30 18:36:06 -05:00
|
|
|
rtl::OUString baseBinDir = fileName.copy( 0, lastSlash );
|
2010-11-21 06:30:02 -06:00
|
|
|
rtl::OUString installPrefix = baseBinDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/../.."));
|
2010-10-18 09:42:48 -05:00
|
|
|
|
|
|
|
rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("OOO_INSTALL_PREFIX"));
|
|
|
|
osl_setEnvironment(envVar.pData, installPrefix.pData);
|
2005-10-19 06:10:07 -05:00
|
|
|
}
|
2009-01-20 06:50:17 -06:00
|
|
|
OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2009-01-20 06:50:17 -06:00
|
|
|
Reference<XComponentContext> xComponentContext
|
|
|
|
= ::cppu::defaultBootstrap_InitialComponentContext();
|
|
|
|
xMSF = Reference<XMultiServiceFactory>
|
|
|
|
( xComponentContext->getServiceManager(), UNO_QUERY );
|
2005-10-19 06:10:07 -05:00
|
|
|
if( !xMSF.is() )
|
|
|
|
fprintf( stderr, "Failed to bootstrap\n" );
|
|
|
|
::comphelper::setProcessServiceFactory( xMSF );
|
|
|
|
|
2009-01-20 06:50:17 -06:00
|
|
|
InitUCB();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GalApp::InitUCB()
|
|
|
|
{
|
2009-10-30 18:36:06 -05:00
|
|
|
rtl::OUString aEmpty;
|
2005-10-19 06:10:07 -05:00
|
|
|
Sequence< Any > aArgs(6);
|
|
|
|
aArgs[0]
|
2010-11-21 08:25:39 -06:00
|
|
|
<<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UCB_CONFIGURATION_KEY1_LOCAL));
|
2005-10-19 06:10:07 -05:00
|
|
|
aArgs[1]
|
2010-11-21 08:25:39 -06:00
|
|
|
<<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UCB_CONFIGURATION_KEY2_OFFICE));
|
2010-11-21 06:30:02 -06:00
|
|
|
aArgs[2] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PIPE"));
|
2005-10-19 06:10:07 -05:00
|
|
|
aArgs[3] <<= aEmpty;
|
2010-11-21 06:30:02 -06:00
|
|
|
aArgs[4] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PORTAL"));
|
2005-10-19 06:10:07 -05:00
|
|
|
aArgs[5] <<= aEmpty;
|
|
|
|
|
2007-06-05 08:35:58 -05:00
|
|
|
if (! ::ucbhelper::ContentBroker::initialize( xMSF, aArgs ) )
|
2006-06-02 05:30:12 -05:00
|
|
|
fprintf( stderr, "Failed to init content broker\n" );
|
2009-01-20 06:50:17 -06:00
|
|
|
}
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2010-12-10 10:12:01 -06:00
|
|
|
int GalApp::Main()
|
2009-01-20 06:50:17 -06:00
|
|
|
{
|
2005-10-19 06:10:07 -05:00
|
|
|
bool bHelp = false;
|
|
|
|
rtl::OUString aPath, aDestDir;
|
2010-11-21 06:30:02 -06:00
|
|
|
rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM("Default name"));
|
2005-10-19 06:10:07 -05:00
|
|
|
UINT32 nNumFrom = 0;
|
|
|
|
FileNameList aFiles;
|
|
|
|
|
|
|
|
for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
|
|
|
|
{
|
2009-10-30 18:36:06 -05:00
|
|
|
rtl::OUString aParam = GetCommandLineParam( i );
|
2005-10-19 06:10:07 -05:00
|
|
|
|
2011-01-20 04:23:45 -06:00
|
|
|
if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--help" ) ) ||
|
|
|
|
aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ) ) )
|
2005-10-19 06:10:07 -05:00
|
|
|
bHelp = true;
|
|
|
|
|
2011-01-20 04:23:45 -06:00
|
|
|
else if ( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--name" ) ) )
|
2005-10-19 06:10:07 -05:00
|
|
|
aName = GetCommandLineParam( ++i );
|
|
|
|
|
2011-01-20 04:23:45 -06:00
|
|
|
else if ( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--path" ) ) )
|
2005-10-19 06:10:07 -05:00
|
|
|
aPath = Smartify( GetCommandLineParam( ++i ) );
|
|
|
|
|
2011-01-20 04:23:45 -06:00
|
|
|
else if ( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--destdir" ) ) )
|
2005-10-19 06:10:07 -05:00
|
|
|
aDestDir = GetCommandLineParam( ++i );
|
|
|
|
|
2011-01-20 04:23:45 -06:00
|
|
|
else if ( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--number-from" ) ) )
|
2005-10-19 06:10:07 -05:00
|
|
|
nNumFrom = GetCommandLineParam( ++i ).ToInt32();
|
|
|
|
|
|
|
|
else
|
|
|
|
aFiles.push_back( Smartify( aParam ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bHelp )
|
|
|
|
{
|
|
|
|
PrintHelp();
|
2010-12-10 10:12:01 -06:00
|
|
|
return EXIT_SUCCESS;
|
2005-10-19 06:10:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
createTheme( aName, aPath, aDestDir, nNumFrom, aFiles );
|
2010-12-10 10:12:01 -06:00
|
|
|
return EXIT_SUCCESS;
|
2005-10-19 06:10:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GalApp aGalApp;
|
2010-10-12 08:53:47 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|