Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HaikuArchives/Calendar
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f0ab3dcc2098
Choose a base ref
...
head repository: HaikuArchives/Calendar
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bfb1d29fad3f
Choose a head ref
  • 1 commit
  • 8 files changed
  • 1 contributor

Commits on Oct 29, 2021

  1. Toggle event menu items based on selection (#93)

    With no event selected, the "edit," "remove," and "cancel" pop-up/"Event" menu
    items are disabled. If an event has been cancelled, it is marked as such
    in the menu.
    JadedCtrl authored Oct 29, 2021
    Copy the full SHA
    bfb1d29 View commit details
Showing with 157 additions and 99 deletions.
  1. +4 −74 src/DayView.cpp
  2. +2 −1 src/DayView.h
  3. +84 −11 src/EventListItem.cpp
  4. +8 −5 src/EventListItem.h
  5. +30 −3 src/EventListView.cpp
  6. +8 −5 src/EventListView.h
  7. +20 −0 src/MainWindow.cpp
  8. +1 −0 src/MainWindow.h
78 changes: 4 additions & 74 deletions src/DayView.cpp
Original file line number Diff line number Diff line change
@@ -12,9 +12,6 @@
#include <LayoutBuilder.h>
#include <List.h>
#include <ScrollView.h>
#include <TimeFormat.h>
#include <DurationFormat.h>
#include <DateFormat.h>

#include "Event.h"
#include "EventListItem.h"
@@ -30,7 +27,7 @@ DayView::DayView(const BDate& date)
BView("DayView", B_WILL_DRAW)
{
fDate = date;
mode = kDayView; // start with Day View
fMode = kDayView; // start with Day View
fEventListView = new EventListView();
fEventListView->SetViewColor(B_TRANSPARENT_COLOR);
fEventListView->SetInvocationMessage(new BMessage(kInvokationMessage));
@@ -70,7 +67,7 @@ DayView::LoadEvents()
fEventListView->MakeEmpty();
}

if (mode == kWeekView)
if (fMode == kWeekView)
fEventList = fDBManager->GetEventsOfWeek(fDate);
else
fEventList = fDBManager->GetEventsOfDay(fDate); // Day and Agenda views
@@ -144,7 +141,7 @@ DayView::MessageReceived(BMessage* message)
case kDayView:
case kWeekView:
case kAgendaView:
mode = message->what;
fMode = message->what;

case kSetCalendarToCurrentDate:
LoadEvents();
@@ -186,77 +183,10 @@ DayView::_PopulateEvents()
{
Event* event;
EventListItem* item;
BString startTime;
BString endTime;
BString startDay;
BString endDay;
BString eventName;
BString timePeriod;
BString remaining;
BTimeFormat timeFormat;
BDateFormat dateFormat;
BDateTime now = BDateTime::CurrentDateTime(B_LOCAL_TIME);

for (int32 i = 0; i < fEventList->CountItems(); i++) {
event = ((Event*)fEventList->ItemAt(i));

remaining = "";
eventName = "";
startTime = "";
endTime = "";
timePeriod = "";

if (event->IsAllDay())
if (mode == kDayView)
timePeriod = B_TRANSLATE("All day");
else {
dateFormat.Format(startDay, event->GetStartDateTime(),
B_SHORT_DATE_FORMAT);
BString startday(B_TRANSLATE("All day, %startDay%"));
startday.ReplaceAll("%startDay%", startDay);
timePeriod << startday;
}
else {
timeFormat.Format(startTime, event->GetStartDateTime(),
B_SHORT_TIME_FORMAT);
timeFormat.Format(endTime, event->GetEndDateTime(),
B_SHORT_TIME_FORMAT);

if (mode == kDayView)
timePeriod << startTime << " - " << endTime;
else if (mode == kWeekView) {
dateFormat.Format(startDay, event->GetStartDateTime(),
B_SHORT_DATE_FORMAT);
dateFormat.Format(endDay, event->GetEndDateTime(),
B_SHORT_DATE_FORMAT);
timePeriod << startTime << ", " << startDay << " - " \
<< endTime << ", " << endDay;
} else {
BDurationFormat formatter(", ", B_TIME_UNIT_ABBREVIATED);
if (now.Time_t() >= event->GetStartDateTime() &&
now.Time_t() <= event->GetEndDateTime()) {
formatter.Format(remaining, 0, difftime(event->GetEndDateTime(), now.Time_t())*1000000);
BString timeLeft(B_TRANSLATE("Now, %remaining% left"));
timeLeft.ReplaceAll("%remaining%", remaining);
timePeriod << timeLeft;
} else if (now.Time_t() < event->GetStartDateTime()) {
formatter.Format(remaining, 0, difftime(event->GetStartDateTime(), now.Time_t())*1000000);
BString timeLeft(B_TRANSLATE("Starts in %remaining%"));
timeLeft.ReplaceAll("%remaining%", remaining);
timePeriod << timeLeft;
} else
timePeriod = B_TRANSLATE("Finished!");
}
}

eventName << event->GetName();
rgb_color color = event->GetCategory()->GetColor();
uint16 face = -1;
if (event->GetStatus() & EVENT_CANCELLED)
face = 0 | B_ITALIC_FACE | B_LIGHT_FACE | B_STRIKEOUT_FACE;

item = new EventListItem(eventName, timePeriod , color, face);
item = new EventListItem(event, fMode);
fEventListView->AddItem(item);
}

}
3 changes: 2 additions & 1 deletion src/DayView.h
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ const uint32 kEditEventMessage = 'ksem';
const uint32 kDeleteEventMessage = 'kdem';
const uint32 kCancelEventMessage = 'kcem';
const uint32 kLaunchEventManagerToModify = 'klem';
const uint32 kEventSelected = 'kevs';

static const int kDayView = 1006;
static const int kWeekView = 1007;
@@ -48,7 +49,7 @@ class DayView: public BView {
BDate fDate;
QueryDBManager* fDBManager;

int32 mode;
int32 fMode;

};

95 changes: 84 additions & 11 deletions src/EventListItem.cpp
Original file line number Diff line number Diff line change
@@ -4,23 +4,31 @@
* All rights reserved. Distributed under the terms of the MIT license.
*/

#include "EventListItem.h"

#include <Application.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <DateFormat.h>
#include <DurationFormat.h>
#include <Font.h>
#include <MenuItem.h>
#include <TimeFormat.h>

#include "DayView.h"
#include "Event.h"

#include "EventListItem.h"

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "EventListItem"

EventListItem::EventListItem(BString name, BString timeText, rgb_color color,
uint16 font_face)

EventListItem::EventListItem(Event* event, int32 mode)
:
fEvent(event),
BListItem()
{
fName = name;
fTimeText = timeText;
fColor = color;
fFace = font_face;
_CalcTimeText(mode);
}


@@ -62,7 +70,7 @@ EventListItem::DrawItem(BView* view, BRect rect, bool complete)
- timefont.Size();

colorRect.bottom = colorRect.top + rect.Height() / 4;
view->SetHighColor(fColor);
view->SetHighColor(fEvent->GetCategory()->GetColor());
view->FillEllipse(colorRect);
view->SetHighUIColor(B_CONTROL_BORDER_COLOR);
view->StrokeEllipse(colorRect);
@@ -98,15 +106,15 @@ EventListItem::DrawItem(BView* view, BRect rect, bool complete)

namefont.SetSize(timefont.Size() + 2);
namefont.GetHeight(&finfo);
if (fFace > -1)
namefont.SetFace(fFace);
if (fEvent->GetStatus() & EVENT_CANCELLED)
namefont.SetFace(0 | B_ITALIC_FACE | B_LIGHT_FACE | B_STRIKEOUT_FACE);
view->SetFont(&namefont);

view->MovePenTo(offset, rect.top + ((rect.Height()
- (finfo.ascent + finfo.descent + finfo.leading)) / 2)
+ (finfo.ascent + finfo.descent) - timefont.Size() + 2);

BString name(fName);
BString name(fEvent->GetName());
view->TruncateString(&name, B_TRUNCATE_END, rect.Width() - offset - 2);
view->DrawString(name.String());

@@ -128,3 +136,68 @@ EventListItem::Update(BView* owner, const BFont* finfo)
float spacing = be_control_look->DefaultLabelSpacing();
SetHeight(fItemHeight + spacing * 2);
}


Event*
EventListItem::GetEvent()
{
return fEvent;
}


void
EventListItem::_CalcTimeText(int32 mode)
{
BString startDay, endDay, startTime, endTime, remaining, timePeriod;
BTimeFormat timeFormat;
BDateFormat dateFormat;
BDateTime now = BDateTime::CurrentDateTime(B_LOCAL_TIME);

if (fEvent->IsAllDay() == true)
if (mode == kDayView)
timePeriod = B_TRANSLATE("All day");
else {
dateFormat.Format(startDay, fEvent->GetStartDateTime(),
B_SHORT_DATE_FORMAT);
BString startday(B_TRANSLATE("All day, %startDay%"));
startday.ReplaceAll("%startDay%", startDay);
timePeriod << startday;
}
else {
timeFormat.Format(startTime, fEvent->GetStartDateTime(),
B_SHORT_TIME_FORMAT);
timeFormat.Format(endTime, fEvent->GetEndDateTime(),
B_SHORT_TIME_FORMAT);

if (mode == kDayView)
timePeriod << startTime << " - " << endTime;
else if (mode == kWeekView) {
dateFormat.Format(startDay, fEvent->GetStartDateTime(),
B_SHORT_DATE_FORMAT);
dateFormat.Format(endDay, fEvent->GetEndDateTime(),
B_SHORT_DATE_FORMAT);
timePeriod << startTime << ", " << startDay << " - " \
<< endTime << ", " << endDay;
} else {
BDurationFormat formatter(", ", B_TIME_UNIT_ABBREVIATED);
if (now.Time_t() >= fEvent->GetStartDateTime() &&
now.Time_t() <= fEvent->GetEndDateTime()) {
formatter.Format(remaining, 0, difftime(fEvent->GetEndDateTime(), now.Time_t())*1000000);
BString timeLeft(B_TRANSLATE("Now, %remaining% left"));
timeLeft.ReplaceAll("%remaining%", remaining);
timePeriod << timeLeft;
} else if (now.Time_t() < fEvent->GetStartDateTime()) {
formatter.Format(remaining, 0, difftime(fEvent->GetStartDateTime(), now.Time_t())*1000000);
BString timeLeft(B_TRANSLATE("Starts in %remaining%"));
timeLeft.ReplaceAll("%remaining%", remaining);
timePeriod << timeLeft;
} else
timePeriod = B_TRANSLATE("Finished!");
}
}

if (fEvent->GetStatus() & EVENT_CANCELLED)
timePeriod << " [Cancelled]";

fTimeText = timePeriod;
}
13 changes: 8 additions & 5 deletions src/EventListItem.h
Original file line number Diff line number Diff line change
@@ -12,23 +12,26 @@
#include <ListItem.h>
#include <String.h>

