New Code by Mattias Sundblad.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2877 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Phil Greenway
2003-03-10 03:01:37 +00:00
parent c5a50d6a06
commit 6b793d4c78
12 changed files with 508 additions and 26 deletions
+100
View File
@@ -0,0 +1,100 @@
/*
SettingsView.cpp
*/
#ifndef _RADIO_BUTTON_H
#include <RadioButton.h>
#endif
#ifndef _STRING_VIEW_H
#include <StringView.h>
#endif
#ifndef _VIEW_H
#include <View.h>
#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)
+26
View File
@@ -0,0 +1,26 @@
/*
SettingsView.h
*/
#ifndef SETTINGS_VIEW_H
#define SETTINGS_VIEW_H
#ifndef _VIEW_H
#include <View.h>
#endif
class SettingsView : public BView
{
public:
SettingsView(BRect frame);
virtual void Draw(BRect frame);
void changeRTCsetting();
private:
void buildView();
};
#endif
+4 -1
View File
@@ -1,6 +1,6 @@
/*
* Time.cpp
* Time [email protected]
* Time mccall@@digitalparadise.co.uk
*
*/
@@ -68,3 +68,6 @@ TimeApplication::~TimeApplication()
{
delete fSettings;
}
+2
View File
@@ -27,3 +27,5 @@ private:
};
#endif
Binary file not shown.
+13
View File
@@ -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
+3 -1
View File
@@ -1,6 +1,6 @@
/*
* TimeSettings.cpp
* Time [email protected]
* Time mccall@@digitalparadise.co.uk
*
*/
@@ -61,3 +61,5 @@ TimeSettings::SetWindowCorner(BPoint corner)
{
fCorner=corner;
}
+2
View File
@@ -18,3 +18,5 @@ private:
};
#endif
+49 -20
View File
@@ -1,12 +1,13 @@
/*
* TimeWindow.cpp
* Time [email protected]
*
* Time mccall@@digitalparadise.co.uk
*
*/
#include <Application.h>
#include <Message.h>
#include <Screen.h>
#include <TabView.h>
#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<TimeApplication *>(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<TimeApplication *>(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()
+7 -4
View File
@@ -3,8 +3,10 @@
#include <Window.h>
/////////////////////////////////
#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
+271
View File
@@ -0,0 +1,271 @@
/*
ZoneView.cpp
*/
#include <Button.h>
#include <Entry.h>
#include <FindDirectory.h>
#include <Directory.h>
#include <ListItem.h>
#include <ListView.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <ScrollView.h>
#include <string.h>
#include <StringView.h>
#include <time.h>
#include <View.h>
#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(&current);
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()
+31
View File
@@ -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