summaryrefslogtreecommitdiff
path: root/patches/dev300/desktop-cmd-bulk-conversion.diff (plain)
blob: c6dcf694ee6bbefbcfa17122ee585f0af6c014c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
diff --git desktop/source/app/app.cxx desktop/source/app/app.cxx
index dc7d7ef..1648da1 100644
--- desktop/source/app/app.cxx
+++ desktop/source/app/app.cxx
@@ -2468,6 +2468,8 @@ void Desktop::OpenClients()
         pArgs->GetPrinterName( aRequest.aPrinterName );
         pArgs->GetForceOpenList( aRequest.aForceOpenList );
         pArgs->GetForceNewList( aRequest.aForceNewList );
+        pArgs->GetConversionList( aRequest.aConversionList );
+        pArgs->GetConversionParams( aRequest.aConversionParams );
 
         if ( aRequest.aOpenList.getLength() > 0 ||
              aRequest.aViewList.getLength() > 0 ||
@@ -2475,7 +2477,8 @@ void Desktop::OpenClients()
              aRequest.aPrintList.getLength() > 0 ||
              aRequest.aForceOpenList.getLength() > 0 ||
              aRequest.aForceNewList.getLength() > 0 ||
-             ( aRequest.aPrintToList.getLength() > 0 && aRequest.aPrinterName.getLength() > 0 ))
+             ( aRequest.aPrintToList.getLength() > 0 && aRequest.aPrinterName.getLength() > 0 ) ||
+	     ( aRequest.aConversionList.getLength() > 0 && aRequest.aConversionParams.getLength() > 0 ))
         {
             bLoaded = sal_True;
 
@@ -2825,7 +2828,8 @@ void Desktop::OpenSplashScreen()
          !pCmdLine->IsNoLogo() &&
          !pCmdLine->IsTerminateAfterInit() &&
          !pCmdLine->GetPrintList( aTmpString ) &&
-         !pCmdLine->GetPrintToList( aTmpString ) )
+         !pCmdLine->GetPrintToList( aTmpString ) &&
+	 !pCmdLine->GetConversionList( aTmpString ))
     {
         // Determine application name from command line parameters
         OUString aAppName;
diff --git desktop/source/app/cmdlineargs.cxx desktop/source/app/cmdlineargs.cxx
index 88cb6bf..0d1f027 100644
--- desktop/source/app/cmdlineargs.cxx
+++ desktop/source/app/cmdlineargs.cxx
@@ -154,6 +154,8 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
     sal_Bool	bForceOpenEvent	= sal_False;
     sal_Bool	bForceNewEvent	= sal_False;
     sal_Bool 	bDisplaySpec	= sal_False;
+    sal_Bool    bConversionEvent= sal_False;
+    sal_Bool    bConversionParamsEvent=sal_False;
 
     m_eArgumentCount = NONE;
 
@@ -286,6 +288,12 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
                             bDisplaySpec	= sal_False;
                     }
                     #endif
+                    else if ( aArgStr.EqualsIgnoreCaseAscii( "-bulk" ))
+                    {
+		      bOpenEvent = sal_False;
+		      bConversionEvent = sal_True;
+		      bConversionParamsEvent = sal_True;
+		    }
                 }
                 else
                 {
@@ -295,6 +303,12 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
                         AddStringListParam_Impl( CMD_STRINGPARAM_PRINTERNAME, aArgStr );
                         bPrinterName = sal_False;
                     }
+                    else if ( bConversionParamsEvent && bConversionEvent )
+                    {
+                        // first argument must be the the params
+                        AddStringListParam_Impl( CMD_STRINGPARAM_CONVERSIONPARAMS, aArgStr );
+                        bConversionParamsEvent = sal_False;
+                    }
                     else
                     {
 						if( bOpenEvent || bViewEvent || bForceNewEvent || bForceOpenEvent )
@@ -326,6 +340,10 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
                             bDisplaySpec = sal_False; // only one display, not a lsit
                             bOpenEvent = sal_True;    // set back to standard
                         }
