~amsn-daily/amsn/amsn-packaging

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
######################################################
##                                                 ##
##   aMSN Plugins System - 0.96-Release Version    ##
##                                                 ##
#####################################################

::Version::setSubversionId {$Id$}

proc plugins_log {plugin msg} {
#return
	if {[info procs "::pluginslog::plugins_log"] == "::pluginslog::plugins_log"} {
		::pluginslog::plugins_log $plugin $msg
	} else {
		status_log "Plugins System: $plugin: $msg"
	}
}

namespace eval ::plugins {
	namespace export PostEvent

	if { $initialize_amsn == 1 } {
		# Name of the current selected plugin
		set selection "" 
		# The path to the plugin selector window
		variable w                      
		# Info about plugins
		array set plugins [list]
		# List of current plugins
		variable loadedplugins [list]
		# Holds the configuration of unloaded plugins
		array set config [list]

		# tmp variable to be used by the XML parser
		variable cur_plugin
	}


	###############################################################
	# PostEvent (event, argarray)
	#
	# This proc can be put anywhere within amsn to call a event.
	#
	# Arguments
	# event - the event that is being called
	# argarray - name of the array holding the arguments
	#
	# Return
	# none
	#
	proc PostEvent { event var } {
		variable pluginsevents 

		plugins_log core "Calling event $event with variable $var\n"
	
		if { [info exists pluginsevents(${event}) ] } { # do we have any procs for the event?
			foreach cmd $pluginsevents(${event}) { # let's call all of them
				plugins_log core "Executing $cmd\n"
				catch { eval $cmd $event $var } res ; # call
				plugins_log core "Return $res from event handler $cmd\n"
			}
		}
	}


	###############################################################
	# RegisterPlugin (plugin)
	#
	# Dummy proc, not needed any more. Is replaced by "loadedplugins"
	#
	# Arguments
	# plugin - name of the plugin
	#
	# Return
	# 0 - plugin already registered
	# 1 - first time plugin registered
	#    
	proc RegisterPlugin { plugin } {
	    
	}
    

	###############################################################
	# RegisterEvent (plugin, event, cmd)
	#
	# This proc registeres a command to a event
	#
	# Arguments
	# plugin - name of the plugin that the command belongs to
	# event - the event to register for
	# cmd - command to register
	#
	# Return
	# -1 - error registering event
	# 1 - all good!
	#      
	proc RegisterEvent { plugin event cmd } {
		variable pluginsevents

		plugins_log core "Plugin Systems: RegisterEvent called with $plugin $event $cmd\n"

	    #check if the plugin is loaded, if not don't register the event and return 0 for false
		if { [lsearch $::plugins::loadedplugins "$plugin"] == -1 } { 
			plugins_log core "Registering an event for an unloaded plugin...\n"
			return -1; # Bye Bye
		}

		#get the namespace of the plugin via it's data in loadedplugins
		set namespace [getInfo $plugin plugin_namespace]

		#Check if the given proc is already registered to the given event
		if {[array names pluginsevents $event] != ""} { 
			if {[lsearch $pluginsevents(${event}) "\:\:$namespace\:\:$cmd"] != -1 } { # Event already registered?
				plugins_log core "Trying to register a event twice"
				return -1; # Bye Bye
			}
		}

		plugins_log core "Binding $event to $cmd\n"
		lappend pluginsevents(${event}) "\:\:$namespace\:\:$cmd"; # Add the command to the list

		return 1
	}


	###############################################################
	# UnRegisterEvent (plugin, event, cmd)
	# 
	# Unregisters a event from a plugin
	#
	# Arguments
	# plugin - the plugin to unregister for
	# event - the event to unregister from
	# cmd - the command to unregister
	#
	# Return
	# -1 - on error
	# 1 - on success
	#
	proc UnRegisterEvent { plugin event cmd } {
		variable pluginsevents

		if { [lsearch $::plugins::loadedplugins $plugin] == -1 } {
			return -1
		}
		
		set namespace [getInfo $plugin plugin_namespace]

		# do stuff only if there is a such a command for the event
		if { [info exists pluginsevents(${event})] == 0 } {
			plugins_log core "Trying to unregister a unknown event...\n"
			return -1
		} 
		set pos [lsearch $pluginsevents(${event}) "\:\:$namespace\:\:$cmd"]
		if {$pos != -1} {
			# the long erase way to remove a item from the list
			set pluginsevents(${event}) [lreplace $pluginsevents(${event}) $pos $pos]
			plugins_log core "Event \:\:$namespace\:\:$cmd on $event unregistered ...\n"
		} else {
			plugins_log core "Trying to unregister a unknown event...\n"
		}
		return 1
	}
    
	###############################################################
	# UnRegisterEvents (plugin)
	#
	# Unregistres all the events for a plugin. It is used when unloading a plugin
	#
	# Arguments
	# plugin - the plugin to unregister for
	#
	# Return
	# none
	#
	proc UnRegisterEvents { plugin } {
		# event list
		variable pluginsevents
		if { [lsearch $::plugins::loadedplugins $plugin] == -1 } {
			return
		}
		set namespace [getInfo $plugin plugin_namespace]

		# go through each event
       		foreach {event} [array names pluginsevents] {
			# While there is a command in the list that belongs to the 
			# plugins namespace, give it's index to x and delete it
			while { [set x [lsearch -regexp $pluginsevents(${event}) "\:\:$namespace\:\:*" ]] != -1 } {
				plugins_log core "UnRegistering command $x from $pluginsevents(${event})...\n"
				# the long remove item procedure
				# TODO: move this into a proc?
				set pluginsevents(${event}) [lreplace $pluginsevents(${event}) $x $x]
			}
		}
	}

	###############################################################
        # calledFrom ()
        #
        # Finds out if a proc was called by a plugin.
	#
        # Arguments
        # none
        #
        # Return
        # -1 - not called by a plugin
	# $pluginnamespace - the namespace of the plugin calling the proc
        #

	proc calledFrom {} {
	    set namespace [string trimleft "[uplevel 2 namespace current]" "::"]
	    
	    if {[::plugins::namespaceExists $namespace] == 1} {
		return $namespace
	    } else {
		#this namespace dosn't belong to any plugin
		return -1
	    }
	}

	###############################################################
        # namespaceExists (namespace)
        #
	# finds out if a namespace belongs to a plugin
        #
        # Arguments
        # namespace - namespace to check for (without ::)
        #
        # Return
	# -1 - nope
	# 1 - yup
        #

	proc namespaceExists {namespace} {
		variable plugins
		# go through each namespace
       		foreach {current} [array names plugins *_plugin_namespace] {
		    if { $plugins(${current}) == $namespace } {
			return 1
		    }
		}
		return -1
	}


	###############################################################
	# getInfo (plugin,param)
	#
	# Checks the plugins array and return the parameter in the 
	# plugininfo.xml file that is symbolized by param
	#
	# Arguments
	# plugin - name of plugin
	# param - name of parameter to check for
	#
	# Return
	# string - the value of the parameter, empty if not found
	#
	
	proc getInfo {plugin param} {
		variable plugins
		plugins_log core "Getting $plugin and $param"
		plugins_log core [array names ::plugins::plugins ${plugin}_${param}]
		if {[array names ::plugins::plugins ${plugin}_${param}] != ""} {
			return $plugins(${plugin}_${param})
		}
		return ""
	}

	proc getVarInfo {plugin param} {
		return "::plugins::plugins(${plugin}_${param})"
	}

