[Libreoffice-commits] core.git: Branch 'feature/slidehack' - sd/CppunitTest_sd_uimpress.mk sd/Library_sd.mk sd/source

Thorsten Behrens tbehrens at suse.com
Sat Apr 13 07:39:57 PDT 2013


 sd/CppunitTest_sd_uimpress.mk          |    1 
 sd/Library_sd.mk                       |    1 
 sd/source/core/slidehack.cxx           |   67 ++++++++++++++++++++++++++++++++-
 sd/source/ui/dlg/GroupSlidesDialog.cxx |    2 
 4 files changed, 69 insertions(+), 2 deletions(-)

New commits:
commit 565891c0441488bf4b169ddee1474478bdaa5fbc
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Sat Apr 13 16:37:50 2013 +0200

    Initial reading and parsing from webservice.
    
    Change-Id: I1637f8a8b21464e3883fd3dc8f6bb214dd58f6d0

diff --git a/sd/CppunitTest_sd_uimpress.mk b/sd/CppunitTest_sd_uimpress.mk
index 01883f3..23e5500 100644
--- a/sd/CppunitTest_sd_uimpress.mk
+++ b/sd/CppunitTest_sd_uimpress.mk
@@ -93,6 +93,7 @@ $(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\
 	boost_headers \
     gtk \
     dbus \
+    curl \
 ))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sd_uimpress,\
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index d4800bd..e7ac01b 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -112,6 +112,7 @@ $(eval $(call gb_Library_use_externals,sd,\
 	boost_headers \
 	libxml2 \
 	dbus \
+	curl \
 ))
 
 ifeq ($(OS),WNT)
diff --git a/sd/source/core/slidehack.cxx b/sd/source/core/slidehack.cxx
index 9a586a4..522b317 100644
--- a/sd/source/core/slidehack.cxx
+++ b/sd/source/core/slidehack.cxx
@@ -9,6 +9,13 @@
 
 #include "slidehack.hxx"
 
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/json_parser.hpp>
+
+#include <curl/curl.h>
+
+using boost::property_tree::ptree;
+
 namespace SlideHack {
 namespace {
 
@@ -37,10 +44,68 @@ public:
     }
 };
 
+static size_t read_function( void* data, size_t item_size, size_t num_members, void* user_data )
+{
+    if( num_members )
+    {
+        std::string* pBuffer=(std::string*)user_data;
+        pBuffer->append( (const char*)data, item_size*num_members );
+    }
+    return item_size * num_members;
+}
+
+static boost::shared_ptr<ptree> read_data( CURL* pCurl, const char* url)
+{
+    std::string buffer;
+    curl_easy_setopt( pCurl, CURLOPT_NOPROGRESS, 1 );
+    curl_easy_setopt( pCurl, CURLOPT_WRITEFUNCTION, read_function );
+    curl_easy_setopt( pCurl, CURLOPT_WRITEDATA, &buffer );
+    curl_easy_setopt( pCurl, CURLOPT_URL, url );
+    curl_easy_setopt( pCurl, CURLOPT_FOLLOWLOCATION, 1);
+    curl_easy_setopt( pCurl, CURLOPT_MAXREDIRS, 100);
+    curl_easy_setopt( pCurl, CURLOPT_SSL_VERIFYPEER, 0);
+    curl_easy_setopt( pCurl, CURLOPT_SSL_VERIFYHOST, 0);
+#if OSL_DEBUG_LEVEL > 2
+    curl_easy_setopt( pCurl, CURLOPT_VERBOSE, 0);
+#endif
+
+    if( !curl_easy_perform( pCurl ) )
+    {
+        boost::shared_ptr<ptree> res(new boost::property_tree::ptree);
+        std::istringstream stream(buffer);
+        boost::property_tree::read_json(stream, *res);
+
+        return res;
+    }
+
+    return boost::shared_ptr<ptree>();
+}
+
 class StoreImpl : public Store {
+    std::vector<OString> m_userList;
+    std::vector<OString> m_tagList;
+    CURL* m_pCurl;
+
 public:
-    StoreImpl()
+    StoreImpl() :
+        m_pCurl(NULL)
+    {
+        curl_global_init( CURL_GLOBAL_ALL );
+        m_pCurl = curl_easy_init( );
+
+        boost::shared_ptr<ptree> users = read_data( m_pCurl, "https://localhost:8080/api/users/" );
+        for( ptree::const_iterator i=users->begin(); i != users->end(); ++i )
+            m_userList.push_back( i->first.c_str() );
+
+        boost::shared_ptr<ptree> tags = read_data( m_pCurl, "https://localhost:8080/api/tags/" );
+        for( ptree::const_iterator i=tags->begin(); i != tags->end(); ++i )
+            m_tagList.push_back( i->first.c_str() );
+    }
+
+    ~StoreImpl()
     {
+        if ( NULL != m_pCurl )
+            curl_easy_cleanup( m_pCurl );
     }
 
     virtual sal_uInt32 search( OUString aSearchEntry )
diff --git a/sd/source/ui/dlg/GroupSlidesDialog.cxx b/sd/source/ui/dlg/GroupSlidesDialog.cxx
index d433467..59dd875 100644
--- a/sd/source/ui/dlg/GroupSlidesDialog.cxx
+++ b/sd/source/ui/dlg/GroupSlidesDialog.cxx
@@ -89,7 +89,7 @@ SdGroupSlidesDialog::~SdGroupSlidesDialog()
 IMPL_LINK_NOARG(SdGroupSlidesDialog, AddHdl)
 {
     SAL_DEBUG("Add to group");
-    EndDialog(0);
+    endDialog(true);
     return 0;
 }
 


More information about the Libreoffice-commits mailing list