[rkward/frameworks] /: Remove further kdelibs4support code. As part of this, change the rk.edit.files()-message from non-modal dialog to KMessageWidget inside main workplace window.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 28 10:45:53 UTC 2016


Git commit c9840f26b81b1af1597e221391c6f5bf419c5e6d by Thomas Friedrichsmeier.
Committed on 28/01/2016 at 10:45.
Pushed by tfry into branch 'frameworks'.

Remove further kdelibs4support code. As part of this, change the rk.edit.files()-message from non-modal dialog to KMessageWidget inside main workplace window.

M  +1    -0    ChangeLog
M  +1    -1    rkward/agents/CMakeLists.txt
M  +14   -5    rkward/agents/rkloadagent.cpp
M  +3    -1    rkward/agents/rkloadagent.h
M  +2    -2    rkward/agents/rksaveagent.cpp
M  +13   -25   rkward/agents/showedittextfileagent.cpp
M  +3    -3    rkward/agents/showedittextfileagent.h
M  +15   -0    rkward/windows/rkworkplace.cpp
M  +6    -0    rkward/windows/rkworkplace.h

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

diff --git a/ChangeLog b/ChangeLog
index 4b723b3..0b9f232 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Show the message accompanying rk.show.files() or rk.edit.files() inside the main window, instead of a separate dialog
 - File browser gains "Rename" context menu action
 - File selection fields in plugin dialogs remember the last used directory (per session), and check for a valid selection
 - Better handling of text drag-and-drop inside the R console window
diff --git a/rkward/agents/CMakeLists.txt b/rkward/agents/CMakeLists.txt
index d71d948..2c37fde 100644
--- a/rkward/agents/CMakeLists.txt
+++ b/rkward/agents/CMakeLists.txt
@@ -14,4 +14,4 @@ SET(agents_STAT_SRCS
    )
 
 ADD_LIBRARY(agents STATIC ${agents_STAT_SRCS})
-TARGET_LINK_LIBRARIES(agents Qt5::Widgets KF5::TextEditor KF5::KDELibs4Support)
\ No newline at end of file
+TARGET_LINK_LIBRARIES(agents Qt5::Widgets KF5::TextEditor)
\ No newline at end of file
diff --git a/rkward/agents/rkloadagent.cpp b/rkward/agents/rkloadagent.cpp
index 1b6bb49..e560613 100644
--- a/rkward/agents/rkloadagent.cpp
+++ b/rkward/agents/rkloadagent.cpp
@@ -16,12 +16,15 @@
  ***************************************************************************/
 #include "rkloadagent.h"
 
-#include <kio/netaccess.h>
 #include <klocale.h>
 #include <kmessagebox.h>
 #include <kdeversion.h>
+#include <kio/filecopyjob.h>
+#include <KJobWidgets>
+#include <KJobUiDelegate>
 
 #include <qstring.h>
+#include <QTemporaryFile>
 
 #include "../rkglobals.h"
 #include "../core/robjectlist.h"