	###############################################################
        # getPlugins ()
        #
	# Returns a list of existing plugins
        #
	# Arguments
	# none
	#
	# Return
	# list of plugins
	#
	proc getPlugins {} {
		set plugins [list]
		foreach {key plugin} [array get ::plugins::plugins *_name] {
			lappend plugins $plugin
		}
		return $plugins
	}

	###############################################################
        # updatePluginsArray ()
        #
        # Updates the plugins array which holds info about plugins
	# by searching possible plugin directories
        #
        # Arguments
        # none
        #
        # Return
        # none
        #
	
	proc updatePluginsArray { } {

	       	global HOME HOME2 program_dir

		#clear the current array
		array set ::plugins::plugins [list]

		# make a list of all the possible places to search
		#TODO: Allow user to choose where to search
		set search_path [list] 
		lappend search_path [file join $program_dir plugins]
		lappend search_path [file join $HOME plugins]
		if { $HOME != $HOME2} {
			lappend search_path [file join $HOME2 plugins]
		}
		lappend search_path [file join $HOME2 amsn-extras plugins]
	    
		# loop through each directory to search
		foreach dir $search_path {
			# for each file names plugininfo.xml that is in any directory, do stuff
			# -nocomplain is used to shut errors up if no plugins found
			foreach file [glob -nocomplain -directory $dir */plugininfo.xml] {
				plugins_log core "Found plugin files in $file\n"
				::plugins::LoadInfo $file
				::plugins::LoadInfoAutoupdate $file
			}
		}

       	}


	###############################################################
	# LoadInfo ()
	#
	# Loads the XML information file of each plugin and parses it, registering
	# each new plugin with proc ::plugins::XMLInfo
	#
	# Arguments
	# path - the path to the pluginsinfo.xml containing the information in XML format
	#
	# Return
	# list containng the information
	#
	proc LoadInfo { path } {

		set fd [file join [file dirname $path] plugininfo.xml]

		if { [file readable $fd] } {
			
			if { [catch {
				set plugin_info [sxml::init $fd]
				sxml::register_routine $plugin_info "plugin" "::plugins::XMLInfo"
				sxml::parse $plugin_info
				sxml::end $plugin_info
				plugins_log core "PLUGINS INFO READ\n"
			} res] } {
				msg_box "ERROR: PLUGIN HAS MALFORMED XML PLUGININFO ($path)"
				return 0
			}
		}

		return 1

	}

	###############################################################
	# XMLInfo (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and appends
	# each new plugin to $::plugins::plugins array
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#

	proc XMLInfo { cstack cdata saved_data cattr saved_attr args } {

		variable plugins
		upvar $saved_data sdata
		#get the path from 2 levels up (::plugins::LoadInfo -> ::sxml::parse -> thisproc)
		#dir is used to set the full path of the file
		upvar 2 path dir

		set name $sdata(${cstack}:name)
		set cur_plugin $name
		set author $sdata(${cstack}:author)

		#Now plugins have an other field in plugininfo.xml in which the description can be translated.
		#It should be used as
		#<description_fr>the description in french</description_fr>
		#The defaut description must be written in english
		#The file should be encoded in utf-8
		set langcode [::config::getGlobalKey language]
		if { ($langcode != "en") && [info exists sdata(${cstack}:description_${langcode}) ] } {
			set desc $sdata(${cstack}:description_${langcode})
		} else {
			set desc $sdata(${cstack}:description)
		}

		set amsn_version $sdata(${cstack}:amsn_version)
		set plugin_version $sdata(${cstack}:plugin_version)
		set plugin_file $sdata(${cstack}:plugin_file)
		set plugin_namespace $sdata(${cstack}:plugin_namespace)
		set init $sdata(${cstack}:init_procedure)

		if { ![info exists sdata(${cstack}:deinit_procedure)] } {
			set deinit ""
		} else {
			set deinit $sdata(${cstack}:deinit_procedure)
		}
		
		set plugins(${name}_name) $name
		set plugins(${name}_author) $author
		set plugins(${name}_description) $desc
		set plugins(${name}_amsn_version) $amsn_version
		set plugins(${name}_plugin_version) $plugin_version
		#dir is the path to pluginsinfo.xml, so we need to use [file dirname] to get the actual dir path
		set plugins(${name}_plugin_file) [file join [file dirname $dir] $plugin_file]
		set plugins(${name}_plugin_dir) [file dirname $dir]
		set plugins(${name}_plugin_namespace) $plugin_namespace
		set plugins(${name}_init_proc) $init
		set plugins(${name}_deinit_proc) $deinit

		return 0
	}


	###############################################################
	# PluginGui ()
	#
	# The Plugin Selector, allows users to load, unload, and configure plugins
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc PluginGui { } {
		# array that will hold information of plugins
		variable plugins
		# the variable that holds the path to the selection window
		variable w
		# list of all the loaded plugins
		variable loadedplugins
		# array that holds info about currently selected plugin
		variable selection
		# the path to the frame where are displayed pieces of information for a plugin
		variable mF

		# clear the selection
		set selection ""
		# set the window path
		set w .plugin_selector

		# if the window already exists, focus it, otherwise create it
		if {[winfo exists $w]} {
			raise $w
			return
		}

		# update the information and list of plugins
		::plugins::updatePluginsArray
		# create window and give it it's title
		toplevel $w
		wm title $w [trans pluginselector]
		wm geometry $w 500x400
		# create widgets
		# listbox with all the plugins
		listbox $w.plugin_list -background "white" -height 15 -yscrollcommand "$w.ys set" -relief flat -highlightthickness 0
		scrollbar $w.ys -command "$w.plugin_list yview"

		#Scrollableframe that will contain pieces of information about a plugin
		ScrolledWindow $w.sw 
		ScrollableFrame $w.sw.sf -areaheight 0 -areawidth 0 
		$w.sw setwidget $w.sw.sf
		set mF [$w.sw.sf getframe]	
			
		# holds the plugins info like name and description
		label $mF.name_title -text [trans name] -font sboldf
		label $mF.name  -wraplength 280 
		label $mF.version_title -text [trans version] -font sboldf
		label $mF.version
		label $mF.author_title -text [trans author] -font sboldf
		label $mF.author  -wraplength 280 
		label $mF.desc_title -text [trans description] -font sboldf
		# TODO make the -wraplength fit the label's width
		label $mF.desc -wraplength 280 -justify left -anchor w
		# holds the 'command center' buttons
		label $w.getmore -text "[trans getmoreplugins]" -fg #0000FF -cursor hand2

		button $w.load -text "[trans load]" -command "::plugins::GUI_Load" -state disabled
		button $w.config -text "[trans configure]" -command "::plugins::GUI_Config" ;#-state disabled
		button $w.close -text [trans close] -command "::plugins::GUI_Close"
 
		#loop through all the plugins and add them to the list
		foreach {plugin} [lsort -dictionary [array names ::plugins::plugins *_name]] {
		    set name $plugins(${plugin})
		    # add the plugin name to the list at counterid position
		    $w.plugin_list insert end $name
		    # if the plugin is loaded, color it one color. otherwise use other colors
		    #TODO: Why not use skins?
		    if {[lsearch "$loadedplugins" $plugins(${name}_name)] != -1} {
			$w.plugin_list itemconfigure end -background #DDF3FE
		    } else {
			$w.plugin_list itemconfigure end -background #FFFFFF
		    }
		}
		if {[$w.plugin_list size] > "15"} {
			$w.plugin_list configure -height [$w.plugin_list size]
		}
		#do the bindings
		bind $w.plugin_list <<ListboxSelect>> "::plugins::GUI_NewSel"
		bind $w <<Escape>> "::plugins::GUI_Close"

		pack $w.plugin_list -fill both -side left
		pack $w.ys -fill both -side left
		pack $mF.name_title -padx 5 -anchor w
		pack $mF.name -padx 5 -anchor w
		pack $mF.version_title -padx 5 -anchor w
		pack $mF.version -padx 5 -anchor w 
		pack $mF.author_title -padx 5 -anchor w
		pack $mF.author -padx 5 -anchor w
		pack $mF.desc_title -padx 5 -anchor w
		pack $mF.desc -anchor nw -expand true -fill x -padx 5
		pack $w.sw -anchor w -side top -expand true -fill both
		pack $w.getmore -side top -anchor e -padx 5
		bind $w.getmore <Enter> "$w.getmore configure -font sunderf"
		bind $w.getmore <Leave> "$w.getmore configure -font splainf"
		set lang [::config::getGlobalKey language]
		bind $w.getmore <ButtonRelease> "launch_browser $::weburl/plugins.php?lang=$lang"

		pack $w.close $w.config $w.load -padx 5 -pady 5 -side right -anchor se


		moveinscreen $w 30
		return

	}

    
	###############################################################
	# GUI_NewSel ()
	#
	# This handles new selections in the listbox aka updates the selection array
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc GUI_NewSel { } {
		# window path
		variable w
		# selection array
		variable selection
		# plugins' info
		variable plugins
		# the loaded plugins
		variable loadedplugins
		# the path to the frame where are displayed pieces of information for a plugin
		variable mF

		# find the id of the currently selected plugin
		if { [ $w.plugin_list curselection ] == "" } {
			return
		}
		set selection [$w.plugin_list get [$w.plugin_list curselection]]
		# if the selection is empty, end proc
		if { $selection == "" } {
			return
		}

		# update the description
		$mF.name configure -text $selection
		$mF.author configure -text [getInfo $selection author]
		$mF.version configure -text [getInfo $selection plugin_version]
		$mF.desc configure -text [getInfo $selection description]
		
		# update the buttons

		$w.config configure -state normal

		if {[lsearch "$loadedplugins" $selection] != -1 } {
			# if the plugin is loaded, enable the Unload button and update the colors
			$w.load configure -state normal -text [trans unload] -command "::plugins::GUI_Unload"
			$w.plugin_list itemconfigure [$w.plugin_list curselection] -background #DDF3FE

			# if the plugin has a configlist, then enable configuration.
			# Otherwise disable it
			if {[info exists ::[getInfo $selection plugin_namespace]::configlist] == 1} {
				$w.config configure -state normal
			} else {
				$w.config configure -state disabled
			}
		} else { # plugin is not loaded
			# enable the load button and disable config button and update color
			$w.load configure -state normal -text "[trans load]" -command "::plugins::GUI_Load"
			$w.plugin_list itemconfigure [$w.plugin_list curselection] -background #FFFFFF
			$w.config configure -state disabled
		}
	}


