From 905ec82d654d0c7783b4732593a37561a5a464bd Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Fri, 3 Jun 2016 21:30:47 +1000 Subject: [PATCH] Add espeak, theWave menu commands --- infopanedropdown.cpp | 8 ++++ infopanedropdown.h | 2 + infopanedropdown.ui | 11 ++++- menu.cpp | 103 +++++++++++++++++++++++++++---------------- menu.ui | 44 ++++++++++++++++++ thewaveworker.cpp | 7 +++ 6 files changed, 136 insertions(+), 39 deletions(-) diff --git a/infopanedropdown.cpp b/infopanedropdown.cpp index edf4640..3e5b986 100644 --- a/infopanedropdown.cpp +++ b/infopanedropdown.cpp @@ -64,6 +64,8 @@ InfoPaneDropdown::InfoPaneDropdown(NotificationDBus* notificationEngine, UPowerD QString thewaveVoiceEngine = settings.value("thewave/ttsEngine", "festival").toString(); if (thewaveVoiceEngine == "pico2wave") { ui->thewaveTTSpico2wave->setChecked(true); + } else if (thewaveVoiceEngine == "espeak") { + ui->thewaveTTSespeak->setChecked(true); } else if (thewaveVoiceEngine == "festival") { ui->thewaveTTSfestival->setChecked(true); } @@ -710,3 +712,9 @@ void InfoPaneDropdown::on_thewaveWikipediaSwitch_toggled(bool checked) { settings.setValue("thewave/wikipediaSearch", checked); } + +void InfoPaneDropdown::on_thewaveTTSespeak_clicked() +{ + settings.setValue("thewave/ttsEngine", "espeak"); + +} diff --git a/infopanedropdown.h b/infopanedropdown.h index 980fb71..64ca37d 100644 --- a/infopanedropdown.h +++ b/infopanedropdown.h @@ -124,6 +124,8 @@ private slots: void on_thewaveWikipediaSwitch_toggled(bool checked); + void on_thewaveTTSespeak_clicked(); + public slots: void getNetworks(); diff --git a/infopanedropdown.ui b/infopanedropdown.ui index f14c5ba..1f29cfc 100644 --- a/infopanedropdown.ui +++ b/infopanedropdown.ui @@ -955,6 +955,13 @@ + + + + espeak + + + @@ -1797,14 +1804,14 @@ 0 1969 12 - 12 + 11 1969 12 - 12 + 11 diff --git a/menu.cpp b/menu.cpp index 85587de..d223d57 100644 --- a/menu.cpp +++ b/menu.cpp @@ -20,6 +20,7 @@ Menu::Menu(QWidget *parent) : ui->commandLinkButton_2->setStyleSheet("background-color: #A00;"); ui->timerIcon->setPixmap(QIcon::fromTheme("player-time").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->callIcon->setPixmap(QIcon::fromTheme("call-start").pixmap(32)); ui->messageIcon->setPixmap(QIcon::fromTheme("message-send").pixmap(32)); @@ -60,6 +61,13 @@ Menu::Menu(QWidget *parent) : } else { ui->InstallLayout->setVisible(false); } + + QNetworkAccessManager networkManager; + if (networkManager.networkAccessible() == QNetworkAccessManager::Accessible) { + ui->thewaveInternetFrame->setVisible(false); + } else { + ui->thewaveInternetFrame->setVisible(true); + } } Menu::~Menu() @@ -330,6 +338,23 @@ void Menu::on_lineEdit_textEdited(const QString &arg1) ui->listWidget->addItem(i); } } 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) { if (app->name().contains(arg1, Qt::CaseInsensitive) || app->description().contains(arg1, Qt::CaseInsensitive)) { QListWidgetItem *i = new QListWidgetItem(); @@ -377,27 +402,13 @@ void Menu::on_lineEdit_textEdited(const QString &arg1) break; } } - } - QUrl uri = QUrl::fromUserInput(arg1); - 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()) { + QUrl uri = QUrl::fromUserInput(arg1); + if (uri.scheme() == "http" || uri.scheme() == "https") { App* app = new App(); - app->setName("Open " + uri.path()); + app->setName("Go to " + uri.toDisplayString()); app->setCommand("xdg-open \"" + uri.toString() + "\""); - app->setIcon(QIcon::fromTheme("system-file-manager")); + app->setIcon(QIcon::fromTheme("text-html")); appsShown->append(app); QListWidgetItem *i = new QListWidgetItem(); @@ -405,29 +416,47 @@ void Menu::on_lineEdit_textEdited(const QString &arg1) i->setIcon(app->icon()); i->setData(Qt::UserRole, app->command()); 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); + } else if (uri.scheme() == "file") { + if (QDir(uri.path() + "/").exists()) { + App* app = new App(); + app->setName("Open " + uri.path()); + app->setCommand("xdg-open \"" + uri.toString() + "\""); + app->setIcon(QIcon::fromTheme("system-file-manager")); + 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); + QListWidgetItem *i = new QListWidgetItem(); + i->setText(app->name()); + i->setIcon(app->icon()); + i->setData(Qt::UserRole, app->command()); + 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) { diff --git a/menu.ui b/menu.ui index dc607b9..7062eb3 100644 --- a/menu.ui +++ b/menu.ui @@ -1070,6 +1070,50 @@ p, li { white-space: pre-wrap; } + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + TextLabel + + + + + + + + 0 + 0 + + + + You're disconnected from the internet. Results are limited. + + + + + + diff --git a/thewaveworker.cpp b/thewaveworker.cpp index 4d7a855..33374d7 100644 --- a/thewaveworker.cpp +++ b/thewaveworker.cpp @@ -319,6 +319,13 @@ void theWaveWorker::speak(QString speech, bool restartOnceComplete) { //while (!sound.isFinished()) { //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 { QProcess *s = new QProcess(this); s->start("festival --tts");