[Libreoffice-commits] core.git: include/sfx2 sfx2/Library_sfx.mk sfx2/source

Krisztian Pinter pin.terminator at gmail.com
Thu Aug 8 12:05:44 PDT 2013


 include/sfx2/recentdocsview.hxx            |   61 +++++++++
 include/sfx2/recentdocsviewitem.hxx        |   26 ++++
 include/sfx2/thumbnailviewitem.hxx         |    2 
 sfx2/Library_sfx.mk                        |    2 
 sfx2/source/control/recentdocsview.cxx     |  183 +++++++++++++++++++++++++++++
 sfx2/source/control/recentdocsviewitem.cxx |   53 ++++++++
 6 files changed, 326 insertions(+), 1 deletion(-)

New commits:
commit 9cf4be5ce8116eb447abea024f07456275d4ef4a
Author: Krisztian Pinter <pin.terminator at gmail.com>
Date:   Thu Aug 8 17:41:07 2013 +0200

    startcenter: Add RecentDocsView for displaying thumbnails for recent docs
    
    Change-Id: I6d9bb87a6ee28d62ee012e6807d1c5a4f3219e27

diff --git a/include/sfx2/recentdocsview.hxx b/include/sfx2/recentdocsview.hxx
new file mode 100644
index 0000000..6ae9391
--- /dev/null
+++ b/include/sfx2/recentdocsview.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __SFX2_RECENTDOCSVIEW_HXX__
+#define __SFX2_RECENTDOCSVIEW_HXX__
+
+#include <sfx2/thumbnailview.hxx>
+#include <sfx2/recentdocsviewitem.hxx>
+
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+
+struct LoadRecentFile
+{
+    ::com::sun::star::util::URL                                                 aTargetURL;
+    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   aArgSeq;
+    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >      xDispatch;
+};
+
+class SFX2_DLLPUBLIC RecentDocsView :   protected ::comphelper::OBaseMutex,
+                                        public ThumbnailView
+{
+public:
+    RecentDocsView( Window* pParent );
+    virtual ~RecentDocsView();
+
+    void insertItem(const OUString &rURL, const OUString &rTitle);
+    void loadRecentDocs();
+
+    virtual Size GetOptimalSize() const;
+
+    void SetThumbnailSize(long ThumbnailWidth, long ThumbnailHeight);
+    void SetHeight(long Height);
+
+    DECL_STATIC_LINK( RecentDocsView, ExecuteHdl_Impl, LoadRecentFile* );
+
+protected:
+    virtual void OnItemDblClicked(ThumbnailViewItem *pItem);
+
+    long    mnItemMaxWidth;
+    long    mnItemMaxHeight;
+    long    mnItemPadding;
+    long    mnItemMaxTextLength;
+    long    mnItemThumbnailMaxHeight;
+    long    mnItemMaxHeightSub;
+
+    long mnHeight;
+
+    int     mnMaxThumbnailItems;
+};
+
+#endif  // __SFX2_RECENTDOCSVIEW_HXX__
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/sfx2/recentdocsviewitem.hxx b/include/sfx2/recentdocsviewitem.hxx
new file mode 100644
index 0000000..05ae15ae
--- /dev/null
+++ b/include/sfx2/recentdocsviewitem.hxx
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef __SFX2_RECENTDOCSVIEWITEM_HXX__
+#define __SFX2_RECENTDOCSVIEWITEM_HXX__
+
+#include <sfx2/thumbnailview.hxx>
+
+class RecentDocsViewItem : public ThumbnailViewItem
+{
+public:
+    RecentDocsViewItem(ThumbnailView &rView, const OUString &rURL, const OUString &rTitle);
+    virtual void setEditTitle (bool edit, bool bChangeFocus = true);
+
+    OUString maURL;
+};
+
+#endif  // __SFX2_RECENTDOCSVIEWITEM_HXX__
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/sfx2/thumbnailviewitem.hxx b/include/sfx2/thumbnailviewitem.hxx
index 64a20cd..2272bc5 100644
--- a/include/sfx2/thumbnailviewitem.hxx
+++ b/include/sfx2/thumbnailviewitem.hxx
@@ -89,7 +89,7 @@ public:
 
     void setHighlight (bool state);
 
