tdf#130272 A warning is now shown and LO do not crash
Change-Id: Icd4ef637cb07c03c11aead53417bd48e47241203
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89415
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index 099174d..70b0619 100644
--- a/cui/inc/strings.hrc
+++ b/cui/inc/strings.hrc
@@ -400,6 +400,8 @@
#define RID_SVXSTR_COMMANDNAME NC_("RID_SVXSTR_COMMANDLABEL", "Command")
#define RID_SVXSTR_COMMANDTIP NC_("RID_SVXSTR_COMMANDLABEL", "Tooltip")
#define RID_SVXSTR_QRCODEDATALONG NC_("RID_SVXSTR_QRCODEDATALONG", "Text exceeds the maximum bits for Error Correction, Enter shorter text")
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/dialogs/QrCodeGenDialog.cxx b/cui/source/dialogs/QrCodeGenDialog.cxx
index 7daaee9..3be6aaf 100644
--- a/cui/source/dialogs/QrCodeGenDialog.cxx
+++ b/cui/source/dialogs/QrCodeGenDialog.cxx
@@ -11,9 +11,11 @@
#include <comphelper/processfactory.hxx>
#include <tools/stream.hxx>
#include <dialmgr.hxx>
#include <strings.hrc>
#include <unotools/streamwrap.hxx>
#include <utility>
#include <vcl/weld.hxx>
#include <vcl/svapp.hxx>
#if defined(SYSTEM_QRCODEGEN)
#include <qrcodegen/QrCode.hpp>
@@ -66,6 +68,7 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, Reference<XModel> xModel
m_xBuilder->weld_radio_button("button_quartile"),
m_xBuilder->weld_radio_button("button_high") }
, m_xSpinBorder(m_xBuilder->weld_spin_button("edit_border"))
, mpParent(pParent)
{
if (!bEditExisting)
{
@@ -101,9 +104,28 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, Reference<XModel> xModel
short QrCodeGenDialog::run()
{
short nRet = GenericDialogController::run();
if (nRet == RET_OK)
Apply();
short nRet;
while (true)
{
nRet = GenericDialogController::run();
if (nRet == RET_OK)
{
try
{
Apply();
break;
}
catch (qrcodegen::data_too_long)
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
mpParent, VclMessageType::Warning, VclButtonsType::Ok,
CuiResId(RID_SVXSTR_QRCODEDATALONG)));
xBox->run();
}
}
else
break;
}
return nRet;
}
@@ -266,12 +288,11 @@ OUString QrCodeGenDialog::GenerateQRCode(OUString aQRText, long aQRECC, int aQRB
OString o = OUStringToOString(aQRText, RTL_TEXTENCODING_UTF8);
const char* qrtext = o.pData->buffer;
//From Qr Code library.
// From QR Code library
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(qrtext, bqrEcc);
std::string svg = qr0.toSvgString(aQRBorder);
//cstring to OUString
char* cstr = &svg[0];
return OUString::createFromAscii(cstr);
return OUString::createFromAscii(svg.c_str());
#endif
}
diff --git a/cui/source/inc/QrCodeGenDialog.hxx b/cui/source/inc/QrCodeGenDialog.hxx
index a3ca38d..563182d 100644
--- a/cui/source/inc/QrCodeGenDialog.hxx
+++ b/cui/source/inc/QrCodeGenDialog.hxx
@@ -32,6 +32,7 @@ private:
std::unique_ptr<weld::Entry> m_xEdittext;
std::unique_ptr<weld::RadioButton> m_xECC[4];
std::unique_ptr<weld::SpinButton> m_xSpinBorder;
weld::Widget* mpParent;
css::uno::Reference<css::beans::XPropertySet> m_xExistingShapeProperties;