void EvaChatView::searchProvider() { // action name is of form "previewProvider[<searchproviderprefix>:]" const TQString searchProviderPrefix = TQString( sender()->name() ).mid( 14 ); KURIFilterData data; TQStringList list; data.setData( searchProviderPrefix + this->selectedText() ); list << "kurisearchfilter" << "kuriikwsfilter"; if( !KURIFilter::self()->filterURI(data, list) ) { KDesktopFile file("searchproviders/google.desktop", true, "services"); data.setData(file.readEntry("Query").replace("\\{@}", this->selectedText())); } KParts::URLArgs args; args.frameName = "_blank"; emit slotLinkClicked( data.uri(), args ); }
/* we just simplify the process. if we use KParts::BrowserExtension, we have to do lots extra work, adding so much classes. so just hack like following. grab useful code from TDEHTMLPopupGUIClient(tdehtml_ext.cpp), and change a little bit to fit our needs */ void EvaChatView::slotPopupMenu( const TQString & _url, const TQPoint & point ) { menu->clear(); bool isImage = false; bool hasSelection = TDEHTMLPart::hasSelection(); KURL url = KURL(_url); if(d) delete d; d = new MenuPrivateData; d->m_url = url; DOM::Element e = nodeUnderMouse(); if ( !e.isNull() && (e.elementId() == ID_IMG) ) { DOM::HTMLImageElement ie = static_cast<DOM::HTMLImageElement>(e); TQString src = ie.src().string(); d->m_imageURL = KURL(src); d->m_suggestedFilename = src.right(src.length() - src.findRev("/") -1); isImage=true; } TDEAction *action = 0L; if(hasSelection) { //action = new TDEAction( i18n( "&Copy Text" ), TDEShortcut("Ctrl+C"), this, SLOT( copy() ), // actionCollection(), "copy" ); //action = KStdAction::copy( browserExtension(), SLOT(copy()), actionCollection(), "copy"); //action->setText(i18n("&Copy Text")); //action->setEnabled(true); copyAction->plug(menu); // search text TQString selectedText = TDEHTMLPart::selectedText(); if ( selectedText.length()>18 ) { selectedText.truncate(15); selectedText+="..."; } #ifdef HAS_KONTQUEROR // Fill search provider entries TDEConfig config("kuriikwsfilterrc"); config.setGroup("General"); const TQString defaultEngine = config.readEntry("DefaultSearchEngine", "google"); const char keywordDelimiter = config.readNumEntry("KeywordDelimiter", ':'); // default search provider KService::Ptr service = KService::serviceByDesktopPath(TQString("searchproviders/%1.desktop").arg(defaultEngine)); // search provider icon TQPixmap icon; KURIFilterData data; TQStringList list; const TQString defaultSearchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; data.setData( defaultSearchProviderPrefix + TQString("some keyword") ); list << "kurisearchfilter" << "kuriikwsfilter"; TQString name; if ( KURIFilter::self()->filterURI(data, list) ) { TQString iconPath = locate("cache", KMimeType::favIconForURL(data.uri()) + ".png"); if ( iconPath.isEmpty() ) icon = SmallIcon("edit-find"); else icon = TQPixmap( iconPath ); name = service->name(); } else { icon = SmallIcon("google"); name = "Google"; } action = new TDEAction( i18n( "Search '%1' at %2" ).arg( selectedText ).arg( name ), icon, 0, this, SLOT( searchProvider() ), actionCollection(), "searchProvider" ); action->plug(menu); // favorite search providers TQStringList favoriteEngines; favoriteEngines = config.readListEntry("FavoriteSearchEngines"); // for KDE 3.2 API compatibility if(favoriteEngines.isEmpty()) favoriteEngines << "google" << "google_groups" << "google_news" << "webster" << "dmoz" << "wikipedia"; if ( !favoriteEngines.isEmpty()) { TDEActionMenu* providerList = new TDEActionMenu( i18n( "Search '%1' At" ).arg( selectedText ), actionCollection(), "searchProviderList" ); bool hasSubMenus = false; TQStringList::ConstIterator it = favoriteEngines.begin(); for ( ; it != favoriteEngines.end(); ++it ) { if (*it==defaultEngine) continue; service = KService::serviceByDesktopPath(TQString("searchproviders/%1.desktop").arg(*it)); if (!service) continue; const TQString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; data.setData( searchProviderPrefix + "some keyword" ); if ( KURIFilter::self()->filterURI(data, list) ) { TQString iconPath = locate("cache", KMimeType::favIconForURL(data.uri()) + ".png"); if ( iconPath.isEmpty() ) icon = SmallIcon("edit-find"); else icon = TQPixmap( iconPath ); name = service->name(); providerList->insert( new TDEAction( name, icon, 0, this, SLOT( searchProvider() ), actionCollection(), TQString( "searchProvider" + searchProviderPrefix ).latin1() ) ); hasSubMenus = true; } } if(hasSubMenus) providerList->plug(menu); } #endif // HAS_KONTQUEROR if ( selectedText.contains("://") && KURL(selectedText).isValid() ) { action = new TDEAction( i18n( "Open '%1'" ).arg( selectedText ), "window_new", 0, this, SLOT( openSelection() ), actionCollection(), "openSelection" ); action->plug(menu); } } if ( !url.isEmpty() ) { if (url.protocol() == "mailto") { action = new TDEAction( i18n( "Copy Email Address" ), 0, this, SLOT( slotCopyLinkLocation() ), actionCollection(), "copylinklocation" ); action->plug(menu); } else { action = new TDEAction( i18n( "Copy &Link Address" ), 0, this, SLOT( slotCopyLinkLocation() ), actionCollection(), "copylinklocation" ); action->plug(menu); } } if (isImage) { #ifndef QT_NO_MIMECLIPBOARD action = (new TDEAction( i18n( "Copy Image" ), 0, this, SLOT( slotCopyImage() ), actionCollection(), "copyimage" )); action->plug(menu); #endif action = new TDEAction( i18n( "Save Image As..." ), 0, this, SLOT( slotSaveImageAs() ), actionCollection(), "saveimageas" ); action->plug(menu); action = new TDEAction( i18n( "Save As Custom Smiley"), 0, this, SLOT( slotSaveAsCustomSmiley() ), actionCollection(), "saveascustomsmiley" ); action->plug(menu); } if(menu->count()) menu->popup(point); }