Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues, improved the app in general #53

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions source/AlarmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
*/

#include "AlarmView.h"
#include <Catalog.h>
#include <TranslationUtils.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "AlarmView"

// Constructor
AlarmView::AlarmView(BRect rect, char *name)
AlarmView::AlarmView(BRect rect, const char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW) {

}

void AlarmView :: AttachedToWindow() {
SetFont (be_bold_font);
SetFontSize(12);

}

// Drawing the window
void AlarmView :: Draw (BRect updateRect) {
MovePenTo(BPoint(20.0, 20.0));
DrawString ("Insert time and date to set an alarm");

}


2 changes: 1 addition & 1 deletion source/AlarmView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AlarmView : public BView {

public:

AlarmView (BRect frame, char *name);
AlarmView (BRect frame, const char *name);
virtual void AttachedToWindow ();
virtual void Draw(BRect updateRect);
};
Expand Down
87 changes: 57 additions & 30 deletions source/AlarmWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@

// Libraries
#include <Alert.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>

#include <stdlib.h>
#include <stdio.h>

//translation
#include <Catalog.h>
#include <TranslationUtils.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "AlarmWindow"


// Messages
#define BUTTON_ALARM_OK 'alok'
#define BUTTON_ALARM_UNDO 'alun'
#define BUTTON_ALARM_CANCEL 'btcn'
#define SET_ALARM 'salr'
#define ALARM_MSG 'alrm'
#define ALARM_CLOSE '_alc'
Expand All @@ -33,7 +44,7 @@
* It is created with the dimensions of BRect
*/
AlarmWindow :: AlarmWindow (BRect frame, BHandler *handler)
: BWindow (frame, "Set alarm for this note", B_TITLED_WINDOW,B_NOT_RESIZABLE) {
: BWindow (frame, B_TRANSLATE("Set an alarm for this note"), B_TITLED_WINDOW,B_NOT_RESIZABLE) {

// Variables
fMessenger = new BMessenger(handler);
Expand All @@ -45,24 +56,24 @@ AlarmWindow :: AlarmWindow (BRect frame, BHandler *handler)
char hourDefaultField[3];

// Initialize text fields with current system time values
sprintf(minuteDefaultField, "%d", GetTime(0));
sprintf(hourDefaultField, "%d", GetTime(1));
sprintf(dayDefaultField, "%d", GetTime(2));
sprintf(monthDefaultField, "%d", GetTime(3));
sprintf(minuteDefaultField, "%02d", GetTime(0));
sprintf(hourDefaultField, "%02d", GetTime(1));
sprintf(dayDefaultField, "%02d", GetTime(2));
sprintf(monthDefaultField, "%02d", GetTime(3));
sprintf(yearDefaultField, "%d", GetTime(4));

// We allocate the view AlarmView and associate it to the AlarmWindow
frame.OffsetTo(B_ORIGIN);
fAlarmView = new AlarmView(frame,"AlarmView");
fAlarmView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fAlarmView);
//AddChild(fAlarmView);
thaflo marked this conversation as resolved.
Show resolved Hide resolved

// Text fields for the data
hour = new BTextControl(BRect(20,40,100,35), "hour", "hour:", hourDefaultField , NULL);
minute = new BTextControl(BRect(120,40,200,35), "minute", "min:", minuteDefaultField, NULL);
day = new BTextControl(BRect(20,100,100,35), "day", "day:", dayDefaultField, NULL);
month = new BTextControl(BRect(120,100,200,35), "month", "month:", monthDefaultField, NULL);
year = new BTextControl(BRect(220,100,300,35), "year", "year:", yearDefaultField, NULL);
hour = new BTextControl(BRect(10,10,100,35), B_TRANSLATE("hour"), B_TRANSLATE("hour:"), hourDefaultField , NULL);
minute = new BTextControl(BRect(110,10,210,35), B_TRANSLATE("minute"), B_TRANSLATE("min:"), minuteDefaultField, NULL);
day = new BTextControl(BRect(10,50,100,75), B_TRANSLATE("day"), B_TRANSLATE("day:"), dayDefaultField, NULL);
month = new BTextControl(BRect(110,50,200,75), B_TRANSLATE("month"), B_TRANSLATE("month:"), monthDefaultField, NULL);
year = new BTextControl(BRect(210,50,300,75), B_TRANSLATE("year"), B_TRANSLATE("year:"), yearDefaultField, NULL);

// Text field label: visible
hour -> SetDivider(hour->StringWidth("hour:") + 5);
Expand All @@ -72,18 +83,36 @@ AlarmWindow :: AlarmWindow (BRect frame, BHandler *handler)
year -> SetDivider(year->StringWidth("year:") + 5);

// Allocate the OK button
fButtonOk = new BButton (BRect(400,230,450,240),"ok", "Done", new BMessage(BUTTON_ALARM_OK));
fButtonUndo = new BButton (BRect(340,230,390,240),"undo","Undo",new BMessage(BUTTON_ALARM_UNDO));

fButtonOk = new BButton (BRect(200,110,300,135),"ok", B_TRANSLATE("Ok"), new BMessage(BUTTON_ALARM_OK));
fButtonCancel = new BButton (BRect(320,110,420,135),"cancel",B_TRANSLATE("Cancel"),new BMessage(BUTTON_ALARM_CANCEL));

//BLayout
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.AddGroup(B_HORIZONTAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(hour)
.Add(minute)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL)
.Add(day)
.Add(month)
.Add(year)
.End()
.AddGroup(B_HORIZONTAL)
.Add(fButtonOk)
.Add(fButtonCancel)
.Add(fAlarmView)
.End();
// Making all the objects part of the view
fAlarmView->AddChild(hour);
/*fAlarmView->AddChild(hour);
thaflo marked this conversation as resolved.
Show resolved Hide resolved
fAlarmView->AddChild(minute);
fAlarmView->AddChild(day);
fAlarmView->AddChild(month);
fAlarmView->AddChild(year);
fAlarmView->AddChild(year);*/

fAlarmView->AddChild(fButtonOk);
fAlarmView->AddChild(fButtonUndo);
//fAlarmView->AddChild(fButtonOk);
//fAlarmView->AddChild(fButtonCancel);

Show();

Expand Down Expand Up @@ -133,22 +162,22 @@ void AlarmWindow :: MessageReceived(BMessage* message) {
*/

// First check if there are any values (in a correct range)
if( (hourN > 0 && hourN < 24) && (minuteN > 0 && minuteN < 60) && (dayN > 0) && (monthN > 0 && monthN <= 12) && (yearN >= 1970 && yearN <= 2150) ) {
if ( (hourN > 0 && hourN < 24) && (minuteN > 0 && minuteN < 60) && (dayN > 0) && (monthN > 0 && monthN <= 12) && (yearN >= 1970 && yearN <= 2150) ) {

// Second check if day is correct in its month
daysInMonth = GetDaysInMonth(monthN,yearN);

if(dayN > daysInMonth) {

BAlert *myAlert = new BAlert("Incorrect days in month", "Insert a correct day for selected month", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
BAlert *myAlert = new BAlert(B_TRANSLATE("Incorrect day in month"), B_TRANSLATE("Insert a correct day for selected month"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
myAlert -> Go();
break;
}

// Third check if input user date/time comes after system time
if ( !(IsAfter(minuteN,hourN,dayN,monthN,yearN)) ) {

BAlert *myAlert = new BAlert("Previous date-time", "Date-time should come after system time", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
BAlert *myAlert = new BAlert(B_TRANSLATE("Previous date-time"), B_TRANSLATE("Date-time should come after system time"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
myAlert -> Go();
break;

Expand Down Expand Up @@ -182,17 +211,17 @@ void AlarmWindow :: MessageReceived(BMessage* message) {
} else {

// If some values are missing show an alert
BAlert *myAlert = new BAlert("Missing values", "Fill all the fields with correct values", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
BAlert *myAlert = new BAlert(B_TRANSLATE("Missing values"), B_TRANSLATE("Fill all the fields with correct values"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
myAlert -> Go();

}

}
break;

case BUTTON_ALARM_UNDO:{
case BUTTON_ALARM_CANCEL:{

BAlert *alert = new BAlert("", "The alarm hasn't been saved yet, do you really want to close the window ?", "Yes", "No", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
BAlert *alert = new BAlert("", B_TRANSLATE("The alarm hasn't been saved yet, do you really want to close the window?"), B_TRANSLATE("Yes"), B_TRANSLATE("No"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetShortcut(0, B_ESCAPE);

if (alert->Go() == 0) {
Expand All @@ -218,7 +247,7 @@ int32 AlarmWindow :: GetDaysInMonth(int month, int year) {
case 1:
return 31;
case 2: {
if ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 29;
else
return 28;
Expand Down Expand Up @@ -275,13 +304,10 @@ bool AlarmWindow :: IsAfter(int min, int h, int d, int mon, int y) {
userTime = mktime(timeinfo);

// Compare user time and system time
if( difftime(userTime, time( &rawtime) ) > 0 ) {

if ( difftime(userTime, time( &rawtime) ) > 0 ) {
thaflo marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

else {

return false;
}
}
Expand All @@ -304,6 +330,7 @@ int AlarmWindow :: GetTime(int element) {

switch(element) {
case 0:
printf("%02d\n",now -> tm_min);
return now -> tm_min;
case 1:
return now -> tm_hour;
Expand Down
2 changes: 1 addition & 1 deletion source/AlarmWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AlarmWindow : public BWindow {
*year;

BButton *fButtonOk;
BButton *fButtonUndo;
BButton *fButtonCancel;

BMessenger *fMessenger;

Expand Down
9 changes: 8 additions & 1 deletion source/ChoiceView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#define BUTTON_OK 'btok'
#define BUTTON_UNDO 'btun'

//translation
#include <Catalog.h>
#include <TranslationUtils.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ChoiceView"

// Constructor
ChoiceView :: ChoiceView(BRect rect, char *vname,BHandler *handler)
: BView(rect, vname, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE){
Expand Down Expand Up @@ -100,7 +107,7 @@ ChoiceView :: ChoiceView(BRect rect, char *vname,BHandler *handler)
frame.top = frame.bottom - 40;
frame.right-= 90;
frame.bottom -= 10;
fUndoButton = new BButton(frame,"undo","Undo",new BMessage(BUTTON_UNDO));
fUndoButton = new BButton(frame,"undo",B_TRANSLATE("Undo"),new BMessage(BUTTON_UNDO));

frame = Bounds();
frame.left += 430;
Expand Down
2 changes: 1 addition & 1 deletion source/ChoiceWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ChoiceWindow :: MessageReceived(BMessage* message) {
// Variables
BAlert *alert;

switch(message -> what) {
switch (message -> what) {

// If a new Radio Button is checked we change the message which stores the current selection
case RADIO_CHECKED:{
Expand Down
16 changes: 7 additions & 9 deletions source/ColorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
#include "ColorView.h"
#include "StringView.h"

//translation
#include <Catalog.h>
#include <TranslationUtils.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ColorWindow"
// Messages
#define COLOR_CHANGED 'ccrq'

// Constructor
ColorView :: ColorView(BRect rect, char *name,BHandler *handler)
ColorView :: ColorView(BRect rect, const char *name,BHandler *handler)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW){
}

Expand All @@ -32,16 +38,8 @@ void ColorView :: AttachedToWindow() {

// Drawing the window
void ColorView :: Draw (BRect updateRect) {
// Variables
BStringView *instructions;
BRect frame(10,20,600,35);
const char *text = "Press the button to change the color";

instructions = new BStringView (frame, "instructions", text);
AddChild(instructions);
}

// When the user clicks...
void ColorView :: MouseDown(BPoint point) {

}
2 changes: 1 addition & 1 deletion source/ColorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ColorView : public BView {

public:

ColorView (BRect frame, char *name, BHandler *handler);
ColorView (BRect frame, const char *name, BHandler *handler);
virtual void AttachedToWindow ();
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
Expand Down
Loading