[rkward-cvs] SF.net SVN: rkward:[3711] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Aug 3 11:56:57 UTC 2011
Revision: 3711
http://rkward.svn.sourceforge.net/rkward/?rev=3711&view=rev
Author: tfry
Date: 2011-08-03 11:56:56 +0000 (Wed, 03 Aug 2011)
Log Message:
-----------
Fix handling of non-HTML files served through the local dynamic help server
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/windows/rkhtmlwindow.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.h
trunk/rkward/rkward/windows/rkworkplace.cpp
trunk/rkward/rkward/windows/rkworkplace.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2011-08-03 09:33:36 UTC (rev 3710)
+++ trunk/rkward/ChangeLog 2011-08-03 11:56:56 UTC (rev 3711)
@@ -1,3 +1,4 @@
+- Fixed: PDFs and many other types of documents linked from help pages would not be opened, correctly
- Add support R 2.14.x
- Removed option to set options("printcmd")
- New option to run arbitrary (setup) commands in each session
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2011-08-03 09:33:36 UTC (rev 3710)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2011-08-03 11:56:56 UTC (rev 3711)
@@ -26,6 +26,7 @@
#include <kactioncollection.h>
#include <kdirwatch.h>
#include <kmimetype.h>
+#include <kio/job.h>
#include <qfileinfo.h>
#include <qwidget.h>
@@ -265,6 +266,7 @@
RK_TRACE (APP);
if (handleRKWardURL (url)) return true;
+
if (window_mode == HTMLOutputWindow) {
if (url != current_url) {
// output window should not change url after initialization
@@ -276,41 +278,52 @@
current_url = url; // needs to be set before registering
RKOutputWindowManager::self ()->registerWindow (this);
}
- } else {
- if (!(url.isLocalFile ())) {
- if (window_mode == HTMLHelpWindow) {
- // since R 2.10.0, help urls may be on local ports
- if (url.protocol ().toLower ().startsWith ("http")) {
- QString host = url.host ();
- if ((host == "127.0.0.1") || (host == "localhost") || host == QHostInfo::localHostName ()) {
- khtmlpart->openUrl (url);
- changeURL (url);
- return true;
- }
- }
- }
+ }
+
+ if (url.isLocalFile () && (KMimeType::findByUrl (url)->is ("text/html") || window_mode == HTMLOutputWindow)) {
+ QFileInfo out_file (url.toLocalFile ());
+ bool ok = out_file.exists();
+ if (ok) {
+ khtmlpart->openUrl (url);
+ } else {
+ fileDoesNotExistMessage ();
}
- if (!(url.isLocalFile () && KMimeType::findByUrl (url)->is ("text/html"))) {
- RKWorkplace::mainWorkplace ()->openAnyUrl (url);
+ changeURL (url);
+ return ok;
+ }
+
+ // special casing for R's dynamic help pages. These should be considered local, even though they are served through http
+ if (url.protocol ().toLower ().startsWith ("http")) {
+ QString host = url.host ();
+ if ((host == "127.0.0.1") || (host == "localhost") || host == QHostInfo::localHostName ()) {
+ KIO::TransferJob *job = KIO::get (url, KIO::Reload);
+ connect (job, SIGNAL (mimetype(KIO::Job*, const QString&)), this, SLOT (mimeTypeDetermined(KIO::Job*, const QString&)));
return true;
}
}
- QFileInfo out_file (url.toLocalFile ());
- bool ok = out_file.exists();
- if (ok) {
- khtmlpart->openUrl (url);
- } else {
- fileDoesNotExistMessage ();
- }
- changeURL (url);
- return ok;
+ RKWorkplace::mainWorkplace ()->openAnyUrl (url);
+ return true;
}
KUrl RKHTMLWindow::url () {
return current_url;
}
+void RKHTMLWindow::mimeTypeDetermined (KIO::Job* job, const QString& type) {
+ RK_TRACE (APP);
+
+ KIO::TransferJob* tj = static_cast<KIO::TransferJob*> (job);
+ KUrl url = tj->url ();
+ tj->putOnHold ();
+ if (type == "text/html") {
+ khtmlpart->openUrl (url);
+ changeURL (url);
+ } else {
+ RKWorkplace::mainWorkplace ()->openAnyUrl (url, type);
+ }
+}
+
void RKHTMLWindow::changeURL (const KUrl &url) {
current_url = url;
updateCaption (url);
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.h 2011-08-03 09:33:36 UTC (rev 3710)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.h 2011-08-03 11:56:56 UTC (rev 3711)
@@ -21,6 +21,7 @@
#include <kurl.h>
#include <kparts/browserextension.h>
#include <kxmlguiclient.h>
+#include <kio/jobclasses.h>
#include "../windows/rkmdiwindow.h"
@@ -87,6 +88,7 @@
/** This slot is called when the new page has finished loading. Sets scroll position to scroll_position */
void loadDone ();
void doGotoAnchorNow ();
+ void mimeTypeDetermined (KIO::Job*, const QString& type);
protected:
/** Here we store the position of the scroll bar before refresh. Used to scroll to the same position after a reload */
int scroll_position;
Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp 2011-08-03 09:33:36 UTC (rev 3710)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp 2011-08-03 11:56:56 UTC (rev 3711)
@@ -206,11 +206,16 @@
}
}
-bool RKWorkplace::openAnyUrl (const KUrl &url) {
+bool RKWorkplace::openAnyUrl (const KUrl &url, const QString &known_mimetype) {
RK_TRACE (APP);
#warning TODO support rkward:\/\/-protocol, here, too
- KMimeType::Ptr mimetype = KMimeType::findByUrl (url);
+ KMimeType::Ptr mimetype;
+ if (!known_mimetype.isEmpty ()) mimetype = KMimeType::mimeType (known_mimetype);
+ else mimetype = KMimeType::findByUrl (url);
+
+// NOTE: Currently a known mimetype implies that the URL is local or served from the local machine.
+// Thus, external web pages are *not* opened, here. Which is the behavior we want, although the implementation is ugly
if (mimetype->is ("text/html")) {
openHelpWindow (url, true);
return true; // TODO
Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h 2011-08-03 09:33:36 UTC (rev 3710)
+++ trunk/rkward/rkward/windows/rkworkplace.h 2011-08-03 11:56:56 UTC (rev 3711)
@@ -92,7 +92,7 @@
RKMDIWindow *activeWindow (RKMDIWindow::State state);
/** Opens the given url in the appropriate way. */
- bool openAnyUrl (const KUrl &url);
+ bool openAnyUrl (const KUrl &url, const QString &known_mimetype = QString ());
/** Opens a new script editor
@param url URL to load. Default option is to open an empty document
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list