Const #LIST_TREE = "feedtree"
Function p_FillListTree(listtree$, treetable)
mui.Set(listtree$, "Quiet", True)
;č ForEach začíná od 1 a teprve na konci se vrací k 0
;ForEach(treetable, p_InsertNode, listtree$)
For _i, t In IPairs(treetable)
mui.DoMethod(listtree$, "Insert",
t.name, t.id, t.parent, "Tail", IIf(t.isNode, "List", ""))
;č pro jednotlivé položky nelze zadat kontextové menu
;mui.Set(t.id, "ContextMenu", "channeltitlemenu")
Next
mui.Set(listtree$, "Quiet", False)
EndFunction
Function p_DumpFeedTree(listtree$)
cFeeds = CreateList() ;currentFeeds
p_DumpListTree(listtree$, cFeeds, "Root", "Root")
Return(cFeeds)
EndFunction
;č tohle musí být rekurzivní
Function p_DumpListTree(listtree$, tabletree, nodeid, muiid)
Local isFound, t = mui.DoMethod(listtree$, "GetEntry", muiid, "Head", "")
While isFound
InsertItem(tabletree, {id=t.id, name=t.name, isNode=t.node, parent=nodeid})
If t.Node = True Then p_DumpListTree(listtree$, tabletree, t.id, t.muiid)
isFound, t = mui.DoMethod(listtree$, "GetEntry", t.muiid, "Next", "")
Wend
EndFunction
Function p_FetchAll()
p_Lock()
If IsOnline() Then p_FetchGroup("Root")
p_Unlock()
EndFunction
;č zjistit co je Node zač,
;č podle toho postupovat
Function p_FetchCurrent()
p_Lock()
Local isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", "Active", "Active", "")
If isFound And Not PleaseStop And IsOnline()
If t.Node
p_FetchGroup(t.muiid)
Else
If p_FetchFeed(t.id) = #ERR_NONE
Ivor:Load(t.id)
EndIf
EndIf
EndIf
p_Unlock()
EndFunction
Function p_ShowCurrent()
Local isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", "Active", "Active", "")
If isFound And Not t.Node
Ivor:Load(t.id)
EndIf
EndFunction
;č zjistit co je Node zač,
;č podle toho postupovat
;č musí být rekurzivní
Function p_FetchGroup(muiid$)
Local isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", muiid$, "Head", "")
While isFound And Not PleaseStop
If t.Node
p_FetchGroup(t.muiid)
Else
p_FetchFeed(t.id)
EndIf
isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", t.muiid, "Next", "")
Wend
EndFunction
;č stáhnout soubor, spočítat hešy,
;č označit buď jako nové, nebo jako přečtené
;č smí se posílat JENOM fidy, nikoliv skupiny
Function p_FetchFeed(feedid$)
If HaveItem(feedsdata, feedid$)
;č Pokud záznam existuje, MUSÍ mít MD5Sum a Name atributy
Local t = feedsdata[feedid$]
If err_code = #ERR_NONE
mui.DoMethod(#LIST_TREE, "Rename", feedid$, "\27".."5\27b" .. feedid$)
Else
mui.DoMethod(#LIST_TREE, "Rename", feedid$, "\27i" .. feedid$)
EndIf
Else
Local err_code = p_Download(feedid$, p_GetXMLname(feedid$))
;č zde je to jednoduchý, stahování je bud úspěšné, nebo neúspěšné
mui.DoMethod(#LIST_TREE, "Rename", feedid$,
IIf(err_code = #ERR_NONE, "\27".."5\27b", "\27i") .. feedid$)
EndIf
Return(err_code)
EndFunction
Function p_RemoveCurrent()
Local isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", "Active", "Active", "")
If isFound And mui.Request("Delete ".. IIf(t.Node, "group", "RSS feed"),
"Do you realy want to delete ".. t.Name ..
IIf(t.Node, " \27ngroup and all its content?", "\27n?"),
"Yes|*Cancel", "Warning")
mui.DoMethod(#LIST_TREE, "Remove", "Active", t.id)
;č vyhodit i přidružená data.
;č Hollywood se pak doopravdy se tváří, že tu položku nikdy neznal,
;č HaveItem je vrací lež no a přístup pak způsobí chybu
feedsdata[t.id] = nil
;č Na soubory ve složce Feeds sereme?
EndIf
EndFunction
Function p_CreateGroup()
Local s$, ok = StringRequest("Create Group", "Enter new group name")
If EmptyStr(s$) Then Return()
s$ = StripStr(s$)
If p_HasItem(s$, "Root")
mui.Set("status", "Contents", "\27bGroup "..s$ .. " already exists")
Else
mui.DoMethod(#LIST_TREE, "Insert", "\27b"..s$, s$, "Root",
IIf(mui.Get(#LIST_TREE, "Active")="Off", "Tail","Active"),
"List; Active")
;p_Replay(err_code, "Group ".."\27b"..s$ .. " has been created")
EndIf
EndFunction
Function p_AddFeed()
Local type, data$ = GetClipboard()
Local s$, ok = StringRequest("Add RSS feed", "Enter feed adress",
IIf(type = #CLIPBOARD_TEXT And StartsWith(data$, "http"),
{Text=data$}, {}))
If EmptyStr(s$) Then Return()
s$ = StripStr(s$)
;č zjednodušená kontrola, pokud řetězec obsahuje procenta,
;č považujeme ho za "eskejpnutý".
;č Na případ, kdy uživatel strčí do URLu osamělý znak procenta vysereme
/* houby, takhle hurl eskejpne úplně všechno
If True ;FindStr(s$, "%") = -1
easy = hurl.Easy()
s$ = easy:Escape(s$)
easy:Close()
EndIf */
If p_HasItem(s$, "Root")
mui.Set("status", "Contents", s$ .. " \27balready exists")
Else
mui.DoMethod(#LIST_TREE, "Insert", "\27".."5"..s$, s$, "Root",
IIf(mui.Get(#LIST_TREE, "Active")="Off", "Tail","Active"),
"Active")
EndIf
EndFunction
;č Kurňadrát, RapaGUI takové starosti nemá...
;č jen pro zábavu
Function p_CanHas(nodeid$)
Return(Not p_HasItem(nodeid$, "Root"))
EndFunction
;č tohle musí být rekurzivní
Function p_HasItem(nodeid$, muiid)
Local isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", muiid, "Head", "")
While isFound
;InsertItem(tabletree, {id=t.id, name=t.name, isNode=t.node, parent=nodeid})
If LowerStr(t.id) = LowerStr(nodeid$) Then Return(True)
If t.Node And p_HasItem(nodeid$, t.muiid) Then Return(True)
isFound, t = mui.DoMethod(#LIST_TREE, "GetEntry", t.muiid, "Next", "")
Wend
Return(False)
EndFunction
;bool = IsOnline()
;r$ = StripStr(s$)
; hURL is required
;e$ = easy:Escape(s$)
;name, isNode, id, parent
/*
Function p_InsertNode(i, t, listtree$)
Local flags$ = IIf(t.isNode, "List", "")
DebugPrint(i, t.id)
mui.DoMethod(listtree$, "Insert", t.name, t.id, t.parent, "Tail", flags$)
EndFunction
*/