Bug 66131 - kviewerpart exits ungracefully when requested viewer is not installed
Summary: kviewerpart exits ungracefully when requested viewer is not installed
Status: RESOLVED FIXED
Alias: None
Product: kviewerpart
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR crash
Target Milestone: ---
Assignee: Matthias Hoelzer-Kluepfel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-16 21:13 UTC by Jeroen Wijnhout
Modified: 2005-05-11 20:24 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeroen Wijnhout 2003-10-16 21:13:19 UTC
Version:           unknown (using KDE 3.1.3)
Installed from:    SuSE
Compiler:          gcc version 3.2
OS:          Linux (i686) release 2.4.20-athlon

Hi,

KViewerPart cause a crash in the app that loads the kviewerpart
library if the requested viewerpart (e.g. dvi, pdf) is not installed.

I have the following code to load the DVI viewer part (using kviewpart) in 
Kile:

KLibFactory *dvifactory;
dvifactory = KLibLoader::self()->factory("kviewerpart");
if (!dvifactory)    
{
      KMessageBox::error(this, i18n("blabla"));
      return;
}
dvipart =(KParts::ReadOnlyPart *)dvifactory->create(topWidgetStack, 
"kviewerpart", "KViewPart", "dvi");

However if the kviewpart library is present, but the dvi part isn't, kviewpart 
crashes and drags Kile along with it. 

The problem is in KViewPart::KViewPart(). If the requested library does not 
exist, it calls ::exit(-1). Is there any way I can prevent this to happen? I 
mean there should be a graceful exit and a change for Kile to deal with the 
problem.

best,
Jeroen
Comment 1 Waldo Bastian 2004-02-12 13:26:12 UTC
CVS commit by waba: 

Don't exit when we can't load part. (BR66131)
Please report back if this fixes BR66131 so it can be added to KDE_3_2_BRANCH as well.
CCMAIL: 66131@bugs.kde.org


  M +14 -7     kviewpart.cpp   1.89
  M +2 -0      kviewpart.h   1.43


--- kdegraphics/kviewshell/kviewpart.cpp  #1.88:1.89
@@ -75,5 +75,10 @@ KParts::Part *KViewPartFactory::createPa
   if (args.count() >= 1)
     partname = args[0];
-  KParts::Part *obj = new KViewPart(partname, parentWidget, widgetName, parent, name);
+  KViewPart *obj = new KViewPart(partname, parentWidget, widgetName, parent, name);
+  if (!obj->isValid())
+  {
+     delete obj;
+     return 0;
+  }
   return obj;
 }
@@ -89,5 +94,5 @@ KInstance *KViewPartFactory::instance()
 
 KViewPart::KViewPart(QString partname, QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name)
-  : KViewPart_Iface(parent, name), _partname(partname), _numberOfPages(0),
+  : KViewPart_Iface(parent, name), _partname(partname), multiPage(0), _numberOfPages(0),
   _currentPage(0)
 {
@@ -137,7 +142,9 @@ KViewPart::KViewPart(QString partname, Q
     multiPage = (KMultiPage*) factory->create(mainWidget, QString("k%1").arg(_partname).utf8(), "KPart");
   } else {
-    KMessageBox::error(mainWidget, i18n("No module (%1) found").arg(_partname));
-    ::exit(-1);
+    KMessageBox::error(parentWidget, i18n("No module (%1) found").arg(_partname));
   }
+  if (!multiPage)
+     return; // Abort
+  
   hbox->addWidget(multiPage->widget());
 
@@ -272,7 +279,7 @@ KViewPart::KViewPart(QString partname, Q
 KViewPart::~KViewPart()
 {
+  if (multiPage)
   writeSettings();
   delete multiPage;
-  if ( tmpUnzipped != 0L ) 
     delete tmpUnzipped;
 }

--- kdegraphics/kviewshell/kviewpart.h  #1.42:1.43
@@ -53,4 +53,6 @@ public:
   virtual ~KViewPart();
 
+  bool isValid() { return multiPage; }
+
   // Returns a description of the current page size, for use in the
   // statusbar of the kviewshell that embeds this KViewPart.


Comment 2 Jeroen Wijnhout 2004-02-12 20:02:38 UTC
Thanks for the patch! It indeed fixes this bug. I've tested it against the KDE_3_2_BRANCH, so it is safe to apply it there as well.

AFAIC you can close this bug.

best,
Jeroen
Comment 3 Jeroen Wijnhout 2004-02-25 19:30:43 UTC
Why isn't the patch backported yet? I could do it for you if you want, just give me a go-ahead.

best,
Jeroen
Comment 4 Matthias H 2004-02-25 19:48:31 UTC
Yes, please, feel free to backport the patch.

Bye,
Matthias.
Comment 5 Jeroen Wijnhout 2004-02-25 20:00:53 UTC
Done.

best,
Jeroen
Comment 6 Jeroen Wijnhout 2005-05-11 20:16:49 UTC
The bug is back again, can you please fix it before KDE 3.4.1 is out?

best,
Jeroen
Comment 7 Jeroen Wijnhout 2005-05-11 20:23:37 UTC
Oops, reopened wrong bug, terribly sorry about that!
Comment 8 Jeroen Wijnhout 2005-05-11 20:24:29 UTC
Oops, reopened wrong bug, terribly sorry about that!