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

deenafrancis deena.francis at gmail.com
Thu Aug 14 23:37:39 PDT 2014


 desktop/source/app/app.cxx             |    1 
 desktop/source/app/cmdlineargs.cxx     |    8 ++++
 desktop/source/app/cmdlineargs.hxx     |    2 +
 desktop/source/app/cmdlinehelp.cxx     |    5 ++
 desktop/source/app/dispatchwatcher.cxx |   57 +++++++++++++++++++++++++++++----
 desktop/source/app/dispatchwatcher.hxx |    3 +
 desktop/source/app/officeipcthread.cxx |    7 ++--
 desktop/source/app/officeipcthread.hxx |    3 +
 8 files changed, 74 insertions(+), 12 deletions(-)

New commits:
commit 3d318e6cf4a183e14a043840b9990958c7527536
Author: deenafrancis <deena.francis at gmail.com>
Date:   Wed Jul 30 01:16:34 2014 +0530

    fdo#70625 Add --cat parameter to make git diffs pretty
    
    Change-Id: I309ca3e718a11ca97991686c229c79ab20e8c3d9
    Reviewed-on: https://gerrit.libreoffice.org/10623
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 46fbebe..8eed982 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -2399,6 +2399,7 @@ void Desktop::OpenClients()
     aRequest.aConversionParams = rArgs.GetConversionParams();
     aRequest.aConversionOut = rArgs.GetConversionOut();
     aRequest.aInFilter = rArgs.GetInFilter();
+    aRequest.bTextCat = rArgs.IsTextCat();
 
     if ( !aRequest.aOpenList.empty() ||
          !aRequest.aViewList.empty() ||
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx
index 5f98e07..2cecabc 100644
--- a/desktop/source/app/cmdlineargs.cxx
+++ b/desktop/source/app/cmdlineargs.cxx
@@ -190,6 +190,13 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
                 m_headless = true;
                 m_invisible = true;
             }
+            else if ( oArg == "cat" )
+            {
+                m_textcat = true;
+                m_conversionparams = "txt:Text";
+                bOpenEvent = false;
+                bConversionEvent = true;
+            }
             else if ( oArg == "quickstart" )
             {
 #if defined(ENABLE_QUICKSTART_APPLET)
@@ -608,6 +615,7 @@ void CommandLineArgs::InitParamValues()
     m_splashpipe = false;
     m_bEmpty = true;
     m_bDocumentArgs  = false;
+    m_textcat = false;
 }
 
 
diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx
index 609befb..74c8c0e 100644
--- a/desktop/source/app/cmdlineargs.hxx
+++ b/desktop/source/app/cmdlineargs.hxx
@@ -85,6 +85,7 @@ class CommandLineArgs: private boost::noncopyable
         bool                IsVersion() const { return m_version;}
         bool                HasModuleParam() const;
         bool                WantsToLoadDocument() const { return m_bDocumentArgs;}
+        bool                IsTextCat() const { return m_textcat;}
 
         OUString            GetUnknown() const { return m_unknown;}
 
@@ -145,6 +146,7 @@ class CommandLineArgs: private boost::noncopyable
         bool m_helpbase;
         bool m_version;
         bool m_splashpipe;
+        bool m_textcat;
 
         OUString m_unknown;
 
diff --git a/desktop/source/app/cmdlinehelp.cxx b/desktop/source/app/cmdlinehelp.cxx
index f042b46..dbec4e9 100644
--- a/desktop/source/app/cmdlinehelp.cxx
+++ b/desktop/source/app/cmdlinehelp.cxx
@@ -124,7 +124,10 @@ namespace desktop
         "      Batch print files to file.\n"\
         "      If --outdir is not specified then current working dir is used as output_dir.\n"\
         "      Eg. --print-to-file *.doc\n"\
-        "          --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc\n"\
+        "          --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc\n" \
+        "--cat files\n"\
+        "      Dump text content of the files to console\n"\
+        "      Eg. --cat *.odt\n"\
         "--pidfile file\n"\
         "      Store soffice.bin pid to file.\n"\
         "-env:<VAR>[=<VALUE>]\n"\
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx
index c792655..01d082e 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -55,7 +55,10 @@
 
 #include <vector>
 #include <osl/thread.hxx>
+#include <osl/file.hxx>
+#include <osl/file.h>
 #include <rtl/instance.hxx>
+#include <iostream>
 
 using namespace ::osl;
 using namespace ::com::sun::star::uno;
@@ -496,11 +499,12 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
             else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
                       aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
                       aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
-                      aDispatchRequest.aRequestType == REQUEST_CONVERSION )
+                      aDispatchRequest.aRequestType == REQUEST_CONVERSION ||
+                      aDispatchRequest.aRequestType == REQUEST_CAT )
             {
                 if ( xDoc.is() )
                 {
-                    if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION ) {
+                    if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION || aDispatchRequest.aRequestType == REQUEST_CAT ) {
                         Reference< XStorable > xStorable( xDoc, UNO_QUERY );
                         if ( xStorable.is() ) {
                             OUString aParam = aDispatchRequest.aPrinterName;
@@ -531,6 +535,14 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
                                                      "/" +
                                                      aOutFilename.getName();
 
+                            OUString fileForCat;
+                            if( aDispatchRequest.aRequestType == REQUEST_CAT )
+                            {
+                                if( ::osl::FileBase::createTempFile(0, 0, &fileForCat) != ::osl::FileBase::E_None )
+                                    fprintf( stderr, "Error: Cannot create temporary file...\n" );
+                                aOutFile = fileForCat;
+                            }
+
                             if ( bGuess )
                             {
                                 aFilter = impl_GuessFilter( aName, aOutFile );
@@ -559,10 +571,13 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
                             OString aSource8 = OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
                             FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
                             OString aTargetURL8 = OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
-                            printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
-                                   OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
-                            if( FStatHelper::IsDocument(aOutFile) )
-                                printf("Overwriting: %s\n",OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
+                            if( aDispatchRequest.aRequestType != REQUEST_CAT )
+                            {
+                                printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
+                                       OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
+                                if( FStatHelper::IsDocument( aOutFile ) )
+                                    printf("Overwriting: %s\n",OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
+                            }
                             try
                             {
                                 xStorable->storeToURL( aOutFile, conversionProperties );
@@ -571,6 +586,36 @@ bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequ
                             {
                                 fprintf( stderr, "Error: Please reverify input parameters...\n" );
                             }
+
+                            if( aDispatchRequest.aRequestType == REQUEST_CAT )
+                            {
+                                osl::File aFile( fileForCat );
+                                osl::File::RC aRC = aFile.open( osl_File_OpenFlag_Read );
+                                if( aRC != osl::File::E_None )
+                                {
+                                    fprintf( stderr, "Error: Cannot read from temp file\n" );
+                                }
+                                else
+                                {
+                                    sal_Bool eof;
+                                    for( ;; )
+                                    {
+                                        aFile.isEndOfFile( &eof );
+                                        if( eof )
+                                            break;
+                                        rtl::ByteSequence bseq;
+                                        aFile.readLine( bseq );
+                                        unsigned const char * aStr = reinterpret_cast< unsigned char const * >( bseq.getConstArray() );
+                                        for( sal_Int32 i = 0; i < bseq.getLength(); i++ )
+                                        {
+                                            std::cout << aStr[i];
+                                        }
+                                        std::cout << "\n";
+                                    }
+                                    aFile.close();
+                                    osl::File::remove( fileForCat );
+                                }
+                            }
                         }
                     } else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) {
                         OUString aParam = aDispatchRequest.aPrinterName;
diff --git a/desktop/source/app/dispatchwatcher.hxx b/desktop/source/app/dispatchwatcher.hxx
index 1fa1c9d..125e9d9 100644
--- a/desktop/source/app/dispatchwatcher.hxx
+++ b/desktop/source/app/dispatchwatcher.hxx
@@ -62,7 +62,8 @@ class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame:
             REQUEST_FORCENEW,
             REQUEST_CONVERSION,
             REQUEST_INFILTER,
-            REQUEST_BATCHPRINT
+            REQUEST_BATCHPRINT,
+            REQUEST_CAT
         };
 
         struct DispatchRequest
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index aed17b9..d636adf 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -975,14 +975,15 @@ static void AddConversionsToDispatchList(
     const OUString& rParam,
     const OUString& rPrinterName,
     const OUString& rFactory,
-    const OUString& rParamOut )
+    const OUString& rParamOut,
+    const bool isTextCat )
 {
     DispatchWatcher::RequestType nType;
     OUString aParam( rParam );
 
     if( !rParam.isEmpty() )
     {
-        nType = DispatchWatcher::REQUEST_CONVERSION;
+        nType = ( isTextCat ) ? DispatchWatcher::REQUEST_CAT : DispatchWatcher::REQUEST_CONVERSION;
         aParam = rParam;
     }
     else
@@ -1035,7 +1036,7 @@ bool OfficeIPCThread::ExecuteCmdLineRequests( ProcessDocumentsRequest& aRequest
     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, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut );
+    AddConversionsToDispatchList( aDispatchList, aRequest.aCwdUrl, aRequest.aConversionList, aRequest.aConversionParams, aRequest.aPrinterName, aRequest.aModule, aRequest.aConversionOut, aRequest.bTextCat );
     bool bShutdown( false );
 
     if ( pGlobalOfficeIPCThread.is() )
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 4628eca..921da49 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -46,7 +46,7 @@ oslSignalAction SAL_CALL SalMainPipeExchangeSignal_impl(void* /*pData*/, oslSign
 struct ProcessDocumentsRequest
 {
     ProcessDocumentsRequest(boost::optional< OUString > const & cwdUrl):
-        aCwdUrl(cwdUrl), pcProcessed( NULL ) {}
+        aCwdUrl(cwdUrl), pcProcessed( NULL ), bTextCat( false ) {}
 
     boost::optional< OUString > aCwdUrl;
     OUString aModule;
@@ -63,6 +63,7 @@ struct ProcessDocumentsRequest
     OUString aConversionOut;
     std::vector< OUString > aInFilter;
     ::osl::Condition *pcProcessed;  // pointer condition to be set when the request has been processed
+    bool bTextCat; // boolean flag indicating whether to dump text content to screen
 };
 
 class DispatchWatcher;


More information about the Libreoffice-commits mailing list