[rkward-cvs] SF.net SVN: rkward-code:[4977] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Wed Oct 29 19:28:27 UTC 2014


Revision: 4977
          http://sourceforge.net/p/rkward/code/4977
Author:   tfry
Date:     2014-10-29 19:28:26 +0000 (Wed, 29 Oct 2014)
Log Message:
-----------
Make the crash recovery dialog less annoying.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/dialogs/rkrecoverdialog.cpp
    trunk/rkward/rkward/dialogs/rkrecoverdialog.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2014-10-29 10:07:09 UTC (rev 4976)
+++ trunk/rkward/ChangeLog	2014-10-29 19:28:26 UTC (rev 4977)
@@ -1,3 +1,5 @@
+- Improve crash recovery dialog to not prompt again for the same files
+- Fixed potential crash while the "RKWard Debug Messages" window is visible
 - Fixed display of file paths containing non-ascii characters in the title bar and startup dialog
 - Fixed some erroneous plugin debug messages
 - IN PROGESS: Allow plugins to be translated
@@ -5,6 +7,7 @@
     - Is it a problem to sync KDE_LANG and LANGUAGE? Should that also be set for the backend?
     - Message extraction: Should we do this in R, using XiMpLe? That might allow us to give better context / comments
     - Don't forget to write documentation
+      - Also general documentation for JS-functions is missing!
     - What should be the policy regarding installing translations (80% criterion)
     - discuss i18n_context vs. comments
     - Important pitfalls: String comparison with checkbox / radio labels! (Probably wrong in some plugins)

Modified: trunk/rkward/rkward/dialogs/rkrecoverdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkrecoverdialog.cpp	2014-10-29 10:07:09 UTC (rev 4976)
+++ trunk/rkward/rkward/dialogs/rkrecoverdialog.cpp	2014-10-29 19:28:26 UTC (rev 4977)
@@ -2,7 +2,7 @@
                           rkrecoverdialog  -  description
                              -------------------
     begin                : Fri Feb 04 2011
-    copyright            : (C) 2011, 2012 by Thomas Friedrichsmeier
+    copyright            : (C) 2011, 2012, 2014 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -23,6 +23,7 @@
 #include <QDir>
 #include <QFileInfo>
 #include <QLabel>
+#include <kmessagebox.h>
 
 #include "../settings/rksettingsmodulegeneral.h"
 
@@ -31,19 +32,27 @@
 RKRecoverDialog::RKRecoverDialog (const QStringList &recovery_files) {
 	RK_TRACE (DIALOGS);
 	RK_ASSERT (!recovery_files.isEmpty ());
+	files = recovery_files;
 
 	const QString caption = i18n ("Crash recovery file detected");
 	setCaption (caption);
 	setButtons (KDialog::Ok | KDialog::Cancel | KDialog::User1);
-	setButtonText (KDialog::User1, i18n ("Show in file browser"));
 	setButtonText (KDialog::Ok, i18n ("Recover"));
-	connect (this, SIGNAL (user1Clicked()), this, SLOT (showButtonClicked ()));
-
+	setButtonToolTip (KDialog::Ok, i18n ("Saves the recovery file(s), and opens it (or the most recent one)"));
+	setButtonWhatsThis (KDialog::Ok, buttonToolTip (KDialog::Ok));
+	setButtonText (KDialog::Cancel, i18n ("Save for later"));
+	setButtonToolTip (KDialog::Cancel, i18n ("Saves the recovery file(s) for later use, but does not open it"));
+	setButtonWhatsThis (KDialog::Cancel, buttonToolTip (KDialog::Cancel));
+	setButtonText (KDialog::User1, i18n ("Delete"));
+	setButtonToolTip (KDialog::User1, i18n ("Deletes the recovery file(s)"));
+	setButtonWhatsThis (KDialog::User1, buttonToolTip (KDialog::User1));
+	
+	connect (this, SIGNAL (user1Clicked()), this, SLOT (deleteButtonClicked ()));
 	QLabel *label = new QLabel (this);
 	QString text = QString ("<p><b>%1</b></p>").arg (caption);
 	text.append (i18n ("<p>It looks like RKWard has crashed, recently. We are sorry about that! However, not everything is lost, and with a bit of luck, your data has been saved in time.</p>"));
-	text.append (i18np ("<p>A workspace recovery file exists in <i>%2</i> as <i>%3</i>.</p>", "<p>%1 workspace recovery files exist in <i>%2</i>, the most recent one of which is <i>%3</i>.</p>", recovery_files.count (), RKSettingsModuleGeneral::filesPath (), recovery_files.first ()));
-	text.append (i18n ("<p>Do you want to open this file, now? <b>Note</b>: You will be prompted again, next time you start RKWard, until you remove/rename the file, manually.</p>"));
+	text.append (i18np ("<p>A workspace recovery file exists, dating from <i>%2</i></p>", "<p>%1 workspace recovery files exist, the most recent one of which dates from <i>%2</i>.</p>", recovery_files.count (), QFileInfo (recovery_files.first ()).lastModified ().toString (Qt::SystemLocaleLongDate)));
+	text.append (i18n ("<p>Do you want to open this file, now, save it for later (as %1), or discard it?</p>", saveFileFor (recovery_files.first ())));
 	label->setText (text);
 	label->setWordWrap (true);
 	setMainWidget (label);
@@ -53,24 +62,58 @@
 	RK_TRACE (DIALOGS);
 }
 