-    void setEditTitle (bool edit, bool bChangeFocus = true);
+    virtual void setEditTitle (bool edit, bool bChangeFocus = true);
     void updateTitleEditSize ();
     virtual void setTitle (const OUString& rTitle);
 
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 4b8f424..836f232 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -134,6 +134,8 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/control/msgpool \
     sfx2/source/control/objface \
     sfx2/source/control/querystatus \
+    sfx2/source/control/recentdocsview \
+    sfx2/source/control/recentdocsviewitem \
     sfx2/source/control/request \
     sfx2/source/control/sfxstatuslistener \
     sfx2/source/control/shell \
diff --git a/sfx2/source/control/recentdocsview.cxx b/sfx2/source/control/recentdocsview.cxx
new file mode 100644
index 0000000..a1654a5
--- /dev/null
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -0,0 +1,183 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sfx2/recentdocsview.hxx>
+
+#include <comphelper/configurationhelper.hxx>
+#include <sfx2/templateabstractview.hxx>
+#include <sfx2/app.hxx>
+#include <unotools/historyoptions.hxx>
+#include <vcl/builder.hxx>
+#include <vcl/svapp.hxx>
+#include <tools/urlobj.hxx>
+#include <com/sun/star/util/URLTransformer.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+
+using namespace ::com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::beans;
+
+static const char SFX_REFERER_USER[] = "private:user";
+
+RecentDocsView::RecentDocsView( Window* pParent )
+    : ThumbnailView(pParent)
+    , mnItemMaxWidth(130)
+    , mnItemMaxHeight(130)
+    , mnItemPadding(0)
+    , mnItemMaxTextLength(30)
+    , mnItemThumbnailMaxHeight(150)
+    , mnItemMaxHeightSub(160)
+    , mnHeight(260)
+    , mnMaxThumbnailItems(50)
+{
+    setItemMaxTextLength( mnItemMaxTextLength );
+    setItemDimensions( mnItemMaxWidth, mnItemThumbnailMaxHeight, mnItemMaxHeight - mnItemThumbnailMaxHeight, mnItemPadding );
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeRecentDocsView(Window *pParent, VclBuilder::stringmap &)
+{
+    return new RecentDocsView(pParent);
+}
+
+RecentDocsView::~RecentDocsView()
+{
+}
+
+void RecentDocsView::insertItem(const OUString &rURL, const OUString &rTitle)
+{
+    RecentDocsViewItem *pChild = new RecentDocsViewItem(*this, rURL, rTitle);
+
+    AppendItem(pChild);
+}
+
+void RecentDocsView::loadRecentDocs()
+{
+    Clear();
+
+    Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
+    int nRecentThumbnailItems = mnMaxThumbnailItems < aHistoryList.getLength() ? mnMaxThumbnailItems : aHistoryList.getLength();
+    for ( int i = 0; i < nRecentThumbnailItems; i++ )
+    {
+        Sequence< PropertyValue >& rRecentEntry = aHistoryList[i];
+
+        OUString aURL;
+        OUString aTitle;
+
+        for ( int j = 0; j < rRecentEntry.getLength(); j++ )
+        {
+            Any a = rRecentEntry[j].Value;
+
+            if (rRecentEntry[j].Name == "URL")
+                a >>= aURL;
+            else if (rRecentEntry[j].Name == "Title")
+                a >>= aTitle;
+        }
+
+        insertItem(aURL, aTitle);
+    }
+
+    CalculateItemPositions();
+    Invalidate();
+}
+
+void RecentDocsView::OnItemDblClicked(ThumbnailViewItem *pItem)
+{
+    RecentDocsViewItem* pRecentItem = dynamic_cast<RecentDocsViewItem*>(pItem);
+
+    Reference< XDispatch >            xDispatch;
+    Reference< XDispatchProvider >    xDispatchProvider;
+    css::util::URL                    aTargetURL;
+    Sequence< PropertyValue >         aArgsList;
+
+    uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
+    uno::Reference< frame::XFrame > xActiveFrame = xDesktop->getActiveFrame();
+
+    osl::ClearableMutexGuard aLock( m_aMutex );
+    xDispatchProvider = Reference< XDispatchProvider >( xActiveFrame, UNO_QUERY );
+    aLock.clear();
+
+    aTargetURL.Complete = pRecentItem->maURL;
+    Reference< ::com::sun::star::util::XURLTransformer > xTrans(
+        ::com::sun::star::util::URLTransformer::create(
+            ::comphelper::getProcessComponentContext() ) );
+    xTrans->parseStrict( aTargetURL );
+
+    sal_Int32 nSize = 2;
+    aArgsList.realloc( nSize );
+    aArgsList[0].Name = "Referer";
+    aArgsList[0].Value = makeAny( OUString( SFX_REFERER_USER ) );
+
+    // documents will never be opened as templates
+    aArgsList[1].Name = "AsTemplate";
+    aArgsList[1].Value = makeAny( (sal_Bool) sal_False );
+
+    xDispatch = xDispatchProvider->queryDispatch( aTargetURL, "_default", 0 );
+
+    if ( xDispatch.is() )
+    {
+        // Call dispatch asychronously as we can be destroyed while dispatch is
+        // executed. VCL is not able to survive this as it wants to call listeners
+        // after select!!!
+        LoadRecentFile* pLoadRecentFile = new LoadRecentFile;
+        pLoadRecentFile->xDispatch  = xDispatch;
+        pLoadRecentFile->aTargetURL = aTargetURL;
+        pLoadRecentFile->aArgSeq    = aArgsList;
+
+        Application::PostUserEvent( STATIC_LINK(0, RecentDocsView, ExecuteHdl_Impl), pLoadRecentFile );
+    }
+}
+
+void RecentDocsView::SetThumbnailSize(long ThumbnailWidth, long ThumbnailHeight)
+{
+    mnItemMaxWidth = ThumbnailWidth;
+    mnItemMaxHeight = ThumbnailHeight;
+    setItemDimensions( mnItemMaxWidth, mnItemThumbnailMaxHeight, mnItemMaxHeight - mnItemThumbnailMaxHeight, mnItemPadding );
+}
+
+void RecentDocsView::SetHeight(long Height)
+{
+    mnHeight = Height;
+}
+
+Size RecentDocsView::GetOptimalSize() const
+{
+    return Size(Window::GetOptimalSize().Width(), mnHeight);
+}
+
+IMPL_STATIC_LINK_NOINSTANCE( RecentDocsView, ExecuteHdl_Impl, LoadRecentFile*, pLoadRecentFile )
+{
+    try
+    {
+        // Asynchronous execution as this can lead to our own destruction!
+        // Framework can recycle our current frame and the layout manager disposes all user interface
+        // elements if a component gets detached from its frame!
+        pLoadRecentFile->xDispatch->dispatch( pLoadRecentFile->aTargetURL, pLoadRecentFile->aArgSeq );
+    }
+    catch ( const Exception& )
+    {
+    }
+
+    delete pLoadRecentFile;
+    return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/recentdocsviewitem.cxx b/sfx2/source/control/recentdocsviewitem.cxx
new file mode 100644
index 0000000..996d064
--- /dev/null
+++ b/sfx2/source/control/recentdocsviewitem.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/recentdocsviewitem.hxx>
+
+#include <sfx2/sfxresid.hxx>
+#include "../doc/doc.hrc"
+
+#include <sfx2/templateabstractview.hxx>
+#include <tools/urlobj.hxx>
+
+RecentDocsViewItem::RecentDocsViewItem(ThumbnailView &rView, const OUString &rURL, const OUString &rTitle)
+    : ThumbnailViewItem(rView)
+{
+    OUString aTitle = rTitle;
+    if( !aTitle.getLength() )
+    {
+        // If we have no title, get filename from the URL
+        INetURLObject aURLObj(rURL);
+        aTitle = aURLObj.GetName(INetURLObject::DECODE_WITH_CHARSET);
+    }
+
+    BitmapEx aThumbnail = ThumbnailView::readThumbnail(rURL);
+    if( aThumbnail.IsEmpty() )
+    {
+        // Use the default thumbnail if we have nothing else
+        aThumbnail = TemplateAbstractView::getDefaultThumbnail(rURL);
+    }
+    if( aThumbnail.IsEmpty() )
+    {
+        // Last fallback
+        aThumbnail = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) );
+    }
+
+    maURL = rURL;
+    maTitle = aTitle;
+    maPreview1 = TemplateAbstractView::scaleImg(aThumbnail, 150, 150);
+}
+
+void RecentDocsViewItem::setEditTitle (bool edit, bool bChangeFocus)
+{
+    // Unused parameters.
+    (void)edit;
+    (void)bChangeFocus;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list