File IvoR.hws changed (mode: 100755) (index 87f34b2..56bbaba) |
1 |
1 |
; Module for the right side of the application |
; Module for the right side of the application |
2 |
2 |
|
|
3 |
|
; Hollywood-like object programming... |
|
|
3 |
|
; Hollywood-like object programming :) |
4 |
4 |
IvoR = {} |
IvoR = {} |
|
5 |
|
IvoR.parsers = CreateList() |
|
6 |
|
|
5 |
7 |
|
|
6 |
|
;č Testy ukazují, že jediný způsob zavolat funkce je IvoR:Foo(), |
|
7 |
|
;č zatímco k atributům lze přistupovat |
|
8 |
|
;č buď pomocí IvoR.Bar nebo self.Bar |
|
9 |
|
;č V tom self nevidím žádný smysl |
|
10 |
8 |
|
|
11 |
|
IvoR.parsers = CreateList() |
|
12 |
9 |
|
|
13 |
10 |
Function IvoR:Load(feedid$) |
Function IvoR:Load(feedid$) |
14 |
11 |
;DebugPrint(p_GetXMLname(feedid$)) |
;DebugPrint(p_GetXMLname(feedid$)) |
15 |
|
Local err_code, text$, _len = ?FileToString(p_GetXMLname(feedid$)) |
|
|
12 |
|
Local err_code, xml$, _len = ?FileToString(p_GetXMLname(feedid$)) |
16 |
13 |
; když máme chybu, tak rovnou končíme |
; když máme chybu, tak rovnou končíme |
17 |
14 |
If err_code <> #ERR_NONE |
If err_code <> #ERR_NONE |
18 |
15 |
mui.Set("status", "Contents", "\27b" .. GetErrorName(err_code)) |
mui.Set("status", "Contents", "\27b" .. GetErrorName(err_code)) |
|
... |
... |
Function IvoR:Load(feedid$) |
28 |
25 |
If Not isNil(lastP) Then lastP:Stop() |
If Not isNil(lastP) Then lastP:Stop() |
29 |
26 |
|
|
30 |
27 |
|
|
31 |
|
items_list = CreateList() |
|
32 |
|
channel_level = True |
|
33 |
|
current_element$ = Nil |
|
34 |
|
|
|
35 |
|
current_item = {title="", pubdate="", category="", description=""} |
|
|
28 |
|
|
36 |
29 |
|
|
37 |
30 |
Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData}) |
Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData}) |
38 |
31 |
InsertItem(Ivor.parsers, p) |
InsertItem(Ivor.parsers, p) |
39 |
32 |
DebugPrint("Created parser ", ListItems(Ivor.parsers)) |
DebugPrint("Created parser ", ListItems(Ivor.parsers)) |
40 |
|
p:Parse(text$) |
|
41 |
|
;GetItem(Ivor.parsers, -1):Parse(text$) |
|
42 |
|
;p:Parse([[ text </to> ]]) |
|
43 |
|
err_code = ?p:Close() |
|
|
33 |
|
|
|
34 |
|
p:setbase(feedid$) |
|
35 |
|
|
|
36 |
|
p:Parse(xml$) |
|
37 |
|
|
|
38 |
|
;Local lin, col, pos = p:pos() |
|
39 |
|
;DebugPrint(lin, col, pos) |
|
40 |
|
|
|
41 |
|
Local err_code = ?p:Close() |
|
42 |
|
Local errorname = GetErrorName(err_code) |
|
43 |
|
;DebugPrint(err_code, GetErrorName(err_code)) |
44 |
44 |
DebugPrint("Parser closed", ListItems(Ivor.parsers)) |
DebugPrint("Parser closed", ListItems(Ivor.parsers)) |
45 |
45 |
RemoveItem(Ivor.parsers) |
RemoveItem(Ivor.parsers) |
46 |
|
;err_code = ?Ivor.parsers[0].Close() |
|
|
46 |
|
|
|
47 |
|
;č moc se mně neptejte, ale zdá se, |
|
48 |
|
;č že se vracejí odlišné chyby se stejným kódem |
|
49 |
|
If errorname = "Error closing parser: unknown encoding!" |
|
50 |
|
DebugPrint("Eště jeden pokus...") |
|
51 |
|
|
|
52 |
|
Ivor:Clear() |
|
53 |
|
|
|
54 |
|
;č je to hodně nebezpečný, ale řekl bych, že spadl-li |
|
55 |
|
;č parser kvůli kódování, tak nemohl žádný kólbek spustit |
|
56 |
|
Local p = XMLParser.New({StartElement = StartElement, EndElement=EndElement, CharacterData = CharacterData}) |
|
57 |
|
InsertItem(Ivor.parsers, p) |
|
58 |
|
DebugPrint("Created parser ", ListItems(Ivor.parsers)) |
|
59 |
|
|
|
60 |
|
p:setbase(feedid$) |
|
61 |
|
|
|
62 |
|
|
|
63 |
|
;č Zoufalý pokus zobrazit aspoň něco |
|
64 |
|
;č 1. Polski Portal Amigowy používá ISO-8859-2 |
|
65 |
|
;č 2. Ale spousta amigistů taky pochází z Polska |
|
66 |
|
;č a budou nejspíš taky mít ISO-8859-2 v systému |
|
67 |
|
;č 3. Polski Portal Amigowy je zahraněn! |
|
68 |
|
xml$ = ConvertStr(xml$, #ENCODING_AMIGA, #ENCODING_UTF8) |
|
69 |
|
p:setencoding("UTF-8") |
|
70 |
|
|
|
71 |
|
p:Parse(xml$) |
|
72 |
|
;Local lin, col, pos = p:pos() |
|
73 |
|
;DebugPrint(lin, col, pos) |
|
74 |
|
|
|
75 |
|
Local err_code = ?p:Close() |
|
76 |
|
;Local errorname = GetErrorName(err_code) |
|
77 |
|
;DebugPrint(err_code, GetErrorName(err_code)) |
|
78 |
|
DebugPrint("Parser closed", ListItems(Ivor.parsers)) |
|
79 |
|
RemoveItem(Ivor.parsers) |
|
80 |
|
EndIf |
47 |
81 |
EndFunction |
EndFunction |
48 |
82 |
|
|
49 |
83 |
|
|
50 |
84 |
Function IvoR:Clear() |
Function IvoR:Clear() |
51 |
85 |
mui.Set("channel_title", "Contents", "") |
mui.Set("channel_title", "Contents", "") |
52 |
|
mui.Set("channel_title", "ContextMenu", "(none)") |
|
|
86 |
|
;mui.Set("channel_title", "ContextMenu", "(none)") |
53 |
87 |
|
|
54 |
88 |
mui.Set("channel_description", "Contents", "") |
mui.Set("channel_description", "Contents", "") |
55 |
|
mui.Set("channel_description", "ContextMenu", "(none)") |
|
56 |
|
|
|
|
89 |
|
;mui.Set("channel_description", "ContextMenu", "(none)") |
57 |
90 |
|
|
58 |
|
mui.Set("articles", "Quiet", True) |
|
59 |
|
For Local k = 1 To mui.Get("articles", "Entries") |
|
60 |
|
mui.DoMethod("articles", "Remove", "Last") |
|
61 |
|
Next |
|
62 |
|
mui.Set("articles", "Quiet", False) |
|
|
91 |
|
mui.DoMethod("articles", "Clear") |
63 |
92 |
|
|
64 |
93 |
mui.Set("item_title", "Contents", "") |
mui.Set("item_title", "Contents", "") |
65 |
|
mui.Set("item_title", "ContextMenu", "(none)") |
|
|
94 |
|
;mui.Set("item_title", "ContextMenu", "(none)") |
66 |
95 |
|
|
67 |
96 |
mui.Set("textfield", "Text", "") |
mui.Set("textfield", "Text", "") |
68 |
|
mui.Set("textfield", "ContextMenu", "(none)") |
|
|
97 |
|
;mui.Set("textfield", "ContextMenu", "(none)") |
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
items_list = CreateList() ;č ten necháme globálním |
|
103 |
|
channel_level = True |
|
104 |
|
current_element$ = Nil |
|
105 |
|
|
|
106 |
|
current_item = {title="", pubdate="", category="", description=""} |
69 |
107 |
EndFunction |
EndFunction |
70 |
108 |
|
|
71 |
109 |
|
|
|
... |
... |
Function EndElement(p, name$) |
97 |
135 |
EndIf |
EndIf |
98 |
136 |
EndFunction |
EndFunction |
99 |
137 |
|
|
100 |
|
;asdf |
|
|
138 |
|
|
|
139 |
|
|
101 |
140 |
Function CharacterData(p, str$) |
Function CharacterData(p, str$) |
102 |
141 |
;DebugPrint("CD: ", str$) |
;DebugPrint("CD: ", str$) |
103 |
142 |
If channel_level |
If channel_level |