[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kate
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2010-08-07 18:59:07
Message-ID: 20100807190020.CAF34AC7CA () svn ! kde ! org
[Download RAW message or body]

SVN commit 1160319 by cullmann:

dianat:
    Improve error handling. Warn the user if the swap file is broken.


 M  +2 -0      CMakeLists.txt  
 M  +1 -4      dialogs/katedialogs.cpp  
 A             swapfile/brokenswapfilewidget.ui  
 A             swapfile/katebrokenswapfilebar.cpp   [License: LGPL (v2+)]
 A             swapfile/katebrokenswapfilebar.h   [License: LGPL (v2+)]
 M  +31 -1     swapfile/kateswapfile.cpp  
 M  +1 -0      swapfile/kateswapfile.h  
 M  +1 -1      swapfile/recoverwidget.ui  
 M  +31 -0     view/kateview.cpp  
 M  +5 -0      view/kateview.h  


--- trunk/KDE/kdelibs/kate/CMakeLists.txt #1160318:1160319
@@ -171,6 +171,7 @@
 # swapfile
 swapfile/katerecoverbar.cpp
 swapfile/kateswapfile.cpp
+swapfile/katebrokenswapfilebar.cpp
 
 )
 
@@ -194,6 +195,7 @@
 dialogs/viinputmodeconfigwidget.ui
 dialogs/spellcheckconfigwidget.ui
 swapfile/recoverwidget.ui
+swapfile/brokenswapfilewidget.ui
 )
 
 add_definitions ( -DKDE_DEFAULT_DEBUG_AREA=13000 )
--- trunk/KDE/kdelibs/kate/dialogs/katedialogs.cpp #1160318:1160319
@@ -934,10 +934,7 @@
   KateDocumentConfig::global()->setBackupPrefix(uiadv->edtBackupPrefix->text());
   KateDocumentConfig::global()->setBackupSuffix(uiadv->edtBackupSuffix->text());
 
-  if ( uiadv->chkNoSync->isChecked() )
-    KateDocumentConfig::global()->setSwapFileNoSync(true);
-  else
-    KateDocumentConfig::global()->setSwapFileNoSync(false);
+  KateDocumentConfig::global()->setSwapFileNoSync(uiadv->chkNoSync->isChecked());
 
   KateDocumentConfig::global()->setSearchDirConfigDepth(uiadv->sbConfigFileSearchDepth->value());
  
--- trunk/KDE/kdelibs/kate/swapfile/kateswapfile.cpp #1160318:1160319
@@ -174,7 +174,11 @@
 
   // replay swapfile
   bool editStarted = false;