+                        else if ( bConversionEvent )
+                            AddStringListParam_Impl( CMD_STRINGPARAM_CONVERSIONLIST, aArgStr );
+                        else if ( bConversionParamsEvent )
+                            AddStringListParam_Impl( CMD_STRINGPARAM_CONVERSIONPARAMS, aArgStr );
                     }
                 }
             }
@@ -870,6 +888,22 @@ sal_Bool CommandLineArgs::GetPrinterName( ::rtl::OUString& rPara ) const
     return m_aStrSetParams[ CMD_STRINGPARAM_PRINTERNAME ];
 }
 
+sal_Bool CommandLineArgs::GetConversionList( ::rtl::OUString& rPara ) const
+{
+    osl::MutexGuard  aMutexGuard( m_aMutex );
+    rPara = m_aStrParams[ CMD_STRINGPARAM_CONVERSIONLIST ];
+    return m_aStrSetParams[ CMD_STRINGPARAM_CONVERSIONLIST ];
+}
+
+sal_Bool CommandLineArgs::GetConversionParams( ::rtl::OUString& rPara ) const
+{
+    osl::MutexGuard  aMutexGuard( m_aMutex );
+    rPara = m_aStrParams[ CMD_STRINGPARAM_CONVERSIONPARAMS ];
+    return m_aStrSetParams[ CMD_STRINGPARAM_CONVERSIONPARAMS ];
+}
+
+
+
 sal_Bool CommandLineArgs::IsEmpty() const
 {
     osl::MutexGuard  aMutexGuard( m_aMutex );
diff --git desktop/source/app/cmdlineargs.hxx desktop/source/app/cmdlineargs.hxx
index 9b5d046..f98becf 100644
--- desktop/source/app/cmdlineargs.hxx
+++ desktop/source/app/cmdlineargs.hxx
@@ -93,6 +93,8 @@ class CommandLineArgs
             CMD_STRINGPARAM_VERSION,
             CMD_STRINGPARAM_PRINTTOLIST,
             CMD_STRINGPARAM_PRINTERNAME,
+	    CMD_STRINGPARAM_CONVERSIONLIST,
+	    CMD_STRINGPARAM_CONVERSIONPARAMS,	    
             CMD_STRINGPARAM_DISPLAY,
             CMD_STRINGPARAM_COUNT			// must be last element!
         };
@@ -171,6 +173,8 @@ class CommandLineArgs
         sal_Bool				GetPrintList( ::rtl::OUString& rPara) const;
         sal_Bool				GetPrintToList( ::rtl::OUString& rPara ) const;
         sal_Bool				GetPrinterName( ::rtl::OUString& rPara ) const;
+        sal_Bool				GetConversionList( ::rtl::OUString& rPara ) const;
+        sal_Bool				GetConversionParams( ::rtl::OUString& rPara ) const;
 
         // Special analyzed states (does not match directly to a command line parameter!)
         sal_Bool                IsPrinting() const;
diff --git desktop/source/app/dispatchwatcher.cxx desktop/source/app/dispatchwatcher.cxx
index 891e756..cc87832 100644
--- desktop/source/app/dispatchwatcher.cxx
+++ desktop/source/app/dispatchwatcher.cxx
@@ -51,6 +51,7 @@
 #include <com/sun/star/util/XURLTransformer.hpp>
 #include <com/sun/star/document/MacroExecMode.hpp>
 #include <com/sun/star/document/UpdateDocMode.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 
 #include <tools/urlobj.hxx>
 #include <comphelper/mediadescriptor.hxx>
@@ -122,7 +123,7 @@ DispatchWatcher* DispatchWatcher::GetDispatchWatcher()
 
 
 DispatchWatcher::DispatchWatcher()
-    : m_nRequestCount(1)
+    : m_nRequestCount(0)
 {
 }
 
