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
|
|
|
/*
|
2023-11-09 19:23:00 +01:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
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
|
|
|
|
2024-02-13 19:10:28 +01:00
|
|
|
#include <JsonUtil.hpp>
|
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
|
|
|
|
{
|
2021-01-25 16:55:45 +01:00
|
|
|
constexpr auto tunnelledDialogImageCacheSize = 100;
|
2021-01-21 13:39:10 +01:00
|
|
|
|
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);
|
2022-09-02 12:43:23 +02:00
|
|
|
const int part = loKitDocument->pClass->getPart(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
|
2022-09-02 12:43:23 +02:00
|
|
|
<< " current=" << part;
|
2016-05-08 05:27:15 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-09-02 12:43:23 +02:00
|
|
|
if (type == LOK_DOCTYPE_SPREADSHEET)
|
|
|
|
{
|
|
|
|
long lastColumn, lastRow;
|
|
|
|
loKitDocument->pClass->getDataArea(loKitDocument, part, &lastColumn, &lastRow);
|
|
|
|
oss << " lastcolumn=" << lastColumn
|
|
|
|
<< " lastrow=" << lastRow;
|
|
|
|
}
|
|
|
|
|
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;
|
2021-11-11 11:58:06 +01:00
|
|
|
std::ostringstream rtlposs;
|
2024-02-13 19:10:28 +01:00
|
|
|
std::ostringstream protectss;
|
2022-08-30 07:27:44 +02:00
|
|
|
std::string mode;
|
2018-09-16 23:32:56 +02:00
|
|
|
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
|
|
|
}
|
2021-11-11 11:58:06 +01:00
|
|
|
else if (name == "rtllayout")
|
|
|
|
{
|
|
|
|
if (prop.second == "1")
|
2022-01-12 07:09:13 +01:00
|
|
|
rtlposs << i << ',';
|
2021-11-11 11:58:06 +01:00
|
|
|
}
|
2024-02-13 19:10:28 +01:00
|
|
|
else if (name == "protected")
|
|
|
|
{
|
|
|
|
if (prop.second == "1")
|
|
|
|
protectss << i << ',';
|
|
|
|
}
|
2022-08-30 07:27:44 +02:00
|
|
|
else if (name == "mode" && mode.empty())
|
|
|
|
{
|
|
|
|
std::ostringstream modess;
|
|
|
|
modess << prop.second;
|
|
|
|
mode = modess.str();
|
|
|
|
}
|
2018-02-01 16:36:24 +01:00
|
|
|
}
|
2018-09-16 23:32:56 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 07:27:44 +02:00
|
|
|
if (!mode.empty())
|
|
|
|
oss << " mode=" << mode;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-11-11 11:58:06 +01:00
|
|
|
std::string rtlparts = rtlposs.str();
|
|
|
|
if (!rtlparts.empty())
|
|
|
|
{
|
|
|
|
rtlparts.pop_back(); // Remove last ','
|
|
|
|
oss << " rtlparts=" << rtlparts;
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:10:28 +01:00
|
|
|
std::string protectparts = protectss.str();
|
|
|
|
if (!protectparts.empty())
|
|
|
|
{
|
|
|
|
protectparts.pop_back(); // Remove last ','
|
|
|
|
oss << " protectedparts=" << protectparts;
|
|
|
|
}
|
|
|
|
|
2023-09-08 22:18:06 +02:00
|
|
|
if (type == LOK_DOCTYPE_SPREADSHEET)
|
|
|
|
{
|
|
|
|
char* values = loKitDocument->pClass->getCommandValues(loKitDocument, ".uno:ReadOnly");
|
|
|
|
if (values)
|
|
|
|
{
|
2023-09-26 17:41:39 +02:00
|
|
|
const std::string isReadOnly = std::string(values);
|
2023-09-08 22:18:06 +02:00
|
|
|
oss << " readonly=" << (isReadOnly.find("true") != std::string::npos);
|
|
|
|
std::free(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-07-23 16:13:26 +02:00
|
|
|
if (type == LOK_DOCTYPE_TEXT)
|
|
|
|
{
|
|
|
|
std::string rectangles = loKitDocument->pClass->getPartPageRectangles(loKitDocument);
|
|
|
|
|
|
|
|
std::string::iterator end_pos = std::remove(rectangles.begin(), rectangles.end(), ' ');
|
|
|
|
rectangles.erase(end_pos, rectangles.end());
|
|
|
|
|
|
|
|
oss << " pagerectangles=" << rectangles.c_str();
|
|
|
|
}
|
|
|
|
|
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: */
|