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
This commit is contained in:
22shubh22 2020-02-25 14:47:29 +05:30 committed by Mike Kaganski
parent d54202ff69
commit 93fe47e113
3 changed files with 31 additions and 7 deletions

View file

@ -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: */

View file

@ -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
}

View file

@ -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;