~ubuntu-branches/ubuntu/saucy/amsn/saucy

« back to all changes in this revision

Viewing changes to plugins/Restore/restore.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-13 23:21:29 UTC
  • mfrom: (1.1.11 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100413232129-vgpx20brdd2qavs7
Tags: 0.98.3-0ubuntu1
* Merge from Debian unstable (LP: #449072), remaining Ubuntu changes:
  - add 08_use_aplay_for_sound.dpatch patch by Festor Wailon Dacoba to use
    aplay to play sounds
  + debian/control:
    - modify iceweasel to firefox | abrowser in amsn Suggests field
    - add xdg-utils and gstreamer0.10-nice to amsn Depends field
    - mofify sox to alsa-utils in amsn Suggests field as we are now using
      aplay
* New upstream release (LP: #562619), tarball repacked according to
  debian/README.source.
* Fix missing-debian-source-format lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
####################################################
 
2
#  This plugin makes aMSN remember any chats open  #
 
3
#  so after a crash, your chatwindows state will   #
 
4
#  be restored.                                    #
 
5
#   ===========================================    #
 
6
#  Karel Demeyer, 2008                             #
 
7
#  ============================================    #
 
8
####################################################
 
9
 
 
10
 
 
11
namespace eval ::restore {
 
12
 
 
13
##############################
 
14
# ::restore::InitPlugin dir   #
 
15
# ---------------------------#
 
16
# Load proc of restore Plugin #
 
17
##############################
 
18
 
 
19
        proc initPlugin { dir } {
 
20
                variable chatslist [list ]
 
21
                global HOME
 
22
                variable filename 
 
23
 
 
24
                set filename [file join $HOME storedchats]
 
25
 
 
26
 
 
27
                ::plugins::RegisterPlugin "Restore Chats"
 
28
                ::plugins::RegisterEvent "Restore Chats" new_conversation addChat
 
29
                ::plugins::RegisterEvent "Restore Chats" chatwindow_closed delChat
 
30
                ::plugins::RegisterEvent "Restore Chats" contactlistLoaded restoreChats
 
31
        }
 
32
 
 
33
 
 
34
 
 
35
        proc addChat { event evpar } {
 
36
                variable chatslist
 
37
 
 
38
                upvar 2 $evpar newvar
 
39
#               upvar 2 $newvar(chatid) chat
 
40
#somehow we can get the value like this without upvar'ing again .. I don't get it :| .. in chatwindow.tcl, the name of the var is passed/stored in the array, not the value.  When upvarring, the proc is not further evaluated
 
41
                set chat $newvar(chatid)
 
42
                set chatusers [::MSN::usersInChat $chat]
 
43
                if { $chatusers == "" } {
 
44
                        set chatusers $chat
 
45
                }
 
46
 
 
47
 
 
48
                #Don't support groupchats
 
49
                if { [llength $chatusers] != 1 || $chatusers == "chatid"} { 
 
50
                        return
 
51
                }
 
52
 
 
53
                lappend chatslist $chatusers
 
54
 
 
55
                updateOnDiskCopy
 
56
 
 
57
        }
 
58
 
 
59
 
 
60
        proc delChat { event evpar } {
 
61
                variable chatslist
 
62
 
 
63
                upvar 2 $evpar newvar
 
64
                upvar 2 $newvar(chatid) chat
 
65
                set chatusers [::MSN::usersInChat $chat]
 
66
                if { $chatusers == "" } {
 
67
                        set chatusers $chat
 
68
                }
 
69
 
 
70
 
 
71
 
 
72
                #Don't support groupchats
 
73
                if { [llength $chatusers] != 1 } { 
 
74
                        return
 
75
                }
 
76
 
 
77
                set userindex [lsearch $chatslist $chatusers]
 
78
                set chatslist [lreplace $chatslist $userindex $userindex]
 
79
 
 
80
                updateOnDiskCopy
 
81
 
 
82
        }
 
83
 
 
84
        proc updateOnDiskCopy { } {
 
85
                variable chatslist
 
86
                variable filename
 
87
 
 
88
                file delete $filename
 
89
 
 
90
                if { $chatslist == [list ] } {
 
91
                        return
 
92
                }
 
93
 
 
94
                set diskcopy [open $filename w+]
 
95
                puts $diskcopy $chatslist
 
96
                close $diskcopy
 
97
 
 
98
        }
 
99
        
 
100
        proc restoreChats { { event ""} { evpar ""} } {
 
101
                variable filename
 
102
#               variable chatslist
 
103
 
 
104
 
 
105
                if { [file exists $filename] } {
 
106
                        set diskcopy [open $filename r]
 
107
                        set chatslist [read -nonewline $diskcopy]
 
108
                        close $diskcopy
 
109
 
 
110
                        file delete $filename
 
111
                        foreach chat $chatslist {
 
112
                                ::amsn::chatUser $chat
 
113
                        }
 
114
 
 
115
                }
 
116
        }
 
117
}
 
118