Use Enum or IntEnum instead of range() constants.

This commit is contained in:
Emmanuel Gil Peyrot 2017-02-07 20:18:41 +00:00
parent b6b1a7a074
commit 2fbadc91e9
17 changed files with 580 additions and 570 deletions

View File

@ -23,6 +23,8 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
from enum import IntEnum
from gi.repository import Gtk
import gtkgui_helpers
from gi.repository import GLib
@ -30,11 +32,10 @@ from gi.repository import Pango
from common import gajim
(
C_PREFNAME,
C_VALUE,
C_TYPE
) = range(3)
class Column(IntEnum):
PREFERENCE_NAME = 0
VALUE = 1
TYPE = 2
def rate_limit(rate):
"""
@ -135,8 +136,8 @@ class AdvancedConfigurationWindow(object):
Check if it's boolen or holds password stuff and if yes make the
cellrenderertext not editable, else - it's editable
"""
optname = model[iter_][C_PREFNAME]
opttype = model[iter_][C_TYPE]
optname = model[iter_][Column.PREFERENCE_NAME]
opttype = model[iter_][Column.TYPE]
if opttype == self.types['boolean'] or optname == 'password':
cell.set_property('editable', False)
else:
@ -263,8 +264,8 @@ class AdvancedConfigurationWindow(object):
elif len(opt_path) == 3:
default = gajim.config.get_default_per(opt_path[2], opt_path[0])
if model[iter_][C_TYPE] == self.types['boolean']:
if self.right_true_dict[default] == model[iter_][C_VALUE]:
if model[iter_][Column.TYPE] == self.types['boolean']:
if self.right_true_dict[default] == model[iter_][Column.VALUE]:
return
modelpath = self.modelfilter.convert_path_to_child_path(path)
modelrow = self.model[modelpath]
@ -275,15 +276,15 @@ class AdvancedConfigurationWindow(object):
keyrow = self.model[modelpath[:2]]
key = keyrow[0]
self.remember_option(option + '\n' + key + '\n' + optname,
modelrow[C_VALUE], default)
modelrow[Column.VALUE], default)
gajim.config.set_per(optname, key, option, default)
else:
self.remember_option(option, modelrow[C_VALUE], default)
self.remember_option(option, modelrow[Column.VALUE], default)
gajim.config.set(option, default)
modelrow[C_VALUE] = self.right_true_dict[default]
modelrow[Column.VALUE] = self.right_true_dict[default]
self.check_for_restart()
else:
if str(default) == model[iter_][C_VALUE]:
if str(default) == model[iter_][Column.VALUE]:
return
self.on_config_edited(None, path.to_string(), str(default))
@ -317,14 +318,14 @@ class AdvancedConfigurationWindow(object):
def visible_func(self, model, treeiter, data):
search_string = self.entry.get_text().lower()
for it in tree_model_pre_order(model, treeiter):
if model[it][C_TYPE] != '':
if model[it][Column.TYPE] != '':
opt_path = self.get_option_path(model, it)
if len(opt_path) == 3:
desc = gajim.config.get_desc_per(opt_path[2], opt_path[1],
opt_path[0])
elif len(opt_path) == 1:
desc = gajim.config.get_desc(opt_path[0])
if search_string in model[it][C_PREFNAME] or (desc and \
if search_string in model[it][Column.PREFERENCE_NAME] or (desc and \
search_string in desc.lower()):
return True
return False

View File

@ -46,7 +46,7 @@ from common import ged
from common import i18n
from common.stanza_session import EncryptedStanzaSession, ArchivingStanzaSession
from common.contacts import GC_Contact
from common.logger import constants
from common.logger import KindConstant
from nbxmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC
from nbxmpp.protocol import NS_RECEIPTS, NS_ESESSION
from nbxmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO
@ -1679,15 +1679,15 @@ class ChatControl(ChatControlBase):
additional_data = row[4]
if not msg: # message is empty, we don't print it
continue
if row[1] in (constants.KIND_CHAT_MSG_SENT,
constants.KIND_SINGLE_MSG_SENT):
if row[1] in (KindConstant.CHAT_MSG_SENT,
KindConstant.SINGLE_MSG_SENT):
kind = 'outgoing'
name = self.get_our_nick()
elif row[1] in (constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV):
elif row[1] in (KindConstant.SINGLE_MSG_RECV,
KindConstant.CHAT_MSG_RECV):
kind = 'incoming'
name = self.contact.get_shown_name()
elif row[1] == constants.KIND_ERROR:
elif row[1] == KindConstant.ERROR:
kind = 'status'
name = self.contact.get_shown_name()

View File

@ -35,15 +35,15 @@
import re
from common import defs
from gi.repository import GLib
from enum import IntEnum
(
OPT_TYPE,
OPT_VAL,
OPT_DESC,
# If OPT_RESTART is True - we need restart to use our changed option
# OPT_DESC also should be there
OPT_RESTART,
) = range(4)
class Option(IntEnum):
TYPE = 0
VAL = 1
DESC = 2
# If Option.RESTART is True - we need restart to use our changed option
# Option.DESC also should be there
RESTART = 3
opt_int = [ 'integer', 0 ]
opt_str = [ 'string', 0 ]
@ -633,7 +633,7 @@ class Config:
def set(self, optname, value):
if optname not in self.__options[1]:
return
value = self.is_valid(self.__options[0][optname][OPT_TYPE], value)
value = self.is_valid(self.__options[0][optname][Option.TYPE], value)
if value is None:
return
@ -650,24 +650,24 @@ class Config:
def get_default(self, optname):
if optname not in self.__options[0]:
return None
return self.__options[0][optname][OPT_VAL]
return self.__options[0][optname][Option.VAL]
def get_type(self, optname):
if optname not in self.__options[0]:
return None
return self.__options[0][optname][OPT_TYPE][0]
return self.__options[0][optname][Option.TYPE][0]
def get_desc(self, optname):
if optname not in self.__options[0]:
return None
if len(self.__options[0][optname]) > OPT_DESC:
return self.__options[0][optname][OPT_DESC]
if len(self.__options[0][optname]) > Option.DESC:
return self.__options[0][optname][Option.DESC]
def get_restart(self, optname):
if optname not in self.__options[0]:
return None
if len(self.__options[0][optname]) > OPT_RESTART:
return self.__options[0][optname][OPT_RESTART]
if len(self.__options[0][optname]) > Option.RESTART:
return self.__options[0][optname][Option.RESTART]
def add_per(self, typename, name): # per_group_of_option
if typename not in self.__options_per_key:
@ -679,7 +679,7 @@ class Config:
return 'you already have added %s before' % name
opt[1][name] = {}
for o in opt[0]:
opt[1][name][o] = opt[0][o][OPT_VAL]
opt[1][name][o] = opt[0][o][Option.VAL]
self._timeout_save()
def del_per(self, typename, name, subname = None): # per_group_of_option
@ -705,7 +705,7 @@ class Config:
obj = dict_[key]
if subname not in obj:
return
typ = self.__options_per_key[optname][0][subname][OPT_TYPE]
typ = self.__options_per_key[optname][0][subname][Option.TYPE]
value = self.is_valid(typ, value)
if value is None:
return
@ -735,7 +735,7 @@ class Config:
dict_ = self.__options_per_key[optname][0]
if subname not in dict_:
return None
return dict_[subname][OPT_VAL]
return dict_[subname][Option.VAL]
def get_type_per(self, optname, subname):
if optname not in self.__options_per_key:
@ -743,7 +743,7 @@ class Config:
dict_ = self.__options_per_key[optname][0]
if subname not in dict_:
return None
return dict_[subname][OPT_TYPE][0]
return dict_[subname][Option.TYPE][0]
def get_desc_per(self, optname, key=None, subname=None):
if optname not in self.__options_per_key:
@ -758,8 +758,8 @@ class Config:
return None
if subname not in obj:
return None
if len(obj[subname]) > OPT_DESC:
return obj[subname][OPT_DESC]
if len(obj[subname]) > Option.DESC:
return obj[subname][Option.DESC]
return None
def get_restart_per(self, optname, key=None, subname=None):
@ -775,8 +775,8 @@ class Config:
return False
if subname not in obj:
return False
if len(obj[subname]) > OPT_RESTART:
return obj[subname][OPT_RESTART]
if len(obj[subname]) > Option.RESTART:
return obj[subname][Option.RESTART]
return False
def should_log(self, account, jid):
@ -794,7 +794,7 @@ class Config:
def _init_options(self):
for opt in self.__options[0]:
self.__options[1][opt] = self.__options[0][opt][OPT_VAL]
self.__options[1][opt] = self.__options[0][opt][Option.VAL]
def _really_save(self):
from common import gajim

View File

@ -26,12 +26,12 @@ import os
import sys
import tempfile
from common import defs
from enum import Enum
(
TYPE_CONFIG,
TYPE_CACHE,
TYPE_DATA
) = range(3)
class Type(Enum):
CONFIG = 0
CACHE = 1
DATA = 2
# Note on path and filename encodings:
#
@ -65,7 +65,7 @@ def get(key):
class ConfigPaths:
def __init__(self):
# {'name': (type, path), } type can be TYPE_CONFIG, TYPE_CACHE, TYPE_DATA
# {'name': (type, path), } type can be Type.CONFIG, Type.CACHE, Type.DATA
# or None
self.paths = {}
@ -109,11 +109,11 @@ class ConfigPaths:
def __getitem__(self, key):
type_, path = self.paths[key]
if type_ == TYPE_CONFIG:
if type_ == Type.CONFIG:
return os.path.join(self.config_root, path)
elif type_ == TYPE_CACHE:
elif type_ == Type.CACHE:
return os.path.join(self.cache_root, path)
elif type_ == TYPE_DATA:
elif type_ == Type.DATA:
return os.path.join(self.data_root, path)
return path
@ -145,26 +145,26 @@ class ConfigPaths:
'RNG_SEED': 'rng_seed'}
for name in d:
d[name] += profile
self.add(name, TYPE_DATA, windowsify(d[name]))
self.add(name, Type.DATA, windowsify(d[name]))
if len(profile):
self.add('MY_DATA', TYPE_DATA, 'data.dir')
self.add('MY_DATA', Type.DATA, 'data.dir')
else:
self.add('MY_DATA', TYPE_DATA, '')
self.add('MY_DATA', Type.DATA, '')
d = {'CACHE_DB': 'cache.db', 'VCARD': 'vcards',
'AVATAR': 'avatars'}
for name in d:
d[name] += profile
self.add(name, TYPE_CACHE, windowsify(d[name]))
self.add(name, Type.CACHE, windowsify(d[name]))
if len(profile):
self.add('MY_CACHE', TYPE_CACHE, 'cache.dir')
self.add('MY_CACHE', Type.CACHE, 'cache.dir')
else:
self.add('MY_CACHE', TYPE_CACHE, '')
self.add('MY_CACHE', Type.CACHE, '')
if len(profile):
self.add('MY_CONFIG', TYPE_CONFIG, 'config.dir')
self.add('MY_CONFIG', Type.CONFIG, 'config.dir')
else:
self.add('MY_CONFIG', TYPE_CONFIG, '')
self.add('MY_CONFIG', Type.CONFIG, '')
try:
self.add('TMP', None, tempfile.gettempdir())
@ -187,10 +187,10 @@ class ConfigPaths:
certsdir += u'.' + profile
localcertsdir += u'.' + profile
self.add('SECRETS_FILE', TYPE_DATA, secretsfile)
self.add('MY_PEER_CERTS', TYPE_DATA, certsdir)
self.add('CONFIG_FILE', TYPE_CONFIG, conffile)
self.add('PLUGINS_CONFIG_DIR', TYPE_CONFIG, pluginsconfdir)
self.add('MY_CERT', TYPE_CONFIG, localcertsdir)
self.add('SECRETS_FILE', Type.DATA, secretsfile)
self.add('MY_PEER_CERTS', Type.DATA, certsdir)
self.add('CONFIG_FILE', Type.CONFIG, conffile)
self.add('PLUGINS_CONFIG_DIR', Type.CONFIG, pluginsconfdir)
self.add('MY_CERT', Type.CONFIG, localcertsdir)
gajimpaths = ConfigPaths()

View File

@ -35,6 +35,7 @@ import nbxmpp
from common import dataforms
from common import exceptions
from common.zeroconf import zeroconf
from common.zeroconf.zeroconf import Constant
from common.logger import LOG_DB_PATH
from common.pep import SUPPORTED_PERSONAL_USER_EVENTS
from nbxmpp.protocol import NS_CHATSTATES
@ -1328,7 +1329,7 @@ class ZeroconfMessageReceivedEvent(MessageReceivedEvent):
if self.fjid is None:
for key in self.conn.connection.zeroconf.contacts:
if self.ip == self.conn.connection.zeroconf.contacts[key][
zeroconf.C_ADDRESS]:
Constant.ADDRESS]:
self.fjid = key
break

View File

