/IvoR.hws (ab1c18deb73057c58d5744e7bdee8b1301cdc08a) (8933 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()
	
	self.feedid = feedid$
	self.link = feedid$
	
	;č teprve teď uklízíme  
	Ivor:Clear()
	
	; TODO: load icon
	If AllowImages
		self.ImageLoaded = False
		self:LoadImage()
		If Not self.ImageLoaded Then mui.Set("feedimage", "Brush", 1)
	EndIf 
	
	
	;č 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 
	
	;č zjednodušená kontrola místo adekvátního zpracování  =]
	If self.feedid = feedid$ Then fd_Set(feedid$, "guids", self.guids)
	
EndFunction 


Function IvoR:ShowArticle(pos)
	If pos >= 0
		Local chosen_item = self.items_list[pos]
		mui.Set("item_author", "Contents", chosen_item.author)
		mui.Set("item_pubdate", "Contents", chosen_item.pubdate)
		mui.Set("item_title", "Contents", tf_Label(chosen_item.title))
		mui.Set("item_link", "Contents", chosen_item.link)
		
		If StrLen(chosen_item.description) > StrLen(chosen_item.content)
			mui.Set("textfield", "Text", tf_TextField(chosen_item.description))
		Else
			mui.Set("textfield", "Text", tf_TextField(chosen_item.content))
		EndIf
		
		If Not HaveItem(self.guids, chosen_item.guid) And 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:DownloadImage(str$)
	If Not AllowImages Or self.ImageLoaded Then Return()
	Local extension$ = "image"
	If StrLen(str$) > 4 
		Switch LowerStr(RightStr(str$, 4))
		Case "ilbm": FallThrough 
		Case ".lbm": extension$ = "ilbm"
		Case ".png": extension$ = "png"
		Case ".gif": extension$ = "gif"
		Case "jpeg": FallThrough 
		Case ".jpg": extension$ = "jpg"
		Case ".bmp": extension$ = "bmp"
		EndSwitch
	EndIf

	Local url$ = p_reconstructURL(self.link, str$)
	Local err_code, _empty_str$, count = ?DownloadFile(url$, 
				{File=p_GetLogoName(self.feedid, extension$), Adapter="hurl", 
				Fail404=True, Encoded=FindStr(url$, "%", True) <> -1})
	p_Replay(err_code, "Image logo is downloaded") 
	fd_Set(self.feedid, "imageformat", extension$)
	
	self:LoadImage()
	
EndFunction

Function IvoR:LoadImage()
	If Not AllowImages Or self.ImageLoaded Then Return()
	Local extension$ = fd_Get(self.feedid, "imageformat")
	If IsNil(extension$) Then Return()
	
	Local filename$ = p_GetLogoName(self.feedid, extension$)
	Local ret, t = IsPicture(filename$, {Loader="Inbuilt"})
	If Not ret Then Return()
	

	Local err_code, _id = ?LoadBrush(2, filename$, 
						{LoadAlpha = t.Alpha, LoadTransparency=t.Transparency})
	If err_code <> #ERR_NONE 
		mui.Set("status", "Contents", "\27b" .. GetErrorName(err_code))
		Return()
	EndIf
	If t.Height > 32 Then ScaleBrush(2, #KEEPASPRAT, 32)
		
	mui.Set("feedimage", "Brush", 2)
	self.ImageLoaded = True
EndFunction

Function IvoR:OpenLink(muid)
	;č Vostuda, ale nemáme to nikde uloženo. Jen na formě =]
	Local url$ = mui.Get(muid, "Contents")
	If url$ Then OpenURL(url$)
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("channel_link", "Contents", "")

	mui.DoMethod("articles", "Clear")

	
	mui.Set("item_author", "Contents", "")
	mui.Set("item_pubdate", "Contents", "")
	mui.Set("item_title", "Contents", "")
	mui.Set("item_link", "Contents", "")
	
	mui.Set("textfield", "Text", "")
	



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

	current_item = {author="", title="", link="", content="", 
					pubdate="", category="", description="", guid=""}
EndFunction 


