From 78709c2107b0ed874e310b84da487fa01f8df476 Mon Sep 17 00:00:00 2001
From: christianju <christianjunker@gmail.com>
Date: Mon, 10 Feb 2014 02:30:48 +0100
Subject: [PATCH] fdo#61320: Allow user to choose whether to create thumbnails
 inside odf.

Change-Id: I8c8129534ebcca32941ad76b201bb9a0243d8c3e
---
 cui/source/options/optsave.cxx                     | 15 +++++-
 cui/source/options/optsave.hxx                     |  1 +
 cui/source/options/treeopt.cxx                     |  1 +
 cui/uiconfig/ui/optsavepage.ui                     | 21 +++++++-
 include/sfx2/sfxsids.hrc                           |  1 +
 include/unotools/saveopt.hxx                       |  4 ++
 .../schema/org/openoffice/Office/Common.xcs        |  9 ++++
 sfx2/source/appl/appcfg.cxx                        | 15 ++++++
 sfx2/source/doc/objstor.cxx                        |  7 +--
 unotools/source/config/saveopt.cxx                 | 56 +++++++++++++++++++---
 10 files changed, 118 insertions(+), 12 deletions(-)

diff --git a/cui/source/options/optsave.cxx b/cui/source/options/optsave.cxx
index ce66f09..19edda3 100644
--- a/cui/source/options/optsave.cxx
+++ b/cui/source/options/optsave.cxx
@@ -96,6 +96,7 @@ SfxSaveTabPage::SfxSaveTabPage( Window* pParent, const SfxItemSet& rCoreSet ) :
     get(aUserAutoSaveCB, "userautosave");
     get(aRelativeFsysCB, "relative_fsys");
     get(aRelativeInetCB, "relative_inet");
+    get(aThumbnailCB, "thumbnail");
 
     get(aODFVersionLB, "odfversion");
     get(aWarnAlienFormatCB, "warnalienformat");
@@ -235,7 +236,6 @@ void SfxSaveTabPage::DetectHiddenControls()
         // hide controls of "UserAutoSave"
         aUserAutoSaveCB->Hide();
     }
-
 }
 // -----------------------------------------------------------------------
 sal_Bool SfxSaveTabPage::FillItemSet( SfxItemSet& rSet )
@@ -311,6 +311,13 @@ sal_Bool SfxSaveTabPage::FillItemSet( SfxItemSet& rSet )
         bModified |= sal_True;
     }
 
+    sal_Bool curThumbGenVal = aThumbnailCB->IsChecked();
+    if ( curThumbGenVal !=  aThumbnailCB->GetSavedValue())
+    {
+        rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_THUMBNAIL ), curThumbGenVal ) );
+        bModified |= sal_True;
+    }
+
     SvtModuleOptions aModuleOpt;
     if(!pImpl->aDefaultArr[APP_MATH].isEmpty() &&
             pImpl->aDefaultArr[APP_MATH] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH))
@@ -478,6 +485,11 @@ void SfxSaveTabPage::Reset( const SfxItemSet& )
 
     aRelativeInetCB->Check( aSaveOpt.IsSaveRelINet() );
 
+    // thumbail generation
+    aThumbnailCB->Check(aSaveOpt.IsGenerateThumbnail());
+    sal_Bool bThumbRO = aSaveOpt.IsReadOnly(SvtSaveOptions::E_GENERATETHUMBNAIL);
+    aBackupCB->Enable(!bThumbRO);
+
     void* pDefaultVersion = (void*)sal_IntPtr( aSaveOpt.GetODFDefaultVersion() );
     aODFVersionLB->SelectEntryPos( aODFVersionLB->GetEntryPos( pDefaultVersion ) );
 
@@ -494,6 +506,7 @@ void SfxSaveTabPage::Reset( const SfxItemSet& )
 
     aRelativeFsysCB->SaveValue();
     aRelativeInetCB->SaveValue();
+    aThumbnailCB->SaveValue();
     aODFVersionLB->SaveValue();
 }
 
diff --git a/cui/source/options/optsave.hxx b/cui/source/options/optsave.hxx
index a3d2a12..3a441a9 100644
--- a/cui/source/options/optsave.hxx
+++ b/cui/source/options/optsave.hxx
@@ -53,6 +53,7 @@ private:
     CheckBox*               aUserAutoSaveCB;
     CheckBox*               aRelativeFsysCB;
     CheckBox*               aRelativeInetCB;
