Skip to content
Browse files

Change the sytem tray icon according to user status if several icons …

…are present
  • Loading branch information...
1 parent b985705 commit 6fbce2093f3a381180706c831c88be015fb3b231 @philsmd philsmd committed Jul 19, 2011
Showing with 38 additions and 14 deletions.
  1. +2 −1 README.md
  2. +1 −1 install.sh
  3. +35 −12 plugin/vimchat.vim
View
3 README.md
@@ -10,7 +10,8 @@ Vimchat allows you to easily connect to jabber servers such as Google Talk. It i
Vimchat supports encryption via OTR (off the record).
-Vimchat can use a status icon in the system tray that will blink when you receive new messages. You simply need to put any icon you would like to use at ~/.vimchat/icon.gif.
+Vimchat can use status icons in the system tray which will blink when you receive new messages. You simply need to put any icon you would like to use at ~/.vimchat/icon[\_status].gif.
+The default icon is ~/.vimchat/icon.gif. To use a different icon for e.g. the away status put an icon at ~/.vimchat/icon\_away.gif
# Requirements
View
2 install.sh
@@ -12,7 +12,7 @@ cp syntax/vimchat.vim ~/.vim/syntax
mkdir -p ~/.vimchat
if [ $? != 0 ]; then echo "Could not create ~/.vimchat"; exit 1; fi
-if [ ! -f ~/.vimchat/icon.gif ]; then cp icon.gif ~/.vimchat/; fi
+if [ ! -f ~/.vimchat/icon.gif ]; then cp icon*.gif ~/.vimchat/; fi
if [ -f ~/.vimchat/config ]; then
cp config ~/.vimchat/config.example
View
47 plugin/vimchat.vim
@@ -177,13 +177,12 @@ class VimChatScope:
self.statusIcon = self.StatusIcon()
self.statusIcon.start()
self.blinktimeout = int(vim.eval('g:vimchat_blinktimeout'))
-
+ #}}}
def stop(self):
if self.statusIcon != None:
self.statusIcon.stop()
self.signOffAll()
#}}}
-
#CLASSES
#{{{ class OtrOps
class OtrOps:
@@ -389,6 +388,8 @@ class VimChatScope:
else:
pass
time.sleep(1)
+ #}}}
+ #{{{ stop
def stop(self):
self.online = 0
#}}}
@@ -747,29 +748,56 @@ class VimChatScope:
#}}}
#{{{ class StatusIcon
class StatusIcon(threading.Thread):
+ #{{{ __init__
+ def __init__(self):
+ self.status_icon_default = "~/.vimchat/icon.gif"
+ self.status_icon_path = self.status_icon_default
+ threading.Thread.__init__ ( self )
+ #}}}
+ #{{{ run
def run(self):
# GTK StausIcon
gtk.gdk.threads_init()
self.status_icon = StatusIcon()
- self.status_icon.set_from_file(os.path.expanduser('~/.vimchat/icon.gif'))
+ self.changeStatus()
self.status_icon.set_tooltip("VimChat")
self.status_icon.set_visible(True)
gtk.main()
+ #}}}
+ #{{{ blink
def blink(self, value):
self.status_icon.set_blinking(value)
-
+ #}}}
+ #{{{ changeStatus
+ def changeStatus(self,statusText=""):
+ if len(statusText)>0:
+ statusText = "_"+statusText
+ file_path = os.path.expanduser(re.sub("(\..[^.]*)$", statusText+"\\1", self.status_icon_default))
+ if not os.path.exists(file_path):
+ file_path = os.path.expanduser(self.status_icon_default)
+ if not os.path.exists(file_path):
+ return
+ self.status_icon_path = file_path
+ self.status_icon.set_from_file(self.status_icon_path)
+ #}}}
+ #{{{ stop
def stop(self):
self.status_icon.set_visible(False)
gtk.main_quit()
+ #}}}
#}}}
#{{{ class BlinkClearer
class BlinkClearer(threading.Thread):
+ #{{{ __init__
def __init__(self, tt):
self.timeoutTime = tt
threading.Thread.__init__ ( self )
+ #}}}
+ #{{{ run
def run(self):
time.sleep(self.timeoutTime)
VimChat.clearNotify()
+ #}}}
#}}}
#CONNECTION FUNCTIONS
#{{{ signOn
@@ -868,11 +896,8 @@ class VimChatScope:
accounts[account].stop()
del accounts[account]
print "%s was signed off of VimChat!" % (account)
-<<<<<<< HEAD
-=======
if self.growl_enabled:
self.growl_notifier.notify ("account status", "VimChat", "%s was signed off of VimChat!" %(account), self.growl_icon)
->>>>>>> upstream/master
except:
print "Error signing off %s VimChat!" % (account)
print sys.exc_info()[0:2]
@@ -1489,6 +1514,9 @@ You can type \on to reconnect.
for jid,account in self.accounts.items():
account.jabberPresenceUpdate(show,status,priority)
+ # update Icon if there are several icons available
+ if self.statusIcon != None:
+ self.statusIcon.changeStatus(show)
print "Updated status to: " + str(priority) + " -- " + show + " -- " + status
#}}}
@@ -1520,7 +1548,6 @@ You can type \on to reconnect.
print "Buffer did not exist for: " + fromJid
except Exception, e:
print "Error in presenceUpdate: " + str(e)
-
#}}}
#{{{ messageReceived
def messageReceived(self, account, fromJid, message, secure=False, groupChat=""):
@@ -1559,12 +1586,9 @@ You can type \on to reconnect.
self.notify(jid, message, groupChat)
except:
print 'Could not notify:', message, 'from:', jid
-<<<<<<< HEAD
-=======
if self.growl_enabled:
self.growl_notifier.notify ("msg txrx", "VimChat - %s" % (jid), message, self.growl_icon)
->>>>>>> upstream/master
#}}}
#{{{ notify
def notify(self, jid, msg, groupChat):
@@ -1686,7 +1710,6 @@ You can type \on to reconnect.
#}}}
#}}}
VimChat = VimChatScope()
-
EOF
"{{{ Vim Commands

0 comments on commit 6fbce20

Please sign in to comment.
Something went wrong with that request. Please try again.