| | 76 | m_list_view.append_column(_("Connected"), m_list_cols.connected); |
| | 77 | m_list_view.append_column(_("Subscribed"), m_list_cols.subscribed); |
| | 78 | |
| | 79 | // Store TreeViewColumns |
| | 80 | m_view_col_colour = m_list_view.get_column(0); |
| | 81 | m_view_col_name = m_list_view.get_column(1); |
| | 82 | m_view_col_connected = m_list_view.get_column(2); |
| | 83 | m_view_col_subscribed = m_list_view.get_column(3); |
| | 84 | |
| | 85 | // Let the user sort by these columns |
| | 86 | m_view_col_name->set_sort_column(m_list_cols.name); |
| | 87 | m_view_col_connected->set_sort_column(m_list_cols.connected); |
| | 88 | m_view_col_subscribed->set_sort_column(m_list_cols.subscribed); |
| | 89 | |
| | 90 | // Let the user reorder the columns |
| | 91 | for(int i = 0; i < 4; ++ i) |
| | 92 | m_list_view.get_column(i)->set_reorderable(true); |
| | 93 | |
| | 94 | // No users can be selected |
| | 95 | m_list_view.get_selection()->set_mode(Gtk::SELECTION_NONE); |
| | 96 | |
| | 97 | // Hide subscription column until a document has been inserted |
| | 98 | m_view_col_subscribed->set_visible(false); |
| 95 | | Gtk::TreeModel::Row row = *(m_list_data->append() ); |
| 96 | | |
| | 136 | // Is there already such a user? |
| | 137 | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| | 138 | if(iter == m_list_data->children().end() ) |
| | 139 | { |
| | 140 | // No, so add the user to the list |
| | 141 | add_user(user); |
| | 142 | } |
| | 143 | else |
| | 144 | { |
| | 145 | // Update connected flag |
| | 146 | (*iter)[m_list_cols.connected] = true; |
| | 147 | } |
| | 148 | } |
| | 149 | |
| | 150 | void Gobby::UserList::obby_user_part(obby::user& user) |
| | 151 | { |
| | 152 | // User is not anymore connceted |
| | 153 | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| | 154 | (*iter)[m_list_cols.connected] = false; |
| | 155 | } |
| | 156 | |
| | 157 | void Gobby::UserList::obby_user_colour(obby::user& user) |
| | 158 | { |
| | 159 | // Get user with this name |
| | 160 | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| | 161 | // Get new colour |
| 100 | | |
| 101 | | row[m_list_cols.name] = user.get_name(); |
| 102 | | row[m_list_cols.color] = create_coloured_pixbuf(red, green, blue); |
| 103 | | } |
| 104 | | |
| 105 | | void Gobby::UserList::obby_user_part(obby::user& user) |
| 106 | | { |
| 107 | | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| 108 | | if(iter == m_list_data->children().end() ) return; |
| 109 | | |
| 110 | | m_list_data->erase(iter); |
| 111 | | } |
| 112 | | |
| 113 | | void Gobby::UserList::obby_user_colour(obby::user& user) |
| 114 | | { |
| 115 | | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| 116 | | |
| 117 | | unsigned int red = user.get_red(); |
| 118 | | unsigned int green = user.get_green(); |
| 119 | | unsigned int blue = user.get_blue(); |
| | 165 | // Update it |
| | 166 | (*iter)[m_list_cols.colour] = create_coloured_pixbuf(red, green, blue); |
| | 167 | } |
| | 168 | |
| | 169 | void Gobby::UserList::obby_document_insert(obby::local_document_info& info) |
| | 170 | { |
| | 171 | // Get notification when a user subscribed to this document |
| | 172 | info.subscribe_event().connect(sigc::bind( |
| | 173 | sigc::mem_fun(*this, &UserList::on_user_subscribe), |
| | 174 | sigc::ref(info)) ); |
| | 175 | |
| | 176 | // Get notification when a user unsubscribed |
| | 177 | info.unsubscribe_event().connect(sigc::bind( |
| | 178 | sigc::mem_fun(*this, &UserList::on_user_unsubscribe), |
| | 179 | sigc::ref(info)) ); |
| | 187 | // Is this the last document to be removed? |
| | 188 | if(document.get_buffer().document_count() == 1) |
| | 189 | // Hide subscription column then |
| | 190 | m_view_col_subscribed->set_visible(false); |
| | 191 | } |
| | 192 | |
| | 193 | void Gobby::UserList::on_folder_tab_switched(Document& document) |
| | 194 | { |
| | 195 | // No document open |
| | 196 | if(!m_view_col_subscribed->get_visible() ) return; |
| | 197 | // Update current info |
| | 198 | obby::local_document_info* info = &document.get_document(); |
| | 199 | // Same document |
| | 200 | if(info == m_info) return; |
| | 201 | m_info = info; |
| | 202 | // Clear current data |
| | 203 | m_list_data->clear(); |
| | 204 | // Get user table |
| | 205 | const obby::user_table& user_table = |
| | 206 | info->get_buffer().get_user_table(); |
| | 207 | // Add all users in user table |
| | 208 | for(obby::user_table::user_iterator<obby::user::NONE, false> iter = |
| | 209 | user_table.user_begin<obby::user::NONE, false>(); |
| | 210 | iter != user_table.user_end<obby::user::NONE, false>(); |
| | 211 | ++ iter) |
| | 212 | add_user(*iter); |
| | 213 | } |
| | 214 | |
| | 215 | void Gobby::UserList::on_user_subscribe(const obby::user& user, |
| | 216 | obby::local_document_info& info) |
| | 217 | { |
| | 218 | // Not current doc |
| | 219 | if(&info != m_info) return; |
| | 220 | // Find user |
| | 221 | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| | 222 | // Update subscribed flag |
| | 223 | (*iter)[m_list_cols.subscribed] = true; |
| | 224 | } |
| | 225 | |
| | 226 | void Gobby::UserList::on_user_unsubscribe(const obby::user& user, |
| | 227 | obby::local_document_info& info) |
| | 228 | { |
| | 229 | // Not current doc |
| | 230 | if(&info != m_info) return; |
| | 231 | // Find user |
| | 232 | Gtk::TreeModel::iterator iter = find_user(user.get_name() ); |
| | 233 | // Update subscribed flag |
| | 234 | (*iter)[m_list_cols.subscribed] = false; |
| | 247 | void Gobby::UserList::add_user(const obby::user& user) |
| | 248 | { |
| | 249 | Gtk::TreeModel::Row row = *(m_list_data->append() ); |
| | 250 | |
| | 251 | unsigned int red = user.get_red(); |
| | 252 | unsigned int green = user.get_green(); |
| | 253 | unsigned int blue = user.get_blue(); |
| | 254 | |
| | 255 | row[m_list_cols.name] = user.get_name(); |
| | 256 | row[m_list_cols.colour] = create_coloured_pixbuf(red, green, blue); |
| | 257 | row[m_list_cols.connected] = true; |
| | 258 | |
| | 259 | if(m_info != NULL) |
| | 260 | row[m_list_cols.subscribed] = m_info->is_subscribed(user); |
| | 261 | } |
| | 262 | |
| | 263 | #if 0 |
| | 264 | Gobby::UserListSession::UserListSession(const Folder& folder) |
| | 265 | : UserList(folder) |
| | 266 | { |
| | 267 | set_sensitive(false); |
| | 268 | } |
| | 269 | |
| | 270 | Gobby::UserListSession::~UserListSession() |
| | 271 | { |
| | 272 | } |
| | 273 | |
| | 274 | void Gobby::UserListSession::obby_start(obby::local_buffer& buf) |
| | 275 | { |
| | 276 | } |
| | 277 | |
| | 278 | void Gobby::UserListSession::obby_end() |
| | 279 | { |
| | 280 | } |
| | 281 | |
| | 282 | void Gobby::UserListSession::obby_user_join(obby::user& user) |
| | 283 | { |
| | 284 | Gtk::TreeModel::Row row = *(m_list_data->append() ); |
| | 285 | |
| | 286 | unsigned int red = user.get_red(); |
| | 287 | unsigned int green = user.get_green(); |
| | 288 | unsigned int blue = user.get_blue(); |
| | 289 | |
| | 290 | row[m_list_cols.name] = user.get_name(); |
| | 291 | row[m_list_cols.connected] = true; |
| | 292 | row[m_list_cols.color] = create_coloured_pixbuf(red, green, blue); |
| | 293 | } |
| | 294 | |
| | 295 | void Gobby::UserListSession::obby_user_part(obby::user& user) |
| | 296 | { |
| | 297 | Gtk::TreeModel::iterator iter = m_list_data->children().begin(); |
| | 298 | (*iter)[m_list_cols.connected] = false; |
| | 299 | } |
| | 300 | |
| | 301 | Gobby::UserListDocument::UserListDocument(const Folder& folder) |
| | 302 | : UserList(folder), m_info(NULL) |
| | 303 | { |
| | 304 | |
| | 305 | // Show subscribed users, not connected ones |
| | 306 | m_list_view.get_column(1)->set_title("Subscribed"); |
| | 307 | set_sensitive(false); |
| | 308 | } |
| | 309 | |
| | 310 | Gobby::UserListDocument::~UserListDocument() |
| | 311 | { |
| | 312 | } |
| | 313 | |
| | 314 | void Gobby::UserListDocument::obby_start(obby::local_buffer& buf) |
| | 315 | { |
| | 316 | } |
| | 317 | |
| | 318 | void Gobby::UserListDocument::obby_end() |
| | 319 | { |
| | 320 | m_info = NULL; |
| | 321 | m_list_data->clear(); |
| | 322 | m_list_view.get_column(2)->set_visible(false); |
| | 323 | set_sensitive(false); |
| | 324 | } |
| | 325 | |
| | 326 | void Gobby::UserListDocument::obby_user_join(obby::user& user) |
| | 327 | { |
| | 328 | // Are there open documents? So add the user. |
| | 329 | if(m_info) |
| | 330 | add_user(user); |
| | 331 | { |
| | 332 | } |
| | 333 | } |
| | 334 | |
| | 335 | void Gobby::UserListDocument::obby_user_part(obby::user& user) |
| | 336 | { |
| | 337 | } |
| | 338 | |
| | 339 | void Gobby::UserListDocument::obby_document_insert( |
| | 340 | obby::local_document_info& info |
| | 341 | ) |
| | 342 | { |
| | 343 | |
| | 344 | // There is at least one document: Enable widget |
| | 345 | set_sensitive(true); |
| | 346 | } |
| | 347 | |
| | 348 | void Gobby::UserListDocument::obby_document_remove( |
| | 349 | obby::local_document_info& info |
| | 350 | ) |
| | 351 | { |
| | 352 | // Is this the last document that gets removed? |
| | 353 | if(info.get_buffer().document_count() == 1) |
| | 354 | { |
| | 355 | m_info = NULL; |
| | 356 | // Hide subcription column |
| | 357 | m_list_view.get_column(2)->set_visible(false); |
| | 358 | } |
| | 359 | } |
| | 360 | #endif |