[PATCH] konqueror crash recovery

Alexander Kellett kelletta at eidetica.com
Sat May 25 11:32:03 BST 2002


On Thu, May 16, 2002 at 12:42:13PM -0700, Waldo Bastian wrote:
> On Thursday 16 May 2002 11:04 am, Alexander Kellett wrote:
> > though i haven't done any real thorough tests as of yet,
> > do you see anything obviously wrong with the patch?
> 
> I don't see the file being flushed anywhere, so I was wondering whether 
> anything ended up on disk at all when you get a crash.

On Thu, May 16, 2002 at 08:01:57AM +0200, David Faure wrote:
> I have nightmares when I see QTextStream, remembering all the problems it gave us
> in the past - but maybe that's fixed in Qt 3. Anyway, opening the file raw and not
> using QTextStream sounds faster and safer to me, but maybe for no good reason.

With this new patch i've taken both of these into consideration
and settled on a flushing QDataStream. 

Still a number of small things to impove (header with version number)
and an abstraction into a KCrashBookmarkWriter in the KCrashBookmarkImporter.cc.
But those can be done later and they distract from the overall theme of 
the patch in any case.

How does this one look for commiting?

Alex

-------------- next part --------------
? crashlog.patch
? history/Makefile
? history/Makefile.in
? keditbookmarks/TODO
? keditbookmarks/tests
Index: KonquerorIface.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/KonquerorIface.cc,v
retrieving revision 1.27
diff -u -p -r1.27 KonquerorIface.cc
--- KonquerorIface.cc	2002/02/22 13:55:34	1.27
+++ KonquerorIface.cc	2002/05/25 10:28:03
@@ -173,6 +173,11 @@ void KonquerorIface::updateProfileList()
     it.current()->viewManager()->profileListDirty( false );
 }
 
