[Libreoffice-commits] core.git: desktop/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Dec 26 04:06:48 UTC 2018


 desktop/source/app/dispatchwatcher.cxx |  130 +++++++++++----------------------
 1 file changed, 46 insertions(+), 84 deletions(-)

New commits:
commit 2a6215507ed9f1da19aa8e4c69fb4e01d20e7c0f
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Dec 25 23:14:52 2018 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Dec 26 05:06:28 2018 +0100

    Use vector<PropertyValue> and containerToSequence to simplify things
    
    This makes creating a sequence of initially unknown size more readable
    and straightforward.
    
    Change-Id: I2c42aea7cc69efd0b53b7a35b72c4ae1a6ed4e87
    Reviewed-on: https://gerrit.libreoffice.org/65612
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx
index 78ed9db13e44..21fa4ff6b956 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -54,6 +54,7 @@
 #include <com/sun/star/script/XLibraryContainer2.hpp>
 #include <com/sun/star/document/XEmbeddedScripts.hpp>
 
+#include <comphelper/sequence.hxx>
 #include <tools/urlobj.hxx>
 #include <unotools/mediadescriptor.hxx>
 
@@ -312,11 +313,6 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
 
     for (auto const & aDispatchRequest: aDispatchRequestsList)
     {
-        // create parameter array
-        sal_Int32 nCount = 4;
-        if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
-            nCount++;
-
         // Set Input Filter
         if ( aDispatchRequest.aRequestType == REQUEST_INFILTER )
         {
@@ -326,20 +322,14 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
             continue;
         }
 
-        // we need more properties for a print/print to request
-        if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-             aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
-             aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
-             aDispatchRequest.aRequestType == REQUEST_CONVERSION ||
-             aDispatchRequest.aRequestType == REQUEST_CAT ||
-             aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT)
-            nCount++;
-
-        Sequence < PropertyValue > aArgs( nCount );
+        // create parameter array
+        std::vector<PropertyValue> aArgs;
 
         // mark request as user interaction from outside
-        aArgs[0].Name = "Referer";
-        aArgs[0].Value <<= OUString("private:OpenEvent");
+        aArgs.emplace_back("Referer", 0, Any(OUString("private:OpenEvent")),
+                           PropertyState_DIRECT_VALUE);
+
+        OUString aTarget("_default");
 
         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
              aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
@@ -348,58 +338,45 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
              aDispatchRequest.aRequestType == REQUEST_CAT ||
              aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT)
         {
-            aArgs[1].Name = "ReadOnly";
-            aArgs[2].Name = "OpenNewView";
-            aArgs[3].Name = "Hidden";
-            aArgs[4].Name = "Silent";
+            // documents opened for printing are opened readonly because they must be opened as a
+            // new document and this document could be open already
+            aArgs.emplace_back("ReadOnly", 0, Any(true), PropertyState_DIRECT_VALUE);
+            // always open a new document for printing, because it must be disposed afterwards
+            aArgs.emplace_back("OpenNewView", 0, Any(true), PropertyState_DIRECT_VALUE);
+            // printing is done in a hidden view
+            aArgs.emplace_back("Hidden", 0, Any(true), PropertyState_DIRECT_VALUE);
+            // load document for printing without user interaction
+            aArgs.emplace_back("Silent", 0, Any(true), PropertyState_DIRECT_VALUE);
+
+            // hidden documents should never be put into open tasks
+            aTarget = "_blank";
         }
         else
         {
             Reference < XInteractionHandler2 > xInteraction(
                 InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), nullptr) );
 
-            aArgs[1].Name = "InteractionHandler";
-            aArgs[1].Value <<= xInteraction;
+            aArgs.emplace_back("InteractionHandler", 0, Any(xInteraction),
+                               PropertyState_DIRECT_VALUE);
 
-            aArgs[2].Name = "MacroExecutionMode";
-            aArgs[2].Value <<= css::document::MacroExecMode::USE_CONFIG;
+            aArgs.emplace_back("MacroExecutionMode", 0,
+                               Any(css::document::MacroExecMode::USE_CONFIG),
+                               PropertyState_DIRECT_VALUE);
 
-            aArgs[3].Name = "UpdateDocMode";
-            aArgs[3].Value <<= css::document::UpdateDocMode::ACCORDING_TO_CONFIG;
+            aArgs.emplace_back("UpdateDocMode", 0,
+                               Any(css::document::UpdateDocMode::ACCORDING_TO_CONFIG),
+                               PropertyState_DIRECT_VALUE);
         }
 
         if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
         {
-            aArgs[nCount-1].Name = utl::MediaDescriptor::PROP_DOCUMENTSERVICE();
-            aArgs[nCount-1].Value <<= aDispatchRequest.aPreselectedFactory;
+            aArgs.emplace_back(utl::MediaDescriptor::PROP_DOCUMENTSERVICE(), 0,
+                               Any(aDispatchRequest.aPreselectedFactory),
+                               PropertyState_DIRECT_VALUE);
         }
 
         OUString aName( GetURL_Impl( aDispatchRequest.aURL, aDispatchRequest.aCwdUrl ) );
-        OUString aTarget("_default");
 
-        if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
-             aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
-             aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
-             aDispatchRequest.aRequestType == REQUEST_CONVERSION ||
-             aDispatchRequest.aRequestType == REQUEST_CAT ||
-             aDispatchRequest.aRequestType == REQUEST_SCRIPT_CAT )
-        {
-            // documents opened for printing are opened readonly because they must be opened as a new document and this
-            // document could be open already
-            aArgs[1].Value <<= true;
-
-            // always open a new document for printing, because it must be disposed afterwards
-            aArgs[2].Value <<= true;
-
-            // printing is done in a hidden view
-            aArgs[3].Value <<= true;
-
-            // load document for printing without user interaction
-            aArgs[4].Value <<= true;
-
-            // hidden documents should never be put into open tasks
-            aTarget = "_blank";
-        }
         // load the document ... if they are loadable!
         // Otherwise try to dispatch it ...
         Reference < XPrintable > xDoc;
@@ -487,58 +464,43 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest
             if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW ||
                  aDispatchRequest.aRequestType == REQUEST_FORCEOPEN     )
             {
-                sal_Int32 nIndex = aArgs.getLength();
-                aArgs.realloc( nIndex+1 );
-                aArgs[nIndex].Name = "AsTemplate";
-                if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW )
-                    aArgs[nIndex].Value <<= true;
-                else
-                    aArgs[nIndex].Value <<= false;
+                aArgs.emplace_back("AsTemplate", 0,
+                                   Any(aDispatchRequest.aRequestType == REQUEST_FORCENEW),
+                                   PropertyState_DIRECT_VALUE);
             }
 
             // if we are called in viewmode, open document read-only
             if(aDispatchRequest.aRequestType == REQUEST_VIEW) {
-                sal_Int32 nIndex = aArgs.getLength();
-                aArgs.realloc(nIndex+1);
-                aArgs[nIndex].Name = "ReadOnly";
-                aArgs[nIndex].Value <<= true;
+                aArgs.emplace_back("ReadOnly", 0, Any(true), PropertyState_DIRECT_VALUE);
             }
 
             // if we are called with -start set Start in mediadescriptor
             if(aDispatchRequest.aRequestType == REQUEST_START) {
-                sal_Int32 nIndex = aArgs.getLength();
-                aArgs.realloc(nIndex+1);
-                aArgs[nIndex].Name = "StartPresentation";
-                aArgs[nIndex].Value <<= true;
+                aArgs.emplace_back("StartPresentation", 0, Any(true), PropertyState_DIRECT_VALUE);
             }
 
             // Force input filter, if possible
             if( bSetInputFilter )
             {
-                sal_Int32 nIndex = aArgs.getLength();
-                aArgs.realloc(nIndex+1);
-                aArgs[nIndex].Name = "FilterName";
-
-                sal_Int32 nFilterOptionsIndex = aForcedInputFilter.indexOf( ':' );
-                if( 0 < nFilterOptionsIndex )
-                {
-                    aArgs[nIndex].Value <<= aForcedInputFilter.copy( 0, nFilterOptionsIndex );
+                sal_Int32 nFilterOptionsIndex = 0;
+                aArgs.emplace_back("FilterName", 0,
+                                   Any(aForcedInputFilter.getToken(0, ':', nFilterOptionsIndex)),
+                                   PropertyState_DIRECT_VALUE);
 
-                    nIndex = aArgs.getLength();
-                    aArgs.realloc(nIndex+1);
-                    aArgs[nIndex].Name = "FilterOptions";
-                    aArgs[nIndex].Value <<= aForcedInputFilter.copy( nFilterOptionsIndex+1 );
-                }
-                else
+                if (0 < nFilterOptionsIndex)
                 {
-                    aArgs[nIndex].Value <<= aForcedInputFilter;
+                    aArgs.emplace_back("FilterOptions", 0,
+                                       Any(aForcedInputFilter.copy(nFilterOptionsIndex)),
+                                       PropertyState_DIRECT_VALUE);
                 }
             }
 
             // This is a synchron loading of a component so we don't have to deal with our statusChanged listener mechanism.
             try
             {
-                xDoc.set( ::comphelper::SynchronousDispatch::dispatch( xDesktop, aName, aTarget, aArgs ), UNO_QUERY );
+                xDoc.set(comphelper::SynchronousDispatch::dispatch(
+                             xDesktop, aName, aTarget, comphelper::containerToSequence(aArgs)),
+                         UNO_QUERY);
             }
             catch (const css::lang::IllegalArgumentException& iae)
             {


More information about the Libreoffice-commits mailing list