1 /*************************************************************************** 2 * Copyright (C) 2012-2020 by Mihai Moldovan <ionic@ionic.de> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 ***************************************************************************/ 19 20 #ifndef PULSEMANAGER_H 21 #define PULSEMANAGER_H 22 23 #include <iostream> 24 #include <QDir> 25 #include <QTcpSocket> 26 #include <QEventLoop> 27 #include <QTemporaryFile> 28 #include <QHostInfo> 29 #include <QProcess> 30 #include <QApplication> 31 #include <QTimer> 32 #include <assert.h> 33 34 #ifdef Q_OS_WIN 35 #include "windows_stdint.h" 36 #else /* defined (Q_OS_WIN) */ 37 #include "unix_stdint.h" 38 #endif /* defined (Q_OS_WIN) */ 39 40 #include "x2gosettings.h" 41 #include "wapi.h" 42 43 class PulseManager: public QObject { 44 Q_OBJECT; 45 46 public: 47 PulseManager (); 48 ~PulseManager (); 49 50 QProcess::ProcessState state (); 51 52 std::uint16_t get_pulse_port () const; 53 std::uint16_t get_esd_port () const; 54 bool get_record () const; 55 bool get_playback () const; 56 QDir get_pulse_dir () const; 57 58 bool set_pulse_port (std::uint16_t pulse_port); 59 bool set_esd_port (std::uint16_t esd_port); 60 bool set_record (bool record); 61 bool set_playback (bool playback); 62 void set_debug (bool debug); 63 bool is_server_running () const; 64 65 66 67 public slots: 68 void start (); 69 void restart (); 70 void shutdown (); 71 72 73 private: 74 PulseManager (const PulseManager &other); 75 76 void start_osx (); 77 void start_win (); 78 // FIXME 79 void start_linux (); 80 void start_generic (); 81 82 void fetch_pulseaudio_version (); 83 84 bool find_port (bool search_esd = false); 85 86 bool generate_server_config (); 87 bool generate_client_config (); 88 89 void create_client_dir (); 90 void cleanup_client_dir (); 91 92 void show_startup_warning (bool play_startup_sound = false); 93 94 95 private slots: 96 void slot_on_pulse_finished (int exit_code); 97 void slot_play_startup_sound (); 98 99 100 signals: 101 void sig_pulse_server_terminated (); 102 void sig_pulse_user_warning(bool error, const QString& main_text, const QString& inf_text, bool modal); 103 104 105 private: 106 QString app_dir_; 107 QString pulse_X2Go_; 108 QDir pulse_dir_; 109 QString server_binary_; 110 QString server_working_dir_; 111 112 QProcessEnvironment env_; 113 QStringList server_args_; 114 QProcess *pulse_server_; 115 QProcess::ProcessState state_; 116 117 std::uint16_t pulse_port_; 118 std::uint16_t esd_port_; 119 120 std::uint32_t pulse_version_major_; 121 std::uint32_t pulse_version_minor_; 122 std::uint32_t pulse_version_micro_; 123 QString pulse_version_misc_; 124 bool pulse_version_valid_; 125 126 bool record_; 127 bool playback_; 128 129 bool debug_; 130 131 bool system_pulse_; 132 bool shutdown_state_; 133 }; 134 135 #endif // PULSEMANAGER_H 136