Kaydet (Commit) a533f986 authored tarafından Andrzej Hunt's avatar Andrzej Hunt Kaydeden (comit) Michael Meeks

Upgrade LibreOfficeKit C++ API.

Change-Id: If263b8fc748f67a1ed423c0f3f7cd465cf533993
üst cd76b999
...@@ -18,18 +18,20 @@ ...@@ -18,18 +18,20 @@
* b) allow ABI stability - C++ vtables are not good for that. * b) allow ABI stability - C++ vtables are not good for that.
* c) avoid C++ types as part of the API. * c) avoid C++ types as part of the API.
*/ */
namespace lok
{
class LODocument class Document
{ {
private: private:
LibreOfficeKitDocument* mpDoc; LibreOfficeKitDocument* mpDoc;
public: public:
inline LODocument(LibreOfficeKitDocument* pDoc) : inline Document(LibreOfficeKitDocument* pDoc) :
mpDoc(pDoc) mpDoc(pDoc)
{} {}
inline ~LODocument() inline ~Document()
{ {
mpDoc->destroy(mpDoc); mpDoc->destroy(mpDoc);
} }
...@@ -50,17 +52,17 @@ public: ...@@ -50,17 +52,17 @@ public:
} }
}; };
class LibLibreOffice class Office
{ {
private: private:
LibreOfficeKit* mpThis; LibreOfficeKit* mpThis;
public: public:
inline LibLibreOffice(LibreOfficeKit* pThis) : inline Office(LibreOfficeKit* pThis) :
mpThis(pThis) mpThis(pThis)
{} {}
inline ~LibLibreOffice() inline ~Office()
{ {
mpThis->destroy(mpThis); mpThis->destroy(mpThis);
} }
...@@ -70,12 +72,12 @@ public: ...@@ -70,12 +72,12 @@ public:
return mpThis->initialize(mpThis, pInstallPath); return mpThis->initialize(mpThis, pInstallPath);
} }
inline LODocument* documentLoad(const char* pUrl) inline Document* documentLoad(const char* pUrl)
{ {
LibreOfficeKitDocument* pDoc = mpThis->documentLoad(mpThis, pUrl); LibreOfficeKitDocument* pDoc = mpThis->documentLoad(mpThis, pUrl);
if (pDoc == NULL) if (pDoc == NULL)
return NULL; return NULL;
return new LODocument(pDoc); return new Document(pDoc);
} }
// return the last error as a string, free me. // return the last error as a string, free me.
...@@ -85,12 +87,14 @@ public: ...@@ -85,12 +87,14 @@ public:
} }
}; };
inline LibLibreOffice* lo_cpp_init(const char* pInstallPath) }
inline ::lok::Office* lo_cpp_init(const char* pInstallPath)
{ {
LibreOfficeKit* pThis = lok_init(pInstallPath); LibreOfficeKit* pThis = lok_init(pInstallPath);
if (pThis == NULL || pThis->nSize == 0) if (pThis == NULL || pThis->nSize == 0)
return NULL; return NULL;
return new LibLibreOffice(pThis); return new ::lok::Office(pThis);
} }
#endif #endif
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <LibreOfficeKit/LibreOfficeKit.hxx> #include <LibreOfficeKit/LibreOfficeKit.hxx>
using namespace ::lok;
long getTimeMS() long getTimeMS()
{ {
struct timeval t; struct timeval t;
...@@ -44,7 +46,7 @@ int main (int argc, char **argv) ...@@ -44,7 +46,7 @@ int main (int argc, char **argv)
return 1; return 1;
} }
LibLibreOffice *pOffice = lo_cpp_init( argv[1] ); Office *pOffice = lo_cpp_init( argv[1] );
if( !pOffice ) if( !pOffice )
{ {
fprintf( stderr, "Failed to initialize\n" ); fprintf( stderr, "Failed to initialize\n" );
...@@ -63,7 +65,7 @@ int main (int argc, char **argv) ...@@ -63,7 +65,7 @@ int main (int argc, char **argv)
start = end; start = end;
fprintf( stderr, "start to load document '%s'\n", argv[2] ); fprintf( stderr, "start to load document '%s'\n", argv[2] );
LODocument *pDocument = pOffice->documentLoad( argv[2] ); Document *pDocument = pOffice->documentLoad( argv[2] );
if( !pDocument ) if( !pDocument )
{ {
char *pError = pOffice->getError(); char *pError = pOffice->getError();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment