; Module for the right side of the application
; Hollywood-like object programming...
IvoR = {}
;č Testy ukazují, že jediný způsob zavolat funkce je IvoR:Foo(),
;č zatímco k atributům lze přistupovat
;č buď pomocí IvoR.Bar nebo self.Bar
;č V tom self nevidím žádný smysl
IvoR.parsers = CreateList()
Function IvoR:Load(feedid$)
;DebugPrint(p_GetXMLname(feedid$))
Local err_code, text$, _len = ?FileToString(p_GetXMLname(feedid$))
; když máme chybu, tak rovnou končíme
If err_code <> #ERR_NONE
mui.Set("status", "Contents", "\27b" .. GetErrorName(err_code))
Return()
EndIf
Ivor:Clear()
; TODO: load icon
local lastP = GetItem(IvoR.parsers, -1)
If Not isNil(lastP) Then lastP:Stop()
items_list = CreateList()
channel_level = True
current_element$ = Nil
current_item = {title="", pubdate="", category="", description=""}
Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData})
InsertItem(Ivor.parsers, p)
DebugPrint("Created parser ", ListItems(Ivor.parsers))
p:Parse(text$)
;GetItem(Ivor.parsers, -1):Parse(text$)
;p:Parse([[ text </to> ]])
err_code = ?p:Close()
DebugPrint("Parser closed", ListItems(Ivor.parsers))
RemoveItem(Ivor.parsers)
;err_code = ?Ivor.parsers[0].Close()
EndFunction
Function IvoR:Clear()
mui.Set("channel_title", "Contents", "")
mui.Set("channel_title", "ContextMenu", "(none)")
mui.Set("channel_description", "Contents", "")
mui.Set("channel_description", "ContextMenu", "(none)")
mui.Set("articles", "Quiet", True)
For Local k = 1 To mui.Get("articles", "Entries")
mui.DoMethod("articles", "Remove", "Last")
Next
mui.Set("articles", "Quiet", False)
mui.Set("item_title", "Contents", "")
mui.Set("item_title", "ContextMenu", "(none)")
mui.Set("textfield", "Text", "")
mui.Set("textfield", "ContextMenu", "(none)")
EndFunction
Function StartElement(p, name$, attrs)
current_element$ = name$
;DebugPrint("starts ", name$)
If name$ = "item" Then channel_level = False
;For i,v In Pairs(attrs)
; If GetType(i) = #STRING Then DebugPrint("-->", i .. "=" .. v)
;Next
EndFunction
Function EndElement(p, name$)
;DebugPrint("ends ", name$)
current_element$ = nil
If name$ = "item"
mui.DoMethod("articles", "Insert", "Bottom",
current_item.title,
current_item.pubdate,
current_item.category)
InsertItem(items_list, current_item)
CheckEvents()
current_item = {title="", pubdate="", category="", description=""}
EndIf
EndFunction
;asdf
Function CharacterData(p, str$)
;DebugPrint("CD: ", str$)
If channel_level
If current_element$ = "title" Then mui.Set("channel_title", "Contents", StripStr(str$))
If current_element$ = "description" Then mui.Set("channel_description", "Contents", StripStr(str$))
else
If current_element$ = "title" Then current_item.title = StripStr(str$)
If current_element$ = "pubDate" Then current_item.pubdate = StripStr(str$)
If current_element$ = "description" Then current_item.description = StripStr(str$)
If current_element$ = "category"
If current_item.category = ""
current_item.category = str$
Else
current_item.category = current_item.category .. ", " .. StripStr(str$)
EndIf
Endif
EndIf
EndFunction