diff options
Diffstat (limited to 'cui/source/dialogs/AdditionsDialog.cxx')
-rw-r--r-- | cui/source/dialogs/AdditionsDialog.cxx | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx index ec173740bc63..4d39ad937664 100644 --- a/cui/source/dialogs/AdditionsDialog.cxx +++ b/cui/source/dialogs/AdditionsDialog.cxx @@ -12,7 +12,6 @@ #include <algorithm> #include <cmath> -#include <string_view> #include <config_folders.h> @@ -30,7 +29,7 @@ #include <rtl/bootstrap.hxx> #include <tools/urlobj.hxx> #include <tools/stream.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <comphelper/processfactory.hxx> #include <vcl/virdev.hxx> #include <vcl/svapp.hxx> @@ -55,18 +54,14 @@ #include <orcus/json_parser.hpp> #include <orcus/config.hpp> +#include <bitmaps.hlst> + #define PAGE_SIZE 30 using namespace css; using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::XComponentContext; -using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::uno::Exception; -using ::com::sun::star::graphic::GraphicProvider; -using ::com::sun::star::graphic::XGraphicProvider; using ::com::sun::star::uno::Sequence; -using ::com::sun::star::beans::PropertyValue; -using ::com::sun::star::graphic::XGraphic; using namespace com::sun::star; using namespace ::com::sun::star::uno; @@ -135,7 +130,7 @@ void parseResponse(const std::string& rResponse, std::vector<AdditionInfo>& aAdd { aJsonDoc.load(rResponse, aConfig); } - catch (const orcus::json::parse_error&) + catch (const orcus::parse_error&) { TOOLS_WARN_EXCEPTION("cui.dialogs", "Invalid JSON file from the extensions API"); return; @@ -230,7 +225,7 @@ bool getPreviewFile(const AdditionInfo& aAdditionInfo, OUString& sPreviewFile) return true; } -void LoadImage(const OUString& rPreviewFile, std::shared_ptr<AdditionsItem> pCurrentItem) +void LoadImage(std::u16string_view rPreviewFile, std::shared_ptr<AdditionsItem> pCurrentItem) { const sal_Int8 Margin = 6; @@ -280,6 +275,11 @@ SearchAndParseThread::SearchAndParseThread(AdditionsDialog* pDialog, const bool , m_bExecute(true) , m_bIsFirstLoading(isFirstLoading) { + // if we are running a UITest, e.g. UITest_sw_options then + // don't attempt to downloading anything + static const bool bUITest = getenv("LIBO_TEST_UNIT"); + + m_bUITest = bUITest; } SearchAndParseThread::~SearchAndParseThread() {} @@ -289,7 +289,8 @@ void SearchAndParseThread::Append(AdditionInfo& additionInfo) if (!m_bExecute) return; OUString aPreviewFile; - bool bResult = getPreviewFile(additionInfo, aPreviewFile); // info vector json data + bool bResult + = !m_bUITest && getPreviewFile(additionInfo, aPreviewFile); // info vector json data if (!bResult) { @@ -382,7 +383,7 @@ void SearchAndParseThread::CheckInstalledExtensions() SolarMutexGuard aGuard; rInfo->m_xButtonInstall->set_sensitive(false); rInfo->m_xButtonInstall->set_label( - CuiResId(RID_SVXSTR_ADDITIONS_INSTALLEDBUTTON)); + CuiResId(RID_CUISTR_ADDITIONS_INSTALLEDBUTTON)); } } } @@ -394,16 +395,16 @@ void SearchAndParseThread::execute() { OUString sProgress; if (m_bIsFirstLoading) - sProgress = CuiResId(RID_SVXSTR_ADDITIONS_LOADING); + sProgress = CuiResId(RID_CUISTR_ADDITIONS_LOADING); else - sProgress = CuiResId(RID_SVXSTR_ADDITIONS_SEARCHING); + sProgress = CuiResId(RID_CUISTR_ADDITIONS_SEARCHING); m_pAdditionsDialog->SetProgress( sProgress); // Loading or searching according to being first call or not if (m_bIsFirstLoading) { - std::string sResponse = ucbGet(m_pAdditionsDialog->m_sURL); + std::string sResponse = !m_bUITest ? ucbGet(m_pAdditionsDialog->m_sURL) : ""; parseResponse(sResponse, m_pAdditionsDialog->m_aAllExtensionsVector); std::sort(m_pAdditionsDialog->m_aAllExtensionsVector.begin(), m_pAdditionsDialog->m_aAllExtensionsVector.end(), @@ -428,7 +429,6 @@ AdditionsDialog::AdditionsDialog(weld::Window* pParent, const OUString& sAdditio , m_aSearchDataTimer("AdditionsDialog SearchDataTimer") , m_xEntrySearch(m_xBuilder->weld_entry("entrySearch")) , m_xButtonClose(m_xBuilder->weld_button("buttonClose")) - , m_xMenuButtonSettings(m_xBuilder->weld_menu_button("buttonGear")) , m_xContentWindow(m_xBuilder->weld_scrolled_window("contentWindow")) , m_xContentGrid(m_xBuilder->weld_container("contentGrid")) , m_xLabelProgress(m_xBuilder->weld_label("labelProgress")) @@ -448,19 +448,43 @@ AdditionsDialog::AdditionsDialog(weld::Window* pParent, const OUString& sAdditio m_nMaxItemCount = PAGE_SIZE; // Dialog initialization item count m_nCurrentListItemCount = 0; // First, there is no item on the list. - OUString titlePrefix = CuiResId(RID_SVXSTR_ADDITIONS_DIALOG_TITLE_PREFIX); + OUString titlePrefix = CuiResId(RID_CUISTR_ADDITIONS_DIALOG_TITLE_PREFIX); if (!m_sTag.isEmpty()) - { - this->set_title(titlePrefix + ": " + sAdditionsTag); + { // tdf#142564 localize extension category names + OUString sDialogTitle = ""; + if (sAdditionsTag == "Templates") + { + sDialogTitle = CuiResId(RID_CUISTR_ADDITIONS_TEMPLATES); + } + else if (sAdditionsTag == "Dictionary") + { + sDialogTitle = CuiResId(RID_CUISTR_ADDITIONS_DICTIONARY); + } + else if (sAdditionsTag == "Gallery") + { + sDialogTitle = CuiResId(RID_CUISTR_ADDITIONS_GALLERY); + } + else if (sAdditionsTag == "Icons") + { + sDialogTitle = CuiResId(RID_CUISTR_ADDITIONS_ICONS); + } + else if (sAdditionsTag == "Color Palette") + { + sDialogTitle = CuiResId(RID_CUISTR_ADDITIONS_PALETTES); + } + this->set_title(sDialogTitle); } else { this->set_title(titlePrefix); m_sTag = "allextensions"; // Means empty parameter } + + OUString sEncodedURLPart = INetURLObject::encode(m_sTag, INetURLObject::PART_PCHAR, + INetURLObject::EncodeMechanism::All); + //FIXME: Temporary URL - v0 is not using actual api - OUString rURL = "https://extensions.libreoffice.org/api/v0/" + m_sTag + ".json"; - m_sURL = rURL; + m_sURL = "https://extensions.libreoffice.org/api/v0/" + sEncodedURLPart + ".json"; m_xExtensionManager = deployment::ExtensionManager::get(::comphelper::getProcessComponentContext()); @@ -580,19 +604,15 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial , m_xLinkButtonWebsite(m_xBuilder->weld_link_button("btnWebsite")) , m_xLabelName(m_xBuilder->weld_label("lbName")) , m_xLabelAuthor(m_xBuilder->weld_label("labelAuthor")) - , m_xLabelDesc(m_xBuilder->weld_label("labelDesc")) // no change (print description) , m_xLabelDescription(m_xBuilder->weld_label("labelDescription")) , m_xLabelLicense(m_xBuilder->weld_label("lbLicenseText")) , m_xLabelVersion(m_xBuilder->weld_label("lbVersionText")) - , m_xLabelComments(m_xBuilder->weld_label("labelComments")) // no change , m_xLinkButtonComments(m_xBuilder->weld_link_button("linkButtonComments")) , m_xImageVoting1(m_xBuilder->weld_image("imageVoting1")) , m_xImageVoting2(m_xBuilder->weld_image("imageVoting2")) , m_xImageVoting3(m_xBuilder->weld_image("imageVoting3")) , m_xImageVoting4(m_xBuilder->weld_image("imageVoting4")) , m_xImageVoting5(m_xBuilder->weld_image("imageVoting5")) - , m_xLabelNoVoting(m_xBuilder->weld_label("votingLabel")) - , m_xImageDownloadNumber(m_xBuilder->weld_image("imageDownloadNumber")) , m_xLabelDownloadNumber(m_xBuilder->weld_label("labelDownloadNumber")) , m_xButtonShowMore(m_xBuilder->weld_button("buttonShowMore")) , m_pParentDialog(pParentDialog) @@ -611,8 +631,8 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial if (additionInfo.sName.getLength() > maxExtensionNameLength) { - OUString sShortName = additionInfo.sName.copy(0, maxExtensionNameLength - 3); - sExtensionName = sShortName + "..."; + std::u16string_view sShortName = additionInfo.sName.subView(0, maxExtensionNameLength - 3); + sExtensionName = OUString::Concat(sShortName) + "..."; } else { @@ -625,19 +645,19 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial switch (std::isnan(aExtensionRating) ? 0 : int(std::clamp(aExtensionRating, 0.0, 5.0))) { case 5: - m_xImageVoting5->set_from_icon_name("cmd/sc_stars-full.png"); + m_xImageVoting5->set_from_icon_name(RID_SVXBMP_STARS_FULL); [[fallthrough]]; case 4: - m_xImageVoting4->set_from_icon_name("cmd/sc_stars-full.png"); + m_xImageVoting4->set_from_icon_name(RID_SVXBMP_STARS_FULL); [[fallthrough]]; case 3: - m_xImageVoting3->set_from_icon_name("cmd/sc_stars-full.png"); + m_xImageVoting3->set_from_icon_name(RID_SVXBMP_STARS_FULL); [[fallthrough]]; case 2: - m_xImageVoting2->set_from_icon_name("cmd/sc_stars-full.png"); + m_xImageVoting2->set_from_icon_name(RID_SVXBMP_STARS_FULL); [[fallthrough]]; case 1: - m_xImageVoting1->set_from_icon_name("cmd/sc_stars-full.png"); + m_xImageVoting1->set_from_icon_name(RID_SVXBMP_STARS_FULL); break; } @@ -647,7 +667,7 @@ AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDial if (!additionInfo.sAuthorName.equalsIgnoreAsciiCase("null")) m_xLabelAuthor->set_label(additionInfo.sAuthorName); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xLabelLicense->set_label(additionInfo.sLicense); m_xLabelVersion->set_label(">=" + additionInfo.sCompatibleVersion); m_xLinkButtonComments->set_label(additionInfo.sCommentNumber); @@ -725,14 +745,14 @@ IMPL_LINK_NOARG(AdditionsItem, ShowMoreHdl, weld::Button&, void) IMPL_LINK_NOARG(AdditionsItem, InstallHdl, weld::Button&, void) { - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLING)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLING)); m_xButtonInstall->set_sensitive(false); OUString aExtensionFile; bool bResult = getExtensionFile(aExtensionFile); // info vector json data if (!bResult) { - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); SAL_INFO("cui.dialogs", "Couldn't get the extension file."); @@ -745,36 +765,36 @@ IMPL_LINK_NOARG(AdditionsItem, InstallHdl, weld::Button&, void) { m_pParentDialog->m_xExtensionManager->addExtension( aExtensionFile, uno::Sequence<beans::NamedValue>(), "user", xAbortChannel, pCmdEnv); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLEDBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLEDBUTTON)); } catch (const ucb::CommandFailedException) { TOOLS_WARN_EXCEPTION("cui.dialogs", ""); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); } catch (const ucb::CommandAbortedException) { TOOLS_WARN_EXCEPTION("cui.dialogs", ""); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); } catch (const deployment::DeploymentException) { TOOLS_WARN_EXCEPTION("cui.dialogs", ""); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); } catch (const lang::IllegalArgumentException) { TOOLS_WARN_EXCEPTION("cui.dialogs", ""); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); } catch (const css::uno::Exception) { TOOLS_WARN_EXCEPTION("cui.dialogs", ""); - m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON)); + m_xButtonInstall->set_label(CuiResId(RID_CUISTR_ADDITIONS_INSTALLBUTTON)); m_xButtonInstall->set_sensitive(true); } } @@ -827,7 +847,7 @@ void TmpRepositoryCommandEnv::update(uno::Any const& /*Status */) {} void TmpRepositoryCommandEnv::pop() {} -IMPL_LINK(AdditionsDialog, GearHdl, const OString&, rIdent, void) +IMPL_LINK(AdditionsDialog, GearHdl, const OUString&, rIdent, void) { if (rIdent == "gear_sort_voting") { |