Changeset fac340a5fac75b5ca9df2f78c5e5bcd7efae5ed9
- Timestamp:
- 01/06/07 23:29:34 (6 years ago)
- Author:
- Philipp Kern <phil@…>
- Parents:
- c29976f37fa4528b898c2529533ab3d5bc0edc42
- Children:
- bfb82f7a7bf6cc0079b05343b7d90cc306215a54
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:29:34Z+0000
- Message:
-
[project @ Watching on Glib::signal_io() instead of using a timer]
Original author: Armin Burgmeier <armin@…>
Date: 2005-04-09 11:23:21+00:00
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r8b2a3a4
|
rfac340a
|
|
| 5 | 5 | |
| 6 | 6 | gobby_SOURCES = \ |
| | 7 | src/buffer_wrapper.cpp \ |
| 7 | 8 | src/config.cpp \ |
| 8 | 9 | src/historyentry.cpp \ |
-
|
rc29976f
|
rfac340a
|
|
| 2 | 2 | Scroll to the cursor if anotherone changed the document |
| 3 | 3 | Initialize size of paned widgets |
| 4 | | Connect to Glib::signal_io() with network connections instead of using a timer |
-
|
r8053a93
|
rfac340a
|
|
| 67 | 67 | void on_obby_chat(obby::user& user, const Glib::ustring& message); |
| 68 | 68 | |
| 69 | | bool on_timer(); |
| 70 | | |
| 71 | 69 | // Helper functions |
| 72 | 70 | void display_error(const Glib::ustring& message); |
| … |
… |
|
| 95 | 93 | bool m_running; // m_running is set if the obby connection has been |
| 96 | 94 | // established successfully. |
| 97 | | bool m_login_failed; // Variable used to indicate a login failed event |
| 98 | | // See corresponding comments in window.cpp |
| 99 | 95 | }; |
| 100 | 96 | |
-
|
r9421ea5
|
rfac340a
|
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | | #include <iostream> |
| 62 | 61 | void Gobby::Document::on_insert(const Gtk::TextBuffer::iterator& begin, |
| 63 | 62 | const Glib::ustring& text, |
| … |
… |
|
| 65 | 64 | { |
| 66 | 65 | if(m_editing) return; |
| 67 | | |
| 68 | | std::cout << "Insert " << text << " at " << begin.get_offset() << std::endl; |
| 69 | 66 | m_doc.insert(begin.get_offset(), text); |
| 70 | 67 | } |
| … |
… |
|
| 74 | 71 | { |
| 75 | 72 | if(m_editing) return; |
| 76 | | |
| 77 | | std::cout << "Erasing from " << begin.get_offset() |
| 78 | | << " to " << end.get_offset() << std::endl; |
| 79 | 73 | m_doc.erase(begin.get_offset(), end.get_offset() ); |
| 80 | 74 | } |
-
|
rc29976f
|
rfac340a
|
|
| 24 | 24 | #include <libobby/client_buffer.hpp> |
| 25 | 25 | #include <libobby/host_buffer.hpp> |
| | 26 | #include "buffer_wrapper.hpp" |
| 26 | 27 | #include "createdialog.hpp" |
| 27 | 28 | #include "joindialog.hpp" |
| … |
… |
|
| 33 | 34 | : Gtk::Window(Gtk::WINDOW_TOPLEVEL), |
| 34 | 35 | m_config(Glib::get_home_dir() + "/.gobby/config.xml"), m_buffer(NULL), |
| 35 | | m_running(false), m_login_failed(false) |
| | 36 | m_running(false) |
| 36 | 37 | { |
| 37 | 38 | m_header.session_create_event().connect( |
| … |
… |
|
| 100 | 101 | |
| 101 | 102 | // Create new buffer |
| 102 | | obby::host_buffer* buffer = new obby::host_buffer( |
| | 103 | obby::host_buffer* buffer = new HostBuffer( |
| 103 | 104 | port, name, red, green, blue); |
| 104 | 105 | |
| … |
… |
|
| 121 | 122 | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| 122 | 123 | |
| 123 | | |
| 124 | | if(!m_timer_conn.connected() ) |
| 125 | | m_timer_conn = Glib::signal_timeout().connect( |
| 126 | | sigc::mem_fun(*this, &Window::on_timer), 400); |
| 127 | | |
| 128 | 124 | // Running |
| 129 | 125 | m_running = true; |
| … |
… |
|
| 140 | 136 | else |
| 141 | 137 | { |
| 142 | | if(m_timer_conn.connected() ) |
| 143 | | m_timer_conn.disconnect(); |
| 144 | | |
| 145 | 138 | // Delete existing buffer, if any |
| 146 | 139 | delete m_buffer; |
| … |
… |
|
| 175 | 168 | // TODO: Keep existing connection if host and port did not |
| 176 | 169 | // change |
| 177 | | obby::client_buffer* buffer = new obby::client_buffer( |
| 178 | | host, port); |
| | 170 | obby::client_buffer* buffer = new ClientBuffer(host, port); |
| | 171 | |
| 179 | 172 | delete m_buffer; |
| 180 | 173 | m_buffer = buffer; |
| … |
… |
|
| 201 | 194 | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| 202 | 195 | |
| 203 | | if(!m_timer_conn.connected() ) |
| 204 | | m_timer_conn = Glib::signal_timeout().connect( |
| 205 | | sigc::mem_fun(*this, &Window::on_timer), 400); |
| 206 | | |
| 207 | 196 | buffer->login(name, red, green, blue); |
| 208 | 197 | } |
| 209 | 198 | else |
| 210 | 199 | { |
| 211 | | if(m_timer_conn.connected() ) |
| 212 | | m_timer_conn.disconnect(); |
| 213 | | |
| 214 | 200 | delete m_buffer; |
| 215 | 201 | m_buffer = NULL; |
| … |
… |
|
| 240 | 226 | m_running = false; |
| 241 | 227 | } |
| 242 | | |
| 243 | | if(m_timer_conn.connected() ) |
| 244 | | m_timer_conn.disconnect(); |
| 245 | 228 | |
| 246 | 229 | delete m_buffer; |
| … |
… |
|
| 315 | 298 | void Gobby::Window::on_obby_login_failed(const std::string& reason) |
| 316 | 299 | { |
| 317 | | // Remove timer connection, we do not need any timer calls while |
| 318 | | // displaying dialogs |
| 319 | | m_timer_conn.disconnect(); |
| 320 | 300 | display_error(reason); |
| 321 | | |
| 322 | | // We can not call on_session_join right here. In the callstack, there |
| 323 | | // is a call to the timer (which emitted the login_failed signal through |
| 324 | | // obby::buffer::select). on_session_join destroys this buffer, but it |
| 325 | | // still remains in the callstack. The program will crash if it regains |
| 326 | | // control. |
| 327 | | // TODO: A good solution would be to disable the name and port field |
| 328 | | // in the dialog now, because we are already connected to a server. Only |
| 329 | | // the login fields (name & color) will be editable. That ensures that |
| 330 | | // we need not to create a new buffer but just resend a login request. |
| 331 | | m_login_failed = true; |
| | 301 | on_session_join(); |
| 332 | 302 | } |
| 333 | 303 | |
| … |
… |
|
| 354 | 324 | { |
| 355 | 325 | m_chat.obby_server_message(message); |
| 356 | | } |
| 357 | | |
| 358 | | bool Gobby::Window::on_timer() |
| 359 | | { |
| 360 | | for(int i = 0; i < 15; ++ i) |
| 361 | | { |
| 362 | | if(!m_buffer) break; |
| 363 | | m_buffer->select(0); |
| 364 | | |
| 365 | | // See comment in Window::on_obby_login_failed |
| 366 | | if(m_login_failed) |
| 367 | | { |
| 368 | | on_session_join(); |
| 369 | | m_login_failed = false; |
| 370 | | return true; |
| 371 | | } |
| 372 | | } |
| 373 | | |
| 374 | | return true; |
| 375 | 326 | } |
| 376 | 327 | |