Code

Rework dialog management. Use singleton behavior for dialogs when
[inkscape.git] / src / ui / dialog / session-player.cpp
1 /**
2  * Whiteboard session playback control dialog
3  *
4  * Authors:
5  * David Yip <yipdw@rose-hulman.edu>
6  *
7  * Copyright (c) 2005 Authors
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
16 #include <glibmm.h>
17 #include <glibmm/i18n.h>
18 #include <gtk/gtkdialog.h>
19 #include <gtkmm.h>
21 #include "inkscape.h"
22 #include "path-prefix.h"
24 #include "desktop.h"
25 #include "desktop-handles.h"
26 #include "document.h"
28 #include "ui/stock.h"
30 #include "jabber_whiteboard/node-tracker.h"
31 #include "jabber_whiteboard/session-manager.h"
32 #include "jabber_whiteboard/session-file-player.h"
34 #include "ui/dialog/session-player.h"
36 #include "util/ucompose.hpp"
38 namespace Inkscape {
40 namespace UI {
42 namespace Dialog {
44 SessionPlaybackDialog*
45 SessionPlaybackDialog::create()
46 {
47         return new SessionPlaybackDialogImpl();
48 }
50 SessionPlaybackDialogImpl::SessionPlaybackDialogImpl() 
51         : _delay(100, 1, 5000, 10, 100), _delayentry(_delay)
52 {
53         this->_desktop = this->getDesktop();
54         this->_sm = this->_desktop->whiteboard_session_manager();
55         this->_sfp = this->_sm->session_player();
56         this->_openfile.set_text(this->_sfp->filename());
58         this->_construct();
59         this->get_vbox()->show_all_children();
60 }
62 SessionPlaybackDialogImpl::~SessionPlaybackDialogImpl()
63 {
65 }
67 void
68 SessionPlaybackDialogImpl::_construct()
69 {
70         Gtk::VBox* main = this->get_vbox();
72         // Dialog organization
73         this->_filemanager.set_label(_("Session file"));
74         this->_playback.set_label(_("Playback controls"));
75         this->_currentmsgbox.set_label(_("Message information"));
77         this->_filemanager.set_border_width(4);
78         this->_playback.set_border_width(4);
79         this->_fm.set_border_width(4);
80         this->_toolbarbox.set_border_width(4);
82         // Active session file display
83         // fixme: Does this mean the active file for the session, or the file for the active session?
84         // Please indicate which with a TRANSLATORS comment.
85         this->_labels[0].set_text(_("Active session file:"));
86         this->_labels[1].set_text(_("Delay (milliseconds):"));
88         this->_openfile.set_editable(false);
90         this->_filebox.pack_start(this->_labels[0], true, false, 8);
91         this->_filebox.pack_end(this->_openfile, true, true, 0);
93         // Unload/load buttons
94         this->_close.set_label(_("Close file"));
95         this->_open.set_label(_("Open new file"));
96         this->_setdelay.set_label(_("Set delay"));
98         // Attach callbacks
99         this->_close.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &SessionPlaybackDialogImpl::_respCallback), CLOSE_FILE));
100         this->_open.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &SessionPlaybackDialogImpl::_respCallback), OPEN_FILE));
101         this->_setdelay.signal_clicked().connect(sigc::bind< 0 >(sigc::mem_fun(*this, &SessionPlaybackDialogImpl::_respCallback), RESET_DELAY));
103         // Button box
104         this->_filebuttons.pack_start(this->_close, true, false, 0);
105         this->_filebuttons.pack_start(this->_open, true, false, 0);
107         // Message information box
108         this->_currentmsgbuffer = Gtk::TextBuffer::create();
109         this->_currentmsgview.set_buffer(this->_currentmsgbuffer);
110         this->_currentmsgview.set_editable(false);
111         this->_currentmsgview.set_cursor_visible(false);
112         this->_currentmsgview.set_wrap_mode(Gtk::WRAP_WORD);
113         this->_currentmsgscroller.add(this->_currentmsgview);
114         this->_currentmsgbox.add(this->_currentmsgscroller);
115         this->_sfp->setMessageOutputWidget(this->_currentmsgbuffer);
116         
117         // Delay setting
118         // parameters: initial lower upper single-incr page-incr
119         this->_delayentry.set_numeric(true);
121         // Playback controls
122         this->_playbackcontrols.set_show_arrow(false);
124         /* these are waiting for the Gtkmm conversion
125         this->_controls[0].set_stock_id(Stock::SESSION_PLAYBACK_REW);
126         this->_controls[1].set_stock_id(Stock::SESSION_PLAYBACK_STEPBACK);
127         this->_controls[2].set_stock_id(Stock::SESSION_PLAYBACK_PAUSE);
128         this->_controls[3].set_stock_id(Stock::SESSION_PLAYBACK_STEPFORWARD);
129         this->_controls[4].set_stock_id(Stock::SESSION_PLAYBACK_PLAY);
130         */
132         this->_controls[0].set_label("Rewind");
133         this->_controls[1].set_label("Go back one");
134         this->_controls[2].set_label("Pause");
135         this->_controls[3].set_label("Go forward one");
136         this->_controls[4].set_label("Play");
138         this->_controls[0].set_tooltip(this->_tooltips, _("Rewind"));
139         this->_controls[1].set_tooltip(this->_tooltips, _("Go back one change"));
140         this->_controls[2].set_tooltip(this->_tooltips, _("Pause"));
141         this->_controls[3].set_tooltip(this->_tooltips, _("Go forward one change"));
142         this->_controls[4].set_tooltip(this->_tooltips, _("Play"));
144         for(int i = 0; i < 5; i++) {
145                 this->_playbackcontrols.append(this->_controls[i], sigc::bind< 0 >(sigc::mem_fun(*this, &SessionPlaybackDialogImpl::_respCallback), TOOLBAR_BASE + i));
146         }
148         this->_delaybox.pack_start(this->_labels[1]);
149         this->_delaybox.pack_start(this->_delayentry);
150         this->_delaybox.pack_end(this->_setdelay);
152         this->_toolbarbox.pack_start(this->_delaybox);
153         this->_toolbarbox.pack_end(this->_playbackcontrols);
155         // Pack widgets into frames
156         this->_fm.pack_start(this->_filebox);
157         this->_fm.pack_end(this->_filebuttons);
159         this->_filemanager.add(this->_fm);
160         this->_playback.add(this->_toolbarbox);
161                         
162         // Pack widgets into main vbox
163         main->pack_start(this->_filemanager);
164         main->pack_start(this->_playback);
165         main->pack_end(this->_currentmsgbox);
168 void
169 SessionPlaybackDialogImpl::_respCallback(int resp)
171         g_log(NULL, G_LOG_LEVEL_DEBUG, "_respCallback: %u", resp);
172         switch(resp) {
173                 case CLOSE_FILE:
174                         this->_sfp->unload();
175                         break;
176                 case OPEN_FILE: {
177                         Gtk::FileChooserDialog sessionfiledlg(_("Open session file"), Gtk::FILE_CHOOSER_ACTION_OPEN);
178                         sessionfiledlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
179                         sessionfiledlg.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
181                         int result = sessionfiledlg.run();
182                         switch (result) {
183                                 case Gtk::RESPONSE_OK:
184                                         this->_sm->clearDocument();
185                                         sp_document_done(sp_desktop_document(this->_desktop), SP_VERB_NONE, 
186                                                          /* TODO: annotate */ "session-player.cpp:186");
187                                         this->_sm->loadSessionFile(sessionfiledlg.get_filename());
188                                         this->_openfile.set_text(this->_sfp->filename());
189                                         break;
190                                 default:
191                                         break;
192                         }
193                         break;
194                                                 }
195                 case RESET_DELAY:
196                         this->_sfp->setDelay(this->_delayentry.get_value_as_int());
197                         break;
198                 case REWIND:
199                         if (this->_sfp->_playing) {
200                                 this->_sfp->stop();
201                         }
202                         this->_sfp->_curdir = Whiteboard::SessionFilePlayer::BACKWARD;
203                         this->_sfp->start();
204                         break;
205                 case STEP_REWIND:
206                         this->_sfp->step(Whiteboard::SessionFilePlayer::BACKWARD);
207                         break;
208                 case PAUSE:
209                         this->_sfp->stop();
210                         break;
211                 case STEP_PLAY:
212                         this->_sfp->step(Whiteboard::SessionFilePlayer::FORWARD);
213                         break;
214                 case PLAY:
215                         if (this->_sfp->_playing) {
216                                 this->_sfp->stop();
217                         }
218                         this->_sfp->_curdir = Whiteboard::SessionFilePlayer::FORWARD;
219                         this->_sfp->start();
220                         break;
221                 default:
222                         break;
223         }