LCOV - code coverage report
Current view: top level - svx/source/gengal - gengal.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 110 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <stdio.h>
      31                 :            : #include <unistd.h>
      32                 :            : #include <memory>
      33                 :            : #include <list>
      34                 :            : 
      35                 :            : #include <unotools/streamwrap.hxx>
      36                 :            : #include <unotools/ucbstreamhelper.hxx>
      37                 :            : 
      38                 :            : #include <comphelper/processfactory.hxx>
      39                 :            : #include <cppuhelper/servicefactory.hxx>
      40                 :            : #include <cppuhelper/bootstrap.hxx>
      41                 :            : #include <com/sun/star/uno/Reference.h>
      42                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      43                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      44                 :            : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      45                 :            : 
      46                 :            : #include <ucbhelper/contentbroker.hxx>
      47                 :            : #include <ucbhelper/configurationkeys.hxx>
      48                 :            : 
      49                 :            : #include <tools/urlobj.hxx>
      50                 :            : #include <tools/fsys.hxx>
      51                 :            : 
      52                 :            : #include <vcl/window.hxx>
      53                 :            : #include <vcl/svapp.hxx>
      54                 :            : #include <vcl/font.hxx>
      55                 :            : #include <vcl/print.hxx>
      56                 :            : #include <vcl/toolbox.hxx>
      57                 :            : #include <vcl/help.hxx>
      58                 :            : #include <vcl/scrbar.hxx>
      59                 :            : #include <vcl/wrkwin.hxx>
      60                 :            : #include <vcl/msgbox.hxx>
      61                 :            : 
      62                 :            : #include <osl/file.hxx>
      63                 :            : #include <osl/process.h>
      64                 :            : #include <rtl/bootstrap.hxx>
      65                 :            : 
      66                 :            : #include <svx/galtheme.hxx>
      67                 :            : #include <svx/gallery1.hxx>
      68                 :            : 
      69                 :            : using namespace ::com::sun::star::uno;
      70                 :            : using namespace ::com::sun::star::registry;
      71                 :            : using namespace ::com::sun::star::lang;
      72                 :            : 
      73                 :            : typedef ::std::list<rtl::OUString> FileNameList;
      74                 :            : 
      75                 :          0 : class GalApp : public Application
      76                 :            : {
      77                 :            : public:
      78                 :            :     virtual int Main();
      79                 :            : 
      80                 :            : protected:
      81                 :            :     Reference<XMultiServiceFactory> xMSF;
      82                 :            :     void Init();
      83                 :            :     void InitUCB();
      84                 :            : };
      85                 :            : 
      86                 :          0 : Gallery* createGallery( const rtl::OUString& aGalleryURL )
      87                 :            : {
      88                 :          0 :     return new Gallery( aGalleryURL );
      89                 :            : }
      90                 :            : 
      91                 :          0 : void disposeGallery( Gallery* pGallery )
      92                 :            : {
      93                 :          0 :     delete pGallery;
      94                 :          0 : }
      95                 :            : 
      96                 :          0 : static void createTheme( rtl::OUString aThemeName,
      97                 :            :                          rtl::OUString aGalleryURL,
      98                 :            :                          rtl::OUString aDestDir,
      99                 :            :                          sal_uInt32 nNumFrom,
     100                 :            :                          FileNameList &rFiles )
     101                 :            : {
     102                 :          0 :     Gallery * pGallery( createGallery( aGalleryURL ) );
     103                 :            : 
     104                 :          0 :     if (!pGallery ) {
     105                 :            :             fprintf( stderr, "Could't acquire '%s'\n",
     106                 :          0 :                      rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
     107                 :          0 :             exit( 1 );
     108                 :            :     }
     109                 :            :     fprintf( stderr, "Work on gallery '%s'\n",
     110                 :          0 :                      rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
     111                 :            : 
     112                 :            :     fprintf( stderr, "Existing themes: %lu\n",
     113                 :            :              sal::static_int_cast< unsigned long >(
     114                 :          0 :                  pGallery->GetThemeCount() ) );
     115                 :            : 
     116                 :          0 :     if( !pGallery->HasTheme( aThemeName) ) {
     117                 :          0 :             if( !pGallery->CreateTheme( aThemeName, nNumFrom ) ) {
     118                 :          0 :                     fprintf( stderr, "Failed to create theme\n" );
     119                 :          0 :                     disposeGallery( pGallery );
     120                 :          0 :                     exit( 1 );
     121                 :            :             }
     122                 :            :     }
     123                 :            : 
     124                 :            :     fprintf( stderr, "Existing themes: %lu\n",
     125                 :            :              sal::static_int_cast< unsigned long >(
     126                 :          0 :                  pGallery->GetThemeCount() ) );
     127                 :            : 
     128                 :          0 :     SfxListener aListener;
     129                 :            : 
     130                 :          0 :     GalleryTheme *pGalTheme = pGallery->AcquireTheme( aThemeName, aListener );
     131                 :          0 :     if ( pGalTheme == NULL  ) {
     132                 :          0 :             fprintf( stderr, "Failed to acquire theme\n" );
     133                 :          0 :             disposeGallery( pGallery );
     134                 :          0 :             exit( 1 );
     135                 :            :     }
     136                 :            : 
     137                 :            :     fprintf( stderr, "Using DestDir: %s\n",
     138                 :          0 :              rtl::OUStringToOString(aDestDir, RTL_TEXTENCODING_UTF8).getStr() );
     139                 :          0 :     pGalTheme->SetDestDir(String(aDestDir));
     140                 :            : 
     141                 :          0 :     FileNameList::const_iterator aIter;
     142                 :            : 
     143                 :          0 :     for( aIter = rFiles.begin(); aIter != rFiles.end(); ++aIter )
     144                 :            :     {
     145                 :            : //  Should/could use:
     146                 :            : //  if ( ! pGalTheme->InsertFileOrDirURL( aURL ) ) {
     147                 :            : //  Requires a load more components ...
     148                 :            : 
     149                 :          0 :         Graphic aGraphic;
     150                 :          0 :         String aFormat;
     151                 :            : 
     152                 :          0 :         if ( ! pGalTheme->InsertURL( *aIter ) )
     153                 :            :             fprintf( stderr, "Failed to import '%s'\n",
     154                 :          0 :                      rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr() );
     155                 :            :         else
     156                 :            :             fprintf( stderr, "Imported file '%s' (%lu)\n",
     157                 :          0 :                      rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr(),
     158                 :            :                      sal::static_int_cast< unsigned long >(
     159                 :          0 :                          pGalTheme->GetObjectCount() ) );
     160                 :          0 :     }
     161                 :            : 
     162                 :          0 :     pGallery->ReleaseTheme( pGalTheme, aListener );
     163                 :          0 :     disposeGallery( pGallery );
     164                 :          0 : }
     165                 :            : 
     166                 :          0 : static void PrintHelp()
     167                 :            : {
     168                 :          0 :     fprintf( stdout, "Utility to generate OO.o gallery files\n\n" );
     169                 :            : 
     170                 :          0 :     fprintf( stdout, "using: gengal --name <name> --path <dir> [ --destdir <path> ]\n");
     171                 :          0 :     fprintf( stdout, "              [ --number-from <num> ] [ files ... ]\n\n" );
     172                 :            : 
     173                 :          0 :     fprintf( stdout, "options:\n");
     174                 :          0 :     fprintf( stdout, " --name <theme>\t\tdefines a name of the created or updated theme.\n");
     175                 :          0 :     fprintf( stdout, " --path <dir>\t\tdefines directory where the gallery files are created\n");
     176                 :          0 :     fprintf( stdout, "\t\t\tor updated.\n");
     177                 :          0 :     fprintf( stdout, " --destdir <dir>\tdefines a path prefix to be removed from the paths\n");
     178                 :          0 :     fprintf( stdout, "\t\t\tstored in the gallery files. It is useful to create\n");
     179                 :          0 :     fprintf( stdout, "\t\t\tRPM packages using the BuildRoot feature.\n");
     180                 :          0 :     fprintf( stdout, " --number-from <num>\tdefines minimal number for the newly created gallery\n");
     181                 :          0 :     fprintf( stdout, "\t\t\ttheme files.\n");
     182                 :          0 :     fprintf( stdout, " files\t\t\tlists files to be added to the gallery. Absolute paths\n");
     183                 :          0 :     fprintf( stdout, "\t\t\tare required.\n");
     184                 :          0 : }
     185                 :            : 
     186                 :          0 : static rtl::OUString Smartify( const rtl::OUString &rPath )
     187                 :            : {
     188                 :          0 :     INetURLObject aURL;
     189                 :          0 :     aURL.SetSmartURL( rPath );
     190                 :          0 :     return aURL.GetMainURL( INetURLObject::NO_DECODE );
     191                 :            : }
     192                 :            : 
     193                 :          0 : void GalApp::Init()
     194                 :            : {
     195                 :          0 :     if( getenv( "OOO_INSTALL_PREFIX" ) == NULL ) {
     196                 :          0 :         rtl::OUString fileName = GetAppFileName();
     197                 :          0 :         int lastSlash = fileName.lastIndexOf( '/' );
     198                 :            : #ifdef WNT
     199                 :            :         // Don't know which directory separators GetAppFileName() returns on Windows.
     200                 :            :         // Be safe and take into consideration they might be backslashes.
     201                 :            :         if( fileName.lastIndexOf( '\\' ) > lastSlash )
     202                 :            :             lastSlash = fileName.lastIndexOf( '\\' );
     203                 :            : #endif
     204                 :          0 :         rtl::OUString baseBinDir = fileName.copy( 0, lastSlash );
     205                 :          0 :         rtl::OUString installPrefix = baseBinDir + rtl::OUString("/../..");
     206                 :            : 
     207                 :          0 :         rtl::OUString envVar("OOO_INSTALL_PREFIX");
     208                 :          0 :         osl_setEnvironment(envVar.pData, installPrefix.pData);
     209                 :            :     }
     210                 :            :     OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
     211                 :            : 
     212                 :            :     Reference<XComponentContext> xComponentContext
     213                 :          0 :         = ::cppu::defaultBootstrap_InitialComponentContext();
     214                 :            :     xMSF = Reference<XMultiServiceFactory>
     215                 :          0 :         ( xComponentContext->getServiceManager(), UNO_QUERY );
     216                 :          0 :     if( !xMSF.is() )
     217                 :          0 :         fprintf( stderr, "Failed to bootstrap\n" );
     218                 :          0 :     ::comphelper::setProcessServiceFactory( xMSF );
     219                 :            : 
     220                 :          0 :     InitUCB();
     221                 :          0 : }
     222                 :            : 
     223                 :          0 : void GalApp::InitUCB()
     224                 :            : {
     225                 :          0 :     Sequence< Any > aArgs(2);
     226                 :          0 :     aArgs[0]
     227                 :          0 :         <<= rtl::OUString(UCB_CONFIGURATION_KEY1_LOCAL);
     228                 :          0 :     aArgs[1]
     229                 :          0 :         <<= rtl::OUString(UCB_CONFIGURATION_KEY2_OFFICE);
     230                 :            : 
     231                 :          0 :     if (! ::ucbhelper::ContentBroker::initialize( xMSF, aArgs ) )
     232                 :          0 :         fprintf( stderr, "Failed to init content broker\n" );
     233                 :          0 : }
     234                 :            : 
     235                 :          0 : int GalApp::Main()
     236                 :            : {
     237                 :          0 :     bool bHelp = false;
     238                 :          0 :     rtl::OUString aPath, aDestDir;
     239                 :          0 :     rtl::OUString aName("Default name");
     240                 :          0 :     sal_uInt32 nNumFrom = 0;
     241                 :          0 :     FileNameList aFiles;
     242                 :            : 
     243                 :          0 :     for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
     244                 :            :     {
     245                 :          0 :         rtl::OUString aParam = GetCommandLineParam( i );
     246                 :            : 
     247                 :          0 :         if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--help" ) ) ||
     248                 :          0 :             aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ) ) )
     249                 :          0 :                 bHelp = true;
     250                 :            : 
     251                 :          0 :         else if ( aParam == "--name" )
     252                 :          0 :             aName = GetCommandLineParam( ++i );
     253                 :            : 
     254                 :          0 :         else if ( aParam == "--path" )
     255                 :          0 :             aPath = Smartify( GetCommandLineParam( ++i ) );
     256                 :            : 
     257                 :          0 :         else if ( aParam == "--destdir" )
     258                 :          0 :             aDestDir = GetCommandLineParam( ++i );
     259                 :            : 
     260                 :          0 :         else if ( aParam == "--number-from" )
     261                 :          0 :              nNumFrom = GetCommandLineParam( ++i ).ToInt32();
     262                 :            : 
     263                 :            :         else
     264                 :          0 :             aFiles.push_back( Smartify( aParam ) );
     265                 :          0 :     }
     266                 :            : 
     267                 :          0 :     if( bHelp )
     268                 :            :     {
     269                 :          0 :         PrintHelp();
     270                 :          0 :         return EXIT_SUCCESS;
     271                 :            :     }
     272                 :            : 
     273                 :          0 :     createTheme( aName, aPath, aDestDir, nNumFrom, aFiles );
     274                 :          0 :     return EXIT_SUCCESS;
     275                 :            : }
     276                 :            : 
     277                 :          0 : GalApp aGalApp;
     278                 :            : 
     279                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10