[Libreoffice-commits] .: svx/inc svx/source writerfilter/inc writerfilter/Library_rtftok.mk writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Jan 10 16:53:14 PST 2012


 svx/inc/svx/dialogs.hrc                           |    1 
 svx/source/stbctrls/stbctrls.src                  |    5 +++
 writerfilter/Library_rtftok.mk                    |    1 
 writerfilter/inc/rtftok/RTFDocument.hxx           |    4 ++
 writerfilter/source/filter/RtfFilter.cxx          |    8 +++++
 writerfilter/source/rtftok/rtfdocumentfactory.cxx |    5 ++-
 writerfilter/source/rtftok/rtfdocumentimpl.cxx    |    8 +++--
 writerfilter/source/rtftok/rtfdocumentimpl.hxx    |    4 ++
 writerfilter/source/rtftok/rtftokenizer.cxx       |   30 ++++++++++++++++++++--
 writerfilter/source/rtftok/rtftokenizer.hxx       |    3 +-
 10 files changed, 58 insertions(+), 11 deletions(-)

New commits:
commit 92c7b6733e55a6ab62bc231ecf0ffd5c0da7c8d2
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Tue Jan 10 18:53:55 2012 +0100

    fdo#38057 implement RTF import progressbar

diff --git a/svx/inc/svx/dialogs.hrc b/svx/inc/svx/dialogs.hrc
index a1038f1..4ef4ad1 100755
--- a/svx/inc/svx/dialogs.hrc
+++ b/svx/inc/svx/dialogs.hrc
@@ -1175,5 +1175,6 @@
 #define RID_SVXBMP_DOC_MODIFIED_FEEDBACK (SVX_OOO_BUILD_START + 3)
 #define RID_SVXSTR_DOC_MODIFIED_YES      (SVX_OOO_BUILD_START + 4)
 #define RID_SVXSTR_DOC_MODIFIED_NO       (SVX_OOO_BUILD_START + 5)
+#define RID_SVXSTR_DOC_LOAD              (SVX_OOO_BUILD_START + 6)
 
 #endif
diff --git a/svx/source/stbctrls/stbctrls.src b/svx/source/stbctrls/stbctrls.src
index c2e0999..dea916d 100644
--- a/svx/source/stbctrls/stbctrls.src
+++ b/svx/source/stbctrls/stbctrls.src
@@ -97,6 +97,11 @@ String RID_SVXSTR_DOC_MODIFIED_NO
     Text [ en-US ] = "The document has not been modified since the last save.";
 };
 
+String RID_SVXSTR_DOC_LOAD
+{
+    Text [ en-US ] = "Loading document...";
+};
+
  // PopupMenu -------------------------------------------------------------
 Menu RID_SVXMNU_ZOOM
 {
diff --git a/writerfilter/Library_rtftok.mk b/writerfilter/Library_rtftok.mk
index 9ee5cde..3835a5d 100644
--- a/writerfilter/Library_rtftok.mk
+++ b/writerfilter/Library_rtftok.mk
@@ -56,6 +56,7 @@ $(eval $(call gb_Library_add_linked_libs,rtftok,\
 	utl \
 	tl \
 	resourcemodel \
+	vcl \
 	$(gb_STDLIBS) \
 ))
 
diff --git a/writerfilter/inc/rtftok/RTFDocument.hxx b/writerfilter/inc/rtftok/RTFDocument.hxx
index 72fe6bd..15b94eb 100644
--- a/writerfilter/inc/rtftok/RTFDocument.hxx
+++ b/writerfilter/inc/rtftok/RTFDocument.hxx
@@ -33,6 +33,7 @@
 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
 
 namespace writerfilter {
     namespace rtftok {
@@ -62,7 +63,8 @@ namespace writerfilter {
                             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext,
                             ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > const & xInputStream,
                             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > const & xDstDoc,
-                            ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > const & xFrame);
+                            ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > const & xFrame,
+                            ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > const & xStatusIndicator);
         };
     } // namespace rtftok
 } // namespace writerfilter
diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx
index 0d0e929..2f549d0 100644
--- a/writerfilter/source/filter/RtfFilter.cxx
+++ b/writerfilter/source/filter/RtfFilter.cxx
@@ -35,6 +35,7 @@
 #include <dmapper/DomainMapper.hxx>
 #include <rtftok/RTFDocument.hxx>
 #include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
 
 using namespace ::rtl;
 using namespace ::cppu;
