• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
khtml_ext.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2000-2003 Simon Hausmann <hausmann@kde.org>
4  * 2001-2003 George Staikos <staikos@kde.org>
5  * 2001-2003 Laurent Montel <montel@kde.org>
6  * 2001-2003 Dirk Mueller <mueller@kde.org>
7  * 2001-2003 Waldo Bastian <bastian@kde.org>
8  * 2001-2003 David Faure <faure@kde.org>
9  * 2001-2003 Daniel Naber <dnaber@kde.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB. If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26 
27 #include "khtml_ext.h"
28 #include "khtmlview.h"
29 #include "khtml_pagecache.h"
30 #include "rendering/render_form.h"
31 #include "rendering/render_image.h"
32 #include "html/html_imageimpl.h"
33 #include "misc/loader.h"
34 #include "dom/html_form.h"
35 #include "dom/html_image.h"
36 #include "dom/dom_string.h"
37 #include "dom/html_document.h"
38 #include "dom/dom_element.h"
39 #include "xml/dom_elementimpl.h"
40 #include <QtGui/QClipboard>
41 #include <QtCore/QFileInfo>
42 #include <QtGui/QMenu>
43 #include <QtCore/QUrl>
44 #include <QtCore/QMetaEnum>
45 #include <assert.h>
46 
47 #include <kdebug.h>
48 #include <klocale.h>
49 #include <kfiledialog.h>
50 #include <kjobuidelegate.h>
51 #include <kio/job.h>
52 #include <kshell.h>
53 #include <ktoolbar.h>
54 #include <ksavefile.h>
55 #include <kstringhandler.h>
56 #include <ktoolinvocation.h>
57 #include <kmessagebox.h>
58 #include <kstandarddirs.h>
59 #include <krun.h>
60 #include <kurifilter.h>
61 #include <kicon.h>
62 #include <kiconloader.h>
63 #include <kdesktopfile.h>
64 #include <kinputdialog.h>
65 #include <ktemporaryfile.h>
66 #include "khtml_global.h"
67 #include <kstandardaction.h>
68 #include <kactioncollection.h>
69 #include <kactionmenu.h>
70 
71 #include "khtmlpart_p.h"
72 
73 KHTMLPartBrowserExtension::KHTMLPartBrowserExtension( KHTMLPart *parent )
74 : KParts::BrowserExtension( parent )
75 {
76  m_part = parent;
77  setURLDropHandlingEnabled( true );
78 
79  enableAction( "cut", false );
80  enableAction( "copy", false );
81  enableAction( "paste", false );
82 
83  m_connectedToClipboard = false;
84 }
85 
86 int KHTMLPartBrowserExtension::xOffset()
87 {
88  return m_part->view()->contentsX();
89 }
90 
91 int KHTMLPartBrowserExtension::yOffset()
92 {
93  return m_part->view()->contentsY();
94 }
95 
96 void KHTMLPartBrowserExtension::saveState( QDataStream &stream )
97 {
98  //kDebug( 6050 ) << "saveState!";
99  m_part->saveState( stream );
100 }
101 
102 void KHTMLPartBrowserExtension::restoreState( QDataStream &stream )
103 {
104  //kDebug( 6050 ) << "restoreState!";
105  m_part->restoreState( stream );
106 }
107 
108 void KHTMLPartBrowserExtension::editableWidgetFocused( QWidget *widget )
109 {
110  m_editableFormWidget = widget;
111  updateEditActions();
112 
113  if ( !m_connectedToClipboard && m_editableFormWidget )
114  {
115  connect( QApplication::clipboard(), SIGNAL(dataChanged()),
116  this, SLOT(updateEditActions()) );
117 
118  if ( m_editableFormWidget->inherits( "QLineEdit" ) || m_editableFormWidget->inherits( "QTextEdit" ) )
119  connect( m_editableFormWidget, SIGNAL(selectionChanged()),
120  this, SLOT(updateEditActions()) );
121 
122  m_connectedToClipboard = true;
123  }
124  editableWidgetFocused();
125 }
126 
127 void KHTMLPartBrowserExtension::editableWidgetBlurred( QWidget * /*widget*/ )
128 {
129  QWidget *oldWidget = m_editableFormWidget;
130 
131  m_editableFormWidget = 0;
132  enableAction( "cut", false );
133  enableAction( "paste", false );
134  m_part->emitSelectionChanged();
135 
136  if ( m_connectedToClipboard )
137  {
138  disconnect( QApplication::clipboard(), SIGNAL(dataChanged()),
139  this, SLOT(updateEditActions()) );
140 
141  if ( oldWidget )
142  {
143  if ( oldWidget->inherits( "QLineEdit" ) || oldWidget->inherits( "QTextEdit" ) )
144  disconnect( oldWidget, SIGNAL(selectionChanged()),
145  this, SLOT(updateEditActions()) );
146  }
147 
148  m_connectedToClipboard = false;
149  }
150  editableWidgetBlurred();
151 }
152 
153 void KHTMLPartBrowserExtension::setExtensionProxy( KParts::BrowserExtension *proxy )
154 {
155  if ( m_extensionProxy )
156  {
157  disconnect( m_extensionProxy, SIGNAL(enableAction(const char*,bool)),
158  this, SLOT(extensionProxyActionEnabled(const char*,bool)) );
159  if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) )
160  {
161  disconnect( m_extensionProxy, SIGNAL(editableWidgetFocused()),
162  this, SLOT(extensionProxyEditableWidgetFocused()) );
163  disconnect( m_extensionProxy, SIGNAL(editableWidgetBlurred()),
164  this, SLOT(extensionProxyEditableWidgetBlurred()) );
165  }
166  }
167 
168  m_extensionProxy = proxy;
169 
170  if ( m_extensionProxy )
171  {
172  connect( m_extensionProxy, SIGNAL(enableAction(const char*,bool)),
173  this, SLOT(extensionProxyActionEnabled(const char*,bool)) );
174  if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) )
175  {
176  connect( m_extensionProxy, SIGNAL(editableWidgetFocused()),
177  this, SLOT(extensionProxyEditableWidgetFocused()) );
178  connect( m_extensionProxy, SIGNAL(editableWidgetBlurred()),
179  this, SLOT(extensionProxyEditableWidgetBlurred()) );
180  }
181 
182  enableAction( "cut", m_extensionProxy->isActionEnabled( "cut" ) );
183  enableAction( "copy", m_extensionProxy->isActionEnabled( "copy" ) );
184  enableAction( "paste", m_extensionProxy->isActionEnabled( "paste" ) );
185  }
186  else
187  {
188  updateEditActions();
189  enableAction( "copy", false ); // ### re-check this
190  }
191 }
192 
193 void KHTMLPartBrowserExtension::cut()
194 {
195  if ( m_extensionProxy )
196  {
197  callExtensionProxyMethod( "cut" );
198  return;
199  }
200 
201  if ( !m_editableFormWidget )
202  return;
203 
204  QLineEdit* lineEdit = qobject_cast<QLineEdit *>( m_editableFormWidget );
205  if ( lineEdit && !lineEdit->isReadOnly() )
206  lineEdit->cut();
207  QTextEdit* textEdit = qobject_cast<QTextEdit *>( m_editableFormWidget );
208  if ( textEdit && !textEdit->isReadOnly() )
209  textEdit->cut();
210 }
211 
212 void KHTMLPartBrowserExtension::copy()
213 {
214  if ( m_extensionProxy )
215  {
216  callExtensionProxyMethod( "copy" );
217  return;
218  }
219 
220  if ( !m_editableFormWidget )
221  {
222  // get selected text and paste to the clipboard
223  QString text = m_part->selectedText();
224  text.replace( QChar( 0xa0 ), ' ' );
225  //kDebug(6050) << text;
226 
227  QClipboard *cb = QApplication::clipboard();
228  disconnect( cb, SIGNAL(selectionChanged()), m_part, SLOT(slotClearSelection()) );
229 #ifndef QT_NO_MIMECLIPBOARD
230  QString htmltext;
231  /*
232  * When selectionModeEnabled, that means the user has just selected
233  * the text, not ctrl+c to copy it. The selection clipboard
234  * doesn't seem to support mime type, so to save time, don't calculate
235  * the selected text as html.
236  * optomisation disabled for now until everything else works.
237  */
238  //if(!cb->selectionModeEnabled())
239  htmltext = m_part->selectedTextAsHTML();
240  QMimeData *mimeData = new QMimeData;
241  mimeData->setText(text);
242  if(!htmltext.isEmpty()) {
243  htmltext.replace( QChar( 0xa0 ), ' ' );
244  mimeData->setHtml(htmltext);
245  }
246  cb->setMimeData(mimeData);
247 #else
248  cb->setText(text);
249 #endif
250 
251  connect( cb, SIGNAL(selectionChanged()), m_part, SLOT(slotClearSelection()) );
252  }
253  else
254  {
255  QLineEdit* lineEdit = qobject_cast<QLineEdit *>( m_editableFormWidget );
256  if ( lineEdit )
257  lineEdit->copy();
258  QTextEdit* textEdit = qobject_cast<QTextEdit *>( m_editableFormWidget );
259  if ( textEdit )
260  textEdit->copy();
261  }
262 }
263 
264 void KHTMLPartBrowserExtension::searchProvider()
265 {
266  KAction *action = qobject_cast<KAction*>(sender());
267  if (action) {
268  KUrl url = action->data().toUrl();
269  if (url.host().isEmpty()) {
270  KUriFilterData data(action->data().toString());
271  if (KUriFilter::self()->filterSearchUri(data, KUriFilter::WebShortcutFilter))
272  url = data.uri();
273  }
274 
275  KParts::BrowserArguments browserArgs;
276  browserArgs.frameName = "_blank";
277  emit m_part->browserExtension()->openUrlRequest( url, KParts::OpenUrlArguments(), browserArgs );
278  }
279 }
280 
281 void KHTMLPartBrowserExtension::paste()
282 {
283  if ( m_extensionProxy )
284  {
285  callExtensionProxyMethod( "paste" );
286  return;
287  }
288 
289  if ( !m_editableFormWidget )
290  return;
291 
292  QLineEdit* lineEdit = qobject_cast<QLineEdit *>( m_editableFormWidget );
293  if ( lineEdit && !lineEdit->isReadOnly() )
294  lineEdit->paste();
295  QTextEdit* textEdit = qobject_cast<QTextEdit *>( m_editableFormWidget );
296  if ( textEdit && !textEdit->isReadOnly() )
297  textEdit->paste();
298 }
299 
300 void KHTMLPartBrowserExtension::callExtensionProxyMethod( const char *method )
301 {
302  if ( !m_extensionProxy )
303  return;
304 
305  QMetaObject::invokeMethod(m_extensionProxy, method, Qt::DirectConnection);
306 }
307 
308 void KHTMLPartBrowserExtension::updateEditActions()
309 {
310  if ( !m_editableFormWidget )
311  {
312  enableAction( "cut", false );
313  enableAction( "copy", false );
314  enableAction( "paste", false );
315  return;
316  }
317 
318  // ### duplicated from KonqMainWindow::slotClipboardDataChanged
319 #ifndef QT_NO_MIMECLIPBOARD // Handle minimalized versions of Qt Embedded
320  const QMimeData *data = QApplication::clipboard()->mimeData();
321  enableAction( "paste", data->hasFormat( "text/plain" ) );
322 #else
323  QString data=QApplication::clipboard()->text();
324  enableAction( "paste", data.contains("://"));
325 #endif
326  bool hasSelection = false;
327 
328  if( m_editableFormWidget) {
329  if ( qobject_cast<QLineEdit*>(m_editableFormWidget))
330  hasSelection = static_cast<QLineEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
331  else if(qobject_cast<QTextEdit*>(m_editableFormWidget))
332  hasSelection = static_cast<QTextEdit *>( &(*m_editableFormWidget) )->textCursor().hasSelection();
333  }
334 
335  enableAction( "copy", hasSelection );
336  enableAction( "cut", hasSelection );
337 }
338 
339 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetFocused() {
340  editableWidgetFocused();
341 }
342 
343 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetBlurred() {
344  editableWidgetBlurred();
345 }
346 
347 void KHTMLPartBrowserExtension::extensionProxyActionEnabled( const char *action, bool enable )
348 {
349  // only forward enableAction calls for actions we actually do forward
350  if ( strcmp( action, "cut" ) == 0 ||
351  strcmp( action, "copy" ) == 0 ||
352  strcmp( action, "paste" ) == 0 ) {
353  enableAction( action, enable );
354  }
355 }
356 
357 void KHTMLPartBrowserExtension::reparseConfiguration()
358 {
359  m_part->reparseConfiguration();
360 }
361 
362 void KHTMLPartBrowserExtension::print()
363 {
364  m_part->view()->print();
365 }
366 
367 void KHTMLPartBrowserExtension::disableScrolling()
368 {
369  QScrollArea *scrollArea = m_part->view();
370  if (scrollArea) {
371  scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
372  scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
373  }
374 }
375 
376 class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate
377 {
378 public:
379  KHTMLPart *m_khtml;
380  KUrl m_url;
381  KUrl m_imageURL;
382  QPixmap m_pixmap;
383  QString m_suggestedFilename;
384  KActionCollection* m_actionCollection;
385  KParts::BrowserExtension::ActionGroupMap actionGroups;
386 };
387 
388 
389 KHTMLPopupGUIClient::KHTMLPopupGUIClient( KHTMLPart *khtml, const KUrl &url )
390  : QObject( khtml ), d(new KHTMLPopupGUIClientPrivate)
391 {
392  d->m_khtml = khtml;
393  d->m_url = url;
394  d->m_actionCollection = new KActionCollection(this);
395  bool isImage = false;
396  bool hasSelection = khtml->hasSelection();
397 
398  DOM::Element e = khtml->nodeUnderMouse();
399 
400  if ( !e.isNull() && (e.elementId() == ID_IMG ||
401  (e.elementId() == ID_INPUT && !static_cast<DOM::HTMLInputElement>(e).src().isEmpty())))
402  {
403  if (e.elementId() == ID_IMG) {
404  DOM::HTMLImageElementImpl *ie = static_cast<DOM::HTMLImageElementImpl*>(e.handle());
405  khtml::RenderImage *ri = dynamic_cast<khtml::RenderImage*>(ie->renderer());
406  if (ri && ri->contentObject()) {
407  d->m_suggestedFilename = static_cast<khtml::CachedImage*>(ri->contentObject())->suggestedFilename();
408  }
409  }
410  isImage=true;
411  }
412 
413  if (hasSelection) {
414  QList<QAction *> editActions;
415  QAction* copyAction = d->m_actionCollection->addAction( KStandardAction::Copy, "copy",
416  d->m_khtml->browserExtension(), SLOT(copy()) );
417 
418  copyAction->setText(i18n("&Copy Text"));
419  copyAction->setEnabled(d->m_khtml->browserExtension()->isActionEnabled( "copy" ));
420  editActions.append(copyAction);
421 
422  editActions.append(khtml->actionCollection()->action("selectAll"));
423 
424  addSearchActions(editActions);
425 
426  QString selectedTextURL = selectedTextAsOneLine(d->m_khtml);
427  if ( selectedTextURL.contains("://") && KUrl(selectedTextURL).isValid() ) {
428  if (selectedTextURL.length() > 18) {
429  selectedTextURL.truncate(15);
430  selectedTextURL += "...";
431  }
432  KAction *action = new KAction(i18n("Open '%1'", selectedTextURL), this);
433  d->m_actionCollection->addAction( "openSelection", action );
434  action->setIcon( KIcon( "window-new" ) );
435  connect( action, SIGNAL(triggered(bool)), this, SLOT(openSelection()) );
436  editActions.append(action);
437  }
438 
439  KAction* separator = new KAction(d->m_actionCollection);
440  separator->setSeparator(true);
441  editActions.append(separator);
442 
443  d->actionGroups.insert("editactions", editActions);
444  }
445 
446  if (!url.isEmpty()) {
447  QList<QAction *> linkActions;
448  if (url.protocol() == "mailto") {
449  KAction *action = new KAction( i18n( "&Copy Email Address" ), this );
450  d->m_actionCollection->addAction( "copylinklocation", action );
451  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCopyLinkLocation()) );
452  linkActions.append(action);
453  } else {
454  KAction *action = new KAction( i18n( "&Save Link As..." ), this );
455  d->m_actionCollection->addAction( "savelinkas", action );
456  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotSaveLinkAs()) );
457  linkActions.append(action);
458 
459  action = new KAction( i18n( "&Copy Link Address" ), this );
460  d->m_actionCollection->addAction( "copylinklocation", action );
461  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCopyLinkLocation()) );
462  linkActions.append(action);
463  }
464  d->actionGroups.insert("linkactions", linkActions);
465  }
466 
467  QList<QAction *> partActions;
468  // frameset? -> add "Reload Frame" etc.
469  if (!hasSelection) {
470  if ( khtml->parentPart() ) {
471  KActionMenu* menu = new KActionMenu( i18nc("@title:menu HTML frame/iframe", "Frame"), this);
472  KAction *action = new KAction( i18n( "Open in New &Window" ), this );
473  d->m_actionCollection->addAction( "frameinwindow", action );
474  action->setIcon( KIcon( "window-new" ) );
475  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotFrameInWindow()) );
476  menu->addAction(action);
477 
478  action = new KAction( i18n( "Open in &This Window" ), this );
479  d->m_actionCollection->addAction( "frameintop", action );
480  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotFrameInTop()) );
481  menu->addAction(action);
482 
483  action = new KAction( i18n( "Open in &New Tab" ), this );
484  d->m_actionCollection->addAction( "frameintab", action );
485  action->setIcon( KIcon( "tab-new" ) );
486  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotFrameInTab()) );
487  menu->addAction(action);
488 
489  action = new KAction(d->m_actionCollection);
490  action->setSeparator(true);
491  menu->addAction(action);
492 
493  action = new KAction( i18n( "Reload Frame" ), this );
494  d->m_actionCollection->addAction( "reloadframe", action );
495  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotReloadFrame()) );
496  menu->addAction(action);
497 
498  action = new KAction( i18n( "Print Frame..." ), this );
499  d->m_actionCollection->addAction( "printFrame", action );
500  action->setIcon( KIcon( "document-print-frame" ) );
501  connect( action, SIGNAL(triggered(bool)), d->m_khtml->browserExtension(), SLOT(print()) );
502  menu->addAction(action);
503 
504  action = new KAction( i18n( "Save &Frame As..." ), this );
505  d->m_actionCollection->addAction( "saveFrame", action );
506  connect( action, SIGNAL(triggered(bool)), d->m_khtml, SLOT(slotSaveFrame()) );
507  menu->addAction(action);
508 
509  action = new KAction( i18n( "View Frame Source" ), this );
510  d->m_actionCollection->addAction( "viewFrameSource", action );
511  connect( action, SIGNAL(triggered(bool)), d->m_khtml, SLOT(slotViewDocumentSource()) );
512  menu->addAction(action);
513 
514  action = new KAction( i18n( "View Frame Information" ), this );
515  d->m_actionCollection->addAction( "viewFrameInfo", action );
516  connect( action, SIGNAL(triggered(bool)), d->m_khtml, SLOT(slotViewPageInfo()) );
517 
518  action = new KAction(d->m_actionCollection);
519  action->setSeparator(true);
520  menu->addAction(action);
521 
522  if ( KHTMLGlobal::defaultHTMLSettings()->isAdFilterEnabled() ) {
523  if ( khtml->d->m_frame->m_type == khtml::ChildFrame::IFrame ) {
524  action = new KAction( i18n( "Block IFrame..." ), this );
525  d->m_actionCollection->addAction( "blockiframe", action );
526  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotBlockIFrame()) );
527  menu->addAction(action);
528  }
529  }
530 
531  partActions.append(menu);
532  }
533  }
534 
535  if (isImage) {
536  if ( e.elementId() == ID_IMG ) {
537  d->m_imageURL = KUrl( static_cast<DOM::HTMLImageElement>( e ).src().string() );
538  DOM::HTMLImageElementImpl *imageimpl = static_cast<DOM::HTMLImageElementImpl *>( e.handle() );
539  Q_ASSERT(imageimpl);
540  if(imageimpl) // should be true always. right?
541  {
542  if(imageimpl->complete()) {
543  d->m_pixmap = imageimpl->currentPixmap();
544  }
545  }
546  }
547  else
548  d->m_imageURL = KUrl( static_cast<DOM::HTMLInputElement>( e ).src().string() );
549  KAction *action = new KAction( i18n( "Save Image As..." ), this );
550  d->m_actionCollection->addAction( "saveimageas", action );
551  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotSaveImageAs()) );
552  partActions.append(action);
553 
554  action = new KAction( i18n( "Send Image..." ), this );
555  d->m_actionCollection->addAction( "sendimage", action );
556  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotSendImage()) );
557  partActions.append(action);
558 
559 #ifndef QT_NO_MIMECLIPBOARD
560  action = new KAction( i18n( "Copy Image" ), this );
561  d->m_actionCollection->addAction( "copyimage", action );
562  action->setEnabled(!d->m_pixmap.isNull());
563  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCopyImage()) );
564  partActions.append(action);
565 #endif
566 
567  if(d->m_pixmap.isNull()) { //fallback to image location if still loading the image. this will always be true if ifdef QT_NO_MIMECLIPBOARD
568  action = new KAction( i18n( "Copy Image Location" ), this );
569  d->m_actionCollection->addAction( "copyimagelocation", action );
570  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotCopyImageLocation()) );
571  partActions.append(action);
572  }
573 
574  QString actionText = d->m_suggestedFilename.isEmpty() ?
575  KStringHandler::csqueeze(d->m_imageURL.fileName()+d->m_imageURL.query(), 25)
576  : d->m_suggestedFilename;
577  action = new KAction( i18n("View Image (%1)", actionText.replace("&", "&&")), this );
578  d->m_actionCollection->addAction( "viewimage", action );
579  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotViewImage()) );
580  partActions.append(action);
581 
582  if (KHTMLGlobal::defaultHTMLSettings()->isAdFilterEnabled()) {
583  action = new KAction( i18n( "Block Image..." ), this );
584  d->m_actionCollection->addAction( "blockimage", action );
585  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotBlockImage()) );
586  partActions.append(action);
587 
588  if (!d->m_imageURL.host().isEmpty() &&
589  !d->m_imageURL.protocol().isEmpty())
590  {
591  action = new KAction( i18n( "Block Images From %1" , d->m_imageURL.host()), this );
592  d->m_actionCollection->addAction( "blockhost", action );
593  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotBlockHost()) );
594  partActions.append(action);
595  }
596  }
597  KAction* separator = new KAction(d->m_actionCollection);
598  separator->setSeparator(true);
599  partActions.append(separator);
600  }
601 
602  if ( isImage || url.isEmpty() ) {
603  KAction *action = new KAction( i18n( "Stop Animations" ), this );
604  d->m_actionCollection->addAction( "stopanimations", action );
605  connect( action, SIGNAL(triggered(bool)), this, SLOT(slotStopAnimations()) );
606  partActions.append(action);
607  KAction* separator = new KAction(d->m_actionCollection);
608  separator->setSeparator(true);
609  partActions.append(separator);
610  }
611  if (!hasSelection && url.isEmpty()) { // only when right-clicking on the page itself
612  partActions.append(khtml->actionCollection()->action("viewDocumentSource"));
613  }
614  if (!hasSelection && url.isEmpty() && !isImage) {
615  partActions.append(khtml->actionCollection()->action("setEncoding"));
616  }
617  d->actionGroups.insert("partactions", partActions);
618 }
619 
620 KHTMLPopupGUIClient::~KHTMLPopupGUIClient()
621 {
622  delete d->m_actionCollection;
623  delete d;
624 }
625 
626 void KHTMLPopupGUIClient::addSearchActions(QList<QAction *>& editActions)
627 {
628  const QString selectedText = d->m_khtml->simplifiedSelectedText();
629  if (selectedText.isEmpty())
630  return;
631 
632  KUriFilterData data(selectedText);
633  QStringList alternateProviders;
634  alternateProviders << "google" << "google_groups" << "google_news" << "webster" << "dmoz" << "wikipedia";
635  data.setAlternateSearchProviders(alternateProviders);
636  data.setAlternateDefaultSearchProvider("google");
637 
638  if (KUriFilter::self()->filterSearchUri(data, KUriFilter::NormalTextFilter)) {
639  const QString squeezedText = KStringHandler::rsqueeze(selectedText, 21);
640  KAction *action = new KAction(i18n("Search for '%1' with %2",
641  squeezedText, data.searchProvider()), this);
642  action->setData(QUrl(data.uri()));
643  action->setIcon(KIcon(data.iconName()));
644  connect(action, SIGNAL(triggered(bool)), d->m_khtml->browserExtension(), SLOT(searchProvider()));
645  d->m_actionCollection->addAction("defaultSearchProvider", action);
646  editActions.append(action);
647 
648  const QStringList preferredSearchProviders = data.preferredSearchProviders();
649  if (!preferredSearchProviders.isEmpty()) {
650  KActionMenu* providerList = new KActionMenu(i18n("Search for '%1' with", squeezedText), this);
651  Q_FOREACH(const QString &searchProvider, preferredSearchProviders) {
652  if (searchProvider == data.searchProvider())
653  continue;
654  KAction *action = new KAction(searchProvider, this);
655  action->setData(data.queryForPreferredSearchProvider(searchProvider));
656  d->m_actionCollection->addAction(searchProvider, action);
657  action->setIcon(KIcon(data.iconNameForPreferredSearchProvider(searchProvider)));
658  connect(action, SIGNAL(triggered(bool)), d->m_khtml->browserExtension(), SLOT(searchProvider()));
659  providerList->addAction(action);
660  }
661  d->m_actionCollection->addAction("searchProviderList", providerList);
662  editActions.append(providerList);
663  }
664  }
665 }
666 
667 QString KHTMLPopupGUIClient::selectedTextAsOneLine(KHTMLPart* part)
668 {
669  QString text = part->simplifiedSelectedText();
670  // in addition to what simplifiedSelectedText does,
671  // remove linefeeds and any whitespace surrounding it (#113177),
672  // to get it all in a single line.
673  text.remove(QRegExp("[\\s]*\\n+[\\s]*"));
674  return text;
675 }
676 
677 void KHTMLPopupGUIClient::openSelection()
678 {
679  KParts::BrowserArguments browserArgs;
680  browserArgs.frameName = "_blank";
681 
682  emit d->m_khtml->browserExtension()->openUrlRequest(selectedTextAsOneLine(d->m_khtml), KParts::OpenUrlArguments(), browserArgs);
683 }
684 
685 KParts::BrowserExtension::ActionGroupMap KHTMLPopupGUIClient::actionGroups() const
686 {
687  return d->actionGroups;
688 }
689 
690 void KHTMLPopupGUIClient::slotSaveLinkAs()
691 {
692  KIO::MetaData metaData;
693  metaData["referrer"] = d->m_khtml->referrer();
694  saveURL( d->m_khtml->widget(), i18n( "Save Link As" ), d->m_url, metaData );
695 }
696 
697 void KHTMLPopupGUIClient::slotSendImage()
698 {
699  QStringList urls;
700  urls.append( d->m_imageURL.url());
701  QString subject = d->m_imageURL.url();
702  KToolInvocation::invokeMailer(QString(), QString(), QString(), subject,
703  QString(), //body
704  QString(),
705  urls); // attachments
706 
707 
708 }
709 
710 void KHTMLPopupGUIClient::slotSaveImageAs()
711 {
712  KIO::MetaData metaData;
713  metaData["referrer"] = d->m_khtml->referrer();
714  saveURL( d->m_khtml->widget(), i18n( "Save Image As" ), d->m_imageURL, metaData, QString(), 0, d->m_suggestedFilename );
715 }
716 
717 void KHTMLPopupGUIClient::slotBlockHost()
718 {
719  QString name=d->m_imageURL.protocol()+"://"+d->m_imageURL.host()+"/*";
720  KHTMLGlobal::defaultHTMLSettings()->addAdFilter( name );
721  d->m_khtml->reparseConfiguration();
722 }
723 
724 void KHTMLPopupGUIClient::slotBlockImage()
725 {
726  bool ok = false;
727 
728  QString url = KInputDialog::getText( i18n("Add URL to Filter"),
729  i18n("Enter the URL:"),
730  d->m_imageURL.url(),
731  &ok);
732  if ( ok ) {
733  KHTMLGlobal::defaultHTMLSettings()->addAdFilter( url );
734  d->m_khtml->reparseConfiguration();
735  }
736 }
737 
738 void KHTMLPopupGUIClient::slotBlockIFrame()
739 {
740  bool ok = false;
741  QString url = KInputDialog::getText( i18n( "Add URL to Filter"),
742  i18n("Enter the URL:"),
743  d->m_khtml->url().url(),
744  &ok );
745  if ( ok ) {
746  KHTMLGlobal::defaultHTMLSettings()->addAdFilter( url );
747  d->m_khtml->reparseConfiguration();
748  }
749 }
750 
751 void KHTMLPopupGUIClient::slotCopyLinkLocation()
752 {
753  KUrl safeURL(d->m_url);
754  safeURL.setPass(QString());
755 #ifndef QT_NO_MIMECLIPBOARD
756  // Set it in both the mouse selection and in the clipboard
757  QMimeData* mimeData = new QMimeData;
758  safeURL.populateMimeData( mimeData );
759  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Clipboard );
760 
761  mimeData = new QMimeData;
762  safeURL.populateMimeData( mimeData );
763  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Selection );
764 
765 #else
766  QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries
767 #endif
768 }
769 
770 void KHTMLPopupGUIClient::slotStopAnimations()
771 {
772  d->m_khtml->stopAnimations();
773 }
774 
775 void KHTMLPopupGUIClient::slotCopyImage()
776 {
777 #ifndef QT_NO_MIMECLIPBOARD
778  KUrl safeURL(d->m_imageURL);
779  safeURL.setPass(QString());
780 
781  // Set it in both the mouse selection and in the clipboard
782  QMimeData* mimeData = new QMimeData;
783  mimeData->setImageData( d->m_pixmap );
784  safeURL.populateMimeData( mimeData );
785  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Clipboard );
786 
787  mimeData = new QMimeData;
788  mimeData->setImageData( d->m_pixmap );
789  safeURL.populateMimeData( mimeData );
790  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Selection );
791 #else
792  kDebug() << "slotCopyImage called when the clipboard does not support this. This should not be possible.";
793 #endif
794 }
795 
796 void KHTMLPopupGUIClient::slotCopyImageLocation()
797 {
798  KUrl safeURL(d->m_imageURL);
799  safeURL.setPass(QString());
800 #ifndef QT_NO_MIMECLIPBOARD
801  // Set it in both the mouse selection and in the clipboard
802  QMimeData* mimeData = new QMimeData;
803  safeURL.populateMimeData( mimeData );
804  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Clipboard );
805  mimeData = new QMimeData;
806  safeURL.populateMimeData( mimeData );
807  QApplication::clipboard()->setMimeData( mimeData, QClipboard::Selection );
808 #else
809  QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries
810 #endif
811 }
812 
813 void KHTMLPopupGUIClient::slotViewImage()
814 {
815  d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL);
816 }
817 
818 void KHTMLPopupGUIClient::slotReloadFrame()
819 {
820  KParts::OpenUrlArguments args = d->m_khtml->arguments();
821  args.setReload( true );
822  args.metaData()["referrer"] = d->m_khtml->pageReferrer();
823  // reload document
824  d->m_khtml->closeUrl();
825  d->m_khtml->setArguments( args );
826  d->m_khtml->openUrl( d->m_khtml->url() );
827 }
828 
829 void KHTMLPopupGUIClient::slotFrameInWindow()
830 {
831  KParts::OpenUrlArguments args = d->m_khtml->arguments();
832  args.metaData()["referrer"] = d->m_khtml->pageReferrer();
833  KParts::BrowserArguments browserArgs( d->m_khtml->browserExtension()->browserArguments() );
834  browserArgs.setForcesNewWindow(true);
835  emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args, browserArgs );
836 }
837 
838 void KHTMLPopupGUIClient::slotFrameInTop()
839 {
840  KParts::OpenUrlArguments args = d->m_khtml->arguments();
841  args.metaData()["referrer"] = d->m_khtml->pageReferrer();
842  KParts::BrowserArguments browserArgs( d->m_khtml->browserExtension()->browserArguments() );
843  browserArgs.frameName = "_top";
844  emit d->m_khtml->browserExtension()->openUrlRequest( d->m_khtml->url(), args, browserArgs );
845 }
846 
847 void KHTMLPopupGUIClient::slotFrameInTab()
848 {
849  KParts::OpenUrlArguments args = d->m_khtml->arguments();
850  args.metaData()["referrer"] = d->m_khtml->pageReferrer();
851  KParts::BrowserArguments browserArgs( d->m_khtml->browserExtension()->browserArguments() );
852  browserArgs.setNewTab(true);
853  emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args, browserArgs );
854 }
855 
856 void KHTMLPopupGUIClient::saveURL( QWidget *parent, const QString &caption,
857  const KUrl &url,
858  const QMap<QString, QString> &metadata,
859  const QString &filter, long cacheId,
860  const QString & suggestedFilename )
861 {
862  QString name = QLatin1String( "index.html" );
863  if ( !suggestedFilename.isEmpty() )
864  name = suggestedFilename;
865  else if ( !url.fileName(KUrl::ObeyTrailingSlash).isEmpty() )
866  name = url.fileName(KUrl::ObeyTrailingSlash);
867 
868  KUrl destURL;
869  int query;
870  do {
871  query = KMessageBox::Yes;
872  // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202)
873  destURL = KFileDialog::getSaveUrl( KUrl::fromPath(name), filter, parent, caption );
874  if( destURL.isLocalFile() )
875  {
876  QFileInfo info( destURL.toLocalFile() );
877  if( info.exists() ) {
878  // TODO: use KIO::RenameDlg (shows more information)
879  query = KMessageBox::warningContinueCancel( parent, i18n( "A file named \"%1\" already exists. " "Are you sure you want to overwrite it?" , info.fileName() ), i18n( "Overwrite File?" ), KGuiItem(i18n( "Overwrite" )) );
880  }
881  }
882  } while ( query == KMessageBox::Cancel );
883 
884  if ( destURL.isValid() )
885  saveURL(parent, url, destURL, metadata, cacheId);
886 }
887 
888 void KHTMLPopupGUIClient::saveURL( QWidget* parent, const KUrl &url, const KUrl &destURL,
889  const QMap<QString, QString> &metadata,
890  long cacheId )
891 {
892  if ( destURL.isValid() )
893  {
894  bool saved = false;
895  if (KHTMLPageCache::self()->isComplete(cacheId))
896  {
897  if (destURL.isLocalFile())
898  {
899  KSaveFile destFile(destURL.toLocalFile());
900  if (destFile.open())
901  {
902  QDataStream stream ( &destFile );
903  KHTMLPageCache::self()->saveData(cacheId, &stream);
904  saved = true;
905  }
906  }
907  else
908  {
909  // save to temp file, then move to final destination.
910  KTemporaryFile destFile;
911  if (destFile.open())
912  {
913  QDataStream stream ( &destFile );
914  KHTMLPageCache::self()->saveData(cacheId, &stream);
915  KUrl url2 = KUrl();
916  url2.setPath(destFile.fileName());
917  KIO::file_move(url2, destURL, -1, KIO::Overwrite);
918  saved = true;
919  }
920  }
921  }
922  if(!saved)
923  {
924  // DownloadManager <-> konqueror integration
925  // find if the integration is enabled
926  // the empty key means no integration
927  // only use download manager for non-local urls!
928  bool downloadViaKIO = true;
929  if ( !url.isLocalFile() )
930  {
931  KConfigGroup cfg = KSharedConfig::openConfig("konquerorrc", KConfig::NoGlobals)->group("HTML Settings");
932  QString downloadManger = cfg.readPathEntry("DownloadManager", QString());
933  if (!downloadManger.isEmpty())
934  {
935  // then find the download manager location
936  kDebug(1000) << "Using: "<<downloadManger <<" as Download Manager";
937  QString cmd = KStandardDirs::findExe(downloadManger);
938  if (cmd.isEmpty())
939  {
940  QString errMsg=i18n("The Download Manager (%1) could not be found in your $PATH ", downloadManger);
941  QString errMsgEx= i18n("Try to reinstall it \n\nThe integration with Konqueror will be disabled.");
942  KMessageBox::detailedSorry(0,errMsg,errMsgEx);
943  cfg.writePathEntry("DownloadManager",QString());
944  cfg.sync ();
945  }
946  else
947  {
948  downloadViaKIO = false;
949  KUrl cleanDest = destURL;
950  cleanDest.setPass( QString() ); // don't put password into commandline
951  cmd += ' ' + KShell::quoteArg(url.url()) + ' ' +
952  KShell::quoteArg(cleanDest.url());
953  kDebug(1000) << "Calling command "<<cmd;
954  KRun::runCommand(cmd, parent->topLevelWidget());
955  }
956  }
957  }
958 
959  if ( downloadViaKIO )
960  {
961  KParts::BrowserRun::saveUrlUsingKIO(url, destURL, parent, metadata);
962  }
963  } //end if(!saved)
964  }
965 }
966 
967 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension( KHTMLPart *part )
968 : KParts::BrowserHostExtension( part )
969 {
970  m_part = part;
971 }
972 
973 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension()
974 {
975 }
976 
977 QStringList KHTMLPartBrowserHostExtension::frameNames() const
978 {
979  return m_part->frameNames();
980 }
981 
982 const QList<KParts::ReadOnlyPart*> KHTMLPartBrowserHostExtension::frames() const
983 {
984  return m_part->frames();
985 }
986 
987 bool KHTMLPartBrowserHostExtension::openUrlInFrame(const KUrl &url, const KParts::OpenUrlArguments& arguments, const KParts::BrowserArguments &browserArguments)
988 {
989  return m_part->openUrlInFrame( url, arguments, browserArguments );
990 }
991 
992 KParts::BrowserHostExtension* KHTMLPartBrowserHostExtension::findFrameParent( KParts::ReadOnlyPart
993  *callingPart, const QString &frame )
994 {
995  KHTMLPart *parentPart = m_part->d->findFrameParent(callingPart, frame, 0, true /* navigation*/);
996  if (parentPart)
997  return parentPart->browserHostExtension();
998  return 0;
999 }
1000 
1001 
1002 // defined in khtml_part.cpp
1003 extern const int KDE_NO_EXPORT fastZoomSizes[];
1004 extern const int KDE_NO_EXPORT fastZoomSizeCount;
1005 
1006 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &icon, const QString &text, QObject *parent )
1007  : KSelectAction( text, parent )
1008 {
1009  setIcon( KIcon( icon ) );
1010 
1011  setToolBarMode(MenuMode);
1012  setToolButtonPopupMode(QToolButton::DelayedPopup);
1013 
1014  init(part, direction);
1015 }
1016 
1017 void KHTMLZoomFactorAction::init(KHTMLPart *part, bool direction)
1018 {
1019  m_direction = direction;
1020  m_part = part;
1021 
1022  // xgettext: no-c-format
1023  addAction( i18n( "Default Font Size (100%)" ) );
1024 
1025  int m = m_direction ? 1 : -1;
1026  int ofs = fastZoomSizeCount / 2; // take index of 100%
1027 
1028  // this only works if there is an odd number of elements in fastZoomSizes[]
1029  for ( int i = m; i != m*(ofs+1); i += m )
1030  {
1031  int num = i * m;
1032  QString numStr = QString::number( num );
1033  if ( num > 0 ) numStr.prepend( QLatin1Char('+') );
1034 
1035  // xgettext: no-c-format
1036  addAction( i18n( "%1%" , fastZoomSizes[ofs + i] ) );
1037  }
1038 
1039  connect( selectableActionGroup(), SIGNAL(triggered(QAction*)), this, SLOT(slotTriggered(QAction*)) );
1040 }
1041 
1042 KHTMLZoomFactorAction::~KHTMLZoomFactorAction()
1043 {
1044 }
1045 
1046 void KHTMLZoomFactorAction::slotTriggered(QAction* action)
1047 {
1048  int idx = selectableActionGroup()->actions().indexOf(action);
1049 
1050  if (idx == 0)
1051  m_part->setFontScaleFactor(100);
1052  else
1053  m_part->setFontScaleFactor(fastZoomSizes[fastZoomSizeCount/2 + (m_direction ? 1 : -1)*idx]);
1054  setCurrentAction( 0L );
1055 }
1056 
1057 KHTMLTextExtension::KHTMLTextExtension(KHTMLPart* part)
1058  : KParts::TextExtension(part)
1059 {
1060  connect(part, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
1061 }
1062 
1063 KHTMLPart* KHTMLTextExtension::part() const
1064 {
1065  return static_cast<KHTMLPart*>(parent());
1066 }
1067 
1068 bool KHTMLTextExtension::hasSelection() const
1069 {
1070  return part()->hasSelection();
1071 }
1072 
1073 QString KHTMLTextExtension::selectedText(Format format) const
1074 {
1075  switch(format) {
1076  case PlainText:
1077  return part()->selectedText();
1078  case HTML:
1079  return part()->selectedTextAsHTML();
1080  }
1081  return QString();
1082 }
1083 
1084 QString KHTMLTextExtension::completeText(Format format) const
1085 {
1086  switch(format) {
1087  case PlainText:
1088  return part()->htmlDocument().body().innerText().string();
1089  case HTML:
1090  return part()->htmlDocument().body().innerHTML().string();
1091  }
1092  return QString();
1093 }
1094 
1096 
1097 KHTMLHtmlExtension::KHTMLHtmlExtension(KHTMLPart* part)
1098  : KParts::HtmlExtension(part)
1099 {
1100 }
1101 
1102 KUrl KHTMLHtmlExtension::baseUrl() const
1103 {
1104  return part()->baseURL();
1105 }
1106 
1107 bool KHTMLHtmlExtension::hasSelection() const
1108 {
1109  return part()->hasSelection();
1110 }
1111 
1112 KParts::SelectorInterface::QueryMethods KHTMLHtmlExtension::supportedQueryMethods() const
1113 {
1114  return (KParts::SelectorInterface::SelectedContent | KParts::SelectorInterface::EntireContent);
1115 }
1116 
1117 static KParts::SelectorInterface::Element convertDomElement(const DOM::ElementImpl* domElem)
1118 {
1119  KParts::SelectorInterface::Element elem;
1120  elem.setTagName(domElem->tagName().string());
1121  const DOM::NamedAttrMapImpl* attrMap = domElem->attributes(true /*readonly*/);
1122  if (attrMap) {
1123  for (unsigned i = 0; i < attrMap->length(); ++i) {
1124  const DOM::AttributeImpl& attr = attrMap->attributeAt(i);
1125  elem.setAttribute(attr.localName().string(), attr.value().string());
1126  // we could have a setAttributeNS too.
1127  }
1128  }
1129  return elem;
1130 }
1131 
1132 KParts::SelectorInterface::Element KHTMLHtmlExtension::querySelector(const QString& query, KParts::SelectorInterface::QueryMethod method) const
1133 {
1134  KParts::SelectorInterface::Element element;
1135 
1136  // If the specified method is None, return an empty list; similarly
1137  // if the document is null, which may be possible in case of an error
1138  if (method == KParts::SelectorInterface::None || part()->document().isNull())
1139  return element;
1140 
1141  if (!(supportedQueryMethods() & method))
1142  return element;
1143 
1144  switch (method) {
1145  case KParts::SelectorInterface::EntireContent: {
1146  int ec = 0; // exceptions are ignored
1147  WTF::RefPtr<DOM::ElementImpl> domElem = part()->document().handle()->querySelector(query, ec);
1148  element = convertDomElement(domElem.get());
1149  break;
1150  }
1151  case KParts::SelectorInterface::SelectedContent:
1152  if (part()->hasSelection()) {
1153  DOM::Element domElem = part()->selection().cloneContents().querySelector(query);
1154  element = convertDomElement(static_cast<DOM::ElementImpl*>(domElem.handle()));
1155  }
1156  break;
1157  default:
1158  break;
1159  }
1160 
1161  return element;
1162 }
1163 
1164 QList<KParts::SelectorInterface::Element> KHTMLHtmlExtension::querySelectorAll(const QString& query, KParts::SelectorInterface::QueryMethod method) const
1165 {
1166  QList<KParts::SelectorInterface::Element> elements;
1167 
1168  // If the specified method is None, return an empty list; similarly
1169  // if the document is null, which may be possible in case of an error
1170  if (method == KParts::SelectorInterface::None || part()->document().isNull())
1171  return elements;
1172 
1173  // If the specified method is not supported, return an empty list...
1174  if (!(supportedQueryMethods() & method))
1175  return elements;
1176 
1177  switch (method) {
1178  case KParts::SelectorInterface::EntireContent: {
1179  int ec = 0; // exceptions are ignored
1180  WTF::RefPtr<DOM::NodeListImpl> nodes = part()->document().handle()->querySelectorAll(query, ec);
1181  const unsigned long len = nodes->length();
1182  elements.reserve(len);
1183  for (unsigned long i = 0; i < len; ++i) {
1184  DOM::NodeImpl* node = nodes->item(i);
1185  if (node->isElementNode()) { // should be always true
1186  elements.append(convertDomElement(static_cast<DOM::ElementImpl*>(node)));
1187  }
1188  }
1189  break;
1190  }
1191  case KParts::SelectorInterface::SelectedContent:
1192  if (part()->hasSelection()) {
1193  DOM::NodeList nodes = part()->selection().cloneContents().querySelectorAll(query);
1194  const unsigned long len = nodes.length();
1195  for (unsigned long i = 0; i < len; ++i) {
1196  DOM::NodeImpl* node = nodes.item(i).handle();
1197  if (node->isElementNode())
1198  elements.append(convertDomElement(static_cast<DOM::ElementImpl*>(node)));
1199  }
1200  }
1201  break;
1202  default:
1203  break;
1204  }
1205 
1206  return elements;
1207 }
1208 
1209 QVariant KHTMLHtmlExtension::htmlSettingsProperty(HtmlSettingsInterface::HtmlSettingsType type) const
1210 {
1211  if (part()) {
1212  switch (type) {
1213  case KParts::HtmlSettingsInterface::AutoLoadImages:
1214  return part()->autoloadImages();
1215  case KParts::HtmlSettingsInterface::DnsPrefetchEnabled:
1216  return (part()->dnsPrefetch() == KHTMLPart::DNSPrefetchEnabled);
1217  case KParts::HtmlSettingsInterface::JavaEnabled:
1218  return part()->javaEnabled();
1219  case KParts::HtmlSettingsInterface::JavascriptEnabled:
1220  return part()->jScriptEnabled();
1221  case KParts::HtmlSettingsInterface::MetaRefreshEnabled:
1222  return part()->metaRefreshEnabled();
1223  case KParts::HtmlSettingsInterface::PluginsEnabled:
1224  return part()->pluginsEnabled();
1225  default:
1226  break;
1227  }
1228  }
1229  return QVariant();
1230 }
1231 
1232 bool KHTMLHtmlExtension::setHtmlSettingsProperty(HtmlSettingsInterface::HtmlSettingsType type, const QVariant& value)
1233 {
1234  KHTMLPart* p = part();
1235 
1236  if (p) {
1237  switch (type) {
1238  case KParts::HtmlSettingsInterface::AutoLoadImages:
1239  p->setAutoloadImages(value.toBool());
1240  return true;
1241  case KParts::HtmlSettingsInterface::DnsPrefetchEnabled:
1242  p->setDNSPrefetch((value.toBool() ? KHTMLPart::DNSPrefetchEnabled : KHTMLPart::DNSPrefetchDisabled));
1243  return true;
1244  case KParts::HtmlSettingsInterface::JavaEnabled:
1245  p->setJavaEnabled(value.toBool());
1246  return true;
1247  case KParts::HtmlSettingsInterface::JavascriptEnabled:
1248  p->setJScriptEnabled(value.toBool());
1249  return true;
1250  case KParts::HtmlSettingsInterface::MetaRefreshEnabled:
1251  p->setMetaRefreshEnabled(value.toBool());
1252  return true;
1253  case KParts::HtmlSettingsInterface::PluginsEnabled:
1254  p->setPluginsEnabled(value.toBool());
1255  return true;
1256  case KParts::HtmlSettingsInterface::UserDefinedStyleSheetURL: {
1257  const KUrl url (value.toUrl());
1258  if (url.protocol() == QLatin1String("data")) {
1259  const QByteArray data (url.encodedPath());
1260  if (!data.isEmpty()) {
1261  const int index = data.indexOf(',');
1262  const QByteArray decodedData ((index > -1 ? QByteArray::fromBase64(data.mid(index)) : QByteArray()));
1263  p->setUserStyleSheet(QString::fromUtf8(decodedData.constData(), decodedData.size()));
1264  }
1265  } else {
1266  p->setUserStyleSheet(url);
1267  }
1268  return true;
1269  }
1270  default:
1271  break; // Unsupported property...
1272  }
1273  }
1274 
1275  return false;
1276 }
1277 
1278 
1279 KHTMLPart* KHTMLHtmlExtension::part() const
1280 {
1281  return static_cast<KHTMLPart*>(parent());
1282 }
1283 
1284 #include "khtml_ext.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 16 2013 11:51:02 by doxygen 1.8.1.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal