aMSN Forums
May 22, 2013, 04:59:51 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New forum for aMSN !!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Organization of received files (a new plugin)  (Read 6546 times)
nilton.volpato
Newbie

Offline Offline

Posts: 5


View Profile
« on: December 29, 2005, 07:45:34 pm »

Hi,

I would like to design a plugin for saving received files by default in a subdir of the sender and optionally another subdir of the date.

For example, if i'm receiving a file from billgates@hotmail.com, in 2005-12-29, then it will be saved in: ~/amsn_received/billgates_hotmail.com/2005-12-29 or just ~/amsn_received/billgates_hotmail.com, depending on configuration.

But I don't know much tcl and don't know how to override amsn actions.

Could someone help me designing this plugin? I think it will be of much use.

Thanks,
-- Nilton
Logged
Backup2
Guest
« Reply #1 on: December 29, 2005, 09:00:00 pm »

I suggest you read the aMSN wiki http://amsn.sourceforge.net/wiki/tiki-index.php
Logged
nilton.volpato
Newbie

Offline Offline

Posts: 5


View Profile
« Reply #2 on: December 31, 2005, 07:42:44 pm »

Thanks,

I tried doing this. But it's not yet working. I have very little knowledge of tcl, so it's even harder...

What i'm trying to do is to wrap the proc ::amns::AcceptFT into another one that changes the default directory for saving files.

Could someone please help. The code is below.

organize_received.tcl
Code:
namespace eval ::organize_received {
    variable plugin_name "Organize Received Files"

    variable loaded 0

    variable old_AcceptFT ::amsn::old_amsn_AcceptFT

    proc Init { dir } {
variable plugin_name
variable loaded
variable old_AcceptFT

if { $loaded == 1 } {
   return 0
}

puts "loading"

::plugins::RegisterPlugin $plugin_name

puts [info proc "::amsn::AcceptFT"]

if { [info proc "::amsn::AcceptFT"] == "::amsn::AcceptFT" } {
   rename ::amsn::AcceptFT $old_AcceptFT
   puts [info proc "$old_AcceptFT"]
   #puts [info body "$old_AcceptFT"]
   proc ::amsn::AcceptFT { chatid cookie {varlist ""} } {
puts "----- AcceptFT ------"
puts $chatid
puts $cookie
puts $varlist
puts "----------------------"
variable old_filesdir $::files_dir
set ::files_dir [file join "$::files_dir" "$chatid"]
puts "::files_dir $::files_dir"
::create_dir "$::files_dir"
puts "dir created"
set r [$::organize_received::old_AcceptFT chatid cookie varlist]
puts "function evaluated"
set ::files_dir $old_filesdir
puts "::files_dir $::files_dir"
puts "r $r"
return r
   }
}
puts "renamed"

puts [info proc "::amsn::AcceptFT"]
#puts [info body "::amsn::AcceptFT"]

set loaded 1
puts "init end"
return 1
    }

    proc DeInit { dir } {
variable plugin_name
variable loaded
variable old_AcceptFT

if { $loaded == 0 } { return 0 }
puts "unloading"

if { [info proc "$old_AcceptFT"] == "$old_AcceptFT" } {
   rename $old_AcceptFT ::amsn::AcceptFT
}

set loaded 0
puts "unloaded"
    }
     
}


plugininfo.xml
Code:
<?xml version="1.0"?>
<plugin>
<name>Organize Received Files</name>
<author>Nilton Volpato</author>
<description>FIXME ADD LATER</description>
<amsn_version>0.95</amsn_version>
<plugin_version>0.1</plugin_version>
<plugin_file>organize_received.tcl</plugin_file>
<plugin_namespace>organize_received</plugin_namespace>
<init_procedure>Init</init_procedure>
<deinit_procedure>DeInit</deinit_procedure>
</plugin>


Thanks,
-- Nilton
Logged
kakaroto
Administrator
Super Power User
*****
Offline Offline

Posts: 9428


View Profile WWW
« Reply #3 on: December 31, 2005, 08:55:22 pm »