	###############################################################
	# GUI_Load ()
	# 
	# This proc is called when the Load button is clicked. It loads a plugin
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc GUI_Load { } {
		# selected info, it will load this plugin
		variable selection
		# window path
		variable w
		#info about the plugins
		variable plugins
		# don't do anything is there is no selection
		if { $selection == "" } {
			plugins_log core "Cannot load plugin, none selected"
			return
		}

		# Do the actual loading and check if it loads properly
		if { [LoadPlugin $selection] == -1 } {
			return
		}

		#update the buttons and colors in the plugins dialog
		GUI_NewSel
	}


	###############################################################
	# GUI_Unload ()
	#
	# Unload the currently selected plugin. Called by the Unload button
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc GUI_Unload { } {
		# the selection, will unload the plugin
		variable selection
		# window path
		variable w

		if {$selection==""} {
		    return;
		}
		
		# do the actual unloading
		UnLoadPlugin $selection
		# update the buttons and colors in the dialog
		GUI_NewSel
	}


	###############################################################
	# GUI_Config ()
	#
	# The Configure button is cliecked. Genereates the configure dialog
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc GUI_Config { } {
	    # selection, will configure it
	    variable selection
	    # window path
	    variable w
	    #info about the plugins
	    variable plugins

	    #the standard "check for selection"
	    if { $selection == "" } {
		return
	    }

	    #name of the configuration window
	    set confw ${w}.winconf_${selection}

	    #If the window is already here, just raise it to the front
	    if { [winfo exists $confw] } {
		raise $confw
		return
	    } else {
		#create the configuration window
		set winconf [toplevel $confw]
	    }

	    # list of callbacks for pressing save of frame types
	    variable saveframelist 
	    set saveframelist {}
	    
	    # get the name
	    set name $selection
	    set namespace [getInfo $selection plugin_namespace]

	    plugins_log core "Calling ConfigPlugin in the $name namespace\n"

	    # is there a config list?
	    if {[info exists ::${namespace}::configlist] == 0} {
	    	# no config list, just put a label "Nothing to configure" in the configure dialog
		plugins_log core "No Configuration variable for $name.\n"
		label $winconf.label -text "No Configuration variable for $name.\n"
		button $winconf.ok -text [trans ok] -command "destroy $winconf"
		pack $winconf.label
		pack $winconf.ok
	    } else { # configlist exists
		    # backup the current config
		    array set ::${namespace}::old_config [array get ::${namespace}::config]
		    # create the frame where the configuration is gonna get packed
		    set confwin [frame $winconf.area]
		    # id used for the item name in the widget
		    set i 0
		    # loop through all the items
		    foreach confitem [set ::${namespace}::configlist] {
			# Increment both variables
			incr i
			# Check the configuration item type and create it in the GUI
			switch [lindex $confitem 0] {
			    label {
				# This configuration item is a label (Simply text to show)
				label $confwin.$i -text [lindex $confitem 1]
				pack $confwin.$i -anchor w -padx 10
			    }
			    bool {
				# This configuration item is a checkbox (Boolean variable)
				checkbutton $confwin.$i -text [lindex $confitem 1] -variable \
				    ::${namespace}::config([lindex $confitem 2])
				pack $confwin.$i -anchor w -padx 20
			    }
			    ext {
				# This configuration item is a button (Action related to key)
				button $confwin.$i -text [lindex $confitem 1] -command \
				    ::${namespace}::[lindex $confitem 2]
				pack $confwin.$i -anchor w -padx 20 -pady 5
			    }
			    str {
				# This configuration item is a text input (Text string variable)
				set frame [frame $confwin.f$i]
				entry $frame.${i}e -textvariable \
				    ::${namespace}::config([lindex $confitem 2]) -bg white
				label $frame.${i}l -text [lindex $confitem 1]
				pack $frame.${i}l -anchor w -side left -padx 20
				pack $frame.${i}e -anchor w -side left -fill x
				pack $frame -fill x
			    }
			    pass {
				# This configuration item is a password input (Text string variable)
				set frame [frame $confwin.f$i]
				entry $frame.${i}e -show "*" -textvariable \
				    ::${namespace}::config([lindex $confitem 2])
				label $frame.${i}l -text [lindex $confitem 1]
				pack $frame.${i}l -anchor w -side left -padx 20
				pack $frame.${i}e -anchor w -side left -fill x
				pack $frame -fill x -anchor w
			    }
			    lst {
				# This configuration item is a listbox that stores the selected item.
				set height [llength [lindex $confitem 1]]
				listbox $confwin.$i -height $height -width 0 -bg white
				foreach item [lindex $confitem 1] {
				    $confwin.$i insert end $item
				}
				bind $confwin.$i <<ListboxSelect>> "::plugins::lst_refresh $confwin.$i ::${namespace}::config([lindex $confitem 2])"
				pack $confwin.$i -anchor w -padx 40
			    }
			    rbt {
				# This configuration item contains radiobutton
				set buttonlist [lrange $confitem 1 end-1]
				set value 0
				foreach item $buttonlist {
				    incr value
				    radiobutton $confwin.$i -text "$item" -variable ::${namespace}::config([lindex $confitem end]) -value $value
				    pack $confwin.$i -anchor w -padx 40
				    incr i
				}
				incr i -1
			    }
			    frame {
			    	# This configureation item creates a frame so the plugin can place whatever it like inside
				frame $confwin.$i
				[lindex $confitem 1] $confwin.$i
				if { "[lindex $confitem 2]" != "" } {
					lappend saveframelist "[lindex $confitem 2] $confwin.$i"
				}
				pack $confwin.$i -fill x -anchor w
			    }
			}
		    }
		}
		
		# set the name of the winconf
		wm title $confw "[trans configure] $selection"
		
		# Grid the frame
		pack $confwin -fill x
		# Create and grid the buttons
		button $winconf.save -text [trans save] -command "[list ::plugins::GUI_SaveConfig $winconf $name]"
		button $winconf.cancel -text [trans cancel] -command "[list ::plugins::GUI_CancelConfig $winconf $namespace]"
		pack $winconf.save -anchor se -pady 5 -padx 5 -side right
		pack $winconf.cancel -anchor se -pady 5 -padx 5 -side right
		bind $winconf <<Escape>> "destroy $winconf"
		moveinscreen $winconf 30
	}


