Changeset 97 for Mulberry/branches/v4.1d1/MacOS/Sources/Application/Address_Book_Manager/CAdbkManagerTable.cp
- Timestamp:
- 07/09/07 22:13:35 (1 year ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
Mulberry/branches/v4.1d1/MacOS/Sources/Application/Address_Book_Manager/CAdbkManagerTable.cp
r74 r97 24 24 #include "CAdbkManagerWindow.h" 25 25 #include "CAdbkProtocol.h" 26 #include "CAddressBook Doc.h"26 #include "CAddressBook.h" 27 27 #include "CAddressBookManager.h" 28 28 #include "CAddressBookWindow.h" … … 31 31 #include "CCommands.h" 32 32 #include "CMessage.h" 33 #include "CRemoteAddressBook.h"34 33 #include "CResources.h" 35 34 #include "CPreferences.h" … … 82 81 mListChanging = false; 83 82 mHierarchyCol = 0; 84 mHasOthers = false;85 83 } 86 84 … … 184 182 break; 185 183 186 case cmd_LogonAddressBook: 187 OnLoginAddressBook(); 188 break; 189 190 case cmd_LogoffAddressBook: 191 OnLogoutAddressBook(); 184 case cmd_ToolbarServerLoginBtn: 185 OnLogin(); 192 186 break; 193 187 … … 267 261 { 268 262 outEnabled = (inCommand == cmd_NewAddressBook) ? false : 269 ! mHasOthers && !CAdminLock::sAdminLock.mNoLocalAdbks;263 !CAdminLock::sAdminLock.mNoLocalAdbks; 270 264 } 271 265 else … … 274 268 275 269 // These can only have logged on protocol selection 276 case cmd_LogonAddressBook: 277 if (IsSingleSelection()) 278 { 279 STableCell aCell(0,0); 280 GetNextSelectedCell(aCell); 281 CAdbkProtocol* proto = GetCellAdbkProtocol(aCell.row); 282 outEnabled = ((proto != NULL) && !proto->IsLoggedOn()); 270 case cmd_ToolbarServerLoginBtn: 271 // Logon button must have single server selected 272 if (IsSingleSelection() && TestSelectionAnd((TestSelectionPP) &CAdbkManagerTable::TestSelectionServer)) 273 { 274 TableIndexT row = GetFirstSelectedRow(); 275 CAddressBook* adbk = GetCellNode(row); 276 277 // Policy: 278 // 279 // 1. Local protocols are always logged in - login button is disabled 280 // 2. Protocols that cannot disconnect 281 // 2.1 maintain their own logged in state when global connect state is on, 282 // 2.2 else they are always logged out when global state is disconnected and the login button is disabled 283 // 3. Protocols that can disconnect 284 // 3.1 when global connect state is on, they maintain their own logged in state based on disconnected state 285 // 3.3 else they are always logged in and the login button is disabled 286 287 // 1. (as above) 288 if (adbk->GetProtocol()->IsOffline() && !adbk->GetProtocol()->IsDisconnected()) 289 { 290 // Local items are always logged in (connected) so disable the button 291 outEnabled = false; 292 outUsesMark = true; 293 ::GetIndString(outName, STRx_Standards, str_Logoff); 294 } 295 296 // 2. (as above) 297 else if (!adbk->GetProtocol()->CanDisconnect()) 298 { 299 // 2.1 (as above) 300 if (CConnectionManager::sConnectionManager.IsConnected()) 301 { 302 outEnabled = true; 303 outUsesMark = true; 304 outMark = adbk->GetProtocol()->IsLoggedOn() ? checkMark : noMark; 305 ::GetIndString(outName, STRx_Standards, !outMark ? str_Logon : str_Logoff); 306 } 307 // 2.2 (as above) 308 else 309 { 310 outEnabled = false; 311 outUsesMark = true; 312 ::GetIndString(outName, STRx_Standards, str_Logoff); 313 } 314 } 315 316 // 3. (as above) 317 else 318 { 319 // 3.1 (as above) 320 if (CConnectionManager::sConnectionManager.IsConnected()) 321 { 322 outEnabled = true; 323 outUsesMark = true; 324 outMark = !adbk->GetProtocol()->IsDisconnected() ? checkMark : noMark; 325 ::GetIndString(outName, STRx_Standards, !outMark ? str_Logon : str_Logoff); 326 } 327 // 3.2 (as above) 328 else 329 { 330 outEnabled = false; 331 outUsesMark = true; 332 ::GetIndString(outName, STRx_Standards, str_Logoff); 333 } 334 } 283 335 } 284 336 else 337 { 285 338 outEnabled = false; 339 outUsesMark = false; 340 ::GetIndString(outName, STRx_Standards, str_Logon); 341 } 286 342 break; 287 343 288 344 // These can only have logged off protocol selection 289 345 case cmd_RefreshAddressBook: 290 case cmd_LogoffAddressBook: 291 if (IsSingleSelection()) 292 { 293 STableCell aCell(0,0); 294 GetNextSelectedCell(aCell); 295 CAdbkProtocol* proto = GetCellAdbkProtocol(aCell.row); 296 outEnabled = ((proto != NULL) && proto->IsLoggedOn()); 297 } 298 else 299 outEnabled = false; 346 // Only if single selection; 347 outEnabled = IsSingleSelection(); 300 348 break; 301 349 … … 325 373 TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row + TABLE_ROW_ADJUST); 326 374 327 CAd bkList::node_type* node= GetCellNode(inCell.row);375 CAddressBook* adbk = GetCellNode(inCell.row); 328 376 329 377 // Do status flag 330 if (!inMouseDown.delaySelect && node->IsSelectable())378 if (!inMouseDown.delaySelect && adbk->IsAdbk()) 331 379 { 332 380 bool set; … … 334 382 { 335 383 case eAdbkColumnOpen: 336 set = ! node->GetSelectData()->IsOpenOnStart();337 node->GetSelectData()->SetFlags(CAddressBook::eOpenOnStart, set);338 CAddressBookManager::sAddressBookManager->SyncAddressBook( node->GetSelectData(), set);384 set = !adbk->IsOpenOnStart(); 385 adbk->SetFlags(CAddressBook::eOpenOnStart, set); 386 CAddressBookManager::sAddressBookManager->SyncAddressBook(adbk, set); 339 387 340 388 // Change prefs list 341 CPreferences::sPrefs->ChangeAddressBookOpenOnStart( node->GetSelectData(), set);389 CPreferences::sPrefs->ChangeAddressBookOpenOnStart(adbk, set); 342 390 break; 343 391 344 392 case eAdbkColumnResolve: 345 set = ! node->GetSelectData()->IsLookup();346 node->GetSelectData()->SetFlags(CAddressBook::eLookup, set);347 CAddressBookManager::sAddressBookManager->SyncAddressBook( node->GetSelectData(), set);393 set = !adbk->IsLookup(); 394 adbk->SetFlags(CAddressBook::eLookup, set); 395 CAddressBookManager::sAddressBookManager->SyncAddressBook(adbk, set); 348 396 349 397 // Change prefs list 350 CPreferences::sPrefs->ChangeAddressBookLookup( node->GetSelectData(), set);398 CPreferences::sPrefs->ChangeAddressBookLookup(adbk, set); 351 399 break; 352 400 353 401 case eAdbkColumnSearch: 354 set = ! node->GetSelectData()->IsSearch();355 node->GetSelectData()->SetFlags(CAddressBook::eSearch, set);356 CAddressBookManager::sAddressBookManager->SyncAddressBook( node->GetSelectData(), set);402 set = !adbk->IsSearch(); 403 adbk->SetFlags(CAddressBook::eSearch, set); 404 CAddressBookManager::sAddressBookManager->SyncAddressBook(adbk, set); 357 405 358 406 // Change prefs list 359 CPreferences::sPrefs->ChangeAddressBookSearch( node->GetSelectData(), set);407 CPreferences::sPrefs->ChangeAddressBookSearch(adbk, set); 360 408 break; 361 409 } … … 389 437 if (GetCellHitBy(imagePt, hitCell)) 390 438 { 391 CAd bkList::node_type* node= GetCellNode(hitCell.row);392 if ((hitCell.col == mHierarchyCol) && UsesBackgroundColor( node))439 CAddressBook* adbk = GetCellNode(hitCell.row); 440 if ((hitCell.col == mHierarchyCol) && UsesBackgroundColor(hitCell)) 393 441 { 394 442 FocusDraw(); 395 443 ApplyForeAndBackColors(); 396 ::RGBBackColor(&GetBackgroundColor( node));444 ::RGBBackColor(&GetBackgroundColor(hitCell)); 397 445 } 398 446 } … … 411 459 TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row + TABLE_ROW_ADJUST); 412 460 413 CAd bkList::node_type* node= GetCellNode(inCell.row);461 CAddressBook* adbk = GetCellNode(inCell.row); 414 462 415 463 // Save text state in stack object … … 432 480 // Erase to ensure drag hightlight is overwritten 433 481 FocusDraw(); 434 if (UsesBackgroundColor( node))482 if (UsesBackgroundColor(inCell)) 435 483 { 436 484 Rect greyer = inLocalRect; 437 485 greyer.bottom = greyer.top + 1; 438 486 ::EraseRect(&greyer); 439 ::RGBBackColor(&GetBackgroundColor( node));487 ::RGBBackColor(&GetBackgroundColor(inCell)); 440 488 greyer = inLocalRect; 441 489 greyer.top++; … … 459 507 DrawDropFlag(inCell, woRow); 460 508 461 #if PP_Target_Carbon462 509 // Draw selection 463 510 bool selected_state = DrawCellSelection(inCell); 464 #else465 bool selected_state = false;466 #endif467 511 468 512 UInt32 nestingLevel = mCollapsableTree->GetNestingLevel(woRow); … … 472 516 iconRect.bottom = inLocalRect.bottom - mIconDescent; 473 517 iconRect.top = iconRect.bottom - 16; 474 ::Ploticns(&iconRect, atNone, selected_state ? ttSelected : ttNone, GetPlotIcon( node, GetCellAdbkProtocol(inCell.row)));518 ::Ploticns(&iconRect, atNone, selected_state ? ttSelected : ttNone, GetPlotIcon(adbk, GetCellAdbkProtocol(inCell.row))); 475 519 476 520 // Get name of item 477 theTxt = node->IsSelectable() ? node->GetSelectData()->GetName() : *node->GetNoSelectData(); 521 theTxt = adbk->GetShortName(); 522 523 // Add protocol state descriptor 524 if (adbk->IsProtocol()) 525 { 526 if (adbk->GetProtocol()->IsDisconnected() && !CConnectionManager::sConnectionManager.IsConnected()) 527 { 528 theTxt.AppendResource("UI::Server::TitleDisconnected"); 529 } 530 else if (adbk->GetProtocol()->IsDisconnected() || !adbk->GetProtocol()->IsOffline() && !adbk->GetProtocol()->IsLoggedOn()) 531 { 532 theTxt.AppendResource("UI::Server::TitleOffline"); 533 } 534 } 478 535 479 536 // Draw the string 480 537 bool strike = false; 481 SetTextStyle( node, GetCellAdbkProtocol(inCell.row), strike);538 SetTextStyle(adbk, GetCellAdbkProtocol(inCell.row), strike); 482 539 ::MoveTo(iconRect.right - 2, inLocalRect.bottom - mTextDescent); 483 540 ::DrawClippedStringUTF8(theTxt, inLocalRect.right - iconRect.right - 2, eDrawString_Left); … … 501 558 502 559 // Do status flag 503 if ( node->IsSelectable())560 if (adbk->IsAdbk()) 504 561 { 505 562 bool ticked = false; … … 507 564 { 508 565 case eAdbkColumnOpen: 509 ticked = node->GetSelectData()->IsOpenOnStart();566 ticked = adbk->IsOpenOnStart(); 510 567 break; 511 568 case eAdbkColumnResolve: 512 ticked = node->GetSelectData()->IsLookup();569 ticked = adbk->IsLookup(); 513 570 break; 514 571 case eAdbkColumnSearch: 515 ticked = node->GetSelectData()->IsSearch();572 ticked = adbk->IsSearch(); 516 573 break; 517 574 } … … 566 623 567 624 // Get appropriate icon id 568 ResIDT CAdbkManagerTable::GetPlotIcon(const CAd bkList::node_type* node, CAdbkProtocol* proto)569 { 570 if ( !node->IsSelectable())625 ResIDT CAdbkManagerTable::GetPlotIcon(const CAddressBook* adbk, CAdbkProtocol* proto) 626 { 627 if (adbk->IsProtocol()) 571 628 { 572 629 if (!proto) … … 580 637 return ICNx_BrowseRemoteHierarchy; 581 638 } 639 else if (adbk->IsDirectory() && !adbk->IsAdbk()) 640 { 641 return ICNx_BrowseDirectory; 642 } 582 643 else 583 644 { 584 const CRemoteAddressBook* adbk = dynamic_cast<const CRemoteAddressBook*>(node->GetSelectData()); 585 if (adbk && adbk->GetProtocol()->CanDisconnect() && adbk->IsLocalAdbk()) 586 return adbk->IsCachedAdbk() ? ICNx_AddressBookCached : ICNx_AddressBookUncached; 587 else 588 return ICNx_AddressBook; 645 return adbk->IsCached() ? ICNx_AddressBook : ICNx_AddressBookUncached; 589 646 } 590 647 } 591 648 592 649 // Get text style 593 void CAdbkManagerTable::SetTextStyle(const CAd bkList::node_type* node, CAdbkProtocol* proto, bool& strike)650 void CAdbkManagerTable::SetTextStyle(const CAddressBook* adbk, CAdbkProtocol* proto, bool& strike) 594 651 { 595 652 strike = false; … … 598 655 if (UEnvironment::HasFeature(env_SupportsColor)) 599 656 { 600 if ( !node->IsSelectable())657 if (adbk->IsProtocol()) 601 658 { 602 659 bool color_set = false; … … 639 696 } 640 697 641 bool CAdbkManagerTable::UsesBackgroundColor(const CAdbkList::node_type* node) const 642 { 643 return !node->IsSelectable(); 644 } 645 646 const RGBColor& CAdbkManagerTable::GetBackgroundColor(const CAdbkList::node_type* node) const 698 bool CAdbkManagerTable::UsesBackgroundColor(const STableCell &inCell) const 699 { 700 TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row); 701 return mCollapsableTree->GetNestingLevel(woRow) == 0; 702 } 703 704 const RGBColor& CAdbkManagerTable::GetBackgroundColor(const STableCell &inCell) const 647 705 { 648 706 return CPreferences::sPrefs->mServerBkgndStyle.GetValue().color; 649 }650 651 void CAdbkManagerTable::DoSelectionChanged()652 {653 CHierarchyTableDrag::DoSelectionChanged();654 655 // Determine whether preview is triggered656 const CUserAction& preview = mTableView->GetPreviewAction();657 if (preview.GetSelection())658 DoPreview();659 660 // Determine whether full view is triggered661 const CUserAction& fullview = mTableView->GetFullViewAction();662 if (fullview.GetSelection())663 DoFullView();664 }665 666 // Handle single click667 void CAdbkManagerTable::DoSingleClick(unsigned long row, const CKeyModifiers& mods)668 {669 // Determine whether preview is triggered670 const CUserAction& preview = mTableView->GetPreviewAction();671 if (preview.GetSingleClick() &&672 (preview.GetSingleClickModifiers() == mods))673 DoPreview();674 675 // Determine whether full view is triggered676 const CUserAction& fullview = mTableView->GetFullViewAction();677 if (fullview.GetSingleClick() &&678 (fullview.GetSingleClickModifiers() == mods))679 DoFullView();680 }681 682 // Handle double click683 void CAdbkManagerTable::DoDoubleClick(unsigned long row, const CKeyModifiers& mods)684 {685 // Determine whether preview is triggered686 const CUserAction& preview = mTableView->GetPreviewAction();687 if (preview.GetDoubleClick() &&688 (preview.GetDoubleClickModifiers() == mods))689 DoPreview();690 691 // Determine whether full view is triggered692 const CUserAction& fullview = mTableView->GetFullViewAction();693 if (fullview.GetDoubleClick() &&694 (fullview.GetDoubleClickModifiers() == mods))695 DoFullView();696 }697 698 void CAdbkManagerTable::DoPreview()699 {700 PreviewAddressBook();701 }702 703 void CAdbkManagerTable::DoPreview(CAddressBook* adbk)704 {705 PreviewAddressBook(adbk);706 }707 708 // Just edit the item709 void CAdbkManagerTable::DoFullView()710 {711 OnOpenAddressBook();712 }713 714 // Reset the table715 void CAdbkManagerTable::ResetTable()716 {717 // Start cursor for busy operation718 CWaitCursor wait;719 720 // Delete all existing rows721 Clear();722 mHierarchyCol = 1;723 mData.clear();724 725 // Only if we have the manager726 if (!mManager)727 return;728 729 // Get list from manager730 const CAdbkList& adbks = mManager->GetAddressBooks();731 732 // Add each node733 TableIndexT row = 0;734 TableIndexT exp_row = 1;735 mHasOthers = true;736 ulvector expand_rows;737 for(CAdbkList::node_list::const_iterator iter = adbks.GetChildren()->begin();738 iter != adbks.GetChildren()->end(); iter++)739 {740 // Don't add empty first row741 if ((iter != adbks.GetChildren()->begin()) || (*iter)->CountChildren())742 {743 AddNode(*iter, row, false);744 745 // Listen to each protocol746 CAdbkProtocol* proto = GetCellAdbkProtocol(exp_row);747 if (proto)748 proto->Add_Listener(this);749 750 // Check expansion - always expand if pure local address account751 if (!proto || proto->GetAddressAccount()->GetExpanded())752 {753 // Add wide open row to expansion list which gets processed later754 TableIndexT woRow = GetWideOpenIndex(exp_row + TABLE_ROW_ADJUST);755 expand_rows.push_back(woRow);756 }757 758 // Bump up exposed row counter759 exp_row++;760 }761 else762 mHasOthers = false;763 }764 765 // Do expansions766 if (expand_rows.size())767 {768 for(ulvector::const_iterator iter = expand_rows.begin(); iter != expand_rows.end(); iter++)769 ExpandRow(*iter);770 }771 772 // Always expand a single account773 else if (exp_row == 2)774 ExpandRow(1);775 776 // Refresh list777 Refresh();778 779 // Force toolbar update780 mTableView->RefreshToolbar();781 782 } // CAdbkManagerTable::ResetTable783 784 // Reset the table from the mboxList785 void CAdbkManagerTable::ClearTable()786 {787 // Delete all existing rows788 Clear();789 mData.clear();790 791 // Refresh list792 Refresh();793 794 // Force toolbar update795 mTableView->RefreshToolbar();796 707 } 797 708 … … 805 716 } 806 717 807 // Remove rows and adjust parts808 void CAdbkManagerTable::RemoveRows(UInt32 inHowMany, TableIndexT inFromRow, Boolean inRefresh)809 {810 // Count number to remove (this + descendents)811 UInt32 remove_count = CountAllDescendents(inFromRow) + 1;812 813 // Do standard removal814 CHierarchyTableDrag::RemoveRows(inHowMany, inFromRow, inRefresh);815 816 // Remove our data using count817 mData.erase(mData.begin() + (inFromRow - 1), mData.begin() + (inFromRow - 1 + remove_count));818 }819 820 // Get the selected adbk821 void* CAdbkManagerTable::GetCellData(TableIndexT woRow)822 {823 return mData.at(woRow - 1);824 }825 826 718 // Adjust cursor over drop area 827 719 bool CAdbkManagerTable::IsCopyCursor(DragReference inDragRef) … … 833 725 bool CAdbkManagerTable::IsDropCell(DragReference inDragRef, STableCell theCell) 834 726 { 835 return IsValidCell(theCell) && IsCellAdbk(theCell.row); 727 CAddressBook* adbk = GetCellNode(theCell.row); 728 return IsValidCell(theCell) && adbk->IsAdbk(); 836 729 } 837 730 … … 843 736 mDropSort = false; 844 737 mDropAdbk = NULL; 845 mDropRemoteAdbk = NULL;846 738 mDropAdbkWnd = NULL; 847 739 mAddressAdded = false; … … 863 755 if (mDropAdbkWnd) 864 756 mDropAdbkWnd->GetAddressBookView()->ResetTable(); 865 866 // Always reset if remote was opened 867 if (mDropRemoteAdbk) 868 { 869 mDropRemoteAdbk->GetProtocol()->CloseAdbk(mDropRemoteAdbk); 870 mDropRemoteAdbk->Clear(); 871 mDropRemoteAdbk->SetFlags(CAddressBook::eLoaded, false); 872 mDropRemoteAdbk = NULL; 873 } 757 mDropAdbk = NULL; 874 758 } 875 759 … … 881 765 { 882 766 // Determine adbk to use for copy 883 mDropAdbk = GetCell Adbk(theCell.row);767 mDropAdbk = GetCellNode(theCell.row); 884 768 885 769 // Does window already exist? 886 770 mDropAdbkWnd = CAddressBookWindow::FindWindow(mDropAdbk); <887 771 mDropSort = (mDropAdbkWnd != NULL);