Hi,
great plugin you'll be doing, and good code so for, especially for a tcl newbie, here's the trick (from what I saw.. didn't test though) :

in your new proc, you're calling :
 
Code:
     set r [$::organize_received::old_AcceptFT chatid cookie varlist]


the three arguments are sent as plain text, it should be :
 
Code:
     set r [$::organize_received::old_AcceptFT $chatid $cookie $varlist]


apart from that, you're doing a file join on the files_dir and chatid variables, although I'm almost 100% sure you'll get the expected result, I would suggest you do something like this :
Code:
set subdir [lindex [::MSN::usersInChat $chatid] 0]  


then do the file join with the subdir directory.. again this is just from memory, so you'll have to make sure the usersInChat proc exists and had no spelling errors... (might have capital letter on the initial 'U')

this is because on a multi-user conversation, the chatid variable contains the SB name, not the user's name, since there are several users in the same chat.. but I don't think you can have file transfers on multi user convo that's why I say it might be safe... but make your code robust!
good luck,
any more info, you know where to post!
[/code]
Logged

KaKaRoTo
nilton.volpato
Newbie

Offline Offline

Posts: 5


View Profile
« Reply #4 on: January 01, 2006, 10:35:02 pm »

Thanks Kakaroto,

I corrected that error you pointed out. I'm always forgetting that in tcl the variable names are just the names and not the value.

As for the email of the sender, in the case of multi-user conversation, I corrected that too using [lindex $varlist 0]. And it is really possible to send files in a multi-user conversation, I remember doing this once... And the way i did it now, it seems it will get the email of the sender, even in multiuser conversations.

The error i'm getting now, is when I unload the plugin. It seems the DeInit procedure is not being called, because I used the puts procedure in it, and there is no output. Any help is welcome...

Despite this, the plugin is totally usable, so I'm doing here a pre-release. The plugin may be download from http://qubit.ic.unicamp.br/~nilton/files/organize_received-0.2.zip. Any feedback are really welcome!

The code is below, for those willing to help. Thanks, Nilton.

Code:
<?xml version="1.0"?>
<plugin>
<name>Organize Received Files</name>
<author>Nilton Volpato &lt;first-name dot last-name @ gmail.com&gt;</author>
<description>When the user accepts an incoming file transfer, the file will be saved in a subdirectory of the amsn_received dir. This subdirectory may be configured, and is by default the email of the user sending the file followed by the current date.</description>
<amsn_version>0.95</amsn_version>
<plugin_version>0.2</plugin_version>
<plugin_file>organize_received.tcl</plugin_file>
<plugin_namespace>organize_received</plugin_namespace>
<init_procedure>Init</init_procedure>
<deinit_procedure>DeInit</deinit_procedure>
</plugin>


Code:
# Organize Received Files
# Plugin for AMSN
#
# Author: Nilton Volpato <first-name dot last-name @ gmail.com>
# Time-stamp: <2006-01-01 19:08:38 nilton>
#
# Changelog:
# 2006-01-01: v0.2 Fixed some problems, added configuration interface
#             and better description.
# 2005-12-31: v0.1 Initial version

namespace eval ::organize_received {
    variable plugin_name "Organize Received Files"

    variable loaded 0

    variable old_AcceptFT ::amsn::old_amsn_AcceptFT

    proc Init { dir } {
variable plugin_name
variable loaded
variable old_AcceptFT

if { $loaded == 1 } {
   return 0
}

::plugins::RegisterPlugin $plugin_name

if { [info proc "::amsn::AcceptFT"] == "::amsn::AcceptFT" } {
   rename ::amsn::AcceptFT $old_AcceptFT
   proc ::amsn::AcceptFT { chatid cookie {varlist ""} } {
set old_filesdir $::files_dir
set email [lindex $varlist 0]
set date [clock format [clock seconds] -format "%Y-%m-%d"]
set subdir [::organize_received::parseDirFormat $::organize_received::config(subdir_fmt) $email $date]
set ::files_dir [file join "$::files_dir" "$subdir"]
::create_dir "$::files_dir"
set r [$::organize_received::old_AcceptFT $chatid $cookie $varlist]
set ::files_dir $old_filesdir
return r
   }
}

array set ::organize_received::config {
   subdir_fmt "\$email/\$date"
}

set ::organize_received::configlist \
   [list \
[list label "Format for subdirs:"] \
[list label "Parameters: \$email, \$date" lbl1] \
[list str "Subdir:" subdir_fmt] \
]

set loaded 1
plugins_log $plugin_name "Plugin loaded"
return 1
    }

    proc DeInit { dir } {
variable plugin_name
variable loaded
variable old_AcceptFT

if { $loaded == 0 } { return 0 }

if { [info proc "$old_AcceptFT"] == "$old_AcceptFT" } {
   rename $old_AcceptFT ::amsn::AcceptFT
}

set loaded 0
plugins_log $plugin_name "Plugin unloaded"
    }

    proc parseDirFormat { fmt email date } {
# quote some chars
set r [string map {"\\" "\\\\" "\$" "\\\$" "\(" "\\\("} $fmt]
# unquote the needed variables
set r [string map {"\\\$email" "\${email}" "\\\$date" "\${date}"} $r]
# split into a list of subdirs
set r [split [subst -nocommands $r] "/\\"]
# apply file join so the correct dir separator is used
return [eval [linsert $r 0 file join]]
    }
     
}
Logged
kakaroto
Administrator
Super Power User
*****
Offline Offline

Posts: 9428


View Profile WWW
« Reply #5 on: January 02, 2006, 08:08:29 am »

Hi there,
seen your code.. it's cool, a few comments :
1 - in a multi convo, assuming it works, you won't get the sender's mail, only get the email of the first user in the conversation where the sender was...
2 - looking at the code it seems you hooked the ::amsn::AcceptFT which is the proc for the old file transfer protocol (compatible with eindows messenger only) you should look at ::MSN6FT::AcceptFT (I think) instead...
3 - If you also hook the ::MSN6FT::AcceptFT, you'll just need to use the $dest variable which will contain the name of the sender...
4 - The DeInit proc doesn't take any argument.. that's why it fails.. you can use the plugins_log window (Alt-P) for info.. but it seems if it crashes it won't tell.. I'll update that in CVS so next time you'd be able to see why the Deinit proc isn't called...
5 - When the plugin is finished and tested, you can send it to the team, I don't remember if we have only a tracker for this, or we have a mailing list for this, or if it was in the 'Patches' tracker that it should be sent.. in any case, you can look at these destinations.. I can also forward it myself, just give me a valid link when the plugin is ready to be in a 1.0 stable release...


Hope that helps..
KaKaRoTo
Logged

KaKaRoTo
the_y_man
Guest
« Reply #6 on: January 02, 2006, 07:34:15 pm »

Good job nilton.volpato, I always wanted such a feature, when it gets more stable, I will be using it.
Logged
nilton.volpato
Newbie

Offline Offline

Posts: 5


View Profile
« Reply #7 on: January 06, 2006, 02:32:55 am »

Hi,

Quote from: "kakaroto"
1 - in a multi convo, assuming it works, you won't get the sender's mail, only get the email of the first user in the conversation where the sender was...

Not really, the way I was doing I was getting [lindex $varlist 0] which is the email of the sender, but it's only available in the new protocol, in the old protocol this var is undefined, so I fixed this to a more robust solution.

Quote from: "kakaroto"
2 - looking at the code it seems you hooked the ::amsn::AcceptFT which is the proc for the old file transfer protocol (compatible with eindows messenger only) you should look at ::MSN6FT::AcceptFT (I think) instead...

Not really again, ::amsn::AcceptFT is the proc from gui.tcl it's not ::MSN::AcceptFT os ::MSN6FT::AcceptFT from protocol.tcl, so wrapping ::amsn::AcceptFT is better because it will call ::MSN::AcceptFT or ::MSN6FT::AcceptFT accordingly.

Quote from: "kakaroto"
3 - If you also hook the ::MSN6FT::AcceptFT, you'll just need to use the $dest variable which will contain the name of the sender...

As I said in (1), I am now using [lindex $varlist 0] which is the same as $dest in ::MSN6FT::AcceptFT, and if it's not defined (in the case of the old protocol being used) I will use ::MSN::usersInChat, so it will work for both cases.

Quote from: "kakaroto"
4 - The DeInit proc doesn't take any argument.. that's why it fails.. you can use the plugins_log window (Alt-P) for info.. but it seems if it crashes it won't tell.. I'll update that in CVS so next time you'd be able to see why the Deinit proc isn't called...

Thanks, I really missed that... Thanks very much, now the unloading is ok.

Quote from: "kakaroto"
5 - When the plugin is finished and tested, you can send it to the team, I don't remember if we have only a tracker for this, or we have a mailing list for this, or if it was in the 'Patches' tracker that it should be sent.. in any case, you can look at these destinations.. I can also forward it myself, just give me a valid link when the plugin is ready to be in a 1.0 stable release...

I think that now it's stable enough. It's available in this link http://qubit.ic.unicamp.br/~nilton/files/organize_received-0.3.zip. If you can, please, send it to the team so it can go on the webpage.

Thanks,
-- Nilton
Logged
germinator
Newbie

Offline Offline

Posts: 19


View Profile
« Reply #8 on: January 07, 2006, 11:12:03 pm »

First of all BRAVO, nice plugin, nice feature. I like it.

Secondly (I'm developer for aMSN) would you contact me by mail, gagnonje5000 at mac.com
I would like to add your plugin to CVS directory of aMSN and also add it to aMSN plugins website

You seems to have some skills in coding may be you could subscribe to amsn-devel mailling list to see what's going on with aMSN and sometimes submit patch or just talk about your plugin, code new plugins, anything, most of the developers are reading the stuff on amsn-devel (more often than the forum)
http://sourceforge.net/mail/?group_id=54091
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!