It is currently Fri Oct 30, 2020 2:47 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Module] iCalModule.pbi (all OS)
PostPosted: Fri Jul 12, 2019 3:48 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1265
Location: Germany
iCal - Module (all OS / 64Bit)

Support for iCal files (import/export)

Code:
; 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

_________________
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 10 x64] [PB V5.7x]


Last edited by Thorsten1867 on Sat Nov 23, 2019 11:52 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] iCalModule.pbi (all OS)
PostPosted: Fri Oct 18, 2019 7:24 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Jun 23, 2014 1:18 pm
Posts: 216
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:
SUMMARY;LANGUAGE=de:Wir haben mal eine Frage zu GEBI

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

Code:
DTSTART;VALUE=DATE:20180307


Top
 Profile  
Reply with quote  
 Post subject: Re: [Module] iCalModule.pbi (all OS)
PostPosted: Fri Sep 04, 2020 12:36 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 1048
Location: Germany
Small addition:
If the description contains html formatted text:

Summary of changes:
Code:
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:
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..."


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye