1
###################################################################
2
# aMSN Emoticon Importer Plugin #
6
###################################################################
8
namespace eval ::emoticons_importer {
12
#######################################################################################
13
#######################################################################################
14
#### Initialization Procedure (Called by the Plugins System) ####
15
#######################################################################################
16
#######################################################################################
22
::plugins::RegisterPlugin emoticons_importer
27
set langdir [file join $dir "lang"]
28
set lang [::config::getGlobalKey language]
30
load_lang $lang $langdir
32
set configlist [list [list frame ::emoticons_importer::populateframe ""] ]
34
proc populateframe { win } {
35
set ::emoticons_importer::importdir ""
36
# Show some kind of UI for choosing a directory and importing from it.
39
pack $win.1 $win.2 -anchor w -side top -padx 0 -pady 5 -fill none
40
label $win.1.path -text "[trans importdir] :" -padx 5 -font sboldf
41
entry $win.1.importdir -width 45 -textvariable ::emoticons_importer::importdir
42
button $win.1.browse -text [trans browse] -command "Browse_Dialog_dir ::emoticons_importer::importdir"
44
grid $win.1.path -row 1 -column 1 -sticky w
45
grid $win.1.importdir -row 1 -column 2 -sticky w
46
grid $win.1.browse -row 1 -column 3 -sticky w
48
button $win.2.import -text [trans import] -command "::emoticons_importer::importSmileys"
49
pack $win.2.import -anchor w -side top -padx 0 -pady 5 -fill none
53
proc importSmileys { } {
54
if {[info exists ::emoticons_importer::importdir] } {
55
importSmileysFromDir $::emoticons_importer::importdir
61
# -1 : directory not found or file not a directory
62
proc importSmileysFromDir { directory } {
63
if { ![file exists $directory] || ![file isdirectory $directory] } {
67
# Check for a kopete compatible emoticon pack
68
if {[file exists [file join $directory emoticons.xml]] &&
69
[file readable [file join $directory emoticons.xml]]} {
71
set xml_fd [open [file join $directory emoticons.xml]]
72
set xml [xml2list [read $xml_fd]]
75
plugins_log emoticons_importer "Found an emoticons.xml file in $directory"
78
set node [GetXmlNode $xml "messaging-emoticon-map:emoticon" $i]
84
set file [GetXmlAttribute $node "emoticon" "file"]
88
set string [GetXmlEntry $node "emoticon:string" $j]
93
append triggers "$string "
96
set name [file rootname $file]
97
set r [AddNewCustomEmoticon $name [file join $directory $file] $triggers]
98
plugins_log emoticons_importer "Added custom emoticon : $name $file '$triggers' : $r"
101
plugins_log emoticons_importer "Error importing from emoticons.xml : $res"
106
plugins_log emoticons_importer "Globing for files in $directory"
107
set files [glob -nocomplain -tails -type f -directory $directory *]
108
foreach file $files {
109
set name [file rootname $file]
110
set triggers "\[$name\]"
111
set r [AddNewCustomEmoticon $name [file join $directory $file] $triggers]
112
plugins_log emoticons_importer "Added custom emoticon : $name $file '$triggers' : $r"
120
# -2 : smiley already exists with that name
121
# -3 : could not find sound file
122
# -4 : could not find the smiley file
123
# -5 : file could not be loaded, wrong format or whatever
124
# -6 : Error converting/resizing the file
125
proc AddNewCustomEmoticon { name file text {casesensitive 0} {sound ""}} {
126
global custom_emotions HOME
128
#Check for needed fields
129
if { $name == "" || $file == "" || $text == "" } {
132
if { [info exists custom_emotions($name)] } {
137
#Check for sound, and copy it
138
if { $sound != "" } {
139
set filename [getfilename [::skin::GetSkinFile sounds $sound]]
140
if { $filename == "null" } {
143
create_dir [file join $HOME sounds]
144
catch { file copy [::skin::GetSkinFile sounds $sound] [file join $HOME sounds]}
146
set emotion(sound) $filename
149
set filename [getfilename [::skin::GetSkinFile smileys $file]]
150
if { $filename == "null" } {
154
create_dir [file join $HOME smileys]
157
if { [ catch {set emotion(animated) [::picture::IsAnimated [::skin::GetSkinFile smileys $file] ] } res ] } {
158
#There is an error with the file, wront format or doesn't exist
161
if { $emotion(animated) == 0 } { unset emotion(animated) }
163
if { ![info exists emotion(animated)] || $emotion(animated) == 0 } {
164
image create photo tmp -file [::skin::GetSkinFile smileys $file]
166
set filetail_noext [filenoext [file tail $file]]
167
set destfile [file join $HOME smileys $filetail_noext]
169
if { [image width tmp] > 50 || [image height tmp] > 50 } {
170
#MSN can't show static smileys which are bigger than 50x50 so we resize it
171
set file [convert_image_plus [::skin::GetSkinFile smileys $file] smileys 50x50]
173
#The smiley has size between 19x19 and 50x50 and user doesn't want to resize it so we just convert it to PNG
174
set filetail_noext [filenoext [file tail $file]]
175
set destfile [file join $HOME smileys $filetail_noext]
176
::picture::Convert [::skin::GetSkinFile smileys $file] "${destfile}.png"
177
set file "${destfile}.png"
180
# Don't forget to delete the temp image...!
183
if { ![file exists $file] } { set file "" }
185
#We convert animated smiley to animated gif even if we can just load animated gif and save to animated gif
186
#Don't care of extension : as the smiley is animated TkCximage will save to GIF format
187
set filetail_noext [filenoext [file tail $file]]
188
set destfile [file join $HOME smileys $filetail_noext]
189
::picture::Convert [::skin::GetSkinFile smileys $file] "${destfile}.png"
190
set file "${destfile}.png"
191
if { ![file exists $file] } { set file "" }
198
set emotion(file) $file
199
set emotion(name) $name
200
set emotion(reachable) 1
202
#Create a list of symbols
203
set emotion(text) [list]
204
foreach symbol [split $text] {
205
if { $symbol != "" } {
206
lappend emotion(text) $symbol
210
if { $casesensitive == 1} {
211
set emotion(casesensitive) 1
213
if { [info exist emotion(casesensitive)] } {unset emotion(casesensitive)}
218
set emotion(image_name) [image create photo emoticonCustom_std_$emotion(text) -file $emotion(file) -format cximage]
219
set emotion(preview) [image create photo emoticonCustom_preview_$emotion(text)]
220
$emotion(preview) copy emoticonCustom_std_$emotion(text)
222
set custom_emotions($name) [array get emotion]
225
if { [winfo exists .smile_selector]} {destroy .smile_selector}
227
#After modifying, clear sortedemotions, could need sorting again
228
if {[info exists ::smiley::sortedemotions]} { unset ::smiley::sortedemotions }
231
#Immediately save settings.xml and update the UI