/IvoRSS.hws (959cdd4530ed01d2332d6123c4f325885d3d2775) (7835 bytes) (mode 100755) (type blob)

@VERSION 6,0
@APPTITLE "IvoRSS"
@APPVERSION "$VER: IvoRSS 0.2 (5.7.22)"
@APPCOPYRIGHT "© 2022, Aleksei Gerasimov"
@APPAUTHOR "Aleksei Gerasimov"
@APPDESCRIPTION "Simple RSS reader"
@APPIDENTIFIER "ivorss"
@REQUIRE "muiroyale", {Version=1, Revision=7}
@REQUIRE "hurl"
@REQUIRE "xmlparser" 
@DISPLAY {Hidden=True}

@FILE 1, "AppWindow.xml"

; Generates default feeds 
; and puts to feeds.json
;@INCLUDE "feeds.hws" 

@INCLUDE "feedtree.hws"

@BRUSH 1, "128px-Feed-icon.png", {LoadAlpha=True, ScaleHeight=32, ScaleWidth=32}
ChannelIconBrush = 1

PleaseStop = True



;Width=#KEEPASPRAT
/*
** Handles all incoming events
*/

Function p_MUIEvent(msg)
    DebugPrint("MUI event!", "  Class:", msg.Class, "  ID:", msg.ID, "  Attribute:", msg.Attribute)
    Switch msg.Class
    Case "Window":
        Switch msg.Attribute
        Case "CloseRequest":
            p_SaveFeeds() 
			End
        EndSwitch
    Case "Menuitem":
        Switch msg.ID
        Case "menu_about":
            Local reqtext$ = "\27c\27b IvoRSS 0.1 \n\27n Simple RSS client"
            If mui.Request("About", reqtext$, "Open repository|*OK") Then OpenURL("http://rocketgit.com/iam-git/IvoRSS")
        Case "menu_about_mui":
            mui.DoMethod("app", "AboutMUI")
        Case "menu_about_muiroyale":
            mui.DoMethod("app", "AboutMUIRoyale")
        Case "menu_quit":
			p_SaveFeeds() 
            End
        Case "menu_muisettings":
            mui.DoMethod("app", "OpenConfigWindow")
		Case "rssi_copy":
			p_CopyIcon() 
		Case "rsst_copy":
			p_CopyContents("channel_title", "Channel title")  
		Case "rssd_copy":
			p_CopyContents("channel_description", "Channel description")  
		Case "artt_copy":
			p_CopyContents("item_title", "Title")  
		Case "art_copy":
			p_CopyText()
			
		Case "menu_save":
			FallThrough
		Case "fdtm_save":
			p_SaveFeeds()
			
		Case "menu_hide":
			FallThrough
		Case "fdtm_hide":
			p_HideFeeds()
			
		Case "menu_expand":
			FallThrough
		Case "fdtm_expand":
			p_ExpandFeeds()
			
		Case "menu_fetchall":
			FallThrough
		Case "fdtm_fetchall":
            p_FetchAll()
			
		Case "fdtm_fetch":
			p_FetchCurrent()
			
		
			
		EndSwitch
	Case "Listview":
		;assert(msg.Attribute = "Active")
		;assert(msg.ID = "articles")
		Local chosen_item = items_list[msg.TriggerValue]
		mui.Set("item_title", "Contents", chosen_item.title)
		mui.Set("textfield", "Text", chosen_item.description)
		
	Case "Button":
		Switch msg.ID
        Case "fetchbtn":
            p_FetchCurrent()
		Case "fetchallbtn":
            p_FetchAll()
		Case "stopbtn":
            p_Unlock()
			
		EndSwitch
    EndSwitch
EndFunction





;č že FFS prý podporovala  
;č jména souborů jen do 31 znaků
Function p_GetFileID(feedid$)
	Return(LeftStr(MD5Str(feedid$), 26))
EndFunction

/* From Hollywood docs:
Action:   #DOWNLOADFILE_STATUS
Count:    Contains the number of bytes that have already been                  downloaded.
Total:    Contains the size of the file being downloaded.
UserData: Contains the value you passed in the "userdata" argument.

The callback function of type #DOWNLOADFILE_STATUS should normally return FALSE. If it returns TRUE, the download operation will be aborted.*/
Function p_callback(t)
	If t.Action = #DOWNLOADFILE_STATUS
		mui.Set("status", "Contents", 
			"Downloading (" .. t.Count .. "/" .. t.Total .. ") " .. t.UserData
				)
		CheckEvents() ; keep MUI responsive
		Return(PleaseStop)
	EndIf
EndFunction


;č stáhnout soubor
Function p_Download(url$, filename$)
	Local err_code, _empty_str$, count = ?DownloadFile(url$, 
			{File=filename$, Adapter = "hurl", Fail404=True, Encoded=True},
			p_callback, url$)
	p_Replay(err_code, count .. "bytes from " .. url$ .. " transmitted") 
	CheckEvents() ; keep MUI even more responsive
	Return(err_code)
EndFunction




