2015-04-13 04:09:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2015-03-28 06:22:15 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* 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 03:39:50 -05:00
|
|
|
#pragma once
|
2015-03-28 06:22:15 -05:00
|
|
|
|
2016-05-07 22:27:15 -05:00
|
|
|
#include <sstream>
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <string>
|
2015-03-28 06:22:15 -05:00
|
|
|
|
2018-02-01 09:36:24 -06:00
|
|
|
#include <Util.hpp>
|
|
|
|
|
2015-03-28 06:22:15 -05:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
|
|
|
|
namespace LOKitHelper
|
|
|
|
{
|
2016-10-29 20:15:00 -05:00
|
|
|
inline std::string documentTypeToString(LibreOfficeKitDocumentType type)
|
2015-03-28 06:22:15 -05: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-29 20:15:00 -05:00
|
|
|
inline std::string getDocumentTypeAsString(LibreOfficeKitDocument *loKitDocument)
|
2016-05-10 07:52:11 -05:00
|
|
|
{
|
|
|
|
assert(loKitDocument && "null loKitDocument");
|
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
return documentTypeToString(type);
|
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
inline std::string documentStatus(LibreOfficeKitDocument *loKitDocument)
|
2015-03-28 06:22:15 -05:00
|
|
|
{
|
2016-10-29 20:15:00 -05:00
|
|
|
char *ptrValue;
|
2016-05-10 07:52:11 -05:00
|
|
|
assert(loKitDocument && "null loKitDocument");
|
2016-05-07 22:27:15 -05:00
|
|
|
const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
|
|
|
|
|
2018-02-07 03:17:28 -06:00
|
|
|
const int parts = loKitDocument->pClass->getParts(loKitDocument);
|
2016-05-07 22:27:15 -05:00
|
|
|
std::ostringstream oss;
|
2016-05-08 08:04:25 -05:00
|
|
|
oss << "type=" << documentTypeToString(type)
|
2016-05-07 22:27:15 -05:00
|
|
|
<< " parts=" << parts
|
|
|
|
<< " current=" << loKitDocument->pClass->getPart(loKitDocument);
|
|
|
|
|
|
|
|
long width, height;
|
2015-03-28 06:22:15 -05:00
|
|
|
loKitDocument->pClass->getDocumentSize(loKitDocument, &width, &height);
|
2016-05-07 22:27:15 -05:00
|
|
|
oss << " width=" << width
|
2016-07-26 07:03:46 -05:00
|
|
|
<< " height=" << height
|
|
|
|
<< " viewid=" << loKitDocument->pClass->getView(loKitDocument);
|
2016-05-07 22:27:15 -05:00
|
|
|
|
|
|
|
if (type == LOK_DOCTYPE_SPREADSHEET || type == LOK_DOCTYPE_PRESENTATION)
|
2015-11-24 02:41:59 -06:00
|
|
|
{
|
2018-09-16 16:32:56 -05:00
|
|
|
std::ostringstream hposs;
|
|
|
|
std::ostringstream sposs;
|
|
|
|
for (int i = 0; i < parts; ++i)
|
2018-02-01 09:36:24 -06:00
|
|
|
{
|
2018-09-16 16:32:56 -05: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 09:36:24 -06:00
|
|
|
{
|
2018-09-16 16:32:56 -05:00
|
|
|
const std::string& name = prop.first;
|
|
|
|
if (name == "visible")
|
2018-02-01 09:36:24 -06:00
|
|
|
{
|
2018-09-16 16:32:56 -05:00
|
|
|
if (prop.second == "0")
|
|
|
|
hposs << i << ',';
|
|
|
|
}
|
|
|
|
else if (name == "selected")
|
|
|
|
{
|
|
|
|
if (prop.second == "1")
|
|
|
|
sposs << i << ',';
|
2018-02-01 09:36:24 -06:00
|
|
|
}
|
|
|
|
}
|
2018-09-16 16:32:56 -05: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 09:36:24 -06:00
|
|
|
}
|
|
|
|
|
2018-02-07 03:17:28 -06:00
|
|
|
for (int i = 0; i < parts; ++i)
|
2015-11-24 02:41:59 -06:00
|
|
|
{
|
2016-05-07 22:27:15 -05:00
|
|
|
oss << "\n";
|
2016-05-30 19:17:08 -05:00
|
|
|
ptrValue = loKitDocument->pClass->getPartName(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == LOK_DOCTYPE_PRESENTATION)
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
for (int i = 0; i < parts; ++i)
|
2016-05-07 22:27:15 -05:00
|
|
|
{
|
2016-05-30 19:17:08 -05:00
|
|
|
oss << "\n";
|
2016-05-24 23:32:00 -05:00
|
|
|
ptrValue = loKitDocument->pClass->getPartHash(loKitDocument, i);
|
|
|
|
oss << ptrValue;
|
|
|
|
std::free(ptrValue);
|
2016-05-07 22:27:15 -05:00
|
|
|
}
|
2015-07-15 10:31:52 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-07 22:27:15 -05:00
|
|
|
|
|
|
|
return oss.str();
|
2015-03-28 06:22:15 -05:00
|
|
|
}
|
2018-06-10 21:30:42 -05:00
|
|
|
}
|
2015-03-28 06:22:15 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|