+QString KonquerorIface::crashLogFile()
+{
+  return KonqMainWindow::s_crashlog_file->name();
+}
+
 QValueList<DCOPRef> KonquerorIface::getWindows()
 {
     QValueList<DCOPRef> lst;
Index: KonquerorIface.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/KonquerorIface.h,v
retrieving revision 1.24
diff -u -p -r1.24 KonquerorIface.h
--- KonquerorIface.h	2002/02/22 13:55:34	1.24
+++ KonquerorIface.h	2002/05/25 10:28:03
@@ -37,6 +37,7 @@ public:
   ~KonquerorIface();
 
 k_dcop:
+
   /**
    * Opens a new window for the given @p url (using createSimpleWindow, i.e. a single view)
    */
@@ -130,6 +131,11 @@ k_dcop:
    * Called by kcontrol when the global configuration changes
    */
   ASYNC reparseConfiguration();
+
+  /**
+   * @return the name of the instance's crash log file
+   */
+  QString crashLogFile();
 
   /**
    * @return a list of references to all the windows
Index: konq_main.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_main.cc,v
retrieving revision 1.112
diff -u -p -r1.112 konq_main.cc
--- konq_main.cc	2002/05/09 06:47:21	1.112
+++ konq_main.cc	2002/05/25 10:28:03
@@ -23,6 +23,7 @@
 #include "konq_mainwindow.h"
 #include "KonquerorIface.h"
 
+#include <ktempfile.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
 #include <kdebug.h>
@@ -59,6 +60,13 @@ int main( int argc, char **argv )
 
   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
+  KTempFile crashlog_file(locateLocal("tmp", "konqueror-crashlog"), ".xml");
+
+  KonqMainWindow::s_crashlog_file = new QFile( crashlog_file.name() );
+  KonqMainWindow::s_crashlog_file->open( IO_WriteOnly );
+
+  KonqMainWindow::s_crashlog = new QDataStream( KonqMainWindow::s_crashlog_file );
+
   if ( kapp->isRestored() )
   {
     int n = 1;
@@ -135,6 +143,8 @@ int main( int argc, char **argv )
      if ( w->testWFlags( Qt::WDestructiveClose ) )
           delete w;
   }  
+
+  KonqMainWindow::s_crashlog_file->remove();
 
   return 0;
 }
Index: konq_mainwindow.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.cc,v
retrieving revision 1.1000
diff -u -p -r1.1000 konq_mainwindow.cc
--- konq_mainwindow.cc	2002/05/21 09:44:04	1.1000
+++ konq_mainwindow.cc	2002/05/25 10:28:08
@@ -93,6 +93,8 @@ template class QPtrList<KToggleAction>;
 QPtrList<KonqMainWindow> *KonqMainWindow::s_lstViews = 0;
 KConfig * KonqMainWindow::s_comboConfig = 0;
 KCompletion * KonqMainWindow::s_pCompletion = 0;
+QFile * KonqMainWindow::s_crashlog_file = 0;
+QDataStream * KonqMainWindow::s_crashlog = 0;
 
 KonqMainWindow::KonqMainWindow( const KURL &initialURL, bool openInitialURL, const char *name )
  : KParts::MainWindow( name, WDestructiveClose | WStyle_ContextHelp )
Index: konq_mainwindow.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.h,v
retrieving revision 1.356
diff -u -p -r1.356 konq_mainwindow.h
--- konq_mainwindow.h	2002/05/07 14:25:17	1.356
+++ konq_mainwindow.h	2002/05/25 10:28:08
@@ -25,6 +25,9 @@
 #include <qtimer.h>
 #include <qguardedptr.h>
 
+#include <qfile.h>
+#include <qtextstream.h>
+
 #include <kfileitem.h>
 #include <konq_openurlrequest.h>
 
@@ -636,6 +639,11 @@ private:
   bool m_urlCompletionStarted;
 
   bool m_bBackRightClick;
+
+public:
+
+  static QFile *s_crashlog_file;
+  static QDataStream *s_crashlog;
 };
 
 #endif
Index: konq_view.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.cc,v
retrieving revision 1.295
diff -u -p -r1.295 konq_view.cc
--- konq_view.cc	2002/05/07 15:13:59	1.295
+++ konq_view.cc	2002/05/25 10:28:09
@@ -19,6 +19,7 @@
 
 
 #include "konq_view.h"
+#include "kapplication.h"
 #include "KonqViewIface.h"
 #include "konq_frame.h"
 #include "konq_run.h"
@@ -65,6 +66,8 @@ KonqView::KonqView( KonqViewFactory &vie
   m_pPart = 0L;
   m_dcopObject = 0L;
 
+  m_randID = KApplication::random();
+
   m_service = service;
   m_partServiceOffers = partServiceOffers;
   m_appServiceOffers = appServiceOffers;
@@ -91,6 +94,17 @@ KonqView::~KonqView()
 {
   kdDebug(1202) << "KonqView::~KonqView : part = " << m_pPart << endl;
 
+  // AK - stupid code duplication, see below comment
+  if (KonqMainWindow::s_crashlog) {
+     QDataStream *s = KonqMainWindow::s_crashlog;
+     QString part_url = (m_pPart)?(m_pPart->url().url()):(QString::null);
+     // opcode 1 == closed
+     (*s) << (Q_INT32)1;
+     (*s) << m_randID;
+     (*s) << part_url; // closed
+     KonqMainWindow::s_crashlog_file->flush();
+  }
+
   // We did so ourselves for passive views
   if (m_pPart != 0L)
   {
@@ -108,6 +122,20 @@ void KonqView::openURL( const KURL &url,
 {
   kdDebug(1202) << "KonqView::openURL url=" << url.url() << " locationBarURL=" << locationBarURL << endl;
   setServiceTypeInExtension();
+
+  // TODO - AK - could be abstracted to prevent duplication here 
+  //             & in destructor & in the importer
+  if (KonqMainWindow::s_crashlog) {
+     QDataStream *s = KonqMainWindow::s_crashlog;
+     QString part_url = (m_pPart)?(m_pPart->url().url()):(QString::null);
+     // format = opcode, id, 
+     // opcode 0 == closed, opened
+     (*s) << (Q_INT32)0;
+     (*s) << m_randID;
+     (*s) << part_url; // closed
+     (*s) << url.url(); // opened
+     KonqMainWindow::s_crashlog_file->flush();
+  }
 
   KParts::BrowserExtension *ext = browserExtension();
   KParts::URLArgs args;
Index: konq_view.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_view.h,v
retrieving revision 1.149
diff -u -p -r1.149 konq_view.h
--- konq_view.h	2002/05/07 14:25:17	1.149
+++ konq_view.h	2002/05/25 10:28:09
@@ -387,6 +387,7 @@ protected:
   KonqViewIface * m_dcopObject;
   KonqBrowserInterface *m_browserIface;
   bool m_bBackRightClick;
+  int m_randID;
 };
 
 #endif


More information about the kfm-devel mailing list