Check if path is None

This commit is contained in:
Philipp Hörist 2018-09-24 23:46:25 +02:00
parent 45e03c2545
commit 7c45943d20
1 changed files with 21 additions and 10 deletions

View File

@ -23,16 +23,23 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>. # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from typing import Optional
import time import time
import locale import locale
import base64 import base64
import logging
from enum import IntEnum, unique
import nbxmpp
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
from gi.repository import Pango from gi.repository import Pango
from gi.repository import GLib from gi.repository import GLib
from gi.repository import Gio from gi.repository import Gio
from gajim import gtkgui_helpers from gajim import gtkgui_helpers
from gajim import gui_menu_builder from gajim import gui_menu_builder
from gajim import message_control from gajim import message_control
@ -44,10 +51,6 @@ from gajim import adhoc_commands
from gajim.gtk import AddNewContactWindow from gajim.gtk import AddNewContactWindow
from gajim.common.const import AvatarSize from gajim.common.const import AvatarSize
from gajim.common.caps_cache import muc_caps_cache from gajim.common.caps_cache import muc_caps_cache
import nbxmpp
from enum import IntEnum, unique
from gajim.common import events from gajim.common import events
from gajim.common import app from gajim.common import app
from gajim.common import helpers from gajim.common import helpers
@ -56,7 +59,6 @@ from gajim.common import ged
from gajim.common import i18n from gajim.common import i18n
from gajim.common import contacts from gajim.common import contacts
from gajim.common.const import StyleAttr from gajim.common.const import StyleAttr
from gajim.chat_control import ChatControl from gajim.chat_control import ChatControl
from gajim.chat_control_base import ChatControlBase from gajim.chat_control_base import ChatControlBase
from gajim.gtk.filechoosers import AvatarChooserDialog from gajim.gtk.filechoosers import AvatarChooserDialog
@ -72,7 +74,6 @@ from gajim.command_system.implementation.hosts import GroupChatCommands
from gajim.common.connection_handlers_events import GcMessageOutgoingEvent from gajim.common.connection_handlers_events import GcMessageOutgoingEvent
import logging
log = logging.getLogger('gajim.groupchat_control') log = logging.getLogger('gajim.groupchat_control')
@unique @unique
@ -1299,13 +1300,18 @@ class GroupchatControl(ChatControlBase):
if contact: if contact:
app.interface.roster.draw_contact(self.room_jid, self.account) app.interface.roster.draw_contact(self.room_jid, self.account)
def get_contact_iter(self, nick): def get_contact_iter(self, nick: str) -> Optional[Gtk.TreeIter]:
try: try:
ref = self._contact_refs[nick] ref = self._contact_refs[nick]
return self.model.get_iter(ref.get_path())
except KeyError: except KeyError:
return None return None
path = ref.get_path()
if path is None:
return None
return self.model.get_iter(path)
def print_old_conversation(self, text, contact='', tim=None, xhtml=None, def print_old_conversation(self, text, contact='', tim=None, xhtml=None,
displaymarking=None, msg_stanza_id=None, encrypted=None, additional_data=None): displaymarking=None, msg_stanza_id=None, encrypted=None, additional_data=None):
if additional_data is None: if additional_data is None:
@ -2092,13 +2098,18 @@ class GroupchatControl(ChatControlBase):
self.draw_banner_text() self.draw_banner_text()
return iter_ return iter_
def get_role_iter(self, role): def get_role_iter(self, role: str) -> Optional[Gtk.TreeIter]:
try: try:
ref = self._role_refs[role] ref = self._role_refs[role]
return self.model.get_iter(ref.get_path())
except KeyError: except KeyError:
return None return None
path = ref.get_path()
if path is None:
return None
return self.model.get_iter(path)
def remove_contact(self, nick): def remove_contact(self, nick):
""" """
Remove a user from the contacts_list Remove a user from the contacts_list