From ff7286ebecbf502e23b49f83124094a322dab94c Mon Sep 17 00:00:00 2001 From: petern Date: Sat, 28 Nov 2009 16:40:47 +0000 Subject: [PATCH] Split session gui from session (dbus) code git-svn-id: file:///home/vcs/svn/jsweeper/trunk@13 6611ac79-6612-48ef-a1e9-b906f853523e --- CMakeLists.txt | 2 + src/gui.cpp | 4 +- src/jsweeper.cpp | 5 +- src/jsweeper.glade | 567 ++++++++++++++++++++++++++------------------ src/session.cpp | 91 +++---- src/session.h | 36 +-- src/session_gui.cpp | 111 +++++++++ src/session_gui.h | 58 +++++ 8 files changed, 542 insertions(+), 332 deletions(-) create mode 100644 src/session_gui.cpp create mode 100644 src/session_gui.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fb7fa1c..cc99633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,8 @@ SET(SOURCES src/portmanager.h src/session.cpp src/session.h + src/session_gui.cpp + src/session_gui.h ) LINK_DIRECTORIES( diff --git a/src/gui.cpp b/src/gui.cpp index a69054d..e6022db 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,7 +5,7 @@ #include "portmanager.h" #include "gui.h" #include "config.h" -#include "session.h" +#include "session_gui.h" Glib::RefPtr g_builder; @@ -172,6 +172,8 @@ void Gui::on_session_save() void Gui::on_session_save_as() { + SessionSaveGui *sgui = SessionSaveGui::Open(); + sgui->show(); } void Gui::on_session_close() diff --git a/src/jsweeper.cpp b/src/jsweeper.cpp index c9c956c..93d1b8b 100644 --- a/src/jsweeper.cpp +++ b/src/jsweeper.cpp @@ -20,10 +20,11 @@ int main(int argc, char **argv) g = Gui::Open(); kit.run(*g); - delete g; jack.Disconnect(); - cfg.Write(); + + delete g; + return 0; } diff --git a/src/jsweeper.glade b/src/jsweeper.glade index 9f7fa9e..f13588e 100644 --- a/src/jsweeper.glade +++ b/src/jsweeper.glade @@ -1,6 +1,6 @@ - + JACK Sweeper @@ -775,12 +775,27 @@ 6 6 - + True - 0 - Font: + True + 0 0 100 1 10 10 + 1 + 2 + 1 + 2 + + + + + True + 0 + Cell padding: + + + 1 + 2 GTK_FILL @@ -797,30 +812,15 @@ - + True 0 - Cell padding: + Font: - 1 - 2 GTK_FILL - - - True - True - 0 0 100 1 10 10 - - - 1 - 2 - 1 - 2 - - 1 @@ -872,169 +872,73 @@ 6 6 - + True - 0 - Background: - - - GTK_FILL - - - - - True - 0 - Client tabs: - - - 1 - 2 - GTK_FILL - - - - - True - 0 - Port group tabs: - - - 2 - 3 - GTK_FILL - - - - - True - 0 - Audio port tabs: - - - 3 - 4 - GTK_FILL - - - - - True - True - True - 0 - #000000000000 - - - 1 - 2 - - - - - - True - True - True - 0 - #000000000000 - - - 1 - 2 - 1 - 2 - GTK_EXPAND - - - - - True - True - True - 0 - #000000000000 - - - 1 - 2 - 2 - 3 - GTK_EXPAND - - - - - True - True - True - 0 - #000000000000 - - - 1 - 2 - 3 - 4 - GTK_EXPAND - - - - - True - 0 - MIDI port tabs: - - - 4 - 5 - GTK_FILL - - - - - True - True - True - 0 - #000000000000 - - - 1 - 2 - 4 - 5 - GTK_EXPAND - - - - - True - 0 - Foreground: 2 3 + 4 + 5 GTK_FILL - + True - True - True - 0 - #000000000000 + 0 + Grid lines (ports): - 3 - 4 - + 2 + 3 + 3 + 4 + GTK_FILL - + + True + 0 + Grid lines (groups): + + + 2 + 3 + 2 + 3 + GTK_FILL + + + + + True + 0 + Grid lines (clients): + + + 2 + 3 + 1 + 2 + GTK_FILL + + + + + True + + + 3 + 4 + 4 + 5 + GTK_FILL + + + + True True True @@ -1044,8 +948,8 @@ 3 4 - 1 - 2 + 3 + 4 @@ -1066,7 +970,7 @@ - + True True True @@ -1076,74 +980,170 @@ 3 4 - 3 - 4 + 1 + 2 - + True + True + True + 0 + #000000000000 3 4 + + + + + + True + 0 + Foreground: + + + 2 + 3 + GTK_FILL + + + + + True + True + True + 0 + #000000000000 + + + 1 + 2 + 4 + 5 + GTK_EXPAND + + + + + True + 0 + MIDI port tabs: + + 4 5 GTK_FILL - + True - 0 - Grid lines (clients): + True + True + 0 + #000000000000 - 2 - 3 + 1 + 2 + 3 + 4 + GTK_EXPAND + + + + + True + True + True + 0 + #000000000000 + + + 1 + 2 + 2 + 3 + GTK_EXPAND + + + + + True + True + True + 0 + #000000000000 + + + 1 + 2 1 2 + GTK_EXPAND + + + + + True + True + True + 0 + #000000000000 + + + 1 + 2 + + + + + + True + 0 + Audio port tabs: + + + 3 + 4 GTK_FILL - + True 0 - Grid lines (groups): + Port group tabs: - 2 - 3 2 3 GTK_FILL - + True 0 - Grid lines (ports): + Client tabs: - 2 - 3 - 3 - 4 + 1 + 2 GTK_FILL - + True + 0 + Background: - 2 - 3 - 4 - 5 GTK_FILL @@ -1261,25 +1261,29 @@ 6 6 - + True True + Stop after matching rule + 0 + True - 1 2 - 1 - 2 + 2 + 3 - + True - True + 0 + _Source match rule: + True + True - 1 - 2 + GTK_FILL @@ -1297,29 +1301,25 @@ - + True - 0 - _Source match rule: - True - True + True - GTK_FILL + 1 + 2 - + True True - Stop after matching rule - 0 - True + 1 2 - 2 - 3 + 1 + 2 @@ -1384,25 +1384,29 @@ 6 6 - + True True + Stop after matching rule + 0 + True - 1 2 - 1 - 2 + 2 + 3 - + True - True + 0 + _Match rule: + True + True - 1 - 2 + GTK_FILL @@ -1420,29 +1424,25 @@ - + True - 0 - _Match rule: - True - True + True - GTK_FILL + 1 + 2 - + True True - Stop after matching rule - 0 - True + 1 2 - 2 - 3 + 1 + 2 @@ -1585,4 +1585,101 @@ + + 5 + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + 2 + + + True + 5 + 6 + + + True + 0 + <b>Save session as</b> + True + + + False + False + + + + + True + + + True + + + + + False + False + + + + + True + True + + + 1 + + + + + 1 + + + + + False + False + 1 + + + + + True + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + 0 + + + + + True + True + True + gtk-ok + True + 0 + + + 1 + + + + + False + GTK_PACK_END + + + + + diff --git a/src/session.cpp b/src/session.cpp index f5390da..b382648 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,29 +1,35 @@ #include -#include #include "session.h" -#include "gui.h" -DBusGConnection *connection; -DBusGProxy *proxy; +std::string Session::m_last_name; Session::Session() { GError *error = NULL; - g_type_init(); + m_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + m_proxy = NULL; - connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (m_connection == NULL) return; - if (connection == NULL) return; - - proxy = dbus_g_proxy_new_for_name( - connection, "org.jackaudio.sessionmanager", + m_proxy = dbus_g_proxy_new_for_name( + m_connection, "org.jackaudio.sessionmanager", "/org/jackaudio/sessionmanager", "org.jackaudio.sessionmanager"); + + if (m_proxy == NULL) { + g_object_unref(m_connection); + m_connection = NULL; + } } Session::~Session() { - g_object_unref(proxy); + if (m_proxy) g_object_unref(m_proxy); +} + +int Session::Save() +{ + return SaveAs(m_last_name); } int Session::SaveAs(std::string name) @@ -31,14 +37,16 @@ int Session::SaveAs(std::string name) GError *error = NULL; int ret; - if (proxy == NULL) return -1; + if (m_proxy == NULL) return -1; - dbus_g_proxy_call(proxy, "save_as", &error, + dbus_g_proxy_call(m_proxy, "save_as", &error, G_TYPE_STRING, name.c_str(), G_TYPE_INVALID, G_TYPE_INT, &ret, G_TYPE_INVALID); + m_last_name = name; + return ret; } @@ -47,27 +55,29 @@ int Session::Load(std::string name) GError *error = NULL; int ret; - if (proxy == NULL) return -1; + if (m_proxy == NULL) return -1; - dbus_g_proxy_call(proxy, "load", &error, + dbus_g_proxy_call(m_proxy, "load", &error, G_TYPE_STRING, name.c_str(), G_TYPE_INVALID, G_TYPE_INT, &ret, G_TYPE_INVALID); + m_last_name = name; + return ret; } std::list Session::List() { GError *error = NULL; - char **session_list; + char **session_list = NULL; char **session_list_ptr; std::list list; - if (proxy == NULL) return list; + if (m_proxy == NULL) return list; - dbus_g_proxy_call(proxy, "list", &error, + dbus_g_proxy_call(m_proxy, "list", &error, G_TYPE_INVALID, G_TYPE_STRV, &session_list, G_TYPE_INVALID); @@ -82,48 +92,3 @@ std::list Session::List() return list; } - -Session s; - -// Session Open window - -SessionOpenGui *SessionOpenGui::Open() -{ - SessionOpenGui *window = NULL; - g_builder->get_widget_derived("dialog_session_open", window); - return window; -} - -SessionOpenGui::SessionOpenGui(BaseObjectType *cobject, const Glib::RefPtr &builder) - : Gtk::Dialog(cobject) -{ - builder->get_widget("combobox_session_open", combobox_session_open); - builder->get_widget("button_session_open_cancel", button_session_open_cancel); - builder->get_widget("button_session_open_okay", button_session_open_okay); - - m_tree_model = Gtk::ListStore::create(m_columns); - combobox_session_open->set_model(m_tree_model); - - Gtk::TreeModel::Row row; - std::list sessions = s.List(); - std::list::iterator it; - for (it = sessions.begin(); it != sessions.end(); ++it) { - row = *(m_tree_model->append()); - row[m_columns.m_name] = *it; - } - - combobox_session_open->pack_start(m_columns.m_name); - - button_session_open_cancel->signal_clicked().connect(sigc::mem_fun(*this, &SessionOpenGui::on_cancel)); - button_session_open_okay->signal_clicked().connect(sigc::mem_fun(*this, &SessionOpenGui::on_okay)); -} - -void SessionOpenGui::on_cancel() -{ - hide(); -} - -void SessionOpenGui::on_okay() -{ - hide(); -} diff --git a/src/session.h b/src/session.h index 8266d8f..496e690 100644 --- a/src/session.h +++ b/src/session.h @@ -3,8 +3,7 @@ #include #include -#include -#include "glib.h" +#include class Session { @@ -12,40 +11,15 @@ public: Session(); ~Session(); + int Save(); int SaveAs(std::string name); int Load(std::string name); std::list List(); -}; -class SessionOpenGui : public Gtk::Dialog -{ private: - Gtk::ComboBox *combobox_session_open; - Gtk::Button *button_session_open_cancel; - Gtk::Button *button_session_open_okay; - -public: - SessionOpenGui(BaseObjectType *cobject, const Glib::RefPtr &builder); - - static SessionOpenGui *Open(); - -protected: - void on_cancel(); - void on_okay(); - - class ModelColumns : public Gtk::TreeModel::ColumnRecord - { - public: - ModelColumns() - { - add(m_name); - } - - Gtk::TreeModelColumn m_name; - }; - - ModelColumns m_columns; - Glib::RefPtr m_tree_model; + DBusGConnection *m_connection; + DBusGProxy *m_proxy; + static std::string m_last_name; }; #endif // SESSION_H diff --git a/src/session_gui.cpp b/src/session_gui.cpp new file mode 100644 index 0000000..1079f57 --- /dev/null +++ b/src/session_gui.cpp @@ -0,0 +1,111 @@ +#include +#include "session_gui.h" +#include "session.h" +#include "gui.h" + +// Session Open window + +SessionOpenGui *SessionOpenGui::Open() +{ + SessionOpenGui *window = NULL; + g_builder->get_widget_derived("dialog_session_open", window); + if (window != NULL) window->Refresh(); + return window; +} + +SessionOpenGui::SessionOpenGui(BaseObjectType *cobject, const Glib::RefPtr &builder) + : Gtk::Dialog(cobject) +{ + builder->get_widget("combobox_session_open", combobox_session_open); + builder->get_widget("button_session_open_cancel", button_session_open_cancel); + builder->get_widget("button_session_open_okay", button_session_open_okay); + + m_tree_model = Gtk::ListStore::create(m_columns); + combobox_session_open->set_model(m_tree_model); + combobox_session_open->pack_start(m_columns.m_name); + + button_session_open_cancel->signal_clicked().connect(sigc::mem_fun(*this, &SessionOpenGui::on_cancel)); + button_session_open_okay->signal_clicked().connect(sigc::mem_fun(*this, &SessionOpenGui::on_okay)); +} + +void SessionOpenGui::Refresh() +{ + Session *s = new Session(); + std::list sessions = s->List(); + delete s; + + bool active = sessions.size() > 0; + combobox_session_open->set_sensitive(active); + button_session_open_okay->set_sensitive(active); + + if (active) { + m_tree_model->clear(); + + Gtk::TreeModel::Row row; + std::list::iterator it; + for (it = sessions.begin(); it != sessions.end(); ++it) { + row = *(m_tree_model->append()); + row[m_columns.m_name] = *it; + } + } +} + +void SessionOpenGui::on_cancel() +{ + hide(); +} + +void SessionOpenGui::on_okay() +{ + Gtk::TreeModel::iterator iter = combobox_session_open->get_active(); + if (iter) { + Gtk::TreeModel::Row row = *iter; + + Session *s = new Session(); + s->Load(row[m_columns.m_name]); + delete s; + } + + hide(); +} + + +// Session Save window + +SessionSaveGui *SessionSaveGui::Open() +{ + SessionSaveGui *window = NULL; + g_builder->get_widget_derived("dialog_session_save", window); + if (window != NULL) window->Refresh(); + return window; +} + +SessionSaveGui::SessionSaveGui(BaseObjectType *cobject, const Glib::RefPtr &builder) + : Gtk::Dialog(cobject) +{ + builder->get_widget("entry_session_name", entry_session_name); + builder->get_widget("button_session_save_cancel", button_session_save_cancel); + builder->get_widget("button_session_save_okay", button_session_save_okay); + + button_session_save_cancel->signal_clicked().connect(sigc::mem_fun(*this, &SessionSaveGui::on_cancel)); + button_session_save_okay->signal_clicked().connect(sigc::mem_fun(*this, &SessionSaveGui::on_okay)); +} + +void SessionSaveGui::Refresh() +{ + entry_session_name->set_text(""); +} + +void SessionSaveGui::on_cancel() +{ + hide(); +} + +void SessionSaveGui::on_okay() +{ + Session *s = new Session(); + s->SaveAs(entry_session_name->get_text()); + delete s; + + hide(); +} diff --git a/src/session_gui.h b/src/session_gui.h new file mode 100644 index 0000000..60cf5d2 --- /dev/null +++ b/src/session_gui.h @@ -0,0 +1,58 @@ +#ifndef SESSION_GUI_H +#define SESSION_GUI_H + +#include +#include + +class SessionOpenGui : public Gtk::Dialog +{ +private: + Gtk::ComboBox *combobox_session_open; + Gtk::Button *button_session_open_cancel; + Gtk::Button *button_session_open_okay; + +public: + SessionOpenGui(BaseObjectType *cobject, const Glib::RefPtr &builder); + + static SessionOpenGui *Open(); + void Refresh(); + +protected: + void on_cancel(); + void on_okay(); + + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { + add(m_name); + } + + Gtk::TreeModelColumn m_name; + }; + + ModelColumns m_columns; + Glib::RefPtr m_tree_model; +}; + + +class SessionSaveGui : public Gtk::Dialog +{ +private: + Gtk::Entry *entry_session_name; + Gtk::Button *button_session_save_cancel; + Gtk::Button *button_session_save_okay; + +public: + SessionSaveGui(BaseObjectType *cobject, const Glib::RefPtr &builder); + + static SessionSaveGui *Open(); + void Refresh(); + +protected: + void on_cancel(); + void on_okay(); +}; + +#endif // SESSION_GUI_H