diff --git a/source/AlarmView.cpp b/source/AlarmView.cpp deleted file mode 100644 index b3583f8..0000000 --- a/source/AlarmView.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2009, Ilio Catallo, Stefano Celentano, Eleonora Ciceri, all rights reserved - * Distribuited under the terms of the GPL v2 license - * - * Authors: - * - * Stefano Celentano - * - * Last revision: Stefano Celentano, 15th May 2009 - * - * Description: AlarmView: it allows you to set an alarm - */ - -#include "AlarmView.h" - -// Constructor -AlarmView::AlarmView(BRect rect, 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"); -} - - diff --git a/source/AlarmView.h b/source/AlarmView.h deleted file mode 100644 index c373382..0000000 --- a/source/AlarmView.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2009, Ilio Catallo, Stefano Celentano, Eleonora Ciceri, all rights reserved - * Distribuited under the terms of the GPL v2 license - * - * Authors: - * - * Stefano Celentano - * - * Last revision: Stefano Celentano, 19th April 2009 - * - * Description: Header of AlarmView - */ - - -#ifndef ALARM_VIEW_H -#define ALARM_VIEW_H - -#include - -class AlarmView : public BView { - - public: - - AlarmView (BRect frame, char *name); - virtual void AttachedToWindow (); - virtual void Draw(BRect updateRect); -}; - -#endif diff --git a/source/AlarmWindow.cpp b/source/AlarmWindow.cpp index 83a10dc..e50c363 100644 --- a/source/AlarmWindow.cpp +++ b/source/AlarmWindow.cpp @@ -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 */ @@ -17,139 +17,143 @@ // Libraries #include +#include +#include +#include +#include +#include #include #include +//translation +#include +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "AlarmWindow" + +class BSpinner; + // 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' - +#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 */ 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); - char dayDefaultField[3]; - char monthDefaultField[3]; - char yearDefaultField[3]; - char minuteDefaultField[3]; - char hourDefaultField[3]; + char dayNow[3]; + char monthNow[4]; + char yearNow[5]; + char hourNow[6]; + char minNow[7]; // 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(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); - - // 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); - - // Text field label: visible - hour -> SetDivider(hour->StringWidth("hour:") + 5); - minute -> SetDivider(minute->StringWidth("min:") + 5); - day -> SetDivider(day->StringWidth("day:") + 5); - month -> SetDivider(month->StringWidth("month:") + 5); - 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)); - - // Making all the objects part of the view - fAlarmView->AddChild(hour); - fAlarmView->AddChild(minute); - fAlarmView->AddChild(day); - fAlarmView->AddChild(month); - fAlarmView->AddChild(year); - - fAlarmView->AddChild(fButtonOk); - fAlarmView->AddChild(fButtonUndo); - + sprintf(minNow,"%02d", GetTime(0)+3); + sprintf(dayNow, "%02d", GetTime(2)); + sprintf(hourNow, "%02d", GetTime(1)); + 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)); + + SetLayout(new BGroupLayout(B_VERTICAL)); + BView* fTopView = new BGroupView(B_VERTICAL); + + BLayoutBuilder::Group<>(fTopView, B_VERTICAL) + .SetInsets(B_USE_WINDOW_INSETS) + .AddGrid() + .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() + .Add(fButtonCancel) + .Add(fButtonOk) + .End(); + AddChild(fTopView); Show(); - } // Receiving the messages void AlarmWindow :: MessageReceived(BMessage* message) { // Variables BMessage *msg; - int16 i; int32 hourN,minuteN,dayN,monthN,yearN; int32 daysInMonth; - switch (message -> what) { + switch (message->what) { 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 - */ - - hourTextField = hour -> Text(); - minuteTextField = minute -> Text(); - dayTextField = day -> Text(); - monthTextField = month -> Text(); - yearTextField = year -> Text(); + hourN = fHour->Value(); + minuteN = fMinute->Value(); + dayN = fDay->Value(); + monthN = fMonth->Value(); + yearN = fYear->Value(); - 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) - 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); - myAlert -> Go(); + 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); - myAlert -> Go(); + 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; } @@ -157,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); @@ -182,24 +177,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); - myAlert -> Go(); + 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:{ - - 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); - alert->SetShortcut(0, B_ESCAPE); - - if (alert->Go() == 0) { - // Discard all the changes - Quit(); - } + case BUTTON_ALARM_CANCEL:{ + Quit(); } break; @@ -218,7 +206,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; @@ -263,34 +251,28 @@ bool AlarmWindow :: IsAfter(int min, int h, int d, int mon, int y) { // Fill the struct with user input - timeinfo -> tm_year = y - 1900; - timeinfo -> tm_mon = mon - 1; - timeinfo -> tm_mday = d; - timeinfo -> tm_hour = h; - timeinfo -> tm_min = min; - timeinfo -> tm_sec = 0; + timeinfo->tm_year = y - 1900; + timeinfo->tm_mon = mon - 1; + timeinfo->tm_mday = d; + timeinfo->tm_hour = h; + timeinfo->tm_min = min; + timeinfo->tm_sec = 0; // Convert from struct tm to data type time_t userTime = mktime(timeinfo); // Compare user time and system time - if( difftime(userTime, time( &rawtime) ) > 0 ) { - + if (difftime(userTime, time( &rawtime)) > 0 ) return true; - } - - else { - - return false; - } + return false; } int AlarmWindow :: GetTime(int element) { // Variables struct tm *now; - time_t time_value; + bigtime_t time_value; // Initialize tm struct and time_t value now = NULL; @@ -304,15 +286,15 @@ int AlarmWindow :: GetTime(int element) { switch(element) { case 0: - return now -> tm_min; + return now->tm_min; case 1: - return now -> tm_hour; + return now->tm_hour; case 2: - return now -> tm_mday; + return now->tm_mday; case 3: - return now -> tm_mon + 1; + return now->tm_mon + 1; case 4: - return now -> tm_year + 1900; + return now->tm_year + 1900; default: return 0; diff --git a/source/AlarmWindow.h b/source/AlarmWindow.h index 0d6b9b9..de6e04d 100644 --- a/source/AlarmWindow.h +++ b/source/AlarmWindow.h @@ -15,13 +15,14 @@ #define ALARM_WINDOW_H -#include "AlarmView.h" - -#include -#include +#include +#include #include #include -#include +#include +#include +#include +#include // Window that allows the user to insert the alarm class AlarmWindow : public BWindow { @@ -35,16 +36,16 @@ class AlarmWindow : public BWindow { private: - AlarmView *fAlarmView; + BSpinner *fHour, + *fMinute, + *fDay, + *fMonth, + *fYear; - BTextControl *hour, - *minute, - *day, - *month, - *year; + BView *fTopView; BButton *fButtonOk; - BButton *fButtonUndo; + BButton *fButtonCancel; BMessenger *fMessenger; diff --git a/source/AppHashTable.cpp b/source/AppHashTable.cpp index b295055..3fc60b3 100644 --- a/source/AppHashTable.cpp +++ b/source/AppHashTable.cpp @@ -39,10 +39,10 @@ void AppHashTable :: AddNote (BString mySignature, BString myPath) { // This is the first node we will insert if (head == NULL) { newElement = new Hash(); - newElement -> signature = mySignature; - newElement -> notes[0] = myPath; - newElement -> numNotes = 1; - newElement -> nextHash = NULL; + newElement->signature = mySignature; + newElement->notes[0] = myPath; + newElement->numNotes = 1; + newElement->nextHash = NULL; // Initializing head and tail head = newElement; tail = newElement; // It points to the last element @@ -54,8 +54,8 @@ void AppHashTable :: AddNote (BString mySignature, BString myPath) { temp = new Hash(); found = 0; - for (temp = head; temp != NULL; temp = temp -> nextHash) { - if ( (temp->signature).Compare(mySignature) == 0){//if (strcmp(temp -> signature, mySignature) == 0) { + for (temp = head; temp != NULL; temp = temp->nextHash) { + if ((temp->signature).Compare(mySignature) == 0){ // Signature found found = 1; break; @@ -66,20 +66,20 @@ void AppHashTable :: AddNote (BString mySignature, BString myPath) { // Signature not found: we insert in the tail if (found == 0){ newElement = new Hash(); - newElement -> signature = mySignature; - newElement -> notes[0] = myPath; - newElement -> numNotes = 1; - newElement -> nextHash = NULL; + newElement->signature = mySignature; + newElement->notes[0] = myPath; + newElement->numNotes = 1; + newElement->nextHash = NULL; // The tail is pushed to the next element - tail -> nextHash = newElement; - tail = tail -> nextHash; + tail->nextHash = newElement; + tail = tail->nextHash; } // Signature found: we add there else { - int position = temp -> numNotes; + int position = temp->numNotes; - temp -> notes[position] = myPath; - temp -> numNotes ++; + temp->notes[position] = myPath; + temp->numNotes ++; } @@ -94,12 +94,12 @@ void AppHashTable :: DeleteNote (BString signature, BString note) { nNotes; Hash *temp = new Hash(); - for (temp = head; temp != NULL; temp = temp -> nextHash) { - if ( (temp -> signature).Compare(signature) == 0) + for (temp = head; temp != NULL; temp = temp->nextHash) { + if ( (temp->signature).Compare(signature) == 0) break; } - nNotes = temp -> numNotes; + nNotes = temp->numNotes; // There's only a note if (nNotes == 1){ @@ -110,23 +110,23 @@ void AppHashTable :: DeleteNote (BString signature, BString note) { } else { // It is the first note - if ((temp -> notes[0]).Compare(note) != 0) + if ((temp->notes[0]).Compare(note) != 0) // Looking for the node that has to be erased for (i = 1; i < nNotes && found != 1; i++) - if ((temp -> notes[i]).Compare(note) == 0) { + if ((temp->notes[i]).Compare(note) == 0) { found = i; break; } // Note found: I can erase it for (int j = found; j < nNotes; j++) { - temp -> notes[j] = temp -> notes[j + 1]; + temp->notes[j] = temp->notes[j + 1]; } - temp -> notes [nNotes - 1] = ""; - temp -> numNotes --; + temp->notes [nNotes - 1] = ""; + temp->numNotes --; } // There aren't any other notes in this signature - if (temp -> numNotes == 0) { + if (temp->numNotes == 0) { // I look for the signature that I have to erase if (!head->nextHash){ @@ -135,14 +135,14 @@ void AppHashTable :: DeleteNote (BString signature, BString note) { } else - if ((head -> signature).Compare(signature) == 0) { + if ((head->signature).Compare(signature) == 0) { // Erase from the head - head = head -> nextHash; + head = head->nextHash; } else { - for (temp = head; temp->nextHash; temp = temp -> nextHash){ - if ((temp -> nextHash -> signature).Compare(signature) == 0) + for (temp = head; temp->nextHash; temp = temp->nextHash){ + if ((temp->nextHash->signature).Compare(signature) == 0) break; } @@ -158,7 +158,7 @@ void AppHashTable :: DeleteNote (BString signature, BString note) { } - temp -> nextHash = temp -> nextHash -> nextHash; + temp->nextHash = temp->nextHash->nextHash; } } } @@ -169,7 +169,7 @@ int AppHashTable :: GetNumSignatures() { Hash *temp = new Hash(); int count = 0; - for (temp = head; temp != NULL; temp = temp -> nextHash) + for (temp = head; temp != NULL; temp = temp->nextHash) count ++; return count; @@ -181,9 +181,9 @@ int AppHashTable :: GetNumNotes(BString mySignature) { Hash *temp = new Hash(); int count = 0; - for (temp = head; temp != NULL; temp = temp -> nextHash) - if ( (temp->signature).Compare(mySignature) == 0){ //if (strcmp(temp -> signature, mySignature) == 0) { - count = temp -> numNotes; + for (temp = head; temp != NULL; temp = temp->nextHash) + if ( (temp->signature).Compare(mySignature) == 0){ //if (strcmp(temp->signature, mySignature) == 0) { + count = temp->numNotes; break; } @@ -196,9 +196,9 @@ char* AppHashTable ::GetNote (BString mySignature, int position) { Hash *temp = new Hash(); BString note = NULL; - for (temp = head; temp != NULL; temp = temp -> nextHash) - if ((temp->signature).Compare(mySignature) == 0){ //if (strcmp (temp -> signature, mySignature) == 0) { - note = temp -> notes[position]; + for (temp = head; temp != NULL; temp = temp->nextHash) + if ((temp->signature).Compare(mySignature) == 0){ //if (strcmp (temp->signature, mySignature) == 0) { + note = temp->notes[position]; break; } @@ -212,9 +212,9 @@ char* AppHashTable :: GetSignature (int position) { temp = head; for (int i = 0; i < position; i++) - temp = temp -> nextHash; + temp = temp->nextHash; - return (char *)(temp -> signature).String(); + return (char *)(temp->signature).String(); } bool AppHashTable :: HasElement(){ diff --git a/source/ChoiceView.cpp b/source/ChoiceView.cpp index da8c6ac..32ee320 100644 --- a/source/ChoiceView.cpp +++ b/source/ChoiceView.cpp @@ -30,6 +30,13 @@ #define BUTTON_OK 'btok' #define BUTTON_UNDO 'btun' +//translation +#include +#include + +#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){ @@ -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; diff --git a/source/ChoiceWindow.cpp b/source/ChoiceWindow.cpp index 726b15b..69fecaf 100644 --- a/source/ChoiceWindow.cpp +++ b/source/ChoiceWindow.cpp @@ -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:{ diff --git a/source/ColorMenuItem.cpp b/source/ColorMenuItem.cpp index 65c38b0..4f7fc49 100644 --- a/source/ColorMenuItem.cpp +++ b/source/ColorMenuItem.cpp @@ -8,7 +8,7 @@ * * Last revision: Eleonora Ciceri, 16h May 2009 * - * Description: Coloured item of the menu "Font -> Color" + * Description: Coloured item of the menu "Font->Color" */ // Libraries @@ -27,9 +27,9 @@ void ColorMenuItem :: DrawContent() { rgb_color menuC; if (menu) { - menuC = menu -> HighColor(); - menu -> SetHighColor (fColor); + menuC = menu->HighColor(); + menu->SetHighColor (fColor); BMenuItem :: DrawContent(); - menu -> SetHighColor (menuC); + menu->SetHighColor (menuC); } -} \ No newline at end of file +} diff --git a/source/ColorView.cpp b/source/ColorView.cpp deleted file mode 100644 index 97a186b..0000000 --- a/source/ColorView.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2009, Ilio Catallo, Stefano Celentano, Eleonora Ciceri, all rights reserved - * Distribuited under the terms of the GPL v2 license - * - * Authors: - * - * Ilio Catallo - * Eleonora Ciceri - * - * Last revision: Eleonora Ciceri, 23th June 2009 - * - * Description: View that allows you to change the background color - */ - -// Libraries -#include "ColorView.h" -#include "StringView.h" - -// Messages -#define COLOR_CHANGED 'ccrq' - -// Constructor -ColorView :: ColorView(BRect rect, char *name,BHandler *handler) - : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW){ -} - -// Font -void ColorView :: AttachedToWindow() { - SetFont (be_bold_font); - SetFontSize(12); -} - -// 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) { - -} diff --git a/source/ColorView.h b/source/ColorView.h deleted file mode 100644 index 1e64c56..0000000 --- a/source/ColorView.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2009, Ilio Catallo, Stefano Celentano, Eleonora Ciceri, all rights reserved - * Distribuited under the terms of the GPL v2 license - * - * Authors: - * - * Ilio Catallo - * Eleonora Ciceri - * - * Last revision: Eleonora Ciceri, 23th June 2009 - * - * Description: Header of the ColorView - */ - -#ifndef COLOR_VIEW_H -#define COLOR_VIEW_H - -#include -#include -#include - -// Definition of the class -class ColorView : public BView { - - public: - - ColorView (BRect frame, char *name, BHandler *handler); - virtual void AttachedToWindow (); - virtual void Draw(BRect updateRect); - virtual void MouseDown(BPoint point); -}; - -#endif diff --git a/source/ColorWindow.cpp b/source/ColorWindow.cpp index 8365b47..4acbe43 100644 --- a/source/ColorWindow.cpp +++ b/source/ColorWindow.cpp @@ -8,58 +8,77 @@ * Eleonora Ciceri * * Last revision: Eleonora Ciceri, 23th June 2009 - * + * December 2020: thaflo: Change color directly (that's the Be way) * Description: Window that is opened to change the background color */ #include "ColorWindow.h" +#include "NoteText.h" +#include +#include // Libraries #include #include +#include +#include +#include +#include // Messages #define COLOR_CHANGED 'ccrq' -#define BUTTON_OK 'btok' -#define BUTTON_UNDO 'btun' +#define BUTTON_REVERT 'btrv' +#define SET_DEFAULT_COLOR 'stdc' #define COLOR_CLOSE '_clc' +#define COLOR_CHOSEN '_cch' +#define COLOR 'colo' +#define SAVE 'save' + +//translation +#include +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "ColorWindow" /* * Constructor * It is created with the dimensions of BRect */ -ColorWindow :: ColorWindow (BRect frame, BHandler *handler) - : BWindow (frame, "Change the background color", B_TITLED_WINDOW,B_NOT_RESIZABLE) { +ColorWindow :: ColorWindow (BRect frame, BHandler *handler, rgb_color color) + : BWindow (frame, B_TRANSLATE("Change the note's background color"), B_TITLED_WINDOW, B_NOT_RESIZABLE) { // Variables - BPoint leftTop(20.0, 50.0); - color_control_layout matrix; - long cellSide; - - BButton *okButton; - BButton *undoButton; + BPoint leftTop(10.0, 10.0); - // Create the view and set the background color, then add child to window - frame.OffsetTo(B_ORIGIN); - fColorView = new ColorView (frame, "ColorView",handler); - fColorView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(fColorView); + BButton *revertButton; + BButton *setAsDefaultButton; // Drawing... fMessenger = new BMessenger(handler); - matrix = B_CELLS_16x16; - cellSide = 16; + fColorControl = new BColorControl (leftTop, B_CELLS_32x8, 9, "ColorControl", new BMessage(COLOR_CHANGED)); + fColorControl->SetValue(color); - fColorControl = new BColorControl (leftTop, matrix, cellSide, "ColorControl"); - fColorView -> AddChild(fColorControl); + revertButton = new BButton ("default", B_TRANSLATE("Defaults"), new BMessage(BUTTON_REVERT)); + setAsDefaultButton = new BButton ("default_color", + B_TRANSLATE("Set as default for new notes"), new BMessage(SET_DEFAULT_COLOR)); - okButton = new BButton (BRect(280, 320, 350, 350), "ok", "Change", new BMessage(BUTTON_OK)); - fColorView -> AddChild(okButton); + //use Haiku's layout management + SetLayout(new BGroupLayout(B_VERTICAL)); - undoButton = new BButton (BRect(200, 320, 270, 350), "undo", "Undo", new BMessage(BUTTON_UNDO)); - fColorView -> AddChild(undoButton); + BView* topView = new BGroupView(B_VERTICAL); + BLayoutBuilder::Group<>(topView, B_VERTICAL, 0.0f) + .SetInsets(B_USE_WINDOW_INSETS) + .Add(fColorControl) + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(revertButton) + .Add(setAsDefaultButton) + .End(); + + AddChild(topView); Show(); } @@ -70,36 +89,32 @@ void ColorWindow :: MessageReceived (BMessage* message) { BMessage *msg; BAlert *alert; - message->PrintToStream(); - - switch (message -> what) { - - // It answer to an OK request - case BUTTON_OK: { - + switch (message->what) { + case COLOR_CHANGED: { // I catch the color that was chosen by the user - userColorChoice = fColorControl -> ValueAsColor(); + userColorChoice = fColorControl->ValueAsColor(); // Sending the message... msg = new BMessage (COLOR_CHANGED); - msg -> AddInt8 ("red", (int8)userColorChoice.red); - msg -> AddInt8 ("green", (int8)userColorChoice.green); - msg -> AddInt8 ("blue", (int8)userColorChoice.blue); + msg->AddInt8 ("red", (int8)userColorChoice.red); + msg->AddInt8 ("green", (int8)userColorChoice.green); + msg->AddInt8 ("blue", (int8)userColorChoice.blue); fMessenger->SendMessage(msg); - Quit(); + } + break; + + // It answer to an REVERT request + case BUTTON_REVERT: { + fColorControl->SetValue(gBgColor); + this->PostMessage(COLOR_CHANGED); } break; - // It answer to an UNDO request - case BUTTON_UNDO: { - - alert = new BAlert("", "Latest changes will be discarded", "Yes", "No", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); - alert->SetShortcut(0, B_ESCAPE); - - if (alert->Go() == 0) { - // Discard all the changes - Quit(); - } + // It answer to SET AS DEFAULT request + case SET_DEFAULT_COLOR: { + msg = new BMessage(SET_DEFAULT_COLOR); + msg->AddColor("new_def_color", fColorControl->ValueAsColor()); + fMessenger->SendMessage(msg); } break; @@ -116,6 +131,7 @@ void ColorWindow :: Quit(){ BMessage *message; // Inform NoteWindow that this window is going to be closed + fMessenger->SendMessage(message); message = new BMessage (COLOR_CLOSE); fMessenger->SendMessage(message); diff --git a/source/ColorWindow.h b/source/ColorWindow.h index e52884a..2253242 100644 --- a/source/ColorWindow.h +++ b/source/ColorWindow.h @@ -16,9 +16,8 @@ #ifndef COLOR_WINDOW_H #define COLOR_WINDOW_H -#include "ColorView.h" - #include +#include // Declaration of the class @@ -26,15 +25,16 @@ class ColorWindow : public BWindow { public: - ColorWindow(BRect frame, BHandler *handler); + ColorWindow(BRect frame, BHandler *handler, rgb_color); virtual bool QuitRequested(); virtual void MessageReceived(BMessage*); virtual void Quit(); + const rgb_color gBgColor = {255,240,113}; + private: BColorControl *fColorControl; - ColorView *fColorView; BMessenger *fMessenger; }; diff --git a/source/Makefile b/source/Makefile index 62c638c..0e85557 100644 --- a/source/Makefile +++ b/source/Makefile @@ -16,15 +16,15 @@ NAME= TakeNotes # DRIVER: Kernel Driver TYPE= APP -# if you plan to use localization features +# if you plan to use localization features # specify the application MIME siganture -APP_MIME_SIG= +APP_MIME_SIG= application/x-vnd.TakeNotes # add support for new Pe and Eddie features # to fill in generic makefile #%{ -# @src->@ +# @src->@ # specify the source files to use # full paths or paths relative to the makefile can be included @@ -34,23 +34,38 @@ APP_MIME_SIG= # if two source files with the same name (source.c or source.cpp) # are included from different directories. Also note that spaces # in folder names do not work well with this makefile. -SRCS= AlarmView.cpp AlarmWindow.cpp \ -AppHashTable.cpp \ -ChoiceView.cpp ChoiceWindow.cpp \ -ColorMenuItem.cpp ColorView.cpp ColorWindow.cpp \ -NoteApplication.cpp NoteRefFilter.cpp NoteText.cpp NoteView.cpp NoteWindow.cpp \ -TagsWindow.cpp +SRCS = \ + AlarmWindow.cpp \ + AppHashTable.cpp \ + ChoiceView.cpp \ + ChoiceWindow.cpp \ + ColorMenuItem.cpp \ + ColorWindow.cpp \ + NoteApplication.cpp \ + NoteRefFilter.cpp \ + NoteText.cpp \ + NoteView.cpp \ + NoteWindow.cpp \ + TagsWindow.cpp \ + # specify the resource definition files to use # full path or a relative path to the resource file can be used. -RDEFS= TakeNotes.rdef - -# specify the resource files to use. +RDEFS = \ + TakeNotes.rdef \ + + +# specify the resource files to use. # full path or a relative path to the resource file can be used. # both RDEFS and RSRCS can be defined in the same makefile. -RSRCS= +RSRCS = \ + + +# @<-src@ +#%} + +#%} -# @<-src@ #%} # end support for Pe and Eddie @@ -66,12 +81,12 @@ RSRCS= # # - for localization support add following libs: # locale localestub -# +# # - if your library does not follow the standard library # naming scheme you need to specify the path to the library # and it's name # library: my_lib.a entry: my_lib.a or path/my_lib.a -LIBS= be tracker $(STDCPPLIBS) +LIBS= be localestub shared translation tracker $(STDCPPLIBS) # specify additional paths to directories following the standard # libXXX.so or libXXX.a naming scheme. You can specify full paths @@ -79,21 +94,21 @@ LIBS= be tracker $(STDCPPLIBS) # be recursive, so include all of the paths where libraries can # be found. Directories where source files are found are # automatically included. -LIBPATHS= +LIBPATHS= # additional paths to look for system headers # thes use the form: #include
# 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" # source file directories are automatically included -LOCAL_INCLUDE_PATHS = +LOCAL_INCLUDE_PATHS = # specify the level of optimization that you desire # NONE, SOME, FULL -OPTIMIZE= +OPTIMIZE= # specify here the codes for languages you are going # to support in this application. The default "en" @@ -101,30 +116,30 @@ OPTIMIZE= # locales/en.catkeys file. Use it as template for creating other # languages catkeys. All localization files must be placed # in "locales" sub-directory. -LOCALES= +LOCALES= en de # specify any preprocessor symbols to be defined. The symbols will not # have their values set automatically; you must supply the value (if any) # to use. For example, setting DEFINES to "DEBUG=1" will cause the # compiler option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" # would pass "-DDEBUG" on the compiler's command line. -DEFINES= +DEFINES= # specify special warning levels # if unspecified default warnings will be used # NONE = supress all warnings # ALL = enable all warnings -WARNINGS = +WARNINGS = # specify whether image symbols will be created # so that stack crawls in the debugger are meaningful # if TRUE symbols will be created -SYMBOLS = +SYMBOLS = # specify debug settings # if TRUE will allow application to be run from a source-level # debugger. Note that this will disable all optimzation. -DEBUGGER = +DEBUGGER = # specify additional compiler flags for all files COMPILER_FLAGS = @@ -133,16 +148,16 @@ COMPILER_FLAGS = LINKER_FLAGS = # specify the version of this particular item -# (for example, -app 3 4 0 d 0 -short 340 -long "340 "`echo -n -e '\302\251'`"1999 GNU GPL") +# (for example, -app 3 4 0 d 0 -short 340 -long "340 "`echo -n -e '\302\251'`"1999 GNU GPL") # This may also be specified in a resource. -APP_VERSION = +APP_VERSION = # (for TYPE == DRIVER only) Specify desired location of driver in the /dev # hierarchy. Used by the driverinstall rule. E.g., DRIVER_PATH = video/usb will # instruct the driverinstall rule to place a symlink to your driver's binary in # ~/add-ons/kernel/drivers/dev/video/usb, so that your driver will appear at # /dev/video/usb when loaded. Default is "misc". -DRIVER_PATH = +DRIVER_PATH = ## include the makefile-engine DEVEL_DIRECTORY := \ diff --git a/source/NoteApplication.cpp b/source/NoteApplication.cpp index 042ff3f..901ced3 100644 --- a/source/NoteApplication.cpp +++ b/source/NoteApplication.cpp @@ -7,7 +7,7 @@ * Ilio Catallo * Eleonora Ciceri * - * Last revision: Ilio Catallo, 26th June 2009 + * Last revision: Florian Thaler, 26th January 2021 * * Description: This is the application, with all the functions implemented. * This is the main container of the functions related to an application. @@ -15,6 +15,7 @@ // Our Libraries #include "NoteApplication.h" +#include // Libraries #include @@ -24,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -42,8 +46,12 @@ // Constants #define COLOR_CHANGED 'ccrq' #define FONT_BOLD 'fntb' +#define NEW 'new' #define OPEN 'open' +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "NoteApplication" + // Global variables NoteApplication *note_app; @@ -52,6 +60,7 @@ const char* kSignature = "application/x-vnd.ccc-TakeNotes"; const char* kDeskbarSignature = "application/x-vnd.Be-TSKB"; const char* kDeskbarItemName = "TakeNotes"; + /* * This function fills the image_info image struct with the app image of itself * and eventually return B_OK @@ -82,15 +91,31 @@ NoteApplication :: NoteApplication() * Creation of the directory with the association between notes * and applications */ - DIR *dir; - dir = opendir("/boot/home/config/settings/TakeNotes"); - if (dir == NULL) - mkdir ("/boot/home/config/settings/TakeNotes", O_CREAT); + + status_t ret = B_BAD_VALUE; + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) == B_OK) { + if (ret = path.Append("TakeNotes") == B_OK) + ret = create_directory(path.Path(), 0777); + } // Private data members initialization fWindowCount = 0; note_app = this; + // Open the config file, if it doesn't exist we create it + // BFile settings; + // status_t err; + // if ((err = settings.SetTo(B_USER_SETTINGS_DIRECTORY + "TakeNotes", B_READ_WRITE | B_CREATE_FILE)) != B_OK){ + // printf("%s\n",err); + // } + + //thaflo 2021: load global settings + fSettingsMessage = new BMessage(); + load_settings(fSettingsMessage, "settings", "TakeNotes"); + if (fSettingsMessage->GetBool("live_in_deskbar") == true) + _InstallReplicantInDeskbar(); + // Create the file open panel fOpenPanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL, B_FILE_NODE, true, NULL, &fNoteRefFilter); @@ -106,28 +131,46 @@ NoteApplication::~NoteApplication() void NoteApplication :: ReadyToRun(){ // Variables - BDeskbar deskbar; + BDeskbar fDeskbar; BAlert *alert; + short int erg; // Check if the replicant isn't already installed in the Deskbar, avoid to ask if we already opened a note - if (!deskbar.HasItem(kDeskbarItemName) && fWindowCount == 0){ + if (!fDeskbar.HasItem(kDeskbarItemName) && fWindowCount == 0 && (fSettingsMessage->GetBool("live_in_deskbar")) == false){ - alert = new BAlert("", "Do you want TakeNotes to live in the Deskbar?", "Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert = new BAlert("", B_TRANSLATE("Do you want TakeNotes to live in the Deskbar?"), B_TRANSLATE("Maybe later"), B_TRANSLATE("No thanks"), B_TRANSLATE("Install"), B_WIDTH_AS_USUAL, B_INFO_ALERT); alert->SetShortcut(0, B_ESCAPE); + erg = alert->Go(); // In case we have to install it in the deskbar... - if (alert->Go() == 1) { + if (erg == 2) { _InstallReplicantInDeskbar(); + fSettingsMessage->SetBool("live_in_deskbar", true); + save_settings(fSettingsMessage, "settings", "TakeNotes"); return; } - + if (erg == 1) { + fSettingsMessage->SetBool("live_in_deskbar", false); + save_settings(fSettingsMessage, "settings", "TakeNotes"); + } } - // If there's some window opened return + // If there's some window open return if (fWindowCount > 0) return; + // If there aren't windows opened, we open a note - else - OpenNote(); + // thaflo 2020: load defaults and last used note + entry_ref *fRef = new entry_ref; + + if (load_settings(fSettingsMessage, "settings", "TakeNotes") != B_OK) { + printf("open settings failed \n"); + + } else { + if (fSettingsMessage->FindBool("load_last_note") == TRUE) + fSettingsMessage->FindRef("last_note", fRef); + } + + OpenNote(fRef); } // Function CheckMime @@ -269,7 +312,6 @@ status_t NoteApplication :: CheckMime(){ void NoteApplication::OpenNote(entry_ref *ref) { - if (ref == NULL) { new NoteWindow(); fWindowCount++; @@ -278,9 +320,12 @@ NoteApplication::OpenNote(entry_ref *ref) entry_ref linkedRef; BEntry entry(ref, true); - if(entry.InitCheck() != B_OK || !entry.Exists() || - entry.GetRef(&linkedRef) != B_OK) + if (entry.InitCheck() != B_OK || !entry.Exists() || + entry.GetRef(&linkedRef) != B_OK) { + new NoteWindow(); + fWindowCount++; return; + } for (int32 i = 0; i < CountWindows(); i++) { NoteWindow *noteWin = dynamic_cast(WindowAt(i)); @@ -291,6 +336,7 @@ NoteApplication::OpenNote(entry_ref *ref) noteWin->Activate(); return; } + new NoteWindow(&linkedRef); fWindowCount++; } @@ -300,7 +346,6 @@ void NoteApplication :: CloseNote(){ fWindowCount--; if (fWindowCount == 0){ - BAutolock lock(this); Quit(); } @@ -313,6 +358,7 @@ void NoteApplication :: ArgvReceived(int32 argc, char** argv){ // Variables const char *cwd = ""; BMessage *message = CurrentMessage(); + fSettingsMessage = new BMessage(); // Extract the cwd (current working directory) if (message != NULL){ @@ -340,32 +386,46 @@ void NoteApplication :: ArgvReceived(int32 argc, char** argv){ get_ref_for_path(path.Path(), &ref); // Open a note + entry_ref *fRef = new entry_ref; + fRef = &ref; + + // load settings so we can set the appropriate mark on the "open last note on startup" menu + if (load_settings(fSettingsMessage, "settings", "TakeNotes") != B_OK) + printf("couldn't load settings\n"); + OpenNote(&ref); } } // Function RefsReceived void NoteApplication :: RefsReceived(BMessage *message){ - // Variables int32 index = 0; entry_ref ref; + fSettingsMessage = new BMessage(); + + if (load_settings(fSettingsMessage, "settings", "TakeNotes") != B_OK) + printf("couldn't load settings\n"); - while(message->FindRef("refs", index++, &ref) == B_OK){ + while (message->FindRef("refs", index++, &ref) == B_OK){ OpenNote(&ref); } } // Function used to receive messages void NoteApplication :: MessageReceived(BMessage *message){ - // Search if the message that was caputed is handled by the application - switch(message->what){ + switch (message->what){ case OPEN: fOpenPanel->Show(); break; + case NEW: + new NoteWindow(); + fWindowCount++; + break; + case B_SILENT_RELAUNCH: OpenNote(); break; @@ -393,13 +453,13 @@ void NoteApplication :: _InstallReplicantInDeskbar(){ BPath path(&ref); // Initialize the deskbar object - BDeskbar deskbar; + BDeskbar fDeskbar; // If the deskbar is running we finally install - if (!deskbar.IsRunning()) + if (!fDeskbar.IsRunning()) return; - if (deskbar.AddItem(&ref) != B_OK) + if (fDeskbar.AddItem(&ref) != B_OK) return; } else @@ -409,7 +469,9 @@ void NoteApplication :: _InstallReplicantInDeskbar(){ * Quit the application, an indipendent instance of TakeNotes is now running * as a replicant in the Deskbar */ - Quit(); + if (fWindowCount == 0) { + //Quit(); ends in debugger + } } // Main @@ -420,3 +482,74 @@ int main(){ myApp.Run(); return(0); } + +// Function that shows about window +void NoteApplication :: AboutRequested() +{ + + BAboutWindow* about = new BAboutWindow("TakeNotes", kSignature); + + const char* authors[] = { + "Ilio Catallo", + "Stefano Celentano", + "Eleonora Ciceri", + "Florian Thaler", + NULL + }; + + about->AddCopyright(2021, "Ilio Catallo & others"); + about->AddAuthors(authors); + about->AddText(B_TRANSLATE("Distribuited under the terms of the GPLv2 license")); + about->AddText(B_TRANSLATE("Icons by Meanwhile")); + about->Show(); +} + + +//stolen from LaunchBox->support.cpp +//thanks Stippi! + +status_t +load_settings(BMessage* message, const char* fileName, const char* folder) +{ + status_t ret = B_BAD_VALUE; + if (message) { + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) == B_OK) { + // passing folder is optional + if (folder) + ret = path.Append( folder ); + if (ret == B_OK && (ret = path.Append(fileName)) == B_OK ) { + BFile file(path.Path(), B_READ_ONLY); + if ((ret = file.InitCheck()) == B_OK) { + ret = message->Unflatten(&file); + file.Unset(); + } + } + } + } + return ret; +} + + +status_t +save_settings(BMessage* message, const char* fileName, const char* folder) +{ + status_t ret = B_BAD_VALUE; + if (message) { + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) == B_OK) { + // passing folder is optional + if (folder && (ret = path.Append(folder)) == B_OK) + ret = create_directory(path.Path(), 0777); + if (ret == B_OK && (ret = path.Append(fileName)) == B_OK) { + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE + | B_ERASE_FILE); + if ((ret = file.InitCheck()) == B_OK) { + ret = message->Flatten(&file); + file.Unset(); + } + } + } + } + return ret; +} diff --git a/source/NoteApplication.h b/source/NoteApplication.h index 095648c..099784b 100644 --- a/source/NoteApplication.h +++ b/source/NoteApplication.h @@ -20,10 +20,10 @@ #include "NoteRefFilter.h" #include +#include #include #include - // Definition of the class class NoteApplication : public BApplication { @@ -36,15 +36,20 @@ class NoteApplication : public BApplication { virtual void RefsReceived(BMessage* message); virtual void MessageReceived(BMessage* message); virtual void ReadyToRun(); + status_t Test(); void _InstallReplicantInDeskbar(); void OpenNote(entry_ref* ref = NULL); void CloseNote(); - status_t CheckMime(); - private: + void AboutRequested(); + status_t CheckMime(); + BMessage* fSettingsMessage; int32 fWindowCount; + BDeskbar* fDeskbar; + + private: BFilePanel *fOpenPanel; NoteRefFilter fNoteRefFilter; diff --git a/source/NoteText.cpp b/source/NoteText.cpp index 4aede7a..e46b3f1 100644 --- a/source/NoteText.cpp +++ b/source/NoteText.cpp @@ -28,7 +28,7 @@ #define TEXT_INSET 10 // Costructor -NoteText :: NoteText(BRect frame, BRect frameText, char *name, BHandler *handler) +NoteText :: NoteText(BRect frame, BRect frameText, const char *name, BHandler *handler) : BTextView(frame, name, frameText, B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE){ // Initialization @@ -36,7 +36,7 @@ NoteText :: NoteText(BRect frame, BRect frameText, char *name, BHandler *handler fReplicated = false; // Background color - SetViewColor(254, 254, 92, 255); + SetViewColor(255,240,113); } @@ -63,7 +63,7 @@ status_t NoteText :: Archive (BMessage *msg, bool deep) const{ /* * Flags the message with the information regarding the application and the class name - * This informations are required and they will be used by the costructor by message + * This informations are required and they will be used by the costructor by message * to rehydrate the replicant */ msg->AddString("add_on","application/x-vnd.ccc-TakeNotes"); @@ -92,17 +92,17 @@ void NoteText :: MessageReceived(BMessage *message){ // Cut request case B_CUT: - this -> Cut(be_clipboard); + this->Cut(be_clipboard); break; // Copy Request case B_COPY: - this -> Copy(be_clipboard); + this->Copy(be_clipboard); break; // Paste Request case B_PASTE: - this -> Paste(be_clipboard); + this->Paste(be_clipboard); break; // All the other messages are forwarded to the superclass method diff --git a/source/NoteText.h b/source/NoteText.h index 682526e..3e5ee91 100644 --- a/source/NoteText.h +++ b/source/NoteText.h @@ -6,12 +6,11 @@ * * Ilio Catallo * - * Last revision: Ilio Catallo, 29th June 2009 + * Last revision: thaflo, december 2020 * * Description: Header of the NoteText */ - #ifndef NOTE_TEXT_H #define NOTE_TEXT_H @@ -28,7 +27,7 @@ class NoteText : public BTextView { public: - NoteText(BRect frame, BRect frameText, char *name,BHandler *handler); + NoteText(BRect frame, BRect frameText, const char *name,BHandler *handler); NoteText(BMessage *message); ~NoteText(); static BArchivable* Instantiate(BMessage *msg); @@ -43,7 +42,6 @@ class NoteText : public BTextView { bool GetReplicated(); void SetHandler(BHandler *handler); - private: bool fReplicated; diff --git a/source/NoteView.cpp b/source/NoteView.cpp index 3a7ef8a..812c83f 100644 --- a/source/NoteView.cpp +++ b/source/NoteView.cpp @@ -8,7 +8,7 @@ * Stefano Celentano * Eleonora Ciceri * - * Last revision: Ilio Catallo, 29th June 2009 + * Last revision: thaflo, december 2020 * * Description: View of the note. It can be implemented in three instances: * - the view in the deskbar is the controller of the application @@ -19,6 +19,7 @@ // Our libraries #include "NoteApplication.h" #include "NoteView.h" +#include // Other libraries #include @@ -35,6 +36,13 @@ #include #include +//translation +#include +#include + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "NoteView" + // System libraries #include #include @@ -45,6 +53,8 @@ #define OPEN_TAKENOTES 'onwp' #define OPEN_FILE 'onfl' #define REMOVE_ASSOCIATION 'rmsc' +#define SETTINGS_CLOSE 'settc' +#define OPEN_NEW_NOTE 'opnn' // Constructor NoteView :: NoteView(BRect frame, int32 resizingMode, bool inDeskbar, BHandler *handler) @@ -237,8 +247,10 @@ void NoteView :: MouseDown(BPoint point){ menu->SetFont(be_plain_font); // Fill the menu - menu->AddItem(new BMenuItem("Open TakeNotes" B_UTF8_ELLIPSIS,new BMessage(OPEN_TAKENOTES))); - menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); + menu->AddItem(new BMenuItem(B_TRANSLATE("Open TakeNotes" B_UTF8_ELLIPSIS),new BMessage(OPEN_TAKENOTES))); + menu->AddItem(new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED))); + menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED))); + if (fHash->HasElement()) menu->AddSeparatorItem(); // Initialization @@ -264,39 +276,39 @@ void NoteView :: MouseDown(BPoint point){ name.Compare("media_addon_server") != 0 && name.Compare("afp_server") != 0 && name.Compare("debug_server") != 0) { // Obtain the signature number - countSignatures = fHash -> GetNumSignatures(); + countSignatures = fHash->GetNumSignatures(); // For each signature in the list we check if it is the hash table and in case we add it to the menu for (int i = 0; i < countSignatures; i++) { - sig = fHash -> GetSignature(i); - if (strcmp (appInfo -> signature, sig) == 0) { + sig = fHash->GetSignature(i); + if (strcmp (appInfo->signature, sig) == 0) { subMenu = new BMenu (ref.name); // Make the list of the notes releated to that application - int countNotes = fHash -> GetNumNotes(sig); + int countNotes = fHash->GetNumNotes(sig); for (int j = 0; j < countNotes; j++) { // Obtain the current note path - note = fHash -> GetNote(sig, j); + note = fHash->GetNote(sig, j); // Create the list of notes for a given application mess = new BMessage(OPEN_FILE); - mess -> AddString("Note", note); + mess->AddString("Note", note); messRemove = new BMessage (REMOVE_ASSOCIATION); - messRemove -> AddString ("Note", note); - messRemove -> AddString ("Signature", sig); + messRemove->AddString ("Note", note); + messRemove->AddString ("Signature", sig); // Sub-menu useful to open or remove a note noteMenu = new BMenu (note); - noteMenu -> AddItem (new BMenuItem ("Open", mess)); - noteMenu -> AddItem (new BMenuItem ("Remove the association", messRemove)); - noteMenu -> SetTargetForItems(this); - subMenu -> AddItem (noteMenu); + noteMenu->AddItem (new BMenuItem ("Open", mess)); + noteMenu->AddItem (new BMenuItem ("Remove the association", messRemove)); + noteMenu->SetTargetForItems(this); + subMenu->AddItem (noteMenu); } - subMenu -> SetTargetForItems(this); - menu -> AddItem (subMenu); + subMenu->SetTargetForItems(this); + menu->AddItem (subMenu); } } @@ -332,14 +344,14 @@ status_t NoteView :: Archive (BMessage *msg,bool deep) const{ /* * Flags the message with the information regarding the application and the class name - * This informations are required and they will be used by the costructor by message + * This informations are required and they will be used by the costructor by message * to rehydrate the replicant */ msg->AddString("add_on","application/x-vnd.ccc-TakeNotes"); msg->AddString("class","NoteView"); - // If the function has been called by NoteWindow::Save we should find this information and use them to save - if (msg->FindRef("directory",&ref) == B_OK && msg -> FindString("name", &name) == B_OK) { + // If the function has been called by NoteWindow::Save we should find this information and use them to save + if (msg->FindRef("directory",&ref) == B_OK && msg->FindString("name", &name) == B_OK) { dir.SetTo(&ref); if ((err = dir.InitCheck()) != B_OK) @@ -375,20 +387,6 @@ BArchivable* NoteView :: Instantiate(BMessage *msg){ } -// Hook function-override,that shows some information about us and our work -void NoteView :: AboutRequested(){ - - // Variable - BAlert *alert; - - alert = new BAlert("About TakeNotes", - "Copyright 2009\n\nIlio Catallo,\nStefano Celentano,\nEleonora Ciceri.\n\nall rights reserved, distribuited under the terms of the GPLv2 license\n\nIcons by Meanwhile", - "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); - alert->SetShortcut(0,B_ESCAPE); - alert->Go(); - -} - /* * Functions that save to FS the associations between applications and notes * It saves the whole Hash table structure to FS with the syntax: @@ -420,16 +418,16 @@ status_t NoteView :: _SaveDB(){ toWrite.SetTo(""); // Writing the structure, for each signature... - countSignatures = fHash -> GetNumSignatures(); + countSignatures = fHash->GetNumSignatures(); for (int i = 0; i < countSignatures; i++) { // Prepare the string - char* signature = fHash -> GetSignature(i); - countNotes = fHash -> GetNumNotes(signature); + char* signature = fHash->GetSignature(i); + countNotes = fHash->GetNumNotes(signature); // Parse the string for (int j = 0; j < countNotes; j++) { - char* note = fHash -> GetNote (signature, j); + char* note = fHash->GetNote (signature, j); printf(">>(FILE) nota: %d, path: %s\n", j, note); toWrite.Append(note); toWrite.Append(":"); @@ -452,11 +450,11 @@ void NoteView :: MessageReceived(BMessage *message){ // Variables char *argv[1]; - switch(message->what){ + switch (message->what){ // The user wants more information about us case B_ABOUT_REQUESTED: - AboutRequested(); + _AboutRequested(); break; // The user wants to open takenotes and write a new note @@ -464,14 +462,19 @@ void NoteView :: MessageReceived(BMessage *message){ _OpenTakeNotes(); break; + // The user wants to open a new note + case OPEN_NEW_NOTE: + be_roster->Launch("application/x-vnd.ccc-TakeNotes", 1, argv, NULL); + break; + // The user wants to open a note releated to an application that is currently running case OPEN_FILE:{ // Find the note path of the releated application - argv[0] = (char*)message -> FindString("Note"); + argv[0] = (char*)message->FindString("Note"); //Open the note - be_roster -> Launch("application/x-vnd.ccc-TakeNotes", 1, argv, NULL); + be_roster->Launch("application/x-vnd.ccc-TakeNotes", 1, argv, NULL); } break; @@ -483,7 +486,7 @@ void NoteView :: MessageReceived(BMessage *message){ BString s(message->FindString("Signature")); // Removing from the data structure - fHash -> DeleteNote (s, n); + fHash->DeleteNote (s, n); // Rewriting the file _SaveDB(); @@ -569,7 +572,7 @@ void NoteView :: _LoadDB(){ // Launch TakeNotes void NoteView :: _OpenTakeNotes(){ - be_roster->Launch("application/x-vnd.ccc-TakeNotes"); + be_roster->Launch("application/x-vnd.ccc-TakeNotes", new BMessage(OPEN_NEW_NOTE)); } @@ -582,12 +585,33 @@ void NoteView :: _Quit(){ deskbar.RemoveItem(kDeskbarItemName); } else { - be_app->PostMessage(B_QUIT_REQUESTED); } } +// About TakeNotes +void NoteView :: _AboutRequested(){ + + BAboutWindow* about = new BAboutWindow("TakeNotes", kSignature); + + const char* authors[] = { + "Ilio Catallo", + "Stefano Celentano", + "Eleonora Ciceri", + "Florian Thaler", + NULL + }; + + about->AddCopyright(2021, "Ilio Catallo & others"); + about->AddAuthors(authors); + about->AddText(B_TRANSLATE("Distributed under the terms of the GPLv2 license")); + about->AddText(B_TRANSLATE("Icons by Meanwhile")); + about->AddExtraInfo("extra info"); + about->Show(); + +} + /* * Setter function, NoteView::Archive is called several times in several different situations * (replicant creation, note loading, note saving). The default behaviour is to set @@ -621,6 +645,6 @@ void NoteView :: SetBackgroundColor(rgb_color color){ } extern "C" _EXPORT BView *instantiate_deskbar_item(void){ - + printf("extern C _export ...\n"); return new NoteView(BRect(0, 0, 15, 15), B_FOLLOW_LEFT | B_FOLLOW_TOP,true); } diff --git a/source/NoteView.h b/source/NoteView.h index 19218ff..05e0e6b 100644 --- a/source/NoteView.h +++ b/source/NoteView.h @@ -40,13 +40,13 @@ class NoteView : public BView { virtual void AttachedToWindow(); virtual void MessageReceived(BMessage *message); virtual void MouseDown(BPoint point); - virtual void AboutRequested(); + virtual void _AboutRequested(); static BArchivable* Instantiate(BMessage *msg); virtual status_t Archive(BMessage *msg, bool deep=true) const; void InitBitmap(); - void SetBackgroundColor(rgb_color color); + void SetBackgroundColor(rgb_color color); void _LoadDB(); status_t _SaveDB(); @@ -73,4 +73,4 @@ class NoteView : public BView { }; -#endif \ No newline at end of file +#endif diff --git a/source/NoteWindow.cpp b/source/NoteWindow.cpp index e2b1b8a..4ec1feb 100644 --- a/source/NoteWindow.cpp +++ b/source/NoteWindow.cpp @@ -20,7 +20,8 @@ // Other Libraries #include -#include +#include + #include #include #include @@ -33,12 +34,18 @@ #include #include #include +#include +#include +#include // System libraries #include #include #include +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "NoteWindow" + // Messages #define SET_COLOR 'mcg' #define COLOR_CHANGED 'ccrq' @@ -48,6 +55,7 @@ #define FONT_STYLE 'ftst' #define TEXT_CHANGED 'txch' #define ADD_DATA 'addd' +#define ADD_URL 'addu' #define SET_ALARM 'salr' #define SET_TAGS 'stag' #define SET_APP 'stap' @@ -55,7 +63,9 @@ #define GO_TO_LINK 'gtlk' #define ABOUT 'bout' #define CHECK_ALARM 'chal' +#define NEW 'new' #define OPEN 'open' +#define DELETE 'open' #define SAVE 'save' #define SAVE_AS 'svas' #define QUIT_APPL 'qtpp' @@ -65,11 +75,18 @@ #define TAGS_CLOSE '_tgc' #define ALARM_CLOSE '_alc' #define CHOICE_CLOSE '_chc' +#define NOTE_SETTINGS 'ntst' +#define SETTINGS_CLOSE '_sec' +#define SET_DEFAULT_COLOR 'stdc' +#define LOAD_LAST_NOTE 'llno' +#define LIVE_IN_DESKBAR 'lind' // Constants #define MENU_BAR_HEIGHT 18 #define TEXT_INSET 10 +using namespace std; + // Structures const struct tm gettime() { time_t t=time(NULL); @@ -79,7 +96,7 @@ const struct tm gettime() { // Constructor NoteWindow::NoteWindow() : - BWindow(BRect(100, 100, 350, 350), "Untitled", B_TITLED_WINDOW, + BWindow(BRect(100, 100, 350, 350), B_TRANSLATE("Untitled"), B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), fRef(NULL) { @@ -102,7 +119,7 @@ NoteWindow::NoteWindow() // Construtor NoteWindow :: NoteWindow(entry_ref *ref) : - BWindow(BRect(100, 100, 350, 350), "Untitled", B_TITLED_WINDOW, + BWindow(BRect(100, 100, 350, 350), B_TRANSLATE("Untitled note"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS), fRef(new entry_ref(*ref)) { @@ -114,10 +131,12 @@ NoteWindow :: NoteWindow(entry_ref *ref) BAlert *alert; BEntry entry(ref, true); // entry of possibly linked file BRect viewRect; - char name[B_FILE_NAME_LENGTH] = "Untitled"; + BString filename = B_TRANSLATE("Untitled note (filename)"); + char name[B_FILE_NAME_LENGTH] = "Untitled1"; bool isNoteFile = false; // readable takenotes file bool isNewFile = false; + // Initialize all the "static" elements like MenuBar,Menu,MenuItems and so on InitWindow(); @@ -172,7 +191,7 @@ NoteWindow :: NoteWindow(entry_ref *ref) // Fetch the view from the file msg->Unflatten(&f); - msg->PrintToStream(); +// msg->PrintToStream(); // Restore all the references for the NoteView's children fNoteView = new NoteView(msg); fScrollView = (BScrollView*) fNoteView->ChildAt(1); @@ -211,7 +230,7 @@ NoteWindow :: ~NoteWindow(){ // Initializing the window void NoteWindow :: InitWindow(){ - SetSizeLimits(250, 10000, 250, 10000); +// SetSizeLimits(250, 10000, 250, 10000); // Initialize the messenger: the handler is the window itself fMessenger = BMessenger(this); @@ -225,7 +244,8 @@ void NoteWindow :: InitWindow(){ BMenu *sizeFont, *colorFont, *fontMenu; - char *label; +// char *label; + BString label; font_family plainFamily, family; font_style plainStyle, @@ -242,7 +262,7 @@ void NoteWindow :: InitWindow(){ color; rgb_color colors[] = {black, red, green, blue, yellow}; - //Initialize the fSaveMessage + //Initialize the fSaveMessage and fSettingsMessage fSaveMessage = NULL; // Create an empty message @@ -258,128 +278,136 @@ void NoteWindow :: InitWindow(){ fCanUndo = false; // If there's no text I can't do undo fUndoFlag = false; + // Menu bar menuBarRect = Bounds(); menuBarRect.bottom = MENU_BAR_HEIGHT; fNoteMenuBar = new BMenuBar(menuBarRect,"Barra del menu"); // Menu - fFileMenu = new BMenu("File"); - fFontMenu = new BMenu("Font"); - fEditMenu = new BMenu("Edit"); - fSettingsMenu = new BMenu("Settings"); - fAboutMenu = new BMenu("About"); + fFileMenu = new BMenu(B_TRANSLATE("Note")); + fFontMenu = new BMenu(B_TRANSLATE("Font")); + fEditMenu = new BMenu(B_TRANSLATE("Edit")); + fSettingsMenu = new BMenu(B_TRANSLATE("Settings")); - fNoteMenuBar -> AddItem (fFileMenu); - fNoteMenuBar -> AddItem (fEditMenu); - fNoteMenuBar -> AddItem (fFontMenu); - fNoteMenuBar -> AddItem (fSettingsMenu); - fNoteMenuBar -> AddItem (fAboutMenu); + fNoteMenuBar->AddItem (fFileMenu); + fNoteMenuBar->AddItem (fEditMenu); + fNoteMenuBar->AddItem (fFontMenu); + fNoteMenuBar->AddItem (fSettingsMenu); + fNoteMenuBar->AddItem(new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED))); - fFontMenu -> SetRadioMode(true); + fFontMenu->SetRadioMode(true); /*************** Menu Item ***************/ // File menu - fFileMenu -> AddItem (fSaveItem = new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(OPEN), 'O')); - fSaveItem -> SetTarget(note_app); - fFileMenu -> AddSeparatorItem(); - fFileMenu -> AddItem (fSaveItem = new BMenuItem("Save", new BMessage(SAVE), 'S')); - fFileMenu -> AddItem (fSaveItem = new BMenuItem("Save as" B_UTF8_ELLIPSIS, new BMessage(SAVE_AS), 'S', B_SHIFT_KEY)); - fFileMenu -> AddSeparatorItem(); - fFileMenu -> AddItem (fQuitItem = new BMenuItem ("Quit", new BMessage (QUIT_APPL), 'Q')); + fFileMenu->AddItem (fNewItem = new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS), new BMessage(NEW), 'N')); + fFileMenu->AddItem (fOpenItem = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), new BMessage(OPEN), 'O')); + fNewItem->SetTarget(note_app); + fOpenItem->SetTarget(note_app); + + fFileMenu->AddSeparatorItem(); + fFileMenu->AddItem (fSaveItem = new BMenuItem(B_TRANSLATE("Save"), new BMessage(SAVE), 'S')); + fFileMenu->AddItem (fSaveItem = new BMenuItem(B_TRANSLATE("Save as" B_UTF8_ELLIPSIS), new BMessage(SAVE_AS), 'S', B_SHIFT_KEY)); + fFileMenu->AddSeparatorItem(); + fFileMenu->AddItem (fQuitItem = new BMenuItem (B_TRANSLATE("Quit"), new BMessage (QUIT_APPL), 'Q')); // Settings menu - fSettingsMenu -> AddItem (fChangeBackgroundColorItem = new BMenuItem ("Change background color", new BMessage (SET_COLOR))); - fSettingsMenu -> AddItem (fAddDateAndTimeItem = new BMenuItem ("Add date and time", new BMessage (ADD_DATA))); - fSettingsMenu -> AddItem (fSetAlarmItem = new BMenuItem ("Set alarm", new BMessage (SET_ALARM))); - fSettingsMenu -> AddItem (fSetTagsItem = new BMenuItem ("Set tags", new BMessage (SET_TAGS))); - fSettingsMenu -> AddItem (fSetAppItem = new BMenuItem ("Set preferred application", new BMessage (SET_APP))); - fSettingsMenu -> AddItem (fLink = new BMenuItem ("Go to the selected link", new BMessage (GO_TO_LINK))); + //: rename it at the end to "Add..." + fSettingsMenu->AddItem (fChangeBackgroundColorItem = new BMenuItem (B_TRANSLATE("Change background color"), new BMessage (SET_COLOR))); + fSettingsMenu->AddItem (fAddDateAndTimeItem = new BMenuItem (B_TRANSLATE("Insert date and time"), new BMessage (ADD_DATA))); + fSettingsMenu->AddItem (fSetAlarmItem = new BMenuItem (B_TRANSLATE("Set alarm"), new BMessage (SET_ALARM), 'L')); + fSettingsMenu->AddItem (fSetTagsItem = new BMenuItem (B_TRANSLATE("Set tags"), new BMessage (SET_TAGS))); + fSettingsMenu->AddItem (fSetAppItem = new BMenuItem (B_TRANSLATE("Set preferred application"), new BMessage (SET_APP))); + fSettingsMenu->AddItem (fLink = new BMenuItem (B_TRANSLATE("Open the selected link"), new BMessage (GO_TO_LINK))); + fSettingsMenu->AddItem (fLoadLastNote = new BMenuItem (B_TRANSLATE("Load last note on startup"), new BMessage (LOAD_LAST_NOTE))); + fSettingsMenu->AddItem (fLiveInDeskbar = new BMenuItem (B_TRANSLATE("Use Deskbar Replicant"), new BMessage (LIVE_IN_DESKBAR))); + fLoadLastNote->SetMarked(note_app->fSettingsMessage->FindBool("load_last_note")); + fLiveInDeskbar->SetMarked(note_app->fSettingsMessage->FindBool("live_in_deskbar")); // Edit menu - fEditMenu -> AddItem (fUndoItem = new BMenuItem("Can't Undo", new BMessage(B_UNDO), 'Z')); + fEditMenu -> AddItem (fUndoItem = new BMenuItem(B_TRANSLATE("Can't Undo"), new BMessage(B_UNDO), 'Z')); fUndoItem -> SetEnabled(false); // I can't do undo without the message TEXT_CHANGED fEditMenu -> AddSeparatorItem(); - fEditMenu -> AddItem (fCutItem = new BMenuItem("Cut", new BMessage(B_CUT), 'X')); + fEditMenu -> AddItem (fCutItem = new BMenuItem(B_TRANSLATE("Cut"), new BMessage(B_CUT), 'X')); fCutItem -> SetTarget(this); - fEditMenu -> AddItem (fCopyItem = new BMenuItem("Copy", new BMessage(B_COPY), 'C')); + fEditMenu -> AddItem (fCopyItem = new BMenuItem(B_TRANSLATE("Copy"), new BMessage(B_COPY), 'C')); fCopyItem -> SetTarget(this); - fEditMenu -> AddItem (fPasteItem = new BMenuItem("Paste", new BMessage(B_PASTE), 'V')); + fEditMenu -> AddItem (fPasteItem = new BMenuItem(B_TRANSLATE("Paste"), new BMessage(B_PASTE), 'V')); fPasteItem -> SetTarget(this); - fEditMenu -> AddItem (fSelectAllItem = new BMenuItem("Select all", new BMessage(B_SELECT_ALL), 'A')); + fEditMenu -> AddItem (fSelectAllItem = new BMenuItem(B_TRANSLATE("Select all"), new BMessage(B_SELECT_ALL), 'A')); fSelectAllItem -> SetTarget(this); // Font menu // Font: Size - sizeFont = new BMenu ("Size"); + sizeFont = new BMenu (B_TRANSLATE("Size")); sizeFont -> SetRadioMode (true); fFontMenu -> AddItem (sizeFont); // Writing the menu... for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++ ){ message = new BMessage (FONT_SIZE); - message -> AddFloat ("size", fontSizes[i]); + message->AddFloat ("size", fontSizes[i]); char label[64]; snprintf(label, sizeof(label), "%ld", fontSizes[i]); - sizeFont -> AddItem (menuItem = new BMenuItem (label, message)); + sizeFont->AddItem (menuItem = new BMenuItem (label, message)); if (i == 3) - menuItem -> SetMarked(true); + menuItem->SetMarked(true); } // Font: Color - colorFont = new BMenu ("Color"); - colorFont -> SetRadioMode (true); - fFontMenu -> AddItem (colorFont); + colorFont = new BMenu (B_TRANSLATE("Color")); + colorFont->SetRadioMode (true); + fFontMenu->AddItem (colorFont); // Writing the menu... for (uint32 i = 0; i < sizeof(colors) / sizeof(colors[0]); i++ ){ message = new BMessage (FONT_COLOR); - message -> AddInt8 ("red", (int8)colors[i].red); - message -> AddInt8 ("green", (int8)colors[i].green); - message -> AddInt8 ("blue", (int8)colors[i].blue); + message->AddInt8 ("red", (int8)colors[i].red); + message->AddInt8 ("green", (int8)colors[i].green); + message->AddInt8 ("blue", (int8)colors[i].blue); - label = NULL; + label = ""; switch (i) { case 0: { - label = "Black"; + label = B_TRANSLATE("Black"); color = black; } break; case 1: { - label = "Red"; + label = B_TRANSLATE("Red"); color = red; } break; case 2: { - label = "Green"; + label = B_TRANSLATE("Green"); color = green; } break; case 3: { - label = "Blue"; + label = B_TRANSLATE("Blue"); color = blue; } break; case 4: { - label = "Yellow"; + label = B_TRANSLATE("Yellow"); color = yellow; } break; default: break; } - colorFont -> AddItem (menuItem = new ColorMenuItem (label, color, message)); + colorFont->AddItem (menuItem = new ColorMenuItem (label, color, message)); // Set the item as "in use" if (i == 0) - menuItem -> SetMarked(true); + menuItem->SetMarked(true); } - fFontMenu -> AddSeparatorItem(); + fFontMenu->AddSeparatorItem(); // Font type fCurrentFont = 0; - be_plain_font -> GetFamilyAndStyle (&plainFamily,&plainStyle); + be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); // Taking the number of font families numFamilies = count_font_families(); @@ -390,11 +418,11 @@ void NoteWindow :: InitWindow(){ // Creating a menu of that font family fontMenu = new BMenu (family); - fontMenu -> SetRadioMode (true); // I can set only one item as "in use" - fFontMenu -> AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); + fontMenu->SetRadioMode (true); // I can set only one item as "in use" + fFontMenu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); if (!strcmp (plainFamily,family)) { - menuItem -> SetMarked (true); + menuItem->SetMarked (true); fCurrentFont = menuItem; } // Number of styles of that font family @@ -404,19 +432,16 @@ void NoteWindow :: InitWindow(){ for (int32 j = 0; j < numStyles; j++) { if (get_font_style(family,j,&style,&flags)==B_OK) { - fontMenu -> AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); + fontMenu->AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); if (!strcmp (plainStyle, style)) - menuItem -> SetMarked(true); + menuItem->SetMarked(true); } } } } - // About menu - fAboutMenu -> AddItem (menuItem = new BMenuItem ("About TakeNotes...", new BMessage (B_ABOUT_REQUESTED))); - // Add the menu to the window AddChild(fNoteMenuBar); @@ -456,15 +481,21 @@ NoteWindow::_CreateNoteView(void) frameText.OffsetTo(B_ORIGIN); frameText.InsetBy(TEXT_INSET, TEXT_INSET); - fNoteText = new NoteText(frameView, frameText, "NoteText", this); + fNoteText = new NoteText(frameView, frameText, B_TRANSLATE("NoteText"), this); fNoteText->SetDoesUndo(true); fNoteText->MakeFocus(); fNoteText->SetStylable(true); - // ScrollView fScrollView = new BScrollView("scrollview", fNoteText, B_FOLLOW_ALL, 0, true, true, B_NO_BORDER); + fNoteView->AddChild(fScrollView); + + //load color read from the settings file which was loaded in fSettingsMessage + fNoteView->SetBackgroundColor(note_app->fSettingsMessage->GetColor("def_color", {255,240,113})); + + if(!fSaveMessage) + MoveTo(200+(note_app->fWindowCount*20),200+( note_app->fWindowCount*20)); } @@ -480,41 +511,41 @@ void NoteWindow :: SetFontStyle (const char* fontFamily, const char* fontStyle) rgb_color sameColor; BMenuItem *oldItem; - fNoteText -> GetFontAndColor (&font, &sameProperties, &sameColor); + fNoteText->GetFontAndColor (&font, &sameProperties, &sameColor); // Copying the current font family and font style font.GetFamilyAndStyle (&oldFamily, &oldStyle); if (strcmp (oldFamily, fontFamily)) { - oldItem = fFontMenu -> FindItem (oldFamily); + oldItem = fFontMenu->FindItem (oldFamily); if (oldItem != NULL) // Removing the check - oldItem -> SetMarked (false); + oldItem->SetMarked (false); } font.SetFamilyAndStyle (fontFamily, fontStyle); - fNoteText -> SetFontAndColor (&font); + fNoteText->SetFontAndColor (&font); - superItem = fFontMenu -> FindItem (fontFamily); + superItem = fFontMenu->FindItem (fontFamily); if (superItem != NULL ) - superItem -> SetMarked (true); // Check the one that was selected + superItem->SetMarked (true); // Check the one that was selected - menuItem = fFontMenu -> FindItem("Black"); - menuItem -> SetMarked(true); + menuItem = fFontMenu->FindItem("Black"); + menuItem->SetMarked(true); } // Function that saves the note status_t NoteWindow :: Save(BMessage *message) { // Variables + BFile config; + BFile settings; BDirectory dir; BEntry entry; entry_ref ref; const char *name; status_t err; - message->PrintToStream(); - if (!message){ message = fSaveMessage; } @@ -522,7 +553,7 @@ status_t NoteWindow :: Save(BMessage *message) { // Saving the directory and the path of the note if ((err = message->FindRef("directory",&ref)) != B_OK) return err; - if ((err = message -> FindString("name", &name)) != B_OK) + if ((err = message->FindString("name", &name)) != B_OK) return err; // Set fRef @@ -545,9 +576,15 @@ status_t NoteWindow :: Save(BMessage *message) { SetTitle(name); BMessage archive(*message); - fNoteView -> Archive(&archive, true); + fNoteView->Archive(&archive, true); fNoteView->SetReplicated(false); + if ((err = config.SetTo("/boot/home/config/settings/TakeNotes/config", B_READ_WRITE | B_CREATE_FILE)) != B_OK){ + return err; + } + else { + save_settings(fSaveMessage, "config", "TakeNotes"); + } if (fSaveMessage != message) { delete fSaveMessage; fSaveMessage = new BMessage(*message); @@ -646,25 +683,25 @@ status_t NoteWindow :: _SaveDB(const char* signature){ _LoadDB(); // We take the number of the signatures... - countSignatures = fHash -> GetNumSignatures(); + countSignatures = fHash->GetNumSignatures(); // Searching if the signature is still present with this note for (int i = 0; i < countSignatures; i++) { - sig = fHash -> GetSignature(i); + sig = fHash->GetSignature(i); // Signature found? if (strcmp (signature, sig) == 0) { // Number of notes in this signature BString str(signature); - countNotes = fHash -> GetNumNotes(str); + countNotes = fHash->GetNumNotes(str); for (int j = 0; j < countNotes; j++) // Note found - if (strcmp(fHash -> GetNote(str, j), path.Path()) == 0) { + if (strcmp(fHash->GetNote(str, j), path.Path()) == 0) { found = 1; - alert = new BAlert("Error", "Error: This selection is in the database!", - "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); + alert = new BAlert("Error", B_TRANSLATE("Error: This selection is in the database!"), + B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetShortcut(0,B_ESCAPE); alert->Go(); } @@ -750,87 +787,111 @@ void NoteWindow :: MessageReceived(BMessage* message) { struct tm *timeinfo; // Receiving the messages - switch (message -> what) { + switch (message->what) { + + case LIVE_IN_DESKBAR: { + if(fLiveInDeskbar->IsMarked()) { + fLiveInDeskbar->SetMarked(false); + BDeskbar *db = new BDeskbar(); + if (db->HasItem(kDeskbarItemName)) + db->RemoveItem(kDeskbarItemName); + } else { + fLiveInDeskbar->SetMarked(true); + note_app->_InstallReplicantInDeskbar(); + } - // Show the panel that allows to save the note - case SAVE_AS: { + note_app->fSettingsMessage->SetBool("load_last_note", fLoadLastNote->IsMarked()); + note_app->fSettingsMessage->SetBool("live_in_deskbar", fLiveInDeskbar->IsMarked()); + + if (fRef) { + note_app->fSettingsMessage->RemoveData("last_note" ); + note_app->fSettingsMessage->AddRef("last_note", fRef ); + } + if (save_settings(note_app->fSettingsMessage, "settings", "TakeNotes") == B_OK) + printf("settings saved\n"); + } + break; + + case LOAD_LAST_NOTE: { + if(fLoadLastNote->IsMarked()) + fLoadLastNote->SetMarked(false); + else + fLoadLastNote->SetMarked(true); + } + + note_app->fSettingsMessage->SetBool("load_last_note", fLoadLastNote->IsMarked()); + if(fRef) { + note_app->fSettingsMessage->RemoveData("last_note" ); + note_app->fSettingsMessage->AddRef("last_note", fRef ); + } + if(save_settings(note_app->fSettingsMessage, "settings", "TakeNotes") == B_OK) + printf("settings saved\n"); - fSavePanel -> Show(); + break; + // Show the panel that allows to save the note + case SAVE_AS: { + fSavePanel->Show(); } break; // Save the changes case SAVE:{ - if (!fSaveMessage){ - fSavePanel -> Show(); + fSavePanel->Show(); } else { Save(fSaveMessage); } - } break; // Save the note case B_SAVE_REQUESTED: { - - Save(message); - + if(Save(message) != B_OK) { + printf("error saving message\n"); + } } break; // Close the application case QUIT_APPL: { - Quit(); - } break; // Edit messages // Cut the selected text case B_CUT: - - fNoteText -> Cut(be_clipboard); - + fNoteText->Cut(be_clipboard); break; // Copy the selected text case B_COPY: - - fNoteText -> Copy(be_clipboard); - + fNoteText->Copy(be_clipboard); break; // Paste the selected text case B_PASTE: - - fNoteText -> Paste(be_clipboard); - + fNoteText->Paste(be_clipboard); break; // Select all the text case B_SELECT_ALL: - - fNoteText -> SelectAll(); - + fNoteText->SelectAll(); break; // Message for the undo function case B_UNDO: { // If I have received a B_UNDO message... - if (fCanUndo) //...and I can do "Undo" fUndoFlag = true; if (fCanRedo) //...and I can do "Redo" fRedoFlag = true; - fNoteText -> Undo(be_clipboard); + fNoteText->Undo(be_clipboard); } break; - // Message that tells if the text is changes (it is used for the "can't undo") case TEXT_CHANGED: { @@ -838,29 +899,29 @@ void NoteWindow :: MessageReceived(BMessage* message) { fCanUndo = false; fCanRedo = true; - fUndoItem -> SetLabel("Redo"); - fUndoItem -> SetEnabled(true); + fUndoItem->SetLabel(B_TRANSLATE("Redo")); + fUndoItem->SetEnabled(true); fUndoFlag = false; } else { - fCanUndo = true; fCanRedo = false; - fUndoItem -> SetLabel("Undo"); - fUndoItem -> SetEnabled(true); + fUndoItem->SetLabel(B_TRANSLATE("Undo")); + fUndoItem->SetEnabled(true); fRedoFlag = false; } + //eventualle check here if there's a string available to convert to a link } break; // Font size case FONT_SIZE: { - if (message -> FindFloat ("size", &fontSize) == B_OK){ - fNoteText -> GetFontAndColor(&font, &sameProperties, &sameColor); + if (message->FindFloat ("size", &fontSize) == B_OK){ + fNoteText->GetFontAndColor(&font, &sameProperties, &sameColor); font.SetSize(fontSize); - fNoteText -> SetFontAndColor (&font, B_FONT_SIZE); + fNoteText->SetFontAndColor (&font, B_FONT_SIZE); } } @@ -877,8 +938,8 @@ void NoteWindow :: MessageReceived(BMessage* message) { colore.blue = (uint8)c; // Setting a different color for the font - fNoteText -> GetFontAndColor(&font, &sameProperties); - fNoteText -> SetFontAndColor(&font,0,&colore); + fNoteText->GetFontAndColor(&font, &sameProperties); + fNoteText->SetFontAndColor(&font,0,&colore); } break; @@ -890,9 +951,9 @@ void NoteWindow :: MessageReceived(BMessage* message) { fontStyle = NULL; // Setting the font family - message -> FindPointer ("source", &ptr); + message->FindPointer ("source", &ptr); fCurrentFont = static_cast (ptr); - fontFamily = fCurrentFont -> Label(); + fontFamily = fCurrentFont->Label(); SetFontStyle (fontFamily, fontStyle); } @@ -905,15 +966,15 @@ void NoteWindow :: MessageReceived(BMessage* message) { fontStyle = NULL; // Setting the font style - message -> FindPointer ("source", &ptr); + message->FindPointer ("source", &ptr); item = static_cast (ptr); - fontStyle = item -> Label(); - menu = item -> Menu(); + fontStyle = item->Label(); + menu = item->Menu(); if (menu != NULL) { - fCurrentFont = menu -> Superitem(); + fCurrentFont = menu->Superitem(); if (fCurrentFont != NULL) - fontFamily = fCurrentFont -> Label(); + fontFamily = fCurrentFont->Label(); } SetFontStyle (fontFamily, fontStyle); @@ -924,7 +985,7 @@ void NoteWindow :: MessageReceived(BMessage* message) { case GO_TO_LINK: { // Copying the selected link - fNoteText -> GetSelection(&k,&j); + fNoteText->GetSelection(&k,&j); length = j - k + 1; // If nothing was selected we need to break @@ -932,91 +993,23 @@ void NoteWindow :: MessageReceived(BMessage* message) { break; offset = k; - fNoteText -> GetText(offset, length, buffer); - found = 0; + fNoteText->GetText(offset, length, buffer); - printf(buffer); - printf("\n"); + //the OS should decide how links are opened, user can adjust settings via the file_type preferences + BString cmd = buffer; - // Verifying if the link passed is an email or a link - for (count = 0; buffer[count] != '\0'; count++){ - if (buffer[count] == '@') { - found = 1; + // Verifying if the link passed is an email ... + if(cmd.FindFirst("@") > 0) { + cmd.Prepend("open mailto:"); + system(cmd.String()); break; - } - } - // Mail found? - if (found == 0) { // No - // Signature of BeZilla - signature = strdup("application/x-vnd.Mozilla-Firefox"); - mail = 0; } - else { // Yes - // Signature of mail - signature = strdup("application/x-vnd.Be-MAIL"); - mail = 1; - } - - // We write "mailto:mail" as required by the program "Mail" - if (mail == 1) { - // Variables - char m[50]; - - // Copying the email - fNoteText -> GetSelection(&k,&j); - length = j - k + 1; - offset = k; - fNoteText -> GetText(offset, length, m); - - // Writing "mailto:mail" - // Variables - BString string; - - string.SetTo("mailto:"); - string.Append(m, sizeof(m)); - string.Append("\0", 1); - param[0] = (char*) string.String(); - // Launching the application - be_roster -> Launch(signature, 1, param, NULL); + // ... or a link + if(cmd.FindFirst("www") > 0 || cmd.FindFirst("http") > 0) { + cmd.Prepend("open "); + system(cmd.String()); + break; } - else { - // Browser - // Flag - found = 0; - - // Initialization - aList = new BList; - appInfo = new app_info(); - - // Obtaining the applications that are running - be_roster->GetAppList(aList); - - // We look for the current instances of BeZilla that are running - for (count=0;count< aList->CountItems();count++){ - who = (team_id)(addr_t)aList->ItemAt(count); - be_roster->GetRunningAppInfo(who,appInfo); - - // Is there an instance that is running? - if (strcmp (appInfo->signature, signature) == 0) { - myAlert = new BAlert("BeZilla is opened", - "Close the browser first, then open this link", - "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); - myAlert -> Go(); - found = 1; - break; - } - } - - // BeZilla is not running - if (found == 0) { - // We launch the application - // Variables - char* buffer2 = buffer; - - be_roster -> Launch(signature, 1, &buffer2, NULL); - } - } - } break; @@ -1031,42 +1024,39 @@ void NoteWindow :: MessageReceived(BMessage* message) { minute = gettime().tm_min; hour = gettime().tm_hour; - sprintf(stringa, "%d/%d/%d - %d:%d:%d", day, + //todo: thaflo 2021: read separator from OS wide preferences + sprintf(stringa, "%02d/%02d/%02d - %02d:%02d:%02d", day, month, year, hour, minute, second); // Inserting the string - fNoteText -> MakeFocus(); - fNoteText -> Insert(stringa); + fNoteText->MakeFocus(); + fNoteText->Insert(stringa); } break; - // Show the window that allow the user to change the background color + // Show the window that allows the user to change the background color case SET_COLOR:{ if (fColorWindow == NULL){ - - fColorWindow = new ColorWindow(BRect(300,300,700,680),this); - fColorWindow -> Show(); + fColorWindow = new ColorWindow(BRect(300,300,700,450),this, this->FindView("NoteText")->ViewColor()); + fColorWindow->Show(); } else { - - fColorWindow->Activate(); +// fColorWindow->Activate(); } - } break; // Background color changed case COLOR_CHANGED: { - message->FindInt8("red", &c); colore.red = (uint8)c; message->FindInt8("green", &c); colore.green = (uint8)c; message->FindInt8("blue", &c); colore.blue = (uint8)c; - fNoteView -> SetBackgroundColor(colore); + fNoteView->SetBackgroundColor(colore); } break; @@ -1075,9 +1065,11 @@ void NoteWindow :: MessageReceived(BMessage* message) { case SET_APP: { if (!fSaveMessage){ + alert = new BAlert("Warning",B_TRANSLATE("You must save your note before!"),B_TRANSLATE("Cancel"),B_TRANSLATE("Save")); - alert = new BAlert("Warning","You must save your note before!","OK"); - alert->Go(); + if (alert->Go() == 1) { + fSavePanel->Show(); + } } else { @@ -1089,13 +1081,13 @@ void NoteWindow :: MessageReceived(BMessage* message) { // Obtaining the applications that are running be_roster->GetAppList(aList); - countApps = aList -> CountItems(); + countApps = aList->CountItems(); h = countApps * 17 + 300; printf("Height: %d\n", h); fChoiceWindow = new ChoiceWindow(BRect(300,300,800,h), this); - fChoiceWindow -> Show(); + fChoiceWindow->Show(); delete aList; aList = NULL; @@ -1112,7 +1104,7 @@ void NoteWindow :: MessageReceived(BMessage* message) { const char* stringa; - message -> FindString("signature", &stringa); + message->FindString("signature", &stringa); // Save the new association into the config file _SaveDB(stringa); @@ -1123,22 +1115,20 @@ void NoteWindow :: MessageReceived(BMessage* message) { case SET_TAGS: { if (!fSaveMessage){ - - alert = new BAlert("Warning","You must save your note before!","OK"); - alert->Go(); - + alert = new BAlert("Warning",B_TRANSLATE("You must save your note before!"),B_TRANSLATE("Cancel"),B_TRANSLATE("Save")); + if (alert->Go() == 1) { + fSavePanel->Show(); + } } else { // It creates a window if (fTagsWindow == NULL){ fTagsWindow = new TagsWindow(fSaveMessage, this); - fTagsWindow -> Show(); + fTagsWindow->Show(); } else fTagsWindow->Activate(); - } - } break; @@ -1147,7 +1137,7 @@ void NoteWindow :: MessageReceived(BMessage* message) { if (fAlarmWindow == NULL){ - fAlarmWindow = new AlarmWindow(BRect(300,300,800,600),this); + fAlarmWindow = new AlarmWindow(BRect(300,300,730,450),this); fAlarmWindow->Show(); } @@ -1162,15 +1152,15 @@ void NoteWindow :: MessageReceived(BMessage* message) { alarm_set = true; - message -> FindInt16("year", &i); + message->FindInt16("year", &i); fData.Year = i; - message -> FindInt16("month", &i); + message->FindInt16("month", &i); fData.Month = i; - message -> FindInt16("day", &i); + message->FindInt16("day", &i); fData.Day = i; - message -> FindInt16("hour", &i); + message->FindInt16("hour", &i); fData.Hour = i; - message -> FindInt16("minute", &i); + message->FindInt16("minute", &i); fData.Minute = i; } @@ -1184,7 +1174,7 @@ void NoteWindow :: MessageReceived(BMessage* message) { break; } // Second check if the runner has been correctly started - if (runner -> InitCheck() < B_NO_ERROR) { + if (runner->InitCheck() < B_NO_ERROR) { break; } @@ -1200,68 +1190,71 @@ void NoteWindow :: MessageReceived(BMessage* message) { timeinfo = localtime ( &rawtime ); // Fill the timeinfo struct with data saved in data struct - timeinfo -> tm_year = fData.Year - 1900; - timeinfo -> tm_mon = fData.Month - 1; - timeinfo -> tm_mday = fData.Day; - timeinfo -> tm_hour = fData.Hour; - timeinfo -> tm_min = fData.Minute; - timeinfo -> tm_sec = 0; + timeinfo->tm_year = fData.Year - 1900; + timeinfo->tm_mon = fData.Month - 1; + timeinfo->tm_mday = fData.Day; + timeinfo->tm_hour = fData.Hour; + timeinfo->tm_min = fData.Minute; + timeinfo->tm_sec = 0; // Convert from struct tm to data type time_t userTime = mktime(timeinfo); // Compare user time and system time if (difftime(userTime, time( &rawtime) ) < 0 ) { - BString string; - string.SetTo("Alarm activated for note: "); - string.Append(Title()); - string.Append("\0",1); - alertstr = (char*) string.String(); - myAlert = new BAlert("Alarm activated", alertstr, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); - myAlert -> Go(); - - // PAY ATTENTION!!!! We have to think about this: when an alarm has been activated, remember to "delete" it otherwise the alarm will appear over and over + + //thaflo: send a notification/ was an alert before + BNotification notification(B_INFORMATION_NOTIFICATION); + notification.SetGroup("TakeNotes"); + notification.SetTitle(Title()); + notification.SetContent(fNoteText->Text()); + notification.SetMessageID("takenotes_info"); + notification.Send(); alarm_set = false; - } + } } break; // It removes the color window case COLOR_CLOSE: { - + if (fSaveMessage) { + this->PostMessage(SAVE); + } fColorWindow = NULL; - } break; // It removes the alarm window case ALARM_CLOSE: { - fAlarmWindow = NULL; - } break; // It removes the tag window case TAGS_CLOSE: { - fTagsWindow = NULL; - } break; // It removes the choice window case CHOICE_CLOSE: { - fChoiceWindow = NULL; - } break; // About menu case B_ABOUT_REQUESTED: { - AboutRequested(); + note_app->AboutRequested(); + } + break; + + case SET_DEFAULT_COLOR: { + //save the new default color + rgb_color c = {10,10,10,10}; + note_app->fSettingsMessage->SetColor("def_color", message->GetColor("new_def_color", c)); + if(save_settings(note_app->fSettingsMessage, "settings", "TakeNotes") != B_OK) + printf("settings not saved\n"); } break; @@ -1277,25 +1270,6 @@ bool NoteWindow :: QuitRequested(){ return(true); } -// Function that shows about window -void NoteWindow :: AboutRequested() -{ - BAboutWindow* about = new BAboutWindow("TakeNotes", kSignature); - - const char* authors[] = { - "Ilio Catallo", - "Stefano Celentano", - "Eleonora Ciceri", - NULL - }; - - about->AddCopyright(2009, "Ilio Catallo"); - about->AddAuthors(authors); - about->AddText("Distribuited under the terms of the GPLv2 license"); - about->AddText("Icons by Meanwhile"); - about->Show(); -} - // Function that quits the window void NoteWindow :: Quit(){ @@ -1303,3 +1277,4 @@ void NoteWindow :: Quit(){ BWindow::Quit(); } + diff --git a/source/NoteWindow.h b/source/NoteWindow.h index 4a1295e..a8db36c 100644 --- a/source/NoteWindow.h +++ b/source/NoteWindow.h @@ -50,6 +50,12 @@ struct AlarmData { int Minute; // Alarm - Minute }; +status_t load_settings(BMessage* message, const char* fileName, + const char* folder = NULL); + +status_t save_settings(BMessage* message, const char* fileName, + const char* folder = NULL); + // Constructor class NoteWindow : public BWindow { @@ -60,7 +66,7 @@ class NoteWindow : public BWindow { virtual void MessageReceived(BMessage* message); virtual void Quit(); virtual bool QuitRequested(); - void AboutRequested(); +// void AboutRequested(); void InitWindow(); void CreateOtherWindows(); void _LoadDB(); @@ -89,7 +95,9 @@ class NoteWindow : public BWindow { BScrollView *fScrollView; // Menu Items: file menu + BMenuItem *fNewItem; BMenuItem *fSaveItem; + BMenuItem *fOpenItem; BMenuItem *fQuitItem; // MenuItems (Edit menu) @@ -103,10 +111,13 @@ class NoteWindow : public BWindow { // MenuItems (Settings menu) BMenuItem *fChangeBackgroundColorItem; + BMenuItem *fSettingsItem; BMenuItem *fAddDateAndTimeItem; BMenuItem *fSetTagsItem; BMenuItem *fSetAppItem; BMenuItem *fSetAlarmItem; + BMenuItem *fLoadLastNote; + BMenuItem *fLiveInDeskbar; BMenuItem *fLink; // Undo flags @@ -128,7 +139,7 @@ class NoteWindow : public BWindow { // Save panel BFilePanel *fSavePanel; - + // Hash table BFile fDatabase; AppHashTable *fHash; diff --git a/source/TagsWindow.cpp b/source/TagsWindow.cpp index 2ccd054..3c33b28 100644 --- a/source/TagsWindow.cpp +++ b/source/TagsWindow.cpp @@ -7,7 +7,7 @@ * Ilio Catallo, * Stefano Celentano * - * Last revision: Ilio Catallo, 28th June 2009 + * Last revision: Florian Thaler, 08.04.2021 * * Description: Tags window, it allows the user to set three customs tags (extra attributes) */ @@ -18,20 +18,30 @@ #include #include #include +#include +#include +#include #include #include +#include +#include #include #include +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "TagsWindow" + // Constants #define BUTTON_OK 'btok' -#define BUTTON_UNDO 'btun' +#define BUTTON_CANCEL 'btcn' #define TAGS_CLOSE '_tgc' + TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler) - : BWindow (BRect(300,300,700,550),"Set Tags for this note",B_TITLED_WINDOW, B_NOT_RESIZABLE){ + : BWindow (BRect(300,300,700,450), B_TRANSLATE("Set tags for this note") + ,B_TITLED_WINDOW, B_NOT_RESIZABLE){ // Variables fMessenger = new BMessenger(handler); @@ -41,44 +51,41 @@ TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler) status_t err; const char *name; - BView *fTagsView; - char bufferTag1[30]; - char bufferTag2[30]; - char bufferTag3[30]; - - // Create the main view - fTagsView = new BView(Bounds(), "TagsView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS); - - // Create the Text Field - fTag1 = new BTextControl(BRect(20,40,200,55), "tag1", "First Tag: ", NULL, NULL); - fTag2 = new BTextControl(BRect(20,70,200,85), "tag2", "Second Tag: ", NULL, NULL); - fTag3 = new BTextControl(BRect(20,100,200,135), "tag3", "Third Tag: ", NULL, NULL); - - //Create the OK and UNDO button - fDoneButton = new BButton(BRect(340,200,390,210), "ok", "OK", new BMessage(BUTTON_OK)); - fUndoButton = new BButton(BRect(270,200,320,210), "undo", "Undo", new BMessage(BUTTON_UNDO)); - - /* - * Add the view as window's child, set back ground color, - * then add the tag TextControl as children - */ - fTagsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - AddChild(fTagsView); - fTagsView->AddChild(fTag1); - fTagsView->AddChild(fTag2); - fTagsView->AddChild(fTag3); - - // Add OK and UNDO button as children - fTagsView->AddChild(fDoneButton); - fTagsView->AddChild(fUndoButton); + 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); + + 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(B_USE_WINDOW_INSETS) + .AddGroup(B_VERTICAL) + .Add(fTag1) + .Add(fTag2) + .Add(fTag3) + .End() + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(fCancelButton) + .Add(fOkButton) + .End(); + AddChild(fTopView); // Open the file from FS starting from the fSaveMessage message if (fSaveMessage->FindRef("directory",&ref) == B_OK && fSaveMessage->FindString("name", &name) == B_OK){ dir.SetTo(&ref); if ((err = dir.InitCheck()) != B_OK){ - BAlert *myalert = new BAlert("ERR","errore di inizializzazione del file","OK"); + BAlert *myalert = new BAlert("ERR", B_TRANSLATE("File initiation failed"), B_TRANSLATE("OK")); myalert->Go(); exit(-1); @@ -86,21 +93,15 @@ TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler) fFile.SetTo(&dir, name, B_READ_WRITE); } - printf("$$$$TAGONE$$$$: %s\n", bufferTag1); + fFile.ReadAttrString("TAKENOTES:tagone", &tagone); + fFile.ReadAttrString("TAKENOTES:tagtwo", &tagtwo); + fFile.ReadAttrString("TAKENOTES:tagthree", &tagthree); - // Read the old values for this file - if (fFile.ReadAttr("TAKENOTES:tagone", B_STRING_TYPE, 0, &bufferTag1, 30) > 0) { - fTag1->SetText(bufferTag1); - } - - if (fFile.ReadAttr("TAKENOTES:tagtwo", B_STRING_TYPE, 0, &bufferTag2, 30) > 0) { - fTag2->SetText(bufferTag2); - } - - if (fFile.ReadAttr("TAKENOTES:tagthree", B_STRING_TYPE, 0, &bufferTag3, 30) > 0) { - fTag3->SetText(bufferTag3); - } + fTag1->SetText(tagone.String()); + fTag2->SetText(tagtwo.String()); + fTag3->SetText(tagthree.String()); + Show(); } // Destructor @@ -129,15 +130,8 @@ void TagsWindow :: MessageReceived(BMessage *message){ break; // Message that answer to an UNDO request - case BUTTON_UNDO: { - - BAlert *alert = new BAlert("", "The tags haven't been saved yet, do you really want to close the window ?", "Yes", "No", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); - alert->SetShortcut(0, B_ESCAPE); - - if (alert->Go() == 0) { - // Discard all the changes - Quit(); - } + case BUTTON_CANCEL: { + Quit(); } break; diff --git a/source/TagsWindow.h b/source/TagsWindow.h index 4ff08e1..4168c5f 100644 --- a/source/TagsWindow.h +++ b/source/TagsWindow.h @@ -20,6 +20,8 @@ #include #include + + // Window that allows you to add tags class TagsWindow : public BWindow{ @@ -33,8 +35,8 @@ class TagsWindow : public BWindow{ private: - BButton *fDoneButton; - BButton *fUndoButton; + BButton *fOkButton; + BButton *fCancelButton; BTextControl *fTag1; BTextControl *fTag2; BTextControl *fTag3; diff --git a/source/TakeNotes.rdef b/source/TakeNotes.rdef index 6ace2c0..f2d362d 100644 --- a/source/TakeNotes.rdef +++ b/source/TakeNotes.rdef @@ -1,34 +1,34 @@ /* * Copyright 2009, Ilio Catallo, Stefano Celentano, Eleonora Ciceri, all rights reserved * Distribuited under the terms of the GPL v2 license - * + * * Authors: * * Ilio Catallo - * + * * Icons by: * * Meanwhile * * - * Last revision: Ilio Catallo, 17th June 2009 + * Last revision: Florian Thaler, 2021 * * Description: TODO */ - + resource app_signature "application/x-vnd.ccc-TakeNotes"; resource app_version { major = 1, - middle = 0, + middle = 5, minor = 0, - variety = B_APPV_BETA, + variety = B_APPV_FINAL, internal = 0, - short_info = "TakeNotes", - long_info = "TakeNotes ©2009 Ilio Catallo, Stefano Celentano, Eleonora Ciceri" + short_info = "TakeNotes, an app to create notes.", + long_info = "TakeNotes is an app to create notes with alarms and the ability to set the background color and custom fonts." }; resource app_flags B_SINGLE_LAUNCH; diff --git a/source/locales/de.catkeys b/source/locales/de.catkeys new file mode 100644 index 0000000..21bff4c --- /dev/null +++ b/source/locales/de.catkeys @@ -0,0 +1,64 @@ +1 English application/x-vnd.TakeNotes 2183189585 +Color NoteWindow Color +NoteText NoteWindow NoteText +month AlarmWindow month +Quit NoteView Quit +Change background color NoteWindow Change background color +Green NoteWindow Green +Insert time and date to set an alarm AlarmView Insert time and date to set an alarm +Icons by Meanwhile NoteWindow Icons by Meanwhile +Alarm activated for note: NoteWindow Alarm activated for note: +Untitled NoteWindow Untitled +Edit NoteWindow Edit +Save NoteWindow Save +Error: This selection is in the database! NoteWindow Error: This selection is in the database! +File NoteWindow File +Open TakeNotes… NoteView Open TakeNotes… +hour: AlarmWindow hour: +Save as… NoteWindow Save as… +About TakeNotes NoteView About TakeNotes +Set alarm NoteWindow Set alarm +Size NoteWindow Size +Copyright 2020\n\nIlio Catallo,\nStefano Celentano,\nEleonora Ciceri.\nFlorian Thaler\n\nall rights reserved, distribuited under the terms of the GPLv2 license\n\nIcons by Meanwhile NoteView Copyright 2020\n\nIlio Catallo,\nStefano Celentano,\nEleonora Ciceri.\nFlorian Thaler\n\nall rights reserved, distribuited under the terms of the GPLv2 license\n\nIcons by Meanwhile +You must save your note before! NoteWindow You must save your note before! +min: AlarmWindow min: +hour AlarmWindow hour +Undo NoteWindow Undo +Red NoteWindow Red +year AlarmWindow year +Undo AlarmWindow Undo +day AlarmWindow day +Install NoteApplication Install +Set alarm for this note AlarmWindow Set alarm for this note +No thanks NoteApplication No thanks +Undo ChoiceView Undo +year: AlarmWindow year: +Yellow NoteWindow Yellow +day: AlarmWindow day: +Done AlarmWindow Done +Add date and time NoteWindow Add date and time +Paste NoteWindow Paste +Cut NoteWindow Cut +About TakeNotes... NoteWindow Über TakeNotes... +Undo ColorWindow Undo +Select all NoteWindow Select all +Set tags NoteWindow Set tags +Settings NoteWindow Settings +Distribuited under the terms of the GPLv2 license NoteWindow Distribuited under the terms of the GPLv2 license +Set preferred application NoteWindow Set preferred application +minute AlarmWindow minute +Open… NoteWindow Open… +Copy NoteWindow Copy +Blue NoteWindow Blue +Thanks NoteView Thanks +Black NoteWindow Black +Can't Undo NoteWindow Can't Undo +Alarm activated NoteWindow Alarm activated +Do you want TakeNotes to live in the Deskbar? NoteApplication Do you want TakeNotes to live in the Deskbar? +Font NoteWindow Font +About NoteWindow About +OK NoteWindow Ok +Go to the selected link NoteWindow Go to the selected link +Redo NoteWindow Redo +month: AlarmWindow month: +Quit NoteWindow Quit diff --git a/source/locales/en.catkeys b/source/locales/en.catkeys new file mode 100644 index 0000000..bc6faad --- /dev/null +++ b/source/locales/en.catkeys @@ -0,0 +1,64 @@ +1 English application/x-vnd.TakeNotes 2183189585 +Color NoteWindow Color +NoteText NoteWindow NoteText +month AlarmWindow month +Quit NoteView Quit +Change background color NoteWindow Change background color +Green NoteWindow Green +Insert time and date to set an alarm AlarmView Insert time and date to set an alarm +Icons by Meanwhile NoteWindow Icons by Meanwhile +Alarm activated for note: NoteWindow Alarm activated for note: +Untitled NoteWindow Untitled +Edit NoteWindow Edit +Save NoteWindow Save +Error: This selection is in the database! NoteWindow Error: This selection is in the database! +File NoteWindow File +Open TakeNotes… NoteView Open TakeNotes… +hour: AlarmWindow hour: +Save as… NoteWindow Save as… +About TakeNotes NoteView About TakeNotes +Set alarm NoteWindow Set alarm +Size NoteWindow Size +Copyright 2020\n\nIlio Catallo,\nStefano Celentano,\nEleonora Ciceri.\nFlorian Thaler\n\nall rights reserved, distribuited under the terms of the GPLv2 license\n\nIcons by Meanwhile NoteView Copyright 2020\n\nIlio Catallo,\nStefano Celentano,\nEleonora Ciceri.\nFlorian Thaler\n\nall rights reserved, distribuited under the terms of the GPLv2 license\n\nIcons by Meanwhile +You must save your note before! NoteWindow You must save your note before! +min: AlarmWindow min: +hour AlarmWindow hour +Undo NoteWindow Undo +Red NoteWindow Red +year AlarmWindow year +Undo AlarmWindow Undo +day AlarmWindow day +Install NoteApplication Install +Set alarm for this note AlarmWindow Set alarm for this note +No thanks NoteApplication No thanks +Undo ChoiceView Undo +year: AlarmWindow year: +Yellow NoteWindow Yellow +day: AlarmWindow day: +Done AlarmWindow Done +Add date and time NoteWindow Add date and time +Paste NoteWindow Paste +Cut NoteWindow Cut +About TakeNotes... NoteWindow About TakeNotes... +Undo ColorWindow Undo +Select all NoteWindow Select all +Set tags NoteWindow Set tags +Settings NoteWindow Settings +Distribuited under the terms of the GPLv2 license NoteWindow Distribuited under the terms of the GPLv2 license +Set preferred application NoteWindow Set preferred application +minute AlarmWindow minute +Open… NoteWindow Open… +Copy NoteWindow Copy +Blue NoteWindow Blue +Thanks NoteView Thanks +Black NoteWindow Black +Can't Undo NoteWindow Can't Undo +Alarm activated NoteWindow Alarm activated +Do you want TakeNotes to live in the Deskbar? NoteApplication Do you want TakeNotes to live in the Deskbar? +Font NoteWindow Font +About NoteWindow About +OK NoteWindow OK +Go to the selected link NoteWindow Go to the selected link +Redo NoteWindow Redo +month: AlarmWindow month: +Quit NoteWindow Quit