@@ -88,14 +89,19 @@ sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescri
         uno::Reference<frame::XFrame> xFrame = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_FRAME(),
                 uno::Reference<frame::XFrame>());
 
+        uno::Reference<task::XStatusIndicator> xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_STATUSINDICATOR(),
+                uno::Reference<task::XStatusIndicator>());
+
         writerfilter::Stream::Pointer_t pStream(
                 new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, writerfilter::dmapper::DOCUMENT_RTF));
         writerfilter::rtftok::RTFDocument::Pointer_t const pDocument(
-                writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, m_xDstDoc, xFrame));
+                writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, m_xDstDoc, xFrame, xStatusIndicator));
         pDocument->resolve(*pStream);
 #ifdef DEBUG_IMPORT
         dmapperLogger->endDocument();
 #endif
+        if (xStatusIndicator.is())
+            xStatusIndicator->end();
         return sal_True;
     }
     catch (const uno::Exception& e)
diff --git a/writerfilter/source/rtftok/rtfdocumentfactory.cxx b/writerfilter/source/rtftok/rtfdocumentfactory.cxx
index a397565..8e8868b 100644
--- a/writerfilter/source/rtftok/rtfdocumentfactory.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentfactory.cxx
@@ -33,9 +33,10 @@ namespace rtftok {
 RTFDocument::Pointer_t RTFDocumentFactory::createDocument(uno::Reference< uno::XComponentContext > const & xContext,
         uno::Reference< io::XInputStream > const & xInputStream,
         uno::Reference< lang::XComponent > const & xDstDoc,
-        uno::Reference< frame::XFrame > const & xFrame)
+        uno::Reference< frame::XFrame > const & xFrame,
+        uno::Reference< task::XStatusIndicator > const & xStatusIndicator)
 {
-    return RTFDocument::Pointer_t(new RTFDocumentImpl(xContext, xInputStream, xDstDoc, xFrame));
+    return RTFDocument::Pointer_t(new RTFDocumentImpl(xContext, xInputStream, xDstDoc, xFrame, xStatusIndicator));
 }
 
 } // namespace rtftok
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 143bd23..b799508 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -248,11 +248,13 @@ static util::DateTime lcl_getDateTime(std::stack<RTFParserState>& aStates)
 RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& xContext,
         uno::Reference<io::XInputStream> const& xInputStream,
         uno::Reference<lang::XComponent> const& xDstDoc,
-        uno::Reference<frame::XFrame>    const& xFrame)
+        uno::Reference<frame::XFrame>    const& xFrame,
+        uno::Reference<task::XStatusIndicator> const& xStatusIndicator)
     : m_xContext(xContext),
     m_xInputStream(xInputStream),
     m_xDstDoc(xDstDoc),
     m_xFrame(xFrame),
+    m_xStatusIndicator(xStatusIndicator),
     m_nGroup(0),
     m_aDefaultState(),
     m_bSkipUnknown(false),
@@ -303,7 +305,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
 
     m_pGraphicHelper.reset(new oox::GraphicHelper(m_xContext, xFrame, m_xStorage));
 
-    m_pTokenizer.reset(new RTFTokenizer(*this, m_pInStream.get()));
+    m_pTokenizer.reset(new RTFTokenizer(*this, m_pInStream.get(), m_xStatusIndicator));
     m_pSdrImport.reset(new RTFSdrImport(*this, m_xDstDoc));
 }
 
