[rkward/frameworks] /: Further KUrl porting

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Nov 24 14:24:30 UTC 2015


Git commit c554699af0e43be4f7a534dca971efa6f7fb4490 by Thomas Friedrichsmeier.
Committed on 24/11/2015 at 14:24.
Pushed by tfry into branch 'frameworks'.

Further KUrl porting

M  +11   -0    TODO
M  +2    -2    rkward/agents/rksaveagent.cpp
M  +5    -2    rkward/rkward.cpp
M  +18   -16   rkward/windows/rkworkplace.cpp

http://commits.kde.org/rkward/c554699af0e43be4f7a534dca971efa6f7fb4490

diff --git a/TODO b/TODO
index cdc9263..dcf48d8 100644
--- a/TODO
+++ b/TODO
@@ -2,6 +2,17 @@ The following list of TODO-items is NOT complete!
 Also, plans change frequently. If something is listed for a specific release, that's no more than a rough plan.
 All in all, this TODO list is mostly for internal purposes, and many parts may not necessarily be intellegible to anybody but the authors.
 
+KF5 port:
+Things to do:
+- Convert to new Signal / slot syntax
+- Remove kde4libssupport classes
+- Remove obsolete version checks
+- Adjust platform checks
+Things to test at the end:
+- Everthing concerning loading / saving, from recent files, scripts, workspace, etc.
+  - Moved installations, moved workspaces.
+- Window embedding
+
 New features in R 3.1.0 to make use of / support:
 
 - A new browser command s has been added, to “step into” function calls.
