Skip to content

Commit

Permalink
tags window is working again
Browse files Browse the repository at this point in the history
alarm window uses BSpinner now (BCalendarView for the day/month/year will follow
cleaned up a lot of the code in AlarmWindow.cpp
  • Loading branch information
thaflo committed Apr 15, 2021
1 parent 839d3b6 commit 772c32e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 104 deletions.
122 changes: 50 additions & 72 deletions source/AlarmWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Ilio Catallo
* Stefano Celentano
*
* Last revision: Stefano Celentano, 30th June 2009
* Last revision: Florian Thaler, April 2021
*
* Description: Alarm Window allows the user to create an alarm for the note
*/
Expand All @@ -21,6 +21,7 @@
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <TimeFormat.h>
#include <Window.h>

#include <stdlib.h>
#include <stdio.h>
Expand All @@ -32,14 +33,19 @@
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "AlarmWindow"

class BSpinner;

// Messages
#define BUTTON_ALARM_OK 'alok'
#define BUTTON_ALARM_CANCEL 'btcn'
#define BUTTON_ALARM_CANCEL 'btcn'
#define SET_ALARM 'salr'
#define ALARM_MSG 'alrm'
#define ALARM_CLOSE '_alc'

#define MSG_HOUR 'msgh'
#define MSG_MINUTE 'msgm'
#define MSG_DAY 'msgd'
#define MSG_MONTH 'msgo'
#define MSG_YEAR 'msgy'
/*
* Constructor
* It is created with the dimensions of BRect
Expand All @@ -50,44 +56,49 @@ AlarmWindow :: AlarmWindow (BRect frame, BHandler *handler)
// Variables
fMessenger = new BMessenger(handler);

char dayDefaultField[3];
char monthDefaultField[4];
char yearDefaultField[5];
char dayNow[3];
char monthNow[4];
char yearNow[5];
char hourNow[6];
char minNow[7];

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

// We allocate the view AlarmView and associate it to the AlarmWindow
// Text fields for the data
hour = new BTextControl("hour", B_TRANSLATE("hour:"), hourNow , NULL);
minute = new BTextControl("min", B_TRANSLATE("min:"), minNow, NULL);
day = new BTextControl("day", B_TRANSLATE("day:"), dayDefaultField, NULL);
month = new BTextControl("month", B_TRANSLATE("month:"), monthDefaultField, NULL);
year = new BTextControl("year", B_TRANSLATE("year:"), yearDefaultField, NULL);

// Allocate the OK button
fButtonOk = new BButton ("ok", B_TRANSLATE("Ok"), new BMessage(BUTTON_ALARM_OK));
sprintf(monthNow, "%02d", GetTime(3));
sprintf(yearNow, "%d", GetTime(4));

//user interface
fHour = new BSpinner("Hour", B_TRANSLATE("Hour:"), new BMessage(MSG_HOUR));
fHour->SetRange(0, 24);
fHour->SetValue(atoi(hourNow));
fMinute = new BSpinner("Minute", B_TRANSLATE("Minute:"), new BMessage(MSG_MINUTE));
fMinute->SetRange(0, 60);
fMinute->SetValue(atoi(minNow));
fDay = new BSpinner("Day", B_TRANSLATE("Day:"), new BMessage(MSG_DAY));
fDay->SetRange(0, 31);
fDay->SetValue(atoi(dayNow));
fMonth = new BSpinner("Month", B_TRANSLATE("Month:"), new BMessage(MSG_MONTH));
fMonth->SetRange(0, 12);
fMonth->SetValue(atoi(monthNow));
fYear = new BSpinner("Year", B_TRANSLATE("Year:"), new BMessage(MSG_YEAR));
fYear->SetValue(atoi(yearNow));

fButtonOk = new BButton ("ok", B_TRANSLATE("OK"), new BMessage(BUTTON_ALARM_OK));
fButtonCancel = new BButton ("cancel",B_TRANSLATE("Cancel"),new BMessage(BUTTON_ALARM_CANCEL));

//thaflo, 2021, adding layout management
SetLayout(new BGroupLayout(B_VERTICAL));

BView* fTopView = new BGroupView(B_VERTICAL);

BLayoutBuilder::Group<>(fTopView, B_VERTICAL)
.SetInsets(5,5,5,5)
.SetInsets(B_USE_WINDOW_INSETS)
.AddGrid()
.Add(day, 1, 0)
.Add(month, 2, 0)
.Add(year, 3, 0)
.Add(hour, 1, 1)
.Add(minute, 2, 1)
.Add(fDay, 1, 0)
.Add(fMonth, 2, 0)
.Add(fYear, 3, 0)
.Add(fHour, 1, 1)
.Add(fMinute, 2, 1)
.End()
.AddGroup(B_HORIZONTAL)
.AddGlue()
Expand All @@ -102,51 +113,27 @@ AlarmWindow :: AlarmWindow (BRect frame, BHandler *handler)
void AlarmWindow :: MessageReceived(BMessage* message) {
// Variables
BMessage *msg;
int16 i;
int32 hourN,minuteN,dayN,monthN,yearN;
int32 daysInMonth;

switch (message->what) {

case kShowPopUpCalendar:
{
int8 which;
message->FindInt8("which", &which);
//_ShowPopUpCalendar(which);
break;
}

case BUTTON_ALARM_OK: {
/*
* When I press OK I throw the message that fills the struct
* We prepare the data to be included in the message
*/
const char *hourTextField;
const char *minuteTextField;
const char *dayTextField;
const char *monthTextField;
const char *yearTextField;

/*
* Get text fields context by calling Text()
* (returns null if empty) and convert to int
*/
hourN = fHour->Value();
minuteN = fMinute->Value();
dayN = fDay->Value();
monthN = fMonth->Value();
yearN = fYear->Value();

hourTextField = hour->Text();
minuteTextField = minute->Text();
dayTextField = day->Text();
monthTextField = month->Text();
yearTextField = year->Text();

hourN = atoi(hourTextField);
minuteN = atoi(minuteTextField);
dayN = atoi(dayTextField);
monthN = atoi(monthTextField);
yearN = atoi(yearTextField);

/*
* Starting controls for time and date
* Notice: I won't send ALARM_MSG if one of these checks is missed
* Notice: I won't send ALARM_MSG if one of these checks fails
*/

// First check if there are any values (in a correct range)
Expand Down Expand Up @@ -174,20 +161,11 @@ void AlarmWindow :: MessageReceived(BMessage* message) {
// Instantiate a new message and fill it with time values
msg = new BMessage (ALARM_MSG);

i = atoi (hourTextField);
msg->AddInt16 ("hour", i);

i = atoi (minuteTextField);
msg->AddInt16 ("minute", i);

i = atoi (dayTextField);
msg->AddInt16 ("day", i);

i = atoi (monthTextField);
msg->AddInt16 ("month", i);

i = atoi (yearTextField);
msg->AddInt16 ("year", i);
msg->AddInt16 ("hour", hourN);
msg->AddInt16 ("minute", minuteN);
msg->AddInt16 ("day", dayN);
msg->AddInt16 ("month", monthN);
msg->AddInt16 ("year", yearN);

// Sending the message
fMessenger->SendMessage(msg);
Expand Down
14 changes: 6 additions & 8 deletions source/AlarmWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
#include <Button.h>
#include <Messenger.h>
#include <StringView.h>
#include <Spinner.h>
#include <TextControl.h>
#include <Window.h>

static const uint32 kShowPopUpCalendar = 'kspc';


// Window that allows the user to insert the alarm
class AlarmWindow : public BWindow {

Expand All @@ -38,11 +36,11 @@ class AlarmWindow : public BWindow {

private:

BTextControl *hour,
*minute,
*day,
*month,
*year;
BSpinner *fHour,
*fMinute,
*fDay,
*fMonth,
*fYear;

BView *fTopView;

Expand Down
2 changes: 1 addition & 1 deletion source/ColorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ColorWindow :: ColorWindow (BRect frame, BHandler *handler, rgb_color color)
BView* topView = new BGroupView(B_VERTICAL);

BLayoutBuilder::Group<>(topView, B_VERTICAL, 0.0f)
.SetInsets(5,5,5,5)
.SetInsets(B_USE_WINDOW_INSETS)
.Add(fColorControl)
.AddGroup(B_HORIZONTAL)
.AddGlue()
Expand Down
2 changes: 1 addition & 1 deletion source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ LIBPATHS=
# additional paths to look for system headers
# thes use the form: #include <header>
# source file directories are NOT auto-included here
SYSTEM_INCLUDE_PATHS =
SYSTEM_INCLUDE_PATHS = /boot/system/develop/headers/private/interface

# additional paths to look for local headers
# thes use the form: #include "header"
Expand Down
34 changes: 12 additions & 22 deletions source/TagsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Ilio Catallo,
* Stefano Celentano
*
* Last revision: Florian Thaler, 08.0.2021
* Last revision: Florian Thaler, 08.04.2021
*
* Description: Tags window, it allows the user to set three customs tags (extra attributes)
*/
Expand Down Expand Up @@ -51,24 +51,23 @@ TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler)
status_t err;
const char *name;

BString tagone = BString();
BString tagtwo = BString();
BString tagthree = BString();
BString tagone;
BString tagtwo;
BString tagthree;

fTag1 = new BTextControl("tag1", B_TRANSLATE("First Tag: "), NULL, NULL);
fTag2 = new BTextControl("tag2", B_TRANSLATE("Second Tag: "), NULL, NULL);
fTag3 = new BTextControl("tag3", B_TRANSLATE("Third Tag: "), NULL, NULL);
fTag1 = new BTextControl("tag1", B_TRANSLATE("First tag: "), NULL, NULL);
fTag2 = new BTextControl("tag2", B_TRANSLATE("Second tag: "), NULL, NULL);
fTag3 = new BTextControl("tag3", B_TRANSLATE("Third tag: "), NULL, NULL);

fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(BUTTON_CANCEL));
fOkButton = new BButton("ok", B_TRANSLATE("OK"), new BMessage(BUTTON_OK));


//thaflo, 2021, adding layout management
SetLayout(new BGroupLayout(B_VERTICAL));
BView* fTopView = new BGroupView(B_VERTICAL);

BLayoutBuilder::Group<>(fTopView, B_VERTICAL)
.SetInsets(5,5,5,5)
.SetInsets(B_USE_WINDOW_INSETS)
.AddGroup(B_VERTICAL)
.Add(fTag1)
.Add(fTag2)
Expand All @@ -80,7 +79,6 @@ TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler)
.Add(fOkButton)
.End();
AddChild(fTopView);
Show();

// Open the file from FS starting from the fSaveMessage message
if (fSaveMessage->FindRef("directory",&ref) == B_OK && fSaveMessage->FindString("name", &name) == B_OK){
Expand All @@ -96,22 +94,14 @@ TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler)
}

fFile.ReadAttrString("TAKENOTES:tagone", &tagone);
printf("read tag one: %s \n", tagone);
fFile.ReadAttrString("TAKENOTES:tagtwo", &tagtwo);
printf("read tag two: %s \n", tagtwo);
fFile.ReadAttrString("TAKENOTES:tagthree", &tagthree);
printf("read tag three: %s \n", tagthree);


fTag1->SetText(tagone);
sleep(10);

printf("set tag one\n");
fTag2->SetText(tagtwo);
printf("set tag two\n");
fTag3->SetText(tagthree);
printf("set tag three\n");
fTag1->SetText(tagone.String());
fTag2->SetText(tagtwo.String());
fTag3->SetText(tagthree.String());

Show();
}

// Destructor
Expand Down
2 changes: 2 additions & 0 deletions source/TagsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <TextControl.h>
#include <Window.h>



// Window that allows you to add tags
class TagsWindow : public BWindow{

Expand Down

0 comments on commit 772c32e

Please sign in to comment.