	###############################################################
	# lst_refresh (path, config)
	#
	# The list box on config window changes its selected value, so
	# this proc refresh the associated variable with the new value
	#
	# Arguments
	# path - The listbox widget path 
	# config - The complete config entry (with plugin namespace)
	#
	# Return
	# none
	#
	proc lst_refresh { path config } {
		set ${config} [$path get [$path curselection] [$path curselection]]	
	}


	###############################################################
	# GUI_SaveConfig (w)
	#
	# The Save button in Configuration Window is clicked. Save the
	# plugins configuration and then destroy the Configuration Window
	#
	# Arguments
	# w - The configuration window widget path
	# name - The name of the plugin that was changed (if any)
	#
	# Return
	# none
	#
	proc GUI_SaveConfig { w {name ""}} {
		variable saveframelist
		
		if { $name != "" } {
			#add a postevent to warn the plugin when it is configured
			set evPar(name) $name
			::plugins::PostEvent PluginConfigured evPar
		}
		
		foreach call $saveframelist {
			eval $call
		}

		set saveframelist {}

		::plugins::save_config
		destroy $w;
	}


	###############################################################
	# GUI_CancelConfig (w, namespace)
	#
	# The Cancel button in Configuration Window is cliecked. Return to
	# original configuration and then destroy the Configuration Window
	#
	# Arguments
	# w - The configuration window widget path 
	# namespace - The namespace of the plugin not configured
	#
	# Return
	# none
	#
	proc GUI_CancelConfig { w namespace } {
		array set ::${namespace}::config [array get ::${namespace}::old_config]
		#unset the old array to save space
		unset ::${namespace}::old_config

		destroy $w;
	}


	###############################################################
	# GUI_Close ()
	#
	# The Close button is cliecked. Simply destroy the Plugins Window
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc GUI_Close { } {
		variable w
		destroy $w
	}


	###############################################################
	# UnLoadPlugins ()
	#
	# Unloads all loaded plugins (if any) 
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc UnLoadPlugins { {saveBefore 1} } {
		variable loadedplugins

		if {$saveBefore} {
			::plugins::save_config
		}

		foreach {plugin} "$loadedplugins" {
			# the "0" is to tell UnLoadPlugin not to save the config
			::plugins::UnLoadPlugin $plugin 0
		}
	}


	###############################################################
	# UnLoadPlugin (plugin)
	#
	# Unloads the $plugin plugin, removes its events, executes its
	# destructor procedure (a.k.a. DeInit) and moves its config
	# array to global namespace (since its namespace will be removed)
	#
	# Arguments
	# plugin - The plugin to be removed
	#
	# Return
	# none
	#
	proc UnLoadPlugin { plugin {save 1}} {

		variable loadedplugins
		plugins_log core "Unloading plugin $plugin\n"

		#unregister events
		UnRegisterEvents $plugin

		#get the namespace and deinit proc and if it exists, call it
		set namespace [getInfo $plugin plugin_namespace]
		set deinit [getInfo $plugin deinit_proc]
		if {[info procs "::${namespace}::${deinit}"] == "::${namespace}::${deinit}"} {
			if { [catch {::${namespace}::${deinit}} res] } {
				plugins_log core "Error in deinit proc : $res"
			}
		}

		#copy the config array to a config plugin
		if {[array exists ::${namespace}::config]} {
			set ::plugins::config($plugin) [array get ::${namespace}::config]
		}

		#remove it from the loadedplugins list
		set loadedplugins [lreplace $loadedplugins [lsearch $loadedplugins "$plugin"] [lsearch $loadedplugins "$plugin"]]

		if {$save} { ::plugins::save_config }

	}


	###############################################################
	# LoadPlugins ()
	#
	# Loads all plugins that were previously loaded (stored in
	# configuration file plugins.xml) reading $loadedplugins
	# Also it loads all the core plugins
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc LoadPlugins {} {

	    variable loadedplugins
		# the "0" is to tell UnLoadPlugins not to save the config before unloading plugins
	    ::plugins::UnLoadPlugins 0
	    
	    #resets the loadedplugins list to plugins that were loaded before
	    load_config

	    #"HACK" to load 'core' plugins for the 0.95 release
	    #HERE WE HAVE A LIST OF PLUGINS THAT ARE SHIPPED WITH AMSN AND SHOULD BE LOADED IF THE USER SEES 'M FOR THE FIRST TIME
	    #logic: if this is the first time the user logged in, then 
	    #the configuration list is empty which means load_config
	    #makes loadedplugins empty
	    if {[llength $loadedplugins] == 0} {
		    set loadedplugins [list "Nudge" "Cam Shooter" "remind"]
	    }

	    #update the list of installed plugins because this proc is usually 
	    #called when a new user logs in, so he migh have diff plugins in
	    # his ~/.amsn/{user}/plugins
	    ::plugins::updatePluginsArray

	    foreach plugin $loadedplugins {
		status_log "PLUGIN : $plugin\n" red
		#check if the plugin exists, then load it
		#TODO: what should we do if it doesn't exist?
		# - remove it from loadedplugins, but how to we know to load it if it exists
		# - (current) keep it and hope nothing calls a proc that depends on this plugin to be loaded (and checks if it is loaded)
		if {[array names ::plugins::plugins ${plugin}_name] != ""} {
			LoadPlugin $plugin
		}
	    }

	}


