dbaccess/source/ui/app/AppController.cxx                      |    2 -
 dbaccess/source/ui/control/opendoccontrols.cxx                |    2 -
 framework/source/uielement/recentfilesmenucontroller.cxx      |   10 ++++--
 include/unotools/historyoptions.hxx                           |    3 +-
 officecfg/registry/schema/org/openoffice/Office/Histories.xcs |    6 ++++
 sfx2/inc/recentdocsview.hxx                                   |    2 -
 sfx2/source/appl/newhelp.cxx                                  |    4 ++
 sfx2/source/appl/sfxpicklist.cxx                              |    4 ++
 sfx2/source/control/recentdocsview.cxx                        |    6 ++--
 sfx2/source/control/recentdocsviewitem.cxx                    |    6 +++-
 sfx2/source/control/recentdocsviewitem.hxx                    |    4 ++
 unotools/source/config/historyoptions.cxx                     |   15 ++++++++--
 12 files changed, 47 insertions(+), 17 deletions(-)

New commits:
commit 404c51f3664ffd4f7e2c1c8bb8a12ac70954fec2
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Apr 25 14:53:33 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Apr 26 10:39:31 2022 +0200

    officecfg,unotools,framework,sfx2: store ReadOnly for recent docs
    
    Add Office::Histories::HistoryItem::ReadOnly flag to configuration so
    that a document that was opened read-only isn't opened as editable from
    recent documents.
    
    Change-Id: I6985da287d3337a53a7e41e8e500421038eedb91
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133385
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/dbaccess/source/ui/app/AppController.cxx 
b/dbaccess/source/ui/app/AppController.cxx
index 96e23f041d6d..f04d7322aa64 100644
--- a/dbaccess/source/ui/app/AppController.cxx
+++ b/dbaccess/source/ui/app/AppController.cxx
@@ -362,7 +362,7 @@ void SAL_CALL OApplicationController::disposing()
                             aURL.GetURLNoPass( 
INetURLObject::DecodeMechanism::NONE ),
                             aFilter,
                             getStrippedDatabaseName(),
-                            std::nullopt);
+                            std::nullopt, std::nullopt);
 
                     // add to recent document list
                     if ( aURL.GetProtocol() == INetProtocol::File )
diff --git a/dbaccess/source/ui/control/opendoccontrols.cxx 
b/dbaccess/source/ui/control/opendoccontrols.cxx
index bf958d4a30b7..2fb86bdca691 100644
--- a/dbaccess/source/ui/control/opendoccontrols.cxx
+++ b/dbaccess/source/ui/control/opendoccontrols.cxx
@@ -145,7 +145,7 @@ namespace dbaui
                 OUString sTitle = rHistoryItem.sTitle;
                 OUString sPassword = rHistoryItem.sPassword;
 
-                //  If the entry is an impress file then insert it into the
+                //  If the entry is a Base file then insert it into the
                 //  history list and the list box.
                 Sequence< PropertyValue > aProps;
                 xFilterFactory->getByName( sFilter ) >>= aProps;
diff --git a/framework/source/uielement/recentfilesmenucontroller.cxx 
b/framework/source/uielement/recentfilesmenucontroller.cxx
index f96621ece94b..74c66e90b9d3 100644
--- a/framework/source/uielement/recentfilesmenucontroller.cxx
+++ b/framework/source/uielement/recentfilesmenucontroller.cxx
@@ -92,7 +92,7 @@ private:
     void fillPopupMenu( css::uno::Reference< css::awt::XPopupMenu > const & 
rPopupMenu );
     void executeEntry( sal_Int32 nIndex );
 
-    std::vector< OUString >   m_aRecentFilesItems;
+    std::vector<std::pair<OUString, bool>>   m_aRecentFilesItems;
     bool                      m_bDisabled : 1;
     bool                      m_bShowToolbarEntries;
 };
@@ -157,7 +157,7 @@ void RecentFilesMenuController::fillPopupMenu( Reference< 
css::awt::XPopupMenu >
         for ( int i = 0; i < nPickListMenuItems; i++ )
         {
             const SvtHistoryOptions::HistoryItem& rPickListEntry = 
aHistoryList[i];
-            m_aRecentFilesItems.push_back( rPickListEntry.sURL );
+            m_aRecentFilesItems.emplace_back(rPickListEntry.sURL, 
rPickListEntry.isReadOnly);
         }
     }
 
