Rss Reader — File Browser
RssReaderv1.0 / RssReaderv1.0 / rss / rss.mrc
rss.mrc — 16.36 KB — Download this file
; Rss Reader A Mirc Addon.
; v 1.0 alpha.
;
alias mdx {
var %dll = $scriptdir $+ mdx.dll
return $dll(%dll,$1,$2-)
}
alias hDock {
var %dll = $scriptdir $+ UltraDock.dll
return $dll(%dll,$1,$2-)
}
alias vdll { return $scriptdir $+ views.mdx }
dialog RssReaderBar {
title "Rss Reader"
size -1 -1 160 400
list 4, 1 -1 163 300, size
button "&Refresh",6, 25 325 57 25,
button "&Display",8,83 325 57 25,
button "Co&nfig",7,25 351 57 25,
button "&Close",5,83 351 57 25,
}
alias RssReader {
dialog -m RssReaderBar RssReaderBar
}
on *:dialog:RssReaderBar:init:0:{
;here it is loading the dll mdx. you can change this with the mark function in mdx.
mdx SetMircVersion $version
mdx MarkDialog $dname
mdx SetDialog $dname style
mdx SetControlMDX 4 treeview haslines hasbuttons linesatroot showsel > $vdll
did -i $dname 4 1 tooltip setdefault TreeView tooltip $+ $crlf $+ link
hDock Dock -1 $dialog(RssReaderBar).hwnd left RssReaderBar
; load from the ini file the rss url.
RssReaderBar.Load
}
;-----------------------------------------------------------------------
; Refresh button
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:6: {
Rss.Read $did-tree(RssReaderBar,4)
;if (+b* !iswm %TreeFirstID) {
; Rss.Read %IDtoRead
;}
}
;-----------------------------------------------------------------------
; Undock dialog and close it.
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:5: {
hDock UnDock 0
dialog -x $dname
}
;-----------------------------------------------------------------------
; Display Rss news
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:8: {
rss.show $did-tree(RssReaderBar,4)
}
;-----------------------------------------------------------------------
; Display Config Dialog where we could add ID and URL of the rss feed.
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:7: {
rss.config
}
;-----------------------------------------------------------------------
; fill the TreeView with info found in the ini file.
;-----------------------------------------------------------------------
alias RssReaderBar.Load {
did -a RssReaderBar 4 +bce Programmation $chr(9) test
did -i RssReaderBar 4 1 cb 2
;--- Retrieve the url and their id from the ini file.
;--- Number of lines under the first section which is [url id]
%lines = $ini($+(",$scriptdir,url.ini,"),1,0)
;--- Setup the the hash table.
.hfree -ws IDUrl
.hmake -s IDUrl 50
;--- Iterate through the ini file, and display them in the tree view.
%iLoop = 1
while (%iLoop <= %lines) {
%col1 = $ini($+(",$scriptdir,url.ini,"),1,%iLoop)
%col2 = $readini($+(",$scriptdir,url.ini,"),urls,%col1)
.hadd -sm IDUrl %col1 %col2
did -a RssReaderBar 4 +e %col1 $chr(9) %col2
inc %iLoop
}
}
var %url
dialog RssDialogConfigAdd {
size -1 -1 276 124
title "Add..."
text "ID:",1,40 13 15 13
text "URL:",2,32 34 23 13
edit "",3,79 10 187 25
edit "",4,79 37 187 49, hsbar multi
button "&OK",5,140 91 60 22, ok
button "&Close",6,205 91 60 22, cancel
}
on *:dialog:RssDialogConfigAdd:sclick:5: {
%var1 = $did(RssDialogConfigAdd,3)
%var2 = $did(RssDialogConfigAdd,4)
; the user must supply values...
if ((!%var1) || (!%var2)) {
%t = $input(You must supply values !!!,oh,Error)
halt
}
; check if this ID still exist in our hash table.
%result = $hget(IDUrl, %var1)
if (%result) {
%t = $input(ID %var1 always exist !!!,oh,Error)
halt
}
did -a RssDialogConfig 1 + 0 0 0 %var1 $+ $chr(9) $+ + 0 0 0 %var2
.hadd -m IDUrl %var1 %var2
}
;-----------------------------------------------------------------------
; a dialog to add rss url.
;-----------------------------------------------------------------------
dialog RssDialogConfig {
size -1 -1 361 226
title "Add Rss Url"
list 1,10 14 332 166,vsbar size
button "&Add",2,100 191 57 25
button "&Update",3,224 191 57 25
button "&Remove",4,157 191 57 25
button "&Close",5,283 191 57 25, ok
}
on *:dialog:RssDialogConfig:sclick:3: {
; create another empty file by erasing the older one.
.remove $+(",$scriptdir,url.ini,")
%lines = $did(RssDialogConfig,1).lines
%iLoop = 1
while (%iLoop < %lines) {
writeini $+(",$scriptdir,url.ini,") urls $ldid(RssDialogConfig,1,1,%iLoop) $ldid(RssDialogConfig,1,2,%iLoop)
inc %iLoop
}
}
on *:dialog:RssDialogConfig:sclick:2: {
dialog -m RssDialogConfigAdd RssDialogConfigAdd
}
on *:dialog:RssDialogConfig:sclick:4: {
%result = $input(Are you sure to remove this item ?,yw,Warning)
if (%result == $true) {
; remove it from the listview.
hdel IDUrl $cell(RssDialogConfig,1,$did(1).sel,1)
; remove it from the listview.
did -d RssDialogConfig 1 $did(1).sel
}
}
on *:dialog:RssDialogConfig:init:*:{
mdx SetMircVersion $version
mdx MarkDialog $dname
mdx SetControlMDX $dname 1 ListView editlabels report rowselect showsel grid single labeltip headerdrag flatsb > $scriptdir $+ views.mdx
did -i $dname 1 1 headerdims 70 243
did -i $dname 1 1 headertext ID $chr(9) URL
;--------- retrieve the url and their id from the ini file.
; number of lines under the first section which is [url id]
%lines = $ini($+(",$scriptdir,url.ini,"),1,0)
;setup the listview control and the hash table.
.hfree -ws IDUrl
.hmake -s IDUrl 50
%iLoop = 1
while (%iLoop <= %lines) {
%col1 = $ini($+(",$scriptdir,url.ini,"),1,%iLoop)
%col2 = $readini($+(",$scriptdir,url.ini,"),urls,%col1)
did -a RssDialogConfig 1 + 0 0 0 %col1 $+ $chr(9) $+ + 0 0 0 %col2
.hadd -sm IDUrl %col1 %col2
inc %iLoop
}
}
alias Rss.config {
dialog -m RssDialogConfig RssDialogConfig
}
alias Rss.Read {
if (!$1-) {
echo -a Missing ID Rss Adress ...
return
}
%url = $hget(IDUrl, $1-)
if (!%url) {
echo -a No Url associated with this ID.
return
}
; save the rss feed we get from internet, in a directory called "Files"
httpget %url Files/ $+ $1-
}
alias Rss.show {
if (!$1-) {
echo -a Missing RSS ID ...
return
}
; dll and .xml files
var %dll = $+(",$scriptdir,xml.dll,")
var %xml = $+(",$scriptdir,Files/,$1,")
if (!$isfile(%dll)) { echo -a Error - missing: %dll | return }
if (!$isfile(%xml)) { echo -a Error - missing: %xml | return }
; parser name
var %n = Rss
var %a = $dll(%dll,create_parser,%n)
if (%a != S_OK) { echo -a Error - create_parser: %a | return }
dll %dll set_handler_chardata %n hchardata
echo -a Setting XML file : %xml
dll %dll set_file %n %xml
; global var: dll pathname will be use in start and end element handlers
%xmldemo.dll = %dll
;echo $color(join) -a Parsing :
var %a = $dll(%dll,parse_file,%n)
if (%a != S_OK) { echo -a Error - parse_file: %a }
;echo -a Deleting parser %n
dll %dll free_parser %n
; unsets global var
unset %xmldemo.*
}
alias hchardata {
; The Channel
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/title ) {
echo -a $chr(31) $+ Channel Title $+ $chr(31) : $2-
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/description ) {
echo -a $chr(31) $+ Channel Description $+ $chr(31) : $2-
}
; item
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/title ) {
echo -a $chr(2)
echo -a $chr(31) $+ Title $+ $chr(31): $2-
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/description ) {
echo -ai $chr(31) $+ Description $+ $chr(31) : $2-
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/link ) {
echo -a $chr(2) $2- $chr(2)
}
; uncomment this one if u would some more information
;if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/Author ) {
; echo -a Article author : $2-
;}
;if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/pubdate ) {
; echo -a Article date : $2-
;}
}
; -----------------------------------------------------------------------------------
;HTTP Transfer Script
;beta phase!
;
;Original script: Tomalak Geret'kal from www.deep-space-5.org/mirchelp.php";
;Usage: /httpget http://<host>/<path> [local_folder]
;
;-------------------------------------------------------------------------------------*/
alias httpget {
if ($regex($1,/^http:\/\/([^\/]+)(\/.+)$/i)) {
echo -a [HTTP] Opening to $+ $regml(1) $+ on port: 80
var %name = httpget_socket
sockopen %name $regml(1) 80
set % $+ %name $+ .url $regml(1)
set % $+ %name $+ .path $regml(2)
var %2 = $2
set % $+ %name $+ .saveto %2
}
}
on *:sockopen:httpget_socket:{
echo -a • Connection established
var %request1 = GET % [ $+ [ $sockname ] $+ .path ] HTTP/1.1
var %request2 = Host: % [ $+ [ $sockname ] $+ .url ]
var %request3 = % [ $+ [ $sockname ] $+ .url ] close
sockwrite -t $sockname %request1 $+ $crlf $+ %request2 $+ $crlf $+ Connection: close $+ $crlf $+ $crlf
echo -a • Request sent...
}
on *:sockwrite:httpget_socket:{
if ($sockerr) echo -a • Error: $ifmatch
}
on *:sockread:httpget_socket:{
if ($sockerr > 0) return
var %fname = $+(",$scriptdir,%httpget_socket.saveto,")
:nextread
if (!$sock($sockname).mark) {
sockread %output
if ($sockbr == 0) {
sockclose $sockname
return
}
var %400 = HTTP/1.1 400 Bad Request
var %404 = HTTP/1.1 404 Not Found
if (%400 iswm %output) {
echo -a 4• Bad HTTP Request
sockclose $sockname
}
elseif (%404 iswm %output) {
echo -a • File Not Found!
sockclose $sockname
}
elseif ($regex(%output,/HTTP\/1.1 (4|5\d\d) (.+)/)) {
echo -a • ERROR $regml(1) $+ : $regml(2)
sockclose $sockname
}
if (%output == $null) {
sockmark $sockname header received
write -c %fname
}
}
else {
sockread -nf 4096 &output
if ($sockbr == 0) {
return
}
bwrite %fname -1 -1 &output
}
goto nextread
}
on *:sockclose:httpget_socket:{
echo -a • Transfer complete. File saved as 12 $+ %httpget_socket.saveto $+
echo -a • Connection closed
.unset % $+ $sockname $+ .*
}
; Usage:
; $cell(Dialog name,ID,Line,Cell)
; Contact:
; IRC: Gallagher @ PTnet
; E-mail: morphy_chaos@hotmail.com
; Website: www.chaos.page.vu
alias cell {
return $gettok($gettok($gettok($did($1,$2,$3),$4,9),$iif($4 = 1,6,5) $+ -,32),1,4)
}
; $ldid(Dialog,ID,N) de l3z4rD
alias ldid {
var %line = $iif($4 isnum,$calc($4 +1),$did($1,$2).sel)) , %did = $did($1,$2,%line)
if ($prop == total) return $numtok(%did,9)
return $gettok($gettok(%did,$3,9),$iif($3 == 1,6-,5-),32)
}
/*
By Yochai Timmer
These commands will help you control a Tree View list.
I've made $did-tree to act like the regular $did command, and supports the props used for
$did-tree(dialog,ID,N) Gives you the text of the Nth branch, You have to use branch loaction and give all the root IDs before like 2 3 4 etc..
$did-tree(dialog,ID,N).lines Gives you the number of lines under the Nth root. (Not including line 1 of course)
$did-tree(dialog,ID) gives you the selected line's text.
$did-tree(dialog,ID).len Gives you the selected line's length.
$did-tree(dialog,ID).sel Gives you the selected line's branch location.
$did-tree(dialog,ID).root Gives you the selected line's root.
$did-tree(dialog,ID).lines Gives you the number of lines in the corrent branch.
$did-tree(dialog,ID).Event Will return the last event for that ID
$did-tree(dialog,ID,N).Tooltip Will give you the Branch's tooltip
Example, Rootview:
-Root {tab} Tooltip - root
|-Branch1
|-Branch2
-Root2
|-THing
|--Subthing {tab} This is the tooltip
The basic law is that mdx uses line 1 in each Branch, so the actuall lines that you see start from line 2
So the location of "Subthing" would be: 3 2 2
and the location of Branch2 would be: 2 3
Now to call check writen in the First root, seconed line you would use this: $did-tree(Dialog,ID,2 3)
Now lets assume that "Subthing" is selected now:
$did-tree(dialog,ID) Gives you Subthing
$did-tree(dialog,ID).len gives you 8
$did-tree(dialog,ID).sel gives you 3 2 2
$did-tree(dialog,ID).root gives you 3
$did-tree(dialog,ID).lines gives you 1 (There's only 1 line in that branch)
$did-tree(dialog,ID).Tooltip gives you This is the tooltip
$did-tree(dialog,ID,2) will give you Root
$did-tree(dialog,ID,2).lines will give you 2 (there are 2 branches under "root")
$did-tree(dialog,ID,2).Tooltip will give you Tooltip - root
$did-tree(dialog,ID,2).Event will give you Sclick
I like using %vars cause it's easier to read %names then $1 $2 $4, but it's not necessery, and you can change that.
*/
alias -l did-tree {
var %dialog = $1
var %id = $2
;It's not necessery to set the $1 and $2 to vars, but I like to use named vars (Espcialy in examples)
if (!$dialog(%dialog)) return
;Just checking...
if ($3) {
; Checks if a specific location was requested
var %Loc = $3-
;Sets the location
if ($prop = lines) {
;Checks if the Property .lines was used
did -i %dialog %id 1 cb root %loc
;always need to use cb (change branch) to get the requested location
return $calc($did(%dialog,%id,0).lines -1)
;mdx default returns the number of lines + 1 (the options line), so you need to reduce by one to get the actuall number of lines
}
if ($numtok(%Loc,32) = 1) did -i %dialog %id 1 cb root
else { did -i %dialog %id 1 cb root $gettok(%loc,1- $+ $calc($numtok(%loc,32) -1),32) }
;Changing to the requested branch...
var %line = $gettok($did(%dialog,%id,$gettok(%Loc,-1,32)),7-,32)
;This sets %line to the branch's text
if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip
return $gettok(%line,1,9)
;This returns the requested branch
}
var %entry = $did(%dialog,%id,1)
if ($gettok(%entry,1,32) = slclick) var %loc = $gettok(%entry,4-,32)
else var %loc = $gettok(%entry,3-,32)
;This checks the last event in the requested ID
var %depth = $calc($numtok(%loc,32) -1)
var %branch = $gettok(%loc,-1,32)
;Setting the depth of the branch, and the actuall branch position
if (%depth = 0) did -i %dialog %id 1 cb root
else did -i %dialog %id 1 cb root $gettok(%loc,1- $+ %depth,32)
;Changing to the requested branch
var %line = $gettok($did(%dialog,%id,%branch),7-,32)
;This sets %line to the branch's text
if (!$prop) return $gettok(%line,1,9)
;If no props were set it returns the branch's text
if ($prop = root) return $gettok(%loc,1,32)
;returns the root ID
if ($prop = sel) return %loc
;returns the branch's location
if ($prop = lines) return $calc($did(%dialog,%id,0).lines -1)
;Returnes the number of lines in the selected branch
if ($prop = len) return $len(%line)
;This returns the length of the branch's text
if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip
if ($prop = event) return $gettok(%entry,1,32)
;This returns the last Event that in the dialog
}
/*
By Yochai Timmer
This snippet is used in MDX Tree-views to search for branches with wildcard text
Usage:
$Find-branch(Dialog,ID,Match string,<Branch Location>)
The location is optional, if you don't give a location, the snippet will search in the root branch.
If you give a Branch location, it will look in all the Sub-branches.
The snippet returns the matching location.
*/
alias Find-branch {
; $1 is the Dialog name
; $2 is the specified ID
; $3 is the Match string
; $4 is the Location
if (!$dialog($1)) return
if (!$4) var %loc = 1
else %loc = $4
var %num = 0
var %a = 2
did -i $1 $2 1 cb root %loc
;selecting the requested location
while ($gettok($did($1,$2,%a),7-,32)) {
;looping through the branches
var %line = $gettok($v1,1,9)
;This sets %line to the branch's value (without the comment)
if ($3 iswm %line) {
if ($4 != 0) return %a
inc %num
}
inc %a
}
if ($4 != 0) return
return %num
}