Page 1 of 1

[Module] iCalModule.pbi (all OS)

Posted: Fri Jul 12, 2019 3:48 pm
by Thorsten1867
iCal - Module (all OS / 64Bit)

Support for iCal files (import/export)

Code: Select all

; iCal::AddEvent()    - adds an event to iCal
; iCal::ClearEvents() - clear all events
; iCal::Create()      - create an iCal entry
; iCal::ExportFile()  - export as iCal file (*.ics)
; iCal::GetEvents()   - get events as linked list (iCal::Event_Structure)
; iCal::ImportFile()  - import an iCal file (*.ics)
; iCal::Remove(ID.i)  - remove the iCal entry
Download: iCalModule.pbi

Re: [Module] iCalModule.pbi (all OS)

Posted: Fri Oct 18, 2019 7:24 am
by Cyllceaux
Nice work... But found some issues:

1) Create returns #True/#False. But if I put #PB_Any in it... How can I receive the "new" ID?
2) The iCal allows something like that:

Code: Select all

SUMMARY;LANGUAGE=de:Wir haben mal eine Frage zu GEBI

Code: Select all

DTEND;TZID="W. Europe Standard Time":20191016T143000
DTSTART;TZID="W. Europe Standard Time":20191016T140000

Code: Select all

DTSTART;VALUE=DATE:20180307

Re: [Module] iCalModule.pbi (all OS)

Posted: Fri Sep 04, 2020 12:36 pm
by dige
Small addition:
If the description contains html formatted text:

Summary of changes:

Code: Select all

CreateRegularExpression(0, "\<[^\<]+\>")

WriteStringN(FileID, #iCal_Description + EscapeText(ReplaceRegularExpression(0, iCal()\Event()\Description, "")), #PB_UTF8)

 If FindString(iCal()\Event()\Description, "<html>", 0, #PB_String_NoCase)
    WriteStringN(FileID, ~"X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" +
                         EscapeText(iCal()\Event()\Description), #PB_UTF8)
 EndIf


In Procedure ExportFile():

Code: Select all

Procedure.i ExportFile(ID.i, File.s="iCal_Export.ics")
    Define.i FileID, Result = #False
    
    CreateRegularExpression(0, "\<[^\<]+\>") ; Html entfernen
    
    If FindMapElement(iCal(), Str(ID))
      
      FileID = CreateFile(#PB_Any, File, #PB_UTF8)
      If FileID
        
        WriteStringFormat(FileID, #PB_UTF8)
        
        WriteStringN(FileID, #iCal_BeginCalendar, #PB_UTF8)
        WriteStringN(FileID, #iCal_Version,       #PB_UTF8)
        WriteStringN(FileID, #iCal_ProID + iCal()\ProducerID, #PB_UTF8)
        
        If iCal()\Method = #Request
          WriteStringN(FileID, #iCal_Request, #PB_UTF8)
        Else
          WriteStringN(FileID, #iCal_Publish, #PB_UTF8)
        EndIf
        
        ForEach iCal()\Event()
          
          WriteStringN(FileID, #iCal_BeginEvent, #PB_UTF8)
          WriteStringN(FileID, #iCal_UID         + iCal()\Event()\UID,         #PB_UTF8)
          WriteStringN(FileID, #iCal_Location    + EscapeText(iCal()\Event()\Location),    #PB_UTF8)
          
          If iCal()\Summary
            WriteStringN(FileID, ReplaceString(#iCal_Summary, ":", iCal()\Summary + ":") + EscapeText(iCal()\Event()\Summary), #PB_UTF8)
          Else
            WriteStringN(FileID, #iCal_Summary + EscapeText(iCal()\Event()\Summary), #PB_UTF8)
          EndIf
          
          WriteStringN(FileID, #iCal_Description + EscapeText(ReplaceRegularExpression(0, iCal()\Event()\Description, "")), #PB_UTF8)
          
          If iCal()\Event()\Class = #Private
            WriteStringN(FileID, #iCal_Private, #PB_UTF8)
          Else
            WriteStringN(FileID, #iCal_Public,  #PB_UTF8)
          EndIf
          
          If FindString(iCal()\Event()\Description, "<html>", 0, #PB_String_NoCase)
            WriteStringN(FileID, ~"X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" +
                                 EscapeText(iCal()\Event()\Description), #PB_UTF8)
          EndIf
          
          If iCal()\DTStart
            WriteStringN(FileID, ReplaceString(#iCal_DateStart, ":", iCal()\DTStart + ":") + DateICal(iCal()\Event()\StartDate), #PB_UTF8)
          Else
            WriteStringN(FileID, #iCal_DateStart + DateICal(iCal()\Event()\StartDate), #PB_UTF8)
          EndIf
          
          If iCal()\DTEnd 
            WriteStringN(FileID, ReplaceString(#iCal_DateEnd, ":", iCal()\DTEnd + ":") + DateICal(iCal()\Event()\EndDate), #PB_UTF8)
          Else
            WriteStringN(FileID, #iCal_DateEnd + DateICal(iCal()\Event()\EndDate), #PB_UTF8)
          EndIf 
          
          WriteStringN(FileID, #iCal_DateStamp + DateICal(iCal()\Event()\DateStamp), #PB_UTF8)
          
          WriteStringN(FileID, #iCal_EndEvent,  #PB_UTF8)
          
        Next
        
        WriteStringN(FileID, #iCal_EndCalendar, #PB_UTF8)

        Result = #True
        
        CloseFile(FileID)
      EndIf
      
    EndIf
    
    ProcedureReturn Result
  EndProcedure

Re: [Module] iCalModule.pbi (all OS)

Posted: Wed Feb 21, 2024 12:40 pm
by loulou2522
How can I send an invitation from the event created in Ical?
Thanks