+    CheckBox*               aThumbnailCB;
 
     ListBox*                aODFVersionLB;
     CheckBox*               aWarnAlienFormatCB;
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index b3089e5..dd22899 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1329,6 +1329,7 @@ SfxItemSet* OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId )
             SID_SAVEREL_INET, SID_SAVEREL_FSYS,
             SID_ATTR_PRETTYPRINTING, SID_ATTR_PRETTYPRINTING,
             SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT,
+            SID_ATTR_THUMBNAIL, SID_ATTR_THUMBNAIL,
             0 );
             SFX_APP()->GetOptions(*pRet);
             break;
diff --git a/cui/uiconfig/ui/optsavepage.ui b/cui/uiconfig/ui/optsavepage.ui
index c312911..1cadd92 100644
--- a/cui/uiconfig/ui/optsavepage.ui
+++ b/cui/uiconfig/ui/optsavepage.ui
@@ -194,7 +194,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">4</property>
+                    <property name="top_attach">5</property>
                     <property name="width">1</property>
                     <property name="height">1</property>
                   </packing>
@@ -228,7 +228,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">5</property>
+                    <property name="top_attach">6</property>
                     <property name="width">1</property>
                     <property name="height">1</property>
                   </packing>
@@ -250,6 +250,23 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkCheckButton" id="thumbnail">
+                    <property name="label" translatable="yes">Include a thumbnail image</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="xalign">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">4</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index bc26695..f57b555 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -520,6 +520,7 @@
 #define SID_ATTR_AUTOSAVEPROMPT         (SID_OPTIONS_START +  3)
 #define SID_ATTR_USERAUTOSAVE           (SID_OPTIONS_START +  4)
 #define SID_ATTR_AUTOSAVEMINUTE         (SID_OPTIONS_START +  5)
+#define SID_ATTR_THUMBNAIL              (SID_OPTIONS_START +  6)
 #define SID_ATTR_WORKINGSET             (SID_OPTIONS_START + 13)
 #define SID_ATTR_UNDO_COUNT             (SID_OPTIONS_START + 16)
     // unused
diff --git a/include/unotools/saveopt.hxx b/include/unotools/saveopt.hxx
index 5e7a9c2..8ecb0dc 100644
--- a/include/unotools/saveopt.hxx
+++ b/include/unotools/saveopt.hxx
@@ -45,6 +45,7 @@ public:
         E_DOPRETTYPRINTING,
         E_WARNALIENFORMAT,
         E_LOADDOCPRINTER,
+        E_GENERATETHUMBNAIL,
         E_ODFDEFAULTVERSION,
         E_USESHA1INODF12,
         E_USEBLOWFISHINODF12,
@@ -114,6 +115,9 @@ public:
     void                    SetLoadDocumentPrinter( sal_Bool _bEnable );
     sal_Bool                IsLoadDocumentPrinter( ) const;
 
+    void                    SetGenerateThumbnail(sal_Bool);
+    sal_Bool                IsGenerateThumbnail() const;
+
     void                    SetODFDefaultVersion( ODFDefaultVersion eVersion );
     ODFDefaultVersion       GetODFDefaultVersion() const;
 
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 5349984..811b93e 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -2154,6 +2154,15 @@
           </info>
           <value>false</value>
         </prop>
+	<prop oor:name="GenerateThumbnail" oor:type="xs:boolean" oor:nillable="false">
+          <!-- UIHints: Tools  Options - General  Save - [Section] Save -->
+          <info>
+            <desc>Specifies whether to generate a thumbnail image and place it inside the 
+	      the odf archive file, which makes it possible to see a preview of the document.</desc>
+            <label>Store a preview of this document</label>
+          </info>
+          <value>true</value>
+        </prop>
         <prop oor:name="CreateBackup" oor:type="xs:boolean" oor:nillable="false">
           <!-- OldPath: General/Save/Documents -->
           <!-- OldLocation: soffice.cfg -->
diff --git a/sfx2/source/appl/appcfg.cxx b/sfx2/source/appl/appcfg.cxx
index fbf0f5b..ce9cabf 100644
--- a/sfx2/source/appl/appcfg.cxx
+++ b/sfx2/source/appl/appcfg.cxx
@@ -186,6 +186,14 @@ sal_Bool SfxApplication::GetOptions( SfxItemSet& rSet )
                                 bRet = sal_False;
                     }
                     break;
