From 873d0332f8b671781f23c97ade04bfa15acf04cd Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 7 May 2024 10:41:12 +0300 Subject: [PATCH] [win-linux] add use of provider list --- win-linux/defaults.pri | 2 + .../src/cascapplicationmanagerwrapper.cpp | 3 +- .../cascapplicationmanagerwrapper_private.h | 1 + win-linux/src/casctabdata.cpp | 8 +- win-linux/src/casctabdata.h | 2 + win-linux/src/ceditortools.cpp | 1 + win-linux/src/components/asctabwidget.h | 1 + win-linux/src/cproviders.cpp | 108 ++++++++++++++++++ win-linux/src/cproviders.h | 57 +++++++++ 9 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 win-linux/src/cproviders.cpp create mode 100644 win-linux/src/cproviders.h diff --git a/win-linux/defaults.pri b/win-linux/defaults.pri index 4e5aa89e7..2fe8ffb78 100644 --- a/win-linux/defaults.pri +++ b/win-linux/defaults.pri @@ -97,6 +97,7 @@ HEADERS += \ $$PWD/src/clogger.h \ $$PWD/src/clangater.h \ $$PWD/src/cprintdata.h \ + $$PWD/src/cproviders.h \ $$PWD/src/cscalingwrapper.h \ $$PWD/src/ctabundockevent.h \ $$PWD/src/ccefeventsgate.h \ @@ -135,6 +136,7 @@ SOURCES += \ $$PWD/src/clogger.cpp \ $$PWD/src/clangater.cpp \ $$PWD/src/cprintdata.cpp \ + $$PWD/src/cproviders.cpp \ $$PWD/src/cscalingwrapper.cpp \ $$PWD/src/ctabundockevent.cpp \ $$PWD/src/ccefeventsgate.cpp \ diff --git a/win-linux/src/cascapplicationmanagerwrapper.cpp b/win-linux/src/cascapplicationmanagerwrapper.cpp index 099d041e1..868147b69 100644 --- a/win-linux/src/cascapplicationmanagerwrapper.cpp +++ b/win-linux/src/cascapplicationmanagerwrapper.cpp @@ -27,6 +27,7 @@ #include "ceditortools.h" #include "cfilechecker.h" #include "OfficeFileFormats.h" +#include "cproviders.h" #ifdef _WIN32 # include @@ -259,7 +260,7 @@ bool CAscApplicationManagerWrapper::processCommonEvent(NSEditorApi::CAscCefMenuE return false; } else if ( cmd.compare(L"provider:list") == 0 ) { - qDebug() << "provider:list" << pData->get_Param(); + CProviders::instance().init(QString::fromStdWString(pData->get_Param())); } else if ( cmd.compare(L"portal:login") == 0 ) { AscAppManager::sendCommandTo(SEND_TO_ALL_START_PAGE, L"portal:login", pData->get_Param()); diff --git a/win-linux/src/cascapplicationmanagerwrapper_private.h b/win-linux/src/cascapplicationmanagerwrapper_private.h index 597330a8a..140bba8ea 100644 --- a/win-linux/src/cascapplicationmanagerwrapper_private.h +++ b/win-linux/src/cascapplicationmanagerwrapper_private.h @@ -177,6 +177,7 @@ public: opts.format = objRoot["type"].toInt(); opts.parent_id = event.m_nSenderId; opts.name = objRoot["name"].toString(); + opts.cloud = objRoot["cloud"].toString(); QRegularExpression re(rePortalName); QRegularExpressionMatch match = re.match(opts.url); diff --git a/win-linux/src/casctabdata.cpp b/win-linux/src/casctabdata.cpp index 099ea2d03..13fcc3518 100644 --- a/win-linux/src/casctabdata.cpp +++ b/win-linux/src/casctabdata.cpp @@ -31,6 +31,7 @@ */ #include "casctabdata.h" +#include "cproviders.h" #include #include @@ -129,6 +130,11 @@ void CAscTabData::setUrl(const QString& u) setUrl(u.toStdWString()); } +void CAscTabData::setCloudName(const QString &cloud) +{ + _cloud = cloud; +} + wstring CAscTabData::url() const { return _url; @@ -235,7 +241,7 @@ bool CAscTabData::hasFeature(const wstring& f) const bool CAscTabData::hasFrame() const { - return hasFeature(L"hasframe\":true"); + return CProviders::instance().editorsHasFrame(QString::fromStdWString(_url), _cloud); } bool CAscTabData::hasError() const diff --git a/win-linux/src/casctabdata.h b/win-linux/src/casctabdata.h index 0dc16f9f8..511fd278f 100644 --- a/win-linux/src/casctabdata.h +++ b/win-linux/src/casctabdata.h @@ -51,6 +51,7 @@ public: void setIsLocal(bool); void setUrl(const std::wstring&); void setUrl(const QString&); + void setCloudName(const QString&); void close(); void reuse(); QString title(bool orig = false) const; @@ -85,6 +86,7 @@ private: bool _event_load_supported = false; std::wstring _features; QString _str_readonly; + QString _cloud; AscEditorType _typeContent; }; diff --git a/win-linux/src/ceditortools.cpp b/win-linux/src/ceditortools.cpp index b8bf0d539..9c9381bfc 100644 --- a/win-linux/src/ceditortools.cpp +++ b/win-linux/src/ceditortools.cpp @@ -319,6 +319,7 @@ namespace CEditorTools if ( result ) { CAscTabData * data = new CAscTabData(opts.name); data->setUrl(opts.wurl); + data->setCloudName(opts.cloud); data->setIsLocal( opts.srctype == etLocalFile || opts.srctype == etNewFile || opts.srctype == etTemplateFile || (opts.srctype == etRecentFile && !CExistanceController::isFileRemote(opts.url)) ); diff --git a/win-linux/src/components/asctabwidget.h b/win-linux/src/components/asctabwidget.h index bd56310d8..dc9b15c87 100644 --- a/win-linux/src/components/asctabwidget.h +++ b/win-linux/src/components/asctabwidget.h @@ -77,6 +77,7 @@ struct COpenOptions { enum class eWidgetType {window, tab}; eWidgetType parent_widget = eWidgetType::tab; + QString cloud; }; class CAscTabWidget : public QStackedWidget, public CScalingWrapper diff --git a/win-linux/src/cproviders.cpp b/win-linux/src/cproviders.cpp new file mode 100644 index 000000000..255669eef --- /dev/null +++ b/win-linux/src/cproviders.cpp @@ -0,0 +1,108 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * +*/ + +#include "cproviders.h" +#include +#include +#include +#include +#include +#include + + +struct ProviderData { + QString provider, editorPage; + bool hasFrame = false, + useRegex = false; +}; + +class CProviders::CProvidersPrivate +{ +public: + QVector m_provid_vec; +}; + +CProviders::CProviders() : + pimpl(new CProvidersPrivate) +{} + +CProviders::~CProviders() +{ + delete pimpl, pimpl = nullptr; +} + +CProviders& CProviders::instance() +{ + static CProviders inst; + return inst; +} + +void CProviders::init(const QString &prvds_json) +{ + QJsonParseError err; + QJsonDocument doc = QJsonDocument::fromJson(prvds_json.toUtf8(), &err); + if (err.error == QJsonParseError::NoError) { + const QJsonArray arr = doc.array(); + for (const auto &val : arr) { + QJsonObject obj = val.toObject(); + ProviderData pd; + pd.provider = obj["provider"].toString().toLower(); + pd.hasFrame = obj["editorFrameSize"].toString() == "finite"; + pd.editorPage = obj["editorPage"].toString(); + QString reg("regex:"); + int ind = pd.editorPage.indexOf(reg); + if (ind != -1) { + pd.useRegex = true; + pd.editorPage = pd.editorPage.mid(ind + reg.length()); + } + pimpl->m_provid_vec.push_back(std::move(pd)); + } + } +} + +bool CProviders::editorsHasFrame(const QString &url, const QString &cloud) +{ + foreach (const auto &pd, pimpl->m_provid_vec) { + if (!pd.provider.isEmpty() && pd.provider == cloud) + return pd.hasFrame; + if (!pd.editorPage.isEmpty()) { + if (pd.useRegex) { + QRegularExpression rgx(pd.editorPage, QRegularExpression::CaseInsensitiveOption); + if (rgx.match(url).hasMatch()) + return pd.hasFrame; + } else + if (url.indexOf(pd.editorPage) != -1) + return pd.hasFrame; + } + } + return false; +} diff --git a/win-linux/src/cproviders.h b/win-linux/src/cproviders.h new file mode 100644 index 000000000..9bb75c4db --- /dev/null +++ b/win-linux/src/cproviders.h @@ -0,0 +1,57 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * +*/ + +#ifndef CPROVIDERS_H +#define CPROVIDERS_H + +#include + + +class CProviders +{ +public: + CProviders(const CProviders&) = delete; + CProviders& operator=(const CProviders&) = delete; + static CProviders& instance(); + + void init(const QString &prvds_json); + bool editorsHasFrame(const QString &url, const QString &cloud); + +private: + CProviders(); + ~CProviders(); + + class CProvidersPrivate; + CProvidersPrivate *pimpl = nullptr; +}; + +#endif // CPROVIDERS_H