Skip to content

Commit

Permalink
Support importing of icalendar events
Browse files Browse the repository at this point in the history
  • Loading branch information
JadedCtrl authored and pulkomandy committed Apr 20, 2021
1 parent 6a6bb0b commit 3c8e458
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SRCS = \
src/Preferences.cpp \
src/SidePanelView.cpp \
src/utils/ColorConverter.cpp \
src/utils/ICal.cpp \
src/utils/ResourceLoader.cpp \
src/model/Category.cpp \
src/model/Event.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ App::RefsReceived(BMessage* message)
info.SetTo(&file);
info.GetType(type);

if (BString(type) == BString("application/x-calendar-event"))
if (BString(type) == BString("application/x-calendar-event") ||
BString(type) == BString("text/calendar"))
fMainWindow->PostMessage(&msg);
else if (BString(type) == BString("application/x-calendar-category")) {
MessageReceived(new BMessage(kMenuCategoryEdit));
Expand Down
11 changes: 7 additions & 4 deletions src/EventWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ EventWindow::EventWindow()
CenterOnScreen();
}

fNew = true;
_DisableControls();
}

Expand Down Expand Up @@ -183,9 +184,11 @@ EventWindow::SetEvent(Event* event)
fTextEndTime->SetText(GetLocaleTimeString(event->GetEndDateTime()));
}

if (fDBManager->GetEvent(event->GetName(), event->GetStartDateTime()))
fNew = false;

fDeleteButton->SetEnabled(true);

if (fNew == false)
fDeleteButton->SetEnabled(true);
}

}
Expand Down Expand Up @@ -324,11 +327,11 @@ EventWindow::OnSaveClick()
fTextDescription->Text(), fAllDayCheckBox->Value() == B_CONTROL_ON,
start, end, category, notified);

if ((fEvent == NULL) && (fDBManager->AddEvent(&newEvent))) {
if ((fNew == true) && (fDBManager->AddEvent(&newEvent))) {
CloseWindow();
}

else if ((fEvent != NULL) && (fDBManager->UpdateEvent(fEvent, &newEvent)))
else if ((fNew == false) && (fDBManager->UpdateEvent(fEvent, &newEvent)))
{
CloseWindow();
}
Expand Down
1 change: 1 addition & 0 deletions src/EventWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class EventWindow: public BWindow {

Event* fEvent;
BList* fCategoryList;
bool fNew;

QueryDBManager* fDBManager;
};
Expand Down
12 changes: 11 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ using BPrivate::BToolBar;
#define B_TRANSLATION_CONTEXT "MainWindow"

extern int32 NotificationLoop(void* data);
extern int32 ImportICalEvents(void* icalFilePtr);


MainWindow::MainWindow()
Expand Down Expand Up @@ -173,9 +174,17 @@ MainWindow::MessageReceived(BMessage* message)
info.SetTo(&file);
info.GetType(type);


if (BString(type) == BString("application/x-calendar-event"))
_LaunchEventManager(DBManager.GetEvent(ref));
else {

else if (BString(type) == BString("text/calendar")) {
thread_id icalThread = spawn_thread(ImportICalEvents,
"ICal import thread", B_NORMAL_PRIORITY,
new BFile(&ref, B_READ_ONLY));
resume_thread(icalThread);

} else {
BMessage msg = BMessage(B_REFS_RECEIVED);
msg.AddRef("refs", &ref);
((App*)be_app)->PostMessage(&msg);
Expand Down Expand Up @@ -376,6 +385,7 @@ MainWindow::_GetSelectedCalendarDate() const
return fSidePanelView->GetSelectedDate();
}


void
MainWindow::_ToggleEventViewButton(int selectedButtonId)
{
Expand Down
3 changes: 2 additions & 1 deletion src/calendar.rdef
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ resource app_version {

resource file_types message {
"types" = "application/x-calendar-category",
"types" = "application/x-calendar-event"
"types" = "application/x-calendar-event",
"types" = "text/calendar"
};

resource(1, "ADD_EVENT") #'VICN' array {
Expand Down
Loading

0 comments on commit 3c8e458

Please sign in to comment.