/IvoR.hws (3cf6263ec8ecae76b4b154a1ee8beb58569ab2af) (5510 bytes) (mode 100755) (type blob)

; Module for the right side of the application

; Hollywood-like object programming :)
IvoR = {}
IvoR.parsers = CreateList()




Function IvoR:Load(feedid$)
	Local err_code, xml$, _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 
	
	;č dále je třeba pozastavit případný parser "z minula"
	local lastP = GetItem(IvoR.parsers, -1)
	If Not isNil(lastP) Then lastP:Stop()
	
	;č teprve teď uklízíme  
	Ivor:Clear()
	
	; TODO: load icon
	
	
	;č a vytahujeme seznam přečteného
	Local t = fd_Get(feedid$, "guids")
	If GetType(t) = #TABLE
		self.oldguids = t
	Else
		self.oldguids = {}
	EndIf
	
	;č na konci tohle nahradí už "staré" guids	
	;č Je to aby se staré, nejspíš i nedostupné zápisy nehromadily. 
	;č Funkce "pravé" strany budou rovnou psát do IvoR.guids
	self.guids = {} 
	
	
	
	Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData})
	InsertItem(Ivor.parsers, p) 
	DebugPrint("Created parser ", ListItems(Ivor.parsers)) 
	
	p:setbase(feedid$)
	
	p:Parse(xml$)
	
	;Local lin, col, pos = p:pos()
	;DebugPrint(lin, col, pos) 
	
	Local err_code = ?p:Close() 
	Local errorname = GetErrorName(err_code)
	;DebugPrint(err_code, GetErrorName(err_code))
	DebugPrint("Parser closed", ListItems(Ivor.parsers)) 
	RemoveItem(Ivor.parsers)
	
	;č moc se mně neptejte, ale zdá se, 
	;č že se vracejí odlišné chyby se stejným kódem 	
	If errorname = "Error closing parser: unknown encoding!"
		
		Ivor:Clear()
		
		;č je to hodně nebezpečný, ale řekl bych, že spadl-li
		;č parser kvůli kódování, tak nemohl žádný kólbek spustit
		Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData})
		InsertItem(Ivor.parsers, p) 
		DebugPrint("Created parser ", ListItems(Ivor.parsers)) 
		
		p:setbase(feedid$)
		
		
		;č Zoufalý pokus zobrazit aspoň něco
		;č 1. Polski Portal Amigowy používá ISO-8859-2
		;č 2. Ale spousta amigistů taky pochází z Polska 
		;č    a budou nejspíš taky mít ISO-8859-2 v systému
		;č 3. Polski Portal Amigowy je zahraněn!  	
		xml$ = ConvertStr(xml$, #ENCODING_AMIGA, #ENCODING_UTF8)
		p:setencoding("UTF-8")
		
		p:Parse(xml$)
		;Local lin, col, pos = p:pos()
		;DebugPrint(lin, col, pos) 
		
		Local err_code = ?p:Close() 
		;Local errorname = GetErrorName(err_code)
		;DebugPrint(err_code, GetErrorName(err_code))
		DebugPrint("Parser closed", ListItems(Ivor.parsers)) 
		RemoveItem(Ivor.parsers)
	EndIf 
	
	fd_Set(feedid$, "guids", self.guids)
	
EndFunction 


Function IvoR:ShowArticle(pos)
	If pos >= 0
		Local chosen_item = self.items_list[pos]
		mui.Set("item_title", "Contents", tf_Label(chosen_item.title))
		mui.Set("textfield", "Text", tf_TextField(chosen_item.description))
		
		If Not HaveItem(self.guids, chosen_item.guid)
			mui.DoMethod("articles", "Rename", pos, 
					chosen_item.title,
					chosen_item.pubdate,
					chosen_item.category)
			self.guids[chosen_item.guid] = 1
		EndIf
	EndIf 
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.DoMethod("articles", "Clear")

	mui.Set("item_title", "Contents", "")
	;mui.Set("item_title", "ContextMenu", "(none)")
	
	mui.Set("textfield", "Text", "")
	;mui.Set("textfield", "ContextMenu", "(none)")
	



	self.items_list = CreateList()
	channel_level = True
	current_element$ = Nil

	current_item = {title="", pubdate="", category="", description="", guid=""}
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"
		Local preparse = ""
		If HaveItem(IvoR.oldguids, current_item.guid)
			IvoR.guids[current_item.guid] = 1
			preparse = ""
		Else
			preparse = "\27b"
		EndIf 
		mui.DoMethod("articles", "Insert", "Bottom", 
					preparse .. current_item.title,
					preparse .. current_item.pubdate,
					preparse .. current_item.category)
		InsertItem(IvoR.items_list, current_item)
		CheckEvents() 
		current_item = {title="", pubdate="", category="", description="", guid=""}
	EndIf
EndFunction 



Function CharacterData(p, str$) 
	;DebugPrint("CD: ", str$) 
	If channel_level
		If current_element$ = "title" Then mui.Set("channel_title", "Contents", tf_Label(str$))
		If current_element$ = "description" Then mui.Set("channel_description", "Contents", tf_Label(str$))
	
	Else
		Switch current_element$
		Case "title": current_item.title = tf_Label(str$)
		
		;č číselné hodnoty se nějak špatně načítají.
		;č fakt je nějaký problém v tom serializatoru 
		Case "guid": current_item.guid = "guid:" .. str$
		Case "pubDate": current_item.pubdate = tf_Label(str$)
		Case "description": 
			current_item.description = current_item.description ..str$
		Case "category":
			If current_item.category = ""
				current_item.category = tf_Label(str$)
			Else
				current_item.category = current_item.category .. ", " .. tf_Label(str$)
			EndIf 
		EndSwitch
	EndIf
EndFunction 

 




Mode Type Size Ref File
100755 blob 7473 1ab45355102d3c454b8d83e05e4af10b0447dee3 128px-Feed-icon.png
100755 blob 5756 d61efca27af920fdf68f18f54807d3033f7760bf AppWindow.xml
100755 blob 5510 3cf6263ec8ecae76b4b154a1ee8beb58569ab2af IvoR.hws
100755 blob 8448 1b61d76a2bb77c5f30b9812a50f0a8a7ed2621d7 IvoRSS.hws
100755 blob 7191 6291191cf3b1e9b7dd44493a09e26918f2c6e3d1 IvoRSS.png
100755 blob 4405 6f1fc460afb31e6e38cd78dd01c0debaae6f5343 feeds.hws
100755 blob 1694 83e47eb86860331dfe771f49029c00559a2f687e feedsdata.hws
100755 blob 8999 c094abfdbb99b8bc338e907131d3f14cab5a01fa feedtree.hws
100755 blob 6412 f39265cc944ed3be89260bc28f32c3805794fb0d lurk.hws
100755 blob 4508 149969e90caff1606eb9311958b5ce936ca87a67 textfield.hws
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/IvoRSS

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/IvoRSS

Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/IvoRSS

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main