Changeset fac340a5fac75b5ca9df2f78c5e5bcd7efae5ed9

Show
Ignore:
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:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r8b2a3a4 rfac340a  
    55 
    66gobby_SOURCES = \ 
     7        src/buffer_wrapper.cpp \ 
    78        src/config.cpp \ 
    89        src/historyentry.cpp \ 
  • TODO

    rc29976f rfac340a  
    22Scroll to the cursor if anotherone changed the document 
    33Initialize size of paned widgets 
    4 Connect to Glib::signal_io() with network connections instead of using a timer 
  • inc/window.hpp

    r8053a93 rfac340a  
    6767        void on_obby_chat(obby::user& user, const Glib::ustring& message); 
    6868 
    69         bool on_timer(); 
    70  
    7169        // Helper functions 
    7270        void display_error(const Glib::ustring& message); 
     
    9593        bool m_running; // m_running is set if the obby connection has been 
    9694                        // established successfully. 
    97         bool m_login_failed; // Variable used to indicate a login failed event 
    98                              // See corresponding comments in window.cpp 
    9995}; 
    10096 
  • src/document.cpp

    r9421ea5 rfac340a  
    5959} 
    6060 
    61 #include <iostream> 
    6261void Gobby::Document::on_insert(const Gtk::TextBuffer::iterator& begin, 
    6362                                const Glib::ustring& text, 
     
    6564{ 
    6665        if(m_editing) return; 
    67  
    68         std::cout << "Insert " << text << " at " << begin.get_offset() << std::endl; 
    6966        m_doc.insert(begin.get_offset(), text); 
    7067} 
     
    7471{ 
    7572        if(m_editing) return; 
    76          
    77         std::cout << "Erasing from " << begin.get_offset() 
    78                   << " to " << end.get_offset() << std::endl; 
    7973        m_doc.erase(begin.get_offset(), end.get_offset() ); 
    8074} 
  • src/window.cpp

    rc29976f rfac340a  
    2424#include <libobby/client_buffer.hpp> 
    2525#include <libobby/host_buffer.hpp> 
     26#include "buffer_wrapper.hpp" 
    2627#include "createdialog.hpp" 
    2728#include "joindialog.hpp" 
     
    3334 : Gtk::Window(Gtk::WINDOW_TOPLEVEL),  
    3435   m_config(Glib::get_home_dir() + "/.gobby/config.xml"), m_buffer(NULL), 
    35    m_running(false), m_login_failed(false) 
     36   m_running(false) 
    3637{ 
    3738        m_header.session_create_event().connect( 
     
    100101 
    101102                // Create new buffer 
    102                 obby::host_buffer* buffer = new obby::host_buffer( 
     103                obby::host_buffer* buffer = new HostBuffer( 
    103104                        port, name, red, green, blue); 
    104105 
     
    121122                        sigc::mem_fun(*this, &Window::on_obby_server_chat) ); 
    122123 
    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  
    128124                // Running 
    129125                m_running = true; 
     
    140136        else 
    141137        { 
    142                 if(m_timer_conn.connected() ) 
    143                         m_timer_conn.disconnect(); 
    144  
    145138                // Delete existing buffer, if any 
    146139                delete m_buffer; 
     
    175168                // TODO: Keep existing connection if host and port did not 
    176169                // change 
    177                 obby::client_buffer* buffer = new obby::client_buffer( 
    178                         host, port); 
     170                obby::client_buffer* buffer = new ClientBuffer(host, port); 
     171 
    179172                delete m_buffer; 
    180173                m_buffer = buffer; 
     
    201194                        sigc::mem_fun(*this, &Window::on_obby_server_chat) ); 
    202195 
    203                 if(!m_timer_conn.connected() ) 
    204                         m_timer_conn = Glib::signal_timeout().connect( 
    205                                 sigc::mem_fun(*this, &Window::on_timer), 400); 
    206  
    207196                buffer->login(name, red, green, blue); 
    208197        } 
    209198        else 
    210199        { 
    211                 if(m_timer_conn.connected() ) 
    212                         m_timer_conn.disconnect(); 
    213  
    214200                delete m_buffer; 
    215201                m_buffer = NULL; 
     
    240226                        m_running = false; 
    241227                } 
    242  
    243                 if(m_timer_conn.connected() ) 
    244                         m_timer_conn.disconnect(); 
    245228 
    246229                delete m_buffer; 
     
    315298void Gobby::Window::on_obby_login_failed(const std::string& reason) 
    316299{ 
    317         // Remove timer connection, we do not need any timer calls while 
    318         // displaying dialogs 
    319         m_timer_conn.disconnect(); 
    320300        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(); 
    332302} 
    333303 
     
    354324{ 
    355325        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; 
    375326} 
    376327