include/sfx2/opengrf.hxx             |    2 ++
 sc/source/ui/drawfunc/fuins1.cxx     |    9 +++++++++
 sd/inc/sdgrffilter.hxx               |    3 ++-
 sd/source/filter/grf/sdgrffilter.cxx |   12 +++++++-----
 sd/source/ui/func/fuinsert.cxx       |    7 ++++---
 sfx2/source/appl/opengrf.cxx         |   28 ++++++++++++++--------------
 6 files changed, 38 insertions(+), 23 deletions(-)

New commits:
commit 86e643a4c4a26401bee8b636f7068859ab7fc683
Author:     Pranam Lashkari <[email protected]>
AuthorDate: Fri Nov 28 21:55:06 2025 +0530
Commit:     Pranam Lashkari <[email protected]>
CommitDate: Tue Dec 2 11:05:58 2025 +0100

    LOK: show warning/error dialogs
    
    show error dialog when invalid images are inserted (calc, impress)
    
    part 2 of 70d8195a2b72440fe929e4e3761d1f1d5ace0096
    
    problem:
    when inserted and image in calc or impress, and image format is incorrect
    or not supported (i.e: .txt, .heic) then LOK did not get any failure 
messages
    
    Change-Id: I8af0cd5cf360574c116e6383ada170e32e317d12
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194801
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Pranam Lashkari <[email protected]>

diff --git a/include/sfx2/opengrf.hxx b/include/sfx2/opengrf.hxx
index 4546fbabc726..94fed4e4b52e 100644
--- a/include/sfx2/opengrf.hxx
+++ b/include/sfx2/opengrf.hxx
@@ -22,6 +22,7 @@
 #include <sfx2/dllapi.h>
 #include <rtl/ustring.hxx>
 #include <comphelper/errcode.hxx>
+#include <unotools/resmgr.hxx>
 
 namespace com::sun::star::ui::dialogs { class XFilePickerControlAccess; }
 namespace com::sun::star::uno { template <class interface_type> class 
Reference; }
@@ -58,6 +59,7 @@ public:
     void                    SetDetectedFilter(const OUString&);
 
     css::uno::Reference<css::ui::dialogs::XFilePickerControlAccess> const & 
GetFilePickerControlAccess() const;
+    static TranslateId SvxOpenGrfErr2ResId(ErrCode err);
 
 private:
     SvxOpenGraphicDialog    (const SvxOpenGraphicDialog&) = delete;
diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index d8eda3aba080..e5cad07b2c4a 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -25,6 +25,7 @@
 #include <sfx2/lokhelper.hxx>
 #include <sfx2/opengrf.hxx>
 #include <sfx2/viewfrm.hxx>
+#include <sfx2/sfxresid.hxx>
 #include <svx/svdograf.hxx>
 #include <svx/svdomedia.hxx>
 #include <svx/svdpage.hxx>
@@ -288,6 +289,14 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell&   
rViewSh,
         {
             lcl_InsertGraphic( aGraphic, aFileName, bAsLink, true, rViewSh, 
pWindow, pView );
         }
+        else
+        {
+            std::shared_ptr<weld::MessageDialog> 
xWarn(Application::CreateMessageDialog(
+                pWin->GetFrameWeld(), VclMessageType::Warning, 
VclButtonsType::Ok,
+                SfxResId(SvxOpenGraphicDialog::SvxOpenGrfErr2ResId(nError))));
+
+            xWarn->runAsync(xWarn, [](sal_uInt32) {});
+        }
     }
     else
     {
diff --git a/sd/inc/sdgrffilter.hxx b/sd/inc/sdgrffilter.hxx
index a90934dd6dea..32647a371870 100644
--- a/sd/inc/sdgrffilter.hxx
+++ b/sd/inc/sdgrffilter.hxx
@@ -33,7 +33,8 @@ public:
     bool Import();
     bool Export() override;
 
-    static void HandleGraphicFilterError(ErrCode nFilterError, ErrCode 
nStreamError);
+    static void HandleGraphicFilterError(ErrCode nFilterError, ErrCode 
nStreamError,
+                                         weld::Window* frameWeld = nullptr);
     static void InsertSdrGrafObj(const Graphic& rGraphic, SdPage* pPage);
 };
 
diff --git a/sd/source/filter/grf/sdgrffilter.cxx 
b/sd/source/filter/grf/sdgrffilter.cxx
index ea437dfb2ee0..10ad074709c4 100644
--- a/sd/source/filter/grf/sdgrffilter.cxx
+++ b/sd/source/filter/grf/sdgrffilter.cxx
@@ -103,7 +103,8 @@ SdGRFFilter::~SdGRFFilter()
 {
 }
 