+  bool brokenSwapFile = false;
   while (!stream.atEnd()) {
+    if (brokenSwapFile)
+      break;
+
     qint8 type;
     stream >> type;
     switch (type) {
@@ -189,6 +193,11 @@
         break;
       }
       case EA_WrapLine: {
+        if (!editStarted) {
+          brokenSwapFile = true;
+          break;
+        }
+
         int line = 0, column = 0;
         stream >> line >> column;
         
@@ -197,6 +206,11 @@
         break;
       }
       case EA_UnwrapLine: {
+        if (!editStarted) {
+          brokenSwapFile = true;
+          break;
+        }
+
         int line = 0;
         stream >> line;
         
@@ -208,6 +222,11 @@
         break;
       }
       case EA_InsertText: {
+        if (!editStarted) {
+          brokenSwapFile = true;
+          break;
+        }
+
         int line, column;
         QByteArray text;
         stream >> line >> column >> text;
@@ -215,6 +234,11 @@
         break;
       }
       case EA_RemoveText: {
+        if (!editStarted) {
+          brokenSwapFile = true;
+          break;
+        }
+
         int line, startColumn, endColumn;
         stream >> line >> startColumn >> endColumn;
         m_document->removeText (KTextEditor::Range(KTextEditor::Cursor(line, \
startColumn), KTextEditor::Cursor(line, endColumn))); @@ -228,10 +252,16 @@
 
   // balance editStart and editEnd
   if (editStarted) {
-    kWarning ( 13020 ) << "Some data might be lost";
+    brokenSwapFile = true;
     m_document->editEnd();
   }
   
+  // warn the user if the swap file is not complete
+  if (brokenSwapFile) {
+    kWarning ( 13020 ) << "Some data might be lost";
+    emit swapFileBroken();
+  }
+  
   // reconnect the signals
   setTrackingEnabled(true);
   
--- trunk/KDE/kdelibs/kate/swapfile/kateswapfile.h #1160318:1160319
@@ -77,6 +77,7 @@
   Q_SIGNALS:
     void swapFileFound();
     void swapFileHandled();
+    void swapFileBroken();
   
   public Q_SLOTS:
     void discard();
--- trunk/KDE/kdelibs/kate/swapfile/recoverwidget.ui #1160318:1160319
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>741</width>
-    <height>112</height>
+    <height>122</height>
    </rect>
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout_2">
--- trunk/KDE/kdelibs/kate/view/kateview.cpp #1160318:1160319
@@ -60,6 +60,7 @@
 #include "script/katescriptaction.h"
 #include "kateswapfile.h"
 #include "katerecoverbar.h"
+#include "katebrokenswapfilebar.h"
 
 #include <kparts/event.h>
 
@@ -125,6 +126,7 @@
     , m_bottomViewBar (0)
     , m_topViewBar (0)
     , m_recoverBar(0)
+    , m_brokenSwapFileBar(0)
     , m_cmdLine (0)
     , m_searchBar (0)
     , m_viModeBar (0)
@@ -260,6 +262,7 @@
   }
   
   // swap file handling
+  connect (doc->swapFile(), SIGNAL(swapFileBroken()), this, \
SLOT(showBrokenSwapFileBar()));  connect (doc->swapFile(), SIGNAL(swapFileFound()), \
this, SLOT(showRecoverBar()));  connect (doc->swapFile(), SIGNAL(swapFileHandled()), \
this, SLOT(hideRecoverBar()));  if (doc->swapFile()->shouldRecover())
@@ -2905,6 +2908,8 @@
 
 void KateView::showRecoverBar()
 {
+  hideBrokenSwapFileBar();
+  
   topViewBar()->showBarWidget(recoverBar());
 }
 
@@ -2927,4 +2932,30 @@
   }
 }
 
+void KateView::showBrokenSwapFileBar()
+{
+  hideRecoverBar();
+  
+  topViewBar()->showBarWidget(brokenSwapFileBar());
+}
+
+KateBrokenSwapFileBar* KateView::brokenSwapFileBar()
+{
+  if (!m_brokenSwapFileBar) {
+    m_brokenSwapFileBar = new KateBrokenSwapFileBar(this);
+    topViewBar()->addBarWidget(m_brokenSwapFileBar);
+  }
+  return m_brokenSwapFileBar;
+}
+
+void KateView::hideBrokenSwapFileBar()
+{
+  if (m_brokenSwapFileBar)
+  {
+    topViewBar()->removeBarWidget(m_brokenSwapFileBar);
+    delete m_brokenSwapFileBar;
+    m_brokenSwapFileBar = 0;
+  }
+}
+
 // kate: space-indent on; indent-width 2; replace-tabs on;
--- trunk/KDE/kdelibs/kate/view/kateview.h #1160318:1160319
@@ -65,6 +65,7 @@
 class KateDictionaryBar;
 class KateSpellingMenu;
 class KateRecoverBar;
+class KateBrokenSwapFileBar;
 
 class KToggleAction;
 class KAction;
@@ -640,6 +641,7 @@
     KateViModeBar *viModeBar();
     KateGotoBar *gotoBar ();
     KateRecoverBar *recoverBar();
+    KateBrokenSwapFileBar *brokenSwapFileBar();
 
   /**
    * viewbar + its widgets
@@ -650,6 +652,7 @@
     KateViewBar *m_bottomViewBar;
     KateViewBar *m_topViewBar;
     KateRecoverBar* m_recoverBar;
+    KateBrokenSwapFileBar *m_brokenSwapFileBar;
     // created on demand..., only access them through the above accessors....
     KateCommandLineBar *m_cmdLine;
     KateSearchBar *m_searchBar;
@@ -702,11 +705,13 @@
   protected Q_SLOTS:
     void toggleOnTheFlySpellCheck(bool b);
     void showRecoverBar();
+    void showBrokenSwapFileBar();
 
   public Q_SLOTS:
     void changeDictionary();
     void reflectOnTheFlySpellCheckStatus(bool enabled);
     void hideRecoverBar();
+    void hideBrokenSwapFileBar();
 
   public:
     KateSpellingMenu* spellingMenu();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic