Add espeak, theWave menu commands

This commit is contained in:
Victor Tran 2016-06-03 21:30:47 +10:00
parent 8694ff1e8b
commit 905ec82d65
6 changed files with 136 additions and 39 deletions

View file

@ -64,6 +64,8 @@ InfoPaneDropdown::InfoPaneDropdown(NotificationDBus* notificationEngine, UPowerD
QString thewaveVoiceEngine = settings.value("thewave/ttsEngine", "festival").toString(); QString thewaveVoiceEngine = settings.value("thewave/ttsEngine", "festival").toString();
if (thewaveVoiceEngine == "pico2wave") { if (thewaveVoiceEngine == "pico2wave") {
ui->thewaveTTSpico2wave->setChecked(true); ui->thewaveTTSpico2wave->setChecked(true);
} else if (thewaveVoiceEngine == "espeak") {
ui->thewaveTTSespeak->setChecked(true);
} else if (thewaveVoiceEngine == "festival") { } else if (thewaveVoiceEngine == "festival") {
ui->thewaveTTSfestival->setChecked(true); ui->thewaveTTSfestival->setChecked(true);
} }
@ -710,3 +712,9 @@ void InfoPaneDropdown::on_thewaveWikipediaSwitch_toggled(bool checked)
{ {
settings.setValue("thewave/wikipediaSearch", checked); settings.setValue("thewave/wikipediaSearch", checked);
} }
void InfoPaneDropdown::on_thewaveTTSespeak_clicked()
{
settings.setValue("thewave/ttsEngine", "espeak");
}

View file

@ -124,6 +124,8 @@ private slots:
void on_thewaveWikipediaSwitch_toggled(bool checked); void on_thewaveWikipediaSwitch_toggled(bool checked);
void on_thewaveTTSespeak_clicked();
public slots: public slots:
void getNetworks(); void getNetworks();

View file

@ -955,6 +955,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="thewaveTTSespeak">
<property name="text">
<string>espeak</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QRadioButton" name="thewaveTTSpico2wave"> <widget class="QRadioButton" name="thewaveTTSpico2wave">
<property name="text"> <property name="text">
@ -1797,14 +1804,14 @@
<second>0</second> <second>0</second>
<year>1969</year> <year>1969</year>
<month>12</month> <month>12</month>
<day>12</day> <day>11</day>
</datetime> </datetime>
</property> </property>
<property name="date"> <property name="date">
<date> <date>
<year>1969</year> <year>1969</year>
<month>12</month> <month>12</month>
<day>12</day> <day>11</day>
</date> </date>
</property> </property>
<property name="displayFormat"> <property name="displayFormat">

103
menu.cpp
View file

@ -20,6 +20,7 @@ Menu::Menu(QWidget *parent) :
ui->commandLinkButton_2->setStyleSheet("background-color: #A00;"); ui->commandLinkButton_2->setStyleSheet("background-color: #A00;");
ui->timerIcon->setPixmap(QIcon::fromTheme("player-time").pixmap(16)); ui->timerIcon->setPixmap(QIcon::fromTheme("player-time").pixmap(16));
ui->userIcon->setPixmap(QIcon::fromTheme("system-users").pixmap(16)); ui->userIcon->setPixmap(QIcon::fromTheme("system-users").pixmap(16));
ui->thewave_connection_disconnection_label->setPixmap(QIcon::fromTheme("network-disconnect").pixmap(16));
ui->timeIcon->setPixmap(QIcon::fromTheme("player-time").pixmap(32)); ui->timeIcon->setPixmap(QIcon::fromTheme("player-time").pixmap(32));
ui->callIcon->setPixmap(QIcon::fromTheme("call-start").pixmap(32)); ui->callIcon->setPixmap(QIcon::fromTheme("call-start").pixmap(32));
ui->messageIcon->setPixmap(QIcon::fromTheme("message-send").pixmap(32)); ui->messageIcon->setPixmap(QIcon::fromTheme("message-send").pixmap(32));
@ -60,6 +61,13 @@ Menu::Menu(QWidget *parent) :
} else { } else {
ui->InstallLayout->setVisible(false); ui->InstallLayout->setVisible(false);
} }
QNetworkAccessManager networkManager;
if (networkManager.networkAccessible() == QNetworkAccessManager::Accessible) {
ui->thewaveInternetFrame->setVisible(false);
} else {
ui->thewaveInternetFrame->setVisible(true);
}
} }
Menu::~Menu() Menu::~Menu()
@ -330,6 +338,23 @@ void Menu::on_lineEdit_textEdited(const QString &arg1)
ui->listWidget->addItem(i); ui->listWidget->addItem(i);
} }
} else { } else {
bool showtheWaveOption = true;
if ((arg1.startsWith("call") && arg1.count() == 4) || arg1.startsWith("call ")) {
QListWidgetItem *call = new QListWidgetItem();
QString parse = arg1;
if (arg1.count() == 4 || arg1.count() == 5) {
call->setText("Place a call");
call->setData(Qt::UserRole, "thewave:call");
} else {
parse.remove(0, 5);
call->setText("Place a call to " + (QString) parse.at(0).toUpper() + parse.right(parse.length() - 1) + "");
call->setData(Qt::UserRole, "thewave:call " + parse);
}
call->setIcon(QIcon::fromTheme("call-start"));
ui->listWidget->addItem(call);
showtheWaveOption = false;
}
for (App *app : *apps) { for (App *app : *apps) {
if (app->name().contains(arg1, Qt::CaseInsensitive) || app->description().contains(arg1, Qt::CaseInsensitive)) { if (app->name().contains(arg1, Qt::CaseInsensitive) || app->description().contains(arg1, Qt::CaseInsensitive)) {
QListWidgetItem *i = new QListWidgetItem(); QListWidgetItem *i = new QListWidgetItem();
@ -377,27 +402,13 @@ void Menu::on_lineEdit_textEdited(const QString &arg1)
break; break;
} }
} }
}
QUrl uri = QUrl::fromUserInput(arg1); QUrl uri = QUrl::fromUserInput(arg1);
if (uri.scheme() == "http" || uri.scheme() == "https") { if (uri.scheme() == "http" || uri.scheme() == "https") {
App* app = new App();
app->setName("Go to " + uri.toDisplayString());
app->setCommand("xdg-open \"" + uri.toString() + "\"");
app->setIcon(QIcon::fromTheme("text-html"));
appsShown->append(app);
QListWidgetItem *i = new QListWidgetItem();
i->setText(app->name());
i->setIcon(app->icon());
i->setData(Qt::UserRole, app->command());
ui->listWidget->addItem(i);
} else if (uri.scheme() == "file") {
if (QDir(uri.path() + "/").exists()) {
App* app = new App(); App* app = new App();
app->setName("Open " + uri.path()); app->setName("Go to " + uri.toDisplayString());
app->setCommand("xdg-open \"" + uri.toString() + "\""); app->setCommand("xdg-open \"" + uri.toString() + "\"");
app->setIcon(QIcon::fromTheme("system-file-manager")); app->setIcon(QIcon::fromTheme("text-html"));
appsShown->append(app); appsShown->append(app);
QListWidgetItem *i = new QListWidgetItem(); QListWidgetItem *i = new QListWidgetItem();
@ -405,29 +416,47 @@ void Menu::on_lineEdit_textEdited(const QString &arg1)
i->setIcon(app->icon()); i->setIcon(app->icon());
i->setData(Qt::UserRole, app->command()); i->setData(Qt::UserRole, app->command());
ui->listWidget->addItem(i); ui->listWidget->addItem(i);
} else if (QFile(uri.path()).exists()) { } else if (uri.scheme() == "file") {
App* app = new App(); if (QDir(uri.path() + "/").exists()) {
app->setName("Open " + uri.path()); App* app = new App();
app->setCommand("xdg-open \"" + uri.toString() + "\""); app->setName("Open " + uri.path());
QFile f(uri.toString()); app->setCommand("xdg-open \"" + uri.toString() + "\"");
QFileInfo info(f); app->setIcon(QIcon::fromTheme("system-file-manager"));
QMimeType mime = (new QMimeDatabase())->mimeTypeForFile(info); appsShown->append(app);
app->setIcon(QIcon::fromTheme(mime.iconName(), QIcon::fromTheme("application-octet-stream")));
appsShown->append(app);
QListWidgetItem *i = new QListWidgetItem(); QListWidgetItem *i = new QListWidgetItem();
i->setText(app->name()); i->setText(app->name());
i->setIcon(app->icon()); i->setIcon(app->icon());
i->setData(Qt::UserRole, app->command()); i->setData(Qt::UserRole, app->command());
ui->listWidget->addItem(i); ui->listWidget->addItem(i);
} else if (QFile(uri.path()).exists()) {
App* app = new App();
app->setName("Open " + uri.path());
app->setCommand("xdg-open \"" + uri.toString() + "\"");
QFile f(uri.toString());
QFileInfo info(f);
QMimeType mime = (new QMimeDatabase())->mimeTypeForFile(info);
app->setIcon(QIcon::fromTheme(mime.iconName(), QIcon::fromTheme("application-octet-stream")));
appsShown->append(app);
QListWidgetItem *i = new QListWidgetItem();
i->setText(app->name());
i->setIcon(app->icon());
i->setData(Qt::UserRole, app->command());
ui->listWidget->addItem(i);
}
}
if (showtheWaveOption) {
QListWidgetItem *wave = new QListWidgetItem();
wave->setText("Ask theWave about \"" + arg1 + "\"");
wave->setIcon(QIcon(":/icons/thewave.svg"));
wave->setData(Qt::UserRole, "thewave:" + arg1);
ui->listWidget->addItem(wave);
} }
} }
QListWidgetItem *wave = new QListWidgetItem();
wave->setText("Ask theWave about \"" + arg1 + "\"");
wave->setIcon(QIcon(":/icons/thewave.svg"));
wave->setData(Qt::UserRole, "thewave:" + arg1);
ui->listWidget->addItem(wave);
} }
bool Menu::eventFilter(QObject *object, QEvent *event) { bool Menu::eventFilter(QObject *object, QEvent *event) {

44
menu.ui
View file

@ -1070,6 +1070,50 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="thewaveInternetFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="thewave_connection_disconnection_label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>You're disconnected from the internet. Results are limited.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>

View file

@ -319,6 +319,13 @@ void theWaveWorker::speak(QString speech, bool restartOnceComplete) {
//while (!sound.isFinished()) { //while (!sound.isFinished()) {
//QApplication::processEvents(); //QApplication::processEvents();
//} //}
} else if (settings.value("thewave/ttsEngine").toString() == "espeak" && QFile("/usr/bin/espeak").exists()) {
QProcess *s = new QProcess(this);
s->start("espeak \"" + speech + "\"");
if (restartOnceComplete && !stopEverything) {
connect(s, SIGNAL(finished(int)), this, SLOT(begin()));
}
} else { } else {
QProcess *s = new QProcess(this); QProcess *s = new QProcess(this);
s->start("festival --tts"); s->start("festival --tts");