@@ -40,14 +43,21 @@ RKLoadAgent::RKLoadAgent (const QUrl &url, bool merge) {
 	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Loading Workspace..."));
 
 	_merge = merge;
+
+	// downlad the file, if remote
+	tmpfile = 0;
 	QString filename;
 	if (!url.isLocalFile ()) {
-		KIO::NetAccess::download (url, tmpfile, RKWardMainWindow::getMain ());
-		filename = tmpfile;
+		tmpfile = new QTemporaryFile (this);
+		KIO::Job* getjob = KIO::file_copy (url, QUrl::fromLocalFile (tmpfile->fileName()));
+		KJobWidgets::setWindow (getjob, RKWardMainWindow::getMain ());
+		if (!getjob->exec ()) {
+			getjob->ui ()->showErrorMessage();
+			return;
+		}
 	} else {
 		filename = url.toLocalFile ();
 	}
-	
 
 	RCommand *command;
 	
@@ -71,7 +81,6 @@ void RKLoadAgent::rCommandDone (RCommand *command) {
 	RK_TRACE (APP);
 	
 	if (command->getFlags () == WORKSPACE_LOAD_COMMAND) {
-		if (!tmpfile.isEmpty ()) KIO::NetAccess::removeTempFile (tmpfile);
 		if (command->failed ()) {
 			KMessageBox::error (0, i18n ("There has been an error opening file '%1':\n%2", RKWorkplace::mainWorkplace ()->workspaceURL ().path (), command->error ()), i18n ("Error loading workspace"));
 			RKWorkplace::mainWorkplace ()->setWorkspaceURL (QUrl());
diff --git a/rkward/agents/rkloadagent.h b/rkward/agents/rkloadagent.h
index f3badd0..9da49a0 100644
--- a/rkward/agents/rkloadagent.h
+++ b/rkward/agents/rkloadagent.h
@@ -23,6 +23,8 @@
 #include <qstring.h>
 #include <QUrl>
 
+class QTemporaryFile;
+
 /** The RKLoadAgent is really a rather simple agent. All it needs to do is display an error message, if loading fails. No further action is required. Like all
 agents, the RKLoadAgent self-destructs when done.
 @author Thomas Friedrichsmeier
@@ -37,7 +39,7 @@ protected:
 	void rCommandDone (RCommand *command) override;
 private:
 /// needed if file to be loaded is remote
-	QString tmpfile;
+	QTemporaryFile* tmpfile;
 	bool _merge;
 };
 
diff --git a/rkward/agents/rksaveagent.cpp b/rkward/agents/rksaveagent.cpp
index ef20df5..7a71f5b 100644
--- a/rkward/agents/rksaveagent.cpp
+++ b/rkward/agents/rksaveagent.cpp
@@ -17,10 +17,10 @@
 #include "rksaveagent.h"
 
 #include <klocale.h>
-#include <kfiledialog.h>
 #include <kmessagebox.h>
 
 #include <qapplication.h>
+#include <QFileDialog>
 
 #include "../rbackend/rinterface.h"
 #include "../core/robjectlist.h"
@@ -59,7 +59,7 @@ RKSaveAgent::~RKSaveAgent () {
 
 bool RKSaveAgent::askURL () {
 	RK_TRACE (APP);
-	save_url = QUrl::fromLocalFile (KFileDialog::getSaveFileName (save_url, i18n ("%1|R Workspace Files (%1)\n*|All files", RKSettingsModuleGeneral::workspaceFilenameFilter ())));
+	save_url = QUrl::fromLocalFile (QFileDialog::getSaveFileName (RKWardMainWindow::getMain (), QString (), save_url.toLocalFile (), i18n ("R Workspace Files [%1](%1);;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/agents/showedittextfileagent.cpp b/rkward/agents/showedittextfileagent.cpp
index eddce1e..7f9a951 100644
--- a/rkward/agents/showedittextfileagent.cpp
+++ b/rkward/agents/showedittextfileagent.cpp
@@ -2,7 +2,7 @@
                           showedittextfileagent  -  description
                              -------------------
     begin                : Tue Sep 13 2005
-    copyright            : (C) 2005, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2016 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -18,13 +18,14 @@
 #include "showedittextfileagent.h"
 
 #include <klocale.h>
-#include <kdialog.h>
 #include <kmessagebox.h>
+#include <KMessageWidget>
 
 #include <qlabel.h>
 #include <qlayout.h>
 #include <qfile.h>
 #include <QVBoxLayout>
+#include <QDialog>
 
 #include "../windows/rkcommandeditorwindow.h"
 #include "../rbackend/rinterface.h"
@@ -40,27 +41,15 @@ ShowEditTextFileAgent::ShowEditTextFileAgent (RBackendRequest *request, const QS
 
 	ShowEditTextFileAgent::request = request;
 
-	dialog = new KDialog (0);
+	message = new KMessageWidget (0);
+	message->setMessageType (KMessageWidget::Information);
+	message->setText (QString ("<p><strong>%1<strong></p><p>%2</p>").arg (caption).arg (QString (text).replace ('\n', "<br/>")));
+	message->setCloseButtonVisible (false);
+	QAction *done_action = new QAction (QIcon::fromTheme ("dialog-ok"), i18n ("Done"), message);
+	connect (done_action, &QAction::triggered, this, &QObject::deleteLater);
+	message->addAction (done_action);
 
-	// dialog setup
-	dialog->setCaption (caption);
-	dialog->setButtons (KDialog::Ok);
-	dialog->setModal (false);
-
-	QWidget *page = new QWidget (dialog);
-	dialog->setMainWidget (page);
-	QVBoxLayout *layout = new QVBoxLayout (page);
-	layout->setContentsMargins (0, 0, 0, 0);
-	QLabel *label = new QLabel (text, page);
-	label->setWordWrap (true);
-	layout->addWidget (label);
-
-	dialog->setButtonText (KDialog::Ok, i18n ("Done"));
-
-	connect (dialog, &KDialog::finished, this, &ShowEditTextFileAgent::deleteLater);
-
-	// do it
-	dialog->show ();
+	RKWorkplace::mainWorkplace ()->addMessageWidget (message);
 }
 
 
@@ -68,7 +57,7 @@ ShowEditTextFileAgent::~ShowEditTextFileAgent () {
 	RK_TRACE (APP);
 
 	RKRBackendProtocolFrontend::setRequestCompleted (request);
-	dialog->deleteLater ();
+	message->deleteLater ();
 }
 
 // static
@@ -107,7 +96,7 @@ void ShowEditTextFileAgent::showEditFiles (RBackendRequest *request) {
 		RKRBackendProtocolFrontend::setRequestCompleted (request);
 	} else if (request->type == RBackendRequest::EditFiles) {
 		if (prompt) {
-			new ShowEditTextFileAgent (request, i18n ("A command running in the R-engine wants you to edit one or more file(s). Please look at these files, edit them as appropriate, and save them. When done, press the \"Done\"-button, or close this dialog to resume.\n\n") + display_titles.join ("\n"), i18n ("Edit file(s)"));
+			new ShowEditTextFileAgent (request, i18n ("A command running in the R-engine wants you to edit the following file(s). Please look at these files, edit them as appropriate, and save them. When done, press the \"Done\"-button, or close this dialog to resume.<ul><li>") + display_titles.join ("</li></li>") + "</li></ul>", i18n ("Edit file(s)"));
 		} else {
 			RKRBackendProtocolFrontend::setRequestCompleted (request);
 		}
@@ -123,4 +112,3 @@ void ShowEditTextFileAgent::showEditFiles (RBackendRequest *request) {
 		RKWorkplace::mainWorkplace ()->openScriptEditor (QUrl::fromLocalFile (files[n]), QString (), r_highlighting, read_only, display_titles[n], delete_files);
 	}
 }
-
diff --git a/rkward/agents/showedittextfileagent.h b/rkward/agents/showedittextfileagent.h
index d1110ed..7c1e024 100644
--- a/rkward/agents/showedittextfileagent.h
+++ b/rkward/agents/showedittextfileagent.h
@@ -2,7 +2,7 @@
                           showedittextfileagent  -  description
                              -------------------
     begin                : Tue Sep 13 2005
-    copyright            : (C) 2005, 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2005, 2010, 2016 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -21,7 +21,7 @@
 #include <qobject.h>
 
 class RBackendRequest;
-class KDialog;
+class KMessageWidget;
 
 /** The purpose of this agent is to display text files for showing and/or editing on request of the R backend. Technically speaking, it gets invoked, whenever the standard R callbacks (ptr_)R_ShowFiles, (ptr_)R_EditFiles, or (ptr_)R_EditFile are called. While the task of simply opening such files for display/editing is rather simple, there is one slightly more difficult issue involved (and hence this class to handle it): In standard R, all these calls are blocking further processing, until the user has closed the shown/edited files. In some cases this may be necessary (for instance if R wants to use with the edited files immediately), in some cases this is an unnecessary nuisance (such as when R simply wants to display a help page or some other purely informational text).
 
@@ -46,7 +46,7 @@ out, what exactly needs to be done. Note that this is a static member. It will t
 	static void showEditFiles (RBackendRequest *request);
 private:
 	RBackendRequest *request;
-	KDialog *dialog;
+	KMessageWidget *message;
 };
 
 #endif
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 6e29fc3..3b7cc45 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -29,6 +29,7 @@
 #include <kmimetype.h>
 #include <kstandarddirs.h>
 #include <KSharedConfig>
+#include <KMessageWidget>
 
 #include <QFileInfo>
 #include <QCryptographicHash>
@@ -100,9 +101,15 @@ RKWorkplace::RKWorkplace (QWidget *parent) : QWidget (parent) {
 	KConfigGroup toolbar_config = KSharedConfig::openConfig ()->group ("ToolwindowBars");
 	for (int i = 0; i < TOOL_WINDOW_BAR_COUNT; ++i) tool_window_bars[i]->restoreSize (toolbar_config);
 
+	// message area
+	message_area = new QWidget (this);
+	QVBoxLayout *message_layout = new QVBoxLayout (message_area);
+	message_layout->setContentsMargins (0, 0, 0, 0);
+
 	// now add it all to this widget
 	QVBoxLayout *box = new QVBoxLayout (this);
 	box->setContentsMargins (0, 0, 0, 0);
+	box->addWidget (message_area);
 	box->addWidget (vbox);
 
 	history = new RKMDIWindowHistory (this);
@@ -120,6 +127,14 @@ RKWorkplace::~RKWorkplace () {
 	}
 }
 
+void RKWorkplace::addMessageWidget (KMessageWidget* message) {
+	RK_TRACE (APP);
+
+	message_area->layout ()->addWidget (message);
+	topLevelWidget ()->show ();
+	topLevelWidget ()->raise ();
+}
+
 QString workspaceConfigFileName (const QUrl &url) {
 	QString base_name = QString (QCryptographicHash::hash (url.toDisplayString ().toUtf8 (), QCryptographicHash::Md5).toHex());
 	return (KStandardDirs::locateLocal ("data", "rkward/workspace_config_" + base_name));
diff --git a/rkward/windows/rkworkplace.h b/rkward/windows/rkworkplace.h
index 6263847..aac3e29 100644
--- a/rkward/windows/rkworkplace.h
+++ b/rkward/windows/rkworkplace.h
@@ -39,6 +39,7 @@ class QAction;
 class RKToolWindowBar;
 class RKMDIWindowHistoryWidget;
 class RKGraphicsDevice;
+class KMessageWidget;
 
 #define TOOL_WINDOW_BAR_COUNT 4
 
@@ -171,6 +172,10 @@ Has no effect, if RKSettingsModuleGeneral::workplaceSaveMode () != RKSettingsMod
 /** Make the next window to be created appear in a specific location (can be a named window). 
  *  @note It is the caller's responsibility to clear the override (by calling setWindowPlacementOverride ()) after the window in question has been created. */
 	void setWindowPlacementOverrides (const QString& placement=QString (), const QString& name=QString (), const QString& style=QString ());
+
+/** Inserts the given message widget above the central area. While technically, the workplace becomes the parent widget of the message widget, it is the caller's responsibility to
+ *  delete the widget, when appropriate. */
+	void addMessageWidget (KMessageWidget *message);
 signals:
 /** emitted when the workspace Url has changed */
 	void workspaceUrlChanged (const QUrl &url);
@@ -200,6 +205,7 @@ private:
 
 	QSplitter *horiz_splitter;
 	QSplitter *vert_splitter;
+	QWidget *message_area;
 
 	RKToolWindowBar* tool_window_bars[TOOL_WINDOW_BAR_COUNT];
 friend class RKToolWindowBar;



More information about the rkward-tracker mailing list