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