mirror of
https://github.com/vicr123/theshell.git
synced 2025-01-23 12:12:06 -05:00
theWave Media Player support
This commit is contained in:
parent
61ef48801f
commit
cf0b0e3c6e
8 changed files with 290 additions and 8 deletions
|
@ -596,6 +596,7 @@ void MainWindow::reloadWindows() {
|
|||
if (replyData.contains("xesam:title")) {
|
||||
title = replyData.value("xesam:title").toString();
|
||||
}
|
||||
this->mprisTitle = title;
|
||||
|
||||
if (replyData.contains("xesam:artist")) {
|
||||
QStringList artists = replyData.value("xesam:artist").toStringList();
|
||||
|
@ -604,6 +605,13 @@ void MainWindow::reloadWindows() {
|
|||
}
|
||||
artist.remove(artist.length() - 2, 2);
|
||||
}
|
||||
this->mprisArtist = artist;
|
||||
|
||||
if (replyData.contains("xesam:album")) {
|
||||
this->mprisAlbum = replyData.value("xesam:album").toString();
|
||||
} else {
|
||||
this->mprisAlbum = "";
|
||||
}
|
||||
|
||||
if (title == "") {
|
||||
QDBusMessage IdentityRequest = QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get");
|
||||
|
@ -625,8 +633,10 @@ void MainWindow::reloadWindows() {
|
|||
QDBusReply<QVariant> PlayStat = QDBusConnection::sessionBus().call(PlayStatRequest);
|
||||
if (PlayStat.value().toString() == "Playing") {
|
||||
ui->mprisPause->setIcon(QIcon::fromTheme("media-playback-pause"));
|
||||
mprisPlaying = true;
|
||||
} else {
|
||||
ui->mprisPause->setIcon(QIcon::fromTheme("media-playback-start"));
|
||||
mprisPlaying = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -963,17 +973,17 @@ void MainWindow::on_timer_clicked()
|
|||
|
||||
void MainWindow::on_mprisPause_clicked()
|
||||
{
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "PlayPause"), QDBus::NoBlock);
|
||||
playPause();
|
||||
}
|
||||
|
||||
void MainWindow::on_mprisBack_clicked()
|
||||
{
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Previous"), QDBus::NoBlock);
|
||||
previousSong();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_3_clicked()
|
||||
void MainWindow::on_mprisForward_clicked()
|
||||
{
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Next"), QDBus::NoBlock);
|
||||
nextSong();
|
||||
}
|
||||
|
||||
void MainWindow::on_mprisSongName_clicked()
|
||||
|
@ -1045,3 +1055,45 @@ void MainWindow::on_desktopBack_clicked()
|
|||
|
||||
sendMessageToRootWindow("_NET_CURRENT_DESKTOP", 0, switchToDesktop);
|
||||
}
|
||||
|
||||
bool MainWindow::isMprisAvailable() {
|
||||
return ui->mprisFrame->isVisible();
|
||||
}
|
||||
|
||||
bool MainWindow::isMprisPlaying() {
|
||||
return this->mprisPlaying;
|
||||
}
|
||||
|
||||
void MainWindow::nextSong() {
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Next"), QDBus::NoBlock);
|
||||
}
|
||||
|
||||
void MainWindow::playPause() {
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "PlayPause"), QDBus::NoBlock);
|
||||
}
|
||||
|
||||
void MainWindow::play() {
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Play"), QDBus::NoBlock);
|
||||
}
|
||||
void MainWindow::pause() {
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Pause"), QDBus::NoBlock);
|
||||
}
|
||||
|
||||
void MainWindow::previousSong() {
|
||||
QDBusConnection::sessionBus().call(QDBusMessage::createMethodCall(mprisCurrentAppName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", "Previous"), QDBus::NoBlock);
|
||||
}
|
||||
|
||||
QString MainWindow::mprisApp() {
|
||||
return this->mprisCurrentAppName;
|
||||
}
|
||||
|
||||
QString MainWindow::songName() {
|
||||
return this->mprisTitle;
|
||||
}
|
||||
|
||||
QString MainWindow::songArtist() {
|
||||
return this->mprisArtist;
|
||||
}
|
||||
QString MainWindow::songAlbum() {
|
||||
return this->mprisAlbum;
|
||||
}
|
||||
|
|
18
mainwindow.h
18
mainwindow.h
|
@ -53,6 +53,18 @@ public:
|
|||
InfoPaneDropdown* getInfoPane();
|
||||
void show();
|
||||
|
||||
bool isMprisAvailable();
|
||||
bool isMprisPlaying();
|
||||
void nextSong();
|
||||
void playPause();
|
||||
void play();
|
||||
void pause();
|
||||
void previousSong();
|
||||
QString mprisApp();
|
||||
QString songName();
|
||||
QString songArtist();
|
||||
QString songAlbum();
|
||||
|
||||
public slots:
|
||||
void on_openMenu_clicked();
|
||||
|
||||
|
@ -113,7 +125,7 @@ private slots:
|
|||
|
||||
void on_mprisBack_clicked();
|
||||
|
||||
void on_pushButton_3_clicked();
|
||||
void on_mprisForward_clicked();
|
||||
|
||||
void on_mprisSongName_clicked();
|
||||
|
||||
|
@ -146,6 +158,10 @@ private:
|
|||
|
||||
QString mprisCurrentAppName = "";
|
||||
QStringList mprisDetectedApps;
|
||||
QString mprisTitle;
|
||||
QString mprisArtist;
|
||||
QString mprisAlbum;
|
||||
bool mprisPlaying;
|
||||
|
||||
void closeEvent(QCloseEvent*);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
|
|
@ -420,7 +420,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<widget class="QPushButton" name="mprisForward">
|
||||
<property name="toolTip">
|
||||
<string>Next</string>
|
||||
</property>
|
||||
|
|
31
menu.cpp
31
menu.cpp
|
@ -724,7 +724,8 @@ void Menu::on_activateTheWave_clicked()
|
|||
connect(waveWorker, SIGNAL(showFlightFrame(QString)), this, SLOT(showFlightFrame(QString))); //Flight
|
||||
connect(waveWorker, SIGNAL(loudnessChanged(qreal)), this, SLOT(thewaveLoudnessChanged(qreal))); //Input Loudness
|
||||
connect(waveWorker, SIGNAL(showSettingsFrame(QIcon,QString,bool)), this, SLOT(showSettingFrame(QIcon,QString,bool))); //Settings
|
||||
connect(waveWorker, SIGNAL(showMathematicsFrame(QString,QString)), this, SLOT(showMathematicsFrame(QString,QString)));
|
||||
connect(waveWorker, SIGNAL(showMathematicsFrame(QString,QString)), this, SLOT(showMathematicsFrame(QString,QString))); //Mathematics
|
||||
connect(waveWorker, SIGNAL(showMediaFrame(QPixmap,QString,QString,bool)), this, SLOT(showMediaFrame(QPixmap,QString,QString,bool))); //Media Player
|
||||
connect(this, SIGNAL(thewave_processText(QString,bool)), waveWorker, SLOT(processSpeech(QString,bool))); //Manual Input Text Processing
|
||||
connect(this, SIGNAL(thewaveBegin()), waveWorker, SLOT(begin())); //Begin
|
||||
connect(this, SIGNAL(thewaveStop()), waveWorker, SLOT(endAndProcess())); //Stop
|
||||
|
@ -807,6 +808,19 @@ void Menu::resetFrames() {
|
|||
ui->thewave_flightFrame->setVisible(false);
|
||||
ui->thewaveSettingsFrame->setVisible(false);
|
||||
ui->thewaveMathematicsFrame->setVisible(false);
|
||||
ui->thewaveMediaFrame->setVisible(false);
|
||||
}
|
||||
|
||||
void Menu::showMediaFrame(QPixmap art, QString title, QString artist, bool isPlaying) {
|
||||
ui->thewaveMedia_Art->setPixmap(art.scaled(32, 32));
|
||||
ui->thewaveMedia_Title->setText(title);
|
||||
ui->thewaveMedia_Artist->setText(artist);
|
||||
if (isPlaying) {
|
||||
ui->thewaveMedia_Play->setIcon(QIcon::fromTheme("media-playback-pause"));
|
||||
} else {
|
||||
ui->thewaveMedia_Play->setIcon(QIcon::fromTheme("media-playback-start"));
|
||||
}
|
||||
ui->thewaveMediaFrame->setVisible(true);
|
||||
}
|
||||
|
||||
void Menu::showWikipediaFrame(QString title, QString text) {
|
||||
|
@ -941,3 +955,18 @@ void Menu::on_thewaveSettingsFrame_Switch_toggled(bool checked)
|
|||
{
|
||||
emit currentSettingChanged(checked);
|
||||
}
|
||||
|
||||
void Menu::on_thewaveMedia_Next_clicked()
|
||||
{
|
||||
MainWin->nextSong();
|
||||
}
|
||||
|
||||
void Menu::on_thewaveMedia_Play_clicked()
|
||||
{
|
||||
MainWin->playPause();
|
||||
}
|
||||
|
||||
void Menu::on_thewaveMedia_Back_clicked()
|
||||
{
|
||||
MainWin->previousSong();
|
||||
}
|
||||
|
|
8
menu.h
8
menu.h
|
@ -130,6 +130,14 @@ private slots:
|
|||
|
||||
void showMathematicsFrame(QString expression, QString answer);
|
||||
|
||||
void showMediaFrame(QPixmap art, QString title, QString artist, bool isPlaying);
|
||||
|
||||
void on_thewaveMedia_Next_clicked();
|
||||
|
||||
void on_thewaveMedia_Play_clicked();
|
||||
|
||||
void on_thewaveMedia_Back_clicked();
|
||||
|
||||
private:
|
||||
Ui::Menu *ui;
|
||||
|
||||
|
|
127
menu.ui
127
menu.ui
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>560</width>
|
||||
<height>2545</height>
|
||||
<height>2796</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -1377,6 +1377,131 @@ p, li { white-space: pre-wrap; }
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="thewaveMediaFrame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_19">
|
||||
<item>
|
||||
<widget class="QLabel" name="launchapp_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Media Player</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
||||
<item>
|
||||
<widget class="QLabel" name="thewaveMedia_Art">
|
||||
<property name="text">
|
||||
<string>albumArt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="thewaveMedia_Title">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="thewaveMedia_Artist">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="thewaveMedia_Back">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="media-skip-backward">
|
||||
<normaloff>../tsscreenlock</normaloff>../tsscreenlock</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="thewaveMedia_Play">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="media-playback-start">
|
||||
<normaloff>../tsscreenlock</normaloff>../tsscreenlock</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="thewaveMedia_Next">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="media-skip-forward">
|
||||
<normaloff>../tsscreenlock</normaloff>../tsscreenlock</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="thewave_spacerFrame">
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -306,6 +306,57 @@ void theWaveWorker::processSpeech(QString speech, bool voiceFeedback) {
|
|||
}
|
||||
emit outputResponse(output);
|
||||
speak(output);
|
||||
} else if (words.contains("song") || words.contains("playing") || words.contains("play") || words.contains("pause") ||
|
||||
((words.contains("track") || words.contains("song") || words.contains("playing")) &&
|
||||
(words.contains("next") || words.contains("previous") || words.contains("now") || words.contains("current")))) { //Media Player Controls
|
||||
if (words.contains("pause")) {
|
||||
MainWin->pause();
|
||||
emit outputResponse("Paused.");
|
||||
speak("Paused");
|
||||
} else if (words.contains("play")) {
|
||||
MainWin->play();
|
||||
emit outputResponse("Playing.");
|
||||
speak("Playing");
|
||||
} else if (words.contains("next")) {
|
||||
MainWin->nextSong();
|
||||
emit outputResponse("Next Track");
|
||||
speak("Next Track");
|
||||
} else if (words.contains("previous")) {
|
||||
MainWin->previousSong();
|
||||
emit outputResponse("Previous Track");
|
||||
speak("Previous Track");
|
||||
} else if (words.contains("playing") || words.contains("current")) {
|
||||
if (MainWin->isMprisAvailable()) {
|
||||
QString title = MainWin->songName();
|
||||
QString artists = MainWin->songArtist();
|
||||
QString album = MainWin->songAlbum();
|
||||
bool playing = MainWin->isMprisPlaying();
|
||||
QPixmap art = QIcon::fromTheme("audio").pixmap(32, 32);
|
||||
QString response;
|
||||
if (title != "" && artists != "" && album != "") {
|
||||
response = "Right now, " + title + " by " + artists + " on the album " + album + " is playing.";
|
||||
emit showMediaFrame(art, title, artists + " · " + album, playing);
|
||||
} else if (title != "" && artists != "" && album == "") {
|
||||
response = "Right now, " + title + " by " + artists + " is playing.";
|
||||
emit showMediaFrame(art, title, artists, playing);
|
||||
} else if (title != "" && artists == "" && album != "") {
|
||||
response = "Right now, " + title + " on the album " + album + " is playing.";
|
||||
emit showMediaFrame(art, title, album, playing);
|
||||
} else if (title != "" && artists == "" && album != "") {
|
||||
response = "Right now, " + title + " is playing.";
|
||||
emit showMediaFrame(art, title, MainWin->mprisApp(), playing);
|
||||
} else {
|
||||
response = "I'm not sure what's playing now.";
|
||||
//emit showMediaFrame(art, title, artists + " · " + album);
|
||||
}
|
||||
emit outputResponse(response);
|
||||
speak(response);
|
||||
} else {
|
||||
emit outputResponse("There's no media player open now.");
|
||||
speak("There's no media player open now.");
|
||||
}
|
||||
}
|
||||
resetOnNextBegin = true;
|
||||
} else if ((words.contains("calculate") || words.contains("add") || words.contains("plus") || parse.contains("+") || words.contains("subtract") || words.contains("minus") ||
|
||||
parse.contains("-") || words.contains("times") || words.contains("multiply") || parse.contains("*") ||
|
||||
words.contains("over") || words.contains("divide") || parse.contains("divided by") ||
|
||||
|
|
|
@ -69,6 +69,7 @@ signals:
|
|||
void showFlightFrame(QString flight);
|
||||
void showSettingsFrame(QIcon icon, QString setting, bool isOn);
|
||||
void showMathematicsFrame(QString expression, QString answer);
|
||||
void showMediaFrame(QPixmap art, QString title, QString artist, bool isPlaying);
|
||||
|
||||
void setTimer(QTime);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue