Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ __Optional ~/.vimrc Variables:__
* let g:vimchat\_buddylistmaxwidth = max width of buddy list window, default ''
* let g:vimchat\_timestampformat = format of the message timestamp, default "[%H:%M]"
* let g:vimchat\_showPresenceNotification = notification if buddy changed status, comma-separated list of states, default ""
* let g:vimchat\_restoreSessionStatus = (0 or 1), default is 0

# Hacking

* Keep all lines to 80 characters wide or less
* All python code should follow pep8 guidelines
* All new features should update documentation in the README


# Contributors

* Philipp [philsmd](https://github.com/philsmd)
Expand Down
71 changes: 66 additions & 5 deletions plugin/vimchat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
" g:vimchat_timestampformat = format of the msg timestamp default "[%H:%M]"
" g:vimchat_showPresenceNotification =
" notify if buddy changed status default ""
" g:vimchat_restoreSessionStatus = (0 or 1) default is 0

python <<EOF
try:
Expand Down Expand Up @@ -110,6 +111,7 @@ class VimChatScope:
blinktimeout = -1
timeformat = "[%H:%M]"
oldShowList = {}
sessionStatusRestore = 0

def init(self):
global pynotify_enabled
Expand Down Expand Up @@ -160,6 +162,10 @@ class VimChatScope:
# Timestamp format
self.timeformat = vim.eval('g:vimchat_timestampformat')

# Set restore session variable
self.sessionStatusRestore = int(vim.eval(
'g:vimchat_restoreSessionStatus'))

# Signon to accounts listed in .vimrc
if vim.eval("exists('g:vimchat_accounts')") == '1':
vimChatAccounts = vim.eval('g:vimchat_accounts')
Expand Down Expand Up @@ -790,6 +796,34 @@ class VimChatScope:
time.sleep(self.timeoutTime)
VimChat.clearNotify()

def getLastStatus(self,account=None):
if not os.path.exists(self.configFilePath):
return # Config file does not exist
status=""
config = RawConfigParser();
config.read(self.configFilePath)
if config.has_section('last_status'):
for acc in config.options('last_status'):
if account == None or account == acc:
status = config.get('last_status', acc)
break
return status

def setLastStatus(self,account,show="",status="",priority=""):
if not os.path.exists(self.configFilePath):
return # Config file does not exist
if account == None:
return
status=show+","+status+","+priority
config = RawConfigParser();
config.read(self.configFilePath)
config.read(self.configFilePath)
if not config.has_section('last_status'):
config.add_section('last_status')
config.set('last_status', account, str(status))
# Does not preserve comments
with open(self.configFilePath,'wb') as configfile:
config.write(configfile)

def signOn(self):
accounts = self.getAccountsFromConfig()
Expand Down Expand Up @@ -844,9 +878,23 @@ class VimChatScope:
try:
self.accounts[accountJid].disconnect()
except: pass

self.accounts[accountJid] = self.JabberConnection(
self, jid, jabberClient, roster)
self.accounts[accountJid].start()

# Restore the status of the previous session
last_status = None
last_show = last_state = last_priority = ""
if self.sessionStatusRestore==1:
last_status = self.getLastStatus(jid)
if last_status:
[last_show,last_state,last_priority] = last_status.split(',')
if last_status:
self.accounts[accountJid].jabberPresenceUpdate(last_show,last_state,
last_priority)
else:
self.accounts[accountJid].jabberPresenceUpdate()
print "Connected with " + jid
if self.growl_enabled:
self.growl_notifier.notify("account status", "VimChat",
Expand All @@ -865,9 +913,10 @@ class VimChatScope:

def signOffAll(self):
accounts = self.accounts
if len(accounts) == 0:
size = len(accounts)
if size == 0:
return
size=len(accounts)
vim.command("normal \<ESC>")
while(size > 0):
account = accounts.keys()[0]
self._signOff(account)
Expand All @@ -881,6 +930,16 @@ class VimChatScope:
accounts = self.accounts
if account in accounts:
try:
# Save the status of this account to the config file
if self.sessionStatusRestore==1:
[show,status] = accounts[account].jabberGetPresence()
priority = accounts[account]._presence.getPriority()
if not show: show=''
if not status: status=''
if not priority: priority=''
self.setLastStatus(account, str(show), str(status),
str(priority))
# disconnect and stop
accounts[account].disconnect()
accounts[account].stop()
del accounts[account]
Expand All @@ -895,9 +954,8 @@ class VimChatScope:
else:
print 'Error: [%s] is an invalid account.' % (account)
if self.growl_enabled:
self.growl_notifier.notify("account status", "VimChat",
"Error signing off %s VimChat" %(account),
self.growl_icon)
self.growl_notifier.notify("account status", "VimChat",
"Error signing off %s VimChat" %(account), self.growl_icon)

def showStatus(self):
print self.accounts[self.accounts.keys()[0]].jabberGetPresence()
Expand Down Expand Up @@ -1727,6 +1785,9 @@ fu! VimChatCheckVars()
if !exists('g:vimchat_showPresenceNotification')
let g:vimchat_showPresenceNotification=""
endif
if !exists('g:vimchat_restoreSessionStatus')
let g:vimchat_restoreSessionStatus=0
endif

return 1
endfu
Expand Down