[Libreoffice-commits] .: Branch 'feature/template-dialog' - 3 commits - sfx2/inc sfx2/source

Rafael Dominguez rdominguez at kemper.freedesktop.org
Tue Jun 5 19:43:53 PDT 2012


 sfx2/inc/templatedlg.hxx        |    4 +
 sfx2/source/doc/templatedlg.cxx |  159 +++++++++++++++++++++++++++++++++++++++-
 sfx2/source/doc/templatedlg.hrc |    2 
 sfx2/source/doc/templatedlg.src |   13 ++-
 4 files changed, 174 insertions(+), 4 deletions(-)

New commits:
commit f74a116fe3303c69cb8d6f886f3678f183e35f84
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Jun 5 22:13:31 2012 -0430

    Display documents embedded thumbnails.
    
    Change-Id: I0f56c6e564dbfcfc646717c562d61b8bd977edd1

diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index e6393dc..337061c 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -9,17 +9,138 @@
 
 #include "templatedlg.hxx"
 
+#include <comphelper/processfactory.hxx>
 #include <sfx2/doctempl.hxx>
 #include <sfx2/sfxresid.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <vcl/pngread.hxx>
+
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
 
 #include "orgmgr.hxx"
 
 #include "doc.hrc"
 #include "templatedlg.hrc"
 
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
 #define MAX_COLUMN_COUNT 4
 #define MAX_LINE_COUNT 2
 
+Image lcl_fetchThumbnail (const rtl::OUString &msURL)
+{
+
+    // Load the thumbnail from a template document.
+    uno::Reference<io::XInputStream> xIStream;
+
+    uno::Reference< lang::XMultiServiceFactory > xServiceManager (
+        ::comphelper::getProcessServiceFactory());
+    if (xServiceManager.is())
+    {
+        try
+        {
+            uno::Reference<lang::XSingleServiceFactory> xStorageFactory(
+                xServiceManager->createInstance( "com.sun.star.embed.StorageFactory"),
+                uno::UNO_QUERY);
+
+            if (xStorageFactory.is())
+            {
+                uno::Sequence<uno::Any> aArgs (2);
+                aArgs[0] <<= msURL;
+                aArgs[1] <<= embed::ElementModes::READ;
+                uno::Reference<embed::XStorage> xDocStorage (
+                    xStorageFactory->createInstanceWithArguments(aArgs),
+                    uno::UNO_QUERY);
+
+                try
+                {
+                    if (xDocStorage.is())
+                    {
+                        uno::Reference<embed::XStorage> xStorage (
+                            xDocStorage->openStorageElement(
+                                "Thumbnails",
+                                embed::ElementModes::READ));
+                        if (xStorage.is())
+                        {
+                            uno::Reference<io::XStream> xThumbnailCopy (
+                                xStorage->cloneStreamElement("thumbnail.png"));
+                            if (xThumbnailCopy.is())
+                                xIStream = xThumbnailCopy->getInputStream();
+                        }
+                    }
+                }
+                catch (const uno::Exception& rException)
+                {
+                    OSL_TRACE (
+                        "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s",
+                        ::rtl::OUStringToOString(msURL,
+                            RTL_TEXTENCODING_UTF8).getStr(),
+                        ::rtl::OUStringToOString(rException.Message,
+                            RTL_TEXTENCODING_UTF8).getStr());
+                }
+
+                try
+                {
+                    // An (older) implementation had a bug - The storage
+                    // name was "Thumbnail" instead of "Thumbnails".  The
+                    // old name is still used as fallback but this code can
+                    // be removed soon.
+                    if ( ! xIStream.is())
+                    {
+                        uno::Reference<embed::XStorage> xStorage (
+                            xDocStorage->openStorageElement( "Thumbnail",
+                                embed::ElementModes::READ));
+                        if (xStorage.is())
+                        {
+                            uno::Reference<io::XStream> xThumbnailCopy (
+                                xStorage->cloneStreamElement("thumbnail.png"));
+                            if (xThumbnailCopy.is())
+                                xIStream = xThumbnailCopy->getInputStream();
+                        }
+                    }
+                }
+                catch (const uno::Exception& rException)
+                {
+                    OSL_TRACE (
+                        "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s",
+                        ::rtl::OUStringToOString(msURL,
+                            RTL_TEXTENCODING_UTF8).getStr(),
+                        ::rtl::OUStringToOString(rException.Message,
+                            RTL_TEXTENCODING_UTF8).getStr());
+                }
+            }
+        }
+        catch (const uno::Exception& rException)
+        {
+            OSL_TRACE (
+                "caught exception while trying to access tuhmbnail of %s: %s",
+                ::rtl::OUStringToOString(msURL,
+                    RTL_TEXTENCODING_UTF8).getStr(),
+                ::rtl::OUStringToOString(rException.Message,
+                    RTL_TEXTENCODING_UTF8).getStr());
+        }
+    }
+
+    // Extract the image from the stream.
+    BitmapEx aThumbnail;
+    if (xIStream.is())
+    {
+        ::std::auto_ptr<SvStream> pStream (
+            ::utl::UcbStreamHelper::CreateStream (xIStream));
+        ::vcl::PNGReader aReader (*pStream);
+        aThumbnail = aReader.Read ();
+    }
+
+    // Note that the preview is returned without scaling it to the desired
+    // width.  This gives the caller the chance to take advantage of a
+    // possibly larger resolution then was asked for.
+    return aThumbnail;
+}
+
 SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     : ModalDialog(parent, SfxResId(DLG_TEMPLATE_MANAGER)),
       aButtonAll(this,SfxResId(BTN_SELECT_ALL)),
