1 #ifndef _PC_MIXER_GUI_H 2 #define _PC_MIXER_GUI_H 3 4 #include <QMainWindow> 5 #include <QSettings> 6 #include <QCloseEvent> 7 #include <QCoreApplication> 8 #include <QHBoxLayout> 9 #include <QScrollBar> 10 #include <QProcess> 11 #include <QAction> 12 #include <QMediaPlayer> 13 #include <QFile> 14 #include <QDir> 15 #include <QTextStream> 16 #include <QMessageBox> 17 18 #include "DeviceWidget.h" 19 #include "MixerBackend.h" 20 21 namespace Ui{ 22 class MixerGUI; 23 }; 24 25 class MixerGUI : public QMainWindow{ 26 Q_OBJECT 27 public: 28 MixerGUI(QSettings* set = 0); 29 ~MixerGUI(); 30 31 void updateGUI(); //For the tray to call before the GUI becomes active 32 33 private: 34 Ui::MixerGUI *ui; 35 QSettings *settings; 36 bool closing; 37 runShellCommand(QString cmd)38 QStringList runShellCommand(QString cmd){ 39 //split the command string with individual commands seperated by a ";" (if any) 40 QProcess p; 41 //Make sure we use the system environment to properly read system variables, etc. 42 p.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); 43 //Merge the output channels to retrieve all output possible 44 p.setProcessChannelMode(QProcess::MergedChannels); 45 p.start(cmd); 46 while(p.state()==QProcess::Starting || p.state() == QProcess::Running){ 47 p.waitForFinished(200); 48 QCoreApplication::processEvents(); 49 } 50 QString outstr = p.readAllStandardOutput(); 51 if(outstr.endsWith("\n")){outstr.chop(1);} //remove the newline at the end 52 return outstr.split("\n"); 53 } 54 readFile(QString path)55 QStringList readFile(QString path){ 56 QFile file(path); 57 QString contents; 58 if(file.open(QIODevice::ReadOnly | QIODevice::Text)){ 59 QTextStream in(&file); 60 contents = in.readAll(); 61 file.close(); 62 } 63 return contents.split("\n"); 64 } 65 writeFile(QString path,QStringList contents)66 bool writeFile(QString path, QStringList contents){ 67 QFile file(path); 68 if(file.open(QIODevice::WriteOnly | QIODevice::Truncate |QIODevice::Text)){ 69 QTextStream out(&file); 70 out << contents.join("\n"); 71 if(!contents.last().simplified().isEmpty()){ out << "\n"; }//make sure to end with a newline in the file 72 file.close(); 73 return true; 74 } 75 return false; 76 } 77 78 void loadPulseDisabled(); 79 80 private slots: 81 void setPulseDisabled(bool disable); 82 hideGUI()83 void hideGUI(){ 84 if(settings==0){ this->close(); } //no tray 85 else{ this->hide(); } //tray 86 } closeApplication()87 void closeApplication(){ 88 closing = true; 89 this->close(); 90 } 91 startExternalApp(QAction * act)92 void startExternalApp(QAction *act){ 93 if(act->whatsThis().isEmpty()){ return; } 94 QProcess::startDetached(act->whatsThis()); 95 } 96 97 void changeDefaultTrayDevice(QString device); 98 void changeRecordingDevice(QString device); 99 void changeOutputDevice(); 100 void saveOutputDevice(); 101 102 void itemChanged(QString device); //for individual device adjustments 103 void TestSound(); 104 void TestStateChanged(QMediaPlayer::State); 105 void RestartPulseAudio(); 106 slotSingleInstance()107 void slotSingleInstance(){ 108 updateGUI(); 109 this->show(); 110 } 111 112 protected: closeEvent(QCloseEvent * event)113 void closeEvent(QCloseEvent *event){ 114 if(!closing && settings!=0){ 115 //tray running - just hide it 116 event->ignore(); 117 hideGUI(); 118 } 119 } 120 121 signals: 122 void updateTray(); 123 void outChanged(); 124 125 }; 126 127 #endif 128