	###############################################################
	# LoadPlugin (plugin)
	#
	# Loads the $plugin plugin and restore its configuration from
	# global namespace if existed.
	#
	# The reason for all the arguments is developemnt testing,
	# we can test different files via the status_log window
	#
	# Arguments
	# plugin - The plugin to load (name)
	# required_version - Required aMSN version for the plugin to load
	# file - The plugin's TCL main file
        # namespace - The plugin's main namespace
        # init_proc - The plugin's init procedure
	#
	# Return
	# 1 - success
	# -1 - failiture
	#
	proc LoadPlugin { plugin } {

		variable loadedplugins

		set required_version [getInfo $plugin amsn_version]
		set file [getInfo $plugin plugin_file]
		set namespace [getInfo $plugin plugin_namespace]
		set init_proc [getInfo $plugin init_proc]

		#error checking
		if { ![CheckRequirements $required_version] } {
			msg_box "$plugin: [trans required_version $required_version]"
			return -1
		}

		if { [catch { source $file } res] } {
			msg_box "$plugin: Failed to load source with result:\n\n$res"
			return -1
		}

		#copy the config if it exists
		if {[array names ::plugins::config $plugin] != ""} {
			if {$::plugins::config(${plugin}) != ""} {
				array set ::${namespace}::config $::plugins::config(${plugin})
			}
		}
	    
		#add it to loadedplugins, if it's not there already
		#we need to add it before the init_proc is called!
		if {[lsearch "$loadedplugins" $plugin] == -1} {
			plugins_log core "appending to loadedplugins\n"
			lappend loadedplugins $plugin
		}

		#call the init proc if it exists
		if {[info procs ::${namespace}::${init_proc}] == "::${namespace}::${init_proc}"} {
			plugins_log core "Initializing plugin $plugin with ${namespace}::${init_proc}\n"
	
			#check for Tcl/Tk errors
			if {[catch {::${namespace}::${init_proc} [file dirname $file]} res] } {
				plugins_log core "Initialization of plugin $plugin with ${namespace}::${init_proc} failed\n$res\n$::errorInfo"
				msg_box "Plugins System: Can't initialize plugin:init procedure caused an internal error"
				UnLoadPlugin $plugin
				return -1
			#If proc returns -1, end because it failed because it's own reasons
			} elseif {$res == -1} {
				UnLoadPlugin $plugin
				return -1
			}
			#can someone explain what this is for?
			eval {proc ::${namespace}::${init_proc} {file} { return } }
		} else {
			msg_box "Plugins System: Can't initialize plugin:init procedure not found"
			return -1
		}

	    	if {[array names ::plugins::config $plugin] != ""} {
			if {$::plugins::config(${plugin}) != ""} {
				array set ::${namespace}::config $::plugins::config(${plugin})
			}
			unset ::plugins::config(${plugin})
		} else {
			plugins_log core "Plugins System: no config for plug-in $plugin\n"
		}
				
		#Call PostEvent Load
		#Keep in variable if we are online or not
		#TODO: dosn't exist on start?
		if { [catch { set stat [ns cget -stat] } ] } {
			set status offline
		} elseif { $stat == "o" } {
	      		set status online
		} else {
			set status offline
		}
		set evpar(name) $plugin
		set evpar(status) $status
		::plugins::PostEvent Load evpar
		::plugins::save_config
		return 1
	}


	###############################################################
	# CheckRequirements (required_version)
	#
	# Checks if we satisfy requirements of the plugin (only version now)
	#
	# Arguments
	# required_version - Version of aMSN needed to run the plugin
	#
	# Return
	# 0 - We don't satisfy them
	# 1 - We satisfy them, we can load the plugin.
	#
	proc CheckRequirements { required_version } {
		global version
		plugins_log core "Plugin needs $required_version"
		scan $required_version "%d.%d" r1 r2;
		scan $version "%d.%d" y1 y2;
		if { $r1 > $y1 } {
			return 0
		} elseif { $r2 > $y2 } {
			return 0
		}
		return 1
	}


	###############################################################
	# save_config ()
	#
	# Saves the configuration of loaded plugins and ::plugins::config
	# in plugins.xml.
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc save_config { } {
		global HOME
		variable loadedplugins

		plugins_log core "save_config: saving plugin config for user [::config::getKey login] in $HOME]\n"
	
		if { [catch {
			if { [OnUnix] } {
				set file_id [open "[file join ${HOME} plugins.xml]" w 00600]
			} else {
				set file_id [open "[file join ${HOME} plugins.xml]" w]
			}
		} res]} {
			return 0
		}

		plugins_log core "save_config: saving plugin config_file. Opening of file returned : $res\n"

		puts $file_id  "<?xml version=\"1.0\"?>\n\n<config>"

		#save the loaded plugins
		foreach {plugin} $loadedplugins {
			set namespace [getInfo $plugin plugin_namespace]
			puts $file_id "\t<plugin>"
			puts $file_id "\t\t<name>${plugin}</name>"
			puts $file_id "\t\t<loaded>true</loaded>"
			if {[array exists ::${namespace}::config]==1} {
				plugins_log core "save_config: Saving from $plugin's namespace: $namespace\n"
				foreach var_attribute [array names ::${namespace}::config] {
					#TODO: a better way to do this
					#set var_value $::${namespace}::config(${var_attribute})
					set var_value ::${namespace}::config
					set var_value [lindex [array get $var_value $var_attribute] 1]
					set var_value [::sxml::xmlreplace $var_value]
					puts $file_id "\t\t<entry>"
					puts $file_id "\t\t\t<key>$var_attribute</key>"
					puts $file_id "\t\t\t<value>$var_value</value>"
					puts $file_id "\t\t</entry>"
				}
			}
			puts $file_id "\t</plugin>"
		}
		
		#save the other plugins
		foreach {plugin} [array names ::plugins::config] {
			puts $file_id "\t<plugin>"
			puts $file_id "\t\t<name>${plugin}</name>"
			puts $file_id "\t\t<loaded>false</loaded>"
			foreach {var_attribute var_value} $plugins::config($plugin) {
				set var_value [::sxml::xmlreplace $var_value]
				puts $file_id "\t\t<entry>\n"
				puts $file_id "\t\t\t<key>$var_attribute</key>\n"
				puts $file_id "\t\t\t<value>$var_value</value>\n"
				puts $file_id "\t\t</entry>"
			}
			puts $file_id "\t</plugin>"
			
		}

		puts $file_id "</config>"
		close $file_id

		plugins_log core "save_config: Plugins config saved\n"
	}


	###############################################################
	# load_config ()
	#
	# Loads the configuration of plugins stored in plugin.xml
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc load_config {} {
		global HOME password protocol
		variable loadedplugins
		foreach {plugin} $loadedplugins {
			::plugins::UnLoadPlugin $plugin
		}
		set loadedplugins [list]

		if { [file exists [file join ${HOME} "plugins.xml"]] } {
			plugins_log core "load_config: loading file [file join ${HOME} plugins.xml]\n"
			if { [catch {
				set file_id [::sxml::init [file join ${HOME} "plugins.xml"]]
				::sxml::register_routine $file_id "config:plugin:name" "::plugins::new_plugin_config"
				::sxml::register_routine $file_id "config:plugin:loaded" "::plugins::new_plugin_loaded"
				::sxml::register_routine $file_id "config:plugin:entry" "::plugins::new_plugin_entry_config"
				::sxml::parse $file_id
				::sxml::end $file_id
				plugins_log core "load_config: Config loaded\n"
			} res] } {
				::amsn::errorMsg "[trans corruptconfig [file join ${HOME} "plugins.xml.old"]]"
				file copy [file join ${HOME} "plugins.xml"] [file join ${HOME} "plugins.xml.old"]
			}
		} else {
			status_log "Plugins System: load_config: No plugins.xml]\n" red
		}
	}


