2003-01-05 05:51:17 +01:00
|
|
|
# Blinkenlights base classes
|
|
|
|
# Copyright (C) 2003 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2003-01-05 05:51:17 +01:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2003-01-05 12:50:01 +01:00
|
|
|
from threading import *
|
2003-01-05 13:01:17 +01:00
|
|
|
from offlineimap.ui.UIBase import UIBase
|
2003-01-05 12:50:01 +01:00
|
|
|
import thread
|
2003-01-06 22:58:29 +01:00
|
|
|
from offlineimap.threadutil import MultiLock
|
2003-01-05 12:50:01 +01:00
|
|
|
|
2003-01-05 05:51:17 +01:00
|
|
|
class BlinkenBase:
|
|
|
|
"""This is a mix-in class that should be mixed in with either UIBase
|
|
|
|
or another appropriate base class. The Tk interface, for instance,
|
|
|
|
will probably mix it in with VerboseUI."""
|
|
|
|
|
|
|
|
def acct(s, accountname):
|
|
|
|
s.gettf().setcolor('purple')
|
|
|
|
s.__class__.__bases__[-1].acct(s, accountname)
|
|
|
|
|
|
|
|
def connecting(s, hostname, port):
|
|
|
|
s.gettf().setcolor('gray')
|
|
|
|
s.__class__.__bases__[-1].connecting(s, hostname, port)
|
|
|
|
|
|
|
|
def syncfolders(s, srcrepos, destrepos):
|
|
|
|
s.gettf().setcolor('blue')
|
|
|
|
s.__class__.__bases__[-1].syncfolders(s, srcrepos, destrepos)
|
|
|
|
|
|
|
|
def syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder):
|
|
|
|
s.gettf().setcolor('cyan')
|
|
|
|
s.__class__.__bases__[-1].syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder)
|
|
|
|
|
|
|
|
def loadmessagelist(s, repos, folder):
|
|
|
|
s.gettf().setcolor('green')
|
|
|
|
s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
|
|
|
|
folder.getvisiblename()))
|
|
|
|
|
|
|
|
def syncingmessages(s, sr, sf, dr, df):
|
|
|
|
s.gettf().setcolor('blue')
|
|
|
|
s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
|
|
|
|
|
|
|
|
def copyingmessage(s, uid, src, destlist):
|
|
|
|
s.gettf().setcolor('orange')
|
|
|
|
s.__class__.__bases__[-1].copyingmessage(s, uid, src, destlist)
|
|
|
|
|
|
|
|
def deletingmessages(s, uidlist, destlist):
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
|
|
|
|
|
|
|
|
def deletingmessage(s, uid, destlist):
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
|
|
|
|
|
2003-01-09 03:16:07 +01:00
|
|
|
def addingflags(s, uidlist, flags, destlist):
|
2003-01-05 05:51:17 +01:00
|
|
|
s.gettf().setcolor('yellow')
|
2003-01-09 03:16:07 +01:00
|
|
|
s.__class__.__bases__[-1].addingflags(s, uidlist, flags, destlist)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2003-01-09 03:16:07 +01:00
|
|
|
def deletingflags(s, uidlist, flags, destlist):
|
2003-01-05 05:51:17 +01:00
|
|
|
s.gettf().setcolor('pink')
|
2003-01-09 03:16:07 +01:00
|
|
|
s.__class__.__bases__[-1].deletingflags(s, uidlist, flags, destlist)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2003-01-05 12:50:01 +01:00
|
|
|
def init_banner(s):
|
|
|
|
s.availablethreadframes = {}
|
|
|
|
s.threadframes = {}
|
2003-01-06 22:58:29 +01:00
|
|
|
s.tflock = MultiLock()
|
2003-01-05 12:50:01 +01:00
|
|
|
|
|
|
|
def threadExited(s, thread):
|
|
|
|
threadid = thread.threadid
|
|
|
|
accountname = s.getthreadaccount(thread)
|
|
|
|
s.tflock.acquire()
|
|
|
|
try:
|
|
|
|
if threadid in s.threadframes[accountname]:
|
|
|
|
tf = s.threadframes[accountname][threadid]
|
|
|
|
del s.threadframes[accountname][threadid]
|
|
|
|
s.availablethreadframes[accountname].append(tf)
|
|
|
|
tf.setthread(None)
|
|
|
|
finally:
|
|
|
|
s.tflock.release()
|
|
|
|
|
|
|
|
UIBase.threadExited(s, thread)
|
|
|
|
|
2003-01-06 22:58:29 +01:00
|
|
|
def gettf(s):
|
2003-01-05 12:50:01 +01:00
|
|
|
threadid = thread.get_ident()
|
|
|
|
accountname = s.getthreadaccount()
|
2003-01-06 12:07:16 +01:00
|
|
|
|
2003-01-06 22:58:29 +01:00
|
|
|
s.tflock.acquire()
|
2003-01-05 12:50:01 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
if not accountname in s.threadframes:
|
|
|
|
s.threadframes[accountname] = {}
|
|
|
|
|
|
|
|
if threadid in s.threadframes[accountname]:
|
|
|
|
return s.threadframes[accountname][threadid]
|
|
|
|
|
|
|
|
if not accountname in s.availablethreadframes:
|
|
|
|
s.availablethreadframes[accountname] = []
|
|
|
|
|
|
|
|
if len(s.availablethreadframes[accountname]):
|
|
|
|
tf = s.availablethreadframes[accountname].pop(0)
|
2003-01-06 22:58:29 +01:00
|
|
|
tf.setthread(currentThread())
|
2003-01-05 12:50:01 +01:00
|
|
|
else:
|
2003-01-06 22:58:29 +01:00
|
|
|
tf = s.getaccountframe().getnewthreadframe()
|
2003-01-05 12:50:01 +01:00
|
|
|
s.threadframes[accountname][threadid] = tf
|
|
|
|
return tf
|
|
|
|
finally:
|
2003-01-06 22:58:29 +01:00
|
|
|
s.tflock.release()
|
|
|
|
|
2003-01-07 00:04:40 +01:00
|
|
|
def sleep(s, sleepsecs):
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.getaccountframe().startsleep(sleepsecs)
|
|
|
|
UIBase.sleep(s, sleepsecs)
|
|
|
|
|
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
|
|
|
if remainingsecs and s.gettf().getcolor() == 'black':
|
|
|
|
s.gettf().setcolor('red')
|
|
|
|
else:
|
|
|
|
s.gettf().setcolor('black')
|
|
|
|
return s.getaccountframe().sleeping(sleepsecs, remainingsecs)
|
2003-01-05 05:51:17 +01:00
|
|
|
|
2003-01-07 00:04:40 +01:00
|
|
|
|