[rkward/work/remove_khtml] rkward/windows: Add select all and encoding actions, fix some bugs.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Wed Feb 25 15:12:45 UTC 2015


Git commit 5fea16d5d5a8dbcdabdd291af72e710dcf1e83ee by Thomas Friedrichsmeier.
Committed on 24/02/2015 at 13:04.
Pushed by tfry into branch 'work/remove_khtml'.

Add select all and encoding actions, fix some bugs.

M  +5    -2    rkward/windows/rkhelpwindow.rc
M  +33   -14   rkward/windows/rkhtmlwindow.cpp
M  +2    -0    rkward/windows/rkhtmlwindow.h
M  +5    -2    rkward/windows/rkoutputwindow.rc

http://commits.kde.org/rkward/5fea16d5d5a8dbcdabdd291af72e710dcf1e83ee

diff --git a/rkward/windows/rkhelpwindow.rc b/rkward/windows/rkhelpwindow.rc
index 43c20a7..3b3bbde 100644
--- a/rkward/windows/rkhelpwindow.rc
+++ b/rkward/windows/rkhelpwindow.rc
@@ -2,15 +2,18 @@
 <kpartgui name="rkward_helpwindow" version="640">
 	<MenuBar>
 		<Menu name="file"><text>&File</text>
-			<Action name="print_help"/>
-			<Action name="save"/>
+			<Action name="print_html"/>
+			<Action name="save_html"/>
 		</Menu>
 		<Menu name="edit"><text>&Edit</text>
 			<Action name="copy"/>
+			<Separator/>
+			<Action name="select_all"/>
 		</Menu>
 		<Menu name="view"><text>&View</text>
 			<Action name="zoom_in"/>
 			<Action name="zoom_out"/>
+			<Action name="view_encoding"/>
 		</Menu>
 	</MenuBar>
 	<ToolBar fullWidth="true" name="mdiToolBar">
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 85286ad..9434f69 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -30,6 +30,7 @@
 #include <kservice.h>
 #include <ktemporaryfile.h>
 #include <kwebview.h>
+#include <kcodecaction.h>
 
 #include <qfileinfo.h>
 #include <qwidget.h>
@@ -42,6 +43,7 @@
 #include <QWebFrame>
 #include <QPrintDialog>
 #include <QMenu>
+#include <QTextCodec>
 
 #include "../rkglobals.h"
 #include "../rbackend/rinterface.h"