+                case SID_ATTR_THUMBNAIL :
+                    {
+                        bRet = sal_True;
+                        if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_GENERATETHUMBNAIL))
+                            if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_THUMBNAIL ),aSaveOptions.IsGenerateThumbnail())))
+                                bRet = sal_False;
+                    }
+                    break;
                 case SID_ATTR_PRETTYPRINTING:
                     {
                         bRet = sal_True;
@@ -658,6 +666,13 @@ void SfxApplication::SetOptions_Impl( const SfxItemSet& rSet )
         aSaveOptions.SetSaveRelFSys(((const SfxBoolItem *)pItem)->GetValue());
     }
 
+    // thumbnail generation
+    if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_THUMBNAIL), sal_True, &pItem))
+    {
+        DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
+        aSaveOptions.SetGenerateThumbnail(((const SfxBoolItem *)pItem)->GetValue());
+    }
+
     // Undo-Count
     if ( SFX_ITEM_SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_UNDO_COUNT), sal_True, &pItem))
     {
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 32bf234..dfc63a1 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1124,6 +1124,8 @@ sal_Bool SfxObjectShell::SaveTo_Impl
 
     ModifyBlocker_Impl aMod(this);
 
+    SvtSaveOptions aSaveOpt;
+
     const SfxFilter *pFilter = rMedium.GetFilter();
     if ( !pFilter )
     {
@@ -1169,7 +1171,6 @@ sal_Bool SfxObjectShell::SaveTo_Impl
         if ( bTryToPreserveScriptSignature )
         {
             // check that the storage format stays the same
-            SvtSaveOptions aSaveOpt;
             SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
 
             OUString aODFVersion;
@@ -1450,8 +1451,8 @@ sal_Bool SfxObjectShell::SaveTo_Impl
             }
         }
 
-
-        if ( bOk && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED && !bPasswdProvided )
+        //fdo#61320: only store thumbnail image if the corresponding option was not disabled in the Options dialog
+        if ( bOk && aSaveOpt.IsGenerateThumbnail() && GetCreateMode() != SFX_CREATE_MODE_EMBEDDED && !bPasswdProvided )
         {
             // store the thumbnail representation image
             // the thumbnail is not stored in case of encrypted document
diff --git a/unotools/source/config/saveopt.cxx b/unotools/source/config/saveopt.cxx
index a58439b..4e40fe6 100644
--- a/unotools/source/config/saveopt.cxx
+++ b/unotools/source/config/saveopt.cxx
@@ -65,6 +65,7 @@ class SvtSaveOptions_Impl : public utl::ConfigItem
                                         bDoPrettyPrinting,
                                         bWarnAlienFormat,
                                         bLoadDocPrinter,
+                                        bGenerateThumbnail,
                                         bUseSHA1InODF12,
                                         bUseBlowfishInODF12;
 
@@ -85,6 +86,7 @@ class SvtSaveOptions_Impl : public utl::ConfigItem
                                         bROWarnAlienFormat,
                                         bRODoPrettyPrinting,
                                         bROLoadDocPrinter,
+                                        bROGenerateThumbnail,
                                         bROODFDefaultVersion,
                                         bROUseSHA1InODF12,
                                         bROUseBlowfishInODF12;
@@ -111,6 +113,7 @@ public:
     sal_Bool                IsPrettyPrintingEnabled( ) const    { return bDoPrettyPrinting; }
     sal_Bool                IsWarnAlienFormat() const           { return bWarnAlienFormat; }
     sal_Bool                IsLoadDocPrinter() const            { return bLoadDocPrinter; }
+    sal_Bool                IsGenerateThumbnail() const        { return bGenerateThumbnail; }
     sal_Bool                IsUseSHA1InODF12() const            { return bUseSHA1InODF12; }
     sal_Bool                IsUseBlowfishInODF12() const        { return bUseBlowfishInODF12; }
 
@@ -131,6 +134,7 @@ public:
     void                    EnablePrettyPrinting( sal_Bool _bDoPP );
     void                    SetWarnAlienFormat( sal_Bool _bDoPP );
     void                    SetLoadDocPrinter( sal_Bool bNew );
+    void                    SetGenerateThumbnail( sal_Bool );
     void                    SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew );
 
     sal_Bool                IsReadOnly( SvtSaveOptions::EOption eOption ) const;
@@ -265,6 +269,15 @@ void SvtSaveOptions_Impl::SetLoadDocPrinter( sal_Bool bNew )
     }
 }
 