@@ -142,11 +143,16 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch
     std::vector< DispatchHolder >	aDispatches;
     ::rtl::OUString					aAsTemplateArg( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate"));
 
+    printf("executeDispatchRequests(bNoTerminate=%i)\n", bNoTerminate);
+    m_nRequestCount++;
+
     for ( p = aDispatchRequestsList.begin(); p != aDispatchRequestsList.end(); p++ )
     {
         String					aPrinterName;
         const DispatchRequest&	aDispatchRequest = *p;
 
+	printf("#aDispatchRequest\n");
+
         // create parameter array
         sal_Int32 nCount = 4;
         if ( aDispatchRequest.aPreselectedFactory.getLength() )
@@ -154,7 +160,8 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch
 
         // we need more properties for a print/print to request
         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-             aDispatchRequest.aRequestType == REQUEST_PRINTTO  )
+             aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
+	     aDispatchRequest.aRequestType == REQUEST_CONVERSION)
             nCount++;
 
         Sequence < PropertyValue > aArgs( nCount );
@@ -164,7 +171,8 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch
         aArgs[0].Value <<= ::rtl::OUString::createFromAscii("private:OpenEvent");
 
         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-             aDispatchRequest.aRequestType == REQUEST_PRINTTO )
+             aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
+	     aDispatchRequest.aRequestType == REQUEST_CONVERSION)
         {
             aArgs[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
             aArgs[2].Name = ::rtl::OUString::createFromAscii("OpenNewView");
@@ -199,7 +207,8 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch
         ::rtl::OUString aTarget( RTL_CONSTASCII_USTRINGPARAM("_default") );
 
         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-             aDispatchRequest.aRequestType == REQUEST_PRINTTO )
+             aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
+	     aDispatchRequest.aRequestType == REQUEST_CONVERSION)
         {
             // documents opened for printing are opened readonly because they must be opened as a new document and this
             // document could be open already
@@ -364,10 +373,38 @@ sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatch
                 OfficeIPCThread::RequestsCompleted( 1 );
             }
             else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-                      aDispatchRequest.aRequestType == REQUEST_PRINTTO )
