📄 kraction.cpp
字号:
//check protocol if ( ! _showonlyProtocol.empty() ) { available = false; for ( QStringList::Iterator it = _showonlyProtocol.begin(); it != _showonlyProtocol.end(); ++it ) { //kdDebug() << "KrAction::isAvailable currendProtocol: " << currentURL.protocol() << " =?= " << *it << endl; if ( currentURL.protocol() == *it ) { // FIXME remove trailing slashes at the xml-parsing (faster because done only once) available = true; break; } } } //check protocol: done //check the Path-list: if ( ! _showonlyPath.empty() ) { available = false; for ( QStringList::Iterator it = _showonlyPath.begin(); it != _showonlyPath.end(); ++it ) { if ( (*it).right(1) == "*" ){ if ( currentURL.path().find( (*it).left( (*it).length() - 1 ) ) == 0 ) { available = true; break; } } else if ( currentURL.directory() == *it ) { // FIXME remove trailing slashes at the xml-parsing (faster because done only once) available = true; break; } } } //check the Path-list: done //check mime-type if ( ! _showonlyMime.empty() ) { available = false; KMimeType::Ptr mime = KMimeType::findByURL( currentURL ); for ( QStringList::Iterator it = _showonlyMime.begin(); it != _showonlyMime.end(); ++it ) { if ( (*it).contains("/") ) { if ( mime->is( *it ) ) { // don't use ==; use 'is()' instead, which is aware of inheritence (ie: text/x-makefile is also text/plain) available = true; break; } } else { if ( mime->name().find( *it ) == 0 ) { // 0 is the beginning, -1 is not found available = true; break; } } } //for } //check the mime-type: done //check filename if ( ! _showonlyFile.empty() ) { available = false; for ( QStringList::Iterator it = _showonlyFile.begin(); it != _showonlyFile.end(); ++it ) { QRegExp regex = QRegExp( *it, false, true ); // case-sensitive = false; wildcards = true if ( regex.exactMatch( currentURL.fileName() ) ) { available = true; break; } } } //check the filename: done return available;}bool KrAction::xmlRead( const QDomElement& element ) {/* This has to be done elsewhere!! if ( element.tagName() != "action" ) return false; Also the name has to be checked before the action is created! setName( element.attribute( "name" ).latin1() );*/ for ( QDomNode node = element.firstChild(); !node.isNull(); node = node.nextSibling() ) { QDomElement e = node.toElement(); if ( e.isNull() ) continue; // this should skip nodes which are not elements ( i.e. comments, <!-- -->, or text nodes) if ( e.tagName() == "title" ) setText( e.text() ); else if ( e.tagName() == "tooltip" ) setToolTip( e.text() ); else if ( e.tagName() == "icon" ) setIcon( e.text() ); else if ( e.tagName() == "category" ) setCategory( e.text() ); else if ( e.tagName() == "description" ) setWhatsThis( e.text() ); else if (e.tagName() == "command") readCommand( e ); else if ( e.tagName() == "startpath" ) setStartpath( e.text() ); else if (e.tagName() == "availability") readAvailability( e ); else if ( e.tagName() == "defaultshortcut" ) setShortcut( KShortcut( e.text() ) ); else // unknown but not empty if ( ! e.tagName().isEmpty() ) krOut << "KrAction::xmlRead() - unrecognized tag found: <action name=\"" << name() << "\"><" << e.tagName() << ">" << endl; } // for ( QDomNode node = action->firstChild(); !node.isNull(); node = node.nextSibling() ) return true;} //KrAction::xmlReadQDomElement KrAction::xmlDump( QDomDocument& doc ) const { QDomElement actionElement = doc.createElement("action"); actionElement.setAttribute( "name", name() );#define TEXT_ELEMENT( TAGNAME, TEXT ) \ { \ QDomElement e = doc.createElement( TAGNAME ); \ e.appendChild( doc.createTextNode( TEXT ) ); \ actionElement.appendChild( e ); \ } TEXT_ELEMENT( "title", text() ) if ( ! toolTip().isEmpty() ) TEXT_ELEMENT( "tooltip", toolTip() ) if ( ! icon().isEmpty() ) TEXT_ELEMENT( "icon", icon() ) if ( ! category().isEmpty() ) TEXT_ELEMENT( "category", category() ) if ( ! whatsThis().isEmpty() ) TEXT_ELEMENT( "description", whatsThis() ) actionElement.appendChild( dumpCommand( doc ) ); if ( ! startpath().isEmpty() ) TEXT_ELEMENT( "startpath", startpath() ) QDomElement availabilityElement = dumpAvailability( doc ); if ( availabilityElement.hasChildNodes() ) actionElement.appendChild( availabilityElement ); if ( ! shortcut().isNull() ) TEXT_ELEMENT( "defaultshortcut", shortcut().toStringInternal() ) //.toString() would return a localised string which can't be read again return actionElement;} //KrAction::xmlDumpvoid KrAction::readCommand( const QDomElement& element ) { QString attr; attr = element.attribute( "executionmode", "normal" ); // default: "normal" if ( attr == "normal") setExecType( Normal ); else if ( attr == "terminal" ) setExecType( Terminal ); else if ( attr == "collect_output") setExecType( CollectOutput ); else if ( attr == "collect_output_separate_stderr") setExecType( CollectOutputSeparateStderr ); else krOut << "KrAction::readCommand() - unrecognized attribute value found: <action name=\"" << name() << "\"><command executionmode=\"" << attr << "\""<< endl; attr = element.attribute( "accept", "local" ); // default: "local" if ( attr == "local" ) setAcceptURLs( false ); else if ( attr == "url") setAcceptURLs( true ); else krOut << "KrAction::readCommand() - unrecognized attribute value found: <action name=\"" << name() << "\"><command accept=\"" << attr << "\""<< endl; attr = element.attribute( "confirmexecution", "false" ); // default: "false" if ( attr == "true" ) setConfirmExecution( true ); else setConfirmExecution( false ); setUser( element.attribute( "run_as" ) ); setCommand( element.text() );} //KrAction::readCommandQDomElement KrAction::dumpCommand( QDomDocument& doc ) const { QDomElement commandElement = doc.createElement("command"); switch ( execType() ) { case Terminal: commandElement.setAttribute( "executionmode", "terminal" ); break; case CollectOutput: commandElement.setAttribute( "executionmode", "collect_output" ); break; case CollectOutputSeparateStderr: commandElement.setAttribute( "executionmode", "collect_output_separate_stderr" ); break; default: // don't write the default to file break; } if ( acceptURLs() ) commandElement.setAttribute( "accept", "url" ); if ( confirmExecution() ) commandElement.setAttribute( "confirmexecution", "true" ); if ( ! user().isEmpty() ) commandElement.setAttribute( "run_as", user() ); commandElement.appendChild( doc.createTextNode( command() ) ); return commandElement;} //KrAction::dumpCommandvoid KrAction::readAvailability( const QDomElement& element ) { for ( QDomNode node = element.firstChild(); ! node.isNull(); node = node.nextSibling() ) { QDomElement e = node.toElement(); if ( e.isNull() ) continue; // this should skip nodes which are not elements ( i.e. comments, <!-- -->, or text nodes) QStringList* showlist = 0; if ( e.tagName() == "protocol" ) showlist = &_showonlyProtocol; else if ( e.tagName() == "path" ) showlist = &_showonlyPath; else if ( e.tagName() == "mimetype" ) showlist = & _showonlyMime; else if ( e.tagName() == "filename" ) showlist = & _showonlyFile; else { krOut << "KrAction::readAvailability() - unrecognized element found: <action name=\"" << name() << "\"><availability><" << e.tagName() << ">"<< endl; showlist = 0; } if ( showlist ) { for ( QDomNode subnode = e.firstChild(); ! subnode.isNull(); subnode = subnode.nextSibling() ) { QDomElement subelement = subnode.toElement(); if ( subelement.tagName() == "show" ) showlist->append( subelement.text() ); } // for } // if ( showlist ) } // for} //KrAction::readAvailabilityQDomElement KrAction::dumpAvailability( QDomDocument& doc ) const { QDomElement availabilityElement = doc.createElement("command");# define LIST_ELEMENT( TAGNAME, LIST ) \ { \ QDomElement e = doc.createElement( TAGNAME ); \ for ( QStringList::const_iterator it = LIST.constBegin(); it != LIST.constEnd(); ++it ) { \ QDomElement show = doc.createElement( "show" ); \ show.appendChild( doc.createTextNode( *it ) ); \ e.appendChild( show ); \ } \ availabilityElement.appendChild( e ); \ } if ( ! _showonlyProtocol.isEmpty() ) LIST_ELEMENT( "protocol", _showonlyProtocol ) if ( ! _showonlyPath.isEmpty() ) LIST_ELEMENT( "path", _showonlyPath ) if ( ! _showonlyMime.isEmpty() ) LIST_ELEMENT( "mimetype", _showonlyMime ) if ( ! _showonlyFile.isEmpty() ) LIST_ELEMENT( "filename", _showonlyFile ) return availabilityElement;} //KrAction::dumpAvailability#include "kraction.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -