void IRGenerator::accept(MatchStmt& stmt) { FNTRACE(); Value* cond = codegen(stmt.condition()); BasicBlock* contBlock = createBlock("match.cont"); MatchInstr* matchInstr = createMatch(stmt.op(), cond); for (const MatchCase& one: stmt.cases()) { BasicBlock* bb = createBlock("match.case"); setInsertPoint(bb); codegen(one.second.get()); createBr(contBlock); for (auto& labelNode: one.first) { Constant* label = getConstant(labelNode.get()); matchInstr->addCase(label, bb); } } if (stmt.elseStmt()) { BasicBlock* elseBlock = createBlock("match.else"); setInsertPoint(elseBlock); codegen(stmt.elseStmt()); createBr(contBlock); matchInstr->setElseBlock(elseBlock); } setInsertPoint(contBlock); }
void AudioPlayerControlRunner::match(Plasma::RunnerContext &context) { if (context.query().length() < 3) { return; } const QString term = context.query(); QList<Plasma::QueryMatch> matches; if (m_useCommands) { /* DBus paths that are used in the command executes */ /* The data variable looks like this: * "/PlayerQLatin1String( " " )org.freedesktop.MediaPlayerQLatin1String( " " )PlayQLatin1String( " " )actionsQLatin1String( " " )start" args... * <path> <interface> <method> <actions> <start player> * <actions> is NONE if no action is needed */ QVariantList playcontrol; playcontrol << QLatin1String( "/Player" ) << QLatin1String( "org.freedesktop.MediaPlayer" ); /* The commands */ //Play if (context.isValid() && m_comPlay.startsWith(term, Qt::CaseInsensitive) && (!m_running || m_songsInPlaylist)) { QVariantList data = playcontrol; data << ((currentSong() == -1) ? QLatin1String( "Next" ) : QLatin1String( "Play" )) << NONE << QLatin1String( "start" ); matches << createMatch(this, i18n("Start playing"), i18n("Audio player control"), QLatin1String( "play" ), KIcon( QLatin1String( "media-playback-start" )), data, 1.0); } if (!context.isValid() || !m_running) { //The interface of the player is not availalbe, so the rest of the commands //is not needed context.addMatches(matches); return; } if (context.isValid() && m_songsInPlaylist) { //The playlist isn't empty //Next song if (m_comNext.startsWith(term,Qt::CaseInsensitive) && m_nextSongAvailable) { QVariantList data = playcontrol; data << QLatin1String( "Next" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Play next song"), i18n("Audio player control"), QLatin1String( "next" ), KIcon( QLatin1String( "media-skip-forward" )), data, 1.0); } //Previous song if (context.isValid() && m_comPrev.startsWith(term,Qt::CaseInsensitive) && m_prevSongAvailable) { QVariantList data = playcontrol; data << QLatin1String( "Prev" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Play previous song"), i18n("Audio player control") , QLatin1String( "previous" ), KIcon( QLatin1String( "media-skip-backward" )), data, 1.0); } }//--- if (m_songsInPlaylist) //Pause if (context.isValid() && m_comPause.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Pause" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Pause playing"), i18n("Audio player control"), QLatin1String( "pause" ), KIcon( QLatin1String( "media-playback-pause" )), data, 1.0); } //Stop if (context.isValid() && m_comStop.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Stop" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Stop playing"), i18n("Audio player control"), QLatin1String( "stop" ), KIcon( QLatin1String( "media-playback-stop" )), data, 1.0); } //Increase if (context.isValid() && m_comIncrease.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "VolumeUp" ) << NONE << QLatin1String( "nostart" ) << m_increaseBy; matches << createMatch(this, i18n("Increase volume by %1" , m_increaseBy), QLatin1String( "volumeup" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-high" )), data, 1.0); } else if (context.isValid() && equals(term, QRegExp( m_comIncrease + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { int volumeChange = getNumber(term, ' ' ); QVariantList data = playcontrol; data << QLatin1String( "VolumeUp" ) << NONE << QLatin1String( "nostart" ) << volumeChange; matches << createMatch(this, i18n("Increase volume by %1" , volumeChange), QLatin1String( "volumeup" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-high" )), data, 1.0); } //Decrease if (context.isValid() && m_comDecrease.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "VolumeDown" ) << NONE << QLatin1String( "nostart" ) << m_decreaseBy; matches << createMatch(this, i18n("Reduce volume by %1", m_decreaseBy), QLatin1String( "volumedown" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-low" )), data, 1.0); } else if (context.isValid() && equals(term, QRegExp( m_comDecrease + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { int volumeChange = getNumber(term, ' '); QVariantList data = playcontrol; data << QLatin1String( "VolumeDown" ) << NONE << QLatin1String( "nostart" ) << volumeChange; matches << createMatch(this, i18n("Reduce volume by %1", volumeChange), QLatin1String( "volumedown" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-low" )), data, 1.0); } //Set volume to if (context.isValid() && equals(term, QRegExp( m_comVolume + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { QVariantList data = playcontrol; int newVolume = getNumber(term , ' '); data << QLatin1String( "VolumeSet" ) << NONE << QLatin1String( "nostart" ) << newVolume; matches << createMatch(this, i18n("Set volume to %1%" , newVolume), QLatin1String( "volume" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-medium" )), data, 1.0); } //Mute if (context.isValid() && m_comMute.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Mute" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Mute"), i18n("Audio player control"), QLatin1String( "mute" ), KIcon( QLatin1String( "audio-volume-muted" )), data, 1.0); } //Quit player if (context.isValid() && m_comQuit.startsWith(term,Qt::CaseInsensitive)) { QVariantList data; data << QLatin1String( "/" ) << QLatin1String( "org.freedesktop.MediaPlayer" ) << QLatin1String( "Quit" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Quit %1", m_player),QLatin1String( "" ), QLatin1String( "quit" ), KIcon( QLatin1String( "application-exit" )), data, 1.0); } }//--- if (m_useCommands) if (context.isValid() && m_searchCollection) { QString actionNames; QString searchTerm = term; QString command; if (term.startsWith(m_comPlay,Qt::CaseInsensitive) && term.length() > m_comPlay.length()) { command = m_comPlay; actionNames = PLAY; } else if (term.startsWith(m_comAppend, Qt::CaseInsensitive) && term.length() > m_comAppend.length()) { command = m_comAppend; actionNames = APPEND; } else if (term.startsWith(m_comQueue, Qt::CaseInsensitive) && term.length() > m_comQueue.length()) { command = m_comQueue; actionNames = QUEUE; } else { actionNames = QString::fromLatin1( "%1,%2,%3").arg(PLAY).arg(APPEND).arg(QUEUE); } if (!context.isValid()) { return; } searchTerm = searchTerm.right(searchTerm.length() - (command.length() + 1)); matches << searchCollectionFor(searchTerm, actionNames); //Adds matches for all song matches for term } context.addMatches(matches); }