-void SdGRFFilter::HandleGraphicFilterError( ErrCode nFilterError, ErrCode 
nStreamError )
+void SdGRFFilter::HandleGraphicFilterError(ErrCode nFilterError, ErrCode 
nStreamError,
+                                           weld::Window* frameWeld)
 {
     if (ERRCODE_NONE != nStreamError)
     {
@@ -130,11 +131,12 @@ void SdGRFFilter::HandleGraphicFilterError( ErrCode 
nFilterError, ErrCode nStrea
 
     if (pId && pId == STR_IMPORT_GRFILTER_IOERROR)
         ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
-    else
+    else if (frameWeld || !comphelper::LibreOfficeKit::isActive())
     {
-        std::unique_ptr<weld::MessageDialog> 
xErrorBox(Application::CreateMessageDialog(nullptr,
-                                                       
VclMessageType::Warning, VclButtonsType::Ok, pId ? SdResId(pId) : OUString()));
-        xErrorBox->run();
+        std::shared_ptr<weld::MessageDialog> xErrorBox(
+            Application::CreateMessageDialog(frameWeld, 
VclMessageType::Warning, VclButtonsType::Ok,
+                                             pId ? SdResId(pId) : OUString()));
+        xErrorBox->runAsync(xErrorBox, [](sal_uInt32) {});
     }
 }
 
diff --git a/sd/source/ui/func/fuinsert.cxx b/sd/source/ui/func/fuinsert.cxx
index fd26dc295c76..bf3aa29db630 100644
--- a/sd/source/ui/func/fuinsert.cxx
+++ b/sd/source/ui/func/fuinsert.cxx
@@ -186,10 +186,11 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq )
             }
         }
     }
-    else if (!comphelper::LibreOfficeKit::isActive())
+    else
     {
-        // TODO: enable in LOK, it contains synchronous error window without 
LOKNotifier
-        SdGRFFilter::HandleGraphicFilterError( nError, 
GraphicFilter::GetGraphicFilter().GetLastError() );
+        SdGRFFilter::HandleGraphicFilterError(nError,
+                                              
GraphicFilter::GetGraphicFilter().GetLastError(),
+                                              mpWindow ? 
mpWindow->GetFrameWeld() : nullptr);
     }
 }
 
diff --git a/sfx2/source/appl/opengrf.cxx b/sfx2/source/appl/opengrf.cxx
index 16e0731f310b..617f417f40f6 100644
--- a/sfx2/source/appl/opengrf.cxx
+++ b/sfx2/source/appl/opengrf.cxx
@@ -45,20 +45,6 @@ using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::ui::dialogs;
 using namespace ::com::sun::star::uno;
 
-static TranslateId SvxOpenGrfErr2ResId( ErrCode err )
-{
-    if (err == ERRCODE_GRFILTER_OPENERROR)
-        return RID_SVXSTR_GRFILTER_OPENERROR;
-    else if (err == ERRCODE_GRFILTER_IOERROR)
-        return RID_SVXSTR_GRFILTER_IOERROR;
-    else if (err == ERRCODE_GRFILTER_VERSIONERROR)
-        return RID_SVXSTR_GRFILTER_VERSIONERROR;
-    else if (err == ERRCODE_GRFILTER_FILTERERROR)
-        return RID_SVXSTR_GRFILTER_FILTERERROR;
-    else
-        return RID_SVXSTR_GRFILTER_FORMATERROR;
-}
-
 struct SvxOpenGrf_Impl
 {
     SvxOpenGrf_Impl(weld::Window* pPreferredParent,
@@ -277,6 +263,20 @@ void SvxOpenGraphicDialog::SetDetectedFilter(const 
OUString& rStr)
     mpImpl->sDetectedFilter = rStr;
 }
 
+TranslateId SvxOpenGraphicDialog::SvxOpenGrfErr2ResId(ErrCode err)
+{
+    if (err == ERRCODE_GRFILTER_OPENERROR)
+        return RID_SVXSTR_GRFILTER_OPENERROR;
+    else if (err == ERRCODE_GRFILTER_IOERROR)
+        return RID_SVXSTR_GRFILTER_IOERROR;
+    else if (err == ERRCODE_GRFILTER_VERSIONERROR)
+        return RID_SVXSTR_GRFILTER_VERSIONERROR;
+    else if (err == ERRCODE_GRFILTER_FILTERERROR)
+        return RID_SVXSTR_GRFILTER_FILTERERROR;
+    else
+        return RID_SVXSTR_GRFILTER_FORMATERROR;
+}
+
 Reference<ui::dialogs::XFilePickerControlAccess> const & 
SvxOpenGraphicDialog::GetFilePickerControlAccess() const
 {
     return mpImpl->xCtrlAcc;

Reply via email to