LCOV - code coverage report
Current view: top level - svx/source/gengal - gengal.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 115 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : 
      11             : // Include this before stdio.h for the __MINGW32__ sake.
      12             : // This header contails a define that modifies the way
      13             : // formatting strings work for the mingw platforms.
      14             : #include <sal/types.h>
      15             : 
      16             : #include <stdio.h>
      17             : #ifndef _WIN32
      18             : #include <unistd.h>
      19             : #endif
      20             : 
      21             : #include <vector>
      22             : 
      23             : #include <unotools/streamwrap.hxx>
      24             : #include <unotools/ucbstreamhelper.hxx>
      25             : 
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <cppuhelper/bootstrap.hxx>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/lang/XInitialization.hpp>
      30             : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      31             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      32             : 
      33             : #include <tools/urlobj.hxx>
      34             : #include <vcl/vclmain.hxx>
      35             : 
      36             : #include <osl/file.hxx>
      37             : #include <osl/process.h>
      38             : #include <rtl/bootstrap.hxx>
      39             : #include <vcl/svapp.hxx>
      40             : 
      41             : #include <svx/galtheme.hxx>
      42             : #include <svx/gallery1.hxx>
      43             : 
      44             : using namespace ::com::sun::star;
      45             : 
      46           0 : class GalApp : public Application
      47             : {
      48             :     bool mbInBuildTree;
      49             :     bool mbRelativeURLs;
      50             : public:
      51           0 :     GalApp() : mbInBuildTree( false ), mbRelativeURLs( false )
      52             :     {
      53           0 :     }
      54             :     virtual int Main() SAL_OVERRIDE;
      55             : 
      56             : protected:
      57             :     uno::Reference<lang::XMultiServiceFactory> xMSF;
      58             :     void Init() SAL_OVERRIDE;
      59             :     void DeInit() SAL_OVERRIDE;
      60             : };
      61             : 
      62           0 : Gallery* createGallery( const OUString& rURL )
      63             : {
      64           0 :     return new Gallery( rURL );
      65             : }
      66             : 
      67           0 : void disposeGallery( Gallery* pGallery )
      68             : {
      69           0 :     delete pGallery;
      70           0 : }
      71             : 
      72           0 : static void createTheme( const OUString& aThemeName, const OUString& aGalleryURL,
      73             :                          const OUString& aDestDir, std::vector<INetURLObject> &rFiles,
      74             :                          bool bRelativeURLs )
      75             : {
      76             :     Gallery* pGallery;
      77             : 
      78           0 :     pGallery = createGallery( aGalleryURL );
      79           0 :     if (!pGallery ) {
      80             :             fprintf( stderr, "Could't create '%s'\n",
      81           0 :                      OUStringToOString( aGalleryURL, RTL_TEXTENCODING_UTF8 ).getStr() );
      82           0 :             exit( 1 );
      83             :     }
      84             :     fprintf( stderr, "Work on gallery '%s'\n",
      85           0 :              OUStringToOString( aGalleryURL, RTL_TEXTENCODING_UTF8 ).getStr() );
      86             : 
      87             :     fprintf( stderr, "Existing themes: %" SAL_PRI_SIZET "u\n",
      88           0 :              pGallery->GetThemeCount() );
      89             : 
      90             :     GalleryTheme *pGalTheme;
      91           0 :     if( !pGallery->HasTheme( aThemeName) ) {
      92           0 :             if( !pGallery->CreateTheme( aThemeName ) ) {
      93           0 :                     fprintf( stderr, "Failed to create theme\n" );
      94           0 :                     exit( 1 );
      95             :             }
      96             :     }
      97             : 
      98             :     fprintf( stderr, "Existing themes: %" SAL_PRI_SIZET "u\n",
      99           0 :              pGallery->GetThemeCount() );
     100             : 
     101           0 :     SfxListener aListener;
     102             : 
     103           0 :     if ( !( pGalTheme = pGallery->AcquireTheme( aThemeName, aListener ) ) ) {
     104           0 :             fprintf( stderr, "Failed to acquire theme\n" );
     105           0 :             exit( 1 );
     106             :     }
     107             : 
     108             :     fprintf( stderr, "Using DestDir: %s\n",
     109           0 :              OUStringToOString( aDestDir, RTL_TEXTENCODING_UTF8 ).getStr() );
     110           0 :     pGalTheme->SetDestDir( aDestDir, bRelativeURLs );
     111             : 
     112           0 :     std::vector<INetURLObject>::const_iterator aIter;
     113             : 
     114           0 :     for( aIter = rFiles.begin(); aIter != rFiles.end(); ++aIter )
     115             :     {
     116             : //  Should/could use:
     117             : //    if ( ! pGalTheme->InsertFileOrDirURL( aURL ) ) {
     118             : //    Requires a load more components ...
     119             : 
     120           0 :         Graphic aGraphic;
     121             : 
     122           0 :         if ( ! pGalTheme->InsertURL( *aIter ) )
     123             :             fprintf( stderr, "Failed to import '%s'\n",
     124           0 :                      OUStringToOString( aIter->GetMainURL(INetURLObject::NO_DECODE), RTL_TEXTENCODING_UTF8 ).getStr() );
     125             :         else
     126             :             fprintf( stderr, "Imported file '%s' (%" SAL_PRI_SIZET "u)\n",
     127             :                      OUStringToOString( aIter->GetMainURL(INetURLObject::NO_DECODE), RTL_TEXTENCODING_UTF8 ).getStr(),
     128           0 :                      pGalTheme->GetObjectCount() );
     129           0 :     }
     130             : 
     131           0 :     pGallery->ReleaseTheme( pGalTheme, aListener );
     132             : 
     133           0 :     disposeGallery( pGallery );
     134           0 : }
     135             : 
     136           0 : static int PrintHelp()
     137             : {
     138           0 :     fprintf( stdout, "Utility to generate LibreOffice gallery files\n\n" );
     139             : 
     140           0 :     fprintf( stdout, "using: gengal --name <name> --path <dir> [ --destdir <path> ]\n");
     141           0 :     fprintf( stdout, "              [ files ... ]\n\n" );
     142             : 
     143           0 :     fprintf( stdout, "options:\n");
     144           0 :     fprintf( stdout, " --name <theme>\t\tdefines the user visible name of the created or updated theme.\n");
     145             : 
     146           0 :     fprintf( stdout, " --path <dir>\t\tdefines directory where the gallery files are created\n");
     147           0 :     fprintf( stdout, "\t\t\tor updated.\n");
     148             : 
     149           0 :     fprintf( stdout, " --destdir <dir>\tdefines a path prefix to be removed from the paths\n");
     150           0 :     fprintf( stdout, "\t\t\tstored in the gallery files. It is useful to create\n");
     151           0 :     fprintf( stdout, "\t\t\tRPM packages using the BuildRoot feature.\n");
     152             : 
     153           0 :     fprintf( stdout, " --relative-urls\t\tflags that after removing the destdir, the URL should be a path relative to the gallery folder in the install\n");
     154           0 :     fprintf( stdout, "\t\t\tprimarily used for internal gallery generation at compile time.\n");
     155           0 :     fprintf( stdout, "\t\t\ttheme files.\n");
     156           0 :     fprintf( stdout, " files\t\t\tlists files to be added to the gallery. Absolute paths\n");
     157           0 :     fprintf( stdout, "\t\t\tare required.\n");
     158             :     // --build-tree not documented - only useful during the build ...
     159             : 
     160           0 :     return EXIT_SUCCESS;
     161             : }
     162             : 
     163           0 : static INetURLObject Smartify( const OUString &rPath )
     164             : {
     165           0 :     INetURLObject aURL;
     166           0 :     aURL.SetSmartURL( rPath );
     167           0 :     return aURL;
     168             : }
     169             : 
     170           0 : void GalApp::Init()
     171             : {
     172             :     try {
     173           0 :         if( !mbInBuildTree && getenv( "OOO_INSTALL_PREFIX" ) == NULL ) {
     174           0 :             OUString fileName = GetAppFileName();
     175           0 :             int lastSlash = fileName.lastIndexOf( '/' );
     176             : #ifdef WNT
     177             :         // Don't know which directory separators GetAppFileName() returns on Windows.
     178             :         // Be safe and take into consideration they might be backslashes.
     179             :             if( fileName.lastIndexOf( '\\' ) > lastSlash )
     180             :                 lastSlash = fileName.lastIndexOf( '\\' );
     181             : #endif
     182           0 :             OUString baseBinDir = fileName.copy( 0, lastSlash );
     183           0 :             OUString installPrefix = baseBinDir + "/../..";
     184             : 
     185           0 :             OUString envVar( "OOO_INSTALL_PREFIX");
     186           0 :             osl_setEnvironment(envVar.pData, installPrefix.pData);
     187             :         }
     188             :         OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
     189             : 
     190             :         uno::Reference<uno::XComponentContext> xComponentContext
     191           0 :             = ::cppu::defaultBootstrap_InitialComponentContext();
     192           0 :         xMSF = uno::Reference<lang::XMultiServiceFactory>
     193           0 :             ( xComponentContext->getServiceManager(), uno::UNO_QUERY );
     194           0 :         if( !xMSF.is() )
     195             :         {
     196           0 :             fprintf( stderr, "Failed to bootstrap\n" );
     197           0 :             exit( 1 );
     198             :         }
     199           0 :         ::comphelper::setProcessServiceFactory( xMSF );
     200             : 
     201             :         // For backwards compatibility, in case some code still uses plain
     202             :         // createInstance w/o args directly to obtain an instance:
     203           0 :         com::sun::star::ucb::UniversalContentBroker::create(xComponentContext);
     204           0 :     } catch (const uno::Exception &e) {
     205             :         fprintf( stderr, "Bootstrap exception '%s'\n",
     206           0 :                  rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
     207           0 :         exit( 1 );
     208             :     }
     209           0 : }
     210             : 
     211           0 : int GalApp::Main()
     212             : {
     213           0 :     OUString aPath, aDestDir;
     214           0 :     OUString aName( "Default name" );
     215           0 :     std::vector<INetURLObject> aFiles;
     216             : 
     217           0 :     for( sal_uInt32 i = 0; i < GetCommandLineParamCount(); i++ )
     218             :     {
     219           0 :         OUString aParam = GetCommandLineParam( i );
     220             : 
     221           0 :         if ( aParam.startsWith( "-env:" ) )
     222           0 :             continue;
     223           0 :         else if ( aParam == "--help" || aParam == "-h"  )
     224           0 :             return PrintHelp();
     225           0 :         else if ( aParam == "--build-tree" )
     226             :         {
     227           0 :             mbRelativeURLs = true;
     228           0 :             mbInBuildTree = true;
     229             :         }
     230           0 :         else if ( aParam == "--name" )
     231           0 :             aName = GetCommandLineParam( ++i );
     232           0 :         else if ( aParam == "--path" )
     233           0 :             aPath = Smartify( GetCommandLineParam( ++i ) ).
     234           0 :                 GetMainURL(INetURLObject::NO_DECODE);
     235           0 :         else if ( aParam == "--destdir" )
     236           0 :             aDestDir = GetCommandLineParam( ++i );
     237           0 :         else if ( aParam == "--relative-urls" )
     238           0 :             mbRelativeURLs = true;
     239           0 :         else if ( aParam == "--number-from" )
     240             :             fprintf ( stderr, "--number-from is deprecated, themes now "
     241           0 :                       "have filenames based on their names\n" );
     242             :         else
     243           0 :             aFiles.push_back( Smartify( aParam ) );
     244           0 :     }
     245             : 
     246           0 :     if( aFiles.empty() )
     247           0 :         return PrintHelp();
     248             : 
     249           0 :     createTheme( aName, aPath, aDestDir, aFiles, mbRelativeURLs );
     250             : 
     251           0 :     return EXIT_SUCCESS;
     252             : }
     253             : 
     254           0 : void GalApp::DeInit()
     255             : {
     256             :     uno::Reference< lang::XComponent >(
     257             :         comphelper::getProcessComponentContext(),
     258           0 :         uno::UNO_QUERY_THROW )-> dispose();
     259           0 :     ::comphelper::setProcessServiceFactory( NULL );
     260           0 : }
     261             : 
     262           0 : void vclmain::createApplication()
     263             : {
     264           0 :     Application::EnableConsoleOnly();
     265           0 :     static GalApp aGalApp;
     266           0 : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10