class Event;


class EventListItem: public BListItem {
public:
EventListItem(BString name, BString timeText,
rgb_color color, uint16 font_face = -1);
EventListItem(Event* event, int32 mode);
~EventListItem();

virtual void DrawItem(BView*, BRect, bool);
virtual void Update(BView*, const BFont*);

Event* GetEvent();

private:
void _CalcTimeText(int32 mode);

static const int fItemHeight = 42;

BString fName;
Event* fEvent;
BString fTimeText;
rgb_color fColor;
uint16 fFace;
};

#endif // EVENTLLISTITEM_H
33 changes: 30 additions & 3 deletions src/EventListView.cpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#include <PopUpMenu.h>
#include <String.h>

#include "Event.h"
#include "EventListItem.h"
#include "MainWindow.h"
#include "DayView.h"
@@ -189,11 +190,36 @@ EventListView::MouseUp(BPoint position)


void
EventListView::SetPopUpMenuEnabled(bool enable)
EventListView::SelectionChanged()
{
if (fPopUpMenuEnabled == enable)
return;
BMessage msg(kEventSelected);
msg.AddInt32("index", CurrentSelection());

if (CurrentSelection() > -1) {
EventListItem* sItem = dynamic_cast<EventListItem *>
(ItemAt(CurrentSelection()));
if (sItem != NULL)
msg.AddBool("_cancelled",
(sItem->GetEvent()->GetStatus() & EVENT_CANCELLED));
}
Messenger().SendMessage(&msg);
}


void
EventListView::MakeEmpty()
{
BMessage msg(kEventSelected);
msg.AddInt32("index", -1);
Messenger().SendMessage(&msg);

BListView::MakeEmpty();
}


void
EventListView::SetPopUpMenuEnabled(bool enable)
{
fPopUpMenuEnabled = enable;
}

@@ -218,6 +244,7 @@ EventListView::_ShowPopUpMenu(BPoint screen)
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Cancel"),
new BMessage(kCancelActionInvoked));
item->SetMarked(sItem->GetEvent()->GetStatus() & EVENT_CANCELLED);
menu->AddItem(item);

if (!fPopUpMenuEnabled) {
13 changes: 8 additions & 5 deletions src/EventListView.h
Original file line number Diff line number Diff line change
@@ -15,14 +15,17 @@ static const uint32 kPopClosed = 'kpop';

class EventListView : public BListView {
public:
EventListView();
~EventListView();
EventListView();
~EventListView();

virtual void Draw(BRect rect);
virtual void FrameResized(float w, float h);
virtual void MessageReceived(BMessage* message);

virtual void Draw(BRect rect);
virtual void FrameResized(float w, float h);
virtual void MessageReceived(BMessage* message);
void MouseDown(BPoint position);
void MouseUp(BPoint position);
void SelectionChanged();
void MakeEmpty();

void SetPopUpMenuEnabled(bool enable);

Loading