@ -21,6 +21,7 @@ import nbxmpp
import socket
from common import gajim
import logging
from enum import IntEnum
log = logging.getLogger('gajim.c.jingle_transport')
@ -33,7 +34,7 @@ def get_jingle_transport(node):
return transports[namespace](node)
class TransportType(object):
class TransportType(IntEnum):
"""
Possible types of a JingleTransport
"""

View File

@ -36,6 +36,7 @@ import json
from gzip import GzipFile
from io import BytesIO
from gi.repository import GLib
from enum import IntEnum
from common import exceptions
from common import gajim
@ -50,59 +51,50 @@ CACHE_DB_PATH = gajim.gajimpaths['CACHE_DB']
import logging
log = logging.getLogger('gajim.c.logger')
class Constants:
def __init__(self):
(
self.JID_NORMAL_TYPE,
self.JID_ROOM_TYPE
) = range(2)
class JIDConstant(IntEnum):
NORMAL_TYPE = 0
ROOM_TYPE = 1
(
self.KIND_STATUS,
self.KIND_GCSTATUS,
self.KIND_GC_MSG,
self.KIND_SINGLE_MSG_RECV,
self.KIND_CHAT_MSG_RECV,
self.KIND_SINGLE_MSG_SENT,
self.KIND_CHAT_MSG_SENT,
self.KIND_ERROR
) = range(8)
class KindConstant(IntEnum):
STATUS = 0
GCSTATUS = 1
GC_MSG = 2
SINGLE_MSG_RECV = 3
CHAT_MSG_RECV = 4
SINGLE_MSG_SENT = 5
CHAT_MSG_SENT = 6
ERROR = 7
(
self.SHOW_ONLINE,
self.SHOW_CHAT,
self.SHOW_AWAY,
self.SHOW_XA,
self.SHOW_DND,
self.SHOW_OFFLINE
) = range(6)
class ShowConstant(IntEnum):
ONLINE = 0
CHAT = 1
AWAY = 2
XA = 3
DND = 4
OFFLINE = 5
(
self.TYPE_AIM,
self.TYPE_GG,
self.TYPE_HTTP_WS,
self.TYPE_ICQ,
self.TYPE_MSN,
self.TYPE_QQ,
self.TYPE_SMS,
self.TYPE_SMTP,
self.TYPE_TLEN,
self.TYPE_YAHOO,
self.TYPE_NEWMAIL,
self.TYPE_RSS,
self.TYPE_WEATHER,
self.TYPE_MRIM,
self.TYPE_NO_TRANSPORT,
) = range(15)
class TypeConstant(IntEnum):
AIM = 0
GG = 1
HTTP_WS = 2
ICQ = 3
MSN = 4
QQ = 5
SMS = 6
SMTP = 7
TLEN = 8
YAHOO = 9
NEWMAIL = 10
RSS = 11
WEATHER = 12
MRIM = 13
NO_TRANSPORT = 14
(
self.SUBSCRIPTION_NONE,
self.SUBSCRIPTION_TO,
self.SUBSCRIPTION_FROM,
self.SUBSCRIPTION_BOTH,
) = range(4)
constants = Constants()
class SubscriptionConstant(IntEnum):
NONE = 0
TO = 1
FROM = 2
BOTH = 3
class Logger:
def __init__(self):
@ -231,7 +223,7 @@ class Logger:
if row is None:
return None
else:
if row[0] == constants.JID_ROOM_TYPE:
if row[0] == JIDConstant.ROOM_TYPE:
return True
return False
@ -255,9 +247,9 @@ class Logger:
return row[0]
# oh! a new jid :), we add it now
if typestr == 'ROOM':
typ = constants.JID_ROOM_TYPE
typ = JIDConstant.ROOM_TYPE
else:
typ = constants.JID_NORMAL_TYPE
typ = JIDConstant.NORMAL_TYPE
try:
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
typ))
@ -277,34 +269,34 @@ class Logger:
Convert from string style to constant ints for db
"""
if kind == 'status':
kind_col = constants.KIND_STATUS
kind_col = KindConstant.STATUS
elif kind == 'gcstatus':
kind_col = constants.KIND_GCSTATUS
kind_col = KindConstant.GCSTATUS
elif kind == 'gc_msg':
kind_col = constants.KIND_GC_MSG
kind_col = KindConstant.GC_MSG
elif kind == 'single_msg_recv':
kind_col = constants.KIND_SINGLE_MSG_RECV
kind_col = KindConstant.SINGLE_MSG_RECV
elif kind == 'single_msg_sent':
kind_col = constants.KIND_SINGLE_MSG_SENT
kind_col = KindConstant.SINGLE_MSG_SENT
elif kind == 'chat_msg_recv':
kind_col = constants.KIND_CHAT_MSG_RECV
kind_col = KindConstant.CHAT_MSG_RECV
elif kind == 'chat_msg_sent':
kind_col = constants.KIND_CHAT_MSG_SENT
kind_col = KindConstant.CHAT_MSG_SENT
elif kind == 'error':
kind_col = constants.KIND_ERROR
kind_col = KindConstant.ERROR
if show == 'online':
show_col = constants.SHOW_ONLINE
show_col = ShowConstant.ONLINE
elif show == 'chat':
show_col = constants.SHOW_CHAT
show_col = ShowConstant.CHAT
elif show == 'away':
show_col = constants.SHOW_AWAY
show_col = ShowConstant.AWAY
elif show == 'xa':
show_col = constants.SHOW_XA
show_col = ShowConstant.XA
elif show == 'dnd':
show_col = constants.SHOW_DND
show_col = ShowConstant.DND
elif show == 'offline':
show_col = constants.SHOW_OFFLINE
show_col = ShowConstant.OFFLINE
elif show is None:
show_col = None
else: # invisible in GC when someone goes invisible
@ -318,70 +310,70 @@ class Logger:
Convert from string style to constant ints for db
"""
if type_ == 'aim':
return constants.TYPE_AIM
return TypeConstant.AIM
if type_ == 'gadu-gadu':
return constants.TYPE_GG
return TypeConstant.GG
if type_ == 'http-ws':
return constants.TYPE_HTTP_WS
return TypeConstant.HTTP_WS
if type_ == 'icq':
return constants.TYPE_ICQ
return TypeConstant.ICQ
if type_ == 'msn':
return constants.TYPE_MSN
return TypeConstant.MSN
if type_ == 'qq':
return constants.TYPE_QQ
return TypeConstant.QQ
if type_ == 'sms':
return constants.TYPE_SMS
return TypeConstant.SMS
if type_ == 'smtp':
return constants.TYPE_SMTP
return TypeConstant.SMTP
if type_ in ('tlen', 'x-tlen'):
return constants.TYPE_TLEN
return TypeConstant.TLEN
if type_ == 'yahoo':
return constants.TYPE_YAHOO
return TypeConstant.YAHOO
if type_ == 'newmail':
return constants.TYPE_NEWMAIL
return TypeConstant.NEWMAIL
if type_ == 'rss':
return constants.TYPE_RSS
return TypeConstant.RSS
if type_ == 'weather':
return constants.TYPE_WEATHER
return TypeConstant.WEATHER
if type_ == 'mrim':
return constants.TYPE_MRIM
return TypeConstant.MRIM
if type_ == 'jabber':
return constants.TYPE_NO_TRANSPORT
return TypeConstant.NO_TRANSPORT
return None
def convert_api_values_to_human_transport_type(self, type_id):
"""
Convert from constant ints for db to string style
"""
if type_id == constants.TYPE_AIM:
if type_id == TypeConstant.AIM:
return 'aim'
if type_id == constants.TYPE_GG:
if type_id == TypeConstant.GG:
return 'gadu-gadu'
if type_id == constants.TYPE_HTTP_WS:
if type_id == TypeConstant.HTTP_WS:
return 'http-ws'
if type_id == constants.TYPE_ICQ:
if type_id == TypeConstant.ICQ:
return 'icq'
if type_id == constants.TYPE_MSN:
if type_id == TypeConstant.MSN:
return 'msn'
if type_id == constants.TYPE_QQ:
if type_id == TypeConstant.QQ:
return 'qq'
if type_id == constants.TYPE_SMS:
if type_id == TypeConstant.SMS:
return 'sms'
if type_id == constants.TYPE_SMTP:
if type_id == TypeConstant.SMTP:
return 'smtp'
if type_id == constants.TYPE_TLEN:
if type_id == TypeConstant.TLEN:
return 'tlen'
if type_id == constants.TYPE_YAHOO:
if type_id == TypeConstant.YAHOO:
return 'yahoo'
if type_id == constants.TYPE_NEWMAIL:
if type_id == TypeConstant.NEWMAIL:
return 'newmail'
if type_id == constants.TYPE_RSS:
if type_id == TypeConstant.RSS:
return 'rss'
if type_id == constants.TYPE_WEATHER:
if type_id == TypeConstant.WEATHER:
return 'weather'
if type_id == constants.TYPE_MRIM:
if type_id == TypeConstant.MRIM:
return 'mrim'
if type_id == constants.TYPE_NO_TRANSPORT:
if type_id == TypeConstant.NO_TRANSPORT:
return 'jabber'
def convert_human_subscription_values_to_db_api_values(self, sub):
@ -389,25 +381,25 @@ class Logger:
Convert from string style to constant ints for db
"""
if sub == 'none':
return constants.SUBSCRIPTION_NONE
return SubscriptionConstant.NONE
if sub == 'to':
return constants.SUBSCRIPTION_TO
return SubscriptionConstant.TO
if sub == 'from':
return constants.SUBSCRIPTION_FROM
return SubscriptionConstant.FROM
if sub == 'both':
return constants.SUBSCRIPTION_BOTH
return SubscriptionConstant.BOTH
def convert_db_api_values_to_human_subscription_values(self, sub):
"""
Convert from constant ints for db to string style
"""
if sub == constants.SUBSCRIPTION_NONE:
if sub == SubscriptionConstant.NONE:
return 'none'
if sub == constants.SUBSCRIPTION_TO:
if sub == SubscriptionConstant.TO:
return 'to'
if sub == constants.SUBSCRIPTION_FROM:
if sub == SubscriptionConstant.FROM:
return 'from'
if sub == constants.SUBSCRIPTION_BOTH:
if sub == SubscriptionConstant.BOTH:
return 'both'
def commit_to_db(self, values, write_unread=False):
@ -539,12 +531,12 @@ class Logger:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
if show is None: # show is None (xmpp), but we say that 'online'
show_col = constants.SHOW_ONLINE
show_col = ShowConstant.ONLINE
elif kind == 'gcstatus':
# status in ROOM (for pm status see status)
if show is None: # show is None (xmpp), but we say that 'online'
show_col = constants.SHOW_ONLINE
show_col = ShowConstant.ONLINE
jid, nick = jid.split('/', 1)
try:
# re-get jid_id for the new jid
@ -608,9 +600,9 @@ class Logger:
SELECT time, kind, message, subject, additional_data FROM logs
WHERE (%s) AND kind IN (%d, %d, %d, %d, %d) AND time > %d
ORDER BY time DESC LIMIT %d OFFSET %d
''' % (where_sql, constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV, constants.KIND_SINGLE_MSG_SENT,
constants.KIND_CHAT_MSG_SENT, constants.KIND_ERROR, timed_out,
''' % (where_sql, KindConstant.SINGLE_MSG_RECV,
KindConstant.CHAT_MSG_RECV, KindConstant.SINGLE_MSG_SENT,
KindConstant.CHAT_MSG_SENT, KindConstant.ERROR, timed_out,
restore_how_many_rows, pending_how_many), jid_tuple)
results = self.cur.fetchall()
@ -736,7 +728,7 @@ class Logger:
AND kind NOT IN (%d, %d)
ORDER BY time
''' % (where_sql, start_of_month, last_second_of_month,
constants.KIND_STATUS, constants.KIND_GCSTATUS), jid_tuple)
KindConstant.STATUS, KindConstant.GCSTATUS), jid_tuple)
result = self.cur.fetchall()
# convert timestamps to day of month
@ -765,7 +757,7 @@ class Logger:
SELECT MAX(time) FROM logs
WHERE (%s)
AND kind NOT IN (%d, %d)
''' % (where_sql, constants.KIND_STATUS, constants.KIND_GCSTATUS),
''' % (where_sql, KindConstant.STATUS, KindConstant.GCSTATUS),
jid_tuple)
results = self.cur.fetchone()

View File

@ -19,6 +19,7 @@
from common.zeroconf import zeroconf
from common.zeroconf.zeroconf import Constant, ConstantRI
class Roster:
def __init__(self, zeroconf):
@ -29,7 +30,7 @@ class Roster:
def update_roster(self):
for val in self.zeroconf.contacts.values():
self.setItem(val[zeroconf.C_NAME])
self.setItem(val[Constant.NAME])
def getRoster(self):
if self._data is None:
@ -58,13 +59,13 @@ class Roster:
addresses = []
i = 0
for ri in contact[zeroconf.C_RESOLVED_INFO]:
for ri in contact[Constant.RESOLVED_INFO]:
addresses += [{}]
addresses[i]['host'] = ri[zeroconf.C_RI_HOST]
addresses[i]['address'] = ri[zeroconf.C_RI_ADDRESS]
addresses[i]['port'] = ri[zeroconf.C_RI_PORT]
addresses[i]['host'] = ri[ConstantRI.HOST]
addresses[i]['address'] = ri[ConstantRI.ADDRESS]
addresses[i]['port'] = ri[ConstantRI.PORT]
i += 1
txt = contact[zeroconf.C_TXT]
txt = contact[Constant.TXT]
self._data[jid]={}
self._data[jid]['ask'] = 'none'

View File

@ -17,8 +17,22 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
C_NAME, C_DOMAIN, C_RESOLVED_INFO, C_BARE_NAME, C_TXT = range(5)
C_RI_INTERFACE, C_RI_PROTOCOL, C_RI_HOST, C_RI_APROTOCOL, C_RI_ADDRESS, C_RI_PORT = range(6)
from enum import IntEnum
class Constant(IntEnum):
NAME = 0
DOMAIN = 1
RESOLVED_INFO = 2
BARE_NAME = 3
TXT = 4
class ConstantRI(IntEnum):
INTERFACE = 0
PROTOCOL = 1
HOST = 2
APROTOCOL = 3
ADDRESS = 4
PORT = 5
def test_avahi():
try:

View File

@ -25,8 +25,7 @@ try:
except ImportError:
pass
from common.zeroconf.zeroconf import C_BARE_NAME, C_RESOLVED_INFO, \
C_RI_INTERFACE, C_RI_PROTOCOL, C_DOMAIN, C_TXT
from common.zeroconf.zeroconf import Constant, ConstantRI
class Zeroconf:
def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB,
@ -95,15 +94,15 @@ class Zeroconf:
if name != self.name:
for key in self.contacts.keys():
val = self.contacts[key]
if val[C_BARE_NAME] == name:
if val[Constant.BARE_NAME] == name:
# try to reduce instead of delete first
resolved_info = val[C_RESOLVED_INFO]
resolved_info = val[Constant.RESOLVED_INFO]
if len(resolved_info) > 1:
for i in range(len(resolved_info)):
if resolved_info[i][C_RI_INTERFACE] == interface and resolved_info[i][C_RI_PROTOCOL] == protocol:
del self.contacts[key][C_RESOLVED_INFO][i]
if resolved_info[i][ConstantRI.INTERFACE] == interface and resolved_info[i][ConstantRI.PROTOCOL] == protocol:
del self.contacts[key][Constant.RESOLVED_INFO][i]
# if still something left, don't remove
if len(self.contacts[key][C_RESOLVED_INFO]) > 1: return
if len(self.contacts[key][Constant.RESOLVED_INFO]) > 1: return
del self.contacts[key]
self.remove_serviceCB(key)
return
@ -201,7 +200,7 @@ class Zeroconf:
name = name + '@' + name
# update TXT data only, as intended according to resolve_all comment
old_contact = self.contacts[name]
self.contacts[name] = old_contact[0:C_TXT] + (txt,) + old_contact[C_TXT+1:]
self.contacts[name] = old_contact[0:Constant.TXT] + (txt,) + old_contact[Constant.TXT+1:]
def service_added_callback(self):
log.debug('Service successfully added')
@ -450,9 +449,9 @@ class Zeroconf:
for val in self.contacts.values():
# get txt data from last recorded resolved info
# TODO: Better try to get it from last IPv6 mDNS, then last IPv4?
ri = val[C_RESOLVED_INFO][0]
self.server.ResolveService(int(ri[C_RI_INTERFACE]), int(ri[C_RI_PROTOCOL]),
val[C_BARE_NAME], self.stype, val[C_DOMAIN],
ri = val[Constant.RESOLVED_INFO][0]
self.server.ResolveService(int(ri[ConstantRI.INTERFACE]), int(ri[ConstantRI.PROTOCOL]),
val[Constant.BARE_NAME], self.stype, val[Constant.DOMAIN],
self.avahi.PROTO_UNSPEC, dbus.UInt32(0),
reply_handler=self.service_resolved_all_callback,
error_handler=self.error_callback)

View File

@ -20,7 +20,7 @@
from common import gajim
import select
import re
from common.zeroconf.zeroconf import C_BARE_NAME, C_DOMAIN, C_TXT
from common.zeroconf.zeroconf import Constant
try:
import pybonjour
@ -86,7 +86,7 @@ class Zeroconf:
return
if name != self.name:
for key in self.contacts.keys():
if self.contacts[key][C_BARE_NAME] == name:
if self.contacts[key][Constant.BARE_NAME] == name:
del self.contacts[key]
self.remove_serviceCB(key)
return
@ -171,7 +171,7 @@ class Zeroconf:
if name != self.name:
# update TXT data only, as intended according to resolve_all comment
old_contact = self.contacts[name]
self.contacts[name] = old_contact[0:C_TXT] + (self.txt,) + old_contact[C_TXT+1:]
self.contacts[name] = old_contact[0:Constant.TXT] + (self.txt,) + old_contact[Constant.TXT+1:]
def service_added_callback(self, sdRef, flags, errorCode, name, regtype, domain):
@ -303,8 +303,8 @@ class Zeroconf:
for val in self.contacts.values():
resolve_sdRef = pybonjour.DNSServiceResolve(0,
pybonjour.kDNSServiceInterfaceIndexAny, val[C_BARE_NAME],
self.stype + '.', val[C_DOMAIN] + '.',
pybonjour.kDNSServiceInterfaceIndexAny, val[Constant.BARE_NAME],
self.stype + '.', val[Constant.DOMAIN] + '.',
self.service_resolved_all_callback)
try:

View File

@ -29,6 +29,8 @@ from gi.repository import Pango
import os
import time
from enum import IntEnum
import gtkgui_helpers
import tooltips
import dialogs
@ -42,14 +44,15 @@ from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER
import logging
log = logging.getLogger('gajim.filetransfer_window')
C_IMAGE = 0
C_LABELS = 1
C_FILE = 2
C_TIME = 3
C_PROGRESS = 4
C_PERCENT = 5
C_PULSE = 6
C_SID = 7
class Column(IntEnum):
IMAGE = 0
LABELS = 1
FILE = 2
TIME = 3
PROGRESS = 4
PERCENT = 5
PULSE = 6
SID = 7
class FileTransfersWindow:
@ -85,11 +88,11 @@ class FileTransfersWindow:
col = Gtk.TreeViewColumn(_('File'))
renderer = Gtk.CellRendererText()
col.pack_start(renderer, False)
col.add_attribute(renderer, 'markup', C_LABELS)
col.add_attribute(renderer, 'markup', Column.LABELS)
renderer.set_property('yalign', 0.)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'markup', C_FILE)
col.add_attribute(renderer, 'markup', Column.FILE)
renderer.set_property('xalign', 0.)
renderer.set_property('yalign', 0.)
renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
@ -100,7 +103,7 @@ class FileTransfersWindow:
col = Gtk.TreeViewColumn(_('Time'))
renderer = Gtk.CellRendererText()
col.pack_start(renderer, False)
col.add_attribute(renderer, 'markup', C_TIME)
col.add_attribute(renderer, 'markup', Column.TIME)
renderer.set_property('yalign', 0.5)
renderer.set_property('xalign', 0.5)
renderer = Gtk.CellRendererText()
@ -114,9 +117,9 @@ class FileTransfersWindow:
renderer.set_property('yalign', 0.5)
renderer.set_property('xalign', 0.5)
col.pack_start(renderer, False)
col.add_attribute(renderer, 'text', C_PROGRESS)
col.add_attribute(renderer, 'value', C_PERCENT)
col.add_attribute(renderer, 'pulse', C_PULSE)
col.add_attribute(renderer, 'text', Column.PROGRESS)
col.add_attribute(renderer, 'value', Column.PERCENT)
col.add_attribute(renderer, 'pulse', Column.PULSE)
col.set_resizable(True)
col.set_expand(False)
self.tree.append_column(col)
@ -480,7 +483,7 @@ class FileTransfersWindow:
iter_ = self.get_iter_by_sid(file_props.type_, file_props.sid)
if iter_ is None:
return
self.model[iter_][C_SID]
self.model[iter_][Column.SID]
if status == 'stop':
file_props.stopped = True
elif status == 'ok':
@ -490,21 +493,21 @@ class FileTransfersWindow:
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
self.model.set(iter_, C_PROGRESS, text)
self.model.set(iter_, C_PULSE, GLib.MAXINT32)
self.model.set(iter_, Column.PROGRESS, text)
self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
elif status == 'computing':
self.model.set(iter_, C_PULSE, 1)
self.model.set(iter_, Column.PULSE, 1)
text = _('Checking file…') + '\n'
received_size = int(file_props.received_len)
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
self.model.set(iter_, C_PROGRESS, text)
self.model.set(iter_, Column.PROGRESS, text)
def pulse():
p = self.model.get(iter_, C_PULSE)[0]
p = self.model.get(iter_, Column.PULSE)[0]
if p == GLib.MAXINT32:
return False
self.model.set(iter_, C_PULSE, p + 1)
self.model.set(iter_, Column.PULSE, p + 1)
return True
GLib.timeout_add(100, pulse)
elif status == 'hash_error':
@ -513,9 +516,9 @@ class FileTransfersWindow:
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
self.model.set(iter_, C_PROGRESS, text)
self.model.set(iter_, C_PULSE, GLib.MAXINT32)
self.model.set(iter_, C_IMAGE, self.get_icon(status))
self.model.set(iter_, Column.PROGRESS, text)
self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
self.model.set(iter_, Column.IMAGE, self.get_icon(status))
path = self.model.get_path(iter_)
self.select_func(path)
@ -609,7 +612,7 @@ class FileTransfersWindow:
iter_ = self.get_iter_by_sid(typ, sid)
if iter_ is not None:
just_began = False
if self.model[iter_][C_PERCENT] == 0 and int(percent > 0):
if self.model[iter_][Column.PERCENT] == 0 and int(percent > 0):
just_began = True
text = self._format_percent(percent)
if transfered_size == 0:
@ -631,8 +634,8 @@ class FileTransfersWindow:
eta, speed = self._get_eta_and_speed(full_size, transfered_size,
file_props)
self.model.set(iter_, C_PROGRESS, text)
self.model.set(iter_, C_PERCENT, int(percent))
self.model.set(iter_, Column.PROGRESS, text)
self.model.set(iter_, Column.PERCENT, int(percent))
text = self._format_time(eta)
text += '\n'
#This should make the string Kb/s,
@ -640,7 +643,7 @@ class FileTransfersWindow:
#Only the 's' after / (which means second) should be translated.
text += _('(%(filesize_unit)s/s)') % {'filesize_unit':
helpers.convert_bytes(speed)}
self.model.set(iter_, C_TIME, text)
self.model.set(iter_, Column.TIME, text)
# try to guess what should be the status image
if file_props.type_ == 'r':
@ -673,7 +676,7 @@ class FileTransfersWindow:
"""
iter_ = self.model.get_iter_first()
while iter_:
if typ + sid == self.model[iter_][C_SID]:
if typ + sid == self.model[iter_][Column.SID]:
return iter_
iter_ = self.model.iter_next(iter_)
@ -736,7 +739,7 @@ class FileTransfersWindow:
file_name = file_props.name
text_props = GLib.markup_escape_text(file_name) + '\n'
text_props += contact.get_shown_name()
self.model.set(iter_, 1, text_labels, 2, text_props, C_PULSE, -1, C_SID,
self.model.set(iter_, 1, text_labels, 2, text_props, Column.PULSE, -1, Column.SID,
file_props.type_ + file_props.sid)
self.set_progress(file_props.type_, file_props.sid, 0, iter_)
if file_props.started is False:
@ -767,7 +770,7 @@ class FileTransfersWindow:
except Exception:
self.tooltip.hide_tooltip()
return
sid = self.model[iter_][C_SID]
sid = self.model[iter_][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if file_props is not None:
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
@ -825,7 +828,7 @@ class FileTransfersWindow:
self.set_all_insensitive()
return
current_iter = self.model.get_iter(path)
sid = self.model[current_iter][C_SID]
sid = self.model[current_iter][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
self.remove_menuitem.set_sensitive(is_row_selected)
self.open_folder_menuitem.set_sensitive(is_row_selected)
@ -883,7 +886,7 @@ class FileTransfersWindow:
i = len(self.model) - 1
while i >= 0:
iter_ = self.model.get_iter((i))
sid = self.model[iter_][C_SID]
sid = self.model[iter_][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if is_transfer_stopped(file_props):
self._remove_transfer(iter_, sid, file_props)
@ -918,7 +921,7 @@ class FileTransfersWindow:
if selected is None or selected[1] is None:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
sid = self.model[s_iter][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if is_transfer_paused(file_props):
file_props.last_time = time.time()
@ -940,7 +943,7 @@ class FileTransfersWindow:
if selected is None or selected[1] is None:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
sid = self.model[s_iter][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
account = file_props.tt_account
if account not in gajim.connections:
@ -966,7 +969,7 @@ class FileTransfersWindow:
# as it was before setting the timeout
if props and self.tooltip.id == props[0]:
iter_ = self.model.get_iter(props[0])
sid = self.model[iter_][C_SID]
sid = self.model[iter_][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
# bounding rectangle of coordinates for the cell within the treeview
rect = self.tree.get_cell_area(props[0], props[1])
@ -1054,7 +1057,7 @@ class FileTransfersWindow:
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
sid = self.model[s_iter][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if not file_props.file_name:
return
@ -1076,7 +1079,7 @@ class FileTransfersWindow:
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
sid = self.model[s_iter][Column.SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
self._remove_transfer(s_iter, sid, file_props)
self.set_all_insensitive()

View File

@ -46,6 +46,8 @@ import cell_renderer_image
import dataforms_widget
import nbxmpp
from enum import IntEnum
from common import events
from common import gajim
from common import helpers
@ -63,14 +65,12 @@ from common.connection_handlers_events import GcMessageOutgoingEvent
import logging
log = logging.getLogger('gajim.groupchat_control')
#(status_image, type, nick, shown_nick)
(
C_IMG, # image to show state (online, new message etc)
C_NICK, # contact nickame or ROLE name
C_TYPE, # type of the row ('contact' or 'role')
C_TEXT, # text shown in the cellrenderer
C_AVATAR, # avatar of the contact
) = range(5)
class Column(IntEnum):
IMG = 0 # image to show state (online, new message etc)
NICK = 1 # contact nickame or ROLE name
TYPE = 2 # type of the row ('contact' or 'role')
TEXT = 3 # text shown in the cellrenderer
AVATAR = 4 # avatar of the contact
empty_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 1, 1)
empty_pixbuf.fill(0xffffff00)
@ -99,7 +99,7 @@ def tree_cell_data_func(column, renderer, model, iter_, tv=None):
renderer.set_property('xalign', 1) # align pixbuf to the right
else:
renderer.set_property('xalign', 0.5)
if parent_iter and (model[iter_][C_AVATAR] or avatar_position == \
if parent_iter and (model[iter_][Column.AVATAR] or avatar_position == \
'left'):
renderer.set_property('visible', True)
renderer.set_property('width', gajim.config.get(
@ -448,8 +448,8 @@ class GroupchatControl(ChatControlBase):
#status_image, shown_nick, type, nickname, avatar
self.columns = [Gtk.Image, str, str, str, GdkPixbuf.Pixbuf]
self.model = Gtk.TreeStore(*self.columns)
self.model.set_sort_func(C_NICK, self.tree_compare_iters)
self.model.set_sort_column_id(C_NICK, Gtk.SortType.ASCENDING)
self.model.set_sort_func(Column.NICK, self.tree_compare_iters)
self.model.set_sort_column_id(Column.NICK, Gtk.SortType.ASCENDING)
# columns
column = Gtk.TreeViewColumn()
@ -469,14 +469,14 @@ class GroupchatControl(ChatControlBase):
self.renderers_list += (
# status img
('icon', renderer_image, False,
'image', C_IMG, tree_cell_data_func, self.list_treeview),
'image', Column.IMG, tree_cell_data_func, self.list_treeview),
# contact name
('name', renderer_text, True,
'markup', C_TEXT, tree_cell_data_func, self.list_treeview))
'markup', Column.TEXT, tree_cell_data_func, self.list_treeview))
# avatar img
avater_renderer = ('avatar', Gtk.CellRendererPixbuf(),
False, 'pixbuf', C_AVATAR,
False, 'pixbuf', Column.AVATAR,
tree_cell_data_func, self.list_treeview)
if gajim.config.get('avatar_position_in_roster') == 'right':
@ -549,8 +549,8 @@ class GroupchatControl(ChatControlBase):
except Exception:
return False
typ = self.model[iter_][C_TYPE]
nick = self.model[iter_][C_NICK]
typ = self.model[iter_][Column.TYPE]
nick = self.model[iter_][Column.NICK]
if typ != 'contact':
return False
@ -589,12 +589,12 @@ class GroupchatControl(ChatControlBase):
"""
Compare two iters to sort them
"""
type1 = model[iter1][C_TYPE]
type2 = model[iter2][C_TYPE]
type1 = model[iter1][Column.TYPE]
type2 = model[iter2][Column.TYPE]
if not type1 or not type2:
return 0
nick1 = model[iter1][C_NICK]
nick2 = model[iter2][C_NICK]
nick1 = model[iter1][Column.NICK]
nick2 = model[iter2][Column.NICK]
if not nick1 or not nick2:
return 0
if type1 == 'role':
@ -700,7 +700,7 @@ class GroupchatControl(ChatControlBase):
"""
# Get the room_jid from treeview
for contact in self.iter_contact_rows():
nick = contact[C_NICK]
nick = contact[Column.NICK]
self.draw_contact(nick)
def on_list_treeview_selection_changed(self, selection):
@ -712,9 +712,9 @@ class GroupchatControl(ChatControlBase):
self._last_selected_contact = None
return
contact = model[selected_iter]
nick = contact[C_NICK]
nick = contact[Column.NICK]
self._last_selected_contact = nick
if contact[C_TYPE] != 'contact':
if contact[Column.TYPE] != 'contact':
return
self.draw_contact(nick, selected=True, focus=True)
@ -782,7 +782,7 @@ class GroupchatControl(ChatControlBase):
self.draw_contact(nick)
def _change_style(self, model, path, iter_, option):
model[iter_][C_NICK] = model[iter_][C_NICK]
model[iter_][Column.NICK] = model[iter_][Column.NICK]
def change_roster_style(self):
self.model.foreach(self._change_style, None)
@ -1100,7 +1100,7 @@ class GroupchatControl(ChatControlBase):
gajim.interface.roster.get_appropriate_state_images(
self.room_jid, icon_name='event')
image = state_images['event']
self.model[iter_][C_IMG] = image
self.model[iter_][Column.IMG] = image
if self.parent_win:
self.parent_win.show_title()
self.parent_win.redraw_tab(self)
@ -1122,7 +1122,7 @@ class GroupchatControl(ChatControlBase):
while role_iter:
user_iter = self.model.iter_children(role_iter)
while user_iter:
if nick == self.model[user_iter][C_NICK]:
if nick == self.model[user_iter][Column.NICK]:
return user_iter
else:
user_iter = self.model.iter_next(user_iter)
@ -1486,7 +1486,7 @@ class GroupchatControl(ChatControlBase):
contact in a room
"""
if nick is None:
nick = model[iter_][C_NICK]
nick = model[iter_][Column.NICK]
ctrl = self._start_private_message(nick)
if ctrl and msg:
@ -1548,8 +1548,8 @@ class GroupchatControl(ChatControlBase):
pixbuf2.get_property('height'), 0, 0, 1.0, 1.0,
GdkPixbuf.InterpType.HYPER, 127)
image = Gtk.Image.new_from_pixbuf(pixbuf1)
self.model[iter_][C_IMG] = image
self.model[iter_][C_TEXT] = name
self.model[iter_][Column.IMG] = image
self.model[iter_][Column.TEXT] = name
def draw_avatar(self, nick):
if not gajim.config.get('show_avatars_in_roster'):
@ -1565,7 +1565,7 @@ class GroupchatControl(ChatControlBase):
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster')
if not scaled_pixbuf:
scaled_pixbuf = empty_pixbuf
self.model[iter_][C_AVATAR] = scaled_pixbuf
self.model[iter_][Column.AVATAR] = scaled_pixbuf
def draw_role(self, role):
role_iter = self.get_role_iter(role)
@ -1576,7 +1576,7 @@ class GroupchatControl(ChatControlBase):
nbr_role, nbr_total = gajim.contacts.get_nb_role_total_gc_contacts(
self.account, self.room_jid, role)
role_name += ' (%s/%s)' % (repr(nbr_role), repr(nbr_total))
self.model[role_iter][C_TEXT] = role_name
self.model[role_iter][Column.TEXT] = role_name
def draw_all_roles(self):
for role in ('visitor', 'participant', 'moderator'):
@ -1967,7 +1967,7 @@ class GroupchatControl(ChatControlBase):
def get_role_iter(self, role):
role_iter = self.model.get_iter_first()
while role_iter:
role_name = self.model[role_iter][C_NICK]
role_name = self.model[role_iter][Column.NICK]
if role == role_name:
return role_iter
role_iter = self.model.iter_next(role_iter)
@ -2429,7 +2429,7 @@ class GroupchatControl(ChatControlBase):
"""
model = widget.get_model()
image = gajim.interface.jabber_state_images['16']['opened']
model[iter_][C_IMG] = image
model[iter_][Column.IMG] = image
def on_list_treeview_row_collapsed(self, widget, iter_, path):
"""
@ -2437,7 +2437,7 @@ class GroupchatControl(ChatControlBase):
"""
model = widget.get_model()
image = gajim.interface.jabber_state_images['16']['closed']
model[iter_][C_IMG] = image
model[iter_][Column.IMG] = image
def kick(self, widget, nick):
"""
@ -2456,7 +2456,7 @@ class GroupchatControl(ChatControlBase):
"""
Make contact's popup menu
"""
nick = self.model[iter_][C_NICK]
nick = self.model[iter_][Column.NICK]
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
fjid = self.room_jid + '/' + nick
jid = c.jid
@ -2619,7 +2619,7 @@ class GroupchatControl(ChatControlBase):
else:
widget.expand_row(path, False)
else: # We want to send a private message
nick = self.model[path][C_NICK]
nick = self.model[path][Column.NICK]
self._start_private_message(nick)
def on_list_treeview_row_activated(self, widget, path, col=0):
@ -2650,7 +2650,7 @@ class GroupchatControl(ChatControlBase):
widget.get_selection().select_path(path)
iter_ = self.model.get_iter(path)
if path.get_depth() == 2:
nick = self.model[iter_][C_NICK]
nick = self.model[iter_][Column.NICK]
self._start_private_message(nick)
return True
@ -2660,7 +2660,7 @@ class GroupchatControl(ChatControlBase):
return True
else:
iter_ = self.model.get_iter(path)
nick = self.model[iter_][C_NICK]
nick = self.model[iter_][Column.NICK]
if not nick in gajim.contacts.get_nick_list(self.account,
self.room_jid):
# it's a group

View File

@ -99,13 +99,13 @@ status = dict((constants.__dict__[i], i[5:].lower()) for i in \
from common import helpers
import dialogs
# time, message, subject
(
C_UNIXTIME,
C_MESSAGE,
C_SUBJECT,
C_NICKNAME
) = range(2, 6)
from enum import IntEnum
class Column(IntEnum):
UNIXTIME = 2
MESSAGE = 3
SUBJECT = 4
NICKNAME = 5
import sqlite3 as sqlite
@ -176,32 +176,32 @@ class HistoryManager:
self.logs_listview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
renderer_text = Gtk.CellRendererText() # holds time
col = Gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
col = Gtk.TreeViewColumn(_('Date'), renderer_text, text=Column.UNIXTIME)
# user can click this header and sort
col.set_sort_column_id(C_UNIXTIME)
col.set_sort_column_id(Column.UNIXTIME)
col.set_resizable(True)
self.logs_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds nickname
col = Gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
col = Gtk.TreeViewColumn(_('Nickname'), renderer_text, text=Column.NICKNAME)
# user can click this header and sort
col.set_sort_column_id(C_NICKNAME)
col.set_sort_column_id(Column.NICKNAME)
col.set_resizable(True)
col.set_visible(False)
self.nickname_col_for_logs = col
self.logs_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds message
col = Gtk.TreeViewColumn(_('Message'), renderer_text, markup=C_MESSAGE)
col = Gtk.TreeViewColumn(_('Message'), renderer_text, markup=Column.MESSAGE)
# user can click this header and sort
col.set_sort_column_id(C_MESSAGE)
col.set_sort_column_id(Column.MESSAGE)
col.set_resizable(True)
self.message_col_for_logs = col
self.logs_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds subject
col = Gtk.TreeViewColumn(_('Subject'), renderer_text, text=C_SUBJECT)
col.set_sort_column_id(C_SUBJECT) # user can click this header and sort
col = Gtk.TreeViewColumn(_('Subject'), renderer_text, text=Column.SUBJECT)
col.set_sort_column_id(Column.SUBJECT) # user can click this header and sort
col.set_resizable(True)
col.set_visible(False)
self.subject_col_for_logs = col
@ -220,28 +220,28 @@ class HistoryManager:
self.search_results_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds time
col = Gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
col = Gtk.TreeViewColumn(_('Date'), renderer_text, text=Column.UNIXTIME)
# user can click this header and sort
col.set_sort_column_id(C_UNIXTIME)
col.set_sort_column_id(Column.UNIXTIME)
col.set_resizable(True)
self.search_results_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds message
col = Gtk.TreeViewColumn(_('Message'), renderer_text, text=C_MESSAGE)
col.set_sort_column_id(C_MESSAGE) # user can click this header and sort
col = Gtk.TreeViewColumn(_('Message'), renderer_text, text=Column.MESSAGE)
col.set_sort_column_id(Column.MESSAGE) # user can click this header and sort
col.set_resizable(True)
self.search_results_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds subject
col = Gtk.TreeViewColumn(_('Subject'), renderer_text, text=C_SUBJECT)
col.set_sort_column_id(C_SUBJECT) # user can click this header and sort
col = Gtk.TreeViewColumn(_('Subject'), renderer_text, text=Column.SUBJECT)
col.set_sort_column_id(Column.SUBJECT) # user can click this header and sort
col.set_resizable(True)
self.search_results_listview.append_column(col)
renderer_text = Gtk.CellRendererText() # holds nickname
col = Gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
col = Gtk.TreeViewColumn(_('Nickname'), renderer_text, text=Column.NICKNAME)
# user can click this header and sort
col.set_sort_column_id(C_NICKNAME)
col.set_sort_column_id(Column.NICKNAME)
col.set_resizable(True)
self.search_results_listview.append_column(col)

View File

@ -31,6 +31,8 @@ from gi.repository import GLib
import time
import calendar
from enum import IntEnum
import gtkgui_helpers
import conversation_textview
import dialogs
@ -39,26 +41,21 @@ from common import gajim
from common import helpers
from common import exceptions
from common.logger import Constants
from common.logger import ShowConstant, KindConstant
constants = Constants()
class InfoColumn(IntEnum):
'''Completion dict'''
JID = 0
ACCOUNT = 1
NAME = 2
COMPLETION = 3
# Completion dict
(
C_INFO_JID,
C_INFO_ACCOUNT,
C_INFO_NAME,
C_INFO_COMPLETION
) = range(4)
# contact_name, date, message, time
(
C_LOG_JID,
C_CONTACT_NAME,
C_UNIXTIME,
C_MESSAGE,
C_TIME
) = range(5)
class Column(IntEnum):
LOG_JID = 0
CONTACT_NAME = 1
UNIXTIME = 2
MESSAGE = 3
TIME = 4
class HistoryWindow:
"""
@ -95,23 +92,23 @@ class HistoryWindow:
self.results_treeview.append_column(col)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', C_CONTACT_NAME)
col.set_sort_column_id(C_CONTACT_NAME) # user can click this header and sort
col.add_attribute(renderer, 'text', Column.CONTACT_NAME)
col.set_sort_column_id(Column.CONTACT_NAME) # user can click this header and sort
col.set_resizable(True)
col = Gtk.TreeViewColumn(_('Date'))
self.results_treeview.append_column(col)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', C_UNIXTIME)
col.set_sort_column_id(C_UNIXTIME) # user can click this header and sort
col.add_attribute(renderer, 'text', Column.UNIXTIME)
col.set_sort_column_id(Column.UNIXTIME) # user can click this header and sort
col.set_resizable(True)
col = Gtk.TreeViewColumn(_('Message'))
self.results_treeview.append_column(col)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', C_MESSAGE)
col.add_attribute(renderer, 'text', Column.MESSAGE)
col.set_resizable(True)
self.jid = None # The history we are currently viewing
@ -372,17 +369,17 @@ class HistoryWindow:
widget.mark_day(day)
def _get_string_show_from_constant_int(self, show):
if show == constants.SHOW_ONLINE:
if show == ShowConstant.ONLINE:
show = 'online'
elif show == constants.SHOW_CHAT:
elif show == ShowConstant.CHAT:
show = 'chat'
elif show == constants.SHOW_AWAY:
elif show == ShowConstant.AWAY:
show = 'away'
elif show == constants.SHOW_XA:
elif show == ShowConstant.XA:
show = 'xa'
elif show == constants.SHOW_DND:
elif show == ShowConstant.DND:
show = 'dnd'
elif show == constants.SHOW_OFFLINE:
elif show == ShowConstant.OFFLINE:
show = 'offline'
return show
@ -402,8 +399,8 @@ class HistoryWindow:
# line[0] is contact_name, line[1] is time of message
# line[2] is kind, line[3] is show, line[4] is message, line[5] is subject
# line[6] is additional_data
if not show_status and line[2] in (constants.KIND_GCSTATUS,
constants.KIND_STATUS):
if not show_status and line[2] in (KindConstant.GCSTATUS,
KindConstant.STATUS):
continue
self._add_new_line(line[0], line[1], line[2], line[3], line[4],
line[5], line[6])
@ -412,8 +409,8 @@ class HistoryWindow:
"""
Add a new line in textbuffer
"""
if not message and kind not in (constants.KIND_STATUS,
constants.KIND_GCSTATUS):
if not message and kind not in (KindConstant.STATUS,
KindConstant.GCSTATUS):
return
buf = self.history_buffer
end_iter = buf.get_end_iter()
@ -444,15 +441,15 @@ class HistoryWindow:
show = self._get_string_show_from_constant_int(show)
if kind == constants.KIND_GC_MSG:
if kind == KindConstant.GC_MSG:
tag_name = 'incoming'
elif kind in (constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV):
contact_name = self.completion_dict[self.jid][C_INFO_NAME]
elif kind in (KindConstant.SINGLE_MSG_RECV,
KindConstant.CHAT_MSG_RECV):
contact_name = self.completion_dict[self.jid][InfoColumn.NAME]
tag_name = 'incoming'
tag_msg = 'incomingtxt'
elif kind in (constants.KIND_SINGLE_MSG_SENT,
constants.KIND_CHAT_MSG_SENT):
elif kind in (KindConstant.SINGLE_MSG_SENT,
KindConstant.CHAT_MSG_SENT):
if self.account:
contact_name = gajim.nicks[self.account]
else:
@ -462,7 +459,7 @@ class HistoryWindow:
contact_name = gajim.nicks[account]
tag_name = 'outgoing'
tag_msg = 'outgoingtxt'
elif kind == constants.KIND_GCSTATUS:
elif kind == KindConstant.GCSTATUS:
# message here (if not None) is status message
if message:
message = _('%(nick)s is now %(status)s: %(status_msg)s') %\
@ -492,7 +489,7 @@ class HistoryWindow:
else:
# do not do this if gcstats, avoid dupping contact_name
# eg. nkour: nkour is now Offline
if contact_name and kind != constants.KIND_GCSTATUS:
if contact_name and kind != KindConstant.GCSTATUS:
# add stuff before and after contact name
before_str = gajim.config.get('before_nickname')
before_str = helpers.from_one_line(before_str)
@ -532,7 +529,7 @@ class HistoryWindow:
# perform search in preselected jids
# jids are preselected with the query_entry
for jid in self.jids_to_search:
account = self.completion_dict[jid][C_INFO_ACCOUNT]
account = self.completion_dict[jid][InfoColumn.ACCOUNT]
if account is None:
# We do not know an account. This can only happen if the contact is offine,
# or if we browse a groupchat history. The account is not needed, a dummy can
@ -554,16 +551,16 @@ class HistoryWindow:
# add "subject: | message: " in message column if kind is single
# also do we need show at all? (we do not search on subject)
for row in results:
if not show_status and row[2] in (constants.KIND_GCSTATUS,
constants.KIND_STATUS):
if not show_status and row[2] in (KindConstant.GCSTATUS,
KindConstant.STATUS):
continue
contact_name = row[0]
if not contact_name:
kind = row[2]
if kind == constants.KIND_CHAT_MSG_SENT: # it's us! :)
if kind == KindConstant.CHAT_MSG_SENT: # it's us! :)
contact_name = gajim.nicks[account]
else:
contact_name = self.completion_dict[jid][C_INFO_NAME]
contact_name = self.completion_dict[jid][InfoColumn.NAME]
tim = row[1]
message = row[4]
local_time = time.localtime(tim)
@ -583,14 +580,14 @@ class HistoryWindow:
cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month)
model = widget.get_model()
# make it a tupple (Y, M, D, 0, 0, 0...)
tim = time.strptime(model[path][C_UNIXTIME], '%Y-%m-%d')
tim = time.strptime(model[path][Column.UNIXTIME], '%Y-%m-%d')
year = tim[0]
gtk_month = tim[1]
month = gtkgui_helpers.make_python_month_gtk_month(gtk_month)
day = tim[2]
# switch to belonging logfile if necessary
log_jid = model[path][C_LOG_JID]
log_jid = model[path][Column.LOG_JID]
if log_jid != self.jid:
self._load_history(log_jid, None)
@ -599,7 +596,7 @@ class HistoryWindow:
self.calendar.select_month(month, year)
self.calendar.select_day(day)
unix_time = model[path][C_TIME]
unix_time = model[path][Column.TIME]
self._scroll_to_result(unix_time)
#FIXME: one day do not search just for unix_time but the whole and user
# specific format of the textbuffer line [time] nick: message

View File

@ -32,6 +32,8 @@ from gi.repository import GdkPixbuf
from gi.repository import GLib
import os
from enum import IntEnum
import gtkgui_helpers
from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog
from htmltextview import HtmlTextView
@ -41,13 +43,12 @@ from plugins.helpers import GajimPluginActivateException
from plugins.plugins_i18n import _
from common.exceptions import PluginsystemError
(
PLUGIN,
NAME,
ACTIVE,
ACTIVATABLE,
ICON,
) = range(5)
class Column(IntEnum):
PLUGIN = 0
NAME = 1
ACTIVE = 2
ACTIVATABLE = 3
ICON = 4
class PluginsWindow(object):
@ -78,19 +79,19 @@ class PluginsWindow(object):
self.installed_plugins_treeview.set_rules_hint(True)
renderer = Gtk.CellRendererText()
col = Gtk.TreeViewColumn(_('Plugin'))#, renderer, text=NAME)
col = Gtk.TreeViewColumn(_('Plugin'))#, renderer, text=Column.NAME)
cell = Gtk.CellRendererPixbuf()
col.pack_start(cell, False)
col.add_attribute(cell, 'pixbuf', ICON)
col.add_attribute(cell, 'pixbuf', Column.ICON)
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', NAME)
col.add_attribute(renderer, 'text', Column.NAME)
col.set_property('expand', True)
self.installed_plugins_treeview.append_column(col)
renderer = Gtk.CellRendererToggle()
renderer.connect('toggled', self.installed_plugins_toggled_cb)
col = Gtk.TreeViewColumn(_('Active'), renderer, active=ACTIVE,
activatable=ACTIVATABLE)
col = Gtk.TreeViewColumn(_('Active'), renderer, active=Column.ACTIVE,
activatable=Column.ACTIVATABLE)
self.installed_plugins_treeview.append_column(col)
self.def_icon = gtkgui_helpers.get_icon_pixmap('preferences-desktop')
@ -124,9 +125,9 @@ class PluginsWindow(object):
def installed_plugins_treeview_selection_changed(self, treeview_selection):
model, iter = treeview_selection.get_selected()
if iter:
plugin = model.get_value(iter, PLUGIN)
plugin_name = model.get_value(iter, NAME)
is_active = model.get_value(iter, ACTIVE)
plugin = model.get_value(iter, Column.PLUGIN)
plugin_name = model.get_value(iter, Column.NAME)
is_active = model.get_value(iter, Column.ACTIVE)
self._display_installed_plugin_info(plugin)
else:
@ -195,8 +196,8 @@ class PluginsWindow(object):
@log_calls('PluginsWindow')
def installed_plugins_toggled_cb(self, cell, path):
is_active = self.installed_plugins_model[path][ACTIVE]
plugin = self.installed_plugins_model[path][PLUGIN]
is_active = self.installed_plugins_model[path][Column.ACTIVE]
plugin = self.installed_plugins_model[path][Column.PLUGIN]
if is_active:
gajim.plugin_manager.deactivate_plugin(plugin)
@ -208,7 +209,7 @@ class PluginsWindow(object):
transient_for=self.window)
return
self.installed_plugins_model[path][ACTIVE] = not is_active
self.installed_plugins_model[path][Column.ACTIVE] = not is_active
@log_calls('PluginsWindow')
def on_plugins_window_destroy(self, widget):
@ -224,9 +225,9 @@ class PluginsWindow(object):
selection = self.installed_plugins_treeview.get_selection()
model, iter = selection.get_selected()
if iter:
plugin = model.get_value(iter, PLUGIN)
plugin_name = model.get_value(iter, NAME)
is_active = model.get_value(iter, ACTIVE)
plugin = model.get_value(iter, Column.PLUGIN)
plugin_name = model.get_value(iter, Column.NAME)
is_active = model.get_value(iter, Column.ACTIVE)
result = plugin.config_dialog.run(self.window)
@ -242,9 +243,9 @@ class PluginsWindow(object):
selection = self.installed_plugins_treeview.get_selection()
model, iter = selection.get_selected()
if iter:
plugin = model.get_value(iter, PLUGIN)
plugin_name = model.get_value(iter, NAME)
is_active = model.get_value(iter, ACTIVE)
plugin = model.get_value(iter, Column.PLUGIN)
plugin_name = model.get_value(iter, Column.NAME)
is_active = model.get_value(iter, Column.ACTIVE)
try:
gajim.plugin_manager.remove_plugin(plugin)
except PluginsystemError as e:
@ -271,8 +272,8 @@ class PluginsWindow(object):
model = self.installed_plugins_model
for i, row in enumerate(model):
if plugin == row[PLUGIN]:
model.remove(model.get_iter((i, PLUGIN)))
if plugin == row[Column.PLUGIN]:
model.remove(model.get_iter((i, Column.PLUGIN)))
break
iter_ = model.append([plugin, plugin.name, False,

View File

@ -43,6 +43,8 @@ import sys
import time
import locale
from enum import IntEnum
import common.sleepy
import history_window
import dialogs
@ -72,20 +74,18 @@ from message_window import MessageWindowMgr
from nbxmpp.protocol import NS_FILE, NS_ROSTERX, NS_CONFERENCE
#(icon, name, type, jid, account, editable, second pixbuf)
(
C_IMG, # image to show state (online, new message etc)
C_NAME, # cellrenderer text that holds contact nickame
C_TYPE, # account, group or contact?
C_JID, # the jid of the row
C_ACCOUNT, # cellrenderer text that holds account name
C_MOOD_PIXBUF,
C_ACTIVITY_PIXBUF,
C_TUNE_PIXBUF,
C_LOCATION_PIXBUF,
C_AVATAR_PIXBUF, # avatar_pixbuf
C_PADLOCK_PIXBUF, # use for account row only
) = range(11)
class Column(IntEnum):
IMG = 0 # image to show state (online, new message etc)
NAME = 1 # cellrenderer text that holds contact nickame
TYPE = 2 # account, group or contact?
JID = 3 # the jid of the row
ACCOUNT = 4 # cellrenderer text that holds account name
MOOD_PIXBUF = 5
ACTIVITY_PIXBUF = 6
TUNE_PIXBUF = 7
LOCATION_PIXBUF = 8
AVATAR_PIXBUF = 9 # avatar_pixbuf
PADLOCK_PIXBUF = 10 # use for account row only
empty_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 1, 1)
empty_pixbuf.fill(0xffffff00)
@ -434,7 +434,7 @@ class RosterWindow:
assert iters, '%s shall be removed but is not in roster' % contact.jid
parent_iter = self.model.iter_parent(iters[0])
parent_type = self.model[parent_iter][C_TYPE]
parent_type = self.model[parent_iter][Column.TYPE]
if groups:
# Only remove from specified groups
@ -451,12 +451,12 @@ class RosterWindow:
return False
# Remove us and empty groups from the model
for i in iters:
assert self.model[i][C_JID] == contact.jid and \
self.model[i][C_ACCOUNT] == account, \
assert self.model[i][Column.JID] == contact.jid and \
self.model[i][Column.ACCOUNT] == account, \
"Invalidated iters of %s" % contact.jid
parent_i = self.model.iter_parent(i)
parent_type = self.model[parent_i][C_TYPE]
parent_type = self.model[parent_i][Column.TYPE]
to_be_removed = i
while parent_type == 'group' and \
@ -465,13 +465,13 @@ class RosterWindow:
account_group = 'MERGED'
else:
account_group = account
group = self.model[parent_i][C_JID]
group = self.model[parent_i][Column.JID]
if group in gajim.groups[account]:
del gajim.groups[account][group]
to_be_removed = parent_i
del self._iters[account_group]['groups'][group]
parent_i = self.model.iter_parent(parent_i)
parent_type = self.model[parent_i][C_TYPE]
parent_type = self.model[parent_i][Column.TYPE]
self.model.remove(to_be_removed)
del self._iters[account]['contacts'][contact.jid]
@ -555,7 +555,7 @@ class RosterWindow:
family_in_roster = True
parent_iter = self.model.iter_parent(iters[0])
parent_type = self.model[parent_iter][C_TYPE]
parent_type = self.model[parent_iter][Column.TYPE]
if parent_type != 'contact':
# The contact on top
@ -603,7 +603,7 @@ class RosterWindow:
big_brother_account, model=self.model)
if child_iters:
parent_iter = self.model.iter_parent(child_iters[0])
parent_type = self.model[parent_iter][C_TYPE]
parent_type = self.model[parent_iter][Column.TYPE]
# Check if the current BigBrother has even been before.
if parent_type == 'contact':
@ -629,7 +629,7 @@ class RosterWindow:
if not child_iters:
continue
parent_iter = self.model.iter_parent(child_iters[0])
parent_type = self.model[parent_iter][C_TYPE]
parent_type = self.model[parent_iter][Column.TYPE]
if parent_type != 'contact':
_contact = gajim.contacts.get_contact(_account, _jid)
self._remove_entity(_contact, _account)
@ -810,7 +810,7 @@ class RosterWindow:
self_iter = self._get_self_contact_iter(account, model=self.model)
if not self_iter:
return
self.model[self_iter][C_JID] = new_jid
self.model[self_iter][Column.JID] = new_jid
self.draw_contact(new_jid, account)
def add_groupchat(self, jid, account, status=''):
@ -1048,9 +1048,9 @@ class RosterWindow:
# the only way to create a pixbuf from stock
# tls_pixbuf = self.window.render_icon_pixbuf(
# Gtk.STOCK_DIALOG_AUTHENTICATION, Gtk.IconSize.MENU)
self.model[child_iter][C_PADLOCK_PIXBUF] = tls_pixbuf
self.model[child_iter][Column.PADLOCK_PIXBUF] = tls_pixbuf
else:
self.model[child_iter][C_PADLOCK_PIXBUF] = empty_pixbuf
self.model[child_iter][Column.PADLOCK_PIXBUF] = empty_pixbuf
if self.regroup:
account_name = _('Merged accounts')
@ -1070,34 +1070,34 @@ class RosterWindow:
accounts = accounts)
account_name += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total))
self.model[child_iter][C_NAME] = account_name
self.model[child_iter][Column.NAME] = account_name
pep_dict = gajim.connections[account].pep
if gajim.config.get('show_mood_in_roster') and 'mood' in pep_dict:
self.model[child_iter][C_MOOD_PIXBUF] = \
self.model[child_iter][Column.MOOD_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['mood'])
else:
self.model[child_iter][C_MOOD_PIXBUF] = empty_pixbuf
self.model[child_iter][Column.MOOD_PIXBUF] = empty_pixbuf
if gajim.config.get('show_activity_in_roster') and 'activity' in \
pep_dict:
self.model[child_iter][C_ACTIVITY_PIXBUF] = \
self.model[child_iter][Column.ACTIVITY_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['activity'])
else:
self.model[child_iter][C_ACTIVITY_PIXBUF] = empty_pixbuf
self.model[child_iter][Column.ACTIVITY_PIXBUF] = empty_pixbuf
if gajim.config.get('show_tunes_in_roster') and 'tune' in pep_dict:
self.model[child_iter][C_TUNE_PIXBUF] = \
self.model[child_iter][Column.TUNE_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['tune'])
else:
self.model[child_iter][C_TUNE_PIXBUF] = empty_pixbuf
self.model[child_iter][Column.TUNE_PIXBUF] = empty_pixbuf
if gajim.config.get('show_location_in_roster') and 'location' in \
pep_dict:
self.model[child_iter][C_LOCATION_PIXBUF] = \
self.model[child_iter][Column.LOCATION_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['location'])
else:
self.model[child_iter][C_LOCATION_PIXBUF] = empty_pixbuf
self.model[child_iter][Column.LOCATION_PIXBUF] = empty_pixbuf
def _really_draw_accounts(self):
for acct in self.accounts_to_draw:
@ -1130,7 +1130,7 @@ class RosterWindow:
accounts = accounts, groups = [group])
text += ' (%s/%s)' % (repr(nbr_on), repr(nbr_total))
self.model[child_iter][C_NAME] = text
self.model[child_iter][Column.NAME] = text
def _really_draw_groups(self):
for ag in self.groups_to_draw.values():
@ -1153,11 +1153,11 @@ class RosterWindow:
if not child_iters:
return False
parent_iter = self.model.iter_parent(child_iters[0])
if self.model[parent_iter][C_TYPE] != 'contact':
if self.model[parent_iter][Column.TYPE] != 'contact':
# parent is not a contact
return
parent_jid = self.model[parent_iter][C_JID]
parent_account = self.model[parent_iter][C_ACCOUNT]
parent_jid = self.model[parent_iter][Column.JID]
parent_account = self.model[parent_iter][Column.ACCOUNT]
self.draw_contact(parent_jid, parent_account)
return False
@ -1269,8 +1269,8 @@ class RosterWindow:
iterC = self.model.iter_children(child_iter)
while iterC:
# a child has awaiting messages?
jidC = self.model[iterC][C_JID]
accountC = self.model[iterC][C_ACCOUNT]
jidC = self.model[iterC][Column.JID]
accountC = self.model[iterC][Column.ACCOUNT]
if len(gajim.events.get_events(accountC, jidC)):
icon_name = 'event'
break
@ -1288,8 +1288,8 @@ class RosterWindow:
# Expand/collapse icon might differ per iter
# (group)
img = state_images[icon_name]
self.model[child_iter][C_IMG] = img
self.model[child_iter][C_NAME] = name
self.model[child_iter][Column.IMG] = img
self.model[child_iter][Column.NAME] = name
else:
# A normal contact or little brother
state_images = self.get_appropriate_state_images(jid,
@ -1298,8 +1298,8 @@ class RosterWindow:
# All iters have the same icon (no expand/collapse)
img = state_images[icon_name]
for child_iter in child_iters:
self.model[child_iter][C_IMG] = img
self.model[child_iter][C_NAME] = name
self.model[child_iter][Column.IMG] = img
self.model[child_iter][Column.NAME] = name
# We are a little brother
if family and not is_big_brother and not self.starting:
@ -1316,7 +1316,7 @@ class RosterWindow:
iterG = self._get_group_iter(g, account, model=self.model)
if iterG:
# it's not self contact
self.model[iterG][C_JID] = self.model[iterG][C_JID]
self.model[iterG][Column.JID] = self.model[iterG][Column.JID]
i += 1
gajim.plugin_manager.gui_extension_point('roster_draw_contact', self,
@ -1363,14 +1363,14 @@ class RosterWindow:
iters = self._get_contact_iter(jid, account, model=self.model)
if not iters or not gajim.config.get('show_avatars_in_roster'):
return
jid = self.model[iters[0]][C_JID]
jid = self.model[iters[0]][Column.JID]
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid)
if pixbuf in (None, 'ask'):
scaled_pixbuf = empty_pixbuf
else:
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster')
for child_iter in iters:
self.model[child_iter][C_AVATAR_PIXBUF] = scaled_pixbuf
self.model[child_iter][Column.AVATAR_PIXBUF] = scaled_pixbuf
return False
def draw_completely(self, jid, account):
@ -1513,9 +1513,9 @@ class RosterWindow:
def _readjust_expand_collapse_state(self):
def func(model, path, iter_, param):
type_ = model[iter_][C_TYPE]
acct = model[iter_][C_ACCOUNT]
jid = model[iter_][C_JID]
type_ = model[iter_][Column.TYPE]
acct = model[iter_][Column.ACCOUNT]
jid = model[iter_][Column.JID]
key = None
if type_ == 'account':
key = acct
@ -1523,9 +1523,9 @@ class RosterWindow:
key = acct + jid
elif type_ == 'contact':
parent_iter = model.iter_parent(iter_)
ptype = model[parent_iter][C_TYPE]
ptype = model[parent_iter][Column.TYPE]
if ptype == 'group':
grp = model[parent_iter][C_JID]
grp = model[parent_iter][Column.JID]
key = acct + grp + jid
if key:
if key in self.collapsed_rows:
@ -1620,18 +1620,18 @@ class RosterWindow:
"""
if self.starting_filtering:
return False
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
if not type_:
return False
if type_ == 'account':
# Always show account
return True
account = model[titer][C_ACCOUNT]
account = model[titer][Column.ACCOUNT]
if not account:
return False
jid = model[titer][C_JID]
jid = model[titer][Column.JID]
if not jid:
return False
@ -1662,7 +1662,7 @@ class RosterWindow:
return True
if self.regroup:
# C_ACCOUNT for groups depends on the order
# Column.ACCOUNT for groups depends on the order
# accounts were connected
# Check all accounts for online group contacts
accounts = gajim.contacts.get_accounts()
@ -1685,10 +1685,10 @@ class RosterWindow:
if model.iter_has_child(titer):
iter_c = model.iter_children(titer)
while iter_c:
if self.rfilter_string in model[iter_c][C_NAME].lower():
if self.rfilter_string in model[iter_c][Column.NAME].lower():
return True
iter_c = model.iter_next(iter_c)
return self.rfilter_string in model[titer][C_NAME].lower()
return self.rfilter_string in model[titer][Column.NAME].lower()
if gajim.config.get('showoffline'):
return True
bb_jid = None
@ -1713,7 +1713,7 @@ class RosterWindow:
return self.contact_is_visible(contact, account)
if type_ == 'agent':
if self.rfilter_enabled:
return self.rfilter_string in model[titer][C_NAME].lower()
return self.rfilter_string in model[titer][Column.NAME].lower()
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
return self.contact_has_pending_roster_events(contact, account) or \
@ -1721,30 +1721,30 @@ class RosterWindow:
(gajim.account_is_connected(account) or \
gajim.config.get('showoffline')))
if type_ == 'groupchat' and self.rfilter_enabled:
return self.rfilter_string in model[titer][C_NAME].lower()
return self.rfilter_string in model[titer][Column.NAME].lower()
return True
def _compareIters(self, model, iter1, iter2, data=None):
"""
Compare two iters to sort them
"""
name1 = model[iter1][C_NAME]
name2 = model[iter2][C_NAME]
name1 = model[iter1][Column.NAME]
name2 = model[iter2][Column.NAME]
if not name1 or not name2:
return 0
name1 = name1
name2 = name2
type1 = model[iter1][C_TYPE]
type2 = model[iter2][C_TYPE]
type1 = model[iter1][Column.TYPE]
type2 = model[iter2][Column.TYPE]
if type1 == 'self_contact':
return -1
if type2 == 'self_contact':
return 1
if type1 == 'group':
name1 = model[iter1][C_JID]
name1 = model[iter1][Column.JID]
if name1:
name1 = name1
name2 = model[iter2][C_JID]
name2 = model[iter2][Column.JID]
if name2:
name2 = name2
if name1 == _('Transports'):
@ -1759,16 +1759,16 @@ class RosterWindow:
return 1
if name2 == _('Groupchats'):
return -1
account1 = model[iter1][C_ACCOUNT]
account2 = model[iter2][C_ACCOUNT]
account1 = model[iter1][Column.ACCOUNT]
account2 = model[iter2][Column.ACCOUNT]
if not account1 or not account2:
return 0
account1 = account1
account2 = account2
if type1 == 'account':
return locale.strcoll(account1, account2)
jid1 = model[iter1][C_JID]
jid2 = model[iter2][C_JID]
jid1 = model[iter1][Column.JID]
jid2 = model[iter2][Column.JID]
if type1 == 'contact':
lcontact1 = gajim.contacts.get_contacts(account1, jid1)
contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
@ -2287,7 +2287,7 @@ class RosterWindow:
else:
# No need to redraw contacts if we're quitting
if child_iterA:
self.model[child_iterA][C_AVATAR_PIXBUF] = empty_pixbuf
self.model[child_iterA][Column.AVATAR_PIXBUF] = empty_pixbuf
if account in gajim.con_types:
gajim.con_types[account] = None
for jid in list(gajim.contacts.get_jid_list(account)):
@ -3049,7 +3049,7 @@ class RosterWindow:
win.redraw_tab(ctrl)
win.show_title()
elif row_type == 'group':
# in C_JID column, we hold the group name (which is not escaped)
# in Column.JID column, we hold the group name (which is not escaped)
self.rename_group(old_text, new_text, account)
def on_canceled():
@ -3327,10 +3327,10 @@ class RosterWindow:
if len(list_of_paths) != 1:
return
path = list_of_paths[0]
type_ = model[path][C_TYPE]
type_ = model[path][Column.TYPE]
if type_ in ('contact', 'group', 'agent'):
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
jid = model[path][Column.JID]
account = model[path][Column.ACCOUNT]
self.on_rename(widget, type_, jid, account)
elif event.keyval == Gdk.KEY_Delete:
@ -3338,17 +3338,17 @@ class RosterWindow:
model, list_of_paths = treeselection.get_selected_rows()
if not len(list_of_paths):
return
type_ = model[list_of_paths[0]][C_TYPE]
account = model[list_of_paths[0]][C_ACCOUNT]
type_ = model[list_of_paths[0]][Column.TYPE]
account = model[list_of_paths[0]][Column.ACCOUNT]
if type_ in ('account', 'group', 'self_contact') or \
account == gajim.ZEROCONF_ACC_NAME:
account == gajim.ZEROCONF_ACConstant.NAME:
return
list_ = []
for path in list_of_paths:
if model[path][C_TYPE] != type_:
if model[path][Column.TYPE] != type_:
return
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
jid = model[path][Column.JID]
account = model[path][Column.ACCOUNT]
if not gajim.account_is_connected(account):
continue
contact = gajim.contacts.get_contact_with_highest_priority(
@ -3462,11 +3462,11 @@ class RosterWindow:
if list_of_paths != [path]:
self.tree.get_selection().unselect_all()
self.tree.get_selection().select_path(path)
type_ = model[path][C_TYPE]
type_ = model[path][Column.TYPE]
if type_ in ('agent', 'contact', 'self_contact', 'groupchat'):
self.on_row_activated(widget, path)
elif type_ == 'account':
account = model[path][C_ACCOUNT]
account = model[path][Column.ACCOUNT]
if account != 'all':
show = gajim.connections[account].connected
if show > 1: # We are connected
@ -3491,7 +3491,7 @@ class RosterWindow:
elif event.button == 1: # Left click
model = self.modelfilter
type_ = model[path][C_TYPE]
type_ = model[path][Column.TYPE]
# x_min is the x start position of status icon column
if gajim.config.get('avatar_position_in_roster') == 'left':
x_min = gajim.config.get('roster_avatar_width')
@ -3532,9 +3532,9 @@ class RosterWindow:
iter = self.modelfilter.get_iter(path)
child_iter = self.modelfilter.iter_children(iter)
while child_iter:
type_ = self.modelfilter[child_iter][C_TYPE]
account = self.modelfilter[child_iter][C_ACCOUNT]
group = self.modelfilter[child_iter][C_JID]
type_ = self.modelfilter[child_iter][Column.TYPE]
account = self.modelfilter[child_iter][Column.ACCOUNT]
group = self.modelfilter[child_iter][Column.JID]
if type_ == 'group' and account + group not in self.collapsed_rows:
self.expand_group_row(self.modelfilter.get_path(child_iter))
child_iter = self.modelfilter.iter_next(child_iter)
@ -3940,10 +3940,10 @@ class RosterWindow:
treeselection = self.tree.get_selection()
model, list_of_paths = treeselection.get_selected_rows()
for path in list_of_paths:
type_ = model[path][C_TYPE]
type_ = model[path][Column.TYPE]
if type_ in ('contact', 'agent'):
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
jid = model[path][Column.JID]
account = model[path][Column.ACCOUNT]
contact = gajim.contacts.get_first_contact_from_jid(account,
jid)
self.on_info(widget, contact, account)
@ -3954,10 +3954,10 @@ class RosterWindow:
if len(list_of_paths) != 1:
return
path = list_of_paths[0]
type_ = model[path][C_TYPE]
type_ = model[path][Column.TYPE]
if type_ in ('contact', 'agent'):
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
jid = model[path][Column.JID]
account = model[path][Column.ACCOUNT]
contact = gajim.contacts.get_first_contact_from_jid(account,
jid)
self.on_history(widget, contact, account)
@ -3972,8 +3972,8 @@ class RosterWindow:
this way)
"""
model = self.modelfilter
account = model[path][C_ACCOUNT]
type_ = model[path][C_TYPE]
account = model[path][Column.ACCOUNT]
type_ = model[path][Column.TYPE]
if type_ in ('group', 'account'):
if self.tree.row_expanded(path):
self.tree.collapse_row(path)
@ -3982,7 +3982,7 @@ class RosterWindow:
return
if self.rfilter_enabled:
GObject.idle_add(self.disable_rfilter)
jid = model[path][C_JID]
jid = model[path][Column.JID]
resource = None
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
titer = model.get_iter(path)
@ -4009,7 +4009,7 @@ class RosterWindow:
if not first_ev and model.iter_has_child(titer):
child_iter = model.iter_children(titer)
while not first_ev and child_iter:
child_jid = model[child_iter][C_JID]
child_jid = model[child_iter][Column.JID]
first_ev = gajim.events.get_first_event(account, child_jid)
if first_ev:
jid = child_jid
@ -4054,12 +4054,12 @@ class RosterWindow:
if self.regroup: # merged accounts
accounts = list(gajim.connections.keys())
else:
accounts = [model[titer][C_ACCOUNT]]
accounts = [model[titer][Column.ACCOUNT]]
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
if type_ == 'group':
group = model[titer][C_JID]
child_model[child_iter][C_IMG] = \
group = model[titer][Column.JID]
child_model[child_iter][Column.IMG] = \
gajim.interface.jabber_state_images['16']['opened']
if self.rfilter_enabled:
return
@ -4091,8 +4091,8 @@ class RosterWindow:
self.tree.expand_row(path, False)
elif type_ == 'contact':
# Metacontact got toggled, update icon
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
contact = gajim.contacts.get_contact(account, jid)
for group in contact.groups:
if account + group + jid in self.collapsed_rows:
@ -4118,15 +4118,15 @@ class RosterWindow:
if self.regroup: # merged accounts
accounts = list(gajim.connections.keys())
else:
accounts = [model[titer][C_ACCOUNT]]
accounts = [model[titer][Column.ACCOUNT]]
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
if type_ == 'group':
child_model[child_iter][C_IMG] = gajim.interface.\
child_model[child_iter][Column.IMG] = gajim.interface.\
jabber_state_images['16']['closed']
if self.rfilter_enabled:
return
group = model[titer][C_JID]
group = model[titer][Column.JID]
for account in accounts:
if group in gajim.groups[account]: # This account has this group
gajim.groups[account][group]['expand'] = False
@ -4139,8 +4139,8 @@ class RosterWindow:
self.draw_account(account)
elif type_ == 'contact':
# Metacontact got toggled, update icon
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
contact = gajim.contacts.get_contact(account, jid)
groups = contact.groups
if not groups:
@ -4167,8 +4167,8 @@ class RosterWindow:
# Signal is emitted when we write to our model
return
type_ = model[titer][C_TYPE]
account = model[titer][C_ACCOUNT]
type_ = model[titer][Column.TYPE]
account = model[titer][Column.ACCOUNT]
if not account:
return
@ -4179,10 +4179,10 @@ class RosterWindow:
# redraw us to show/hide expand icon
if self.filtering:
# Prevent endless loops
jid = model[titer][C_JID]
jid = model[titer][Column.JID]
GLib.idle_add(self.draw_contact, jid, account)
elif type_ == 'group':
group = model[titer][C_JID]
group = model[titer][Column.JID]
GLib.idle_add(self._adjust_group_expand_collapse_state, group, account)
elif type_ == 'account':
GLib.idle_add(self._adjust_account_expand_collapse_state, account)
@ -4209,11 +4209,11 @@ class RosterWindow:
# return
# for path in list_of_paths:
# row = model[path]
# if row[C_TYPE] != 'contact':
# if row[Column.TYPE] != 'contact':
# self._last_selected_contact = []
# return
# jid = row[C_JID]
# account = row[C_ACCOUNT]
# jid = row[Column.JID]
# account = row[Column.ACCOUNT]
# self._last_selected_contact.append((jid, account))
# GLib.idle_add(self.draw_contact, jid, account, True)
@ -4283,8 +4283,8 @@ class RosterWindow:
# select first row
self.tree.get_selection().unselect_all()
def _func(model, path, iter_, param):
if model[iter_][C_TYPE] == 'contact' and self.rfilter_string in \
model[iter_][C_NAME].lower():
if model[iter_][Column.TYPE] == 'contact' and self.rfilter_string in \
model[iter_][Column.NAME].lower():
col = self.tree.get_column(0)
self.tree.set_cursor_on_cell(path, col, None, False)
return True
@ -4361,7 +4361,7 @@ class RosterWindow:
path = list_of_paths[0]
data = ''
if path.get_depth() >= 2:
data = model[path][C_JID]
data = model[path][Column.JID]
selection.set_text(data, -1)
def drag_begin(self, treeview, context):
@ -4570,9 +4570,9 @@ class RosterWindow:
path_dest = (path_dest[0], path_dest[1]-1)
# destination: the row something got dropped on
iter_dest = model.get_iter(path_dest)
type_dest = model[iter_dest][C_TYPE]
jid_dest = model[iter_dest][C_JID]
account_dest = model[iter_dest][C_ACCOUNT]
type_dest = model[iter_dest][Column.TYPE]
jid_dest = model[iter_dest][Column.JID]
account_dest = model[iter_dest][Column.ACCOUNT]
# drop on account row in merged mode, we cannot know the desired account
if account_dest == 'all':
@ -4635,8 +4635,8 @@ class RosterWindow:
# source: the row that was dragged
path_source = treeview.get_selection().get_selected_rows()[1][0]
iter_source = model.get_iter(path_source)
type_source = model[iter_source][C_TYPE]
account_source = model[iter_source][C_ACCOUNT]
type_source = model[iter_source][Column.TYPE]
account_source = model[iter_source][Column.ACCOUNT]
if gajim.config.get_per('accounts', account_source, 'is_zeroconf'):
return
@ -4654,18 +4654,18 @@ class RosterWindow:
if account_source != account_dest:
# drop on another account
return
grp_source = model[iter_source][C_JID]
grp_source = model[iter_source][Column.JID]
delimiter = gajim.connections[account_source].nested_group_delimiter
grp_source_list = grp_source.split(delimiter)
new_grp = None
if type_dest == 'account':
new_grp = grp_source_list[-1]
elif type_dest == 'group':
grp_dest = model[iter_dest][C_JID]
grp_dest = model[iter_dest][Column.JID]
grp_dest_list = grp_dest.split(delimiter)
# Do not allow to drop on a subgroup of source group
if grp_source_list[0] != grp_dest_list[0]:
new_grp = model[iter_dest][C_JID] + delimiter + \
new_grp = model[iter_dest][Column.JID] + delimiter + \
grp_source_list[-1]
if new_grp:
self.move_group(grp_source, new_grp, account_source)
@ -4685,9 +4685,9 @@ class RosterWindow:
# Get valid source group, jid and contact
it = iter_source
while model[it][C_TYPE] == 'contact':
while model[it][Column.TYPE] == 'contact':
it = model.iter_parent(it)
grp_source = model[it][C_JID]
grp_source = model[it][Column.JID]
if grp_source in helpers.special_groups and \
grp_source not in ('Not in Roster', 'Observers'):
# a transport or a minimized groupchat was dragged
@ -4701,12 +4701,12 @@ class RosterWindow:
# Get destination group
grp_dest = None
if type_dest == 'group':
grp_dest = model[iter_dest][C_JID]
grp_dest = model[iter_dest][Column.JID]
elif type_dest in ('contact', 'agent'):
it = iter_dest
while model[it][C_TYPE] != 'group':
while model[it][Column.TYPE] != 'group':
it = model.iter_parent(it)
grp_dest = model[it][C_JID]
grp_dest = model[it][Column.JID]
if grp_dest in helpers.special_groups:
return
@ -4865,7 +4865,7 @@ class RosterWindow:
show = gajim.SHOW_LIST[status]
else: # accounts merged
show = helpers.get_global_show()
self.model[child_iterA][C_IMG] = gajim.interface.jabber_state_images[
self.model[child_iterA][Column.IMG] = gajim.interface.jabber_state_images[
'16'][show]
################################################################################
@ -4906,9 +4906,9 @@ class RosterWindow:
gtkgui_helpers.set_unset_urgency_hint(self.window, nb_unread)
def _change_style(self, model, path, titer, option):
if option is None or model[titer][C_TYPE] == option:
if option is None or model[titer][Column.TYPE] == option:
# We changed style for this type of row
model[titer][C_NAME] = model[titer][C_NAME]
model[titer][Column.NAME] = model[titer][Column.NAME]
def change_roster_style(self, option):
self.model.foreach(self._change_style, option)
@ -4954,7 +4954,7 @@ class RosterWindow:
When a row is added, set properties for icon renderer
"""
try:
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
except TypeError:
return
if type_ == 'account':
@ -4963,20 +4963,20 @@ class RosterWindow:
elif type_ == 'group':
self._set_group_row_background_color(renderer)
parent_iter = model.iter_parent(titer)
if model[parent_iter][C_TYPE] == 'group':
if model[parent_iter][Column.TYPE] == 'group':
renderer.set_property('xalign', 0.4)
else:
renderer.set_property('xalign', 0.2)
elif type_:
# prevent type_ = None, see http://trac.gajim.org/ticket/2534
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
if not model[titer][Column.JID] or not model[titer][Column.ACCOUNT]:
# This can append when at the moment we add the row
return
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
parent_iter = model.iter_parent(titer)
if model[parent_iter][C_TYPE] == 'contact':
if model[parent_iter][Column.TYPE] == 'contact':
renderer.set_property('xalign', 1)
else:
renderer.set_property('xalign', 0.6)
@ -4987,7 +4987,7 @@ class RosterWindow:
When a row is added, set properties for name renderer
"""
try:
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
except TypeError:
return
theme = gajim.config.get('roster_theme')
@ -5011,18 +5011,18 @@ class RosterWindow:
renderer.set_property('font',
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
parent_iter = model.iter_parent(titer)
if model[parent_iter][C_TYPE] == 'group':
if model[parent_iter][Column.TYPE] == 'group':
renderer.set_property('xpad', 8)
else:
renderer.set_property('xpad', 4)
self._set_group_row_background_color(renderer)
elif type_:
# prevent type_ = None, see http://trac.gajim.org/ticket/2534
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
if not model[titer][Column.JID] or not model[titer][Column.ACCOUNT]:
# This can append when at the moment we add the row
return
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
color = None
if type_ == 'groupchat':
ctrl = gajim.interface.minimized_controls[account].get(jid,
@ -5042,7 +5042,7 @@ class RosterWindow:
renderer.set_property('font',
gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont'))
parent_iter = model.iter_parent(titer)
if model[parent_iter][C_TYPE] == 'contact':
if model[parent_iter][Column.TYPE] == 'contact':
renderer.set_property('xpad', 16)
else:
renderer.set_property('xpad', 12)
@ -5053,7 +5053,7 @@ class RosterWindow:
When a row is added, draw the respective pep icon
"""
try:
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
except TypeError:
return
@ -5067,11 +5067,11 @@ class RosterWindow:
self._set_account_row_background_color(renderer)
renderer.set_property('xalign', 1)
elif type_:
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
if not model[titer][Column.JID] or not model[titer][Column.ACCOUNT]:
# This can append at the moment we add the row
return
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer,
@ -5080,7 +5080,7 @@ class RosterWindow:
When a row is added, set properties for avatar renderer
"""
try:
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
except TypeError:
return
@ -5089,20 +5089,20 @@ class RosterWindow:
return
# allocate space for the icon only if needed
if model[titer][C_AVATAR_PIXBUF] or \
if model[titer][Column.AVATAR_PIXBUF] or \
gajim.config.get('avatar_position_in_roster') == 'left':
renderer.set_property('visible', True)
if type_:
# prevent type_ = None, see http://trac.gajim.org/ticket/2534
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
if not model[titer][Column.JID] or not model[titer][Column.ACCOUNT]:
# This can append at the moment we add the row
return
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
else:
renderer.set_property('visible', False)
if model[titer][C_AVATAR_PIXBUF] == empty_pixbuf and \
if model[titer][Column.AVATAR_PIXBUF] == empty_pixbuf and \
gajim.config.get('avatar_position_in_roster') != 'left':
renderer.set_property('visible', False)
@ -5119,12 +5119,12 @@ class RosterWindow:
When a row is added, set properties for padlock renderer
"""
try:
type_ = model[titer][C_TYPE]
type_ = model[titer][Column.TYPE]
except TypeError:
return
# allocate space for the icon only if needed
if type_ == 'account' and model[titer][C_PADLOCK_PIXBUF]:
if type_ == 'account' and model[titer][Column.PADLOCK_PIXBUF]:
renderer.set_property('visible', True)
self._set_account_row_background_color(renderer)
renderer.set_property('xalign', 1) # align pixbuf to the right
@ -5596,7 +5596,7 @@ class RosterWindow:
Make account's popup menu
"""
model = self.modelfilter
account = model[titer][C_ACCOUNT]
account = model[titer][Column.ACCOUNT]
if account != 'all': # not in merged mode
menu = self.build_account_menu(account)
@ -5627,14 +5627,14 @@ class RosterWindow:
"""
model = self.modelfilter
path = model.get_path(titer)
group = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
group = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
list_ = [] # list of (contact, account) tuples
list_online = [] # list of (contact, account) tuples
show_bookmarked = True
group = model[titer][C_JID]
group = model[titer][Column.JID]
for jid in gajim.contacts.get_jid_list(account):
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
@ -5773,8 +5773,8 @@ class RosterWindow:
Make contact's popup menu
"""
model = self.modelfilter
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = gui_menu_builder.get_contact_menu(contact, account)
event_button = gtkgui_helpers.get_possible_button_event(event)
@ -5791,8 +5791,8 @@ class RosterWindow:
is_blocked = True
privacy_rules_supported = True
for titer in iters:
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
if gajim.connections[account].connected < 2:
one_account_offline = True
if not gajim.connections[account].privacy_rules_supported:
@ -5881,9 +5881,9 @@ class RosterWindow:
Make transport's popup menu
"""
model = self.modelfilter
jid = model[titer][C_JID]
jid = model[titer][Column.JID]
path = model.get_path(titer)
account = model[titer][C_ACCOUNT]
account = model[titer][Column.ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = gui_menu_builder.get_transport_menu(contact, account)
event_button = gtkgui_helpers.get_possible_button_event(event)
@ -5893,8 +5893,8 @@ class RosterWindow:
def make_groupchat_menu(self, event, titer):
model = self.modelfilter
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = Gtk.Menu()
@ -6063,9 +6063,9 @@ class RosterWindow:
def show_appropriate_context_menu(self, event, iters):
# iters must be all of the same type
model = self.modelfilter
type_ = model[iters[0]][C_TYPE]
type_ = model[iters[0]][Column.TYPE]
for titer in iters[1:]:
if model[titer][C_TYPE] != type_:
if model[titer][Column.TYPE] != type_:
return
if type_ == 'group' and len(iters) == 1:
self.make_group_menu(event, iters[0])
@ -6137,9 +6137,9 @@ class RosterWindow:
except Exception:
return False
typ = model[iter_][C_TYPE]
account = model[iter_][C_ACCOUNT]
jid = model[iter_][C_JID]
typ = model[iter_][Column.TYPE]
account = model[iter_][Column.ACCOUNT]
jid = model[iter_][Column.JID]
connected_contacts = []
if typ in ('contact', 'self_contact'):
@ -6340,9 +6340,9 @@ class RosterWindow:
# cell_data_func, func_arg)
self.renderers_list = []
self.renderers_propertys ={}
self._pep_type_to_model_column = {'mood': C_MOOD_PIXBUF,
'activity': C_ACTIVITY_PIXBUF, 'tune': C_TUNE_PIXBUF,
'location': C_LOCATION_PIXBUF}
self._pep_type_to_model_column = {'mood': Column.MOOD_PIXBUF,
'activity': Column.ACTIVITY_PIXBUF, 'tune': Column.TUNE_PIXBUF,
'location': Column.LOCATION_PIXBUF}
renderer_text = Gtk.CellRendererText()
self.renderers_propertys[renderer_text] = ('ellipsize',
@ -6350,7 +6350,7 @@ class RosterWindow:
def add_avatar_renderer():
self.renderers_list.append(('avatar', Gtk.CellRendererPixbuf(),
False, 'pixbuf', C_AVATAR_PIXBUF,
False, 'pixbuf', Column.AVATAR_PIXBUF,
self._fill_avatar_pixbuf_renderer, None))
if gajim.config.get('avatar_position_in_roster') == 'left':
@ -6358,32 +6358,32 @@ class RosterWindow:
self.renderers_list += (
('icon', cell_renderer_image.CellRendererImage(0, 0), False,
'image', C_IMG, self._iconCellDataFunc, None),
'image', Column.IMG, self._iconCellDataFunc, None),
('name', renderer_text, True,
'markup', C_NAME, self._nameCellDataFunc, None),
'markup', Column.NAME, self._nameCellDataFunc, None),
('mood', Gtk.CellRendererPixbuf(), False,
'pixbuf', C_MOOD_PIXBUF,
self._fill_pep_pixbuf_renderer, C_MOOD_PIXBUF),
'pixbuf', Column.MOOD_PIXBUF,
self._fill_pep_pixbuf_renderer, Column.MOOD_PIXBUF),
('activity', Gtk.CellRendererPixbuf(), False,
'pixbuf', C_ACTIVITY_PIXBUF,
self._fill_pep_pixbuf_renderer, C_ACTIVITY_PIXBUF),
'pixbuf', Column.ACTIVITY_PIXBUF,
self._fill_pep_pixbuf_renderer, Column.ACTIVITY_PIXBUF),
('tune', Gtk.CellRendererPixbuf(), False,
'pixbuf', C_TUNE_PIXBUF,
self._fill_pep_pixbuf_renderer, C_TUNE_PIXBUF),
'pixbuf', Column.TUNE_PIXBUF,
self._fill_pep_pixbuf_renderer, Column.TUNE_PIXBUF),
('location', Gtk.CellRendererPixbuf(), False,
'pixbuf', C_LOCATION_PIXBUF,
self._fill_pep_pixbuf_renderer, C_LOCATION_PIXBUF))
'pixbuf', Column.LOCATION_PIXBUF,
self._fill_pep_pixbuf_renderer, Column.LOCATION_PIXBUF))
if gajim.config.get('avatar_position_in_roster') == 'right':
add_avatar_renderer()
self.renderers_list.append(('padlock', Gtk.CellRendererPixbuf(), False,
'pixbuf', C_PADLOCK_PIXBUF,
'pixbuf', Column.PADLOCK_PIXBUF,
self._fill_padlock_pixbuf_renderer, None))
# fill and append column