khtml Library API Documentation

khtml_ext.cpp

00001 // -*- c-basic-offset: 2 -*- 00002 /* This file is part of the KDE project 00003 * 00004 * Copyright (C) 2000-2003 Simon Hausmann <hausmann@kde.org> 00005 * 2001-2003 George Staikos <staikos@kde.org> 00006 * 2001-2003 Laurent Montel <montel@kde.org> 00007 * 2001-2003 Dirk Mueller <mueller@kde.org> 00008 * 2001-2003 Waldo Bastian <bastian@kde.org> 00009 * 2001-2003 David Faure <faure@kde.org> 00010 * 2001-2003 Daniel Naber <dnaber@kde.org> 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Library General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Library General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Library General Public License 00023 * along with this library; see the file COPYING.LIB. If not, write to 00024 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00025 * Boston, MA 02111-1307, USA. 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 00056 #include "dom/dom_element.h" 00057 #include "misc/htmltags.h" 00058 00059 KHTMLPartBrowserExtension::KHTMLPartBrowserExtension( KHTMLPart *parent, const char *name ) 00060 : KParts::BrowserExtension( parent, name ) 00061 { 00062 m_part = parent; 00063 setURLDropHandlingEnabled( true ); 00064 00065 enableAction( "cut", false ); 00066 enableAction( "copy", false ); 00067 enableAction( "paste", false ); 00068 00069 m_connectedToClipboard = false; 00070 } 00071 00072 int KHTMLPartBrowserExtension::xOffset() 00073 { 00074 return m_part->view()->contentsX(); 00075 } 00076 00077 int KHTMLPartBrowserExtension::yOffset() 00078 { 00079 return m_part->view()->contentsY(); 00080 } 00081 00082 void KHTMLPartBrowserExtension::saveState( QDataStream &stream ) 00083 { 00084 kdDebug( 6050 ) << "saveState!" << endl; 00085 m_part->saveState( stream ); 00086 } 00087 00088 void KHTMLPartBrowserExtension::restoreState( QDataStream &stream ) 00089 { 00090 kdDebug( 6050 ) << "restoreState!" << endl; 00091 m_part->restoreState( stream ); 00092 } 00093 00094 void KHTMLPartBrowserExtension::editableWidgetFocused( QWidget *widget ) 00095 { 00096 m_editableFormWidget = widget; 00097 updateEditActions(); 00098 00099 if ( !m_connectedToClipboard && m_editableFormWidget ) 00100 { 00101 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 00102 this, SLOT( updateEditActions() ) ); 00103 00104 if ( m_editableFormWidget->inherits( "QLineEdit" ) || m_editableFormWidget->inherits( "QTextEdit" ) ) 00105 connect( m_editableFormWidget, SIGNAL( selectionChanged() ), 00106 this, SLOT( updateEditActions() ) ); 00107 00108 m_connectedToClipboard = true; 00109 } 00110 editableWidgetFocused(); 00111 } 00112 00113 void KHTMLPartBrowserExtension::editableWidgetBlurred( QWidget *widget ) 00114 { 00115 QWidget *oldWidget = m_editableFormWidget; 00116 00117 m_editableFormWidget = 0; 00118 enableAction( "cut", false ); 00119 enableAction( "paste", false ); 00120 m_part->emitSelectionChanged(); 00121 00122 if ( m_connectedToClipboard ) 00123 { 00124 disconnect( QApplication::clipboard(), SIGNAL( dataChanged() ), 00125 this, SLOT( updateEditActions() ) ); 00126 00127 if ( oldWidget ) 00128 { 00129 if ( oldWidget->inherits( "QLineEdit" ) || oldWidget->inherits( "QTextEdit" ) ) 00130 disconnect( oldWidget, SIGNAL( selectionChanged() ), 00131 this, SLOT( updateEditActions() ) ); 00132 } 00133 00134 m_connectedToClipboard = false; 00135 } 00136 editableWidgetBlurred(); 00137 } 00138 00139 void KHTMLPartBrowserExtension::setExtensionProxy( KParts::BrowserExtension *proxy ) 00140 { 00141 if ( m_extensionProxy ) 00142 { 00143 disconnect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ), 00144 this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) ); 00145 if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) ) 00146 { 00147 disconnect( m_extensionProxy, SIGNAL( editableWidgetFocused() ), 00148 this, SLOT( extensionProxyEditableWidgetFocused() ) ); 00149 disconnect( m_extensionProxy, SIGNAL( editableWidgetBlurred() ), 00150 this, SLOT( extensionProxyEditableWidgetBlurred() ) ); 00151 } 00152 } 00153 00154 m_extensionProxy = proxy; 00155 00156 if ( m_extensionProxy ) 00157 { 00158 connect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ), 00159 this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) ); 00160 if ( m_extensionProxy->inherits( "KHTMLPartBrowserExtension" ) ) 00161 { 00162 connect( m_extensionProxy, SIGNAL( editableWidgetFocused() ), 00163 this, SLOT( extensionProxyEditableWidgetFocused() ) ); 00164 connect( m_extensionProxy, SIGNAL( editableWidgetBlurred() ), 00165 this, SLOT( extensionProxyEditableWidgetBlurred() ) ); 00166 } 00167 00168 enableAction( "cut", m_extensionProxy->isActionEnabled( "cut" ) ); 00169 enableAction( "copy", m_extensionProxy->isActionEnabled( "copy" ) ); 00170 enableAction( "paste", m_extensionProxy->isActionEnabled( "paste" ) ); 00171 } 00172 else 00173 { 00174 updateEditActions(); 00175 enableAction( "copy", false ); // ### re-check this 00176 } 00177 } 00178 00179 void KHTMLPartBrowserExtension::cut() 00180 { 00181 if ( m_extensionProxy ) 00182 { 00183 callExtensionProxyMethod( "cut()" ); 00184 return; 00185 } 00186 00187 if ( !m_editableFormWidget ) 00188 return; 00189 00190 if ( m_editableFormWidget->inherits( "QLineEdit" ) ) 00191 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->cut(); 00192 else if ( m_editableFormWidget->inherits( "QTextEdit" ) ) 00193 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->cut(); 00194 } 00195 00196 void KHTMLPartBrowserExtension::copy() 00197 { 00198 if ( m_extensionProxy ) 00199 { 00200 callExtensionProxyMethod( "copy()" ); 00201 return; 00202 } 00203 00204 kdDebug( 6050 ) << "************! KHTMLPartBrowserExtension::copy()" << endl; 00205 if ( !m_editableFormWidget ) 00206 { 00207 // get selected text and paste to the clipboard 00208 QString text = m_part->selectedText(); 00209 text.replace( QChar( 0xa0 ), ' ' ); 00210 QClipboard *cb = QApplication::clipboard(); 00211 disconnect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) ); 00212 cb->setText(text); 00213 connect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) ); 00214 } 00215 else 00216 { 00217 if ( m_editableFormWidget->inherits( "QLineEdit" ) ) 00218 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->copy(); 00219 else if ( m_editableFormWidget->inherits( "QTextEdit" ) ) 00220 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->copy(); 00221 } 00222 } 00223 00224 void KHTMLPartBrowserExtension::paste() 00225 { 00226 if ( m_extensionProxy ) 00227 { 00228 callExtensionProxyMethod( "paste()" ); 00229 return; 00230 } 00231 00232 if ( !m_editableFormWidget ) 00233 return; 00234 00235 if ( m_editableFormWidget->inherits( "QLineEdit" ) ) 00236 static_cast<QLineEdit *>( &(*m_editableFormWidget) )->paste(); 00237 else if ( m_editableFormWidget->inherits( "QTextEdit" ) ) 00238 static_cast<QTextEdit *>( &(*m_editableFormWidget) )->paste(); 00239 } 00240 00241 void KHTMLPartBrowserExtension::callExtensionProxyMethod( const char *method ) 00242 { 00243 if ( !m_extensionProxy ) 00244 return; 00245 00246 int slot = m_extensionProxy->metaObject()->findSlot( method ); 00247 if ( slot == -1 ) 00248 return; 00249 00250 QUObject o[ 1 ]; 00251 m_extensionProxy->qt_invoke( slot, o ); 00252 } 00253 00254 void KHTMLPartBrowserExtension::updateEditActions() 00255 { 00256 if ( !m_editableFormWidget ) 00257 { 00258 enableAction( "cut", false ); 00259 enableAction( "paste", false ); 00260 return; 00261 } 00262 00263 // ### duplicated from KonqMainWindow::slotClipboardDataChanged 00264 #ifndef QT_NO_MIMECLIPBOARD // Handle minimalized versions of Qt Embedded 00265 QMimeSource *data = QApplication::clipboard()->data(); 00266 enableAction( "paste", data->provides( "text/plain" ) ); 00267 #else 00268 QString data=QApplication::clipboard()->text(); 00269 enableAction( "paste", data.contains("://")); 00270 #endif 00271 00272 bool hasSelection = false; 00273 00274 if ( m_editableFormWidget->inherits( "QLineEdit" ) ) { 00275 hasSelection = static_cast<QLineEdit *>( &(*m_editableFormWidget) )->hasSelectedText(); 00276 } 00277 else if ( m_editableFormWidget->inherits( "QTextEdit" ) ) 00278 { 00279 hasSelection = static_cast<QTextEdit *>( &(*m_editableFormWidget) )->hasSelectedText(); 00280 } 00281 00282 enableAction( "copy", hasSelection ); 00283 enableAction( "cut", hasSelection ); 00284 } 00285 00286 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetFocused() { 00287 editableWidgetFocused(); 00288 } 00289 00290 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetBlurred() { 00291 editableWidgetBlurred(); 00292 } 00293 00294 void KHTMLPartBrowserExtension::extensionProxyActionEnabled( const char *action, bool enable ) 00295 { 00296 // only forward enableAction calls for actions we actually do forward 00297 if ( strcmp( action, "cut" ) == 0 || 00298 strcmp( action, "copy" ) == 0 || 00299 strcmp( action, "paste" ) == 0 ) { 00300 enableAction( action, enable ); 00301 } 00302 } 00303 00304 void KHTMLPartBrowserExtension::reparseConfiguration() 00305 { 00306 m_part->reparseConfiguration(); 00307 } 00308 00309 void KHTMLPartBrowserExtension::print() 00310 { 00311 m_part->view()->print(); 00312 } 00313 00314 class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate 00315 { 00316 public: 00317 KHTMLPart *m_khtml; 00318 KURL m_url; 00319 KURL m_imageURL; 00320 }; 00321 00322 00323 KHTMLPopupGUIClient::KHTMLPopupGUIClient( KHTMLPart *khtml, const QString &doc, const KURL &url ) 00324 : QObject( khtml ) 00325 { 00326 d = new KHTMLPopupGUIClientPrivate; 00327 d->m_khtml = khtml; 00328 d->m_url = url; 00329 bool isImage = false; 00330 setInstance( khtml->instance() ); 00331 00332 DOM::Element e; 00333 e = khtml->nodeUnderMouse(); 00334 00335 if ( !e.isNull() && (e.elementId() == ID_IMG || 00336 (e.elementId() == ID_INPUT && !static_cast<DOM::HTMLInputElement>(e).src().isEmpty()))) 00337 { 00338 isImage=true; 00339 } 00340 00341 if ( url.isEmpty() && !isImage ) 00342 { 00343 KAction* copyAction = KStdAction::copy( d->m_khtml->browserExtension(), SLOT( copy() ), actionCollection(), "copy" ); 00344 copyAction->setText(i18n("&Copy Text")); 00345 copyAction->setEnabled(d->m_khtml->browserExtension()->isActionEnabled( "copy" )); 00346 actionCollection()->insert( khtml->actionCollection()->action( "selectAll" ) ); 00347 actionCollection()->insert( khtml->actionCollection()->action( "security" ) ); 00348 actionCollection()->insert( khtml->actionCollection()->action( "setEncoding" ) ); 00349 new KAction( i18n( "Stop Animations" ), 0, this, SLOT( slotStopAnimations() ), 00350 actionCollection(), "stopanimations" ); 00351 } 00352 00353 if ( !url.isEmpty() ) 00354 { 00355 new KAction( i18n( "&Save Link As..." ), 0, this, SLOT( slotSaveLinkAs() ), 00356 actionCollection(), "savelinkas" ); 00357 new KAction( i18n( "Copy Link Location" ), 0, this, SLOT( slotCopyLinkLocation() ), 00358 actionCollection(), "copylinklocation" ); 00359 } 00360 00361 // frameset? -> add "Reload Frame" etc. 00362 if ( khtml->parentPart() ) 00363 { 00364 new KAction( i18n( "Open in New &Window" ), "window_new", 0, this, SLOT( slotFrameInWindow() ), 00365 actionCollection(), "frameinwindow" ); 00366 new KAction( i18n( "Open in &New Tab" ), "tab_new", 0, this, SLOT( slotFrameInTab() ), 00367 actionCollection(), "frameintab" ); 00368 new KAction( i18n( "Reload Frame" ), 0, this, SLOT( slotReloadFrame() ), 00369 actionCollection(), "reloadframe" ); 00370 new KAction( i18n( "View Frame Source" ), 0, d->m_khtml, SLOT( slotViewDocumentSource() ), 00371 actionCollection(), "viewFrameSource" ); 00372 new KAction( i18n( "View Frame Information" ), 0, d->m_khtml, SLOT( slotViewPageInfo() ), actionCollection(), "viewFrameInfo" ); 00373 // This one isn't in khtml_popupmenu.rc anymore, because Print isn't either, 00374 // and because print frame is already in the toolbar and the menu. 00375 // But leave this here, so that it's easy to readd it. 00376 new KAction( i18n( "Print Frame..." ), "frameprint", 0, d->m_khtml->browserExtension(), SLOT( print() ), actionCollection(), "printFrame" ); 00377 00378 actionCollection()->insert( khtml->parentPart()->actionCollection()->action( "viewDocumentSource" ) ); 00379 actionCollection()->insert( khtml->parentPart()->actionCollection()->action( "viewPageInfo" ) ); 00380 } else { 00381 actionCollection()->insert( khtml->actionCollection()->action( "viewDocumentSource" ) ); 00382 actionCollection()->insert( khtml->actionCollection()->action( "viewPageInfo" ) ); 00383 } 00384 00385 if (isImage) 00386 { 00387 if ( e.elementId() == ID_IMG ) 00388 d->m_imageURL = KURL( static_cast<DOM::HTMLImageElement>( e ).src().string() ); 00389 else 00390 d->m_imageURL = KURL( static_cast<DOM::HTMLInputElement>( e ).src().string() ); 00391 new KAction( i18n( "Save Image As..." ), 0, this, SLOT( slotSaveImageAs() ), 00392 actionCollection(), "saveimageas" ); 00393 new KAction( i18n( "Send Image" ), 0, this, SLOT( slotSendImage() ), 00394 actionCollection(), "sendimage" ); 00395 00396 00397 new KAction( i18n( "Copy Image Location" ), 0, this, SLOT( slotCopyImageLocation() ), 00398 actionCollection(), "copyimagelocation" ); 00399 QString name = KStringHandler::csqueeze(d->m_imageURL.fileName()+d->m_imageURL.query(), 25); 00400 new KAction( i18n( "View Image (%1)" ).arg(name.replace("&", "&&")), 0, this, SLOT( slotViewImage() ), 00401 actionCollection(), "viewimage" ); 00402 } 00403 00404 setXML( doc ); 00405 setDOMDocument( QDomDocument(), true ); // ### HACK 00406 00407 QDomElement menu = domDocument().documentElement().namedItem( "Menu" ).toElement(); 00408 00409 if ( actionCollection()->count() > 0 ) 00410 menu.insertBefore( domDocument().createElement( "separator" ), menu.firstChild() ); 00411 } 00412 00413 KHTMLPopupGUIClient::~KHTMLPopupGUIClient() 00414 { 00415 delete d; 00416 } 00417 00418 void KHTMLPopupGUIClient::slotSaveLinkAs() 00419 { 00420 KIO::MetaData metaData; 00421 metaData["referrer"] = d->m_khtml->referrer(); 00422 saveURL( d->m_khtml->widget(), i18n( "Save Link As" ), d->m_url, metaData ); 00423 } 00424 00425 void KHTMLPopupGUIClient::slotSendImage() 00426 { 00427 QStringList urls; 00428 urls.append( d->m_imageURL.url()); 00429 QString subject = d->m_imageURL.url(); 00430 kapp->invokeMailer(QString::null, QString::null, QString::null, subject, 00431 QString::null, //body 00432 QString::null, 00433 urls); // attachments 00434 00435 00436 } 00437 00438 void KHTMLPopupGUIClient::slotSaveImageAs() 00439 { 00440 KIO::MetaData metaData; 00441 metaData["referrer"] = d->m_khtml->referrer(); 00442 saveURL( d->m_khtml->widget(), i18n( "Save Image As" ), d->m_imageURL, metaData ); 00443 } 00444 00445 void KHTMLPopupGUIClient::slotCopyLinkLocation() 00446 { 00447 KURL safeURL(d->m_url); 00448 safeURL.setPass(QString::null); 00449 #ifndef QT_NO_MIMECLIPBOARD 00450 // Set it in both the mouse selection and in the clipboard 00451 KURL::List lst; 00452 lst.append( safeURL ); 00453 QApplication::clipboard()->setSelectionMode(true); 00454 QApplication::clipboard()->setData( new KURLDrag( lst ) ); 00455 QApplication::clipboard()->setSelectionMode(false); 00456 QApplication::clipboard()->setData( new KURLDrag( lst ) ); 00457 #else 00458 QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries 00459 #endif 00460 } 00461 00462 void KHTMLPopupGUIClient::slotStopAnimations() 00463 { 00464 d->m_khtml->stopAnimations(); 00465 } 00466 00467 void KHTMLPopupGUIClient::slotCopyImageLocation() 00468 { 00469 KURL safeURL(d->m_imageURL); 00470 safeURL.setPass(QString::null); 00471 #ifndef QT_NO_MIMECLIPBOARD 00472 // Set it in both the mouse selection and in the clipboard 00473 KURL::List lst; 00474 lst.append( safeURL ); 00475 QApplication::clipboard()->setSelectionMode(true); 00476 QApplication::clipboard()->setData( new KURLDrag( lst ) ); 00477 QApplication::clipboard()->setSelectionMode(false); 00478 QApplication::clipboard()->setData( new KURLDrag( lst ) ); 00479 #else 00480 QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries 00481 #endif 00482 } 00483 00484 void KHTMLPopupGUIClient::slotViewImage() 00485 { 00486 d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL); 00487 } 00488 00489 void KHTMLPopupGUIClient::slotReloadFrame() 00490 { 00491 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() ); 00492 args.reload = true; 00493 args.metaData()["referrer"] = d->m_khtml->pageReferrer(); 00494 // reload document 00495 d->m_khtml->closeURL(); 00496 d->m_khtml->browserExtension()->setURLArgs( args ); 00497 d->m_khtml->openURL( d->m_khtml->url() ); 00498 } 00499 00500 void KHTMLPopupGUIClient::slotFrameInWindow() 00501 { 00502 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() ); 00503 args.metaData()["referrer"] = d->m_khtml->pageReferrer(); 00504 args.metaData()["forcenewwindow"] = "true"; 00505 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args ); 00506 } 00507 00508 void KHTMLPopupGUIClient::slotFrameInTab() 00509 { 00510 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() ); 00511 args.metaData()["referrer"] = d->m_khtml->pageReferrer(); 00512 args.setNewTab(true); 00513 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args ); 00514 } 00515 00516 void KHTMLPopupGUIClient::saveURL( QWidget *parent, const QString &caption, 00517 const KURL &url, 00518 const QMap<QString, QString> &metadata, 00519 const QString &filter, long cacheId, 00520 const QString & suggestedFilename ) 00521 { 00522 QString name = QString::fromLatin1( "index.html" ); 00523 if ( !suggestedFilename.isEmpty() ) 00524 name = suggestedFilename; 00525 else if ( !url.fileName().isEmpty() ) 00526 name = url.fileName(); 00527 00528 KURL destURL; 00529 int query; 00530 do { 00531 query = KMessageBox::Yes; 00532 destURL = KFileDialog::getSaveURL( name, filter, parent, caption ); 00533 if( destURL.isLocalFile() ) 00534 { 00535 QFileInfo info( destURL.path() ); 00536 if( info.exists() ) 00537 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() ); 00538 } 00539 } while ( query == KMessageBox::No ); 00540 00541 if ( destURL.isValid() ) 00542 saveURL(url, destURL, metadata, cacheId); 00543 } 00544 00545 void KHTMLPopupGUIClient::saveURL( const KURL &url, const KURL &destURL, 00546 const QMap<QString, QString> &metadata, 00547 long cacheId ) 00548 { 00549 if ( destURL.isValid() ) 00550 { 00551 bool saved = false; 00552 if (KHTMLPageCache::self()->isComplete(cacheId)) 00553 { 00554 if (destURL.isLocalFile()) 00555 { 00556 KSaveFile destFile(destURL.path()); 00557 if (destFile.status() == 0) 00558 { 00559 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream()); 00560 saved = true; 00561 } 00562 } 00563 else 00564 { 00565 // save to temp file, then move to final destination. 00566 KTempFile destFile; 00567 if (destFile.status() == 0) 00568 { 00569 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream()); 00570 destFile.close(); 00571 KURL url2 = KURL(); 00572 url2.setPath(destFile.name()); 00573 KIO::move(url2, destURL); 00574 saved = true; 00575 } 00576 } 00577 } 00578 if(!saved) 00579 { 00580 // DownloadManager <-> konqueror integration 00581 // find if the integration is enabled 00582 // the empty key means no integration 00583 // only use download manager for non-local urls! 00584 bool downloadViaKIO = true; 00585 if ( !url.isLocalFile() ) 00586 { 00587 KConfig cfg("konquerorrc", false, false); 00588 cfg.setGroup("HTML Settings"); 00589 QString downloadManger = cfg.readPathEntry("DownloadManager"); 00590 if (!downloadManger.isEmpty()) 00591 { 00592 // then find the download manager location 00593 kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl; 00594 QString cmd = KStandardDirs::findExe(downloadManger); 00595 if (cmd.isEmpty()) 00596 { 00597 QString errMsg=i18n("The Download Manager (%1) could not be found in your $PATH ").arg(downloadManger); 00598 QString errMsgEx= i18n("Try to reinstall it \n\nThe integration with Konqueror will be disabled!"); 00599 KMessageBox::detailedSorry(0,errMsg,errMsgEx); 00600 cfg.writePathEntry("DownloadManager",QString::null); 00601 cfg.sync (); 00602 } 00603 else 00604 { 00605 downloadViaKIO = false; 00606 KURL cleanDest = destURL; 00607 cleanDest.setPass( QString::null ); // don't put password into commandline 00608 cmd += " " + KProcess::quote(url.url()) + " " + 00609 KProcess::quote(cleanDest.url()); 00610 kdDebug(1000) << "Calling command "<<cmd<<endl; 00611 KRun::runCommand(cmd); 00612 } 00613 } 00614 } 00615 00616 if ( downloadViaKIO ) 00617 { 00618 KIO::Job *job = KIO::copy( url, destURL ); 00619 job->setMetaData(metadata); 00620 job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache. 00621 job->addMetaData("cache", "cache"); // Use entry from cache if available. 00622 job->setAutoErrorHandlingEnabled( true ); 00623 } 00624 } //end if(!saved) 00625 } 00626 } 00627 00628 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension( KHTMLPart *part ) 00629 : KParts::BrowserHostExtension( part ) 00630 { 00631 m_part = part; 00632 } 00633 00634 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension() 00635 { 00636 } 00637 00638 QStringList KHTMLPartBrowserHostExtension::frameNames() const 00639 { 00640 return m_part->frameNames(); 00641 } 00642 00643 const QPtrList<KParts::ReadOnlyPart> KHTMLPartBrowserHostExtension::frames() const 00644 { 00645 return m_part->frames(); 00646 } 00647 00648 bool KHTMLPartBrowserHostExtension::openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs ) 00649 { 00650 return m_part->openURLInFrame( url, urlArgs ); 00651 } 00652 00653 // BCI: remove in KDE 4 00654 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name ) 00655 : KAction( text, icon, 0, receiver, slot, parent, name ) 00656 { 00657 m_direction = direction; 00658 m_part = part; 00659 00660 m_popup = new QPopupMenu; 00661 m_popup->insertItem( i18n( "Default Font Size" ) ); 00662 00663 int m = m_direction ? 1 : -1; 00664 00665 for ( int i = 1; i < 5; ++i ) 00666 { 00667 int num = i * m; 00668 QString numStr = QString::number( num ); 00669 if ( num > 0 ) numStr.prepend( '+' ); 00670 00671 m_popup->insertItem( i18n( "Font Size %1" ).arg( numStr ) ); 00672 } 00673 00674 connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) ); 00675 } 00676 00677 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 ) 00678 : KAction( text, icon, cut, receiver, slot, parent, name ) 00679 { 00680 m_direction = direction; 00681 m_part = part; 00682 00683 m_popup = new QPopupMenu; 00684 m_popup->insertItem( i18n( "Default Font Size" ) ); 00685 00686 int m = m_direction ? 1 : -1; 00687 00688 for ( int i = 1; i < 5; ++i ) 00689 { 00690 int num = i * m; 00691 QString numStr = QString::number( num ); 00692 if ( num > 0 ) numStr.prepend( '+' ); 00693 00694 m_popup->insertItem( i18n( "Font Size %1" ).arg( numStr ) ); 00695 } 00696 00697 connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) ); 00698 } 00699 00700 KHTMLZoomFactorAction::~KHTMLZoomFactorAction() 00701 { 00702 delete m_popup; 00703 } 00704 00705 int KHTMLZoomFactorAction::plug( QWidget *w, int index ) 00706 { 00707 int containerId = KAction::plug( w, index ); 00708 if ( containerId == -1 || !w->inherits( "KToolBar" ) ) 00709 return containerId; 00710 00711 KToolBarButton *button = static_cast<KToolBar *>( w )->getButton( itemId( containerId ) ); 00712 if ( !button ) 00713 return containerId; 00714 00715 button->setDelayedPopup( m_popup ); 00716 return containerId; 00717 } 00718 00719 void KHTMLZoomFactorAction::slotActivated( int id ) 00720 { 00721 int idx = m_popup->indexOf( id ); 00722 00723 if (idx == 0) 00724 m_part->setZoomFactor(100); 00725 else 00726 m_part->setZoomFactor(m_part->zoomFactor() + (m_direction ? 10 : -10) * idx); 00727 } 00728 00729 #include "khtml_ext.moc" 00730
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:23:45 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003