Function StartElement(p, name$, attrs) 
	current_element$ = name$
	If name$ = "item" Or name$ = "entry" Then channel_level = False
EndFunction 


Function EndElement(p, name$) 
	current_element$ = nil
	If name$ = "item" Or name$ = "entry"
		Local preparse = ""
		If current_item.guid <> "" 
			;č mezery v indexu zboří serializator
			;č prázdný řetězec zboří MD5 kalkulačku  
			current_item.guid = MD5Str(current_item.guid)
			If HaveItem(IvoR.oldguids, current_item.guid)
				IvoR.guids[current_item.guid] = 1
			Else
				preparse = "\27b"
			EndIf
		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 = {author="", title="", link="", content="", 
						pubdate="", category="", description="", guid=""}
	EndIf
EndFunction 



Function CharacterData(p, str$) 
	If channel_level
		Switch current_element$
		Case "title": mui.Set("channel_title", "Contents", tf_Label(str$))
		Case "description": 
			mui.Set("channel_description", "Contents", tf_Label(str$))
		
		Case "id": FallThrough 
		Case "link": 
			IvoR.link = StripStr(str$)
			mui.Set("channel_link", "Contents", StripStr(str$))
			
		;č url podle RSS specifikace musí být pouze u obrázků. 
		Case "url": IvoR:DownloadImage(StripStr(str$))
		Case "logo": IvoR:DownloadImage(StripStr(str$))
			
		EndSwitch
	
	Else
		current_item.guid = current_item.guid .. str$
		Switch current_element$
		Case "title": 
			current_item.title = tf_Label(str$)
			;current_item.guid = current_item.guid .. "title:" .. str$
		Case "dc:creator": FallThrough 
		Case "author": current_item.author = StripStr(str$)
		;č číselné hodnoty se nějak špatně načítají.
		;č fakt je nějaký problém v tom serializatoru 
		Case "guid": 
			If current_item.link = "" Then current_item.link = StripStr(str$)
			;current_item.guid = current_item.guid .. "guid:" .. str$
		Case "updated": 
			;current_item.guid = current_item.guid .. "updated:" .. str$
			current_item.pubdate = StripStr(str$)
		Case "pubDate": current_item.pubdate = StripStr(str$)
		
			
		Case "summary": FallThrough 
		Case "atom:summary": FallThrough 
		Case "description": 
			current_item.description = current_item.description ..StripStr(str$)
			
		Case "content": FallThrough 
		Case "content:encoded": 
			current_item.content = current_item.content ..StripStr(str$)
			
		Case "id": FallThrough 
		Case "link": 
			current_item.link = StripStr(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 6407 e72a76d6b87c502f01cb106825d3faf3176883d3 AppWindow.xml
100755 blob 8933 ab1c18deb73057c58d5744e7bdee8b1301cdc08a IvoR.hws
100755 blob 9258 bbaabaceb6d076c017ef6eb91e68560d3898bfaf IvoRSS.hws
100644 blob 10608 192d95f5f61757959ec1bc13686ade1b23197e28 IvoRSS.info
100755 blob 7191 6291191cf3b1e9b7dd44493a09e26918f2c6e3d1 IvoRSS.png
100755 blob 6591 b736627eb96bd0ce013c7bebe86342c8c5304d68 IvoRSS_light.png
100755 blob 1093 263306d87c51114b1320be2ee3277ea0bff99b1f LICENSE
100755 blob 1906 4e18f3e83d428c9bf940ef131f8b2187d2c2bbd3 ReadMe
100755 blob 4007 8956c1bb5d76b481d4e2458b16a64fbee8f6f9e6 feeds.hws
100755 blob 1694 83e47eb86860331dfe771f49029c00559a2f687e feedsdata.hws
100755 blob 13089 b20da94931f651264cb9ab0655fca95b0ac1a3f3 feedtree.hws
100755 blob 7305 d6eda6d26dcd117cbe3eeda270397ef72a592f83 lurk.hws
100755 blob 10863 6a7d367a3f5e63c2738121c1bfc25c448017c0aa 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