@@ -191,7 +191,7 @@ void RecentFilesMenuController::fillPopupMenu( Reference< 
css::awt::XPopupMenu >
 
             // Abbreviate URL
             OUString   aMenuTitle;
-            INetURLObject   aURL( m_aRecentFilesItems[i] );
+            INetURLObject const aURL(m_aRecentFilesItems[i].first);
             OUString aTipHelpText( aURL.getFSysPath( FSysStyle::Detect ) );
 
             if ( aURL.GetProtocol() == INetProtocol::File )
@@ -263,13 +263,15 @@ void RecentFilesMenuController::executeEntry( sal_Int32 
nIndex )
     Sequence< PropertyValue > aArgsList{
         comphelper::makePropertyValue("Referer", OUString( "private:user" )),
 
+        comphelper::makePropertyValue("ReadOnly", 
m_aRecentFilesItems[nIndex].second),
+
         // documents in the picklist will never be opened as templates
         comphelper::makePropertyValue("AsTemplate", false),
 
         // Type detection needs to know which app we are opening it from.
         comphelper::makePropertyValue("DocumentService", m_aModuleName)
     };
-    dispatchCommand( m_aRecentFilesItems[ nIndex ], aArgsList, "_default" );
+    dispatchCommand(m_aRecentFilesItems[nIndex].first, aArgsList, "_default");
 }
 
 // XEventListener
diff --git a/include/unotools/historyoptions.hxx 
b/include/unotools/historyoptions.hxx
index dccc8101cf89..1f743e062cb2 100644
--- a/include/unotools/historyoptions.hxx
+++ b/include/unotools/historyoptions.hxx
@@ -58,6 +58,7 @@ namespace SvtHistoryOptions
         OUString sTitle;
         OUString sPassword;
         OUString sThumbnail;
+        bool isReadOnly = false;
     };
     UNOTOOLS_DLLPUBLIC std::vector< HistoryItem > GetList(EHistoryType 
eHistory);
 
@@ -72,7 +73,7 @@ namespace SvtHistoryOptions
     */
     UNOTOOLS_DLLPUBLIC void AppendItem(EHistoryType eHistory,
             const OUString& sURL, const OUString& sFilter, const OUString& 
sTitle,
-            const std::optional<OUString>& sThumbnail);
+            const std::optional<OUString>& sThumbnail, std::optional<bool> 
oIsReadOnly);
 
     /** Delete item from the specified list.
     */
diff --git a/officecfg/registry/schema/org/openoffice/Office/Histories.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
index d4f8b27ea67e..0f4894477d4c 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
@@ -47,6 +47,11 @@
           <desc>Contains a base64 encoded thumbnail of the document.</desc>
         </info>
       </prop>
+      <prop oor:name="ReadOnly" oor:type="xs:boolean">
+        <info>
+          <desc>Stores whether the document was opened editable or 
read-only.</desc>
+        </info>
+      </prop>
     </group>
     <group oor:name="HistoryOrder">
       <info>
diff --git a/sfx2/inc/recentdocsview.hxx b/sfx2/inc/recentdocsview.hxx
index 28b1f77e7c27..3ee34eabc41a 100644
--- a/sfx2/inc/recentdocsview.hxx
+++ b/sfx2/inc/recentdocsview.hxx
@@ -63,7 +63,7 @@ public:
     RecentDocsView(std::unique_ptr<weld::ScrolledWindow> xWindow, 
std::unique_ptr<weld::Menu> xMenu);
     virtual ~RecentDocsView() override;
 
-    void insertItem(const OUString &rURL, const OUString &rTitle, const 
OUString& rThumbnail, sal_uInt16 nId);
+    void insertItem(const OUString &rURL, const OUString &rTitle, const 
OUString& rThumbnail, bool isReadOnly, sal_uInt16 nId);
 
     static bool typeMatchesExtension(ApplicationType type, std::u16string_view 
rExt);
 
diff --git a/sfx2/source/appl/newhelp.cxx b/sfx2/source/appl/newhelp.cxx
index a120a99f41bb..289a848b4b36 100644
--- a/sfx2/source/appl/newhelp.cxx
+++ b/sfx2/source/appl/newhelp.cxx
@@ -1186,7 +1186,9 @@ BookmarksTabPage_Impl::~BookmarksTabPage_Impl()
     SvtHistoryOptions::Clear( EHistoryType::HelpBookmarks );
     const sal_Int32 nCount = m_xBookmarksBox->n_children();
     for (sal_Int32 i = 0; i < nCount; ++i)
-        SvtHistoryOptions::AppendItem(EHistoryType::HelpBookmarks, 
m_xBookmarksBox->get_id(i), "", m_xBookmarksBox->get_text(i), std::nullopt);
+    {
+        SvtHistoryOptions::AppendItem(EHistoryType::HelpBookmarks, 
m_xBookmarksBox->get_id(i), "", m_xBookmarksBox->get_text(i), std::nullopt, 
std::nullopt);
+    }
 
     m_xBookmarksBox.reset();
     m_xBookmarksPB.reset();
diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx
index 83834597aff0..8d929d1ad68b 100644
--- a/sfx2/source/appl/sfxpicklist.cxx
+++ b/sfx2/source/appl/sfxpicklist.cxx
@@ -123,13 +123,15 @@ void SfxPickListImpl::AddDocumentToPickList( const 
SfxObjectShell* pDocSh )
             }
         }
     }
+    ::std::optional<bool> const oIsReadOnly(pDocSh->IsReadOnly());
 
     // add to svtool history options
     SvtHistoryOptions::AppendItem( EHistoryType::PickList,
             aURL.GetURLNoPass( INetURLObject::DecodeMechanism::NONE ),
             aFilter,
             aTitle,
-            aThumbnail);
+            aThumbnail,
+            oIsReadOnly);
 
     if ( aURL.GetProtocol() == INetProtocol::File )
         Application::AddToRecentDocumentList( aURL.GetURLNoPass( 
INetURLObject::DecodeMechanism::NONE ),
diff --git a/sfx2/source/control/recentdocsview.cxx 
b/sfx2/source/control/recentdocsview.cxx
index 3c6110c1e8a1..b7a6ba4adcea 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -143,9 +143,9 @@ bool RecentDocsView::isAcceptedFile(const INetURLObject& 
rURL) const
            (mnFileTypes & ApplicationType::TYPE_OTHER    && 
typeMatchesExtension(ApplicationType::TYPE_OTHER,   aExt));
 }
 
-void RecentDocsView::insertItem(const OUString &rURL, const OUString &rTitle, 
const OUString& rThumbnail, sal_uInt16 nId)
+void RecentDocsView::insertItem(const OUString &rURL, const OUString &rTitle, 
const OUString& rThumbnail, bool isReadOnly, sal_uInt16 nId)
 {
-    AppendItem( std::make_unique<RecentDocsViewItem>(*this, rURL, rTitle, 
rThumbnail, nId, mnItemMaxSize) );
+    AppendItem( std::make_unique<RecentDocsViewItem>(*this, rURL, rTitle, 
rThumbnail, nId, mnItemMaxSize, isReadOnly) );
 }
 
 void RecentDocsView::Reload()
@@ -166,7 +166,7 @@ void RecentDocsView::Reload()
         //Remove extension from url's last segment and use it as title
         const OUString aTitle = aURLObj.GetBase(); 
//DecodeMechanism::WithCharset
 
-        insertItem(aURL, aTitle, rRecentEntry.sThumbnail, i+1);
+        insertItem(aURL, aTitle, rRecentEntry.sThumbnail, 
rRecentEntry.isReadOnly, i+1);
     }
 
     CalculateItemPositions();
diff --git a/sfx2/source/control/recentdocsviewitem.cxx 
b/sfx2/source/control/recentdocsviewitem.cxx
index d58f1a49d562..e9c53faeffcf 100644
--- a/sfx2/source/control/recentdocsviewitem.cxx
+++ b/sfx2/source/control/recentdocsviewitem.cxx
@@ -121,10 +121,13 @@ BitmapEx getModuleOverlay(const OUString& rURL)
 };
 
 RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const 
OUString &rURL,
-    const OUString &rTitle, std::u16string_view sThumbnailBase64, sal_uInt16 
nId, tools::Long nThumbnailSize)
+    const OUString &rTitle, std::u16string_view const sThumbnailBase64,
+        sal_uInt16 const nId, tools::Long const nThumbnailSize,
+        bool const isReadOnly)
     : ThumbnailViewItem(rView, nId),
       mrParentView(rView),
       maURL(rURL),
+      m_isReadOnly(isReadOnly),
       m_bRemoveIconHighlighted(false),
       m_aRemoveRecentBitmap(BMP_RECENTDOC_REMOVE),
       m_aRemoveRecentBitmapHighlighted(BMP_RECENTDOC_REMOVE_HIGHLIGHTED)
@@ -317,6 +320,7 @@ void RecentDocsViewItem::OpenDocument()
     xTrans->parseStrict(aTargetURL);
 
     aArgsList = { comphelper::makePropertyValue("Referer", 
OUString("private:user")),
+                  comphelper::makePropertyValue("ReadOnly", m_isReadOnly),
                   // documents will never be opened as templates
                   comphelper::makePropertyValue("AsTemplate", false) };
 
