|
| 1 | +#include "pulseeffectscompatibility.h" |
| 2 | +#include "ui_pulseeffectscompatibility.h" |
| 3 | +#include "misc/common.h" |
| 4 | +#include "misc/autostartmanager.h" |
| 5 | +#include "mainwindow.h" |
| 6 | + |
| 7 | +#include <QTimer> |
| 8 | +#include <QEasingCurve> |
| 9 | +#include <QDesktopServices> |
| 10 | +#include <QUrl> |
| 11 | +#include <QFileInfo> |
| 12 | +#include <QDir> |
| 13 | +#include <QMessageBox> |
| 14 | +#include <QProcess> |
| 15 | + |
| 16 | +PulseeffectsCompatibility::PulseeffectsCompatibility(AppConfigWrapper* _appconf, MainWindow* mainwin, QWidget *parent) : |
| 17 | + QWidget(parent), |
| 18 | + ui(new Ui::PulseeffectsCompatibility) |
| 19 | +{ |
| 20 | + ui->setupUi(this); |
| 21 | + |
| 22 | + appconf = _appconf; |
| 23 | + ui->stackedWidget->setCurrentIndex(0); |
| 24 | + ui->stackedWidget->setAnimation(QEasingCurve::Type::OutCirc); |
| 25 | + connect(ui->p1_next,&QPushButton::clicked,[=]{ |
| 26 | + QString absolute = |
| 27 | + QFileInfo(appconf->getPath()).absoluteDir().absolutePath(); |
| 28 | + QString devices(pathAppend(absolute,"devices.conf")); |
| 29 | + if(ui->p2_dev_select->currentData() == "---"){ |
| 30 | + QMessageBox::warning(this,"Warning","Invalid device! Please select another one."); |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + ConfigContainer* devconf = new ConfigContainer(); |
| 35 | + devconf->setConfigMap(ConfigIO::readFile(devices)); |
| 36 | + devconf->setValue("location",ui->p2_dev_select->currentData()); |
| 37 | + ConfigIO::writeFile(devices,devconf->getConfigMap()); |
| 38 | + |
| 39 | + ui->stackedWidget->slideInIdx(1); |
| 40 | + }); |
| 41 | + |
| 42 | + connect(ui->p2_next,&QPushButton::clicked,[=]{ |
| 43 | + ui->stackedWidget->slideInIdx(2); |
| 44 | + }); |
| 45 | + connect(ui->p3_next,&QPushButton::clicked,[=]{ |
| 46 | + emit wizardFinished(); |
| 47 | + }); |
| 48 | + connect(ui->p1_cancel,&QPushButton::clicked,[=]{ |
| 49 | + emit wizardFinished(); |
| 50 | + }); |
| 51 | + |
| 52 | + refreshDevices(); |
| 53 | +} |
| 54 | + |
| 55 | +PulseeffectsCompatibility::~PulseeffectsCompatibility() |
| 56 | +{ |
| 57 | + delete ui; |
| 58 | +} |
| 59 | + |
| 60 | +void PulseeffectsCompatibility::refreshDevices() |
| 61 | +{ |
| 62 | + lockslot = true; |
| 63 | + ui->p2_dev_select->clear(); |
| 64 | + QString absolute = |
| 65 | + QFileInfo(appconf->getPath()).absoluteDir().absolutePath(); |
| 66 | + QFile devices(pathAppend(absolute,"devices.conf")); |
| 67 | + |
| 68 | + QProcess process; |
| 69 | + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
| 70 | + env.insert("LC_ALL", "C"); |
| 71 | + process.setProcessEnvironment(env); |
| 72 | + process.start("sh", QStringList()<<"-c"<<"pactl list sinks | grep \'Name: \' -A1"); |
| 73 | + process.waitForFinished(500); |
| 74 | + |
| 75 | + ConfigContainer* devconf = new ConfigContainer(); |
| 76 | + devconf->setConfigMap(ConfigIO::readFile(pathAppend(absolute,"devices.conf"))); |
| 77 | + QString out = process.readAllStandardOutput(); |
| 78 | + ui->p2_dev_select->addItem("...","---"); |
| 79 | + for(auto item : out.split("Name:")){ |
| 80 | + item.prepend("Name:"); |
| 81 | + QRegularExpression re(R"((?<=(Name:)\s)(?<name>.+)[\s\S]+(?<=(Description:)\s)(?<desc>.+))"); |
| 82 | + QRegularExpressionMatch match = re.match(item, 0, QRegularExpression::PartialPreferCompleteMatch); |
| 83 | + if(match.hasMatch()){ |
| 84 | + ui->p2_dev_select->addItem(QString("%1 (%2)").arg(match.captured("desc")).arg(match.captured("name")), |
| 85 | + match.captured("name")); |
| 86 | + } |
| 87 | + } |
| 88 | + QString dev_location = devconf->getString("location"); |
| 89 | + if(dev_location.isEmpty()) |
| 90 | + ui->p2_dev_select->setCurrentIndex(0); |
| 91 | + else{ |
| 92 | + bool notFound = true; |
| 93 | + for(int i = 0; i < ui->p2_dev_select->count(); i++){ |
| 94 | + if(ui->p2_dev_select->itemData(i) == |
| 95 | + dev_location){ |
| 96 | + notFound = false; |
| 97 | + ui->p2_dev_select->setCurrentIndex(i); |
| 98 | + break; |
| 99 | + } |
| 100 | + } |
| 101 | + if(notFound){ |
| 102 | + QString name = QString("Unknown (%1)").arg(dev_location); |
| 103 | + ui->p2_dev_select->addItem(name,dev_location); |
| 104 | + ui->p2_dev_select->setCurrentText(name); |
| 105 | + } |
| 106 | + } |
| 107 | + lockslot = false; |
| 108 | +} |
0 commit comments