[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - desktop/source sc/source

2021-07-25 Thread Eike Rathke (via logerrit)
 desktop/source/app/dispatchwatcher.cxx |   19 +++--
 sc/source/ui/docshell/docsh.cxx|   48 +++--
 2 files changed, 45 insertions(+), 22 deletions(-)

New commits:
commit 55f0121dd7ed2d7e84adc597bdd24ca40e0b0ce4
Author: Eike Rathke 
AuthorDate: Tue Jul 20 23:09:59 2021 +0200
Commit: Caolán McNamara 
CommitDate: Sun Jul 25 15:54:14 2021 +0200

Related: tdf#135762 Suppress cout if not command line

Change-Id: I9431221aadf97739bb197871f25fa151ef4c391c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119294
Reviewed-by: Eike Rathke 
Tested-by: Jenkins
(cherry picked from commit 0cda081c9aa3b3dcb363f97bac60c845ce9a13e0)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119255
Reviewed-by: Caolán McNamara 

diff --git a/desktop/source/app/dispatchwatcher.cxx 
b/desktop/source/app/dispatchwatcher.cxx
index 1c4d878614c5..0e39415d8fab 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -608,15 +608,17 @@ bool DispatchWatcher::executeDispatchRequests( const 
std::vector conversionProperties( 
nProps );
-conversionProperties[0].Name = "Overwrite";
-conversionProperties[0].Value <<= true;
+conversionProperties[0].Name = 
"ConversionRequestOrigin";
+conversionProperties[0].Value <<= 
OUString("CommandLine");
+conversionProperties[1].Name = "Overwrite";
+conversionProperties[1].Value <<= true;
 
-conversionProperties[1].Name = "FilterName";
+conversionProperties[2].Name = "FilterName";
 if( 0 < nFilterOptionsIndex )
 {
 OUString sFilterName = aFilter.copy(0, 
nFilterOptionsIndex);
@@ -641,18 +643,19 @@ bool DispatchWatcher::executeDispatchRequests( const 
std::vector & rArgs = 
rMed.GetArgs();
+const auto pProp = std::find_if( rArgs.begin(), rArgs.end(),
+[](const css::beans::PropertyValue& rProp) { return 
rProp.Name == "ConversionRequestOrigin"; });
+if (pProp != rArgs.end())
+{
+OUString aOrigin;
+pProp->Value >>= aOrigin;
+bVerbose = (aOrigin == "CommandLine");
+}
+
 SCTAB nStartTab;
 SCTAB nCount = m_aDocument.GetTableCount();
 if (aOptions.nSheetToExport == -1)
@@ -2433,11 +2446,14 @@ bool ScDocShell::ConvertTo( SfxMedium  )
 else
 {
 // Usage error, no export but log.
-if (aOptions.nSheetToExport < 0)
-std::cout << "Bad sheet number string given." << std::endl;
-else
-std::cout << "No sheet number " << 
OString::number(aOptions.nSheetToExport)
-<< ", number of sheets is 
" << nCount << std::endl;
+if (bVerbose)
+{
+if (aOptions.nSheetToExport < 0)
+std::cout << "Bad sheet number string given." << 
std::endl;
+else
+std::cout << "No sheet number " << 
aOptions.nSheetToExport
+<< ", number of sheets is " << nCount << std::endl;
+}
 nStartTab = 0;
 nCount = 0;
 SetError(SCERR_EXPORT_DATA);
@@ -2462,15 +2478,19 @@ bool ScDocShell::ConvertTo( SfxMedium  )
 
 // log similar to DispatchWatcher::executeDispatchRequests
 OUString aOutFile = 
aSheetURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-OUString aDisplayedName;
-if (osl::FileBase::E_None != 
osl::FileBase::getSystemPathFromFileURL(aOutFile, aDisplayedName))
-aDisplayedName = aOutFile;
-std::cout << "Writing sheet " << OUStringToOString(sTabName, 
osl_getThreadTextEncoding()) << " -> "
-  << 
OUStringToOString(aDisplayedName, osl_getThreadTextEncoding())
-  << std::endl;
-
-if (FStatHelper::IsDocument(aOutFile))
-std::cout << "Overwriting: " << 
OUStringToOString(aDisplayedName, osl_getThreadTextEncoding()) << std::endl ;
+if (bVerbose)
+{
+OUString aDisplayedName;
+if (osl::FileBase::E_None != 
osl::FileBase::getSystemPathFromFileURL(aOutFile, aDisplayedName))
+aDisplayedName = aOutFile;
+std::cout << "Writing sheet " << 
OUStringToOString(sTabName, osl_getThreadTextEncoding()) << " -> "
+  

[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - desktop/source sc/source

2021-07-15 Thread Eike Rathke (via logerrit)
 desktop/source/app/dispatchwatcher.cxx |   13 ++--
 sc/source/ui/dbgui/imoptdlg.cxx|   15 +++---
 sc/source/ui/docshell/docsh.cxx|   34 ++---
 sc/source/ui/inc/imoptdlg.hxx  |8 +++
 4 files changed, 58 insertions(+), 12 deletions(-)

New commits:
commit d756a599298abb23657469cfd94c4a201824c419
Author: Eike Rathke 
AuthorDate: Thu Jul 15 10:37:57 2021 +0200
Commit: Caolán McNamara 
CommitDate: Thu Jul 15 14:54:48 2021 +0200

Related: tdf#135762 Allow --convert-to csv to specify 1-based sheet number

Same multifile mechanism as for -1 all sheets is used, so

soffice --convert-to csv:"Text - txt - csv 
(StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,2 sample.ods

writes a file sample-Sheet2.csv

Change-Id: Ib9248c9561e4e340c88458ac5dfd159e443a4cfd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118971
Reviewed-by: Eike Rathke 
Tested-by: Jenkins
(cherry picked from commit fda91f8be16ba760e360940ebafd6244c648cb8c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118920
Reviewed-by: Caolán McNamara 

diff --git a/desktop/source/app/dispatchwatcher.cxx 
b/desktop/source/app/dispatchwatcher.cxx
index 8541c273cc83..1c4d878614c5 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -625,11 +625,20 @@ bool DispatchWatcher::executeDispatchRequests( const 
std::vector0 then that sheet 
(1-based) with the output
+// filename concatenated with the 
sheet name. So even if
+// that is a single file, the multi 
file target mechanism is
+// used.
+const OUString 
aTok(sFilterOptions.getToken(11, ',', nIdx));
+// Actual validity is checked in Calc, 
here just check for
+// presence of numeric value at start.
+bMultiFileTarget = (!aTok.isEmpty() && 
aTok.toInt32() != 0);
 }
 
 conversionProperties[1].Value <<= 
sFilterName;
diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx
index d8c4fd810ea3..a362e4df0ee7 100644
--- a/sc/source/ui/dbgui/imoptdlg.cxx
+++ b/sc/source/ui/dbgui/imoptdlg.cxx
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -43,7 +44,7 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
 bSaveNumberAsSuch = true;
 bSaveFormulas = false;
 bRemoveSpace = false;
-bNewFilePerSheet = false;
+nSheetToExport = 0;
 sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
 if ( nTokenCount < 3 )
 return;
@@ -79,7 +80,15 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
 if ( nTokenCount >= 11 )
 bRemoveSpace = rStr.getToken(0, ',', nIdx) == "true";
 if ( nTokenCount >= 12 )
-bNewFilePerSheet = rStr.getToken(0, ',', nIdx) == "-1";
+{
+const OUString aTok(rStr.getToken(0, ',', nIdx));
+if (aTok == "-1")
+nSheetToExport = -1;// all
+else if (aTok.isEmpty() || CharClass::isAsciiNumeric(aTok))
+nSheetToExport = aTok.toInt32();
+else
+nSheetToExport = -23;   // invalid, force error
+}
 }
 }
 
@@ -104,7 +113,7 @@ OUString ScImportOptions::BuildString() const
 "," +
 OUString::boolean( bRemoveSpace ) +  // same as "Remove space" in 
ScAsciiOptions
 "," +
-std::u16string_view(bNewFilePerSheet ? u"-1" : u"0") ;  // Only 
available for command line --convert-to
+OUString::number(nSheetToExport) ;  // Only available for command 
line --convert-to
 
 return aResult;
 }
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 873e5c598bab..21137a7bb1b6 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -2412,16 +2412,44 @@ bool ScDocShell::ConvertTo( SfxMedium  )
 weld::WaitObject aWait( GetActiveDialogParent() );
 ScImportOptions aOptions( sItStr );
 
-if (aOptions.bNewFilePerSheet)
+if (aOptions.nSheetToExport)
 {
+// Only from command line --convert-to
 bRet = true;
 
+SCTAB nStartTab;
+SCTAB nCount = m_aDocument.GetTableCount();
+if (aOptions.nSheetToExport == -1)
+{
+// All sheets.
+nStartTab = 0;
+}
+else if (0 < aOptions.nSheetToExport && aOptions.nSheetToExport <= 
nCount)
+{
+// One sheet, 1-based.
+nCount = aOptions.nSheetToExport;
+

[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - desktop/source sc/source

2021-07-15 Thread Caolán McNamara (via logerrit)
 desktop/source/app/dispatchwatcher.cxx |   26 +++-
 sc/source/ui/dbgui/imoptdlg.cxx|7 ++
 sc/source/ui/docshell/docsh.cxx|   97 -
 sc/source/ui/inc/docsh.hxx |2 
 sc/source/ui/inc/imoptdlg.hxx  |6 +-
 5 files changed, 106 insertions(+), 32 deletions(-)

New commits:
commit b41d21453fd3f109c77b03e296f62bc4d8b9ca9b
Author: Caolán McNamara 
AuthorDate: Tue Jul 13 12:38:07 2021 +0100
Commit: Eike Rathke 
CommitDate: Thu Jul 15 10:38:27 2021 +0200

rhbz#1980800 allow --convert-to csv to write each sheet to a separate file

Related: tdf#135762 except only currently implemented for command line use

sample usage:
soffice --convert-to csv:"Text - txt - csv 
(StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,-1 sample.ods
where the new (11th!) final token ("-1") enables writing each sheet to a
new file based on the suggested target name so output in this example
is files sample-Sheet1.csv and sample-Sheet2.csv

Only -1 for 'all sheets' vs 0 for existing 'current sheet only' (which
is always sheet 0 from the command line) are currently options but the
token could be expanded in the future to select specific sheets to
export.

Change-Id: Ib99a120f1a2c8d1008a7a3c59a6b39f572fb346e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118850
Tested-by: Jenkins
Reviewed-by: Eike Rathke 
(cherry picked from commit b8903bc106dad036acb3d117e5c4fc955697fe02)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118915

diff --git a/desktop/source/app/dispatchwatcher.cxx 
b/desktop/source/app/dispatchwatcher.cxx
index a2e79d8283ae..8541c273cc83 100644
--- a/desktop/source/app/dispatchwatcher.cxx
+++ b/desktop/source/app/dispatchwatcher.cxx
@@ -30,6 +30,7 @@
 #include "officeipcthread.hxx"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -598,6 +599,8 @@ bool DispatchWatcher::executeDispatchRequests( const 
std::vector " << aTargetURL8;
+std::cout << "convert " << aSource8;
+if (!bMultiFileTarget)
+std::cout << " -> " << aTargetURL8;
 std::cout << " using filter : " << 
OUStringToOString(aFilter, osl_getThreadTextEncoding()) << std::endl;
-if (FStatHelper::IsDocument(aOutFile))
+if (!bMultiFileTarget && 
FStatHelper::IsDocument(aOutFile))
 std::cout << "Overwriting: " << 
OUStringToOString(aTempName, osl_getThreadTextEncoding()) << std::endl ;
 }
 try
diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx
index 071f1b0257bc..d8c4fd810ea3 100644
--- a/sc/source/ui/dbgui/imoptdlg.cxx
+++ b/sc/source/ui/dbgui/imoptdlg.cxx
@@ -43,6 +43,7 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
 bSaveNumberAsSuch = true;
 bSaveFormulas = false;
 bRemoveSpace = false;
+bNewFilePerSheet = false;
 sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
 if ( nTokenCount < 3 )
 return;
@@ -77,6 +78,8 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
 bSaveFormulas = rStr.getToken(0, ',', nIdx) == "true";
 if ( nTokenCount >= 11 )
 bRemoveSpace = rStr.getToken(0, ',', nIdx) == "true";
+if ( nTokenCount >= 12 )
+bNewFilePerSheet = rStr.getToken(0, ',', nIdx) == "-1";
 }
 }
 
@@ -99,7 +102,9 @@ OUString ScImportOptions::BuildString() const
 "," +
 OUString::boolean( bSaveFormulas ) +  // "save formulas": not in 
ScAsciiOptions
 "," +
-OUString::boolean( bRemoveSpace );// same as "Remove space" in 
ScAsciiOptions
+OUString::boolean( bRemoveSpace ) +  // same as "Remove space" in 
ScAsciiOptions
+"," +
+std::u16string_view(bNewFilePerSheet ? u"-1" : u"0") ;  // Only 
available for command line --convert-to
 
 return aResult;
 }
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 055f2fdf727a..873e5c598bab 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -44,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -120,6 +121,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1926,7 +1928,7 @@ void escapeTextSep(sal_Int32 nPos, const StrT& rStrDelim, 
StrT& rStr)
 
 }
 
-void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& 
rAsciiOpt )
+void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& 
rAsciiOpt, SCTAB nTab )
 {
 sal_Unicode cDelim= rAsciiOpt.nFieldSepCode;
 sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
@@