130 lines
2.7 KiB
C++
130 lines
2.7 KiB
C++
#include <string>
|
|
#include <dbus/dbus-glib.h>
|
|
#include "session.h"
|
|
#include "gui.h"
|
|
|
|
DBusGConnection *connection;
|
|
DBusGProxy *proxy;
|
|
|
|
Session::Session()
|
|
{
|
|
GError *error = NULL;
|
|
|
|
g_type_init();
|
|
|
|
connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
|
|
|
|
if (connection == NULL) return;
|
|
|
|
proxy = dbus_g_proxy_new_for_name(
|
|
connection, "org.jackaudio.sessionmanager",
|
|
"/org/jackaudio/sessionmanager", "org.jackaudio.sessionmanager");
|
|
}
|
|
|
|
Session::~Session()
|
|
{
|
|
g_object_unref(proxy);
|
|
}
|
|
|
|
int Session::SaveAs(std::string name)
|
|
{
|
|
GError *error = NULL;
|
|
int ret;
|
|
|
|
if (proxy == NULL) return -1;
|
|
|
|
dbus_g_proxy_call(proxy, "save_as", &error,
|
|
G_TYPE_STRING, name.c_str(),
|
|
G_TYPE_INVALID,
|
|
G_TYPE_INT, &ret,
|
|
G_TYPE_INVALID);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int Session::Load(std::string name)
|
|
{
|
|
GError *error = NULL;
|
|
int ret;
|
|
|
|
if (proxy == NULL) return -1;
|
|
|
|
dbus_g_proxy_call(proxy, "load", &error,
|
|
G_TYPE_STRING, name.c_str(),
|
|
G_TYPE_INVALID,
|
|
G_TYPE_INT, &ret,
|
|
G_TYPE_INVALID);
|
|
|
|
return ret;
|
|
}
|
|
|
|
std::list<std::string> Session::List()
|
|
{
|
|
GError *error = NULL;
|
|
char **session_list;
|
|
char **session_list_ptr;
|
|
std::list<std::string> list;
|
|
|
|
if (proxy == NULL) return list;
|
|
|
|
dbus_g_proxy_call(proxy, "list", &error,
|
|
G_TYPE_INVALID,
|
|
G_TYPE_STRV, &session_list,
|
|
G_TYPE_INVALID);
|
|
|
|
if (session_list == NULL) return list;
|
|
|
|
for (session_list_ptr = session_list; *session_list_ptr; session_list_ptr++) {
|
|
list.push_back(*session_list_ptr);
|
|
}
|
|
|
|
g_strfreev(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<Gtk::Builder> &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<std::string> sessions = s.List();
|
|
std::list<std::string>::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();
|
|
}
|