void URLGrabber::matchingMimeActions(const QString& clipData) { KUrl url(clipData); KConfigGroup cg(KGlobal::config(), "Actions"); if(!cg.readEntry("EnableMagicMimeActions",true)) { //kDebug() << "skipping mime magic due to configuration"; return; } if(!url.isValid()) { //kDebug() << "skipping mime magic due to invalid url"; return; } if(url.isRelative()) { //openinng a relative path will just not work. what path should be used? //kDebug() << "skipping mime magic due to relative url"; return; } if(url.isLocalFile()) { if ( clipData == "//") { //kDebug() << "skipping mime magic due to C++ comment //"; return; } if(!QFile::exists(url.toLocalFile())) { //kDebug() << "skipping mime magic due to nonexistent localfile"; return; } } // try to figure out if clipData contains a filename KMimeType::Ptr mimetype = KMimeType::findByUrl( url, 0, false, true /*fast mode*/ ); // let's see if we found some reasonable mimetype. // If we do we'll populate menu with actions for apps // that can handle that mimetype // first: if clipboard contents starts with http, let's assume it's "text/html". // That is even if we've url like "http://www.kde.org/somescript.pl", we'll // still treat that as html page, because determining a mimetype using kio // might take a long time, and i want this function to be quick! if ( ( clipData.startsWith( QLatin1String("http://") ) || clipData.startsWith( QLatin1String("https://") ) ) && mimetype->name() != "text/html" ) { // use a fake path to create a mimetype that corresponds to "text/html" mimetype = KMimeType::findByPath( "/tmp/klipper.html", 0, true /*fast mode*/ ); } if ( !mimetype->isDefault() ) { ClipAction* action = new ClipAction( QString(), mimetype->comment() ); KService::List lst = KMimeTypeTrader::self()->query( mimetype->name(), "Application" ); foreach( const KService::Ptr &service, lst ) { QHash<QChar,QString> map; map.insert( 'i', "--icon " + service->icon() ); map.insert( 'c', service->name() ); QString exec = service->exec(); exec = KMacroExpander::expandMacros( exec, map ).trimmed(); action->addCommand( ClipCommand( exec, service->name(), true, service->icon() ) ); }
ActionList * ActionWidget::actionList() { Q3ListViewItem *item = listView->firstChild(); Q3ListViewItem *child = 0L; ClipAction *action = 0L; ActionList *list = new ActionList; list->setAutoDelete( true ); while ( item ) { action = new ClipAction( item->text( 0 ), item->text( 1 ) ); child = item->firstChild(); // add the commands while ( child ) { action->addCommand( child->text( 0 ), child->text( 1 ), true ); child = child->nextSibling(); } list->append( action ); item = item->nextSibling(); } return list; }