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