@@ -37,17 +158,22 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     aButtonAll.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewAllHdl));
     aButtonDocs.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewDocsHdl));
 
-    sal_uInt16 nCount = mpMgr->GetTemplates()->GetRegionCount();
+    const SfxDocumentTemplates* pTemplates = mpMgr->GetTemplates();
+
+    sal_uInt16 nCount = pTemplates->GetRegionCount();
     for (sal_uInt16 i = 0; i < nCount; ++i)
     {
-        rtl::OUString aRegionName(mpMgr->GetTemplates()->GetFullRegionName(i));
+        rtl::OUString aRegionName(pTemplates->GetFullRegionName(i));
 
         if (aRegionName == "My Templates")
         {
-            sal_uInt16 nEntries = mpMgr->GetTemplates()->GetCount(i);
+            sal_uInt16 nEntries = pTemplates->GetCount(i);
 
             for ( sal_uInt16 j = 0; j < nEntries; ++j)
-                maView.InsertItem(i,mpMgr->GetTemplates()->GetName(i,j),THUMBNAILVIEW_APPEND);
+            {
+                Image aImg = lcl_fetchThumbnail(pTemplates->GetPath(i,j));
+                maView.InsertItem(i,aImg,pTemplates->GetName(i,j));
+            }
 
             break;
         }
commit f19a58570f34888b17ec243f345ddeb5877c24aa
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Jun 5 21:43:51 2012 -0430

    Hide thumbnail view as default.
    
    Change-Id: Ied6d9b9e1ceb2605013273b6361770e97d2065da

diff --git a/sfx2/source/doc/templatedlg.src b/sfx2/source/doc/templatedlg.src
index f59e025..73ea0c7 100644
--- a/sfx2/source/doc/templatedlg.src
+++ b/sfx2/source/doc/templatedlg.src
@@ -17,6 +17,7 @@ ModalDialog DLG_TEMPLATE_MANAGER
     SVLook = TRUE;
     Moveable = TRUE;
     Closeable = TRUE;
+    Hide = TRUE;
     Size = MAP_APPFONT ( 270 , 190 );
     Text [en-US] = "Template Manager";
 
commit 87bbe2b6c906357b8e05f9e89a2c91bc7f802014
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Jun 5 21:37:05 2012 -0430

    Display filesystem templates under My Templates folder.
    
    Change-Id: I9d504d62392b30a7eca2be9be5330e6118967a1a

diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index 1317381..0af1cb7 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -15,6 +15,8 @@
 #include <vcl/dialog.hxx>
 #include <vcl/button.hxx>
 
+class SfxOrganizeMgr;
+
 class SfxTemplateManagerDlg : public ModalDialog
 {
 public:
@@ -38,6 +40,8 @@ private:
     PushButton aButtonDraws;
 
     ThumbnailView maView;
+
+    SfxOrganizeMgr *mpMgr;
 };
 
 #endif // TEMPLATEDLG_HXX
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 18cad11..e6393dc 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -7,13 +7,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "templatedlg.hxx"
+
+#include <sfx2/doctempl.hxx>
 #include <sfx2/sfxresid.hxx>
 
-#include "templatedlg.hxx"
+#include "orgmgr.hxx"
 
 #include "doc.hrc"
 #include "templatedlg.hrc"
 
+#define MAX_COLUMN_COUNT 4
+#define MAX_LINE_COUNT 2
+
 SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     : ModalDialog(parent, SfxResId(DLG_TEMPLATE_MANAGER)),
       aButtonAll(this,SfxResId(BTN_SELECT_ALL)),
@@ -21,11 +27,34 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
       aButtonPresents(this,SfxResId(BTN_SELECT_PRESENTATIONS)),
       aButtonSheets(this,SfxResId(BTN_SELECT_SHEETS)),
       aButtonDraws(this,SfxResId(BTN_SELECT_DRAWS)),
-      maView(this,SfxResId(TEMPLATE_VIEW))
+      maView(this,SfxResId(TEMPLATE_VIEW)),
+      mpMgr(new SfxOrganizeMgr(NULL,NULL))
 {
+    maView.SetStyle(WB_RADIOSEL | WB_TABSTOP);
+    maView.SetColCount(MAX_COLUMN_COUNT);
+    maView.SetLineCount(MAX_LINE_COUNT);
+
     aButtonAll.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewAllHdl));
     aButtonDocs.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewDocsHdl));
 
