29 #include "khtml_ext.h" 30 #include "khtmlview.h" 31 #include "khtml_pagecache.h" 32 #include "rendering/render_form.h" 33 #include "rendering/render_image.h" 34 #include "html/html_imageimpl.h" 35 #include "misc/loader.h" 36 #include "dom/html_form.h" 37 #include "dom/html_image.h" 38 #include <tqclipboard.h> 39 #include <tqfileinfo.h> 40 #include <tqpopupmenu.h> 42 #include <tqmetaobject.h> 43 #include <tqucomextra_p.h> 44 #include <tqdragobject.h> 48 #include <kfiledialog.h> 51 #include <ktoolbarbutton.h> 53 #include <ksavefile.h> 55 #include <kstringhandler.h> 56 #include <kapplication.h> 57 #include <kmessagebox.h> 58 #include <kstandarddirs.h> 60 #include <kurifilter.h> 61 #include <kiconloader.h> 62 #include <kdesktopfile.h> 63 #include <kmultipledrag.h> 64 #include <kinputdialog.h> 66 #include "khtml_factory.h" 68 #include "dom/dom_element.h" 69 #include "misc/htmltags.h" 71 #include "khtmlpart_p.h" 73 KHTMLPartBrowserExtension::KHTMLPartBrowserExtension(
KHTMLPart *parent,
const char *name )
74 :
KParts::BrowserExtension( parent, name )
77 setURLDropHandlingEnabled(
true );
79 enableAction(
"cut",
false );
80 enableAction(
"copy",
false );
81 enableAction(
"paste",
false );
83 m_connectedToClipboard =
false;
86 int KHTMLPartBrowserExtension::xOffset()
88 return m_part->view()->contentsX();
91 int KHTMLPartBrowserExtension::yOffset()
93 return m_part->view()->contentsY();
96 void KHTMLPartBrowserExtension::saveState( TQDataStream &stream )
99 m_part->saveState( stream );
102 void KHTMLPartBrowserExtension::restoreState( TQDataStream &stream )
105 m_part->restoreState( stream );
108 void KHTMLPartBrowserExtension::editableWidgetFocused( TQWidget *widget )
110 m_editableFormWidget = widget;
113 if ( !m_connectedToClipboard && m_editableFormWidget )
115 connect( TQApplication::clipboard(), TQT_SIGNAL( dataChanged() ),
116 this, TQT_SLOT( updateEditActions() ) );
118 if ( m_editableFormWidget->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) || m_editableFormWidget->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) )
119 connect( m_editableFormWidget, TQT_SIGNAL( selectionChanged() ),
120 this, TQT_SLOT( updateEditActions() ) );
122 m_connectedToClipboard =
true;
124 editableWidgetFocused();
127 void KHTMLPartBrowserExtension::editableWidgetBlurred( TQWidget * )
129 TQWidget *oldWidget = m_editableFormWidget;
131 m_editableFormWidget = 0;
132 enableAction(
"cut",
false );
133 enableAction(
"paste",
false );
134 m_part->emitSelectionChanged();
136 if ( m_connectedToClipboard )
138 disconnect( TQApplication::clipboard(), TQT_SIGNAL( dataChanged() ),
139 this, TQT_SLOT( updateEditActions() ) );
143 if ( oldWidget->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) || oldWidget->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) )
144 disconnect( oldWidget, TQT_SIGNAL( selectionChanged() ),
145 this, TQT_SLOT( updateEditActions() ) );
148 m_connectedToClipboard =
false;
150 editableWidgetBlurred();
155 if ( m_extensionProxy )
157 disconnect( m_extensionProxy, TQT_SIGNAL( enableAction(
const char *,
bool ) ),
158 this, TQT_SLOT( extensionProxyActionEnabled(
const char *,
bool ) ) );
159 if ( m_extensionProxy->inherits(
"KHTMLPartBrowserExtension" ) )
161 disconnect( m_extensionProxy, TQT_SIGNAL( editableWidgetFocused() ),
162 this, TQT_SLOT( extensionProxyEditableWidgetFocused() ) );
163 disconnect( m_extensionProxy, TQT_SIGNAL( editableWidgetBlurred() ),
164 this, TQT_SLOT( extensionProxyEditableWidgetBlurred() ) );
168 m_extensionProxy = proxy;
170 if ( m_extensionProxy )
172 connect( m_extensionProxy, TQT_SIGNAL( enableAction(
const char *,
bool ) ),
173 this, TQT_SLOT( extensionProxyActionEnabled(
const char *,
bool ) ) );
174 if ( m_extensionProxy->inherits(
"KHTMLPartBrowserExtension" ) )
176 connect( m_extensionProxy, TQT_SIGNAL( editableWidgetFocused() ),
177 this, TQT_SLOT( extensionProxyEditableWidgetFocused() ) );
178 connect( m_extensionProxy, TQT_SIGNAL( editableWidgetBlurred() ),
179 this, TQT_SLOT( extensionProxyEditableWidgetBlurred() ) );
182 enableAction(
"cut", m_extensionProxy->isActionEnabled(
"cut" ) );
183 enableAction(
"copy", m_extensionProxy->isActionEnabled(
"copy" ) );
184 enableAction(
"paste", m_extensionProxy->isActionEnabled(
"paste" ) );
189 enableAction(
"copy",
false );
193 void KHTMLPartBrowserExtension::cut()
195 if ( m_extensionProxy )
197 callExtensionProxyMethod(
"cut()" );
201 if ( !m_editableFormWidget )
204 if ( m_editableFormWidget->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) )
205 static_cast<TQLineEdit *>( &(*m_editableFormWidget) )->
cut();
206 else if ( m_editableFormWidget->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) )
207 static_cast<TQTextEdit *>( &(*m_editableFormWidget) )->
cut();
210 void KHTMLPartBrowserExtension::copy()
212 if ( m_extensionProxy )
214 callExtensionProxyMethod(
"copy()" );
218 kdDebug( 6050 ) <<
"************! KHTMLPartBrowserExtension::copy()" <<
endl;
219 if ( !m_editableFormWidget )
222 TQString text= m_part->selectedText();
223 text.replace( TQChar( 0xa0 ),
' ' );
226 TQClipboard *cb = TQApplication::clipboard();
227 disconnect( cb, TQT_SIGNAL( selectionChanged() ), m_part, TQT_SLOT( slotClearSelection() ) );
228 #ifndef QT_NO_MIMECLIPBOARD 238 htmltext = m_part->selectedTextAsHTML();
239 TQTextDrag *textdrag =
new TQTextDrag(text, 0L);
242 if(!htmltext.isEmpty()) {
243 htmltext.replace( TQChar( 0xa0 ),
' ' );
244 TQTextDrag *htmltextdrag =
new TQTextDrag(htmltext, 0L);
245 htmltextdrag->setSubtype(
"html");
253 connect( cb, TQT_SIGNAL( selectionChanged() ), m_part, TQT_SLOT( slotClearSelection() ) );
257 if ( m_editableFormWidget->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) )
258 static_cast<TQLineEdit *>( &(*m_editableFormWidget) )->
copy();
259 else if ( m_editableFormWidget->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) )
260 static_cast<TQTextEdit *>( &(*m_editableFormWidget) )->
copy();
264 void KHTMLPartBrowserExtension::searchProvider()
267 const TQString searchProviderPrefix = TQString( TQT_TQOBJECT_CONST(sender())->
name() ).mid( 14 );
271 data.setData( searchProviderPrefix + m_part->selectedText() );
272 list <<
"kurisearchfilter" <<
"kuriikwsfilter";
274 if( !KURIFilter::self()->filterURI(data, list) )
276 KDesktopFile file(
"searchproviders/google.desktop",
true,
"services");
277 TQString encodedSearchTerm = m_part->selectedText();
278 TQUrl::encode(encodedSearchTerm);
279 data.setData(file.readEntry(
"Query").replace(
"\\{@}", encodedSearchTerm));
285 emit m_part->browserExtension()->openURLRequest( data.uri(), args );
288 void KHTMLPartBrowserExtension::openSelection()
293 emit m_part->browserExtension()->openURLRequest( m_part->selectedText(), args );
296 void KHTMLPartBrowserExtension::paste()
298 if ( m_extensionProxy )
300 callExtensionProxyMethod(
"paste()" );
304 if ( !m_editableFormWidget )
307 if ( m_editableFormWidget->inherits( TQLINEEDIT_OBJECT_NAME_STRING ) )
308 static_cast<TQLineEdit *>( &(*m_editableFormWidget) )->
paste();
309 else if ( m_editableFormWidget->inherits( TQTEXTEDIT_OBJECT_NAME_STRING ) )
310 static_cast<TQTextEdit *>( &(*m_editableFormWidget) )->
paste();
313 void KHTMLPartBrowserExtension::callExtensionProxyMethod(
const char *method )
315 if ( !m_extensionProxy )
318 int slot = m_extensionProxy->metaObject()->findSlot( method );
323 m_extensionProxy->qt_invoke( slot, o );
326 void KHTMLPartBrowserExtension::updateEditActions()
328 if ( !m_editableFormWidget )
330 enableAction(
"cut",
false );
331 enableAction(
"copy",
false );
332 enableAction(
"paste",
false );
337 #ifndef QT_NO_MIMECLIPBOARD // Handle minimalized versions of Qt Embedded 338 TQMimeSource *data = TQApplication::clipboard()->data();
339 enableAction(
"paste", data->provides(
"text/plain" ) );
341 TQString data=TQApplication::clipboard()->text();
342 enableAction(
"paste", data.contains(
"://"));
344 bool hasSelection =
false;
346 if( m_editableFormWidget) {
347 if ( ::tqqt_cast<TQLineEdit*>(m_editableFormWidget))
348 hasSelection = static_cast<TQLineEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
349 else if(::tqqt_cast<TQTextEdit*>(m_editableFormWidget))
350 hasSelection = static_cast<TQTextEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
353 enableAction(
"copy", hasSelection );
354 enableAction(
"cut", hasSelection );
357 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetFocused() {
358 editableWidgetFocused();
361 void KHTMLPartBrowserExtension::extensionProxyEditableWidgetBlurred() {
362 editableWidgetBlurred();
365 void KHTMLPartBrowserExtension::extensionProxyActionEnabled(
const char *action,
bool enable )
368 if ( strcmp( action,
"cut" ) == 0 ||
369 strcmp( action,
"copy" ) == 0 ||
370 strcmp( action,
"paste" ) == 0 ) {
371 enableAction( action, enable );
375 void KHTMLPartBrowserExtension::reparseConfiguration()
377 m_part->reparseConfiguration();
380 void KHTMLPartBrowserExtension::print()
382 m_part->view()->print();
385 void KHTMLPartBrowserExtension::disableScrolling()
387 TQScrollView *scrollView = m_part->view();
389 scrollView->setVScrollBarMode(TQScrollView::AlwaysOff);
390 scrollView->setHScrollBarMode(TQScrollView::AlwaysOff);
394 class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate
401 TQString m_suggestedFilename;
405 KHTMLPopupGUIClient::KHTMLPopupGUIClient(
KHTMLPart *
khtml,
const TQString &doc,
const KURL &url )
408 d =
new KHTMLPopupGUIClientPrivate;
411 bool isImage =
false;
418 if ( !e.isNull() && (e.elementId() == ID_IMG ||
421 if (e.elementId() == ID_IMG) {
422 DOM::HTMLImageElementImpl *ie =
static_cast<DOM::HTMLImageElementImpl*
>(e.handle());
423 khtml::RenderImage *ri =
dynamic_cast<khtml::RenderImage*
>(ie->renderer());
424 if (ri && ri->contentObject()) {
425 d->m_suggestedFilename =
static_cast<khtml::CachedImage*
>(ri->contentObject())->suggestedFilename();
434 copyAction->
setText(i18n(
"&Copy Text"));
435 copyAction->
setEnabled(d->m_khtml->browserExtension()->isActionEnabled(
"copy" ));
440 KConfig config(
"kuriikwsfilterrc");
441 config.setGroup(
"General");
442 const TQString defaultEngine = config.readEntry(
"DefaultSearchEngine",
"google");
443 const char keywordDelimiter = config.readNumEntry(
"KeywordDelimiter",
':');
447 selectedText.replace(
"&",
"&&");
448 if ( selectedText.length()>18 ) {
449 selectedText.truncate(15);
454 KService::Ptr service = KService::serviceByDesktopPath(TQString(
"searchproviders/%1.desktop").arg(defaultEngine));
460 data.setData( TQString(
"some keyword") );
461 list <<
"kurisearchfilter" <<
"kuriikwsfilter";
464 if ( KURIFilter::self()->filterURI(data, list) )
466 TQString iconPath =
locate(
"cache", KMimeType::favIconForURL(data.uri()) +
".png");
467 if ( iconPath.isEmpty() )
468 icon = SmallIcon(
"find");
470 icon = TQPixmap( iconPath );
471 name = service->name();
475 icon = SmallIcon(
"google");
480 new KAction( i18n(
"Search for '%1' with %2" ).arg( selectedText, name ), icon, 0, d->m_khtml->browserExtension(),
481 TQT_SLOT( searchProvider() ), actionCollection(),
"searchProvider" );
484 TQStringList favoriteEngines;
485 favoriteEngines <<
"google" <<
"google_groups" <<
"google_news" <<
"webster" <<
"dmoz" <<
"wikipedia";
486 favoriteEngines = config.readListEntry(
"FavoriteSearchEngines", favoriteEngines);
488 if ( !favoriteEngines.isEmpty()) {
489 KActionMenu* providerList =
new KActionMenu( i18n(
"Search for '%1' with" ).arg( selectedText ), actionCollection(),
"searchProviderList" );
491 TQStringList::ConstIterator it = favoriteEngines.begin();
492 for ( ; it != favoriteEngines.end(); ++it ) {
493 if (*it==defaultEngine)
495 service = KService::serviceByDesktopPath(TQString(
"searchproviders/%1.desktop").arg(*it));
498 const TQString searchProviderPrefix = *(service->property(
"Keys").toStringList().begin()) + keywordDelimiter;
499 data.setData( searchProviderPrefix +
"some keyword" );
501 if ( KURIFilter::self()->filterURI(data, list) )
503 TQString iconPath =
locate(
"cache", KMimeType::favIconForURL(data.uri()) +
".png");
504 if ( iconPath.isEmpty() )
505 icon = SmallIcon(
"find");
507 icon = TQPixmap( iconPath );
508 name = service->name();
510 providerList->insert(
new KAction( name, icon, 0, d->m_khtml->browserExtension(),
511 TQT_SLOT( searchProvider() ), actionCollection(), TQString(
"searchProvider" + searchProviderPrefix ).latin1() ) );
517 if ( selectedText.contains(
"://") &&
KURL(selectedText).
isValid() )
518 new KAction( i18n(
"Open '%1'" ).arg( selectedText ),
"window_new", 0,
519 d->m_khtml->browserExtension(), TQT_SLOT( openSelection() ), actionCollection(),
"openSelection" );
521 else if ( url.
isEmpty() && !isImage )
525 new KAction( i18n(
"Stop Animations" ), 0,
this, TQT_SLOT( slotStopAnimations() ),
526 actionCollection(),
"stopanimations" );
533 new KAction( i18n(
"Copy Email Address" ), 0,
this, TQT_SLOT( slotCopyLinkLocation() ),
534 actionCollection(),
"copylinklocation" );
538 new KAction( i18n(
"&Save Link As..." ), 0,
this, TQT_SLOT( slotSaveLinkAs() ),
539 actionCollection(),
"savelinkas" );
540 new KAction( i18n(
"Copy &Link Address" ), 0,
this, TQT_SLOT( slotCopyLinkLocation() ),
541 actionCollection(),
"copylinklocation" );
550 new KAction( i18n(
"Open in New &Window" ),
"window_new", 0,
this, TQT_SLOT( slotFrameInWindow() ),
551 actionCollection(),
"frameinwindow" );
552 new KAction( i18n(
"Open in &This Window" ), 0,
this, TQT_SLOT( slotFrameInTop() ),
553 actionCollection(),
"frameintop" );
554 new KAction( i18n(
"Open in &New Tab" ),
"tab_new", 0,
this, TQT_SLOT( slotFrameInTab() ),
555 actionCollection(),
"frameintab" );
556 new KAction( i18n(
"Reload Frame" ), 0,
this, TQT_SLOT( slotReloadFrame() ),
557 actionCollection(),
"reloadframe" );
559 if ( KHTMLFactory::defaultHTMLSettings()->isAdFilterEnabled() ) {
560 if ( khtml->d->m_frame->m_type == khtml::ChildFrame::IFrame )
561 new KAction( i18n(
"Block IFrame..." ), 0,
this, TQT_SLOT( slotBlockIFrame() ), actionCollection(),
"blockiframe" );
564 new KAction( i18n(
"View Frame Source" ), 0, d->m_khtml, TQT_SLOT( slotViewDocumentSource() ),
565 actionCollection(),
"viewFrameSource" );
566 new KAction( i18n(
"View Frame Information" ), 0, d->m_khtml, TQT_SLOT( slotViewPageInfo() ), actionCollection(),
"viewFrameInfo" );
570 new KAction( i18n(
"Print Frame..." ),
"frameprint", 0, d->m_khtml->browserExtension(), TQT_SLOT(
print() ), actionCollection(),
"printFrame" );
571 new KAction( i18n(
"Save &Frame As..." ), 0, d->m_khtml, TQT_SLOT( slotSaveFrame() ), actionCollection(),
"saveFrame" );
579 }
else if (isImage || !url.
isEmpty()) {
582 new KAction( i18n(
"Stop Animations" ), 0,
this, TQT_SLOT( slotStopAnimations() ),
583 actionCollection(),
"stopanimations" );
588 if ( e.elementId() == ID_IMG ) {
589 d->m_imageURL =
KURL( static_cast<DOM::HTMLImageElement>( e ).src().
string() );
590 DOM::HTMLImageElementImpl *imageimpl =
static_cast<DOM::HTMLImageElementImpl *
>( e.handle() );
594 if(imageimpl->complete()) {
595 d->m_pixmap = imageimpl->currentPixmap();
600 d->m_imageURL =
KURL( static_cast<DOM::HTMLInputElement>( e ).src().
string() );
601 new KAction( i18n(
"Save Image As..." ), 0,
this, TQT_SLOT( slotSaveImageAs() ),
602 actionCollection(),
"saveimageas" );
603 new KAction( i18n(
"Send Image..." ), 0,
this, TQT_SLOT( slotSendImage() ),
604 actionCollection(),
"sendimage" );
607 #ifndef QT_NO_MIMECLIPBOARD 608 (
new KAction( i18n(
"Copy Image" ), 0,
this, TQT_SLOT( slotCopyImage() ),
609 actionCollection(),
"copyimage" ))->setEnabled(!d->m_pixmap.isNull());
612 if(d->m_pixmap.isNull()) {
613 new KAction( i18n(
"Copy Image Location" ), 0,
this, TQT_SLOT( slotCopyImageLocation() ),
614 actionCollection(),
"copyimagelocation" );
618 new KAction( i18n(
"View Image (%1)" ).arg(d->m_suggestedFilename.isEmpty() ? name.replace(
"&",
"&&") : d->m_suggestedFilename.replace(
"&",
"&&")), 0,
this, TQT_SLOT( slotViewImage() ),
619 actionCollection(),
"viewimage" );
621 if (KHTMLFactory::defaultHTMLSettings()->isAdFilterEnabled())
623 new KAction( i18n(
"Block Image..." ), 0,
this, TQT_SLOT( slotBlockImage() ),
624 actionCollection(),
"blockimage" );
626 if (!d->m_imageURL.host().isEmpty() &&
627 !d->m_imageURL.protocol().isEmpty())
629 new KAction( i18n(
"Block Images From %1" ).arg(d->m_imageURL.host()), 0,
this, TQT_SLOT( slotBlockHost() ),
630 actionCollection(),
"blockhost" );
636 setDOMDocument( TQDomDocument(),
true );
638 TQDomElement menu = domDocument().documentElement().namedItem(
"Menu" ).toElement();
640 if ( actionCollection()->count() > 0 )
641 menu.insertBefore( domDocument().createElement(
"separator" ), menu.firstChild() );
644 KHTMLPopupGUIClient::~KHTMLPopupGUIClient()
649 void KHTMLPopupGUIClient::slotSaveLinkAs()
651 KIO::MetaData metaData;
652 metaData[
"referrer"] = d->m_khtml->referrer();
653 saveURL( d->m_khtml->widget(), i18n(
"Save Link As" ), d->m_url, metaData );
656 void KHTMLPopupGUIClient::slotSendImage()
659 urls.append( d->m_imageURL.url());
660 TQString subject = d->m_imageURL.url();
661 kapp->invokeMailer(TQString::null, TQString::null, TQString::null, subject,
669 void KHTMLPopupGUIClient::slotSaveImageAs()
671 KIO::MetaData metaData;
672 metaData[
"referrer"] = d->m_khtml->referrer();
673 saveURL( d->m_khtml->widget(), i18n(
"Save Image As" ), d->m_imageURL, metaData, TQString::null, 0, d->m_suggestedFilename );
676 void KHTMLPopupGUIClient::slotBlockHost()
678 TQString name=d->m_imageURL.protocol()+
"://"+d->m_imageURL.host()+
"/*";
679 KHTMLFactory::defaultHTMLSettings()->addAdFilter( name );
680 d->m_khtml->reparseConfiguration();
683 void KHTMLPopupGUIClient::slotBlockImage()
688 i18n(
"Enter the URL:"),
692 KHTMLFactory::defaultHTMLSettings()->addAdFilter( url );
693 d->m_khtml->reparseConfiguration();
697 void KHTMLPopupGUIClient::slotBlockIFrame()
701 i18n(
"Enter the URL:"),
702 d->m_khtml->url().url(),
705 KHTMLFactory::defaultHTMLSettings()->addAdFilter( url );
706 d->m_khtml->reparseConfiguration();
710 void KHTMLPopupGUIClient::slotCopyLinkLocation()
712 KURL safeURL(d->m_url);
713 safeURL.setPass(TQString::null);
714 #ifndef QT_NO_MIMECLIPBOARD 717 lst.append( safeURL );
718 TQApplication::clipboard()->setData(
new KURLDrag( lst ), TQClipboard::Clipboard );
719 TQApplication::clipboard()->setData(
new KURLDrag( lst ), TQClipboard::Selection );
721 TQApplication::clipboard()->setText( safeURL.url() );
725 void KHTMLPopupGUIClient::slotStopAnimations()
727 d->m_khtml->stopAnimations();
730 void KHTMLPopupGUIClient::slotCopyImage()
732 #ifndef QT_NO_MIMECLIPBOARD 733 KURL safeURL(d->m_imageURL);
734 safeURL.setPass(TQString::null);
737 lst.append( safeURL );
740 drag->
addDragObject(
new TQImageDrag(d->m_pixmap.convertToImage()) );
744 TQApplication::clipboard()->setData( drag, TQClipboard::Clipboard );
745 TQApplication::clipboard()->setData(
new KURLDrag(lst), TQClipboard::Selection );
747 kdDebug() <<
"slotCopyImage called when the clipboard does not support this. This should not be possible." <<
endl;
751 void KHTMLPopupGUIClient::slotCopyImageLocation()
753 KURL safeURL(d->m_imageURL);
754 safeURL.setPass(TQString::null);
755 #ifndef QT_NO_MIMECLIPBOARD 758 lst.append( safeURL );
759 TQApplication::clipboard()->setData(
new KURLDrag( lst ), TQClipboard::Clipboard );
760 TQApplication::clipboard()->setData(
new KURLDrag( lst ), TQClipboard::Selection );
762 TQApplication::clipboard()->setText( safeURL.url() );
766 void KHTMLPopupGUIClient::slotViewImage()
768 d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL);
771 void KHTMLPopupGUIClient::slotReloadFrame()
775 args.
metaData()[
"referrer"] = d->m_khtml->pageReferrer();
777 d->m_khtml->closeURL();
778 d->m_khtml->browserExtension()->setURLArgs( args );
779 d->m_khtml->openURL( d->m_khtml->url() );
782 void KHTMLPopupGUIClient::slotFrameInWindow()
785 args.
metaData()[
"referrer"] = d->m_khtml->pageReferrer();
786 args.
metaData()[
"forcenewwindow"] =
"true";
787 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
790 void KHTMLPopupGUIClient::slotFrameInTop()
793 args.
metaData()[
"referrer"] = d->m_khtml->pageReferrer();
795 emit d->m_khtml->browserExtension()->openURLRequest( d->m_khtml->url(), args );
798 void KHTMLPopupGUIClient::slotFrameInTab()
801 args.
metaData()[
"referrer"] = d->m_khtml->pageReferrer();
803 emit d->m_khtml->browserExtension()->createNewWindow( d->m_khtml->url(), args );
806 void KHTMLPopupGUIClient::saveURL( TQWidget *parent,
const TQString &caption,
808 const TQMap<TQString, TQString> &metadata,
809 const TQString &filter,
long cacheId,
810 const TQString & suggestedFilename )
812 TQString name = TQString::fromLatin1(
"index.html" );
813 if ( !suggestedFilename.isEmpty() )
814 name = suggestedFilename;
815 else if ( !url.
fileName().isEmpty() )
821 query = KMessageBox::Yes;
822 destURL = KFileDialog::getSaveURL( name, filter, parent, caption );
825 TQFileInfo info( destURL.
path() );
826 if( info.exists() ) {
828 query =
KMessageBox::warningContinueCancel( parent, i18n(
"A file named \"%1\" already exists. " "Are you sure you want to overwrite it?" ).arg( info.fileName() ), i18n(
"Overwrite File?" ), i18n(
"Overwrite" ) );
831 }
while ( query == KMessageBox::Cancel );
834 saveURL(url, destURL, metadata, cacheId);
837 void KHTMLPopupGUIClient::saveURL(
const KURL &url,
const KURL &destURL,
838 const TQMap<TQString, TQString> &metadata,
849 if (destFile.status() == 0)
859 if (destFile.
status() == 0)
865 KIO::file_move(url2, destURL, -1,
true );
876 bool downloadViaKIO =
true;
879 KConfig cfg(
"konquerorrc",
false,
false);
880 cfg.setGroup(
"HTML Settings");
881 TQString downloadManger = cfg.readPathEntry(
"DownloadManager");
882 if (!downloadManger.isEmpty())
885 kdDebug(1000) <<
"Using: "<<downloadManger <<
" as Download Manager" <<
endl;
889 TQString errMsg=i18n(
"The Download Manager (%1) could not be found in your $PATH ").arg(downloadManger);
890 TQString errMsgEx= i18n(
"Try to reinstall it \n\nThe integration with Konqueror will be disabled!");
892 cfg.writePathEntry(
"DownloadManager",TQString::null);
897 downloadViaKIO =
false;
898 KURL cleanDest = destURL;
899 cleanDest.
setPass( TQString::null );
903 KRun::runCommand(cmd);
908 if ( downloadViaKIO )
910 KIO::Job *job = KIO::file_copy( url, destURL, -1,
true );
911 job->setMetaData(metadata);
912 job->addMetaData(
"MaxCacheSize",
"0");
913 job->addMetaData(
"cache",
"cache");
914 job->setAutoErrorHandlingEnabled(
true );
920 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension(
KHTMLPart *part )
921 :
KParts::BrowserHostExtension( part )
926 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension()
930 TQStringList KHTMLPartBrowserHostExtension::frameNames()
const 935 const TQPtrList<KParts::ReadOnlyPart> KHTMLPartBrowserHostExtension::frames()
const 937 return m_part->frames();
940 bool KHTMLPartBrowserHostExtension::openURLInFrame(
const KURL &url,
const KParts::URLArgs &urlArgs )
942 return m_part->openURLInFrame( url, urlArgs );
945 void KHTMLPartBrowserHostExtension::virtual_hook(
int id,
void *data )
947 if (
id == VIRTUAL_FIND_FRAME_PARENT)
949 FindFrameParentParams *param =
static_cast<FindFrameParentParams*
>(data);
952 param->parent = parentPart->browserHostExtension();
955 BrowserHostExtension::virtual_hook(
id, data );
960 extern const int KDE_NO_EXPORT fastZoomSizes[];
961 extern const int KDE_NO_EXPORT fastZoomSizeCount;
964 KHTMLZoomFactorAction::KHTMLZoomFactorAction(
KHTMLPart *part,
bool direction,
const TQString &text,
const TQString &icon,
const TQObject *receiver,
const char *slot, TQObject *parent,
const char *name )
965 :
KAction( text, icon, 0, receiver, slot, parent, name )
967 init(part, direction);
970 KHTMLZoomFactorAction::KHTMLZoomFactorAction(
KHTMLPart *part,
bool direction,
const TQString &text,
const TQString &icon,
const KShortcut &cut,
const TQObject *receiver,
const char *slot, TQObject *parent,
const char *name )
971 :
KAction( text, icon, cut, receiver, slot, parent, name )
973 init(part, direction);
976 void KHTMLZoomFactorAction::init(
KHTMLPart *part,
bool direction)
978 m_direction = direction;
981 m_popup =
new TQPopupMenu;
983 m_popup->insertItem( i18n(
"Default Font Size (100%)" ) );
985 int m = m_direction ? 1 : -1;
986 int ofs = fastZoomSizeCount / 2;
989 for (
int i = m; i != m*(ofs+1); i += m )
992 TQString numStr = TQString::number( num );
993 if ( num > 0 ) numStr.prepend(
'+' );
996 m_popup->insertItem( i18n(
"%1%" ).arg( fastZoomSizes[ofs + i] ) );
999 connect( m_popup, TQT_SIGNAL( activated(
int ) ),
this, TQT_SLOT( slotActivated(
int ) ) );
1002 KHTMLZoomFactorAction::~KHTMLZoomFactorAction()
1007 int KHTMLZoomFactorAction::plug( TQWidget *w,
int index )
1010 if ( containerId == -1 || !w->inherits(
"KToolBar" ) )
1021 void KHTMLZoomFactorAction::slotActivated(
int id )
1023 int idx = m_popup->indexOf(
id );
1026 m_part->setZoomFactor(100);
1028 m_part->setZoomFactor(fastZoomSizes[fastZoomSizeCount/2 + (m_direction ? 1 : -1)*idx]);
1031 #include "khtml_ext.moc"
DOM::Node nodeUnderMouse() const
Returns the Node currently under the mouse.
TQString locate(const char *type, const TQString &filename, const KInstance *instance=KGlobal::instance())
static KHTMLPageCache * self()
static "constructor".
const KShortcut & paste()
TQString url(int _trailing=0, int encoding_hint=0) const
static TQString csqueeze(const TQString &str, uint maxlen=40)
TQDataStream * dataStream()
TQString protocol() const
This class is khtml's main class.
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
kdbgstream kdDebug(int area=0)
KAction * copy(const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0)
KHTMLPart * findFrameParent(KParts::ReadOnlyPart *callingPart, const TQString &f, khtml::ChildFrame **childFrame=0)
Recursively finds the part containing the frame with name f and checks if it is accessible by calling...
By far the vast majority of objects (apart from text) that authors encounter when traversing a docume...
void setPass(const TQString &_txt)
void setPath(const TQString &path)
static void detailedSorry(TQWidget *parent, const TQString &text, const TQString &details, const TQString &caption=TQString::null, int options=Notify)
virtual int plug(TQWidget *widget, int index=-1)
TQString fileName(bool _ignore_trailing_slash_in_path=true) const
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
void saveData(long id, TQDataStream *str)
Save the data of cache entry id to the datastream str.
virtual TQString selectedText() const
Returns the text the user has marked.
void setNewTab(bool newTab)
bool hasSelection() const
Has the user selected anything?
TQString name(StdAccel id)
static TQString quote(const TQString &arg)
void addDragObject(TQDragObject *dragObject)
TQMap< TQString, TQString > & metaData()
virtual KActionCollection * actionCollection() const
kndbgstream & endl(kndbgstream &s)
virtual KInstance * instance() const
const KShortcut & print()
virtual void setEnabled(bool enable)
virtual void setText(const TQString &text)
TQStringList frameNames() const
Returns a list of names of all frame (including iframe) objects of the current document.
KHTMLPart * parentPart()
Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset.
virtual KAction * action(int index) const