diff --git a/src/prefs/time/SettingsView.cpp b/src/prefs/time/SettingsView.cpp new file mode 100644 index 0000000000..b556de7def --- /dev/null +++ b/src/prefs/time/SettingsView.cpp @@ -0,0 +1,100 @@ +/* + SettingsView.cpp +*/ +#ifndef _RADIO_BUTTON_H +#include +#endif + +#ifndef _STRING_VIEW_H +#include +#endif + +#ifndef _VIEW_H +#include +#endif +//////// +#ifndef SETTINGS_VIEW_H +#include "SettingsView.h" +#endif +SettingsView::SettingsView(BRect frame): + BView(frame,"Settings",B_FOLLOW_ALL,B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP | B_PULSE_NEEDED) + { + buildView(); + } //SettingsView::SettingsView() + +void +SettingsView:: buildView() +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + //month/date/year + //BBox? + //BRect monthFrame(8.0, 1.0, 150.0, 20.0); + + //the calender + + //hour/minute/second AM/PM + + //the clock + + + //"Clock set to:"-label + BStringView *fClockSet; + + const char *clockset= "Clock set to: "; + float csLength= be_plain_font->StringWidth(clockset); + BRect clockSetframe(178.0, 147.0, 178.0+csLength, 157.0); + fClockSet= new BStringView(clockSetframe, "clockset", clockset); + AddChild(fClockSet); + + //the radiobuttons.. + //local time + BRadioButton *locButton; + BRect locFrame(247.0, 144.0, 324.0, 154.0); + locButton= new BRadioButton(locFrame,"loc", "Local time", NULL); + AddChild(locButton); + //GMT + BRadioButton *gmtButton; + BRect gmtFrame(247.0, 160.0, 324.0, 170.0); + gmtButton= new BRadioButton(gmtFrame,"gmt", "GMT", NULL); + AddChild(gmtButton); + +}//SettingsView::buildView() + +void +SettingsView::changeRTCSetting() +{ + /* + edit file "RTC_time_settings" in B_USER_SETTINGS_DIRECTORY + if GMT is set, file reads "GMT", if set to local time, file reads "local" + If no such file exists, create one! + + if(file_exists){ + open file + read file + if content != msgstring + change content + } + else + create file RTC_time_settings + write string from msg to file + + */ + + +}//SettingsView::changeRTCSetting() + +void +SettingsView::Draw(BRect frame) +{ + //inherited::Draw(updateFrame); + //draw a separator line + rgb_color black= {0,0,0,255}; + SetLowColor(black); + + BPoint start(160.0, 5.0); + BPoint end(160.0, 175.0); + StrokeLine(start, end, B_SOLID_LOW); +}//SettingsView::Draw(BRect frame) + + diff --git a/src/prefs/time/SettingsView.h b/src/prefs/time/SettingsView.h new file mode 100644 index 0000000000..6cfb403d1e --- /dev/null +++ b/src/prefs/time/SettingsView.h @@ -0,0 +1,26 @@ +/* + + SettingsView.h +*/ + +#ifndef SETTINGS_VIEW_H +#define SETTINGS_VIEW_H + +#ifndef _VIEW_H +#include +#endif + +class SettingsView : public BView +{ +public: + SettingsView(BRect frame); + virtual void Draw(BRect frame); + void changeRTCsetting(); + + +private: + void buildView(); + +}; + +#endif \ No newline at end of file diff --git a/src/prefs/time/Time.cpp b/src/prefs/time/Time.cpp index 289dc1b7d8..f3235bfc90 100644 --- a/src/prefs/time/Time.cpp +++ b/src/prefs/time/Time.cpp @@ -1,6 +1,6 @@ /* * Time.cpp - * Time mccall@digitalparadise.co.uk + * Time mccall@@digitalparadise.co.uk * */ @@ -68,3 +68,6 @@ TimeApplication::~TimeApplication() { delete fSettings; } + + + diff --git a/src/prefs/time/Time.h b/src/prefs/time/Time.h index 4b4d95ffb6..b1e121e04d 100644 --- a/src/prefs/time/Time.h +++ b/src/prefs/time/Time.h @@ -27,3 +27,5 @@ private: }; #endif + + diff --git a/src/prefs/time/Time.rsrc b/src/prefs/time/Time.rsrc index 6abd9c5ae7..4b1e16fb9a 100644 Binary files a/src/prefs/time/Time.rsrc and b/src/prefs/time/Time.rsrc differ diff --git a/src/prefs/time/TimeMessages.h b/src/prefs/time/TimeMessages.h index 90fa272b29..a6e3ede989 100644 --- a/src/prefs/time/TimeMessages.h +++ b/src/prefs/time/TimeMessages.h @@ -14,4 +14,17 @@ const uint32 SLIDER_DELAY_RATE = 'SLdr'; const uint32 ERROR_DETECTED = 'ERor'; +//Timezonemessages +const uint32 REGION_CHANGED ='REch'; +const uint32 TIME_ZONE_CHANGED ='TZch'; + +//SetButton +const uint32 SET_TIME_ZONE ='SEti'; + +//local and GMT settings +const uint32 RTC_SETTINGS ='RTse'; + #endif //TIME_MESSAGES_H + + + diff --git a/src/prefs/time/TimeSettings.cpp b/src/prefs/time/TimeSettings.cpp index 436573b571..197c7fb015 100644 --- a/src/prefs/time/TimeSettings.cpp +++ b/src/prefs/time/TimeSettings.cpp @@ -1,6 +1,6 @@ /* * TimeSettings.cpp - * Time mccall@digitalparadise.co.uk + * Time mccall@@digitalparadise.co.uk * */ @@ -61,3 +61,5 @@ TimeSettings::SetWindowCorner(BPoint corner) { fCorner=corner; } + + diff --git a/src/prefs/time/TimeSettings.h b/src/prefs/time/TimeSettings.h index 6c7d8e953e..db0a99d039 100644 --- a/src/prefs/time/TimeSettings.h +++ b/src/prefs/time/TimeSettings.h @@ -18,3 +18,5 @@ private: }; #endif + + diff --git a/src/prefs/time/TimeWindow.cpp b/src/prefs/time/TimeWindow.cpp index 159a2d41fd..5b2e1486f2 100644 --- a/src/prefs/time/TimeWindow.cpp +++ b/src/prefs/time/TimeWindow.cpp @@ -1,12 +1,13 @@ /* * TimeWindow.cpp - * Time mccall@digitalparadise.co.uk - * + * Time mccall@@digitalparadise.co.uk + * */ #include #include #include +#include #include "TimeMessages.h" #include "TimeWindow.h" @@ -20,7 +21,7 @@ TimeWindow::TimeWindow() : BWindow(BRect(0,0,TIME_WINDOW_RIGHT,TIME_WINDOW_BOTTTOM), "Time & Date", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE ) { BScreen screen; - BSlider *slider=NULL; + //BSlider *slider=NULL; MoveTo(dynamic_cast(be_app)->WindowCorner()); @@ -28,21 +29,40 @@ TimeWindow::TimeWindow() if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom)) MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5); - BuildView(); - AddChild(fView); - + BuildViews(); + SetPulseRate(500000); //pulse rate. Mattias Sundblad Show(); -} +}//TimeWindow::TimeWindow() -void -TimeWindow::BuildView() +void TimeWindow::BuildViews() { - fView = new TimeView(Bounds()); -} + BRect viewRect= Bounds(); + + //the views: + fTimeSettings = new SettingsView(viewRect); + fTimeZones = new ZoneView(viewRect); + + //The tabs: + BTabView *fTabView; + BTab *fTab; + fTabView = new BTabView(viewRect, "tab_view"); -bool -TimeWindow::QuitRequested() + // Settings Tab; + fTab = new BTab(); + fTabView -> AddTab(fTimeSettings,fTab); + fTab -> SetLabel("Settings"); + + //Time zone tab: + fTab = new BTab(); + fTabView -> AddTab(fTimeZones,fTab); + fTab -> SetLabel("Time Zone"); + + AddChild(fTabView); + +}//TimeWindow::BuildViews() + +bool TimeWindow::QuitRequested() { dynamic_cast(be_app)->SetWindowCorner(BPoint(Frame().left,Frame().top)); @@ -50,21 +70,30 @@ TimeWindow::QuitRequested() be_app->PostMessage(B_QUIT_REQUESTED); return(true); -} +} //TimeWindow::QuitRequested() -void -TimeWindow::MessageReceived(BMessage *message) +void TimeWindow::MessageReceived(BMessage *message) { - switch(message->what) { + case REGION_CHANGED: + fTimeZones -> ChangeRegion(message); + break; + case SET_TIME_ZONE: + fTimeZones -> setTimeZone(); + break; + case TIME_ZONE_CHANGED: + fTimeZones -> newTimeZone(); + break; default: BWindow::MessageReceived(message); - break; + break; } -} +}//TimeWindow::MessageReceived(BMessage *message) TimeWindow::~TimeWindow() { -} +}//TimeWindow::~TimeWindow() + + diff --git a/src/prefs/time/TimeWindow.h b/src/prefs/time/TimeWindow.h index f615d417d7..a6b0475b7b 100644 --- a/src/prefs/time/TimeWindow.h +++ b/src/prefs/time/TimeWindow.h @@ -3,8 +3,10 @@ #include +///////////////////////////////// +#include "SettingsView.h" #include "TimeSettings.h" -#include "TimeView.h" +#include "ZoneView.h" class TimeWindow : public BWindow { @@ -14,11 +16,12 @@ public: bool QuitRequested(); void MessageReceived(BMessage *message); - void BuildView(); + void BuildViews(); private: - TimeView *fView; - + SettingsView *fTimeSettings; + ZoneView *fTimeZones; }; #endif + diff --git a/src/prefs/time/ZoneView.cpp b/src/prefs/time/ZoneView.cpp new file mode 100644 index 0000000000..aaf0a12de6 --- /dev/null +++ b/src/prefs/time/ZoneView.cpp @@ -0,0 +1,271 @@ +/* + ZoneView.cpp +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TimeMessages.h" +#include "ZoneView.h" + +ZoneView::ZoneView(BRect frame): + BView(frame,"",B_FOLLOW_ALL,B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP | B_PULSE_NEEDED) + { + buildView(); + } //ZoneView::ZoneView() + +void +ZoneView:: buildView() +{ + //viewcolor + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + //BMenuField with BPopUpMenu for the timezones. + //The box... + BRect boxrect(8.0, 1.0, 157.0, 20.0); + + //popup menu + fZonePopUp = new BPopUpMenu("",true, true, B_ITEMS_IN_COLUMN); + + //Menufield.. + BMenuField *mField; + mField= new BMenuField(boxrect, "mfield", NULL, fZonePopUp, true, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); + + AddChild(mField); + + + //Adding listview. Matsu + BRect flistframe(10.0, 25.0, 140.0, 170.0); + //BListView *fCityList; to header + fCityList= new BListView(flistframe,"cities", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); + //selectionmessage + BMessage *cityChange = new BMessage(TIME_ZONE_CHANGED); + fCityList -> SetSelectionMessage(cityChange); + + //place listview in a scrollview. matsu + BScrollView *scrollList; + scrollList = new BScrollView("scroll_list", fCityList, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true); + AddChild(scrollList); + + //adding menuitems + BMenuItem *zoneItem; + BMessage *zoneMessage; + + zoneItem= new BMenuItem("Africa", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Africa"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Antarctica", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Antarctica"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Arctic", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Arctic"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Asia", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Asia"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Atlantic Ocean", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Atlantic"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Australia", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Australia"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Europe", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Europe"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Greenland", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Greenland"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Indian Ocean", zoneMessage= new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Indian"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("North and Central America", zoneMessage= new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "North_and_Central_America"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("Pacific Ocean", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "Pacific"); + fZonePopUp -> AddItem(zoneItem); + zoneItem= new BMenuItem("South America", zoneMessage = new BMessage(REGION_CHANGED)); + zoneMessage -> AddString("region", "South_America"); + fZonePopUp -> AddItem(zoneItem); + + //label #1 + BStringView *fCurrent; + + const char *current= "Current time zone:"; + float length = be_plain_font -> StringWidth(current); + + BRect currframe(168.0, 43.0, 168.0+length, 53.0); + fCurrent = new BStringView(currframe, "current", current); + + AddChild(fCurrent); + + //label #2 + BStringView *fTimeIn; + + const char *timeIn= "Time in:"; + float timeLength; + + timeLength = be_plain_font -> StringWidth(timeIn); + + BRect timeFrame(168.0, 87.0, 168.0+timeLength, 97.0); + + fTimeIn= new BStringView(timeFrame, "time", timeIn); + + AddChild(fTimeIn); + + //The "Set" button: + BRect buttonFrame(247.0, 155.0, 324.0, 165.0); + fSetTimeZone = new BButton(buttonFrame, "set", "Set", new BMessage(SET_TIME_ZONE)); + fSetTimeZone -> SetEnabled(false); + AddChild(fSetTimeZone); + + //current time zone + getCurrentTZ(); +}//ZoneView::buildView() + +void +ZoneView::ChangeRegion(BMessage *message) +{ + //First: get the region name from the message: + const char *area; + message -> FindString("region",&area); + + //clear listview from previous items + fCityList -> MakeEmpty(); + + //Enter time zones directory. Find subdir with name that matches string stored in area. + //Enter subdirectory and count the items. For each item, add a StringItem to fCityList + //Time zones directory + BDirectory zoneDir("/boot/beos/etc/timezones/"); + BDirectory cityDir; + BStringItem *city; + entry_ref ref; + + //locate subdirectory: + if ( zoneDir.Contains(area, B_DIRECTORY_NODE) ){ + cityDir.SetTo(&zoneDir, area); //There is a subdir with a name that matches 'area'. That's the one!! + //iterate over the items in the subdir and fill the listview with stringitems: + while(cityDir.GetNextRef(&ref) == B_NO_ERROR){ + city = new BStringItem(ref.name); + fCityList -> AddItem(city); + } + } + +}//ZoneView::ChangeRegion() + +void +ZoneView::getCurrentTime() +{ + char tmp[10]; + struct tm locTime; + time_t current; + + current= time(0); + locTime= *localtime(¤t); + + strftime(tmp, 10, "%I:%M %p", &locTime); + + strcpy(fTimeStr, tmp); + + //strftime(tmp, 10, "%z", &locTime); + + //strcpy(fZoneStr,tmp); + +}//ZoneView::getCurrentTime() + +void +ZoneView::getCurrentTZ() +{ + + BPath path; + BEntry tzLink; + char buffer[B_FILE_NAME_LENGTH]; + + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK){ + path.Append("timezone"); + tzLink.SetTo(path.Path(), true); + tzLink.GetName(buffer); + strcpy(fZoneStr, buffer); + } + + +}//ZoneView::getCurrentTz() + +void +ZoneView::Draw(BRect rect) +{ + + + + BPoint tZone(170.0, 65.0); + BPoint tTime(280.0, 65.0); + + //BPoint bZone(170.0, 107.0); + //BPoint bTime(280.0, 107.0); + + SetHighColor(ViewColor()); + SetLowColor(ViewColor()); + FillRect(Bounds()); + SetHighColor(0,0,0,255); + + DrawString(fZoneStr, tZone); + DrawString(fTimeStr, tTime); + + //DrawString(fZoneStr, bZone); + //DrawString(fTimeStr, bTime); + +}//ZoneView:: Draw() + +void +ZoneView::Pulse() +{ + getCurrentTime(); + + Draw(Bounds()); +}//ZoneView:: Pulse() + +void +ZoneView::newTimeZone() +{ + + int32 selection; + BStringItem *item; + const char *text; + + selection = fCityList -> CurrentSelection(); + item = (BStringItem *)fCityList -> ItemAt(selection); + text = item -> Text(); + strcpy(fZoneStr, text); + Draw(Bounds()); + fSetTimeZone -> SetEnabled(true); +}//ZoneView::newTimeZone() + +void +ZoneView::setTimeZone() +{ + /* + set time based on supplied timezone. How to do this? + replace symlink, "timezone", in B_USER_SETTINGS_DIR with a link to the new timezone + */ + + fSetTimeZone -> SetEnabled(false); +} //ZoneView::setTimeZone() + + + + + \ No newline at end of file diff --git a/src/prefs/time/ZoneView.h b/src/prefs/time/ZoneView.h new file mode 100644 index 0000000000..dc2da61c1e --- /dev/null +++ b/src/prefs/time/ZoneView.h @@ -0,0 +1,31 @@ +/* + + ZoneView.h +*/ + +#ifndef ZONE_VIEW_H +#define ZONE_VIEW_H + +class ZoneView : public BView +{ +public: + ZoneView(BRect frame); + void ChangeRegion(BMessage *region); + void setTimeZone(); + void newTimeZone(); + virtual void Pulse(); + virtual void Draw(BRect updateRect); +private: + void buildView(); + void getCurrentTime(); + void getCurrentTZ(); + + + BPopUpMenu *fZonePopUp; + BListView *fCityList; + BButton *fSetTimeZone; + char fTimeStr[10]; + char fZoneStr[B_FILE_NAME_LENGTH]; +}; + +#endif