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

List:       kde-commits
Subject:    branches/KDE/3.5/kdewebdev/kommander/editor
From:       Andras Mantia <amantia () kde ! org>
Date:       2008-01-29 9:32:17
Message-ID: 1201599137.637365.26432.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 768069 by amantia:

Save the forms every 5 minutes and on run in a backup file.

 M  +2 -0      formfile.cpp  
 M  +33 -0     mainwindow.cpp  
 M  +4 -3      mainwindow.h  
 M  +14 -0     mainwindowactions.cpp  


--- branches/KDE/3.5/kdewebdev/kommander/editor/formfile.cpp #768068:768069
@@ -195,6 +195,8 @@
 
   emit removedFormFile(this);
   setModified(false);
+  QFile f(filename + ".backup");
+  f.remove();
   return true;
 }
 
--- branches/KDE/3.5/kdewebdev/kommander/editor/mainwindow.cpp #768068:768069
@@ -14,6 +14,7 @@
  Modified for Kommander:
   (C) 2002-2003 Marc Britton <consume@optusnet.com.au>
   (C) 2004      Michal Rudolf <mrudolf@kdewebdev.org>
+  (C) 2008      Andras Mantia <amantia@kde.org>
 
 **********************************************************************/
 
@@ -194,6 +195,9 @@
   statusBar()->setSizeGripEnabled(true);
   SpecialInformation::registerSpecials();
 
+  backupTimer = new QTimer(this);
+  connect(backupTimer, SIGNAL(timeout()), this, SLOT(slotCreateBackups()));
+  backupTimer->start(1000*60*5); //fire it every five minutes
   //createGUI(0);
 
 }
@@ -367,6 +371,31 @@
   return QString::fromLatin1(actionCurrentTool->name()).toInt();
 }
 
+void MainWindow::slotCreateBackups()
+{
+//create a backup of the opened forms
+  QWidgetList windows = qworkspace->windowList(QWorkspace::StackingOrder);
+  for (int i = 0; i < (int)windows.count(); ++i)
+  {
+    FormWindow* form = dynamic_cast<FormWindow*>(windows.at(i));
+    if (!form || !form->formFile())
+      continue;
+    QString fileName = form->formFile()->fileName();
+    QString backupName = fileName + ".backup";
+    bool modified = form->formFile()->isModified();
+    if (form->formFile()->hasTempFileName())
+      continue; //no need to create a backup
+    
+    form->formFile()->setFileName(backupName);  
+    form->formFile()->setModified(true);
+    if (!form->formFile()->save(false))
+    {
+      KMessageBox::error(this, i18n("<qt>Cannot create backup file \
<i>%1</i>.</qt>").arg(backupName)); +    }
+    form->formFile()->setFileName(fileName);  
+    form->formFile()->setModified(modified); 
+  }
+}
 
 void MainWindow::runForm()
 {
@@ -411,6 +440,10 @@
   form->formFile()->setModified(true);
   if (form->formFile()->save(false))
   {
+    if (!KIO::NetAccess::file_copy(KURL::fromPathOrURL(m_fileName), \
KURL::fromPathOrURL(m_fileName + ".backup"), statbuf.st_mode, true)) +    {
+      KMessageBox::error(this, i18n("<qt>Cannot create backup file \
<i>%1</i>.</qt>").arg(m_fileName + ".backup")); +    }
     ::chmod(m_fileName.local8Bit(), S_IRWXU);
     KProcess* process = new KProcess;
     process->setUseShell(true);
--- branches/KDE/3.5/kdewebdev/kommander/editor/mainwindow.h #768068:768069
@@ -179,6 +179,7 @@
     void editBreakLayout();
     void editAccels();
     void editConnections();
+    void editFindGlobal();
     
     void editFormSettings();
     void editPreferences();
@@ -206,6 +207,7 @@
     void createNewTemplate();
     
     void closeRunningForm(KProcess* process);
+    void slotCreateBackups();
     
 private:
     void setupMDI();
@@ -244,8 +246,6 @@
 
     QString whatsThisFrom( const QString &key );
 
-private slots:
-
 private:
     PropertyEditor *propertyEditor;
     HierarchyView *hierarchyView;
@@ -267,7 +267,7 @@
       *actionEditHLayout, *actionEditVLayout, *actionEditGridLayout,
       *actionEditSplitHorizontal, *actionEditSplitVertical,
       *actionEditSelectAll, *actionEditBreakLayout, *actionEditConnections,
-      *actionEditLower, *actionEditRaise;
+      *actionEditLower, *actionEditRaise, *actionEditFindGlobal;
     
     KToggleAction* actionPointerTool, *actionConnectTool, *actionOrderTool;
     KAction* actionCurrentTool;
@@ -289,6 +289,7 @@
 
     bool databaseAutoEdit;
     QTimer *updateSlotsTimer;
+    QTimer *backupTimer;
     bool inDebugMode;
     QObjectList debuggingForms;
     QString lastOpenFilter;
--- branches/KDE/3.5/kdewebdev/kommander/editor/mainwindowactions.cpp #768068:768069
@@ -140,6 +140,11 @@
   actionEditLower->setWhatsThis(i18n("Lowers the selected widgets"));
   actionEditLower->setEnabled(false);
 
+  actionEditFindGlobal = new KAction(i18n("Find in Form..."), CTRL + ALT + Key_F, \
this, SLOT(editFindGlobal()), actionCollection(), "edit_find_global"); +  \
actionEditFindGlobal->setToolTip(i18n("Search for a text in the whole form.")); +  \
actionEditFindGlobal->setWhatsThis(whatsThisFrom("Edit|Find in Form")); +  \
connect(this, SIGNAL(hasActiveForm(bool)), actionEditFindGlobal, \
SLOT(setEnabled(bool))); +
   actionEditAccels = new KAction(i18n("Check Accelerators"), ALT + Key_R, this, \
SLOT(editAccels()),  actionCollection(), "edit_check_accel");
   actionEditAccels->setToolTip(i18n("Checks if the accelerators used in the form are \
unique")); @@ -182,6 +187,7 @@
   actionEditSelectAll->plug(menu);
   actionEditAccels->plug(menu);
   menu->insertSeparator();
+//   actionEditFindGlobal->plug(menu); //enable when implemented
   actionEditConnections->plug(menu);
   actionEditFormSettings->plug(menu);
   menu->insertSeparator();
@@ -1060,6 +1066,14 @@
   statusBar()->clear();
 }
 
+void MainWindow::editFindGlobal()
+{
+  if (!formWindow())
+    return;
+  
+}
+
+
 void MainWindow::editFormSettings()
 {
   if (!formWindow())


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

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