@@ -74,8 +76,7 @@ bool RKWebPage::acceptNavigationRequest (QWebFrame* frame, const QNetworkRequest
 	Q_UNUSED (type);
 
 	RK_TRACE (APP);
-	// TODO: Debug level
-	RK_DEBUG (APP, DL_WARNING, "Navigation request to %s", qPrintable (request.url ().toString ()));
+	RK_DEBUG (APP, DL_DEBUG, "Navigation request to %s", qPrintable (request.url ().toString ()));
 	if (direct_load && (frame == mainFrame ())) {
 		direct_load = false;
 		return true;
@@ -142,6 +143,7 @@ RKHTMLWindow::RKHTMLWindow (QWidget *parent, WindowMode mode) : RKMDIWindow (par
 	current_history_position = -1;
 	url_change_is_from_history = false;
 
+	window_mode = Undefined;
 	useMode (mode);
 
 	// needed to enable / disable the run selection action
@@ -302,7 +304,12 @@ bool RKHTMLWindow::handleRKWardURL (const KUrl &url, RKHTMLWindow *window) {
 		} else {
 			if (url.host () == "rhelp") {
 				// TODO: find a nice solution to render this in the current window
-				RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (url.path ().mid (1));
+				QStringList spec = url.path ().mid (1).split ('/');
+				QString function, package, type;
+				if (!spec.isEmpty ()) function = spec.takeLast ();
+				if (!spec.isEmpty ()) package = spec.takeLast ();
+				if (!spec.isEmpty ()) type = spec.takeLast ();
+				RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (function, package, type);
 				return true;
 			}
 
@@ -443,6 +450,14 @@ void RKHTMLWindow::zoomOut () {
 	RK_TRACE (APP);
 	view->setZoomFactor (view->zoomFactor () / 1.1);
 }
+
+void RKHTMLWindow::setTextEncoding (QTextCodec* encoding) {
+	RK_TRACE (APP);
+
+	page->settings ()->setDefaultTextEncoding (encoding->name ());
+	view->reload ();
+}
+
 void RKHTMLWindow::useMode (WindowMode new_mode) {
 	RK_TRACE (APP);
 
@@ -542,9 +557,19 @@ void RKHTMLWindowPart::initActions () {
 
 	// common actions
 	actionCollection ()->addAction (KStandardAction::Copy, "copy", window->view->pageAction (QWebPage::Copy), SLOT (trigger()));
+	QAction* zoom_in = actionCollection ()->addAction ("zoom_in", new KAction (KIcon ("zoom-in"), i18n ("Zoom In"), this));
+	connect (zoom_in, SIGNAL(triggered(bool)), window, SLOT (zoomIn()));
+	QAction* zoom_out = actionCollection ()->addAction ("zoom_out", new KAction (KIcon ("zoom-out"), i18n ("Zoom Out"), this));
+	connect (zoom_out, SIGNAL(triggered(bool)), window, SLOT (zoomOut()));
+	QAction* select_all = actionCollection ()->addAction (KStandardAction::SelectAll, "select_all", window->view->pageAction (QWebPage::SelectAll), SLOT (trigger()));
+	// unfortunately, this will only affect the default encoding, not necessarily the "real" encoding
+	KCodecAction *encoding = new KCodecAction (KIcon ("character-set"), i18n ("Default &Encoding"), this, true);
+	encoding->setStatusTip (i18n ("Set the encoding to assume in case no explicit encoding has been set in the page or in the HTTP headers."));
+	actionCollection ()->addAction ("view_encoding", encoding);
+	connect (encoding, SIGNAL (triggered(QTextCodec*)), window, SLOT (setTextEncoding(QTextCodec*)));
 
-	print = actionCollection ()->addAction (KStandardAction::Print, "print_help", window, SLOT (slotPrint()));
-	save_page = actionCollection ()->addAction (KStandardAction::Save, "save", window, SLOT (slotSave()));
+	print = actionCollection ()->addAction (KStandardAction::Print, "print_html", window, SLOT (slotPrint()));
+	save_page = actionCollection ()->addAction (KStandardAction::Save, "save_html", window, SLOT (slotSave()));
 
 	run_selection = RKStandardActions::runCurrent (window, window, SLOT (runSelection()));
 
@@ -564,19 +589,12 @@ void RKHTMLWindowPart::initActions () {
 	outputRefresh->setText (i18n ("&Refresh Output"));
 	outputRefresh->setIcon (KIcon ("view-refresh"));
 
-	QAction* zoom_in = actionCollection ()->addAction ("zoom_in", new KAction (KIcon ("zoom-in"), i18n ("Zoom In"), this));
-	connect (zoom_in, SIGNAL(triggered(bool)), window, SLOT (zoomIn()));
-	QAction* zoom_out = actionCollection ()->addAction ("zoom_out", new KAction (KIcon ("zoom-out"), i18n ("Zoom Out"), this));
-	connect (zoom_out, SIGNAL(triggered(bool)), window, SLOT (zoomOut()));
-
 	// TODO!!!
 	QAction* find;
 	QAction* findAhead;      // shortcut '/'
 	QAction* find_next;
 	QAction* find_previous;
-	QAction* select_all;
-	// needed? QAction* encoding;
-}
+
 
 void RKHTMLWindowPart::setOutputWindowSkin () {
 	RK_TRACE (APP);
@@ -653,7 +671,8 @@ bool RKHelpRenderer::renderRKHelp (const KUrl &url) {
 		element = help_xml->getChildElement (help_doc_element, "title", DL_WARNING);
 		page_title = help_xml->i18nElementText (element, false, DL_WARNING);
 	}
-	writeHTML ("<html><head><title>" + page_title + "</title><link rel=\"stylesheet\" type=\"text/css\" href=\"" + css_filename + "\"></head>\n<body><div id=\"main\">\n<h1>" + page_title + "</h1>\n");
+	writeHTML ("<html><head><title>" + page_title + "</title><link rel=\"stylesheet\" type=\"text/css\" href=\"" + css_filename + "\">"
+	           "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>\n<body><div id=\"main\">\n<h1>" + page_title + "</h1>\n");
 
 	if (help_doc_element.isNull ()) {
 		RK_ASSERT (for_component);
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index d22d3eb..c5a87e8 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -68,6 +68,7 @@ class RKHTMLWindow : public RKMDIWindow {
 	Q_OBJECT
 public:
 	enum WindowMode {
+		Undefined,
 		HTMLHelpWindow,
 		HTMLOutputWindow
 	};
@@ -107,6 +108,7 @@ public slots:
 	void refresh ();
 	void zoomIn ();
 	void zoomOut ();
+	void setTextEncoding (QTextCodec* encoding);
 private slots:
 	void scrollToBottom ();
 	void mimeTypeDetermined (KIO::Job*, const QString& type);
diff --git a/rkward/windows/rkoutputwindow.rc b/rkward/windows/rkoutputwindow.rc
index 64ce5f4..2aa6987 100644
--- a/rkward/windows/rkoutputwindow.rc
+++ b/rkward/windows/rkoutputwindow.rc
@@ -2,17 +2,20 @@
 <kpartgui name="rkward_outputwindow" version="640">
 	<MenuBar>
 		<Menu name="file"><text>&File</text>
-			<Action name="print_help"/>
-			<Action name="save"/>
+			<Action name="print_html"/>
+			<Action name="save_html"/>
 		</Menu>
 		<Menu name="edit"><text>&Edit</text>
 			<Action name="copy"/>
 			<Separator/>
+			<Action name="select_all"/>
+			<Separator/>
 			<Action name="output_flush"/>
 		</Menu>
 		<Menu name="view"><text>&View</text>
 			<Action name="zoom_in"/>
 			<Action name="zoom_out"/>
+			<Action name="view_encoding"/>
 			<Separator/>
 			<Action name="output_refresh"/>
 		</Menu>



More information about the rkward-tracker mailing list