| | 64 | |
| | 65 | // Set the address book manager |
| | 66 | void CAdbkManagerTable::SetManager(CAddressBookManager* manager) |
| | 67 | { |
| | 68 | // Save server |
| | 69 | mManager = manager; |
| | 70 | |
| | 71 | if (mManager) |
| | 72 | { |
| | 73 | mManager->Add_Listener(this); |
| | 74 | |
| | 75 | // Make sure its open so items will actually be displayed |
| | 76 | mTableView->SetOpen(); |
| | 77 | |
| | 78 | // Calculate number of rows for first time |
| | 79 | ResetTable(); |
| | 80 | } |
| | 81 | } |
| | 82 | |
| | 83 | // Reset the table |
| | 84 | void CAdbkManagerTable::ResetTable() |
| | 85 | { |
| | 86 | // Start cursor for busy operation |
| | 87 | CWaitCursor wait; |
| | 88 | |
| | 89 | // Delete all existing rows |
| | 90 | Clear(); |
| | 91 | mHierarchyCol = 1; |
| | 92 | mData.clear(); |
| | 93 | |
| | 94 | // Only if we have the manager |
| | 95 | if (!mManager) |
| | 96 | return; |
| | 97 | |
| | 98 | // Get list from manager |
| | 99 | const CAddressBookList& nodes = mManager->GetNodes(); |
| | 100 | |
| | 101 | // Add each node |
| | 102 | TableIndexT row = 0; |
| | 103 | TableIndexT exp_row = 1; |
| | 104 | for(CAddressBookList::const_iterator iter = nodes.begin(); iter != nodes.end(); iter++) |
| | 105 | { |
| | 106 | AddNode(*iter, row, false); |
| | 107 | |
| | 108 | // Listen to each protocol |
| | 109 | CAdbkProtocol* proto = (*iter)->GetProtocol(); |
| | 110 | if (proto) |
| | 111 | proto->Add_Listener(this); |
| | 112 | |
| | 113 | // Bump up exposed row counter |
| | 114 | exp_row++; |
| | 115 | } |
| | 116 | |
| | 117 | // Always expand a single account |
| | 118 | if (exp_row == 2) |
| | 119 | ExpandRow(1); |
| | 120 | |
| | 121 | // Refresh list |
| | 122 | FRAMEWORK_REFRESH_WINDOW(this) |
| | 123 | |
| | 124 | // Force toolbar update |
| | 125 | mTableView->RefreshToolbar(); |
| | 126 | |
| | 127 | } |
| | 128 | |
| | 129 | // Reset the table from the mboxList |
| | 130 | void CAdbkManagerTable::ClearTable() |
| | 131 | { |
| | 132 | // Delete all existing rows |
| | 133 | Clear(); |
| | 134 | mData.clear(); |
| | 135 | |
| | 136 | // Refresh list |
| | 137 | FRAMEWORK_REFRESH_WINDOW(this) |
| | 138 | |
| | 139 | // Force toolbar update |
| | 140 | mTableView->RefreshToolbar(); |
| | 141 | } |
| 88 | | } |
| 89 | | } |
| 90 | | |
| 91 | | // Test for selected adbk |
| 92 | | bool CAdbkManagerTable::TestSelectionAdbk(TableIndexT row) |
| 93 | | { |
| 94 | | // This is an adbk |
| 95 | | return IsCellAdbk(row); |
| 96 | | } |
| 97 | | |
| 98 | | // Test for selected adbk |
| 99 | | bool CAdbkManagerTable::TestSelectionAdbkDisconnected(TableIndexT row) |
| 100 | | { |
| 101 | | // This is an adbk |
| 102 | | if (IsCellAdbk(row)) |
| 103 | | { |
| 104 | | CRemoteAddressBook* adbk = dynamic_cast<CRemoteAddressBook*>(GetCellAdbk(row)); |
| 105 | | |
| 106 | | return adbk && adbk->GetProtocol()->CanDisconnect() && !adbk->GetProtocol()->IsDisconnected(); |
| 107 | | } |
| 108 | | |
| 109 | | return false; |
| 110 | | } |
| 111 | | |
| 112 | | // Test for selected adbk |
| 113 | | bool CAdbkManagerTable::TestSelectionAdbkClearDisconnected(TableIndexT row) |
| 114 | | { |
| 115 | | // This is an adbk |
| 116 | | if (IsCellAdbk(row)) |
| 117 | | { |
| 118 | | CRemoteAddressBook* adbk = dynamic_cast<CRemoteAddressBook*>(GetCellAdbk(row)); |
| 119 | | |
| 120 | | return adbk && adbk->GetProtocol()->CanDisconnect(); |
| 121 | | } |
| 122 | | |
| 123 | | return false; |
| 124 | | } |
| 125 | | |
| 126 | | // Set the address book manager |
| 127 | | void CAdbkManagerTable::SetManager(CAddressBookManager* manager) |
| 128 | | { |
| 129 | | // Save server |
| 130 | | mManager = manager; |
| 131 | | |
| 132 | | if (mManager) |
| 133 | | { |
| 134 | | mManager->Add_Listener(this); |
| 135 | | |
| 136 | | // Make sure its open so items will actually be displayed |
| 137 | | mTableView->SetOpen(); |
| 138 | | |
| 139 | | // Calculate number of rows for first time |
| 140 | | ResetTable(); |
| 141 | | } |
| | 169 | case CAdbkProtocol::eBroadcast_ClearSubList: |
| | 170 | ClearSubList(static_cast<CAddressBook*>(param)); |
| | 171 | break; |
| | 172 | case CAdbkProtocol::eBroadcast_RefreshSubList: |
| | 173 | RefreshSubList(static_cast<CAddressBook*>(param)); |
| | 174 | break; |
| | 175 | case CAddressBookManager::eBroadcast_InsertNode: |
| | 176 | InsertNode(static_cast<CAddressBook*>(param)); |
| | 177 | break; |
| | 178 | case CAddressBookManager::eBroadcast_RemoveNode: |
| | 179 | case CAddressBookManager::eBroadcast_DeleteNode: |
| | 180 | DeleteNode(static_cast<CAddressBook*>(param)); |
| | 181 | break; |
| | 182 | case CAdbkProtocol::eBroadcast_RefreshNode: |
| | 183 | RefreshNode(static_cast<CAddressBook*>(param)); |
| | 184 | break; |
| | 185 | } |
| | 186 | } |
| | 187 | |
| | 188 | void CAdbkManagerTable::DoSelectionChanged() |
| | 189 | { |
| | 190 | CHierarchyTableDrag::DoSelectionChanged(); |
| | 191 | |
| | 192 | // Determine whether preview is triggered |
| | 193 | const CUserAction& preview = mTableView->GetPreviewAction(); |
| | 194 | if (preview.GetSelection()) |
| | 195 | DoPreview(); |
| | 196 | |
| | 197 | // Determine whether full view is triggered |
| | 198 | const CUserAction& fullview = mTableView->GetFullViewAction(); |
| | 199 | if (fullview.GetSelection()) |
| | 200 | DoFullView(); |
| | 201 | } |
| | 202 | |
| | 203 | // Handle single click |
| | 204 | void CAdbkManagerTable::DoSingleClick(unsigned long row, const CKeyModifiers& mods) |
| | 205 | { |
| | 206 | // Determine whether preview is triggered |
| | 207 | const CUserAction& preview = mTableView->GetPreviewAction(); |
| | 208 | if (preview.GetSingleClick() && |
| | 209 | (preview.GetSingleClickModifiers() == mods)) |
| | 210 | DoPreview(); |
| | 211 | |
| | 212 | // Determine whether full view is triggered |
| | 213 | const CUserAction& fullview = mTableView->GetFullViewAction(); |
| | 214 | if (fullview.GetSingleClick() && |
| | 215 | (fullview.GetSingleClickModifiers() == mods)) |
| | 216 | DoFullView(); |
| | 217 | } |
| | 218 | |
| | 219 | // Handle double click |
| | 220 | void CAdbkManagerTable::DoDoubleClick(unsigned long row, const CKeyModifiers& mods) |
| | 221 | { |
| | 222 | // Determine whether preview is triggered |
| | 223 | const CUserAction& preview = mTableView->GetPreviewAction(); |
| | 224 | if (preview.GetDoubleClick() && |
| | 225 | (preview.GetDoubleClickModifiers() == mods)) |
| | 226 | DoPreview(); |
| | 227 | |
| | 228 | // Determine whether full view is triggered |
| | 229 | const CUserAction& fullview = mTableView->GetFullViewAction(); |
| | 230 | if (fullview.GetDoubleClick() && |
| | 231 | (fullview.GetDoubleClickModifiers() == mods)) |
| | 232 | DoFullView(); |
| | 233 | } |
| | 234 | |
| | 235 | void CAdbkManagerTable::DoPreview() |
| | 236 | { |
| | 237 | PreviewAddressBook(); |
| | 238 | } |
| | 239 | |
| | 240 | void CAdbkManagerTable::DoPreview(CAddressBook* adbk) |
| | 241 | { |
| | 242 | PreviewAddressBook(adbk); |
| | 243 | } |
| | 244 | |
| | 245 | // Just edit the item |
| | 246 | void CAdbkManagerTable::DoFullView() |
| | 247 | { |
| | 248 | OnOpenAddressBook(); |
| | 430 | void CAdbkManagerTable::OnLogin() |
| | 431 | { |
| | 432 | // Must have single selected protocol |
| | 433 | if (!IsSingleSelection()) |
| | 434 | return; |
| | 435 | |
| | 436 | TableIndexT row = GetFirstSelectedRow(); |
| | 437 | CAddressBook* adbk = GetCellNode(row); |
| | 438 | |
| | 439 | if (!adbk->IsProtocol()) |
| | 440 | return; |
| | 441 | |
| | 442 | // Policy: |
| | 443 | // |
| | 444 | // 1. Local protocols are always logged in |
| | 445 | // 2. Protocols that cannot disconnect |
| | 446 | // 2.1 can change login state only when global state is connected |
| | 447 | // 2.2 are always logged out when global state is disconnected |
| | 448 | // 3. Protocols that can disconnect |
| | 449 | // 3.1 can change login/disconnect state when global state is connected |
| | 450 | // 3.1 are always logged in when global state is disconnected |
| | 451 | |
| | 452 | // 1. (as above) |
| | 453 | if (adbk->GetProtocol()->IsOffline() && !adbk->GetProtocol()->IsDisconnected()) |
| | 454 | { |
| | 455 | // Ignore - should already be in logged in state |
| | 456 | return; |
| | 457 | } |
| | 458 | |
| | 459 | // 2. (as above) |
| | 460 | else if (!adbk->GetProtocol()->CanDisconnect()) |
| | 461 | { |
| | 462 | // 2.1 (as above) |
| | 463 | if (CConnectionManager::sConnectionManager.IsConnected()) |
| | 464 | { |
| | 465 | // Toggle login state |
| | 466 | if (adbk->GetProtocol()->IsLoggedOn()) |
| | 467 | { |
| | 468 | mManager->StopProtocol(adbk->GetProtocol()); |
| | 469 | } |
| | 470 | else |
| | 471 | { |
| | 472 | mManager->StartProtocol(adbk->GetProtocol()); |
| | 473 | } |
| | 474 | } |
| | 475 | // 2.2 (as above) |
| | 476 | else |
| | 477 | { |
| | 478 | // Ignore - should already be in logged out state |
| | 479 | return; |
| | 480 | } |
| | 481 | } |
| | 482 | |
| | 483 | // 3. (as above) |
| | 484 | else |
| | 485 | { |
| | 486 | // 3.1 (as above) |
| | 487 | if (CConnectionManager::sConnectionManager.IsConnected()) |
| | 488 | { |
| | 489 | // Toggle force disconnect state |
| | 490 | adbk->GetProtocol()->ForceDisconnect(!adbk->GetProtocol()->IsForceDisconnect()); |
| | 491 | } |
| | 492 | // 3.2 (as above) |
| | 493 | else |
| | 494 | { |
| | 495 | // Ignore - should already be in logged in state |
| | 496 | return; |
| | 497 | } |
| | 498 | } |
| | 499 | |
| | 500 | // Reset all views |
| | 501 | //CCalendarView::ResetAll(); |
| | 502 | } |
| | 503 | |
| 333 | | TableIndexT woRow = GetWideOpenIndex(row + TABLE_ROW_ADJUST); |
| 334 | | |
| 335 | | CAdbkList::node_type* node = (CAdbkList::node_type*) GetCellData(woRow); |
| 336 | | proto = GetCellAdbkProtocol(row); |
| 337 | | |
| 338 | | // If proto is null we have an address book - so get its protocol |
| | 520 | TableIndexT row = GetFirstSelectedRow(); |
| | 521 | TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(row); |
| | 522 | |
| | 523 | // First check logged in state of server - may come back as NULL if cabinet selected |
| | 524 | CAdbkProtocol* server = GetCellAdbkProtocol(row); |
| | 525 | node = GetCellNode(row); |
| | 526 | |
| | 527 | // If logged in then use current selection as reference point |
| | 528 | if (server && server->IsLoggedOn()) |
| | 529 | { |
| | 530 | proto = server; |
| | 531 | create.account = proto->GetAccountName(); |
| | 532 | |
| | 533 | if (node->IsProtocol()) |
| | 534 | { |
| | 535 | create.use_wd = false; |
| | 536 | } |
| | 537 | else if (node->IsDirectory()) |
| | 538 | { |
| | 539 | create.use_wd = true; |
| | 540 | create.parent = node->GetName(); |
| | 541 | } |
| | 542 | else |
| | 543 | { |
| | 544 | create.use_wd = false; |
| | 545 | } |
| | 546 | } |
| | 547 | else |
| | 548 | { |
| | 549 | // Force generic create |
| | 550 | create.use_wd = false; |
| | 551 | } |
| | 552 | } |
| | 553 | |
| | 554 | try |
| | 555 | { |
| | 556 | if (CCreateAdbkDialog::PoseDialog(&create)) |
| | 557 | { |
| | 558 | cdstring new_name; |
| | 559 | if (create.use_wd) |
| | 560 | { |
| | 561 | new_name = create.parent; |
| | 562 | if (node->GetProtocol()->GetDirDelim()) |
| | 563 | new_name += node->GetProtocol()->GetDirDelim(); |
| | 564 | new_name += create.name; |
| | 565 | } |
| | 566 | else |
| | 567 | new_name = create.name; |
| | 568 | |
| | 569 | // Check and get proto from dialog |
| 347 | | return; |
| 348 | | } |
| 349 | | |
| 350 | | // Get name for new address book |
| 351 | | CCreateAdbkDialog::SCreateAdbk details; |
| 352 | | details.personal = true; |
| 353 | | details.account = proto ? proto->GetAccountName() : cdstring::null_str; |
| 354 | | details.open_on_startup = true; |
| 355 | | details.use_nicknames = true; |
| 356 | | details.use_search = true; |
| 357 | | |
| 358 | | if (CCreateAdbkDialog::PoseDialog(&details)) |
| 359 | | { |
| 360 | | // Get the chosen protocol |
| 361 | | proto = mManager->GetProtocol(details.account); |
| 362 | | |
| 363 | | |
| 364 | | // never allow personal on local account |
| 365 | | if ((details.account == CPreferences::sPrefs->mLocalAdbkAccount.GetValue().GetName()) || |
| 366 | | (details.account == CPreferences::sPrefs->mOSAdbkAccount.GetValue().GetName())) |
| 367 | | details.personal = false; |
| 368 | | |
| 369 | | // Adjust name if required |
| 370 | | cdstring adbk_name = details.name; |
| 371 | | if (details.personal) |
| 372 | | { |
| 373 | | cdstring default_name = proto->GetUserPrefix(); |
| 374 | | default_name += proto->GetAccount()->GetAuthenticator().GetAuthenticator()->GetActualUID(); |
| 375 | | |
| 376 | | // Add user id to address book name |
| 377 | | adbk_name = default_name; |
| 378 | | adbk_name += proto->GetSeparator(); |
| 379 | | adbk_name += details.name; |
| 380 | | } |
| 381 | | |
| 382 | | CRemoteAddressBook* adbk = NULL; |
| 383 | | try |
| 384 | | { |
| | 573 | { |
| | 574 | CLOG_LOGTHROW(CGeneralException, -1); |
| | 575 | throw CGeneralException(-1); |
| | 576 | } |
| | 577 | |
| | 578 | CAddressBook* adbk = NULL; |
| | 579 | |
| 398 | | CPreferences::sPrefs->ChangeAddressBookOpenOnStart(adbk, details.open_on_startup); |
| 399 | | CPreferences::sPrefs->ChangeAddressBookLookup(adbk, details.use_nicknames); |
| 400 | | CPreferences::sPrefs->ChangeAddressBookSearch(adbk, details.use_search); |
| 401 | | |
| 402 | | // Update table |
| 403 | | |
| 404 | | // Always force table to logged off state |
| 405 | | int pos = 0; |
| 406 | | |
| 407 | | if (mManager->FindProtocol(proto, pos)) |
| 408 | | { |
| 409 | | TableIndexT temp = pos; |
| 410 | | CAdbkList::node_type* proto_node = (CAdbkList::node_type*) GetCellData(temp); |
| 411 | | |
| 412 | | // Iterate over all adbk manager windows |
| 413 | | cdmutexprotect<CAdbkManagerView::CAdbkManagerViewList>::lock _lock(CAdbkManagerView::sAdbkManagerViews); |
| 414 | | for(CAdbkManagerView::CAdbkManagerViewList::iterator iter = CAdbkManagerView::sAdbkManagerViews->begin(); iter != CAdbkManagerView::sAdbkManagerViews->end(); iter++) |
| 415 | | { |
| 416 | | (*iter)->GetTable()->RemoveChildren(temp, true); |
| 417 | | (*iter)->GetTable()->AddChildren(proto_node, temp, false); |
| 418 | | (*iter)->GetTable()->RefreshRow(row); |
| 419 | | (*iter)->GetTable()->RefreshRowsBelow(temp); |
| 420 | | } |
| | 592 | CPreferences::sPrefs->ChangeAddressBookOpenOnStart(adbk, create.open_on_startup); |
| | 593 | CPreferences::sPrefs->ChangeAddressBookLookup(adbk, create.use_nicknames); |
| | 594 | CPreferences::sPrefs->ChangeAddressBookSearch(adbk, create.use_search); |
| | 595 | } |
| | 596 | |
| | 597 | result = adbk; |