From c2ec65fc81cc51573f3fb9deb02fa2830a359604 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 27 Jul 2006 18:14:19 +0000 Subject: initial commit git-svn-id: file:///home/lennart/svn/public/paprefs/trunk@3 54a58c19-9419-0410-9bbb-d8fa3e5d54ff --- src/Makefile.am | 31 +++ src/paprefs.cc | 316 +++++++++++++++++++++++++++++++ src/paprefs.desktop | 11 ++ src/paprefs.glade | 532 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 890 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/paprefs.cc create mode 100644 src/paprefs.desktop create mode 100644 src/paprefs.glade (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..6a54d31 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,31 @@ +# $Id$ +# +# This file is part of paprefs. +# +# paprefs is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# paprefs is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with paprefs; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +desktopdir = $(datadir)/applications + +bin_PROGRAMS=paprefs + +dist_pkgdata_DATA=paprefs.glade +dist_desktop_DATA=paprefs.desktop + +paprefs_SOURCES=paprefs.cc + +paprefs_LDADD=$(AM_LDADD) $(GUILIBS_LIBS) +paprefs_CXXFLAGS=$(AM_CXXFLAGS) $(GUILIBS_CFLAGS) +paprefs_CXXFLAGS+=-DGLADE_FILE=\"$(pkgdatadir)/paprefs.glade\" diff --git a/src/paprefs.cc b/src/paprefs.cc new file mode 100644 index 0000000..8f59404 --- /dev/null +++ b/src/paprefs.cc @@ -0,0 +1,316 @@ +/* $Id$ */ + +/*** + This file is part of paprefs. + + paprefs is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + paprefs is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with paprefs; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include + +#define PA_GCONF_ROOT "/system/pulseaudio" +#define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules" + +class MainWindow : public Gtk::Window { +public: + MainWindow(BaseObjectType* cobject, const Glib::RefPtr& x); + static MainWindow* create(); + + Gtk::EventBox *titleEventBox; + Gtk::Button *closeButton; + + Gtk::CheckButton + *remoteAccessCheckButton, + *zeroconfCheckButton, + *anonymousAuthCheckButton, + *rtpReceiveCheckButton, + *rtpSendCheckButton, + *rtpLoopbackCheckButton; + + Gtk::RadioButton + *rtpMikeRadioButton, + *rtpSpeakerRadioButton, + *rtpNullSinkRadioButton; + + Glib::RefPtr gconf; + + bool ignoreChanges; + + void onCloseButtonClicked(); + void updateSensitive(); + void onChangeRemoteAccess(); + void onChangeRtpReceive(); + void onChangeRtpSend(); + void readFromGConf(); + void writeToGConfRemoteAccess(); + void writeToGConfRtpReceive(); + void writeToGConfRtpSend(); + void onGConfChange(const Glib::ustring& key, const Gnome::Conf::Value& value); +}; + +MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr& x) : + Gtk::Window(cobject), ignoreChanges(true) { + + x->get_widget("titleEventBox", titleEventBox); + x->get_widget("closeButton", closeButton); + + x->get_widget("remoteAccessCheckButton", remoteAccessCheckButton); + x->get_widget("zeroconfCheckButton", zeroconfCheckButton); + x->get_widget("anonymousAuthCheckButton", anonymousAuthCheckButton); + x->get_widget("rtpReceiveCheckButton", rtpReceiveCheckButton); + x->get_widget("rtpSendCheckButton", rtpSendCheckButton); + x->get_widget("rtpLoopbackCheckButton", rtpLoopbackCheckButton); + + x->get_widget("rtpMikeRadioButton", rtpMikeRadioButton); + x->get_widget("rtpSpeakerRadioButton", rtpSpeakerRadioButton); + x->get_widget("rtpNullSinkRadioButton", rtpNullSinkRadioButton); + + Gdk::Color c("white"); + titleEventBox->modify_bg(Gtk::STATE_NORMAL, c); + + gconf = Gnome::Conf::Client::get_default_client(); + gconf->set_error_handling(Gnome::Conf::CLIENT_HANDLE_ALL); + gconf->add_dir(PA_GCONF_ROOT, Gnome::Conf::CLIENT_PRELOAD_RECURSIVE); + + gconf->signal_value_changed().connect(sigc::mem_fun(*this, &MainWindow::onGConfChange)); + readFromGConf(); + + closeButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onCloseButtonClicked)); + + remoteAccessCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRemoteAccess)); + zeroconfCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRemoteAccess)); + anonymousAuthCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRemoteAccess)); + + rtpReceiveCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpReceive)); + + rtpSendCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpSend)); + rtpLoopbackCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpSend)); + rtpMikeRadioButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpSend)); + rtpSpeakerRadioButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpSend)); + rtpNullSinkRadioButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onChangeRtpSend)); +} + +MainWindow* MainWindow::create() { + MainWindow* w; + Glib::RefPtr x = Gnome::Glade::Xml::create(GLADE_FILE, "mainWindow"); + x->get_widget_derived("mainWindow", w); + return w; +} + +void MainWindow::onCloseButtonClicked() { + Gtk::Main::quit(); +} + +void MainWindow::updateSensitive() { + bool b; + + b = remoteAccessCheckButton->get_active(); + zeroconfCheckButton->set_sensitive(b); + anonymousAuthCheckButton->set_sensitive(b); + + b = rtpSendCheckButton->get_active(); + rtpLoopbackCheckButton->set_sensitive(b && !rtpSpeakerRadioButton->get_active()); + rtpMikeRadioButton->set_sensitive(b); + rtpSpeakerRadioButton->set_sensitive(b); + rtpNullSinkRadioButton->set_sensitive(b); +} + +void MainWindow::onChangeRemoteAccess() { + + if (ignoreChanges) + return; + + updateSensitive(); + writeToGConfRemoteAccess(); +} + +void MainWindow::onChangeRtpReceive() { + if (ignoreChanges) + return; + + updateSensitive(); + writeToGConfRtpReceive(); + writeToGConfRtpSend(); +} + +void MainWindow::onChangeRtpSend() { + if (ignoreChanges) + return; + + updateSensitive(); + writeToGConfRtpSend(); +} + +void MainWindow::writeToGConfRemoteAccess() { + Gnome::Conf::ChangeSet changeSet; + bool zeroconfEnabled, anonymousEnabled; + + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/locked", true); + gconf->change_set_commit(changeSet, true); + + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/zeroconf_enabled", zeroconfEnabled = zeroconfCheckButton->get_active()); + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/anonymous_enabled", anonymousEnabled = anonymousAuthCheckButton->get_active()); + + if (remoteAccessCheckButton->get_active()) { + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/name0", Glib::ustring("module-native-protocol-tcp")); + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/name1", Glib::ustring("module-esound-protocol-tcp")); + + if (anonymousEnabled) { + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/args0", Glib::ustring("auth-anonymous=1")); + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/args1", Glib::ustring("auth-anonymous=1")); + } else { + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/args0", Glib::ustring("")); + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/args1", Glib::ustring("")); + } + + if (zeroconfEnabled) { + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/name2", Glib::ustring("module-zeroconf-publish")); + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/args2", Glib::ustring("")); + } else { + changeSet.unset(PA_GCONF_PATH_MODULES"/remote-access/name2"); + changeSet.unset(PA_GCONF_PATH_MODULES"/remote-access/args2"); + } + + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/enabled", true); + } else + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/enabled", false); + + gconf->change_set_commit(changeSet, true); + + changeSet.set(PA_GCONF_PATH_MODULES"/remote-access/locked", false); + gconf->change_set_commit(changeSet, true); + + gconf->suggest_sync(); +} + +void MainWindow::writeToGConfRtpReceive() { + Gnome::Conf::ChangeSet changeSet; + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/locked", true); + gconf->change_set_commit(changeSet, true); + + if (rtpReceiveCheckButton->get_active()) { + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/name0", Glib::ustring("module-rtp-recv")); + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/args0", Glib::ustring("")); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/enabled", true); + } else + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/enabled", false); + + gconf->change_set_commit(changeSet, true); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-recv/locked", false); + gconf->change_set_commit(changeSet, true); + + gconf->suggest_sync(); +} + +void MainWindow::writeToGConfRtpSend() { + Gnome::Conf::ChangeSet changeSet; + bool loopbackEnabled, mikeEnabled, speakerEnabled = false; + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/locked", true); + gconf->change_set_commit(changeSet, true); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/loopback_enabled", loopbackEnabled = rtpLoopbackCheckButton->get_active()); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/mode", Glib::ustring( + (mikeEnabled = rtpMikeRadioButton->get_active()) ? "microphone" : + ((speakerEnabled = rtpSpeakerRadioButton->get_active()) ? "speaker" : "null-sink"))); + + if (rtpSendCheckButton->get_active()) { + if (!mikeEnabled && !speakerEnabled) { + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/name0", Glib::ustring("module-null-sink")); + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/args0", Glib::ustring("sink_name=rtp format=s16be channels=2 rate=44100")); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/name1", Glib::ustring("module-rtp-send")); + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/args1", Glib::ustring(loopbackEnabled ? "source=rtp_monitor loop=1" : "source=rtp_monitor loop=0")); + } else { + char tmp[256]; + + snprintf(tmp, sizeof(tmp), "%s %s", + mikeEnabled ? "source=@DEFAULT_SOURCE@" : "source=@DEFAULT_MONITOR@", + mikeEnabled && loopbackEnabled ? "loop=1" : "loop=0"); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/name0", Glib::ustring("module-rtp-send")); + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/args0", Glib::ustring(tmp)); + + changeSet.unset(PA_GCONF_PATH_MODULES"/rtp-send/name1"); + changeSet.unset(PA_GCONF_PATH_MODULES"/rtp-send/args1"); + } + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/enabled", true); + } else + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/enabled", false); + + gconf->change_set_commit(changeSet, true); + + changeSet.set(PA_GCONF_PATH_MODULES"/rtp-send/locked", false); + gconf->change_set_commit(changeSet, true); + + gconf->suggest_sync(); +} + +void MainWindow::onGConfChange(const Glib::ustring&, const Gnome::Conf::Value&) { + readFromGConf(); +} + +void MainWindow::readFromGConf() { + Glib::ustring mode; + + ignoreChanges = TRUE; + + remoteAccessCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/remote-access/enabled")); + zeroconfCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/remote-access/zeroconf_enabled")); + anonymousAuthCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/remote-access/anonymous_enabled")); + + rtpReceiveCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/rtp-recv/enabled")); + + rtpSendCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/rtp-send/enabled")); + rtpLoopbackCheckButton->set_active(gconf->get_bool(PA_GCONF_PATH_MODULES"/rtp-send/loopback_enabled")); + + mode = gconf->get_string(PA_GCONF_PATH_MODULES"/rtp-send/mode"); + if (mode == "microphone") + rtpMikeRadioButton->set_active(TRUE); + else if (mode == "speaker") + rtpSpeakerRadioButton->set_active(TRUE); + else + rtpNullSinkRadioButton->set_active(TRUE); + + ignoreChanges = FALSE; + + updateSensitive(); +} + +int main(int argc, char *argv[]) { + signal(SIGPIPE, SIG_IGN); + Gtk::Main kit(argc, argv); + + Gnome::Conf::init(); + + Gtk::Window* mainWindow = MainWindow::create(); + + Gtk::Main::run(*mainWindow); + delete mainWindow; +} diff --git a/src/paprefs.desktop b/src/paprefs.desktop new file mode 100644 index 0000000..7de90fb --- /dev/null +++ b/src/paprefs.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Encoding=UTF-8 +Name=PulseAudio Preferences +GenericName=Sound server Preferences +Comment=View and modify the configuration of the local sound server +Exec=paprefs +Icon=preferences-desktop +StartupNotify=true +Type=Application +Categories=Application;AudioVideo;Audio; diff --git a/src/paprefs.glade b/src/paprefs.glade new file mode 100644 index 0000000..77f9bba --- /dev/null +++ b/src/paprefs.glade @@ -0,0 +1,532 @@ + + + + + + + PulseAudio Preferences + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + preferences-desktop + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + True + False + 0 + + + + True + True + False + + + + 12 + True + False + 12 + + + + True + 6 + preferences-desktop + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + False + 6 + + + + True + <span size="18000" color="black"><b>PulseAudio Preferences</b></span> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 1 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + True + + + + + + True + View and modify the configuration of the local sound server + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + True + + + + + 0 + True + True + + + + + + + 0 + False + False + + + + + + True + + + 0 + False + False + + + + + + 12 + True + False + 12 + + + + True + False + 0 + + + + True + <b>Network Access</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 12 + True + False + 6 + + + + True + True + Enable _network access to local sound devices + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + Allow other machines in LAN to _browse for local sound devices + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + False + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + Don't require _authentication + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + False + True + + + + + 0 + False + True + + + + + + True + <b>Multicast/RTP</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 12 + True + False + 6 + + + + True + True + Enable Multicast/RTP _receiver + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Enable Multicast/RTP _sender + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + Send audio from local _microphone + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + False + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + Send audio from local s_peakers + True + GTK_RELIEF_NORMAL + True + False + False + True + rtpMikeRadioButton + + + + + 0 + False + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + Create seperate audio _device for Multicast/RTP + True + GTK_RELIEF_NORMAL + True + False + False + True + rtpMikeRadioButton + + + + + 0 + False + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + True + _Loopback audio to local speakers + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + False + False + + + + + 0 + False + True + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_END + 0 + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + False + GTK_PACK_END + + + + + 0 + True + True + + + + + + + -- cgit