diff --git a/rkward/agents/rksaveagent.cpp b/rkward/agents/rksaveagent.cpp
index 5a65292..ef20df5 100644
--- a/rkward/agents/rksaveagent.cpp
+++ b/rkward/agents/rksaveagent.cpp
@@ -50,7 +50,7 @@ RKSaveAgent::RKSaveAgent (QUrl url, bool save_file_as, DoneAction when_done, QUr
 	
 	RKWorkplace::mainWorkplace ()->setWorkspaceURL (save_url, true);
 	RKWorkplace::mainWorkplace ()->saveWorkplace (save_chain);
-	RKGlobals::rInterface ()->issueCommand (new RCommand ("save.image (\"" + save_url.toLocalFile () + "\")", RCommand::App, QString (), this), save_chain);
+	RKGlobals::rInterface ()->issueCommand (new RCommand ("save.image (" + RObject::rQuote (save_url.toLocalFile ()) + ')', RCommand::App, QString (), this), save_chain);
 }
 
 RKSaveAgent::~RKSaveAgent () {
@@ -59,7 +59,7 @@ RKSaveAgent::~RKSaveAgent () {
 
 bool RKSaveAgent::askURL () {
 	RK_TRACE (APP);
-	save_url = KFileDialog::getSaveFileName (save_url, i18n ("%1|R Workspace Files (%1)\n*|All files", RKSettingsModuleGeneral::workspaceFilenameFilter ()));
+	save_url = QUrl::fromLocalFile (KFileDialog::getSaveFileName (save_url, i18n ("%1|R Workspace Files (%1)\n*|All files", RKSettingsModuleGeneral::workspaceFilenameFilter ())));
 	if (save_url.isEmpty ()) {
 		if (when_done != DoNothing) {
 			if (KMessageBox::warningYesNo (0, i18n ("No filename given. Your data was NOT saved. Do you still want to proceed?")) != KMessageBox::Yes) when_done = DoNothing;
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 16ed23a..a83b926 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -463,10 +463,13 @@ void RKWardMainWindow::initActions() {
 
 	fileSaveWorkspace = actionCollection ()->addAction (KStandardAction::Save, "file_savex", this, SLOT(slotFileSaveWorkspace()));
 	fileSaveWorkspace->setText (i18n ("Save Workspace"));
-	fileSaveWorkspace->setShortcut (Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_S);
+	actionCollection ()->setDefaultShortcut (fileSaveWorkspace, Qt::ControlModifier + Qt::AltModifier + Qt::Key_S);
+	fileSaveWorkspace->setShortcut (Qt::ControlModifier + Qt::AltModifier + Qt::Key_S); // KF5 TODO: Not needed for KF5 >= 5.2
 	fileSaveWorkspace->setStatusTip (i18n ("Saves the actual document"));
 
 	fileSaveWorkspaceAs = actionCollection ()->addAction (KStandardAction::SaveAs, "file_save_asx", this, SLOT(slotFileSaveWorkspaceAs()));
+	actionCollection ()->setDefaultShortcut (fileSaveWorkspaceAs, Qt::ControlModifier + Qt::AltModifier + Qt::ShiftModifier + Qt::Key_S);
+	fileSaveWorkspaceAs->setShortcut (Qt::ControlModifier + Qt::AltModifier + Qt::ShiftModifier + Qt::Key_S); // KF5 TODO: Not needed for KF5 >= 5.2
 	fileSaveWorkspaceAs->setText (i18n ("Save Workspace As"));
 	fileSaveWorkspaceAs->setStatusTip (i18n ("Saves the actual document as..."));
 
@@ -928,7 +931,7 @@ void RKWardMainWindow::setCaption (const QString &) {
 	RK_TRACE (APP);
 
 	QString wcaption = RKWorkplace::mainWorkplace ()->workspaceURL ().fileName ();
-	if (wcaption.isEmpty ()) wcaption = RKWorkplace::mainWorkplace ()->workspaceURL ().prettyUrl ();
+	if (wcaption.isEmpty ()) wcaption = RKWorkplace::mainWorkplace ()->workspaceURL ().toDisplayString ();
 	if (wcaption.isEmpty ()) wcaption = i18n ("[Unnamed Workspace]");
 	RKMDIWindow *window = RKWorkplace::mainWorkplace ()->view ()->activePage ();
 	if (window) wcaption.append (" - " + window->fullCaption ());
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 8a3796e..182c95c 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -33,6 +33,7 @@
 #include <QFileInfo>
 #include <QCryptographicHash>
 #include <QKeyEvent>
+#include <QDir>
 
 #include "detachedwindowcontainer.h"
 #include "rkcommandeditorwindow.h"
@@ -128,9 +129,13 @@ KConfigBase *RKWorkplace::workspaceConfig () {
 }
 
 QString RKWorkplace::portableUrl (const QUrl &url) {
-	QUrl relative = QUrl::relativeUrl (workspaceURL (), url);
-	relative.cleanPath ();
-	return relative.prettyUrl ();
+	QUrl ret = url;
+	if (url.scheme () == workspaceURL ().scheme () && url.authority () == workspaceURL ().authority ()) {
+		QString relative = QDir (workspaceURL ().path ()).relativeFilePath (url.path ());
+		ret = QUrl (relative);
+	}
+	// QUrl::toDisplayString () used here, for the side effect of stripping credentials
+	return QUrl (ret).adjusted (QUrl::NormalizePathSegments).toDisplayString ();
 }
 
 void RKWorkplace::setWorkspaceURL (const QUrl &url, bool keep_config) {
@@ -251,7 +256,7 @@ void RKWorkplace::placeInToolWindowBar (RKMDIWindow *window, int position) {
 bool RKWorkplace::openAnyUrl (const QUrl &url, const QString &known_mimetype, bool force_external) {
 	RK_TRACE (APP);
 
-	if (url.protocol () == "rkward") {
+	if (url.scheme () == "rkward") {
 		if (RKHTMLWindow::handleRKWardURL (url)) return true;
 	}
 	KMimeType::Ptr mimetype;
@@ -275,7 +280,7 @@ bool RKWorkplace::openAnyUrl (const QUrl &url, const QString &known_mimetype, bo
 		RK_DEBUG (APP, DL_INFO, "Don't know how to handle mimetype %s.", qPrintable (mimetype->name ()));
 	}
 
-	if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file or the filetype is not supported by RKWard. Do you want to open the url in the default application?", url.prettyUrl ()), i18n ("Open in default application?")) != KMessageBox::Yes) {
+	if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file or the filetype is not supported by RKWard. Do you want to open the url in the default application?", url.toDisplayString ()), i18n ("Open in default application?")) != KMessageBox::Yes) {
 		return false;
 	}
 	KRun *runner = new KRun (url, topLevelWidget());		// according to KRun-documentation, KRun will self-destruct when done.
@@ -303,7 +308,7 @@ RKMDIWindow* RKWorkplace::openScriptEditor (const QUrl &url, const QString& enco
 	if (!url.isEmpty ()) {
 		if (!editor->openURL (url, encoding, use_r_highlighting, read_only, delete_on_close)) {
 			delete editor;
-			KMessageBox::messageBox (view (), KMessageBox::Error, i18n ("Unable to open \"%1\"", url.prettyUrl ()), i18n ("Could not open command file"));
+			KMessageBox::messageBox (view (), KMessageBox::Error, i18n ("Unable to open \"%1\"", url.toDisplayString ()), i18n ("Could not open command file"));
 			return 0;
 		}
 	}
@@ -324,7 +329,7 @@ RKMDIWindow* RKWorkplace::openHelpWindow (const QUrl &url, bool only_once) {
 	if (only_once) {
 		RKWorkplaceObjectList help_windows = getObjectList (RKMDIWindow::HelpWindow, RKMDIWindow::AnyWindowState);
 		for (RKWorkplaceObjectList::const_iterator it = help_windows.constBegin (); it != help_windows.constEnd (); ++it) {
-			if (static_cast<RKHTMLWindow *> (*it)->url ().equals (url, QUrl::CompareWithoutTrailingSlash | QUrl::CompareWithoutFragment)) {
+			if (static_cast<RKHTMLWindow *> (*it)->url ().matches (url, QUrl::StripTrailingSlash | QUrl::NormalizePathSegments)) {
 				(*it)->activate ();
 				return (*it);
 			}
@@ -566,9 +571,8 @@ QStringList RKWorkplace::makeWorkplaceDescription () {
 	QStringList workplace_description;
 
 	// first, save the base directory of the workplace. This allows us to cope better with moved workspaces while restoring.
-	QUrl base_url = workspaceURL ();
-	base_url.setPath (base_url.directory ());
-	if (base_url.isLocalFile () && base_url.hasPath ()) workplace_description.append ("base::::" + base_url.url ());
+	QUrl base_url = workspaceURL ().adjusted (QUrl::RemoveFilename);
+	if (base_url.isLocalFile () && !base_url.isEmpty ()) workplace_description.append ("base::::" + base_url.url ());
 
 	// window order in the workplace view may have changed with respect to our list. Thus we first generate a properly sorted list
 	RKWorkplaceObjectList list = getObjectList (RKMDIWindow::DocumentWindow, RKMDIWindow::Detached);
@@ -633,11 +637,10 @@ void RKWorkplace::restoreWorkplace (RCommandChain *chain, bool merge) {
 }
 
 QUrl checkAdjustRestoredUrl (const QString &_url, const QString old_base) {
-	QUrl url (_url);
+	QUrl url = QUrl::fromUserInput (_url, QString (), QUrl::AssumeLocalFile);
 
 	if (old_base.isEmpty ()) return (url);
-	QUrl new_base_url = RKWorkplace::mainWorkplace ()->workspaceURL ();
-	new_base_url.setPath (new_base_url.directory ());
+	QUrl new_base_url = RKWorkplace::mainWorkplace ()->workspaceURL ().adjusted (QUrl::RemoveFilename | QUrl::NormalizePathSegments);
 	if (new_base_url.isEmpty ()) return (url);
 	QUrl old_base_url (old_base);
 	if (old_base_url == new_base_url) return (url);
@@ -649,9 +652,8 @@ QUrl checkAdjustRestoredUrl (const QString &_url, const QString old_base) {
 	if (QFileInfo (url.toLocalFile ()).exists ()) return (url);
 
 	// check whether a file exists for the adjusted url
-	QUrl relative = QUrl::fromLocalFile (new_base_url.path () + '/' + QUrl::relativePath (old_base_url.path (), url.path ()));
-	relative.cleanPath ();
-// 	if (QFileInfo (relative.toLocalFile ()).exists ()) return (relative);
+	QUrl relative = new_base_url.resolved (QDir (old_base_url.path ()).relativeFilePath (url.path ()));
+	if (QFileInfo (relative.toLocalFile ()).exists ()) return (relative);
 	return (url);
 }
 



More information about the rkward-tracker mailing list