2015-04-13 11:09:02 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-28 12:22:15 +01:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 10:39:50 +02:00
|
|
|
#pragma once
|
2015-03-28 12:22:15 +01:00
|
|
|
|
2016-05-08 05:27:15 +02:00
|
|
|
#include <sstream>
|
2016-10-30 02:15:00 +01:00
|
|
|
#include <string>
|
2015-03-28 12:22:15 +01:00
|
|
|
|
2018-02-01 16:36:24 +01:00
|
|
|
#include <Util.hpp>
|
|
|
|
|
2015-03-28 12:22:15 +01:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
|
|
|
|
namespace LOKitHelper
|
|
|
|
{
|
2016-10-30 02:15:00 +01:00
|
|
|
inline std::string documentTypeToString(LibreOfficeKitDocumentType type)
|
2015-03-28 12:22:15 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LOK_DOCTYPE_TEXT:
|
|
|
|
return "text";
|
|
|
|
case LOK_DOCTYPE_SPREADSHEET:
|
|
|
|
return "spreadsheet";
|
|
|
|
case LOK_DOCTYPE_PRESENTATION:
|
|
|
|
return "presentation";
|
|
|
|
case LOK_DOCTYPE_DRAWING:
|
|
|
|
return "drawing";
|
|
|
|
default:
|
|
|
|
return "other-" + std::to_string(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 02:15:00 +01:00
|
|
|
inline std::string getDocumentTypeAsString(LibreOfficeKitDocument *loKitDocument)
|
2016-05-10 14:52:11 +02:00
|
|
|
{
|
|
|
|
assert(loKitDocument && "null loKitDocument");
|
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
return documentTypeToString(type);
|
|
|
|
}
|
|
|
|
|
2016-10-30 02:15:00 +01:00
|
|
|
inline std::string documentStatus(LibreOfficeKitDocument *loKitDocument)
|
2015-03-28 12:22:15 +01:00
|
|
|
{
|
2016-10-30 02:15:00 +01:00
|
|
|
char *ptrValue;
|
2016-05-10 14:52:11 +02:00
|
|
|
assert(loKitDocument && "null loKitDocument");
|
2016-05-08 05:27:15 +02:00
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
|
2018-02-07 10:17:28 +01:00
|
|
|
const int parts = loKitDocument->pClass->getParts(loKitDocument);
|
2016-05-08 05:27:15 +02:00
|
|
|
std::ostringstream oss;
|
2016-05-08 15:04:25 +02:00
|
|
|
oss << "type=" << documentTypeToString(type)
|
2016-05-08 05:27:15 +02:00
|
|
|
<< " parts=" << parts
|
|
|
|
<< " current=" << loKitDocument->pClass->getPart(loKitDocument);
|
|
|
|
|
|
|
|
long width, height;
|
2015-03-28 12:22:15 +01:00
|
|
|
loKitDocument->pClass->getDocumentSize(loKitDocument, &width, &height);
|
2016-05-08 05:27:15 +02:00
|
|
|
oss << " width=" << width
|
2016-07-26 14:03:46 +02:00
|
|
|
<< " height=" << height
|
|
|
|
<< " viewid=" << loKitDocument->pClass->getView(loKitDocument);
|
2016-05-08 05:27:15 +02:00
|
|
|
|
2020-06-24 21:25:12 +02:00
|
|
|
if (type == LOK_DOCTYPE_SPREADSHEET || type == LOK_DOCTYPE_PRESENTATION || type == LOK_DOCTYPE_DRAWING)
|
2015-11-24 09:41:59 +01:00
|
|
|
{
|
2018-09-16 23:32:56 +02:00
|
|
|
std::ostringstream hposs;
|
|
|
|
std::ostringstream sposs;
|
|
|
|
for (int i = 0; i < parts; ++i)
|
2018-02-01 16:36:24 +01:00
|
|
|
{
|
2018-09-16 23:32:56 +02:00
|
|
|
ptrValue = loKitDocument->pClass->getPartInfo(loKitDocument, i);
|
|
|
|
const std::string partinfo(ptrValue);
|
|
|
|
std::free(ptrValue);
|
|
|
|
for (const auto& prop : Util::JsonToMap(partinfo))
|
2018-02-01 16:36:24 +01:00
|
|
|
{
|
2018-09-16 23:32:56 +02:00
|
|
|
const std::string& name = prop.first;
|
|
|
|
if (name == "visible")
|
2018-02-01 16:36:24 +01:00
|
|
|
{
|
2018-09-16 23:32:56 +02:00
|
|
|
if (prop.second == "0")
|
|
|
|
hposs << i << ',';
|
|
|
|
}
|
|
|
|
else if (name == "selected")
|
|
|
|
{
|
|
|
|
if (prop.second == "1")
|
|
|
|
sposs << i << ',';
|
2018-02-01 16:36:24 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-16 23:32:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string hiddenparts = hposs.str();
|
|
|
|
if (!hiddenparts.empty())
|
|
|
|
{
|
|
|
|
hiddenparts.pop_back(); // Remove last ','
|
|
|
|
oss << " hiddenparts=" << hiddenparts;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string selectedparts = sposs.str();
|
|
|
|
if (!selectedparts.empty())
|
|
|
|
{
|
|
|
|
selectedparts.pop_back(); // Remove last ','
|
|
|
|
oss << " selectedparts=" << selectedparts;
|
2018-02-01 16:36:24 +01:00
|
|
|
}
|
|
|
|
|
2018-02-07 10:17:28 +01:00
|
|
|
for (int i = 0; i < parts; ++i)
|
2015-11-24 09:41:59 +01:00
|
|
|
{
|
2020-05-24 15:10:18 +02:00
|
|
|
oss << '\n';
|
2016-05-31 02:17:08 +02:00
|
|
|
ptrValue = loKitDocument->pClass->getPartName(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
|
|
|
}
|
|
|
|
|
2020-06-24 21:25:12 +02:00
|
|
|
if (type == LOK_DOCTYPE_PRESENTATION || type == LOK_DOCTYPE_DRAWING)
|
2016-05-31 02:17:08 +02:00
|
|
|
{
|
2018-02-07 10:17:28 +01:00
|
|
|
for (int i = 0; i < parts; ++i)
|
2016-05-08 05:27:15 +02:00
|
|
|
{
|
2020-05-24 15:10:18 +02:00
|
|
|
oss << '\n';
|
2016-05-25 06:32:00 +02:00
|
|
|
ptrValue = loKitDocument->pClass->getPartHash(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
2016-05-08 05:27:15 +02:00
|
|
|
}
|
2015-07-15 17:31:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-08 05:27:15 +02:00
|
|
|
|
|
|
|
return oss.str();
|
2015-03-28 12:22:15 +01:00
|
|
|
}
|
2018-06-11 04:30:42 +02:00
|
|
|
}
|
2015-03-28 12:22:15 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|