Show
Ignore:
Timestamp:
07/09/07 22:13:35 (1 year ago)
Author:
daboo
Message:

More v4.1 code. Includes experiment, though non-functioning WebKit? message
display option.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Mulberry/branches/v4.1d1/MacOS/Sources/Application/Address_Book_Manager/CAdbkManagerTable.cp

    <
    r74 r97  
    2424#include "CAdbkManagerWindow.h" 
    2525#include "CAdbkProtocol.h" 
    26 #include "CAddressBookDoc.h" 
     26#include "CAddressBook.h" 
    2727#include "CAddressBookManager.h" 
    2828#include "CAddressBookWindow.h" 
     
    3131#include "CCommands.h" 
    3232#include "CMessage.h" 
    33 #include "CRemoteAddressBook.h" 
    3433#include "CResources.h" 
    3534#include "CPreferences.h" 
     
    8281        mListChanging = false; 
    8382        mHierarchyCol = 0; 
    84         mHasOthers = false; 
    8583} 
    8684 
     
    184182                break; 
    185183 
    186         case cmd_LogonAddressBook: 
    187                 OnLoginAddressBook(); 
    188                 break; 
    189  
    190         case cmd_LogoffAddressBook: 
    191                 OnLogoutAddressBook(); 
     184        case cmd_ToolbarServerLoginBtn: 
     185                OnLogin(); 
    192186                break; 
    193187 
     
    267261                { 
    268262                        outEnabled = (inCommand == cmd_NewAddressBook) ? false : 
    269                                                         !mHasOthers && !CAdminLock::sAdminLock.mNoLocalAdbks; 
     263                                                        !CAdminLock::sAdminLock.mNoLocalAdbks; 
    270264                } 
    271265                else 
     
    274268 
    275269        // 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                        } 
    283335                } 
    284336                else 
     337                { 
    285338                        outEnabled = false; 
     339                        outUsesMark = false; 
     340                        ::GetIndString(outName, STRx_Standards, str_Logon); 
     341                } 
    286342                break; 
    287343 
    288344        // These can only have logged off protocol selection 
    289345        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(); 
    300348                break; 
    301349 
     
    325373                TableIndexT     woRow = mCollapsableTree->GetWideOpenIndex(inCell.row + TABLE_ROW_ADJUST); 
    326374 
    327                 CAdbkList::node_type* node = GetCellNode(inCell.row); 
     375                CAddressBook* adbk = GetCellNode(inCell.row); 
    328376 
    329377                // Do status flag 
    330                 if (!inMouseDown.delaySelect && node->IsSelectable()) 
     378                if (!inMouseDown.delaySelect && adbk->IsAdbk()) 
    331379                { 
    332380                        bool set; 
     
    334382                        { 
    335383                        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); 
    339387 
    340388                                // Change prefs list 
    341                                 CPreferences::sPrefs->ChangeAddressBookOpenOnStart(node->GetSelectData(), set); 
     389                                CPreferences::sPrefs->ChangeAddressBookOpenOnStart(adbk, set); 
    342390                                break; 
    343391 
    344392                        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); 
    348396 
    349397                                // Change prefs list 
    350                                 CPreferences::sPrefs->ChangeAddressBookLookup(node->GetSelectData(), set); 
     398                                CPreferences::sPrefs->ChangeAddressBookLookup(adbk, set); 
    351399                                break; 
    352400 
    353401                        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); 
    357405 
    358406                                // Change prefs list 
    359                                 CPreferences::sPrefs->ChangeAddressBookSearch(node->GetSelectData(), set); 
     407                                CPreferences::sPrefs->ChangeAddressBookSearch(adbk, set); 
    360408                                break; 
    361409                        } 
     
    389437        if (GetCellHitBy(imagePt, hitCell)) 
    390438        { 
    391                 CAdbkList::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)) 
    393441                { 
    394442                        FocusDraw(); 
    395443                        ApplyForeAndBackColors(); 
    396                         ::RGBBackColor(&GetBackgroundColor(node)); 
     444                        ::RGBBackColor(&GetBackgroundColor(hitCell)); 
    397445                } 
    398446        } 
     
    411459        TableIndexT     woRow = mCollapsableTree->GetWideOpenIndex(inCell.row + TABLE_ROW_ADJUST); 
    412460 
    413         CAdbkList::node_type* node = GetCellNode(inCell.row); 
     461        CAddressBook* adbk = GetCellNode(inCell.row); 
    414462 
    415463        // Save text state in stack object 
     
    432480        // Erase to ensure drag hightlight is overwritten 
    433481        FocusDraw(); 
    434         if (UsesBackgroundColor(node)) 
     482        if (UsesBackgroundColor(inCell)) 
    435483        { 
    436484                Rect greyer = inLocalRect; 
    437485                greyer.bottom = greyer.top + 1; 
    438486                ::EraseRect(&greyer); 
    439                 ::RGBBackColor(&GetBackgroundColor(node)); 
     487                ::RGBBackColor(&GetBackgroundColor(inCell)); 
    440488                greyer = inLocalRect; 
    441489                greyer.top++; 
     
    459507                DrawDropFlag(inCell, woRow); 
    460508 
    461 #if PP_Target_Carbon 
    462509                // Draw selection 
    463510                bool selected_state = DrawCellSelection(inCell); 
    464 #else 
    465                 bool selected_state = false; 
    466 #endif 
    467511 
    468512                UInt32  nestingLevel = mCollapsableTree->GetNestingLevel(woRow); 
     
    472516                iconRect.bottom = inLocalRect.bottom - mIconDescent; 
    473517                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))); 
    475519 
    476520                // 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                } 
    478535 
    479536                // Draw the string 
    480537                bool strike = false; 
    481                 SetTextStyle(node, GetCellAdbkProtocol(inCell.row), strike); 
     538                SetTextStyle(adbk, GetCellAdbkProtocol(inCell.row), strike); 
    482539                ::MoveTo(iconRect.right - 2, inLocalRect.bottom - mTextDescent); 
    483540                ::DrawClippedStringUTF8(theTxt, inLocalRect.right - iconRect.right - 2, eDrawString_Left); 
     
    501558 
    502559                // Do status flag 
    503                 if (node->IsSelectable()) 
     560                if (adbk->IsAdbk()) 
    504561                { 
    505562                        bool ticked = false; 
     
    507564                        { 
    508565                        case eAdbkColumnOpen: 
    509                                 ticked = node->GetSelectData()->IsOpenOnStart(); 
     566                                ticked = adbk->IsOpenOnStart(); 
    510567                                break; 
    511568                        case eAdbkColumnResolve: 
    512                                 ticked = node->GetSelectData()->IsLookup(); 
     569                                ticked = adbk->IsLookup(); 
    513570                                break; 
    514571                        case eAdbkColumnSearch: 
    515                                 ticked = node->GetSelectData()->IsSearch(); 
     572                                ticked = adbk->IsSearch(); 
    516573                                break; 
    517574                        } 
     
    566623 
    567624// Get appropriate icon id 
    568 ResIDT CAdbkManagerTable::GetPlotIcon(const CAdbkList::node_type* node, CAdbkProtocol* proto) 
    569 { 
    570         if (!node->IsSelectable()) 
     625ResIDT CAdbkManagerTable::GetPlotIcon(const CAddressBook* adbk, CAdbkProtocol* proto) 
     626{ 
     627        if (adbk->IsProtocol()) 
    571628        { 
    572629                if (!proto) 
     
    580637                        return ICNx_BrowseRemoteHierarchy; 
    581638        } 
     639        else if (adbk->IsDirectory() && !adbk->IsAdbk()) 
     640        { 
     641                return ICNx_BrowseDirectory; 
     642        } 
    582643        else 
    583644        { 
    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; 
    589646        } 
    590647} 
    591648 
    592649// Get text style 
    593 void CAdbkManagerTable::SetTextStyle(const CAdbkList::node_type* node, CAdbkProtocol* proto, bool& strike) 
     650void CAdbkManagerTable::SetTextStyle(const CAddressBook* adbk, CAdbkProtocol* proto, bool& strike) 
    594651{ 
    595652        strike = false; 
     
    598655        if (UEnvironment::HasFeature(env_SupportsColor)) 
    599656        { 
    600                 if (!node->IsSelectable()) 
     657                if (adbk->IsProtocol()) 
    601658                { 
    602659                        bool color_set = false; 
     
    639696} 
    640697 
    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 
     698bool CAdbkManagerTable::UsesBackgroundColor(const STableCell &inCell) const 
     699{ 
     700        TableIndexT     woRow = mCollapsableTree->GetWideOpenIndex(inCell.row); 
     701        return mCollapsableTree->GetNestingLevel(woRow) == 0; 
     702} 
     703 
     704const RGBColor& CAdbkManagerTable::GetBackgroundColor(const STableCell &inCell) const 
    647705{ 
    648706        return CPreferences::sPrefs->mServerBkgndStyle.GetValue().color; 
    649 } 
    650  
    651 void CAdbkManagerTable::DoSelectionChanged() 
    652 { 
    653         CHierarchyTableDrag::DoSelectionChanged(); 
    654          
    655         // Determine whether preview is triggered 
    656         const CUserAction& preview = mTableView->GetPreviewAction(); 
    657         if (preview.GetSelection()) 
    658                 DoPreview(); 
    659  
    660         // Determine whether full view is triggered 
    661         const CUserAction& fullview = mTableView->GetFullViewAction(); 
    662         if (fullview.GetSelection()) 
    663                 DoFullView(); 
    664 } 
    665  
    666 // Handle single click 
    667 void CAdbkManagerTable::DoSingleClick(unsigned long row, const CKeyModifiers& mods) 
    668 { 
    669         // Determine whether preview is triggered 
    670         const CUserAction& preview = mTableView->GetPreviewAction(); 
    671         if (preview.GetSingleClick() && 
    672                 (preview.GetSingleClickModifiers() == mods)) 
    673                 DoPreview(); 
    674  
    675         // Determine whether full view is triggered 
    676         const CUserAction& fullview = mTableView->GetFullViewAction(); 
    677         if (fullview.GetSingleClick() && 
    678                 (fullview.GetSingleClickModifiers() == mods)) 
    679                 DoFullView(); 
    680 } 
    681  
    682 // Handle double click 
    683 void CAdbkManagerTable::DoDoubleClick(unsigned long row, const CKeyModifiers& mods) 
    684 { 
    685         // Determine whether preview is triggered 
    686         const CUserAction& preview = mTableView->GetPreviewAction(); 
    687         if (preview.GetDoubleClick() && 
    688                 (preview.GetDoubleClickModifiers() == mods)) 
    689                 DoPreview(); 
    690  
    691         // Determine whether full view is triggered 
    692         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 item 
    709 void CAdbkManagerTable::DoFullView() 
    710 { 
    711         OnOpenAddressBook(); 
    712 } 
    713  
    714 // Reset the table 
    715 void CAdbkManagerTable::ResetTable() 
    716 { 
    717         // Start cursor for busy operation 
    718         CWaitCursor wait; 
    719  
    720         // Delete all existing rows 
    721         Clear(); 
    722         mHierarchyCol = 1; 
    723         mData.clear(); 
    724  
    725         // Only if we have the manager 
    726         if (!mManager) 
    727                 return; 
    728  
    729         // Get list from manager 
    730         const CAdbkList& adbks = mManager->GetAddressBooks(); 
    731  
    732         // Add each node 
    733         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 row 
    741                 if ((iter != adbks.GetChildren()->begin()) || (*iter)->CountChildren()) 
    742                 { 
    743                         AddNode(*iter, row, false); 
    744  
    745                         // Listen to each protocol 
    746                         CAdbkProtocol* proto = GetCellAdbkProtocol(exp_row); 
    747                         if (proto) 
    748                                 proto->Add_Listener(this); 
    749                          
    750                         // Check expansion - always expand if pure local address account 
    751                         if (!proto || proto->GetAddressAccount()->GetExpanded()) 
    752                         { 
    753                                 // Add wide open row to expansion list which gets processed later 
    754                                 TableIndexT     woRow = GetWideOpenIndex(exp_row + TABLE_ROW_ADJUST); 
    755                                 expand_rows.push_back(woRow); 
    756                         } 
    757                          
    758                         // Bump up exposed row counter 
    759                         exp_row++; 
    760                 } 
    761                 else 
    762                         mHasOthers = false; 
    763         } 
    764  
    765         // Do expansions 
    766         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 account 
    773         else if (exp_row == 2) 
    774                 ExpandRow(1); 
    775  
    776         // Refresh list 
    777         Refresh(); 
    778          
    779         // Force toolbar update 
    780         mTableView->RefreshToolbar(); 
    781  
    782 } // CAdbkManagerTable::ResetTable 
    783  
    784 // Reset the table from the mboxList 
    785 void CAdbkManagerTable::ClearTable() 
    786 { 
    787         // Delete all existing rows 
    788         Clear(); 
    789         mData.clear(); 
    790  
    791         // Refresh list 
    792         Refresh(); 
    793          
    794         // Force toolbar update 
    795         mTableView->RefreshToolbar(); 
    796707} 
    797708 
     
    805716} 
    806717 
    807 // Remove rows and adjust parts 
    808 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 removal 
    814         CHierarchyTableDrag::RemoveRows(inHowMany, inFromRow, inRefresh); 
    815          
    816         // Remove our data using count 
    817         mData.erase(mData.begin() + (inFromRow - 1), mData.begin() + (inFromRow - 1 + remove_count)); 
    818 } 
    819  
    820 // Get the selected adbk 
    821 void* CAdbkManagerTable::GetCellData(TableIndexT woRow) 
    822 { 
    823         return mData.at(woRow - 1); 
    824 } 
    825  
    826718// Adjust cursor over drop area 
    827719bool CAdbkManagerTable::IsCopyCursor(DragReference inDragRef) 
     
    833725bool CAdbkManagerTable::IsDropCell(DragReference inDragRef, STableCell theCell) 
    834726{ 
    835         return IsValidCell(theCell) && IsCellAdbk(theCell.row); 
     727        CAddressBook* adbk = GetCellNode(theCell.row); 
     728        return IsValidCell(theCell) && adbk->IsAdbk(); 
    836729} 
    837730 
     
    843736        mDropSort = false; 
    844737        mDropAdbk = NULL; 
    845         mDropRemoteAdbk = NULL; 
    846738        mDropAdbkWnd = NULL; 
    847739        mAddressAdded = false; 
     
    863755        if (mDropAdbkWnd) 
    864756                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; 
    874758} 
    875759 
     
    881765        { 
    882766                // Determine adbk to use for copy 
    883                 mDropAdbk = GetCellAdbk(theCell.row); 
     767                mDropAdbk = GetCellNode(theCell.row); 
    884768 
    885769                // Does window already exist? 
    886770                mDropAdbkWnd = CAddressBookWindow::FindWindow(mDropAdbk); 
    887771                mDropSort = (mDropAdbkWnd != NULL);