LCOV - code coverage report
Current view: top level - libreoffice/svx/source/gengal - gengal.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 103 0.0 %
Date: 2012-12-27 Functions: 0 11 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             :  *
       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/bootstrap.hxx>
      40             : #include <com/sun/star/uno/Reference.h>
      41             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      42             : #include <com/sun/star/lang/XInitialization.hpp>
      43             : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      44             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      45             : 
      46             : #include <tools/urlobj.hxx>
      47             : #include <tools/fsys.hxx>
      48             : 
      49             : #include <vcl/vclmain.hxx>
      50             : #include <vcl/window.hxx>
      51             : #include <vcl/svapp.hxx>
      52             : #include <vcl/font.hxx>
      53             : #include <vcl/print.hxx>
      54             : #include <vcl/toolbox.hxx>
      55             : #include <vcl/help.hxx>
      56             : #include <vcl/scrbar.hxx>
      57             : #include <vcl/wrkwin.hxx>
      58             : #include <vcl/msgbox.hxx>
      59             : 
      60             : #include <osl/file.hxx>
      61             : #include <osl/process.h>
      62             : #include <rtl/bootstrap.hxx>
      63             : 
      64             : #include <svx/galtheme.hxx>
      65             : #include <svx/gallery1.hxx>
      66             : 
      67             : using namespace ::com::sun::star::uno;
      68             : using namespace ::com::sun::star::registry;
      69             : using namespace ::com::sun::star::lang;
      70             : 
      71             : typedef ::std::list<rtl::OUString> FileNameList;
      72             : 
      73           0 : class GalApp : public Application
      74             : {
      75             : public:
      76             :     virtual int Main();
      77             : 
      78             : protected:
      79             :     Reference<XMultiServiceFactory> xMSF;
      80             :     void Init();
      81             : };
      82             : 
      83           0 : Gallery* createGallery( const rtl::OUString& aGalleryURL )
      84             : {
      85           0 :     return new Gallery( aGalleryURL );
      86             : }
      87             : 
      88           0 : void disposeGallery( Gallery* pGallery )
      89             : {
      90           0 :     delete pGallery;
      91           0 : }
      92             : 
      93           0 : static void createTheme( rtl::OUString aThemeName,
      94             :                          rtl::OUString aGalleryURL,
      95             :                          rtl::OUString aDestDir,
      96             :                          sal_uInt32 nNumFrom,
      97             :                          FileNameList &rFiles )
      98             : {
      99           0 :     Gallery * pGallery( createGallery( aGalleryURL ) );
     100             : 
     101           0 :     if (!pGallery ) {
     102             :             fprintf( stderr, "Could't acquire '%s'\n",
     103           0 :                      rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
     104           0 :             exit( 1 );
     105             :     }
     106             :     fprintf( stderr, "Work on gallery '%s'\n",
     107           0 :                      rtl::OUStringToOString(aGalleryURL, RTL_TEXTENCODING_UTF8).getStr() );
     108             : 
     109             :     fprintf( stderr, "Existing themes: %lu\n",
     110             :              sal::static_int_cast< unsigned long >(
     111           0 :                  pGallery->GetThemeCount() ) );
     112             : 
     113           0 :     if( !pGallery->HasTheme( aThemeName) ) {
     114           0 :             if( !pGallery->CreateTheme( aThemeName, nNumFrom ) ) {
     115           0 :                     fprintf( stderr, "Failed to create theme\n" );
     116           0 :                     disposeGallery( pGallery );
     117           0 :                     exit( 1 );
     118             :             }
     119             :     }
     120             : 
     121             :     fprintf( stderr, "Existing themes: %lu\n",
     122             :              sal::static_int_cast< unsigned long >(
     123           0 :                  pGallery->GetThemeCount() ) );
     124             : 
     125           0 :     SfxListener aListener;
     126             : 
     127           0 :     GalleryTheme *pGalTheme = pGallery->AcquireTheme( aThemeName, aListener );
     128           0 :     if ( pGalTheme == NULL  ) {
     129           0 :             fprintf( stderr, "Failed to acquire theme\n" );
     130           0 :             disposeGallery( pGallery );
     131           0 :             exit( 1 );
     132             :     }
     133             : 
     134             :     fprintf( stderr, "Using DestDir: %s\n",
     135           0 :              rtl::OUStringToOString(aDestDir, RTL_TEXTENCODING_UTF8).getStr() );
     136           0 :     pGalTheme->SetDestDir(String(aDestDir));
     137             : 
     138           0 :     FileNameList::const_iterator aIter;
     139             : 
     140           0 :     for( aIter = rFiles.begin(); aIter != rFiles.end(); ++aIter )
     141             :     {
     142             : //  Should/could use:
     143             : //  if ( ! pGalTheme->InsertFileOrDirURL( aURL ) ) {
     144             : //  Requires a load more components ...
     145             : 
     146           0 :         Graphic aGraphic;
     147           0 :         String aFormat;
     148             : 
     149           0 :         if ( ! pGalTheme->InsertURL( *aIter ) )
     150             :             fprintf( stderr, "Failed to import '%s'\n",
     151           0 :                      rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr() );
     152             :         else
     153             :             fprintf( stderr, "Imported file '%s' (%lu)\n",
     154           0 :                      rtl::OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8).getStr(),
     155             :                      sal::static_int_cast< unsigned long >(
     156           0 :                          pGalTheme->GetObjectCount() ) );
     157           0 :     }
     158             : 
     159           0 :     pGallery->ReleaseTheme( pGalTheme, aListener );
     160           0 :     disposeGallery( pGallery );
     161           0 : }
     162             : 
     163           0 : static void PrintHelp()
     164             : {
     165           0 :     fprintf( stdout, "Utility to generate OO.o gallery files\n\n" );
     166             : 
     167           0 :     fprintf( stdout, "using: gengal --name <name> --path <dir> [ --destdir <path> ]\n");
     168           0 :     fprintf( stdout, "              [ --number-from <num> ] [ files ... ]\n\n" );
     169             : 
     170           0 :     fprintf( stdout, "options:\n");
     171           0 :     fprintf( stdout, " --name <theme>\t\tdefines a name of the created or updated theme.\n");
     172           0 :     fprintf( stdout, " --path <dir>\t\tdefines directory where the gallery files are created\n");
     173           0 :     fprintf( stdout, "\t\t\tor updated.\n");
     174           0 :     fprintf( stdout, " --destdir <dir>\tdefines a path prefix to be removed from the paths\n");
     175           0 :     fprintf( stdout, "\t\t\tstored in the gallery files. It is useful to create\n");
     176           0 :     fprintf( stdout, "\t\t\tRPM packages using the BuildRoot feature.\n");
     177           0 :     fprintf( stdout, " --number-from <num>\tdefines minimal number for the newly created gallery\n");
     178           0 :     fprintf( stdout, "\t\t\ttheme files.\n");
     179           0 :     fprintf( stdout, " files\t\t\tlists files to be added to the gallery. Absolute paths\n");
     180           0 :     fprintf( stdout, "\t\t\tare required.\n");
     181           0 : }
     182             : 
     183           0 : static rtl::OUString Smartify( const rtl::OUString &rPath )
     184             : {
     185           0 :     INetURLObject aURL;
     186           0 :     aURL.SetSmartURL( rPath );
     187           0 :     return aURL.GetMainURL( INetURLObject::NO_DECODE );
     188             : }
     189             : 
     190           0 : void GalApp::Init()
     191             : {
     192           0 :     if( getenv( "OOO_INSTALL_PREFIX" ) == NULL ) {
     193           0 :         rtl::OUString fileName = GetAppFileName();
     194           0 :         int lastSlash = fileName.lastIndexOf( '/' );
     195             : #ifdef WNT
     196             :         // Don't know which directory separators GetAppFileName() returns on Windows.
     197             :         // Be safe and take into consideration they might be backslashes.
     198             :         if( fileName.lastIndexOf( '\\' ) > lastSlash )
     199             :             lastSlash = fileName.lastIndexOf( '\\' );
     200             : #endif
     201           0 :         rtl::OUString baseBinDir = fileName.copy( 0, lastSlash );
     202           0 :         rtl::OUString installPrefix = baseBinDir + rtl::OUString("/../..");
     203             : 
     204           0 :         rtl::OUString envVar("OOO_INSTALL_PREFIX");
     205           0 :         osl_setEnvironment(envVar.pData, installPrefix.pData);
     206             :     }
     207             :     OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
     208             : 
     209             :     Reference<XComponentContext> xComponentContext
     210           0 :         = ::cppu::defaultBootstrap_InitialComponentContext();
     211             :     xMSF = Reference<XMultiServiceFactory>
     212           0 :         ( xComponentContext->getServiceManager(), UNO_QUERY );
     213           0 :     if( !xMSF.is() )
     214           0 :         fprintf( stderr, "Failed to bootstrap\n" );
     215           0 :     ::comphelper::setProcessServiceFactory( xMSF );
     216             : 
     217             :     // For backwards compatibility, in case some code still uses plain
     218             :     // createInstance w/o args directly to obtain an instance:
     219           0 :     com::sun::star::ucb::UniversalContentBroker::create(xComponentContext);
     220           0 : }
     221             : 
     222           0 : int GalApp::Main()
     223             : {
     224           0 :     bool bHelp = false;
     225           0 :     rtl::OUString aPath, aDestDir;
     226           0 :     rtl::OUString aName("Default name");
     227           0 :     sal_uInt32 nNumFrom = 0;
     228           0 :     FileNameList aFiles;
     229             : 
     230           0 :     for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
     231             :     {
     232           0 :         rtl::OUString aParam = GetCommandLineParam( i );
     233             : 
     234           0 :         if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--help" ) ) ||
     235           0 :             aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ) ) )
     236           0 :                 bHelp = true;
     237             : 
     238           0 :         else if ( aParam == "--name" )
     239           0 :             aName = GetCommandLineParam( ++i );
     240             : 
     241           0 :         else if ( aParam == "--path" )
     242           0 :             aPath = Smartify( GetCommandLineParam( ++i ) );
     243             : 
     244           0 :         else if ( aParam == "--destdir" )
     245           0 :             aDestDir = GetCommandLineParam( ++i );
     246             : 
     247           0 :         else if ( aParam == "--number-from" )
     248           0 :              nNumFrom = GetCommandLineParam( ++i ).ToInt32();
     249             : 
     250             :         else
     251           0 :             aFiles.push_back( Smartify( aParam ) );
     252           0 :     }
     253             : 
     254           0 :     if( bHelp )
     255             :     {
     256           0 :         PrintHelp();
     257           0 :         return EXIT_SUCCESS;
     258             :     }
     259             : 
     260           0 :     createTheme( aName, aPath, aDestDir, nNumFrom, aFiles );
     261           0 :     return EXIT_SUCCESS;
     262             : }
     263             : 
     264           0 : void vclmain::createApplication()
     265             : {
     266           0 :     static GalApp aGalApp;
     267           0 : }
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10