+    sal_uInt16 nCount = mpMgr->GetTemplates()->GetRegionCount();
+    for (sal_uInt16 i = 0; i < nCount; ++i)
+    {
+        rtl::OUString aRegionName(mpMgr->GetTemplates()->GetFullRegionName(i));
+
+        if (aRegionName == "My Templates")
+        {
+            sal_uInt16 nEntries = mpMgr->GetTemplates()->GetCount(i);
+
+            for ( sal_uInt16 j = 0; j < nEntries; ++j)
+                maView.InsertItem(i,mpMgr->GetTemplates()->GetName(i,j),THUMBNAILVIEW_APPEND);
+
+            break;
+        }
+    }
+
+    maView.Show();
+
     FreeResource();
 }
 
diff --git a/sfx2/source/doc/templatedlg.hrc b/sfx2/source/doc/templatedlg.hrc
index 78fe393..cd48687 100644
--- a/sfx2/source/doc/templatedlg.hrc
+++ b/sfx2/source/doc/templatedlg.hrc
@@ -13,3 +13,5 @@
 #define BTN_SELECT_DRAWS            5
 
 #define TEMPLATE_VIEW               6
+
+#define IMG_ONLINE_REPOSITORY       100
diff --git a/sfx2/source/doc/templatedlg.src b/sfx2/source/doc/templatedlg.src
index 3d73d11..f59e025 100644
--- a/sfx2/source/doc/templatedlg.src
+++ b/sfx2/source/doc/templatedlg.src
@@ -17,7 +17,7 @@ ModalDialog DLG_TEMPLATE_MANAGER
     SVLook = TRUE;
     Moveable = TRUE;
     Closeable = TRUE;
-    Size = MAP_APPFONT ( 270 , 165 );
+    Size = MAP_APPFONT ( 270 , 190 );
     Text [en-US] = "Template Manager";
 
     PushButton BTN_SELECT_ALL
@@ -64,7 +64,15 @@ ModalDialog DLG_TEMPLATE_MANAGER
     Control TEMPLATE_VIEW
     {
         Pos = MAP_APPFONT(5,30);
-        Size = MAP_APPFONT(50,260);
+        Size = MAP_APPFONT(260,150);
         TabStop = TRUE;
     };
+
+    Image IMG_ONLINE_REPOSITORY
+    {
+        ImageBitmap = Bitmap
+        {
+            File = "signet.png";
+        };
+    };
 };


More information about the Libreoffice-commits mailing list