diff --git a/sfx2/source/control/recentdocsviewitem.hxx 
b/sfx2/source/control/recentdocsviewitem.hxx
index 41225e68c21b..3f5f6d3faab2 100644
--- a/sfx2/source/control/recentdocsviewitem.hxx
+++ b/sfx2/source/control/recentdocsviewitem.hxx
@@ -21,7 +21,7 @@ class RecentDocsViewItem final : public ThumbnailViewItem
 {
 public:
     RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUString &rURL,
-        const OUString &rTitle, std::u16string_view sThumbnailBase64, 
sal_uInt16 nId, tools::Long nThumbnailSize);
+        const OUString &rTitle, std::u16string_view sThumbnailBase64, 
sal_uInt16 nId, tools::Long nThumbnailSize, bool isReadOnly);
 
     /** Updates own highlight status based on the aPoint position.
 
@@ -50,6 +50,8 @@ private:
 
     OUString maURL;
 
+    bool m_isReadOnly = false;
+
     OUString m_sHelpText;
 
     /// Is the icon that the user can click to remove the document from the 
recent documents highlighted?
diff --git a/unotools/source/config/historyoptions.cxx 
b/unotools/source/config/historyoptions.cxx
index de8186795cda..edbf5f5d6b7b 100644
--- a/unotools/source/config/historyoptions.cxx
+++ b/unotools/source/config/historyoptions.cxx
@@ -42,6 +42,7 @@ namespace {
     constexpr OUStringLiteral s_sTitle = u"Title";
     constexpr OUStringLiteral s_sPassword = u"Password";
     constexpr OUStringLiteral s_sThumbnail = u"Thumbnail";
+    constexpr OUStringLiteral s_sReadOnly = u"ReadOnly";
 }
 
 static uno::Reference<container::XNameAccess> GetConfig();
@@ -123,6 +124,7 @@ std::vector< HistoryItem > GetList( EHistoryType eHistory )
                 xSet->getPropertyValue(s_sTitle) >>= aItem.sTitle;
                 xSet->getPropertyValue(s_sPassword) >>= aItem.sPassword;
                 xSet->getPropertyValue(s_sThumbnail) >>= aItem.sThumbnail;
+                xSet->getPropertyValue(s_sReadOnly) >>= aItem.isReadOnly;
                 aRet.push_back(aItem);
             }
             catch(const uno::Exception&)
@@ -147,7 +149,8 @@ std::vector< HistoryItem > GetList( EHistoryType eHistory )
 
 void AppendItem(EHistoryType eHistory,
         const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
-        const std::optional<OUString>& sThumbnail)
+        const std::optional<OUString>& sThumbnail,
+        ::std::optional<bool> const oIsReadOnly)
 {
     try
     {
@@ -171,12 +174,16 @@ void AppendItem(EHistoryType eHistory,
         if (xItemList->hasByName(sURL))
         {
             uno::Reference<beans::XPropertySet>       xSet;
+            xItemList->getByName(sURL) >>= xSet;
             if (sThumbnail)
             {
                 // update the thumbnail
-                xItemList->getByName(sURL) >>= xSet;
                 xSet->setPropertyValue(s_sThumbnail, 
uno::makeAny(*sThumbnail));
             }
+            if (oIsReadOnly)
+            {
+                xSet->setPropertyValue(s_sReadOnly, 
uno::makeAny(*oIsReadOnly));
+            }
 
             for (sal_Int32 i=0; i<nLength; ++i)
             {
@@ -265,6 +272,10 @@ void AppendItem(EHistoryType eHistory,
             xSet->setPropertyValue(s_sTitle, uno::makeAny(sTitle));
             xSet->setPropertyValue(s_sPassword, uno::makeAny(OUString()));
             xSet->setPropertyValue(s_sThumbnail, 
uno::makeAny(sThumbnail.value_or(OUString())));
+            if (oIsReadOnly)
+            {
+                xSet->setPropertyValue(s_sReadOnly, 
uno::makeAny(*oIsReadOnly));
+            }
 
             ::comphelper::ConfigurationHelper::flush(xCfg);
         }
commit c51ef466f736c9e0e192d2c7feeda0a39bca2011
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Apr 25 14:58:29 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Apr 26 10:39:22 2022 +0200

    officecfg: deprecate Office::Histories::HistoryItem::Password
    
    Appears not to be set anywhere in the code, which is probably for the
    best; let's deprecate it.
    
    Change-Id: I2cb1d4095773819dfa602b0e2f71e83f1329011d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133386
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Histories.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
index 23095a8ebb66..d4f8b27ea67e 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Histories.xcs
@@ -38,6 +38,7 @@
       </prop>
       <prop oor:name="Password" oor:type="xs:string">
         <info>
+          <deprecated>Not used anymore</deprecated>
           <desc>Contains an encoded password used to open the document.</desc>
         </info>
       </prop>

Reply via email to