tdf#133026: Additions: Install Button Handler

Change-Id: If4e9b192557b6c9f56bd04ccf9f6a5a8273d7515
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100340
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
This commit is contained in:
Yusuf Keten
2020-08-13 14:24:04 +02:00
committed by Muhammet Kara
parent 96b3de39bc
commit d21f802d91
2 changed files with 99 additions and 103 deletions
+63 -47
View File
@@ -14,7 +14,6 @@
#include <rtl/ustrbuf.hxx>
#include <unordered_set>
#include <sal/log.hxx>
#include <strings.hrc>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/inspection/PropertyLineElement.hpp>
@@ -29,8 +28,6 @@
#include <tools/urlobj.hxx>
#include <tools/stream.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <dialmgr.hxx>
#include <vcl/virdev.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
@@ -293,7 +290,7 @@ bool getPreviewFile(const AdditionInfo& aAdditionInfo, OUString& sPreviewFile)
return true;
}
void LoadImage(const OUString& rPreviewFile, const AdditionsItem& rCurrentItem)
void LoadImage(const OUString& rPreviewFile, std::shared_ptr<AdditionsItem> pCurrentItem)
{
SolarMutexGuard aGuard;
@@ -306,11 +303,11 @@ void LoadImage(const OUString& rPreviewFile, const AdditionsItem& rCurrentItem)
aFilter.ImportGraphic(aGraphic, aURLObj);
BitmapEx aBmp = aGraphic.GetBitmapEx();
ScopedVclPtr<VirtualDevice> xVirDev = rCurrentItem.m_xImageScreenshot->create_virtual_device();
ScopedVclPtr<VirtualDevice> xVirDev = pCurrentItem->m_xImageScreenshot->create_virtual_device();
xVirDev->SetOutputSizePixel(aBmp.GetSizePixel());
xVirDev->DrawBitmapEx(Point(0, 0), aBmp);
rCurrentItem.m_xImageScreenshot->set_image(xVirDev.get());
pCurrentItem->m_xImageScreenshot->set_image(xVirDev.get());
xVirDev.disposeAndClear();
}
@@ -326,32 +323,7 @@ SearchAndParseThread::SearchAndParseThread(AdditionsDialog* pDialog, const bool&
SearchAndParseThread::~SearchAndParseThread() {}
void SearchAndParseThread::LoadInfo(const AdditionInfo& additionInfo, AdditionsItem& rCurrentItem)
{
SolarMutexGuard aGuard;
rCurrentItem.m_xContainer->set_grid_left_attach(0);
rCurrentItem.m_xContainer->set_grid_top_attach(m_pAdditionsDialog->m_aAdditionsItems.size()
- 1);
rCurrentItem.m_xLinkButtonName->set_label(additionInfo.sName);
rCurrentItem.m_xLinkButtonName->set_uri(additionInfo.sExtensionURL);
rCurrentItem.m_xLabelDescription->set_label(additionInfo.sIntroduction);
rCurrentItem.m_xLabelAuthor->set_label(additionInfo.sAuthorName);
rCurrentItem.m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON));
OUString sLicenseString = CuiResId(RID_SVXSTR_ADDITIONS_LICENCE) + additionInfo.sLicense;
rCurrentItem.m_xLabelLicense->set_label(sLicenseString);
OUString sVersionString
= CuiResId(RID_SVXSTR_ADDITIONS_REQUIREDVERSION) + additionInfo.sCompatibleVersion;
rCurrentItem.m_xLabelVersion->set_label(sVersionString);
rCurrentItem.m_xLinkButtonComments->set_label(additionInfo.sCommentNumber);
rCurrentItem.m_xLinkButtonComments->set_uri(additionInfo.sCommentURL);
rCurrentItem.m_xLabelDownloadNumber->set_label(additionInfo.sDownloadNumber);
rCurrentItem.m_pParentDialog = m_pAdditionsDialog;
rCurrentItem.m_sDownloadURL = additionInfo.sDownloadURL;
}
void SearchAndParseThread::Append(const AdditionInfo& additionInfo)
void SearchAndParseThread::Append(AdditionInfo& additionInfo)
{
if (!m_bExecute)
return;
@@ -366,10 +338,11 @@ void SearchAndParseThread::Append(const AdditionInfo& additionInfo)
SolarMutexGuard aGuard;
m_pAdditionsDialog->m_aAdditionsItems.emplace_back(m_pAdditionsDialog->m_xContentGrid.get());
AdditionsItem& aCurrentItem = m_pAdditionsDialog->m_aAdditionsItems.back();
auto newItem = std::make_shared<AdditionsItem>(m_pAdditionsDialog->m_xContentGrid.get(),
m_pAdditionsDialog, additionInfo);
m_pAdditionsDialog->m_aAdditionsItems.push_back(newItem);
std::shared_ptr<AdditionsItem> aCurrentItem = m_pAdditionsDialog->m_aAdditionsItems.back();
LoadInfo(additionInfo, aCurrentItem);
LoadImage(aPreviewFile, aCurrentItem);
m_pAdditionsDialog->m_nCurrentListItemCount++;
@@ -377,15 +350,7 @@ void SearchAndParseThread::Append(const AdditionInfo& additionInfo)
{
if (m_pAdditionsDialog->m_nCurrentListItemCount
!= m_pAdditionsDialog->m_aAllExtensionsVector.size())
aCurrentItem.m_xButtonShowMore->set_visible(true);
}
}
void SearchAndParseThread::AppendAllExtensions()
{
for (auto& additionInfo : m_pAdditionsDialog->m_aAllExtensionsVector)
{
Append(additionInfo);
aCurrentItem->m_xButtonShowMore->set_visible(true);
}
}
@@ -445,7 +410,7 @@ void SearchAndParseThread::CheckInstalledExtensions()
for (auto& rInfo : m_pAdditionsDialog->m_aAdditionsItems)
{
OUString sExtensionDownloadURL = rInfo.m_sDownloadURL;
OUString sExtensionDownloadURL = rInfo->m_sDownloadURL;
if (!textSearch.searchForward(sExtensionDownloadURL))
{
@@ -453,7 +418,7 @@ void SearchAndParseThread::CheckInstalledExtensions()
}
else
{
rInfo.m_xButtonInstall->set_sensitive(false);
rInfo->m_xButtonInstall->set_sensitive(false);
}
}
}
@@ -604,11 +569,57 @@ void AdditionsDialog::ClearList()
for (auto& item : this->m_aAdditionsItems)
{
item.m_xContainer->hide();
item->m_xContainer->hide();
}
this->m_aAdditionsItems.clear();
}
AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDialog,
AdditionInfo& additionInfo)
: m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/additionsfragment.ui"))
, m_xContainer(m_xBuilder->weld_widget("additionsEntry"))
, m_xImageScreenshot(m_xBuilder->weld_image("imageScreenshot"))
, m_xButtonInstall(m_xBuilder->weld_button("buttonInstall"))
, m_xLinkButtonName(m_xBuilder->weld_link_button("linkButtonName"))
, 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("labelLicense"))
, m_xLabelVersion(m_xBuilder->weld_label("labelVersion"))
, m_xLabelComments(m_xBuilder->weld_label("labelComments")) // no change
, m_xLinkButtonComments(m_xBuilder->weld_link_button("linkButtonComments"))
, m_xImageVoting(m_xBuilder->weld_image("imageVoting"))
, m_xImageDownloadNumber(m_xBuilder->weld_image("imageDownloadNumber"))
, m_xLabelDownloadNumber(m_xBuilder->weld_label("labelDownloadNumber"))
, m_xButtonShowMore(m_xBuilder->weld_button("buttonShowMore"))
, m_pParentDialog(pParentDialog)
, m_sDownloadURL("")
{
SolarMutexGuard aGuard;
m_xContainer->set_grid_left_attach(0);
m_xContainer->set_grid_top_attach(pParentDialog->m_aAdditionsItems.size() - 1);
m_xLinkButtonName->set_label(additionInfo.sName);
m_xLinkButtonName->set_uri(additionInfo.sExtensionURL);
m_xLabelDescription->set_label(additionInfo.sIntroduction);
m_xLabelAuthor->set_label(additionInfo.sAuthorName);
m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTON));
OUString sLicenseString = CuiResId(RID_SVXSTR_ADDITIONS_LICENCE) + additionInfo.sLicense;
m_xLabelLicense->set_label(sLicenseString);
OUString sVersionString
= CuiResId(RID_SVXSTR_ADDITIONS_REQUIREDVERSION) + additionInfo.sCompatibleVersion;
m_xLabelVersion->set_label(sVersionString);
m_xLinkButtonComments->set_label(additionInfo.sCommentNumber);
m_xLinkButtonComments->set_uri(additionInfo.sCommentURL);
m_xLabelDownloadNumber->set_label(additionInfo.sDownloadNumber);
m_pParentDialog = pParentDialog;
m_sDownloadURL = additionInfo.sDownloadURL;
m_xButtonShowMore->connect_clicked(LINK(this, AdditionsItem, ShowMoreHdl));
m_xButtonInstall->connect_clicked(LINK(this, AdditionsItem, InstallHdl));
}
IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void)
{
if (m_pSearchThread.is())
@@ -651,4 +662,9 @@ IMPL_LINK_NOARG(AdditionsItem, ShowMoreHdl, weld::Button&, void)
m_pParentDialog->m_pSearchThread->launch();
}
IMPL_LINK_NOARG(AdditionsItem, InstallHdl, weld::Button&, void)
{
m_xButtonInstall->set_label("Success");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+36 -56
View File
@@ -14,6 +14,9 @@
#include <salhelper/thread.hxx>
#include <rtl/ref.hxx>
#include <vcl/weld.hxx>
#include <strings.hrc>
#include <comphelper/string.hxx>
#include "dialmgr.hxx"
// Detect changes on the UI
#include <vcl/timer.hxx>
@@ -28,53 +31,7 @@
class AdditionsDialog;
class SearchAndParseThread;
struct AdditionsItem
{
AdditionsItem(weld::Widget* pParent)
: m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/additionsfragment.ui"))
, m_xContainer(m_xBuilder->weld_widget("additionsEntry"))
, m_xImageScreenshot(m_xBuilder->weld_image("imageScreenshot"))
, m_xButtonInstall(m_xBuilder->weld_button("buttonInstall"))
, m_xLinkButtonName(m_xBuilder->weld_link_button("linkButtonName"))
, 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("labelLicense"))
, m_xLabelVersion(m_xBuilder->weld_label("labelVersion"))
, m_xLabelComments(m_xBuilder->weld_label("labelComments")) // no change
, m_xLinkButtonComments(m_xBuilder->weld_link_button("linkButtonComments"))
, m_xImageVoting(m_xBuilder->weld_image("imageVoting"))
, m_xImageDownloadNumber(m_xBuilder->weld_image("imageDownloadNumber"))
, m_xLabelDownloadNumber(m_xBuilder->weld_label("labelDownloadNumber"))
, m_xButtonShowMore(m_xBuilder->weld_button("buttonShowMore"))
, m_pParentDialog(nullptr)
, m_sDownloadURL("")
{
m_xButtonShowMore->connect_clicked(LINK(this, AdditionsItem, ShowMoreHdl));
}
DECL_LINK(ShowMoreHdl, weld::Button&, void);
std::unique_ptr<weld::Builder> m_xBuilder;
std::unique_ptr<weld::Widget> m_xContainer;
std::unique_ptr<weld::Image> m_xImageScreenshot;
std::unique_ptr<weld::Button> m_xButtonInstall;
std::unique_ptr<weld::LinkButton> m_xLinkButtonName;
std::unique_ptr<weld::Label> m_xLabelAuthor;
std::unique_ptr<weld::Label> m_xLabelDesc;
std::unique_ptr<weld::Label> m_xLabelDescription;
std::unique_ptr<weld::Label> m_xLabelLicense;
std::unique_ptr<weld::Label> m_xLabelVersion;
std::unique_ptr<weld::Label> m_xLabelComments;
std::unique_ptr<weld::LinkButton> m_xLinkButtonComments;
std::unique_ptr<weld::Image> m_xImageVoting;
std::unique_ptr<weld::Image> m_xImageDownloadNumber;
std::unique_ptr<weld::Label> m_xLabelDownloadNumber;
std::unique_ptr<weld::Button> m_xButtonShowMore;
AdditionsDialog* m_pParentDialog;
OUString m_sDownloadURL;
};
class AdditionsItem;
struct AdditionInfo
{
@@ -99,7 +56,6 @@ class AdditionsDialog : public weld::GenericDialogController
{
private:
Timer m_aSearchDataTimer;
css::uno::Reference<css::deployment::XExtensionManager> m_xExtensionManager;
DECL_LINK(SearchUpdateHdl, weld::Entry&, void);
@@ -111,8 +67,8 @@ public:
std::unique_ptr<weld::Entry> m_xEntrySearch;
std::unique_ptr<weld::Button> m_xButtonClose;
std::unique_ptr<weld::MenuButton> m_xMenuButtonSettings;
std::vector<AdditionsItem> m_aAdditionsItems; // UI components
std::vector<AdditionInfo> m_aAllExtensionsVector; //
std::vector<std::shared_ptr<AdditionsItem>> m_aAdditionsItems; // UI components
std::vector<AdditionInfo> m_aAllExtensionsVector; // Stores the all extensions' info
std::unique_ptr<weld::ScrolledWindow> m_xContentWindow;
std::unique_ptr<weld::Container> m_xContentGrid;
@@ -135,6 +91,35 @@ public:
void ClearList();
};
class AdditionsItem
{
public:
AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDialog,
AdditionInfo& additionInfo);
DECL_LINK(ShowMoreHdl, weld::Button&, void);
DECL_LINK(InstallHdl, weld::Button&, void);
std::unique_ptr<weld::Builder> m_xBuilder;
std::unique_ptr<weld::Widget> m_xContainer;
std::unique_ptr<weld::Image> m_xImageScreenshot;
std::unique_ptr<weld::Button> m_xButtonInstall;
std::unique_ptr<weld::LinkButton> m_xLinkButtonName;
std::unique_ptr<weld::Label> m_xLabelAuthor;
std::unique_ptr<weld::Label> m_xLabelDesc;
std::unique_ptr<weld::Label> m_xLabelDescription;
std::unique_ptr<weld::Label> m_xLabelLicense;
std::unique_ptr<weld::Label> m_xLabelVersion;
std::unique_ptr<weld::Label> m_xLabelComments;
std::unique_ptr<weld::LinkButton> m_xLinkButtonComments;
std::unique_ptr<weld::Image> m_xImageVoting;
std::unique_ptr<weld::Image> m_xImageDownloadNumber;
std::unique_ptr<weld::Label> m_xLabelDownloadNumber;
std::unique_ptr<weld::Button> m_xButtonShowMore;
AdditionsDialog* m_pParentDialog;
OUString m_sDownloadURL;
};
class SearchAndParseThread : public salhelper::Thread
{
private:
@@ -142,13 +127,8 @@ private:
std::atomic<bool> m_bExecute;
bool m_bIsFirstLoading;
void LoadInfo(const AdditionInfo& additionInfo, AdditionsItem& rCurrentItem);
void Search();
void Append(const AdditionInfo& additionInfo);
void AppendAllExtensions();
void Append(AdditionInfo& additionInfo);
void CheckInstalledExtensions();
virtual ~SearchAndParseThread() override;