[Module] iCalModule.pbi (all OS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] iCalModule.pbi (all OS)

Post 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
Last edited by Thorsten1867 on Sat Nov 23, 2019 11:52 am, edited 1 time in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

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

Post 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
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

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

Post 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
"Daddy, I'll run faster, then it is not so far..."
loulou2522
Enthusiast
Enthusiast
Posts: 496
Joined: Tue Oct 14, 2014 12:09 pm

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

Post by loulou2522 »

How can I send an invitation from the event created in Ical?
Thanks
Post Reply