-void RKRecoverDialog::showButtonClicked () {
+void RKRecoverDialog::deleteButtonClicked () {
 	RK_TRACE (DIALOGS);
 
-	new KRun (KUrl::fromLocalFile (RKSettingsModuleGeneral::filesPath ()), this);	// KRun auto-deletes itself by default
+	if (KMessageBox::warningContinueCancel (this, i18np ("You are about to delete the recovery file %2. There will be no way to bring it back. Continue?", "You are about to delete %1 recovery files (the most recent one is %2). There will be no way to bring them back. Continue?", files.count (), files.first ())) != KMessageBox::Continue) return;
+
+	for (int i = 0; i < files.count (); ++i) {
+		QFile (files[i]).remove ();	// TODO: error handling?
+	}
+	files.clear ();
 	reject ();
 }
 
 //static
+QString RKRecoverDialog::saveFileFor (const QString& recovery_file) {
+	RK_TRACE (DIALOGS);
+
+	QFileInfo fi (recovery_file);
+	QDateTime mtime = fi.lastModified ();
+	QDir dir = fi.absoluteDir ();
+	QString new_name;
+	for (int i = 0; i < 100; ++i) {	// If we just had more than 100 crashes per minutes, you'll excuse another small bug, at this point
+		QString num;
+		if (i > 0) num = "_" + QString::number (i+1);
+		new_name = dir.absoluteFilePath ("recovered_workspace_" + mtime.toString ("yyyy-MM-dd_hh:mm") + num + ".RData");
+		if (!QFileInfo (new_name).exists ()) break;
+	}
+	return new_name;
+}
+
+//static
 KUrl RKRecoverDialog::checkRecoverCrashedWorkspace () {
 	RK_TRACE (DIALOGS);
 
 	QDir dir (RKSettingsModuleGeneral::filesPath ());
 	dir.setNameFilters (QStringList ("rkward_recover*.RData"));
 	QStringList matches = dir.entryList (QDir::Files, QDir::Time);
+	for (int i = 0; i < matches.count (); ++i) {
+		matches[i] = dir.absoluteFilePath (matches[i]);
+	}
 
 	if (!matches.isEmpty ()) {
 		RKRecoverDialog dialog (matches);
 		dialog.exec ();
+
+		// "Save" recovery files, so they want be matched, again
+		matches = dialog.files;	// May have been modified, notably deleted
+		for (int i = matches.count () - 1; i >= 0; --i) {
+			QString new_name = saveFileFor (matches[i]);
+			QFile::rename (matches[i], new_name);
+			matches[i] = new_name;
+		}
+
 		if (dialog.result () == QDialog::Accepted) return (KUrl::fromLocalFile (dir.absoluteFilePath (matches.first ())));
 	}
 

Modified: trunk/rkward/rkward/dialogs/rkrecoverdialog.h
===================================================================
--- trunk/rkward/rkward/dialogs/rkrecoverdialog.h	2014-10-29 10:07:09 UTC (rev 4976)
+++ trunk/rkward/rkward/dialogs/rkrecoverdialog.h	2014-10-29 19:28:26 UTC (rev 4977)
@@ -2,7 +2,7 @@
                           rkrecoverdialog  -  description
                              -------------------
     begin                : Fri Feb 04 2011
-    copyright            : (C) 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2011, 2014 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -32,8 +32,10 @@
 protected:
 	RKRecoverDialog (const QStringList &recovery_files);
 	~RKRecoverDialog ();
+	static QString saveFileFor (const QString &recovery_file);
+	QStringList files;
 private slots:
-	void showButtonClicked ();
+	void deleteButtonClicked ();
 };
 
 #endif





More information about the rkward-tracker mailing list