+void SvtSaveOptions_Impl::SetGenerateThumbnail( sal_Bool bThumbnailOption )
+{
+    if ( !bROGenerateThumbnail && bGenerateThumbnail != bThumbnailOption )
+    {
+        bGenerateThumbnail = bThumbnailOption;
+        SetModified();
+    }
+}
+
 void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew )
 {
     if ( !bROODFDefaultVersion && eODFDefaultVersion != eNew )
@@ -324,6 +337,9 @@ sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) cons
         case SvtSaveOptions::E_LOADDOCPRINTER :
             bReadOnly = bROLoadDocPrinter;
             break;
+        case SvtSaveOptions::E_GENERATETHUMBNAIL:
+            bReadOnly = bROGenerateThumbnail;
+            break;
         case SvtSaveOptions::E_ODFDEFAULTVERSION :
             bReadOnly = bROLoadDocPrinter;
             break;
@@ -349,12 +365,14 @@ sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) cons
 #define PRETTYPRINTING      9
 #define WARNALIENFORMAT     10
 #define LOADDOCPRINTER      11
-#define FILESYSTEM          12
-#define INTERNET            13
-#define SAVEWORKINGSET      14
-#define ODFDEFAULTVERSION   15
-#define USESHA1INODF12      16
-#define USEBLOWFISHINODF12  17
+#define GENERATETHUMBNAIL   12
+#define FILESYSTEM          13
+#define INTERNET            14
+#define SAVEWORKINGSET      15
+#define ODFDEFAULTVERSION   16
+#define USESHA1INODF12      17
+#define USEBLOWFISHINODF12  18
+
 
 Sequence< OUString > GetPropertyNames()
 {
@@ -372,6 +390,7 @@ Sequence< OUString > GetPropertyNames()
         "Document/PrettyPrinting",
         "Document/WarnAlienFormat",
         "Document/LoadPrinter",
+        "Document/GenerateThumbnail",
         "URL/FileSystem",
         "URL/Internet",
         "WorkingSet",
@@ -408,6 +427,7 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl()
     , bDoPrettyPrinting( sal_False )
     , bWarnAlienFormat( sal_True )
     , bLoadDocPrinter( sal_True )
+    , bGenerateThumbnail( sal_True )
     , bUseSHA1InODF12( sal_False )
     , bUseBlowfishInODF12( sal_False )
     , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST )
@@ -426,6 +446,7 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl()
     , bROWarnAlienFormat( CFG_READONLY_DEFAULT )
     , bRODoPrettyPrinting( CFG_READONLY_DEFAULT )
     , bROLoadDocPrinter( CFG_READONLY_DEFAULT )
+    , bROGenerateThumbnail( CFG_READONLY_DEFAULT )
     , bROODFDefaultVersion( CFG_READONLY_DEFAULT )
     , bROUseSHA1InODF12( CFG_READONLY_DEFAULT )
     , bROUseBlowfishInODF12( CFG_READONLY_DEFAULT )
@@ -540,6 +561,11 @@ SvtSaveOptions_Impl::SvtSaveOptions_Impl()
                                     bROLoadDocPrinter = pROStates[nProp];
                                     break;
 
+                                case GENERATETHUMBNAIL:
+                                    bGenerateThumbnail = bTemp;
+                                    bROGenerateThumbnail = pROStates[nProp];
+                                    break;
+
                                 case USESHA1INODF12:
                                     bUseSHA1InODF12 = bTemp;
                                     bROUseSHA1InODF12 = pROStates[nProp];
@@ -703,6 +729,14 @@ void SvtSaveOptions_Impl::Commit()
                     ++nRealCount;
                 }
                 break;
+            case GENERATETHUMBNAIL:
+                if (!bROGenerateThumbnail)
+                {
+                    pValues[nRealCount] <<= bGenerateThumbnail;
+                    pNames[nRealCount] = pOrgNames[i];
+                    ++nRealCount;
+                }
+                break;
             case ODFDEFAULTVERSION:
                 if (!bROODFDefaultVersion)
                 {
@@ -1001,6 +1035,16 @@ sal_Bool SvtSaveOptions::IsLoadDocumentPrinter() const
     return pImp->pSaveOpt->IsLoadDocPrinter();
 }
 
+sal_Bool SvtSaveOptions::IsGenerateThumbnail() const
+{
+    return pImp->pSaveOpt->IsGenerateThumbnail();
+}
+
+void SvtSaveOptions::SetGenerateThumbnail(sal_Bool _bEnable )
+{
+    pImp->pSaveOpt->SetGenerateThumbnail(_bEnable);
+}
+
 void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion )
 {
     pImp->pSaveOpt->SetODFDefaultVersion( eVersion );
-- 
1.8.5.3