	###############################################################
	# new_plugin_config (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and appends
	# each new plugin from plugin.xml to config
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#
	proc new_plugin_config {cstack cdata saved_data cattr saved_attr args} {
		variable cur_plugin
		set cur_plugin $cdata
		set ::plugins::config(${cur_plugin}) [list]
		return 0
	}


	###############################################################
	# new_plugin_loaded (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and appends
	# each new plugin from plugin.xml that was loaded before to
	# $::plugins::loadedplugins
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#
	proc new_plugin_loaded {cstack cdata saved_data cattr saved_attr args} {
		variable cur_plugin
		variable loadedplugins
		set yes $cdata
		plugins_log core "$cur_plugin has a loaded tag with $yes in it...\n"
		if {$yes == "true"} {
			if {[lsearch $loadedplugins $cur_plugin] == -1 } {
				lappend loadedplugins $cur_plugin
			}
		}
		return 0
	}


	###############################################################
	# new_plugin_entry_config (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and sets
	# an array in global namespace with the configuration of the plugin.
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#
	proc new_plugin_entry_config {cstack cdata saved_data cattr saved_attr args} {
		variable cur_plugin
		upvar $saved_data sdata
		lappend ::plugins::config(${cur_plugin}) $sdata(${cstack}:key) $sdata(${cstack}:value);
		return 0
	}


	###############################################################
	# LoadInfoAutoupdate (plugin)
	#
	# Load the XML information of a plugin for autoupdate
	#
	# Arguments
	# The name of the plugin
	#
	# Return
	# 0 if an error occured, 1 else
	#
	proc LoadInfoAutoupdate { plugin } {

		variable plugins
		variable cur_plugin $plugin

		set plugins(${plugin}_lang) ""
		set plugins(${plugin}_file) ""

		set fd [file join [getInfo $plugin plugin_dir] plugininfo.xml]

		if { [file readable $fd] } {
			
			if { [catch {
				set plugin_info [sxml::init $fd]
				sxml::register_routine $plugin_info "plugin" "::plugins::XMLInfoCVS"
				sxml::register_routine $plugin_info "plugin:lang" "::plugins::XMLInfoLang"
				sxml::register_routine $plugin_info "plugin:file" "::plugins::XMLInfoFile"
				sxml::register_routine $plugin_info "plugin:URL" "::plugins::XMLInfoURLplugininfo"
				sxml::parse $plugin_info
				sxml::end $plugin_info
				plugins_log core "PLUGINS INFO READ\n"
			} res] } {
				msg_box "ERROR: PLUGIN $plugin HAS MALFORMED XML PLUGININFO for autoupdate"
				return 0
			}
		}

		return 1

	}