@@ -363,7 +365,7 @@ void RTFDocumentImpl::resolveSubstream(sal_uInt32 nPos, Id nId, OUString& rIgnor
 {
     sal_uInt32 nCurrent = Strm().Tell();
     // Seek to header position, parse, then seek back.
-    RTFDocumentImpl::Pointer_t pImpl(new RTFDocumentImpl(m_xContext, m_xInputStream, m_xDstDoc, m_xFrame));
+    RTFDocumentImpl::Pointer_t pImpl(new RTFDocumentImpl(m_xContext, m_xInputStream, m_xDstDoc, m_xFrame, m_xStatusIndicator));
     pImpl->setSubstream(true);
     pImpl->setIgnoreFirst(rIgnoreFirst);
     if (m_aAuthor.getLength())
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 5e6fc68..178cdb3 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -288,7 +288,8 @@ namespace writerfilter {
                 RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& xContext,
                                 uno::Reference<io::XInputStream> const& xInputStream,
                                 uno::Reference<lang::XComponent> const& xDstDoc,
-                                uno::Reference<frame::XFrame> const& xFrame);
+                                uno::Reference<frame::XFrame> const& xFrame,
+                                uno::Reference<task::XStatusIndicator> const& xStatusIndicator);
                 virtual ~RTFDocumentImpl();
                 virtual void resolve(Stream & rHandler);
                 virtual std::string getType() const;
@@ -351,6 +352,7 @@ namespace writerfilter {
                 uno::Reference<io::XInputStream> const& m_xInputStream;
                 uno::Reference<lang::XComponent> const& m_xDstDoc;
                 uno::Reference<frame::XFrame> const& m_xFrame;
+                uno::Reference<task::XStatusIndicator> const& m_xStatusIndicator;
                 uno::Reference<lang::XMultiServiceFactory> m_xModelFactory;
                 uno::Reference<document::XDocumentProperties> m_xDocumentProperties;
                 boost::shared_ptr<SvStream> m_pInStream;
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index e881ea1..415424b 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -26,6 +26,9 @@
  */
 
 #include <tools/stream.hxx>
+#include <tools/resmgr.hxx>
+#include <svx/dialogs.hrc>
+#include <vcl/svapp.hxx>
 
 #include <rtftokenizer.hxx>
 #include <rtfskipdestination.hxx>
@@ -39,9 +42,10 @@ using rtl::OUStringToOString;
 namespace writerfilter {
 namespace rtftok {
 
-RTFTokenizer::RTFTokenizer(RTFDocumentImpl& rImport, SvStream* pInStream)
+RTFTokenizer::RTFTokenizer(RTFDocumentImpl& rImport, SvStream* pInStream, uno::Reference<task::XStatusIndicator> const& xStatusIndicator)
     : m_rImport(rImport),
-    m_pInStream(pInStream)
+    m_pInStream(pInStream),
+    m_xStatusIndicator(xStatusIndicator)
 {
 }
 
@@ -61,10 +65,32 @@ int RTFTokenizer::resolveParse()
     int ret;
     // for hex chars
     int b = 0, count = 2;
+    sal_uInt32 nPercentSize;
+    sal_uInt32 nLastPos;
+
+    if (m_xStatusIndicator.is())
+    {
+        static ResMgr* pResMgr = ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILocale());
+        OUString sDocLoad(ResId::toString(ResId(RID_SVXSTR_DOC_LOAD, *pResMgr)));
+
+        sal_uInt32 nCurrentPos = Strm().Tell();
+        Strm().Seek(STREAM_SEEK_TO_END);
+        sal_uInt32 nEndPos = Strm().Tell();
+        Strm().Seek(nCurrentPos);
+        m_xStatusIndicator->start(sDocLoad, nEndPos);
+        nPercentSize = nEndPos / 100;
+
+        m_xStatusIndicator->setValue(nLastPos = nCurrentPos);
+    }
 
     while ((Strm() >> ch, !Strm().IsEof()))
     {
         //SAL_INFO("writerfilter", OSL_THIS_FUNC << ": parsing character '" << ch << "'");
+
+        sal_uInt32 nCurrentPos = Strm().Tell();
+        if (m_xStatusIndicator.is() && nCurrentPos > (nLastPos + nPercentSize))
+            m_xStatusIndicator->setValue(nLastPos = nCurrentPos);
+
         if (m_rImport.getGroup() < 0)
             return ERROR_GROUP_UNDER;
         if (!m_rImport.isEmpty() && m_rImport.getState().nInternalState == INTERNAL_BIN)
diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx
index 3556f9c..3b8dee0 100644
--- a/writerfilter/source/rtftok/rtftokenizer.hxx
+++ b/writerfilter/source/rtftok/rtftokenizer.hxx
@@ -38,7 +38,7 @@ namespace writerfilter {
         class RTFTokenizer
         {
             public:
-                RTFTokenizer(RTFDocumentImpl& rImport, SvStream* pInStream);
+                RTFTokenizer(RTFDocumentImpl& rImport, SvStream* pInStream, uno::Reference<task::XStatusIndicator> const& xStatusIndicator);
                 virtual ~RTFTokenizer();
 
                 int resolveParse();
@@ -50,6 +50,7 @@ namespace writerfilter {
 
                 RTFDocumentImpl& m_rImport;
                 SvStream* m_pInStream;
+                uno::Reference<task::XStatusIndicator> const& m_xStatusIndicator;
         };
     } // namespace rtftok
 } // namespace writerfilter


More information about the Libreoffice-commits mailing list