| 134 | | void Gobby::Window::on_session_create() try |
| 135 | | { |
| | 137 | void Gobby::Window::obby_start() |
| | 138 | { |
| | 139 | // Connect to obby events |
| | 140 | m_buffer->user_join_event().connect( |
| | 141 | sigc::mem_fun(*this, &Window::on_obby_user_join) ); |
| | 142 | m_buffer->user_part_event().connect( |
| | 143 | sigc::mem_fun(*this, &Window::on_obby_user_part) ); |
| | 144 | m_buffer->document_insert_event().connect( |
| | 145 | sigc::mem_fun(*this, &Window::on_obby_document_insert)); |
| | 146 | m_buffer->document_remove_event().connect( |
| | 147 | sigc::mem_fun(*this, &Window::on_obby_document_remove)); |
| | 148 | |
| | 149 | m_buffer->message_event().connect( |
| | 150 | sigc::mem_fun(*this, &Window::on_obby_chat) ); |
| | 151 | m_buffer->server_message_event().connect( |
| | 152 | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| | 153 | |
| | 154 | // Delegate start of obby session |
| | 155 | m_header.obby_start(*m_buffer); |
| | 156 | m_folder.obby_start(*m_buffer); |
| | 157 | m_userlist.obby_start(*m_buffer); |
| | 158 | m_chat.obby_start(*m_buffer); |
| | 159 | m_statusbar.obby_start(*m_buffer); |
| | 160 | |
| | 161 | // Forward user joins for users that are connected |
| | 162 | const obby::user_table& user_table = m_buffer->get_user_table(); |
| | 163 | for(obby::user_table::user_iterator<obby::user::CONNECTED> iter = |
| | 164 | user_table.user_begin<obby::user::CONNECTED>(); |
| | 165 | iter != user_table.user_end<obby::user::CONNECTED>(); |
| | 166 | ++ iter) |
| | 167 | { |
| | 168 | on_obby_user_join(*iter); |
| | 169 | } |
| | 170 | |
| | 171 | // Send documents to components |
| | 172 | obby::buffer::document_iterator iter = m_buffer->document_begin(); |
| | 173 | for(; iter != m_buffer->document_end(); ++ iter) |
| | 174 | on_obby_document_insert(*iter); |
| | 175 | |
| | 176 | // Set last page as active one because it is currently shown anyway. |
| | 177 | if(m_buffer->document_count() > 0) |
| | 178 | m_folder.set_current_page(m_buffer->document_count() - 1); |
| | 179 | } |
| | 180 | |
| | 181 | void Gobby::Window::obby_end() |
| | 182 | { |
| | 183 | // Nothing to do if no buffer is open |
| | 184 | if(!m_buffer.get() ) return; |
| | 185 | |
| | 186 | // Tell GUI components that the session ended |
| | 187 | m_header.obby_end(); |
| | 188 | m_folder.obby_end(); |
| | 189 | m_userlist.obby_end(); |
| | 190 | m_chat.obby_end(); |
| | 191 | m_statusbar.obby_end(); |
| | 192 | |
| | 193 | // Delete buffer and zeroconf |
| | 194 | m_buffer.reset(); |
| | 195 | #ifdef WITH_HOWL |
| | 196 | delete m_zeroconf; |
| | 197 | m_zeroconf = NULL; |
| | 198 | #endif |
| | 199 | } |
| | 200 | |
| | 201 | void Gobby::Window::on_session_create() |
| | 202 | { |
| | 203 | // Show up host dialog |
| 144 | | unsigned int red = color.get_red() * 255 / 65535; |
| 145 | | unsigned int green = color.get_green() * 255 / 65535; |
| 146 | | unsigned int blue = color.get_blue() * 255 / 65535; |
| 147 | | |
| 148 | | // Create new buffer |
| 149 | | obby::host_buffer* buffer = |
| 150 | | new HostBuffer(*this, port, name, red, green, blue); |
| 151 | | |
| | 215 | // Set up host with hostprogressdialog |
| | 216 | HostProgressDialog prgdlg(*this, m_config, port, name, color); |
| | 217 | if(prgdlg.run() == Gtk::RESPONSE_OK) |
| | 218 | { |
| | 219 | prgdlg.hide(); |
| | 220 | |
| | 221 | // Get buffer |
| | 222 | std::auto_ptr<obby::host_buffer> buffer = |
| | 223 | prgdlg.get_buffer(); |
| | 224 | |
| | 225 | // Set password |
| | 226 | buffer->set_global_password(password); |
| 158 | | buffer->set_global_password(password); |
| 159 | | |
| 160 | | // Delete existing buffer, take new one |
| 161 | | delete m_buffer; |
| 162 | | m_buffer = buffer; |
| 163 | | |
| 164 | | m_buffer->user_join_event().connect( |
| 165 | | sigc::mem_fun(*this, &Window::on_obby_user_join) ); |
| 166 | | m_buffer->user_part_event().connect( |
| 167 | | sigc::mem_fun(*this, &Window::on_obby_user_part) ); |
| 168 | | m_buffer->document_insert_event().connect( |
| 169 | | sigc::mem_fun(*this, &Window::on_obby_document_insert)); |
| 170 | | m_buffer->document_remove_event().connect( |
| 171 | | sigc::mem_fun(*this, &Window::on_obby_document_remove)); |
| 172 | | |
| 173 | | m_buffer->message_event().connect( |
| 174 | | sigc::mem_fun(*this, &Window::on_obby_chat) ); |
| 175 | | m_buffer->server_message_event().connect( |
| 176 | | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| 177 | | |
| 178 | | // Running |
| 179 | | m_running = true; |
| 180 | | |
| 181 | | // Delegate start of obby session |
| 182 | | m_header.obby_start(*m_buffer); |
| 183 | | m_folder.obby_start(*m_buffer); |
| 184 | | m_userlist.obby_start(*m_buffer); |
| 185 | | m_chat.obby_start(*m_buffer); |
| 186 | | m_statusbar.obby_start(*m_buffer); |
| 187 | | |
| 188 | | // Let the local user join |
| 189 | | on_obby_user_join(buffer->get_self() ); |
| 190 | | } |
| 191 | | else |
| 192 | | { |
| 193 | | // Delete existing buffer, if any |
| 194 | | delete m_buffer; |
| 195 | | m_buffer = NULL; |
| 196 | | } |
| 197 | | } |
| 198 | | catch(Glib::Exception& e) |
| 199 | | { |
| 200 | | display_error(e.what() ); |
| 201 | | on_session_create(); |
| 202 | | } |
| 203 | | catch(std::exception& e) |
| 204 | | { |
| 205 | | display_error(e.what() ); |
| 206 | | on_session_create(); |
| 207 | | } |
| 208 | | |
| 209 | | void Gobby::Window::on_session_join() try |
| | 233 | // Start session |
| | 234 | m_buffer = buffer; |
| | 235 | obby_start(); |
| | 236 | } |
| | 237 | } |
| | 238 | } |
| | 239 | |
| | 240 | void Gobby::Window::on_session_join() |
| 219 | | unsigned int red = color.get_red() * 255 / 65535; |
| 220 | | unsigned int green = color.get_green() * 255 / 65535; |
| 221 | | unsigned int blue = color.get_blue() * 255 / 65535; |
| 222 | | |
| 223 | | // TODO: Keep existing connection if host and port did not |
| 224 | | // change |
| 225 | | obby::client_buffer* buffer = |
| 226 | | new ClientBuffer(*this, host, port); |
| 227 | | |
| 228 | | delete m_buffer; |
| 229 | | m_buffer = buffer; |
| 230 | | |
| 231 | | buffer->login_failed_event().connect( |
| 232 | | sigc::mem_fun(*this, &Window::on_obby_login_failed) ); |
| 233 | | buffer->global_password_event().connect( |
| 234 | | sigc::mem_fun(*this, &Window::on_obby_global_password)); |
| 235 | | buffer->user_password_event().connect( |
| 236 | | sigc::mem_fun(*this, &Window::on_obby_user_password) ); |
| 237 | | buffer->close_event().connect( |
| 238 | | sigc::mem_fun(*this, &Window::on_obby_close) ); |
| 239 | | buffer->sync_event().connect( |
| 240 | | sigc::mem_fun(*this, &Window::on_obby_sync) ); |
| 241 | | |
| 242 | | /* TODO: Add password entry widget in join dialog */ |
| 243 | | /* TODO: Add password entry widget in host dialog */ |
| 244 | | |
| 245 | | m_buffer->user_join_event().connect( |
| 246 | | sigc::mem_fun(*this, &Window::on_obby_user_join) ); |
| 247 | | m_buffer->user_part_event().connect( |
| 248 | | sigc::mem_fun(*this, &Window::on_obby_user_part) ); |
| 249 | | m_buffer->document_insert_event().connect( |
| 250 | | sigc::mem_fun(*this, &Window::on_obby_document_insert)); |
| 251 | | m_buffer->document_remove_event().connect( |
| 252 | | sigc::mem_fun(*this, &Window::on_obby_document_remove)); |
| 253 | | |
| 254 | | m_buffer->message_event().connect( |
| 255 | | sigc::mem_fun(*this, &Window::on_obby_chat) ); |
| 256 | | m_buffer->server_message_event().connect( |
| 257 | | sigc::mem_fun(*this, &Window::on_obby_server_chat) ); |
| 258 | | |
| 259 | | buffer->login(name, red, green, blue); |
| 260 | | } |
| 261 | | else |
| 262 | | { |
| 263 | | delete m_buffer; |
| 264 | | m_buffer = NULL; |
| 265 | | } |
| 266 | | } |
| 267 | | catch(Glib::Exception& e) |
| 268 | | { |
| 269 | | display_error(e.what()); |
| 270 | | on_session_join(); |
| 271 | | } |
| 272 | | catch(std::exception& e) |
| 273 | | { |
| 274 | | display_error(e.what()); |
| 275 | | on_session_join(); |
| | 253 | JoinProgressDialog prgdlg( |
| | 254 | *this, m_config, host, port, name, color); |
| | 255 | if(prgdlg.run() == Gtk::RESPONSE_OK) |
| | 256 | { |
| | 257 | prgdlg.hide(); |
| | 258 | |
| | 259 | // Get buffer |
| | 260 | std::auto_ptr<obby::client_buffer> buffer = |
| | 261 | prgdlg.get_buffer(); |
| | 262 | |
| | 263 | buffer->close_event().connect( |
| | 264 | sigc::mem_fun(*this, &Window::on_obby_close) ); |
| | 265 | |
| | 266 | // Start session |
| | 267 | m_buffer = buffer; |
| | 268 | obby_start(); |
| | 269 | } |
| | 270 | } |
| 600 | | // Send obby start to GUI components if this is a join command for the |
| 601 | | // local user. The host does not emit such a signal (well it does, but |
| 602 | | // in its constructor - no signal handler could have been connected), |
| 603 | | // so it is only done for the client upon successful login |
| 604 | | if(&m_buffer->get_self() == &user) |
| 605 | | { |
| 606 | | m_header.obby_start(*m_buffer); |
| 607 | | m_folder.obby_start(*m_buffer); |
| 608 | | m_userlist.obby_start(*m_buffer); |
| 609 | | m_chat.obby_start(*m_buffer); |
| 610 | | m_statusbar.obby_start(*m_buffer); |
| 611 | | |
| 612 | | m_running = true; |
| 613 | | } |
| 614 | | |