	###############################################################
	# XMLInfoCVS (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoLang (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoFile (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoURL (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and appends
	# each new plugin to $::plugins::plugins array
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#
	proc XMLInfoCVS { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:cvs_version)] } {
			set cvs_version ""
		} else {
			set cvs_version $sdata(${cstack}:cvs_version)
		}

		set plugins(${cur_plugin}_cvs_version) $cvs_version

		return 0

	}


	proc XMLInfoLang { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:langcode)] || ![info exists sdata(${cstack}:version)] } {
			set  langcode ""
			set version ""
		} else {
			set langcode $sdata(${cstack}:langcode)
			set version $sdata(${cstack}:version)
		}

		lappend plugins(${cur_plugin}_lang) [list $langcode $version]

		return 0

	}


	proc XMLInfoFile { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:path)] || ![info exists sdata(${cstack}:version)] } {
			set  path ""
			set version ""
		} else {
			set path $sdata(${cstack}:path)
			set version $sdata(${cstack}:version)
		}

		lappend plugins(${cur_plugin}_file) [list $path $version]

		return 0

	}
	
	
	proc XMLInfoURLplugininfo { cstack cdata saved_data cattr saved_attr args } {
	
		upvar $saved_data sdata
		variable plugins
		variable cur_plugin
		
		if { ![info exists sdata(${cstack}:plugininfo)] } {
			set URL_plugininfo ""
		} else {
			set URL_plugininfo $sdata(${cstack}:plugininfo)
		}

		set plugins(${cur_plugin}_URL_plugininfo) $URL_plugininfo

		return 0
		
	}


	###############################################################
	# LoadInfoAutoupdate_Online (plugin)
	#
	# Get the plugininfo.xml on the website, and load it
	#
	# Arguments
	# The name of the plugin
	#
	# Return
	# 0 if an error occured, 1 else
	#
	proc LoadInfoAutoupdate_Online { plugin } {

		global HOME2
		variable plugins
		variable cur_plugin $plugin

		set plugins(${plugin}_lang_online) ""
		set plugins(${plugin}_file_online) ""
		
		set URL [getInfo $plugin URL_plugininfo]
		
		if { [catch {
			
			# If no URL is given, look at the CVS URL
			if { $URL == "" } {
				
				set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/plugininfo.xml" -timeout 120000 -binary 1]
				set content [::http::data $token]
				::http::cleanup $token
				
				if { [string first "<html>" "$content"] == -1 } {
					set plugins(${plugin}_URL_place) 1
				} else {
					set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/plugininfo.xml" -timeout 120000 -binary 1]
					set content [::http::data $token]
					if { [string first "<html>" "$content"] == -1 } {
						set plugins(${plugin}_URL_place) 2
					} else {
						::http::cleanup $token
						return 0
					}
					
				}

				
				# Else, look at the URL given
			} else {
				
				set token [::http::geturl "$URL" -timeout 120000 -binary 1]
				set content [::http::data $token]
				if { [string first "<html>" "$content"] != -1 } {
					::http::cleanup $token
					return 0
				}
				set plugins(${plugin}_URL_place) 3
				
			}
			
			set status [::http::status $token]
			if { $status != "ok" } {
				status_log "Can't get plugininfo.xml for $plugin (place [getInfo $plugin URL_place] - URL $URL): $status (http token: $token)\n" red
				::http::cleanup $token
				return 0
			}
			
			set filename "[file join $HOME2 $plugin.xml]"
			set fid [open $filename w]
			fconfigure $fid -encoding binary
			puts -nonewline $fid "$content"
			close $fid
			::http::cleanup $token
		
			set id [::sxml::init $filename]
			sxml::register_routine $id "plugin" "::plugins::XMLInfoCVS_Online"
			sxml::register_routine $id "plugin:lang" "::plugins::XMLInfoLang_Online"
			sxml::register_routine $id "plugin:file" "::plugins::XMLInfoFile_Online"
			sxml::register_routine $id "plugin:URL" "::plugins::XMLInfoURL_Online"
			sxml::parse $id
			sxml::end $id
			
		} ] } {
			if {[info exists token] } {
				status_log "Can't get online plugininfo.xml for $plugin (place [getInfo $plugin URL_place] - URL $URL)(token: $token)\n" red
				::http::cleanup $token
			}
			return 0
			
		}
		
		return 1

	}


	###############################################################
	# XMLInfoCVS_Online (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoLang_Online (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoFile_Online (cstack, cdata, saved_data, cattr saved_attr, args)
	# XMLInfoURL_Online (cstack, cdata, saved_data, cattr saved_attr, args)
	#
	# Raises the information parsed by the sxml component and appends
	# each new plugin to $::plugins::plugins array
	#
	# Arguments
	# supplied by the sxml component (its only executor)
	#
	# Return
	# none
	#
	proc XMLInfoCVS_Online { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:amsn_version)] || ![info exists sdata(${cstack}:cvs_version)] } {
			set amsn_version ""
			set cvs_version ""
		} else {
			set amsn_version $sdata(${cstack}:amsn_version)
			set cvs_version $sdata(${cstack}:cvs_version)
		}

		set plugins(${cur_plugin}_amsn_version_online) $amsn_version
		set plugins(${cur_plugin}_cvs_version_online) $cvs_version

		return 0

	}


	proc XMLInfoLang_Online { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:langcode)] || ![info exists sdata(${cstack}:version)] } {
			set  langcode ""
			set version ""
		} else {
			set langcode $sdata(${cstack}:langcode)
			set version $sdata(${cstack}:version)
		}

		lappend plugins(${cur_plugin}_lang_online) [list $langcode $version]

		return 0

	}


	proc XMLInfoFile_Online { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin

		if { ![info exists sdata(${cstack}:path)] || ![info exists sdata(${cstack}:version)] } {
			set  path ""
			set version ""
		} else {
			set path $sdata(${cstack}:path)
			set version $sdata(${cstack}:version)
		}

		lappend plugins(${cur_plugin}_file_online) [list $path $version]

		return 0

	}


	proc XMLInfoURL_Online { cstack cdata saved_data cattr saved_attr args } {

		upvar $saved_data sdata
		variable plugins
		variable cur_plugin
		
		if { ![info exists sdata(${cstack}:main)] } {
			set URL_main ""
		} else {
			set URL_main $sdata(${cstack}:main)
		}

		if { ![info exists sdata(${cstack}:plugininfo)] } {
			set URL_plugininfo ""
		} else {
			set URL_plugininfo $sdata(${cstack}:plugininfo)
		}

		if { ![info exists sdata(${cstack}:lang)] } {
			set URL_lang ""
		} else {
			set URL_lang $sdata(${cstack}:lang)
		}

		if { ![info exists sdata(${cstack}:file)] } {
			set URL_file ""
		} else {
			set URL_file $sdata(${cstack}:file)
		}


		set plugins(${cur_plugin}_URL_main_online) $URL_main
		set plugins(${cur_plugin}_URL_plugininfo_online) $URL_plugininfo
		set plugins(${cur_plugin}_URL_lang_online) $URL_lang
		set plugins(${cur_plugin}_URL_file_online) $URL_file

		return 0

	}


	###############################################################
	# DownloadMain (plugin)
	#
	# Download the main file of a plugin
	#
	# Arguments
	# The name of the plugin
	#
	# Return
	# 0 if there was a problem, 1 else
	#
	proc DownloadMain { plugin } {
	
		variable plugins

		set version [getInfo $plugin cvs_version_online]

		set w ".updatelangplugin"
		
		if { [winfo exists $w] } {
			$w.update.txt configure -text "[trans updating] $plugin..."
		}

		set place [getInfo $plugin URL_place]
		set URL [getInfo $plugin URL_main_online]	
		
		if { $place == 1 } {
			set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/[getInfo $plugin plugin_file]" -timeout 120000 -binary 1]
		} elseif { $place == 2 } {
			set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/[getInfo $plugin plugin_file]" -timeout 120000 -binary 1]
		} elseif { $place == 3 && $URL != "" } {
			set URL "[subst $URL]"
			set token [::http::geturl "$URL" -timeout 120000 -binary 1]
		} else {
			return 0
		}

		set status [::http::status $token]
		if { $status != "ok" } {
			::http::cleanup $token
			return 0
		}

		set content [::http::data $token]
		
		if { [string first "<html>" "$content"] != -1 } {
			::http::cleanup $token
			return 0
		}

		set filename [file join [getInfo $plugin plugin_dir] [getInfo $plugin plugin_file]]
		set fid [open $filename w]
		fconfigure $fid -encoding binary
		puts -nonewline $fid "$content"
		close $fid
		::http::cleanup $token		
		
		return 1

	}

	###############################################################
	# DownloadLangs (plugin langs)
	#
	# Download the lang files of a plugin
	#
	# Arguments
	# The name of the plugin
	# The langs we want to download, which is a list of items "{langcode version}"
	#
	# Return
	# 0 if there was a problem, 1 else
	#
	proc DownloadLangs { plugin langs } {

		variable plugins

		set w ".updatelangplugin"
		
		foreach lang $langs {

			set langcode [lindex $lang 0]
			set version [lindex $lang 1]
		
			if { [winfo exists $w] } {
				$w.update.txt configure -text "[trans updating] $plugin : lang$langcode..."
			}

			set place [getInfo $plugin URL_place]
			set URL [getInfo $plugin URL_lang_online]

			if { $place == 1 } {
				set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/lang/lang$langcode" -timeout 120000 -binary 1]
			} elseif { $place == 2 } {
				set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/lang/lang$langcode" -timeout 120000 -binary 1]
			} elseif { $place == 3 && $URL != "" } {
				set URL "[subst $URL]"
				set token [::http::geturl "$URL" -timeout 120000 -binary 1]
			} else {
				return 0
			}

			set status [::http::status $token]
			if { $status != "ok" } {
				::http::cleanup $token
				return 0
			}

			set content [::http::data $token]
			
			if { [string first "<html>" "$content"] != -1 } {
				::http::cleanup $token
				return 0
			}

			set filename [file join [getInfo $plugin plugin_dir] "lang" lang$langcode]
			set dir [file join [getInfo $plugin plugin_dir] "lang"]

			if { ![file isdirectory $dir] } {
				file mkdir $dir
				status_log "Auto-update ($plugin) : create dir $dir\n" red
			}

			set fid [open $filename w]
			fconfigure $fid -encoding binary
			puts -nonewline $fid "$content"
			close $fid
			::http::cleanup $token

		}
		
		return 1
		
	}


	###############################################################
	# DownloadFiles (plugin files)
	#
	# Download the other files of a plugin
	#
	# Arguments
	# The name of the plugin
	# The files we want to download, which is a list of items "{path version}"
	#
	# Return
	# 0 if there was a problem, 1 else
	#
	proc DownloadFiles { plugin files } {

		variable plugins
		
		set w ".updatelangplugin"
		
		foreach file_version $files {

			set file [lindex $file_version 0]
			set version [lindex $file_version 1]

			if { [winfo exists $w] } {
				$w.update.txt configure -text "[trans updating] $plugin : $file..."
			}

			set place [getInfo $plugin URL_place]
			set URL [getInfo $plugin URL_file_online]

			if { $place == 1 } {
				set token [::http::geturl "${::weburl}/autoupdater/plugins/$plugin/$file" -timeout 120000 -binary 1]
			} elseif { $place == 2} {
				set token [::http::geturl "${::weburl}/autoupdater/plugins2/$plugin/$file" -timeout 120000 -binary 1]
			} elseif { $place == 3 && $URL != "" } {
				set URL "[subst $URL]"
				set token [::http::geturl "$URL" -timeout 120000 -binary 1]
			} else {
				return 0
			}

			set status [::http::status $token]
			if { $status != "ok" } {
				::http::cleanup $token
				return 0
			}

			set content [::http::data $token]
			
			if { [string first "<html>" "$content"] != -1 } {
				::http::cleanup $token
				return 0				
			}

			set filename [file join [getInfo $plugin plugin_dir] $file]
			set dir [file join [getInfo $plugin plugin_dir] [file dirname $file]]

			if { ![file isdirectory $dir] } {
				file mkdir $dir
				status_log "Auto-update ($plugin) : create dir $dir\n" red
			}

			set fid [open $filename w]
			fconfigure $fid -encoding binary
			puts -nonewline $fid "$content"
			close $fid
			::http::cleanup $token
			
		}
		
		return 1

	}


	###############################################################
	# UpdatePlugin (plugin)
	#
	# Update a plugin
	#
	# Arguments
	# The name of the plugin
	#
	# Return
	# none
	#
	proc UpdatePlugin { plugin } {
	
		variable plugins
		variable loadedplugins

		set error 0
		set mainstate 0
		set langstate 0
		set filestate 0

		# if no error occurs while updating the plugin, save the plugininfo.xml file		
		#if { [catch {

			if { [getInfo $plugin updated_main] == 1 } {
				set mainstate [DownloadMain $plugin]
			} else {
				set mainstate 1
			}

			if { [getInfo $plugin updated_lang] == 1 } {
				set langstate [DownloadLangs $plugin [getInfo $plugin updated_langs]]
			} else { 
				set langstate 1
			}

			if { [getInfo $plugin updated_file] == 1 } {
				set filestate [DownloadFiles $plugin [getInfo $plugin updated_files]]
			} else {
				set filestate 1
			}

		#	}] } {

		#	status_log "Error while updating $plugin\n" red
		#	set error 1

		#}

		if { $mainstate == 1 && $langstate == 1 && $filestate == 1 && $error == 0 } {

			SavePlugininfo $plugin
			
			# Reload the plugin if it was loaded
			if { [lsearch $loadedplugins $plugin] != -1 } {
				UnLoadPlugin $plugin
				LoadPlugin $plugin
			}
			
		} else {
			status_log "Error while updating $plugin : main $mainstate, lang $langstate, file $filestate, error $error\n" red
		}
		
	}


	###############################################################
	# UpdatedPlugins ()
	#
	# Look for updated files for every plugins
	#
	# Arguments
	# none
	#
	# Return
	# 1 if a plugin has been updated, 0 else
	#

	proc UpdatedPlugins { } {

		variable plugins

		set updatedplugins 0

		foreach plugin [getPlugins] {

			set updated 0
			set protected 0

			LoadInfoAutoupdate $plugin

			set path [getInfo $plugin plugin_dir]

			# If the file is protected
			if { ![file writable [file join $path plugininfo.xml]] } {
				continue
			}

			if { [LoadInfoAutoupdate_Online $plugin] == 0 } {
				continue
			}

			if { [getInfo $plugin amsn_version_online] == ""} {
				continue
			}

			# If the online plugin is not compatible with the current version of aMSN
			if { ![::plugins::CheckRequirements [getInfo $plugin amsn_version_online]] } {
				status_log "Can't update $plugin : required version [getInfo $plugin amsn_version_online]\n" red
				continue
			}

			# If the main file has been updated
			if { [DetectNew [getInfo $plugin cvs_version] [getInfo $plugin cvs_version_online]] } {

				set file [file join $path [getInfo $plugin plugin_file]]
				
				if { ![file writable $file] } {
					status_log "File $file is protected"
					set protected 1
				} else {
					set plugins(${plugin}_updated_main) 1
					set updated 1
				}
				
			} else {
				set plugins(${plugin}_updated_main) 0
			}
				

			# Check each language file

			set plugins(${plugin}_updated_langs) ""
			
			foreach lang_online [getInfo $plugin lang_online] {

				set langcode_online [lindex $lang_online 0]
				set version_online [lindex $lang_online 1]

				if { [::lang::LangExists $langcode_online] } {

					foreach lang [getInfo $plugin lang] {
						set langcode [lindex $lang 0]
						set version [lindex $lang 1]
						if { $langcode == $langcode_online } {
							break
						}
					}

					if { [::plugins::DetectNew $version $version_online] } {
					
						set file [file join $path "lang" lang$langcode]
						
						if { [file exists $file] && ![file writable $file] } {
							status_log "File $file is protected"
							set protected 1
						} else {
							lappend plugins(${plugin}_updated_langs) [list $langcode_online $version_online] 
							set plugins(${plugin}_updated_lang) 1
							set updated 1
						}
						
					}
				}
			}


			# Check each other file

			set plugins(${plugin}_updated_files) ""
			
			foreach file_online [getInfo $plugin file_online] {

				set pathfile_online [lindex $file_online 0]
				set version_online [lindex $file_online 1]

				foreach file [getInfo $plugin file] {
					set pathfile [lindex $file 0]
					set version [lindex $file 1]
					if { $pathfile == $pathfile_online } {
						break
					}
				}

				if { [::plugins::DetectNew $version $version_online] } {
					set file [file join $path $pathfile_online]
					if { [file exists $file] && ![file writable $file] } {
						status_log "File $file is protected"
						set protected 1
					} else {
						lappend plugins(${plugin}_updated_files) [list $pathfile_online $version_online]
						set plugins(${plugin}_updated_file) 1
						set updated 1
					}
				}
			}

			# If the plugin has been updated and no file is protected, add it to the updated plugin list
			if { $updated == 1 && $protected == 0 } {
				set plugins(${plugin}_updated) 1
				set updatedplugins 1
			} elseif { $updated == 1 } {
				set plugins(${plugin}_updated) 0	
				status_log "Can't update $plugin : files protected\n" red
			} else {
				set plugins(${plugin}_updated) 0
			}
			
		}

		return $updatedplugins

	}


	###############################################################
	# DetectNew (version onlineversion)
	#
	# Tell if the onlineversion is upper the version
	#
	# Arguments
	# The version and the onlineversion
	#
	# Return
	# 1 if onlineversion > version, 0 else
	#
	proc DetectNew { version onlineversion } {

		set current [split $version "."]
		set new [split $onlineversion "."]
		if { $version == "" || $onlineversion == ""} {
			return 0
		} elseif { [lindex $new 0] > [lindex $current 0] } {
			return 1
		} elseif { [lindex $new 0] == [lindex $current 0] && [lindex $new 1] > [lindex $current 1] } {
			return 1
		} else {
			return 0
		}

	}


	###############################################################
	# SavePlugininfo (plugin)
	#
	# Save the plugininfo.xml file of a plugin
	#
	# Arguments
	# The name of the plugin
	#
	# Return
	# none
	#
	proc SavePlugininfo { plugin } {

		global HOME2
		
		set file "[file join $HOME2 $plugin.xml]"
		set pathplugininfo [file join [getInfo $plugin plugin_dir] plugininfo.xml]

		if { [file exists $file] } {
			file copy -force $file $pathplugininfo
			file delete $file
		} else {
			status_log "Error while updating $plugin : can't find plugininfo.xml\n"
		}

	}



	###############################################################
	# getOnlinePluginsList ()
	#
	# Get the list of the plugins which are online
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	proc getOnlinePluginsList { } {

		global HOME2

		set token [::http::geturl "${::weburl}/autoupdater/pluginslist.xml" -timeout 120000 -binary 1]

		set status [::http::status $token]
		if { $status != "ok" } {
			::http::cleanup $token
			return 0
		}

		set content [::http::data $token]

		set filename [file join $HOME2 "pluginslist.xml"]
		set fid [open $filename w]
		fconfigure $fid -encoding binary
		puts -nonewline $fid "$content"
		close $fid
		::http::cleanup $token
	}


	###############################################################
	# OnlinePluginGui ()
	#
	# Display the plugins which are online
	#
	# Arguments
	# none
	#
	# Return
	# none
	#
	# NOT YET FINISHED
	#
	proc OnlinePluginGui { } {

		set w .onlinepluginlist

		if { [winfo exists $w] } {
			raise $w
			return
		}

		::plugins::getOnlinePluginsList

		toplevel $w
		wm title $w [trans getonlineplugins]
		wm geometry $w 500x400

	}


}