Commit 2fbadc91 authored by Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot

Use Enum or IntEnum instead of range() constants.

parent b6b1a7a0
......@@ -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
......
......@@ -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()
......
......@@ -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
......
......@@ -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()
......@@ -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
......
......@@ -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
"""
......
This diff is collapsed.
......@@ -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'
......
......@@ -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:
......
......@@ -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)
......
......@@ -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:
......
This diff is collapsed.
This diff is collapsed.
......@@ -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)
......
......@@ -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
constants = Constants()
from common.logger import ShowConstant, KindConstant
# Completion dict
(
C_INFO_JID,
C_INFO_ACCOUNT,
C_INFO_NAME,
C_INFO_COMPLETION
) = range(4)
class InfoColumn(IntEnum):
'''Completion dict'''
JID = 0
ACCOUNT = 1
NAME = 2
COMPLETION = 3
# 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.