25
25
" g:vimchat_otr = (0 or 1) default is 0
26
26
" g:vimchat_logotr = (0 or 1) default is 1
27
27
" g:vimchat_statusicon = (0 or 1) default is 1
28
+ " g:vimchat_blinktimeout = timeout in seconds default is -1
29
+ " g:vimchat_buddylistmaxwidth = max width of buddy list window default ''
30
+ " g:vimchat_timestampformat = format of the message timestamp default "[%H:%M]"
28
31
29
32
30
33
python <<EOF
@@ -65,7 +68,6 @@ except:
65
68
pyotr_enabled = False
66
69
pyotr_logging = False
67
70
68
-
69
71
gtk_enabled = False
70
72
if ' DISPLAY' in os.environ :
71
73
try :
@@ -88,6 +90,8 @@ class VimChatScope:
88
90
rosterFile = ' /tmp/vimChatRoster'
89
91
statusIcon = None
90
92
lastMessageTime = 0
93
+ blinktimeout = -1
94
+ timeformat = " [%H:%M]"
91
95
92
96
#{{{ init
93
97
def init (self ):
@@ -126,13 +130,8 @@ class VimChatScope:
126
130
pyotr_enabled = False
127
131
pyotr_logging = False
128
132
129
- isStatusIcon = int (vim .eval (' g:vimchat_statusicon' ))
130
- if isStatusIcon != 1 :
131
- self .gtk_enabled = False
132
-
133
- if self .gtk_enabled:
134
- self .statusIcon = self .StatusIcon ()
135
- self .statusIcon.start ()
133
+ # Timestamp format
134
+ self .timeformat = vim .eval (' g:vimchat_timestampformat' )
136
135
137
136
# Signon to accounts listed in .vimrc
138
137
if vim .eval (" exists('g:vimchat_accounts')" ) == ' 1' :
@@ -149,6 +148,19 @@ class VimChatScope:
149
148
password = config.get (' accounts' , jid)
150
149
self ._signOn (jid, password)
151
150
151
+ if len (self .accounts) and self .statusIcon == None:
152
+ isStatusIcon = int (vim .eval (' g:vimchat_statusicon' ))
153
+ if isStatusIcon != 1 :
154
+ self .gtk_enabled = False
155
+ if self .gtk_enabled:
156
+ self .statusIcon = self .StatusIcon ()
157
+ self .statusIcon.start ()
158
+ self .blinktimeout = int (vim .eval (' g:vimchat_blinktimeout' ))
159
+
160
+ def stop (self ):
161
+ if self .statusIcon != None:
162
+ self .statusIcon.stop ()
163
+ self .signOffAll ()
152
164
#}}}
153
165
154
166
#CLASSES
@@ -277,7 +289,7 @@ class VimChatScope:
277
289
def still_secure (self , opdata= None, context= None, is_reply= 0 ):
278
290
# this is called when the OTR session was refreshed
279
291
# (ie. new session keys have been created)
280
- # is_reply will be 0 when we started we started that refresh,
292
+ # is_reply will be 0 when we started that refresh,
281
293
# 1 when the contact started it
282
294
try :
283
295
connection = VimChat.accounts[context.accountname]
@@ -317,7 +329,6 @@ class VimChatScope:
317
329
#}}}
318
330
#{{{ class JabberConnection
319
331
class JabberConnection (threading.Thread):
320
-
321
332
#{{{ class Variables
322
333
_roster = {}
323
334
_chats = {}
@@ -332,6 +343,7 @@ class VimChatScope:
332
343
self ._roster = roster
333
344
threading.Thread.__init__ ( self )
334
345
self .jabber = jabberClient
346
+ self .online = 0
335
347
self ._protocol = ' xmpp'
336
348
#}}}
337
349
#{{{ run
@@ -344,18 +356,20 @@ class VimChatScope:
344
356
RECV_BUF = 4096
345
357
self .xmppS = self .jabber.Connection._sock
346
358
socketlist = [self .xmppS]
347
- online = 1
359
+ self . online = 1
348
360
349
361
#set up otr
350
362
self .otrSetup ()
351
-
352
- while online:
363
+ while self .online:
353
364
(i , o , e ) = select.select (socketlist,[],[],1 )
354
365
for each in i :
355
366
if each == self .xmppS:
356
367
self .jabber.Process (1 )
357
368
else :
358
369
pass
370
+ time.sleep (1 )
371
+ def stop (self ):
372
+ self .online = 0
359
373
#}}}
360
374
361
375
#From Jabber Functions
@@ -716,21 +730,32 @@ class VimChatScope:
716
730
# GTK StausIcon
717
731
gtk.gdk.threads_init ()
718
732
self .status_icon = StatusIcon ()
719
- self .status_icon.set_from_file (os.path .expanduser (
720
- ' ~/.vimchat/icon.gif' ))
733
+ self .status_icon.set_from_file (os.path .expanduser (' ~/.vimchat/icon.gif' ))
721
734
self .status_icon.set_tooltip (" VimChat" )
722
735
self .status_icon.set_visible (True)
723
736
gtk.main ()
724
737
def blink (self , value):
725
738
self .status_icon.set_blinking (value)
726
- #}}}
727
739
740
+ def stop (self ):
741
+ self .status_icon.set_visible (False)
742
+ gtk.main_quit ()
743
+ #}}}
744
+ #{{{ class BlinkClearer
745
+ class BlinkClearer (threading.Thread):
746
+ def __init__ (self , tt):
747
+ self .timeoutTime = tt
748
+ threading.Thread.__init__ ( self )
749
+ def run (self ):
750
+ time.sleep (self .timeoutTime)
751
+ VimChat.clearNotify ()
752
+ #}}}
728
753
#CONNECTION FUNCTIONS
729
754
#{{{ signOn
730
755
def signOn (self ):
731
756
accounts = self .getAccountsFromConfig ()
732
757
if len (accounts) == 0 :
733
- print ' No acounts found in the vimchat config %s.' \
758
+ print ' No accounts found in the vimchat config %s.' \
734
759
% (self .configFilePath)
735
760
return
736
761
for account in accounts:
@@ -778,29 +803,44 @@ class VimChatScope:
778
803
self .accounts[accountJid] = self .JabberConnection (
779
804
self , jid, jabberClient, roster)
780
805
self .accounts[accountJid].start ()
781
-
782
806
print " Connected with " + jid
783
807
#}}}
784
808
#{{{ signOff
785
809
def signOff (self ):
786
810
accounts = self .accounts
787
811
if len (accounts) == 0 :
788
- print ' No acounts found'
812
+ print ' No accounts found'
789
813
return
790
814
for account in accounts:
791
815
print account
792
816
account = vim .eval (
793
817
' input("Enter the account from the above list: ")' )
794
818
self ._signOff (account)
795
819
#}}}
820
+ #{{{ signOffAll
821
+ def signOffAll (self ):
822
+ accounts = self .accounts
823
+ if len (accounts) == 0 :
824
+ return
825
+ size= len (accounts)
826
+ while (size > 0 ):
827
+ account = accounts.keys ()[0 ]
828
+ self ._signOff (account)
829
+ if len (accounts) >= size:
830
+ print " Error while signing off"
831
+ break
832
+ else :
833
+ size= len (accounts)
834
+ #}}}
796
835
#{{{ _signOff
797
836
def _signOff (self , account):
798
837
accounts = self .accounts
799
838
if account in accounts:
800
839
try :
801
840
accounts[account].disconnect ()
841
+ accounts[account].stop ()
802
842
del accounts[account]
803
- print " Signed Off VimChat!"
843
+ print " %s was signed off of VimChat!" % (account)
804
844
except:
805
845
print " Error signing off %s VimChat!" % (account)
806
846
print sys.exc_info ()[0 :2 ]
@@ -837,7 +877,7 @@ class VimChatScope:
837
877
#}}}
838
878
#{{{ getTimestamp
839
879
def getTimestamp (self ):
840
- return time.strftime (" [%H:%M] " )
880
+ return time.strftime (self .timeformat )
841
881
#}}}
842
882
#{{{ getBufByName
843
883
def getBufByName (self , name):
@@ -892,7 +932,6 @@ class VimChatScope:
892
932
print e
893
933
vim .command (" new " + self .rosterFile)
894
934
895
-
896
935
commands = " " "
897
936
setlocal foldtext = VimChatFoldText ()
898
937
setlocal nowrap
@@ -901,11 +940,13 @@ class VimChatScope:
901
940
nnoremap <buffer> <silent> <Leader> l :py VimChat.openLogFromBuddyList()<CR>
902
941
nnoremap <buffer> <silent> B :py VimChat.toggleBuddyList()<CR>
903
942
nnoremap <buffer> <silent> q :py VimChat.toggleBuddyList()<CR>
943
+ nnoremap <buffer> <silent> r :py VimChat.refreshBuddyList()<CR>
944
+ nnoremap <buffer> <silent> R :py VimChat.refreshBuddyList()<CR>
945
+ nnoremap <buffer> <silent> <Leader> n /{{{ (<CR>
904
946
nnoremap <buffer> <silent> <Leader> c :py VimChat.openGroupChat()<CR>
905
947
nnoremap <buffer> <silent> <Leader> ss :py VimChat.setStatus()<CR>
906
- nnoremap <buffer> <silent> <Space> :silent exec 'vertical resize ' . (winwidth('.') > g:vimchat_buddylistwidth ? (g:vimchat_buddylistwidth) : '' )<CR>
948
+ nnoremap <buffer> <silent> <Space> :silent exec 'vertical resize ' . (winwidth('.') > g:vimchat_buddylistwidth ? (g:vimchat_buddylistwidth) : (g:vimchat_buddylistmaxwidth) )<CR>
907
949
" ""
908
-
909
950
vim .command (commands)
910
951
self .setupLeaderMappings ()
911
952
@@ -926,7 +967,6 @@ class VimChatScope:
926
967
vim .command (" normal [z" )
927
968
928
969
account = str (vim .current.line ).split (' ' )[2 ]
929
-
930
970
return account, toJid
931
971
#}}}
932
972
#{{{ beginChatFromBuddyList
@@ -939,11 +979,15 @@ class VimChatScope:
939
979
#print " Error getting buddy info: " + jid
940
980
return 0
941
981
942
-
943
982
vim .command (' sbuffer ' + str (buf .number ))
944
983
VimChat.toggleBuddyList ()
945
984
vim .command (' wincmd K' )
946
985
#}}}
986
+ #{{{ refreshBuddyList
987
+ def refreshBuddyList (self ):
988
+ self .writeBuddyList ()
989
+ vim .command (" silent e!" )
990
+ #}}}
947
991
#{{{ writeBuddyList
948
992
def writeBuddyList (self ):
949
993
#write roster to file
@@ -1001,7 +1045,6 @@ You can type \on to reconnect.
1001
1045
#CHAT BUFFERS
1002
1046
#{{{ beginChat
1003
1047
def beginChat (self , fromAccount, toJid, groupChat = False):
1004
- #return 0
1005
1048
#Set the ChatFile
1006
1049
connection = self .accounts[fromAccount]
1007
1050
if toJid in connection._chats.keys ():
@@ -1013,7 +1056,6 @@ You can type \on to reconnect.
1013
1056
chatFile = ' chat:' + toJid
1014
1057
1015
1058
connection._chats[toJid] = chatFile
1016
-
1017
1059
bExists = int (vim .eval (' buflisted("' + chatFile + ' ")' ))
1018
1060
if bExists:
1019
1061
#TODO : Need to call sbuffer only if buffer is hidden .
@@ -1031,7 +1073,6 @@ You can type \on to reconnect.
1031
1073
vim .command (" let b:account = '" + fromAccount + " '" )
1032
1074
self .setupChatBuffer (groupChat);
1033
1075
return vim .current.buffer
1034
-
1035
1076
#}}}
1036
1077
#{{{ setupChatBuffer
1037
1078
def setupChatBuffer (self , isGroupChat= False):
@@ -1124,10 +1165,10 @@ You can type \on to reconnect.
1124
1165
1125
1166
#Get the first line
1126
1167
if resource:
1127
- line = tstamp + secureString + \
1168
+ line = tstamp + " " + secureString + \
1128
1169
user + " /" + resource + " : " + lines .pop (0 );
1129
1170
else :
1130
- line = tstamp + secureString + user + " : " + lines .pop (0 );
1171
+ line = tstamp + " " + secureString + user + " : " + lines .pop (0 );
1131
1172
1132
1173
buf .append (line )
1133
1174
#TODO : remove these lines
@@ -1483,16 +1524,12 @@ You can type \on to reconnect.
1483
1524
try :
1484
1525
self .notify (jid, message, groupChat)
1485
1526
except:
1486
- print ' Error zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
1487
- print ' could not notify:' , message, ' from:' , jid
1527
+ print ' Could not notify:' , message, ' from:' , jid
1488
1528
#}}}
1489
1529
#{{{ notify
1490
1530
def notify (self , jid, msg, groupChat):
1491
- # Important to keep this echo statement . As a side effect, it
1492
- # refreshes the buffer so the new message shows up . Need to find
1493
- # a better solution though.
1494
- vim .command (" echo 'Message Received from: " + jid.replace (" '" , " ''" )
1495
- + " '" )
1531
+ # refreshes the buffer so the new message shows up
1532
+ vim .command (" echo " );
1496
1533
1497
1534
if groupChat:
1498
1535
msgLowered = msg.lower ()
@@ -1519,6 +1556,9 @@ You can type \on to reconnect.
1519
1556
1520
1557
if self .gtk_enabled:
1521
1558
self .statusIcon.blink (True)
1559
+ if self .blinktimeout != -1 :
1560
+ thr1 = self .BlinkClearer (self .blinktimeout)
1561
+ thr1.start ()
1522
1562
#}}}
1523
1563
#{{{ clearNotify
1524
1564
def clearNotify (self ):
@@ -1616,6 +1656,7 @@ endif
1616
1656
let g: vimchat_loaded = 1
1617
1657
1618
1658
com ! VimChat py VimChat.init ()
1659
+ com ! VimChatStop py VimChat.stop ()
1619
1660
com ! VimChatBuddyList py VimChat.toggleBuddyList ()
1620
1661
com ! VimChatViewLog py VimChat.openLogFromChat ()
1621
1662
com ! VimChatJoinGroupChat py VimChat.openGroupChat ()
@@ -1625,6 +1666,7 @@ com! VimChatOtrGenerateKey py VimChat.otrGenerateKey()
1625
1666
com ! -nargs =0 VimChatSetStatus py VimChat.setStatus (<args> )
1626
1667
com ! VimChatShowStatus py VimChat.showStatus ()
1627
1668
com ! VimChatJoinChatroom py VimChat.joinChatroom ()
1669
+ autocmd ! VIMLeave * :VimChatStop
1628
1670
1629
1671
set switchbuf = usetab
1630
1672
@@ -1634,6 +1676,9 @@ fu! VimChatCheckVars()
1634
1676
if ! exists (' g:vimchat_buddylistwidth' )
1635
1677
let g: vimchat_buddylistwidth= 30
1636
1678
endif
1679
+ if ! exists (' g:vimchat_buddylistmaxwidth' )
1680
+ let g: vimchat_buddylistmaxwidth= ' '
1681
+ endif
1637
1682
if ! exists (' g:vimchat_libnotify' )
1638
1683
let g: vimchat_libnotify= 1
1639
1684
endif
@@ -1652,6 +1697,12 @@ fu! VimChatCheckVars()
1652
1697
if ! exists (' g:vimchat_statusicon' )
1653
1698
let g: vimchat_statusicon= 1
1654
1699
endif
1700
+ if ! exists (' g:vimchat_blinktimeout' )
1701
+ let g: vimchat_blinktimeout= -1
1702
+ endif
1703
+ if ! exists (' g:vimchat_timestampformat' )
1704
+ let g: vimchat_timestampformat= " [%H:%M]"
1705
+ endif
1655
1706
1656
1707
return 1
1657
1708
endfu
0 commit comments