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
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 );
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
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
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
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
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
00374
00375
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 );
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,
00432 QString::null,
00433 urls);
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 #ifndef QT_NO_MIMECLIPBOARD
00448
00449 KURL::List lst;
00450 lst.append( d->m_url );
00451 if ( d->m_url.url().contains( "mailto:" ) )
00452 {
00453 QApplication::clipboard()->setSelectionMode(true);
00454 QApplication::clipboard()->setText(d->m_url.path() );
00455 QApplication::clipboard()->setSelectionMode(false);
00456 QApplication::clipboard()->setText(d->m_url.path() );
00457 }
00458 else
00459 {
00460 QApplication::clipboard()->setSelectionMode(true);
00461 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00462 QApplication::clipboard()->setSelectionMode(false);
00463 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00464 }
00465 #else
00466 QApplication::clipboard()->setText( d->m_url.url() );
00467 #endif
00468 }
00469
00470 void KHTMLPopupGUIClient::slotStopAnimations()
00471 {
00472 d->m_khtml->stopAnimations();
00473 }
00474
00475 void KHTMLPopupGUIClient::slotCopyImageLocation()
00476 {
00477 #ifndef QT_NO_MIMECLIPBOARD
00478
00479 KURL::List lst;
00480 lst.append( d->m_imageURL);
00481 QApplication::clipboard()->setSelectionMode(true);
00482 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00483 QApplication::clipboard()->setSelectionMode(false);
00484 QApplication::clipboard()->setData( new KURLDrag( lst ) );
00485 #else
00486 QApplication::clipboard()->setText(d->m_imageURL.url());
00487 #endif
00488 }
00489
00490 void KHTMLPopupGUIClient::slotViewImage()
00491 {
00492 d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL);
00493 }
00494
00495 void KHTMLPopupGUIClient::slotReloadFrame()
00496 {
00497 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00498 args.reload = true;
00499 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00500
00501 d->m_khtml->closeURL();
00502 d->m_khtml->browserExtension()->setURLArgs( args );
00503 d->m_khtml->openURL( d->m_khtml->url() );
00504 }
00505
00506 void KHTMLPopupGUIClient::slotFrameInWindow()
00507 {
00508 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00509 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00510 args.metaData()["forcenewwindow"] = "true";
00511 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
00512 }
00513
00514 void KHTMLPopupGUIClient::slotFrameInTab()
00515 {
00516 KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00517 args.metaData()["referrer"] = d->m_khtml->pageReferrer();
00518 args.setNewTab(true);
00519 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
00520 }
00521
00522 void KHTMLPopupGUIClient::saveURL( QWidget *parent, const QString &caption,
00523 const KURL &url,
00524 const QMap<QString, QString> &metadata,
00525 const QString &filter, long cacheId,
00526 const QString & suggestedFilename )
00527 {
00528 QString name = QString::fromLatin1( "index.html" );
00529 if ( !suggestedFilename.isEmpty() )
00530 name = suggestedFilename;
00531 else if ( !url.fileName().isEmpty() )
00532 name = url.fileName();
00533
00534 KURL destURL;
00535 int query;
00536 do {
00537 query = KMessageBox::Yes;
00538 destURL = KFileDialog::getSaveURL( name, filter, parent, caption );
00539 if( destURL.isLocalFile() )
00540 {
00541 QFileInfo info( destURL.path() );
00542 if( info.exists() )
00543 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() );
00544 }
00545 } while ( query == KMessageBox::No );
00546
00547 if ( destURL.isValid() )
00548 saveURL(url, destURL, metadata, cacheId);
00549 }
00550
00551 void KHTMLPopupGUIClient::saveURL( const KURL &url, const KURL &destURL,
00552 const QMap<QString, QString> &metadata,
00553 long cacheId )
00554 {
00555 if ( destURL.isValid() )
00556 {
00557 bool saved = false;
00558 if (KHTMLPageCache::self()->isComplete(cacheId))
00559 {
00560 if (destURL.isLocalFile())
00561 {
00562 KSaveFile destFile(destURL.path());
00563 if (destFile.status() == 0)
00564 {
00565 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00566 saved = true;
00567 }
00568 }
00569 else
00570 {
00571
00572 KTempFile destFile;
00573 if (destFile.status() == 0)
00574 {
00575 KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00576 destFile.close();
00577 KURL url2 = KURL();
00578 url2.setPath(destFile.name());
00579 KIO::move(url2, destURL);
00580 saved = true;
00581 }
00582 }
00583 }
00584 if(!saved)
00585 {
00586
00587
00588
00589
00590 bool downloadViaKIO = true;
00591 if ( !url.isLocalFile() )
00592 {
00593 KConfig cfg("konquerorrc", false, false);
00594 cfg.setGroup("HTML Settings");
00595 QString downloadManger = cfg.readPathEntry("DownloadManager");
00596 if (!downloadManger.isEmpty())
00597 {
00598
00599 kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl;
00600 QString cmd = KStandardDirs::findExe(downloadManger);
00601 if (cmd.isEmpty())
00602 {
00603 QString errMsg=i18n("The Download Manager (%1) could not be found in your $PATH ").arg(downloadManger);
00604 QString errMsgEx= i18n("Try to reinstall it \n\nThe integration with Konqueror will be disabled!");
00605 KMessageBox::detailedSorry(0,errMsg,errMsgEx);
00606 cfg.writePathEntry("DownloadManager",QString::null);
00607 cfg.sync ();
00608 }
00609 else
00610 {
00611 downloadViaKIO = false;
00612 KURL cleanDest = destURL;
00613 cleanDest.setPass( QString::null );
00614 cmd += " " + KProcess::quote(url.url()) + " " +
00615 KProcess::quote(cleanDest.url());
00616 kdDebug(1000) << "Calling command "<<cmd<<endl;
00617 KRun::runCommand(cmd);
00618 }
00619 }
00620 }
00621
00622 if ( downloadViaKIO )
00623 {
00624 KIO::Job *job = KIO::copy( url, destURL );
00625 job->setMetaData(metadata);
00626 job->addMetaData("MaxCacheSize", "0");
00627 job->addMetaData("cache", "cache");
00628 job->setAutoErrorHandlingEnabled( true );
00629 }
00630 }
00631 }
00632 }
00633
00634 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension( KHTMLPart *part )
00635 : KParts::BrowserHostExtension( part )
00636 {
00637 m_part = part;
00638 }
00639
00640 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension()
00641 {
00642 }
00643
00644 QStringList KHTMLPartBrowserHostExtension::frameNames() const
00645 {
00646 return m_part->frameNames();
00647 }
00648
00649 const QPtrList<KParts::ReadOnlyPart> KHTMLPartBrowserHostExtension::frames() const
00650 {
00651 return m_part->frames();
00652 }
00653
00654 bool KHTMLPartBrowserHostExtension::openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs )
00655 {
00656 return m_part->openURLInFrame( url, urlArgs );
00657 }
00658
00659 void KHTMLPartBrowserHostExtension::virtual_hook( int id, void *data )
00660 {
00661 if (id == VIRTUAL_FIND_FRAME_PARENT)
00662 {
00663 FindFrameParentParams *param = static_cast<FindFrameParentParams*>(data);
00664 KHTMLPart *parentPart = m_part->findFrameParent(param->callingPart, param->frame);
00665 if (parentPart)
00666 param->parent = parentPart->browserHostExtension();
00667 return;
00668 }
00669 BrowserHostExtension::virtual_hook( id, data );
00670 }
00671
00672
00673 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name )
00674 : KAction( text, icon, 0, receiver, slot, parent, name )
00675 {
00676 m_direction = direction;
00677 m_part = part;
00678
00679 m_popup = new QPopupMenu;
00680 m_popup->insertItem( i18n( "Default Font Size" ) );
00681
00682 int m = m_direction ? 1 : -1;
00683
00684 for ( int i = 1; i < 5; ++i )
00685 {
00686 int num = i * m;
00687 QString numStr = QString::number( num );
00688 if ( num > 0 ) numStr.prepend( '+' );
00689
00690 m_popup->insertItem( i18n( "Font Size %1" ).arg( numStr ) );
00691 }
00692
00693 connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) );
00694 }
00695
00696 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 )
00697 : KAction( text, icon, cut, receiver, slot, parent, name )
00698 {
00699 m_direction = direction;
00700 m_part = part;
00701
00702 m_popup = new QPopupMenu;
00703 m_popup->insertItem( i18n( "Default Font Size" ) );
00704
00705 int m = m_direction ? 1 : -1;
00706
00707 for ( int i = 1; i < 5; ++i )
00708 {
00709 int num = i * m;
00710 QString numStr = QString::number( num );
00711 if ( num > 0 ) numStr.prepend( '+' );
00712
00713 m_popup->insertItem( i18n( "Font Size %1" ).arg( numStr ) );
00714 }
00715
00716 connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) );
00717 }
00718
00719 KHTMLZoomFactorAction::~KHTMLZoomFactorAction()
00720 {
00721 delete m_popup;
00722 }
00723
00724 int KHTMLZoomFactorAction::plug( QWidget *w, int index )
00725 {
00726 int containerId = KAction::plug( w, index );
00727 if ( containerId == -1 || !w->inherits( "KToolBar" ) )
00728 return containerId;
00729
00730 KToolBarButton *button = static_cast<KToolBar *>( w )->getButton( itemId( containerId ) );
00731 if ( !button )
00732 return containerId;
00733
00734 button->setDelayedPopup( m_popup );
00735 return containerId;
00736 }
00737
00738 void KHTMLZoomFactorAction::slotActivated( int id )
00739 {
00740 int idx = m_popup->indexOf( id );
00741
00742 if (idx == 0)
00743 m_part->setZoomFactor(100);
00744 else
00745 m_part->setZoomFactor(m_part->zoomFactor() + (m_direction ? 10 : -10) * idx);
00746 }
00747
00748 #include "khtml_ext.moc"
00749