+                      aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
+		      aDispatchRequest.aRequestType == REQUEST_CONVERSION )
             {
                 if ( xDoc.is() )
                 {
+		  if (aDispatchRequest.aRequestType == REQUEST_CONVERSION) {
+		    Reference< XStorable > xStorable( xDoc, UNO_QUERY );
+		    if (xStorable.is()) {		  
+		      rtl::OString aSource8 = ::rtl::OUStringToOString (aObj.GetFull(), RTL_TEXTENCODING_UTF8);
+		      INetURLObject aParam( aDispatchRequest.aPrinterName, INetURLObject::FSYS_DETECT);
+		      rtl::OUString aParamName=aParam.GetName(INetURLObject::DECODE_WITH_CHARSET);
+
+		      rtl::OUString aParamExt=aParam.GetExtension(INetURLObject::DECODE_WITH_CHARSET);
+		      rtl::OUString aFilterName(aParamName, aParamName.getLength()-aParamExt.getLength()-1);
+		      rtl::OString aFilterName8 = ::rtl::OUStringToOString (aFilterName, RTL_TEXTENCODING_UTF8);		      
+		      
+		      Sequence<PropertyValue> conversionProperties(2);
+		      conversionProperties[0].Name = ::rtl::OUString::createFromAscii("Overwrite");
+		      conversionProperties[0].Value <<= sal_True;
+		      
+		      conversionProperties[1].Name = ::rtl::OUString::createFromAscii("FilterName");
+		    conversionProperties[1].Value <<= aFilterName;
+		    
+		    INetURLObject aTargetURL(aParam);
+		    aTargetURL.SetName(aObj.GetName());
+		    aTargetURL.SetExtension(aParam.GetExtension());
+		    rtl::OString aTargetURL8 = ::rtl::OUStringToOString (aTargetURL.GetFull(), RTL_TEXTENCODING_UTF8);
+		    
+		    printf("convert %s->%s using %s\n", aSource8.getStr(), aTargetURL8.getStr(), aFilterName8.getStr());
+		    xStorable->storeToURL( aTargetURL.GetMainURL(INetURLObject::NO_DECODE), conversionProperties);
+		    }
+		  } else {
                     if ( aDispatchRequest.aRequestType == REQUEST_PRINTTO )
                     {
                         // create the printer
@@ -473,7 +510,7 @@ throw(::com::sun::star::uno::RuntimeException)
 void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException )
 {
     osl::ClearableMutexGuard aGuard( GetMutex() );
-    sal_Int16 nCount = --m_nRequestCount;
+    sal_Int16 nCount = m_nRequestCount;
     aGuard.clear();
     OfficeIPCThread::RequestsCompleted( 1 );
 /*
diff --git desktop/source/app/dispatchwatcher.hxx desktop/source/app/dispatchwatcher.hxx
index ef62dc2..3d3a619 100644
--- desktop/source/app/dispatchwatcher.hxx
+++ desktop/source/app/dispatchwatcher.hxx
@@ -78,7 +78,8 @@ class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame:
             REQUEST_PRINT,
             REQUEST_PRINTTO,
             REQUEST_FORCEOPEN,
-            REQUEST_FORCENEW
+            REQUEST_FORCENEW,
+	    REQUEST_CONVERSION
         };
 
         struct DispatchRequest
@@ -89,7 +90,7 @@ class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame:
             RequestType		aRequestType;
             rtl::OUString	aURL;
             boost::optional< rtl::OUString > aCwdUrl;
-            rtl::OUString	aPrinterName;
+            rtl::OUString	aPrinterName;  // also conversion params
             rtl::OUString   aPreselectedFactory;
         };
 
diff --git desktop/source/app/officeipcthread.cxx desktop/source/app/officeipcthread.cxx
index 9e158b7..73085f5 100644
--- desktop/source/app/officeipcthread.cxx
+++ desktop/source/app/officeipcthread.cxx
@@ -948,6 +948,29 @@ static void AddToDispatchList(
     }
 }
 
+static void AddConversionsToDispatchList(
+    DispatchWatcher::DispatchList& rDispatchList,
+    boost::optional< rtl::OUString > const & cwdUrl,
+    const OUString& aRequestList,
+    DispatchWatcher::RequestType nType,
+    const OUString& aParam,
+    const OUString& aFactory )
+{
+    if ( aRequestList.getLength() > 0 )
+    {
+        sal_Int32 nIndex = 0;
+        do
+        {
+            OUString aToken = aRequestList.getToken( 0, APPEVENT_PARAM_DELIMITER, nIndex );
+            if ( aToken.getLength() > 0 )
+                rDispatchList.push_back(
+                    DispatchWatcher::DispatchRequest( nType, aToken, cwdUrl, aParam, aFactory ));
+        }
+        while ( nIndex >= 0 );
+    }
+}
+
+
 sal_Bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest )
 {
     // protect the dispatch list
@@ -964,7 +987,7 @@ sal_Bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequ
     AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aPrintToList, DispatchWatcher::REQUEST_PRINTTO, aRequest.aPrinterName, aRequest.aModule );
     AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceOpenList, DispatchWatcher::REQUEST_FORCEOPEN, aEmpty, aRequest.aModule );
     AddToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aForceNewList, DispatchWatcher::REQUEST_FORCENEW, aEmpty, aRequest.aModule );
-
+    AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, DispatchWatcher::REQUEST_CONVERSION, aRequest.aConversionParams, aRequest.aModule );
     sal_Bool bShutdown( sal_False );
 
     if ( pGlobalOfficeIPCThread )
diff --git desktop/source/app/officeipcthread.hxx desktop/source/app/officeipcthread.hxx
index a2949b9..75d5485 100644
--- desktop/source/app/officeipcthread.hxx
+++ desktop/source/app/officeipcthread.hxx
@@ -69,6 +69,8 @@ struct ProcessDocumentsRequest
     ::rtl::OUString aForceNewList;	// Documents that should be forced to create a new document
     ::rtl::OUString aPrinterName;	// The printer name that should be used for printing
     ::rtl::OUString aPrintToList;	// Documents that should be printed on the given printer
+    ::rtl::OUString aConversionList;
+    ::rtl::OUString aConversionParams;
     ::osl::Condition *pcProcessed;  // pointer condition to be set when the request has been processed
 };