/*
Function p_Replay(err_code, msg$) 
	If err_code = #ERR_NONE
		mui.Set("status", "Contents", msg$)
	Else
		mui.Set("status", "Contents", "\27b" .. GetErrorName(err_code))
	EndIf 
EndFunction 
*/

Function p_Replay(err_code, msg$) 
	mui.Set("status", "Contents", 
			IIf(err_code = #ERR_NONE, msg$, "\27b" .. GetErrorName(err_code)))
EndFunction 


Function p_CopyIcon() 
	err_code = ?SetClipboard(#CLIPBOARD_IMAGE, ChannelIconBrush)
	p_Replay(err_code, "Icon is copied") 
EndFunction 

Function p_CopyContents(source_id$, source_desc$) 
	err_code = ?SetClipboard(#CLIPBOARD_TEXT, mui.Get(source_id$, "Contents"))
	p_Replay(err_code, source_desc$ .. " is copied") 
EndFunction 

Function p_CopyText() 
	err_code = ?SetClipboard(#CLIPBOARD_TEXT, mui.Get("textfield", "Text"))
	p_Replay(err_code, "Text is copied") 
EndFunction 







Function p_StartUpLoading() 
	; default feeds are generated by feeds.hws
	Local err_code, s$, _len = ?FileToString("feeds.json")
	p_Replay(err_code, "Program started") 

	err_code = ?p_FillListTree("feedtree", DeserializeTable(s$))
	p_Replay(err_code, "Feeds are imported") 

	feedsdata = {} ; Global
	err_code = ?LoadPrefs(feedsdata)
	p_Replay(err_code, "Settings loaded") 
EndFunction 


Function p_SaveFeeds() 
	Local err_code = ?StringToFile(SerializeTable(
							p_DumpFeedTree("feedtree")), "feeds.json")
	p_Replay(err_code, "Tree arrangement saved") 
	
	err_code = ?SavePrefs(feedsdata)
	p_Replay(err_code, "Settings saved") 
EndFunction 	



Function p_HideFeeds() 
	mui.DoMethod("feedtree", "close", "root", "all")
EndFunction 

Function p_ExpandFeeds() 
	mui.DoMethod("feedtree", "open", "root", "all")
EndFunction 


Function p_Lock() 
	mui.Set("fetchbtn", "Disabled", True)
	mui.Set("fetchallbtn", "Disabled", True)
	mui.Set("stopbtn", "Disabled", False)
	PleaseStop = False
EndFunction 

Function p_Unlock()
	PleaseStop = True
	mui.Set("stopbtn", "Disabled", True)
	mui.Set("fetchbtn", "Disabled", False)
	mui.Set("fetchallbtn", "Disabled", False)
EndFunction 




		

mui.CreateGUI(ReadString(1))
InstallEventHandler({MUIRoyale = p_MUIEvent})

p_StartUpLoading()

DebugPrint(err_code)

url$ = "https://www.powerpc-notebook.org/en/feed/"
StartTimer(1)
;DownloadFile(url$, {File = "Feeds/feed.xml", Adapter = "hurl"})
p_FetchFeed(url$, {})
DebugPrint("This took", GetTimer(1), "ms", err_code)
text$ = FileToString("feed.xml")
;mui.Set("textfield", "Text", text$)


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

current_item = {title="", pubdate="", category="", description=""}
 
Function StartElement(p, name$, attrs) 
	current_element$ = 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$) 
	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)
		current_item = {title="", pubdate="", category="", description=""}
	EndIf
EndFunction 


Function CharacterData(p, str$) 
	If channel_level
		If current_element$ = "title" Then mui.Set("channel_title", "Contents", str$)
		If current_element$ = "description" Then mui.Set("channel_description", "Contents", str$)
	
	else
		If current_element$ = "title" Then current_item.title = str$
		If current_element$ = "pubDate" Then current_item.pubdate = str$
		If current_element$ = "description" Then current_item.description = str$
		If current_element$ = "category"
			If current_item.category = ""
				current_item.category = str$
			Else
				current_item.category = current_item.category .. ", " .. str$
			EndIf 
		Endif
	EndIf
EndFunction 

 
p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData}) 
p:Parse(text$)
p:Close() 


;sum$ = MD5Str(s$)

;OpenURL(url$)

;t = CreateList()




;Print(GetCatalogString(4, "default string"))

Repeat
	WaitEvent
Forever

Mode Type Size Ref File
100755 blob 7473 1ab45355102d3c454b8d83e05e4af10b0447dee3 128px-Feed-icon.png
100755 blob 4250 225685530c349792288930bccdcb077f6a2f8350 AppWindow.xml
100755 blob 7835 959cdd4530ed01d2332d6123c4f325885d3d2775 IvoRSS.hws
100755 blob 7191 6291191cf3b1e9b7dd44493a09e26918f2c6e3d1 IvoRSS.png
100755 blob 4405 6f1fc460afb31e6e38cd78dd01c0debaae6f5343 feeds.hws
100755 blob 3018 672f3db7befc160cc170712c493dfd7c8e828e97 feedtree.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