Changeset 25415

Show
Ignore:
Timestamp:
05/10/08 07:24:27 (6 days ago)
Author:
stippi
Message:
Applied patch by Philippe Saint-Pierre:
* Extended the scope of the Revert feature to include changes to the time zone.
* Moved the Revert button out of the tab view, so that it indicates the above
  visually. The window now handles the Revert feature.
* Added Others/Greenwhich time zone which is equivalent to an "unset" time zone.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/src/preferences/time/DateTimeView.cpp

    r25210 r25415  
    1616#include "TimeMessages.h" 
    1717#include "DateTime.h" 
    18  
    19  
    20 #include <Button.h> 
     18#include "TimeWindow.h" 
     19 
     20 
    2121#include <CheckBox.h> 
    2222#include <Entry.h> 
     
    7070                fInitialized = true; 
    7171 
    72                 fGmtTime->SetTarget(this); 
    73                 fLocalTime->SetTarget(this); 
    7472                fCalendarView->SetTarget(this); 
    75                 fRevertButton->SetTarget(this); 
    7673        } 
    7774} 
     
    132129                        fUseGmtTime = fGmtTime->Value() == B_CONTROL_ON; 
    133130                        _UpdateGmtSettings(); 
    134                         CheckCanRevert(); 
    135131                        break; 
    136132 
    137133                case kMsgRevert: 
    138134                        _Revert(); 
    139                         fRevertButton->SetEnabled(false); 
    140135                        break; 
    141136         
     
    147142 
    148143 
    149 void 
     144bool 
    150145DateTimeView::CheckCanRevert() 
    151146{ 
     
    158153        time(&changedNow); 
    159154 
    160         enable = enable || (changedNow != unchangedNow); 
    161  
    162         fRevertButton->SetEnabled(enable); 
     155        return enable || (changedNow != unchangedNow); 
    163156} 
    164157 
     
    266259 
    267260        fOldUseGmtTime = fUseGmtTime; 
    268  
    269         BRect rect = Bounds(); 
    270  
    271         rect.left = 10; 
    272         rect.top = rect.bottom - 10; 
    273  
    274         fRevertButton = new BButton(rect, "revert", "Revert", 
    275                 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 
    276          
    277         fRevertButton->ResizeToPreferred(); 
    278         fRevertButton->SetEnabled(false); 
    279         float buttonHeight = fRevertButton->Bounds().Height(); 
    280         fRevertButton->MoveBy(0, -buttonHeight); 
    281         AddChild(fRevertButton); 
    282261 
    283262        ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0); 
  • haiku/trunk/src/preferences/time/DateTimeView.h

    r25210 r25415  
    2121class BRadioButton; 
    2222class TAnalogClock; 
    23 class BButton; 
    2423 
    2524 
     
    3332                virtual void    MessageReceived(BMessage *message); 
    3433 
    35                                 void    CheckCanRevert(); 
     34                bool                    CheckCanRevert(); 
     35                bool                    GetUseGmtTime(); 
    3636 
    3737        private: 
     
    5252                TAnalogClock    *fClock; 
    5353 
    54                 BButton                 *fRevertButton; 
    55  
    56                 bool                    fUseGmtTime; 
     54                bool                    fUseGmtTime; 
    5755                bool                    fOldUseGmtTime; 
    5856                bool                    fInitialized; 
  • haiku/trunk/src/preferences/time/Time.cpp

    r24403 r25415  
    4747        BAlert *alert = new BAlert("about",  
    4848                "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 
    49                 "Julun\n\nCopyright 2004-2007, Haiku.", "OK"); 
     49                "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku.", "OK"); 
    5050        alert->Go(); 
    5151} 
  • haiku/trunk/src/preferences/time/TimeWindow.cpp

    r25210 r25415  
    2121#include <Screen.h> 
    2222#include <TabView.h> 
     23#include <Button.h> 
    2324 
    2425 
     
    3839 
    3940 
     41void 
     42TTimeWindow::SetRevertStatus() 
     43{ 
     44        fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert()  
     45                || fTimeZoneView->CheckCanRevert()); 
     46} 
     47 
     48 
    4049void  
    4150TTimeWindow::MessageReceived(BMessage *message) 
     
    4453                case H_USER_CHANGE: 
    4554                        fBaseView->ChangeTime(message); 
    46                         fDateTimeView->CheckCanRevert(); 
     55                        SetRevertStatus(); 
    4756                        break; 
    4857                 
    4958                case B_ABOUT_REQUESTED: 
    5059                        be_app->PostMessage(B_ABOUT_REQUESTED); 
     60                        break; 
     61 
     62                case kMsgRevert: 
     63                        fDateTimeView->MessageReceived(message); 
     64                        fTimeZoneView->MessageReceived(message); 
     65                        fRevertButton->SetEnabled(false); 
     66                        break; 
     67 
     68                case kRTCUpdate: 
     69                        fDateTimeView->MessageReceived(message); 
     70                        SetRevertStatus(); 
    5171                        break; 
    5272 
     
    102122        fBaseView->AddChild(tabView); 
    103123        tabView->ResizeBy(0.0, tabView->TabHeight()); 
     124 
     125        BRect rect = Bounds(); 
     126 
     127        rect.left = 10; 
     128        rect.top = rect.bottom - 10; 
     129 
     130        fRevertButton = new BButton(rect, "revert", "Revert", 
     131                new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 
     132         
     133        fRevertButton->ResizeToPreferred(); 
     134        fRevertButton->SetEnabled(false); 
     135        float buttonHeight = fRevertButton->Bounds().Height(); 
     136        fRevertButton->MoveBy(0, -buttonHeight); 
     137        fBaseView->AddChild(fRevertButton); 
     138        fRevertButton->SetTarget(this); 
     139 
    104140        fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0,  
    105                 tabView->Bounds().Height() + 10.0); 
     141                tabView->Bounds().Height() + buttonHeight + 30.0); 
    106142 
    107143        ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); 
  • haiku/trunk/src/preferences/time/TimeWindow.h

    r22633 r25415  
    2828                virtual bool    QuitRequested(); 
    2929                virtual void    MessageReceived(BMessage *message); 
     30                void                            SetRevertStatus(); 
    3031 
    3132        private: 
     
    3738                DateTimeView    *fDateTimeView; 
    3839                TimeZoneView    *fTimeZoneView; 
     40                BButton                 *fRevertButton; 
    3941}; 
    4042 
  • haiku/trunk/src/preferences/time/ZoneView.cpp

    r22633 r25415  
    11/* 
    2  * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. 
     2 * Copyright 2004-2008, Haiku, Inc. All Rights Reserved. 
    33 * Distributed under the terms of the MIT License. 
    44 * 
     
    66 *              Mike Berg <mike@berg-net.us> 
    77 *              Julun <host.haiku@gmx.de> 
     8 *              Philippe Saint-Pierre <stpere@gmail.com> 
    89 */ 
    910 
     
    2223#include "TimeMessages.h" 
    2324#include "TZDisplay.h" 
     25#include "TimeWindow.h" 
    2426 
    2527 
     
    3840#include <String.h> 
    3941#include <View.h> 
     42#include <Window.h> 
    4043 
    4144 
     
    6871 
    6972 
     73bool 
     74TimeZoneView::CheckCanRevert() 
     75{ 
     76        return fCurrentZone != fOldZone; 
     77} 
     78 
     79 
     80void 
     81TimeZoneView::_Revert() 
     82{ 
     83        BPath parent; 
     84 
     85        fCurrentZone = fOldZone; 
     86        int32 czone; 
     87 
     88        if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) { 
     89                if (BMenuItem* item = fRegionPopUp->FindItem("Others")) 
     90                        item->SetMarked(true); 
     91                czone = FillCityList("Others"); 
     92        } else { 
     93                fCurrentZone.GetParent(&parent); 
     94                if (BMenuItem* item = fRegionPopUp->FindItem(parent.Leaf())) 
     95                        item->SetMarked(true); 
     96                czone = FillCityList(parent.Path()); 
     97        } 
     98 
     99        if (czone > -1) { 
     100                fCityList->Select(czone); 
     101                fCityList->ScrollToSelection(); 
     102                fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 
     103                SetPreview(); 
     104        } 
     105        SetTimeZone(); 
     106} 
     107 
     108 
    70109TimeZoneView::~TimeZoneView() 
    71110{ 
     
    88127                // update displays       
    89128                BPath parent; 
    90                 fCurrentZone.GetParent(&parent); 
    91                 int32 czone = FillCityList(parent.Path()); 
    92                 if (czone > -1) { 
    93                         fCityList->Select(czone); 
    94                         fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 
     129                if (strcmp(fCurrentZone.Leaf(), "Greenwich") != 0) { 
     130                        fCurrentZone.GetParent(&parent); 
     131                        int32 czone = FillCityList(parent.Path()); 
     132                        if (czone > -1) { 
     133                                fCityList->Select(czone); 
     134                                fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 
     135                        } 
     136                } else { 
     137                        int32 czone = FillCityList("Others"); 
     138                        if (czone > -1) { 
     139                                fCityList->Select(czone); 
     140                                fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 
     141                        } 
    95142                } 
    96143        } 
     
    121168                 
    122169                case H_SET_TIME_ZONE: 
     170                { 
    123171                        SetTimeZone(); 
     172                        BMessage msg(*message); 
     173                        msg.what = kRTCUpdate; 
     174                        Window()->PostMessage(&msg); 
     175                        ((TTimeWindow*)Window())->SetRevertStatus(); 
    124176                        break; 
    125                  
     177                } 
     178 
     179                case kMsgRevert: 
     180                        _Revert(); 
     181                        break; 
     182 
    126183                case H_CITY_CHANGED: 
    127184                        SetPreview(); 
     
    243300                        // skip Etc directory 
    244301                        if (itemtext.Compare("Etc", 3) == 0) 
    245                              continue; 
     302                              continue; 
    246303                          
    247304                        markit = itemtext.Compare(region.Leaf()) == 0; 
     
    264321                } 
    265322        } 
     323        BMessage *msg = new BMessage(H_REGION_CHANGED); 
     324        msg->AddString("region", "Others"); 
     325 
     326        item = new BMenuItem("Others", msg); 
     327        item->SetMarked(strcmp(fCurrentZone.Leaf(), "Greenwich") == 0); 
     328        fRegionPopUp->AddItem(item); 
    266329} 
    267330 
     
    278341        } 
    279342 
    280         // Enter time zones directory. Find subdir with name that matches string 
    281         // stored in area. Enter subdirectory and count the items. For each item, 
    282         // add a StringItem to fCityList Time zones directory  
    283  
    284         BPath path; 
    285         if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK) 
    286                 return 0; 
    287  
    288         path.Append("timezones"); 
    289  
    290         BPath Area(area); 
    291         BDirectory zoneDir(path.Path());  
    292         BDirectory cityDir; 
    293343        BStringItem *city; 
    294         BString city_name; 
    295         BEntry entry; 
    296344        int32 index = -1;  
    297          
    298         //locate subdirectory: 
    299         if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) { 
    300                 cityDir.SetTo(&zoneDir, Area.Leaf());   
    301  
    302                 // There is a subdir with a name that matches 'area'. That's the one!! 
    303                 // Iterate over the items in the subdir, fill listview with TZoneItems 
    304                 while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) { 
    305                         if (!entry.IsDirectory()) { 
    306                                 BPath zone(&entry); 
    307                                 city_name = zone.Leaf(); 
    308                                 city_name.ReplaceAll("_IN", ", Indiana"); 
    309                                 city_name.ReplaceAll("__Calif", ", Calif"); 
    310                                 city_name.ReplaceAll("__", ", "); 
    311                                 city_name.ReplaceAll("_", " "); 
    312                                 city = new TZoneItem(city_name.String(), zone.Path()); 
    313                                 fCityList->AddItem(city); 
    314                                 if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0) 
    315                                         index = fCityList->IndexOf(city); 
     345        if (strcmp(area, "Others") != 0) { 
     346 
     347                // Enter time zones directory. Find subdir with name that matches string 
     348                // stored in area. Enter subdirectory and count the items. For each item, 
     349                // add a StringItem to fCityList Time zones directory  
     350 
     351                BPath path; 
     352                if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK) 
     353                        return 0; 
     354 
     355                path.Append("timezones"); 
     356 
     357                BPath Area(area); 
     358                BDirectory zoneDir(path.Path());  
     359                BDirectory cityDir; 
     360                BString city_name; 
     361                BEntry entry; 
     362 
     363         
     364                //locate subdirectory: 
     365                if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) { 
     366                        cityDir.SetTo(&zoneDir, Area.Leaf());   
     367 
     368                        // There is a subdir with a name that matches 'area'. That's the one!! 
     369                        // Iterate over the items in the subdir, fill listview with TZoneItems 
     370                        while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) { 
     371                                if (!entry.IsDirectory()) { 
     372                                        BPath zone(&entry); 
     373                                        city_name = zone.Leaf(); 
     374                                        city_name.ReplaceAll("_IN", ", Indiana"); 
     375                                        city_name.ReplaceAll("__Calif", ", Calif"); 
     376                                        city_name.ReplaceAll("__", ", "); 
     377                                        city_name.ReplaceAll("_", " "); 
     378                                        city = new TZoneItem(city_name.String(), zone.Path()); 
     379                                        fCityList->AddItem(city); 
     380                                        if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0) 
     381                                                index = fCityList->IndexOf(city); 
     382                                } 
    316383                        } 
     384                } 
     385        } else { 
     386                city = new TZoneItem("Greenwich", "/boot/beos/etc/timezones/Greenwich"); 
     387                fCityList->AddItem(city); 
     388                if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) { 
     389                        index = fCityList->IndexOf(city); 
    317390                } 
    318391        } 
     
    364437                        // do something like set to a default GMT??? 
    365438                } 
     439                else if (!tzLink.Exists()) { // link doesn't exists 
     440                        tzLink.SetTo("/boot/beos/etc/timezones/Greenwich"); 
     441                } 
    366442        } else { 
    367                 // set tzlink to a defaul
     443                // directory doesn't exis
    368444                tzLink.SetTo("/boot/beos/etc/timezones/EST"); 
    369445        } 
     
    371447        // we need something in the current zone 
    372448        fCurrentZone.SetTo(&tzLink); 
     449        fOldZone.SetTo(&tzLink); 
    373450} 
    374451 
     
    450527        // update environment 
    451528        SetTimeZone(target.Path()); 
    452  
     529         
    453530        // update display 
    454531        time_t current = time(0); 
  • haiku/trunk/src/preferences/time/ZoneView.h

    r22633 r25415  
    2929                virtual void    AttachedToWindow(); 
    3030                virtual void    MessageReceived(BMessage *message); 
     31                bool                    CheckCanRevert(); 
    3132 
    3233        private: 
     
    4041                void                    ReadTimeZoneLink(); 
    4142                void                    BuildRegionMenu(); 
     43                void                    _Revert(); 
    4244 
    4345                // returns index of current zone 
     
    5456                int32                   fMinute; 
    5557                BPath                   fCurrentZone; 
     58                BPath                           fOldZone; 
    5659                bool                    fInitialized; 
    5760};