From 565891c0441488bf4b169ddee1474478bdaa5fbc Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Sat, 13 Apr 2013 16:37:50 +0200 Subject: Initial reading and parsing from webservice. Change-Id: I1637f8a8b21464e3883fd3dc8f6bb214dd58f6d0 --- 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(-) diff --git a/sd/CppunitTest_sd_uimpress.mk b/sd/CppunitTest_sd_uimpress.mk index 01883f38821a..23e5500b29e7 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 d4800bd66a94..e7ac01b6de65 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 9a586a457ee7..522b317007c1 100644 --- a/sd/source/core/slidehack.cxx +++ b/sd/source/core/slidehack.cxx @@ -9,6 +9,13 @@ #include "slidehack.hxx" +#include +#include + +#include + +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 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 res(new boost::property_tree::ptree); + std::istringstream stream(buffer); + boost::property_tree::read_json(stream, *res); + + return res; + } + + return boost::shared_ptr(); +} + class StoreImpl : public Store { + std::vector m_userList; + std::vector 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 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 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 d433467b8f53..59dd875e3a56 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; } -- cgit