00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <assert.h>
00029 #include "khtml_ext.h"
00030 #include "khtmlview.h"
00031 #include "khtml_pagecache.h"
00032 #include "rendering/render_form.h"
00033 #include "rendering/render_image.h"
00034 #include "html/html_imageimpl.h"
00035 #include "misc/loader.h"
00036 #include "dom/html_form.h"
00037 #include "dom/html_image.h"
00038 #include <qclipboard.h>
00039 #include <qfileinfo.h>
00040 #include <qpopupmenu.h>
00041 #include <qmetaobject.h>
00042 #include <private/qucomextra_p.h>
00043
00044 #include <kdebug.h>
00045 #include <klocale.h>
00046 #include <kfiledialog.h>
00047 #include <kio/job.h>
00048 #include <kprocess.h>
00049 #include <ktoolbarbutton.h>
00050 #include <ktoolbar.h>
00051 #include <ksavefile.h>
00052 #include <kurldrag.h>
00053 #include <kstringhandler.h>
00054 #include <kapplication.h>
00055 #include <kmessagebox.h>
00056 #include <kstandarddirs.h>
00057 #include <krun.h>
00058 #include <kurifilter.h>
00059 #include <kiconloader.h>
00060 #include <kdesktopfile.h>
00061
00062
00063 #include "dom/dom_element.h"
00064 #include "misc/htmltags.h"
00065
00066 KHTMLPartBrowserExtension::KHTMLPartBrowserExtension( KHTMLPart *parent, const char *name )
00067 : KParts::BrowserExtension( parent, name )
00068 {
00069 m_part = parent;
00070 setURLDropHandlingEnabled( true );
00071
00072 enableAction( "cut", false );
00073 enableAction( "copy", false );
00074 enableAction( "paste", false );
00075
00076 m_connectedToClipboard = false;
00077 }
00078
00079 int KHTMLPartBrowserExtension::xOffset()
00080 {
00081 return m_part->view()->contentsX();
00082 }
00083
00084 int KHTMLPartBrowserExtension::yOffset()
00085 {
00086 return m_part->view()->contentsY();
00087 }
00088
00089 void KHTMLPartBrowserExtension::saveState( QDataStream &stream )
00090 {
00091
00092 m_part->saveState( stream );
00093 }
00094
00095 void KHTMLPartBrowserExtension::restoreState( QDataStream &stream )
00096 {
00097
00098 m_part->restoreState( stream );
00099 }
00100
00101 void KHTMLPartBrowserExtension::editableWidgetFocused( QWidget *widget )
00102 {
00103 m_editableFormWidget = widget;
00104 updateEditActions();
00105
00106 if ( !m_connectedToClipboard && m_editableFormWidget )
00107 {
00108 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00109 this, SLOT( updateEditActions() ) );
00110
00111 if ( m_editableFormWidget->inherits( "QLineEdit" ) || m_editableFormWidget->inherits( "QTextEdit" ) )
00112 connect( m_editableFormWidget, SIGNAL( selectionChanged() ),
00113 this, SLOT( updateEditActions() ) );
00114
00115 m_connectedToClipboard = true;
00116 }
00117 editableWidgetFocused();
00118 }
00119
00120 void KHTMLPartBrowserExtension::editableWidgetBlurred( QWidget * )
00121 {
00122 QWidget *oldWidget = m_editableFormWidget;
00123
00124 m_editableFormWidget = 0;
00125 enableAction( "cut", false );
00126 enableAction( "paste", false );
00127 m_part->emitSelectionChanged();
00128
00129 if ( m_connectedToClipboard )
00130 {
00131 disconnect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00132 this, SLOT( updateEditActions() ) );
00133
00134 if ( oldWidget )
00135 {
00136 if ( oldWidget->inherits( "QLineEdit" ) || oldWidget->inherits( "QTextEdit" ) )
00137 disconnect( oldWidget, SIGNAL( selectionChanged() ),
00138 this, SLOT( updateEditActions() ) );
00139 }
00140
00141 m_connectedToClipboard = false;
00142 }
00143 editableWidgetBlurred();
00144 }
00145
00146 void KHTMLPartBrowserExtension::setExtensionProxy( KParts::BrowserExtension *proxy )
00147 {
00148 if ( m_extensionProxy )
00149 {
00150 disconnect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ),
00151 this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) );
00152 if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) )
00153 {
00154 disconnect( m_extensionProxy, SIGNAL( editableWidgetFocused() ),
00155 this, SLOT( extensionProxyEditableWidgetFocused() ) );
00156 disconnect( m_extensionProxy, SIGNAL( editableWidgetBlurred() ),
00157 this, SLOT( extensionProxyEditableWidgetBlurred() ) );
00158 }
00159 }
00160
00161 m_extensionProxy = proxy;
00162
00163 if ( m_extensionProxy )
00164 {
00165 connect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ),
00166 this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) );
00167 if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) )
00168 {
00169 connect( m_extensionProxy, SIGNAL( editableWidgetFocused() ),
00170 this, SLOT( extensionProxyEditableWidgetFocused() ) );
00171 connect( m_extensionProxy, SIGNAL( editableWidgetBlurred() ),
00172 this, SLOT( extensionProxyEditableWidgetBlurred() ) );
00173 }
00174
00175 enableAction( "cut", m_extensionProxy->isActionEnabled( "cut" ) );
00176 enableAction( "copy", m_extensionProxy->isActionEnabled( "copy" ) );
00177 enableAction( "paste", m_extensionProxy->isActionEnabled( "paste" ) );
00178 }
00179 else
00180 {
00181 updateEditActions();
00182 enableAction( "copy", false );
00183 }
00184 }
00185
00186 void KHTMLPartBrowserExtension::cut()
00187 {
00188 if ( m_extensionProxy )
00189 {
00190 callExtensionProxyMethod( "cut()" );
00191 return;
00192 }
00193
00194 if ( !m_editableFormWidget )
00195 return;
00196
00197 if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00198 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->cut();
00199 else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00200 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->cut();
00201 }
00202
00203 void KHTMLPartBrowserExtension::copy()
00204 {
00205 if ( m_extensionProxy )
00206 {
00207 callExtensionProxyMethod( "copy()" );
00208 return;
00209 }
00210
00211 kdDebug( 6050 ) << "************! KHTMLPartBrowserExtension::copy()" << endl;
00212 if ( !m_editableFormWidget )
00213 {
00214
00215 QString text = m_part->selectedText();
00216 text.replace( QChar( 0xa0 ), ' ' );
00217 QClipboard *cb = QApplication::clipboard();
00218 disconnect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) );
00219 cb->setText(text);
00220 connect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) );
00221 }
00222 else
00223 {
00224 if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00225 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->copy();
00226 else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00227 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->copy();
00228 }
00229 }
00230
00231 void KHTMLPartBrowserExtension::searchProvider()
00232 {
00233 if ( m_extensionProxy )
00234 {
00235 callExtensionProxyMethod( "searchProvider()" );
00236 return;
00237 }
00238
00239 KURIFilterData data;
00240 QStringList list;
00241 data.setData( m_part->selectedText() );
00242 list << "kurisearchfilter" << "kuriikwsfilter";
00243
00244 if( !KURIFilter::self()->filterURI(data, list) )
00245 {
00246 KDesktopFile file("searchproviders/google.desktop", true, "services");
00247 data.setData(file.readEntry("Query").replace("\\{@}", m_part->selectedText()));
00248 }
00249
00250 emit m_part->browserExtension()->openURLRequest( data.uri() );
00251 }
00252
00253 void KHTMLPartBrowserExtension::paste()
00254 {
00255 if ( m_extensionProxy )
00256 {
00257 callExtensionProxyMethod( "paste()" );
00258 return;
00259 }
00260
00261 if ( !m_editableFormWidget )
00262 return;
00263
00264 if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00265 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->paste();
00266 else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00267 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->paste();
00268 }
00269
00270 void KHTMLPartBrowserExtension::callExtensionProxyMethod( const char *method )
00271 {
00272 if ( !m_extensionProxy )
00273 return;
00274
00275 int slot = m_extensionProxy->metaObject()->findSlot( method );
00276 if ( slot == -1 )
00277 return;
00278
00279 QUObject o[ 1 ];
00280 m_extensionProxy->qt_invoke( slot, o );
00281 }
00282
00283 void KHTMLPartBrowserExtension::updateEditActions()
00284 {
00285 if ( !m_editableFormWidget )
00286 {
00287 enableAction( "cut", false );
00288 enableAction( "copy", false );
00289 enableAction( "paste", false );
00290 return;
00291 }
00292
00293
00294 #ifndef QT_NO_MIMECLIPBOARD // Handle minimalized versions of Qt Embedded
00295 QMimeSource *data = QApplication::clipboard()->data();
00296 enableAction( "paste", data->provides( "text/plain" ) );
00297 #else
00298 QString data=QApplication::clipboard()->text();
00299 enableAction( "paste", data.contains("://"));
00300 #endif
00301 bool hasSelection = false;
00302
00303 if( m_editableFormWidget) {
00304 if ( ::qt_cast<QLineEdit*>(m_editableFormWidget))
00305 hasSelection = static_cast<QLineEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
00306 else if(::qt_cast<QTextEdit*>(m_editableFormWidget))
00307 hasSelection = static_cast<QTextEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
00308 }
00309
00310 enableAction( "copy", hasSelection );
00311 enableAction( "cut", hasSelection );
00312 }
00313
00314 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetFocused() {
00315 editableWidgetFocused();
00316 }
00317
00318 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetBlurred() {
00319 editableWidgetBlurred();
00320 }
00321
00322 void KHTMLPartBrowserExtension::extensionProxyActionEnabled( const char *action, bool enable )
00323 {
00324
00325 if ( strcmp( action, "cut" ) == 0 ||
00326 strcmp( action, "copy" ) == 0 ||
00327 strcmp( action, "paste" ) == 0 ) {
00328 enableAction( action, enable );
00329 }
00330 }
00331
00332 void KHTMLPartBrowserExtension::reparseConfiguration()
00333 {
00334 m_part->reparseConfiguration();
00335 }
00336
00337 void KHTMLPartBrowserExtension::print()
00338 {
00339 m_part->view()->print();
00340 }
00341
00342 class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate
00343 {
00344 public:
00345 KHTMLPart *m_khtml;
00346 KURL m_url;
00347 KURL m_imageURL;
00348 QString m_suggestedFilename;
00349 };
00350
00351
00352 KHTMLPopupGUIClient::KHTMLPopupGUIClient( KHTMLPart *khtml, const QString &doc, const KURL &url )
00353 : QObject( khtml )
00354 {
00355 d = new KHTMLPopupGUIClientPrivate;
00356 d->m_khtml = khtml;
00357 d->m_url = url;
00358 bool isImage = false;
00359 bool hasSelection = khtml->hasSelection();
00360 setInstance( khtml->instance() );
00361
00362 DOM::Element e;
00363 e = khtml->nodeUnderMouse();
00364
00365 if ( !e.isNull() && (e.elementId() == ID_IMG ||
00366 (e.elementId() == ID_INPUT && !static_cast<DOM::HTMLInputElement>(e).src().isEmpty())))
00367 {
00368 if (e.elementId() == ID_IMG) {
00369 DOM::HTMLImageElementImpl *ie = static_cast<DOM::HTMLImageElementImpl*>(e.handle());
00370 khtml::RenderImage *ri = dynamic_cast<khtml::RenderImage*>(ie->renderer());
00371 if (ri && ri->contentObject()) {
00372 d->m_suggestedFilename = static_cast<khtml::CachedImage*>(ri->contentObject())->suggestedFilename();
00373 }
00374 }
00375 isImage=true;
00376 }
00377
00378 if ( url.isEmpty() && !isImage )
00379 {
00380 if (hasSelection)
00381 {
00382 KAction* copyAction = KStdAction::copy( d->m_khtml->browserExtension(), SLOT( copy() ), actionCollection(), "copy" );
00383 copyAction->setText(i18n("&Copy Text"));
00384 copyAction->setEnabled(d->m_khtml->browserExtension()->isActionEnabled( "copy" ));
00385 actionCollection()->insert( khtml->actionCollection()->action( "selectAll" ) );
00386
00387 KConfig config("kuriikwsfilterrc");
00388 config.setGroup("General");
00389 QString engine = config.readEntry("DefaultSearchEngine");
00390
00391
00392 QString selectedText = khtml->selectedText();
00393 if ( selectedText.length()>18 ) {
00394 selectedText.truncate(15);
00395 selectedText+="...";
00396 }
00397
00398
00399 KDesktopFile file("searchproviders/" + engine + ".desktop", true, "services");
00400
00401
00402 QPixmap icon;
00403 KURIFilterData data;
00404 QStringList list;
00405 data.setData( QString("some keyword") );
00406 list << "kurisearchfilter" << "kuriikwsfilter";
00407
00408 QString name;
00409 if ( KURIFilter::self()->filterURI(data, list) )
00410 {
00411 QString iconPath = locate("cache", KMimeType::favIconForURL(data.uri()) + ".png");
00412 if ( iconPath.isEmpty() )
00413 icon = SmallIcon("find");
00414 else
00415 icon = QPixmap( iconPath );
00416 name = file.readName();
00417 }
00418 else
00419 {
00420 icon = SmallIcon("google");
00421 name = "Google";
00422 }
00423
00424 new KAction( i18n( "Search '%1' at %2" ).arg( selectedText ).arg( name ), icon, 0, d->m_khtml->browserExtension(),
00425 SLOT( searchProvider() ), actionCollection(), "searchProvider" );
00426 }
00427 else
00428 {
00429 actionCollection()->insert( khtml->actionCollection()->action( "security" ) );
00430 actionCollection()->insert( khtml->actionCollection()->action( "setEncoding" ) );
00431 new KAction( i18n( "Stop Animations" ), 0, this, SLOT( slotStopAnimations() ),
00432 actionCollection(), "stopanimations" );
00433 }
00434 }
00435
00436 if ( !url.isEmpty() )
00437 {
00438 if (url.protocol() == "mailto")
00439 {
00440 new KAction( i18n( "Copy Email Address" ), 0, this, SLOT( slotCopyLinkLocation() ),
00441 actionCollection(), "copylinklocation" );
00442 }
00443 else
00444 {
00445 new KAction( i18n( "&Save Link As..." ), 0, this, SLOT( slotSaveLinkAs() ),
00446 actionCollection(), "savelinkas" );
00447 new KAction( i18n( "Copy Link Address" ), 0, this, SLOT( slotCopyLinkLocation() ),
00448 actionCollection(), "copylinklocation" );
00449 }
00450 }
00451
00452
00453 if (!hasSelection)
00454 {
00455 if ( khtml->parentPart() )
00456 {
00457 new KAction( i18n( "Open in New &Window" ), "window_new", 0, this, SLOT( slotFrameInWindow() ),
00458 actionCollection(), "frameinwindow" );
00459 new KAction( i18n( "Open in &This Window" ), 0, this, SLOT( slotFrameInTop() ),
00460 actionCollection(), "frameintop" );
00461 new KAction( i18n( "Open in &New Tab" ), "tab_new", 0, this, SLOT( slotFrameInTab() ),
00462 actionCollection(), "frameintab" );
00463 new KAction( i18n( "Reload Frame" ), 0, this, SLOT( slotReloadFrame() ),
00464 actionCollection(), "reloadframe" );
00465 new KAction( i18n( "View Frame Source" ), 0, d->m_khtml, SLOT( slotViewDocumentSource() ),
00466 actionCollection(), "viewFrameSource" );
00467 new KAction( i18n( "View Frame Information" ), 0, d->m_khtml, SLOT( slotViewPageInfo() ), actionCollection(), "viewFrameInfo" );
00468
00469
00470
00471 new KAction( i18n( "Print Frame..." ), "frameprint", 0, d->m_khtml->browserExtension(), SLOT( print() ), actionCollection(), "printFrame" );
00472
00473 actionCollection()->insert( khtml->parentPart()->actionCollection()->action( "viewDocumentSource" ) );
00474 actionCollection()->insert( khtml->parentPart()->actionCollection()->action( "viewPageInfo" ) );
00475 } else {
00476 actionCollection()->insert( khtml->actionCollection()->action( "viewDocumentSource" ) );
00477 actionCollection()->insert( khtml->actionCollection()->action( "viewPageInfo" ) );
00478 }
00479 } else if (isImage || !url.isEmpty()) {
00480 actionCollection()->insert( khtml->actionCollection()->action( "viewDocumentSource" ) );
00481 actionCollection()->insert( khtml->actionCollection()->action( "viewPageInfo" ) );
00482 new KAction( i18n( "Stop Animations" ), 0, this, SLOT( slotStopAnimations() ),
00483 actionCollection(), "stopanimations" );
00484 }
00485
00486 if (isImage)
00487 {
00488 if ( e.elementId() == ID_IMG )
00489 d->m_imageURL = KURL( static_cast<DOM::HTMLImageElement>( e ).src().string() );
00490 else
00491 d->m_imageURL = KURL( static_cast<DOM::HTMLInputElement>( e ).src().string() );
00492 new KAction( i18n( "Save Image As..." ), 0, this, SLOT( slotSaveImageAs() ),
00493 actionCollection(), "saveimageas" );
00494 new KAction( i18n( "Send Image" ), 0, this, SLOT( slotSendImage() ),
00495 actionCollection(), "sendimage" );
00496
00497
00498 new KAction( i18n( "Copy Image Location" ), 0, this, SLOT( slotCopyImageLocation() ),
00499 actionCollection(), "copyimagelocation" );
00500 QString name = KStringHandler::csqueeze(d->m_imageURL.fileName()+d->m_imageURL.query(), 25);
00501 new KAction( i18n( "View Image (%1)" ).arg(d->m_suggestedFilename.isEmpty() ? name.replace("&", "&&") : d->m_suggestedFilename.replace("&", "&&")), 0, this, SLOT( slotViewImage() ),
00502 actionCollection(), "viewimage" );
00503 }
00504
00505 setXML( doc );
00506 setDOMDocument( QDomDocument(), true );
00507
00508 QDomElement menu = domDocument().documentElement().namedItem( "Menu" ).toElement();
00509
00510 if ( actionCollection()->count() > 0 )
00511 menu.insertBefore( domDocument().createElement( "separator" ), menu.firstChild() );
00512 }
00513
00514 KHTMLPopupGUIClient::~KHTMLPopupGUIClient()
00515 {
00516 delete d;
00517 }
00518
00519 void KHTMLPopupGUIClient::slotSaveLinkAs()
00520 {
00521 KIO::MetaData metaData;
00522 metaData["referrer"] = d->m_khtml->referrer();
00523 saveURL( d->m_khtml->widget(), i18n( "Save Link As" ), d->m_url, metaData );
00524 }
00525
00526 void KHTMLPopupGUIClient::slotSendImage()
00527 {
00528 QStringList urls;
00529 urls.append( d->m_imageURL.url());
00530 QString subject = d->m_imageURL.url();
00531 kapp->invokeMailer(QString::null, QString::null, QString::null, subject,
00532 QString::null,
00533 QString::null,
00534 urls);
00535
00536
00537 }
00538
00539 void KHTMLPopupGUIClient::slotSaveImageAs()
00540 {
00541 KIO::MetaData metaData;
00542 metaData["referrer"] = d->m_khtml->referrer();
00543 saveURL( d->m_khtml->widget(), i18n( "Save Image As" ), d->m_imageURL, metaData, QString::null, 0, d->m_suggestedFilename );
00544 }
00545
00546 void KHTMLPopupGUIClient::slotCopyLinkLocation()
00547 {
00548 KURL safeURL(d->m_url);
00549 safeURL.setPass(QString::null);
00550 #ifndef QT_NO_MIMECLIPBOARD
00551
00552 KURL::List lst;
00553 lst.append( safeURL );
00554 if ( d->m_url.url().contains( "mailto:" ) )
00555 {
00556 QApplication::clipboard()->setSelectionMode(true);
00557 QApplication::clipboard()->setText(d->m_url.path() );
00558 QApplication::clipboard()->setSelectionMode(false);
00559 QApplication::clipboard()->setText(d->m_url.path() );
00560 }
00561 else
00562 {
00563 QApplication::clipboard()->setSelectionMode(true);
00564 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00565 QApplication::clipboard()->setSelectionMode(false);
00566 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00567 }
00568 #else
00569 QApplication::clipboard()->setText( safeURL.url() );
00570 #endif
00571 }
00572
00573 void KHTMLPopupGUIClient::slotStopAnimations()
00574 {
00575 d->m_khtml->stopAnimations();
00576 }
00577
00578 void KHTMLPopupGUIClient::slotCopyImageLocation()
00579 {
00580 KURL safeURL(d->m_imageURL);
00581 safeURL.setPass(QString::null);
00582 #ifndef QT_NO_MIMECLIPBOARD
00583
00584 KURL::List lst;
00585 lst.append( safeURL );
00586 QApplication::clipboard()->setSelectionMode(true);
00587 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00588 QApplication::clipboard()->setSelectionMode(false);
00589 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00590 #else
00591 QApplication::clipboard()->setText( safeURL.url() );
00592 #endif
00593 }
00594
00595 void KHTMLPopupGUIClient::slotViewImage()
00596 {
00597 d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL);
00598 }
00599
00600 void KHTMLPopupGUIClient::slotReloadFrame()
00601 {
00602 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00603 args.reload = true;
00604 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00605
00606 d->m_khtml->closeURL();
00607 d->m_khtml->browserExtension()->setURLArgs( args );
00608 d->m_khtml->openURL( d->m_khtml->url() );
00609 }
00610
00611 void KHTMLPopupGUIClient::slotFrameInWindow()
00612 {
00613 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00614 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00615 args.metaData()["forcenewwindow"] = "true";
00616 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
00617 }
00618
00619 void KHTMLPopupGUIClient::slotFrameInTop()
00620 {
00621 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00622 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00623 args.frameName = "_top";
00624 emit d->m_khtml->browserExtension()->openURLRequest( d->m_khtml->url(), args );
00625 }
00626
00627 void KHTMLPopupGUIClient::slotFrameInTab()
00628 {
00629 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00630 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00631 args.setNewTab(true);
00632 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
00633 }
00634
00635 void KHTMLPopupGUIClient::saveURL( QWidget *parent, const QString &caption,
00636 const KURL &url,
00637 const QMap<QString, QString> &metadata,
00638 const QString &filter, long cacheId,
00639 const QString & suggestedFilename )
00640 {
00641 QString name = QString::fromLatin1( "index.html" );
00642 if ( !suggestedFilename.isEmpty() )
00643 name = suggestedFilename;
00644 else if ( !url.fileName().isEmpty() )
00645 name = url.fileName();
00646
00647 KURL destURL;
00648 int query;
00649 do {
00650 query = KMessageBox::Yes;
00651 destURL = KFileDialog::getSaveURL( name, filter, parent, caption );
00652 if( destURL.isLocalFile() )
00653 {
00654 QFileInfo info( destURL.path() );
00655 if( info.exists() ) {
00656
00657 query = KMessageBox::warningYesNo( parent, i18n( "A file named \"%1\" already exists. " "Are you sure you want to overwrite it?" ).arg( info.fileName() ), i18n( "Overwrite File?" ), i18n( "Overwrite" ), KStdGuiItem::cancel() );
00658 }
00659 }
00660 } while ( query == KMessageBox::No );
00661
00662 if ( destURL.isValid() )
00663 saveURL(url, destURL, metadata, cacheId);
00664 }
00665
00666 void KHTMLPopupGUIClient::saveURL( const KURL &url, const KURL &destURL,
00667 const QMap<QString, QString> &metadata,
00668 long cacheId )
00669 {
00670 if ( destURL.isValid() )
00671 {
00672 bool saved = false;
00673 if (KHTMLPageCache::self()->isComplete(cacheId))
00674 {
00675 if (destURL.isLocalFile())
00676 {
00677 KSaveFile destFile(destURL.path());
00678 if (destFile.status() == 0)
00679 {
00680 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00681 saved = true;
00682 }
00683 }
00684 else
00685 {
00686
00687 KTempFile destFile;
00688 if (destFile.status() == 0)
00689 {
00690 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00691 destFile.close();
00692 KURL url2 = KURL();
00693 url2.setPath(destFile.name());
00694 KIO::file_move(url2, destURL, -1, true );
00695 saved = true;
00696 }
00697 }
00698 }
00699 if(!saved)
00700 {
00701
00702
00703
00704
00705 bool downloadViaKIO = true;
00706 if ( !url.isLocalFile() )
00707 {
00708 KConfig cfg("konquerorrc", false, false);
00709 cfg.setGroup("HTML Settings");
00710 QString downloadManger = cfg.readPathEntry("DownloadManager");
00711 if (!downloadManger.isEmpty())
00712 {
00713
00714 kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl;
00715 QString cmd = KStandardDirs::findExe(downloadManger);
00716 if (cmd.isEmpty())
00717 {
00718 QString errMsg=i18n("The Download Manager (%1) could not be found in your $PATH ").arg(downloadManger);
00719 QString errMsgEx= i18n("Try to reinstall it \n\nThe integration with Konqueror will be disabled!");
00720 KMessageBox::detailedSorry(0,errMsg,errMsgEx);
00721 cfg.writePathEntry("DownloadManager",QString::null);
00722 cfg.sync ();
00723 }
00724 else
00725 {
00726 downloadViaKIO = false;
00727 KURL cleanDest = destURL;
00728 cleanDest.setPass( QString::null );
00729 cmd += " " + KProcess::quote(url.url()) + " " +
00730 KProcess::quote(cleanDest.url());
00731 kdDebug(1000) << "Calling command "<<cmd<<endl;
00732 KRun::runCommand(cmd);
00733 }
00734 }
00735 }
00736
00737 if ( downloadViaKIO )
00738 {
00739 KIO::Job *job = KIO::file_copy( url, destURL, -1, true );
00740 job->setMetaData(metadata);
00741 job->addMetaData("MaxCacheSize", "0");
00742 job->addMetaData("cache", "cache");
00743 job->setAutoErrorHandlingEnabled( true );
00744 }
00745 }
00746 }
00747 }
00748
00749 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension( KHTMLPart *part )
00750 : KParts::BrowserHostExtension( part )
00751 {
00752 m_part = part;
00753 }
00754
00755 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension()
00756 {
00757 }
00758
00759 QStringList KHTMLPartBrowserHostExtension::frameNames() const
00760 {
00761 return m_part->frameNames();
00762 }
00763
00764 const QPtrList<KParts::ReadOnlyPart> KHTMLPartBrowserHostExtension::frames() const
00765 {
00766 return m_part->frames();
00767 }
00768
00769 bool KHTMLPartBrowserHostExtension::openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs )
00770 {
00771 return m_part->openURLInFrame( url, urlArgs );
00772 }
00773
00774 void KHTMLPartBrowserHostExtension::virtual_hook( int id, void *data )
00775 {
00776 if (id == VIRTUAL_FIND_FRAME_PARENT)
00777 {
00778 FindFrameParentParams *param = static_cast<FindFrameParentParams*>(data);
00779 KHTMLPart *parentPart = m_part->findFrameParent(param->callingPart, param->frame);
00780 if (parentPart)
00781 param->parent = parentPart->browserHostExtension();
00782 return;
00783 }
00784 BrowserHostExtension::virtual_hook( id, data );
00785 }
00786
00787
00788
00789 extern const int KDE_NO_EXPORT fastZoomSizes[];
00790 extern const int KDE_NO_EXPORT fastZoomSizeCount;
00791
00792
00793 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name )
00794 : KAction( text, icon, 0, receiver, slot, parent, name )
00795 {
00796 init(part, direction);
00797 }
00798
00799 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const KShortcut &cut, const QObject *receiver, const char *slot, QObject *parent, const char *name )
00800 : KAction( text, icon, cut, receiver, slot, parent, name )
00801 {
00802 init(part, direction);
00803 }
00804
00805 void KHTMLZoomFactorAction::init(KHTMLPart *part, bool direction)
00806 {
00807 m_direction = direction;
00808 m_part = part;
00809
00810 m_popup = new QPopupMenu;
00811 m_popup->insertItem( i18n( "Default Font Size (100%)" ) );
00812
00813 int m = m_direction ? 1 : -1;
00814 int ofs = fastZoomSizeCount / 2;
00815
00816
00817 for ( int i = m; i != m*(ofs+1); i += m )
00818 {
00819 int num = i * m;
00820 QString numStr = QString::number( num );
00821 if ( num > 0 ) numStr.prepend( '+' );
00822
00823 m_popup->insertItem( i18n( "%1%" ).arg( fastZoomSizes[ofs + i] ) );
00824 }
00825
00826 connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) );
00827 }
00828
00829 KHTMLZoomFactorAction::~KHTMLZoomFactorAction()
00830 {
00831 delete m_popup;
00832 }
00833
00834 int KHTMLZoomFactorAction::plug( QWidget *w, int index )
00835 {
00836 int containerId = KAction::plug( w, index );
00837 if ( containerId == -1 || !w->inherits( "KToolBar" ) )
00838 return containerId;
00839
00840 KToolBarButton *button = static_cast<KToolBar *>( w )->getButton( itemId( containerId ) );
00841 if ( !button )
00842 return containerId;
00843
00844 button->setDelayedPopup( m_popup );
00845 return containerId;
00846 }
00847
00848 void KHTMLZoomFactorAction::slotActivated( int id )
00849 {
00850 int idx = m_popup->indexOf( id );
00851
00852 if (idx == 0)
00853 m_part->setZoomFactor(100);
00854 else
00855 m_part->setZoomFactor(fastZoomSizes[fastZoomSizeCount/2 + (m_direction ? 1 : -1)*idx]);
00856 }
00857
00858 #include "khtml_ext.moc"
00859