Split session gui from session (dbus) code

git-svn-id: file:///home/vcs/svn/jsweeper/trunk@13 6611ac79-6612-48ef-a1e9-b906f853523e
master
petern 2009-11-28 16:40:47 +00:00
parent c5e15fbf08
commit ff7286ebec
8 changed files with 542 additions and 332 deletions

View File

@ -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(

View File

@ -5,7 +5,7 @@
#include "portmanager.h"
#include "gui.h"
#include "config.h"
#include "session.h"
#include "session_gui.h"
Glib::RefPtr<Gtk::Builder> 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()

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Fri Nov 27 18:40:27 2009 -->
<!--Generated with glade3 3.4.5 on Sat Nov 28 15:24:09 2009 -->
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="title" translatable="yes">JACK Sweeper</property>
@ -775,12 +775,27 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkLabel" id="label6">
<widget class="GtkSpinButton" id="spin_cell_padding">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Font:</property>
<property name="can_focus">True</property>
<property name="adjustment">0 0 100 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Cell padding:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@ -797,30 +812,15 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Cell padding:</property>
<property name="label" translatable="yes">Font:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_cell_padding">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">0 0 100 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
@ -872,169 +872,73 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkLabel" id="label7">
<widget class="GtkLabel" id="label34">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Background:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Client tabs:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Port group tabs:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Audio port tabs:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_clients">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_port_groups">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_ports_audio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">MIDI port tabs:</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_ports_midi">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Foreground:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_text">
<widget class="GtkLabel" id="label33">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (ports):</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="x_options"></property>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_grid_client">
<widget class="GtkLabel" id="label32">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (groups):</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label31">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (clients):</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label30">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_grid_port">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@ -1044,8 +948,8 @@
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
</packing>
</child>
@ -1066,7 +970,7 @@
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_grid_port">
<widget class="GtkColorButton" id="colorbutton_grid_client">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@ -1076,74 +980,170 @@
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label30">
<widget class="GtkColorButton" id="colorbutton_text">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Foreground:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_ports_midi">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">MIDI port tabs:</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label31">
<widget class="GtkColorButton" id="colorbutton_ports_audio">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (clients):</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_port_groups">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_clients">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="colorbutton_background">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<property name="color">#000000000000</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Audio port tabs:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label32">
<widget class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (groups):</property>
<property name="label" translatable="yes">Port group tabs:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label33">
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Grid lines (ports):</property>
<property name="label" translatable="yes">Client tabs:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label34">
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Background:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@ -1261,25 +1261,29 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkEntry" id="entry_destination_rule">
<widget class="GtkCheckButton" id="check_connections_stop">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop after matching rule</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_source_rule">
<widget class="GtkLabel" id="label29">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Source match rule:</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
@ -1297,29 +1301,25 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label29">
<widget class="GtkEntry" id="entry_source_rule">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Source match rule:</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="check_connections_stop">
<widget class="GtkEntry" id="entry_destination_rule">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop after matching rule</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget>
@ -1384,25 +1384,29 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkEntry" id="entry_replace_rule">
<widget class="GtkCheckButton" id="check_aliases_stop">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop after matching rule</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_match_rule">
<widget class="GtkLabel" id="label26">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Match rule:</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
@ -1420,29 +1424,25 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label26">
<widget class="GtkEntry" id="entry_match_rule">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Match rule:</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="check_aliases_stop">
<widget class="GtkEntry" id="entry_replace_rule">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop after matching rule</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget>
@ -1585,4 +1585,101 @@
</widget>
</child>
</widget>
<widget class="GtkDialog" id="dialog_session_save">
<property name="border_width">5</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<widget class="GtkVBox" id="vbox18">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="spacing">6</property>
<child>
<widget class="GtkLabel" id="label37">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">&lt;b&gt;Save session as&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox12">
<property name="visible">True</property>
<child>
<widget class="GtkLabel" id="label38">
<property name="visible">True</property>
<property name="label" translatable="yes">
</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_session_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area7">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button_session_save_cancel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_session_save_okay">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,29 +1,35 @@
#include <string>
#include <dbus/dbus-glib.h>
#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<std::string> Session::List()
{
GError *error = NULL;
char **session_list;
char **session_list = NULL;
char **session_list_ptr;
std::list<std::string> 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<std::string> 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();
}

View File

@ -3,8 +3,7 @@
#include <string>
#include <list>
#include <gtkmm.h>
#include "glib.h"
#include <dbus/dbus-glib.h>
class Session
{
@ -12,40 +11,15 @@ public:
Session();
~Session();
int Save();
int SaveAs(std::string name);
int Load(std::string name);
std::list<std::string> 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<Gtk::Builder> &builder);
static SessionOpenGui *Open();
protected:
void on_cancel();
void on_okay();
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{
add(m_name);
}
Gtk::TreeModelColumn<std::string> m_name;
};
ModelColumns m_columns;
Glib::RefPtr<Gtk::ListStore> m_tree_model;
DBusGConnection *m_connection;
DBusGProxy *m_proxy;
static std::string m_last_name;
};
#endif // SESSION_H

111
src/session_gui.cpp 100644
View File

@ -0,0 +1,111 @@
#include <string>
#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<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);
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<std::string> 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<std::string>::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<Gtk::Builder> &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();
}

58
src/session_gui.h 100644
View File

@ -0,0 +1,58 @@
#ifndef SESSION_GUI_H
#define SESSION_GUI_H
#include <string>
#include <gtkmm.h>
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<Gtk::Builder> &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<std::string> m_name;
};
ModelColumns m_columns;
Glib::RefPtr<Gtk::ListStore> 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<Gtk::Builder> &builder);
static SessionSaveGui *Open();
void Refresh();
protected:
void on_cancel();
void on_okay();
};
#endif // SESSION_GUI_H