Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/gtk/start_chat.py
    ... ... @@ -20,8 +20,9 @@ from gi.repository import Gtk
    20 20
     from gi.repository import GLib
    
    21 21
     from gi.repository import Pango
    
    22 22
     
    
    23
    -from nbxmpp.util import is_error_result
    
    23
    +from nbxmpp.errors import is_error
    
    24 24
     from nbxmpp.errors import StanzaError
    
    25
    +from nbxmpp.errors import CancelledError
    
    25 26
     
    
    26 27
     from gajim.common import app
    
    27 28
     from gajim.common.helpers import validate_jid
    
    ... ... @@ -32,11 +33,11 @@ from gajim.common.i18n import _
    32 33
     from gajim.common.i18n import get_rfc5646_lang
    
    33 34
     from gajim.common.const import AvatarSize
    
    34 35
     from gajim.common.const import MUC_DISCO_ERRORS
    
    36
    +from gajim.common.modules.util import as_task
    
    35 37
     
    
    36 38
     from gajim.gtk.groupchat_info import GroupChatInfoScrolled
    
    37 39
     from gajim.gtk.groupchat_nick import NickChooser
    
    38 40
     from gajim.gtk.util import get_builder
    
    39
    -from gajim.gtk.util import ensure_not_destroyed
    
    40 41
     from gajim.gtk.util import get_icon_name
    
    41 42
     from gajim.gtk.util import generate_account_badge
    
    42 43
     
    
    ... ... @@ -307,7 +308,6 @@ class StartChatDialog(Gtk.ApplicationWindow):
    307 308
                 callback=self._disco_info_received,
    
    308 309
                 user_data=account)
    
    309 310
     
    
    310
    -    @ensure_not_destroyed
    
    311 311
         def _disco_info_received(self, task):
    
    312 312
             try:
    
    313 313
                 result = task.finish()
    
    ... ... @@ -527,85 +527,79 @@ class StartChatDialog(Gtk.ApplicationWindow):
    527 527
             else:
    
    528 528
                 self._start_iq_search(con, text)
    
    529 529
     
    
    530
    +    @as_task
    
    530 531
         def _start_iq_search(self, con, text):
    
    532
    +        _task = yield
    
    533
    +
    
    531 534
             if self._parameter_form is None:
    
    532
    -            con.get_module('Muclumbus').request_parameters(
    
    533
    -                app.settings.get('muclumbus_api_jid'),
    
    534
    -                callback=self._parameters_received,
    
    535
    -                user_data=(con, text))
    
    536
    -        else:
    
    537
    -            self._parameter_form.vars['q'].value = text
    
    535
    +            result = yield con.get_module('Muclumbus').request_parameters(
    
    536
    +                app.settings.get('muclumbus_api_jid'))
    
    537
    +
    
    538
    +            self._process_search_result(result, parameters=True)
    
    538 539
     
    
    539
    -            con.get_module('Muclumbus').set_search(
    
    540
    +            self._parameter_form = result
    
    541
    +            self._parameter_form.type_ = 'submit'
    
    542
    +
    
    543
    +        self._parameter_form.vars['q'].value = text
    
    544
    +
    
    545
    +        result = yield con.get_module('Muclumbus').set_search(
    
    546
    +            app.settings.get('muclumbus_api_jid'),
    
    547
    +            self._parameter_form)
    
    548
    +
    
    549
    +        self._process_search_result(result)
    
    550
    +
    
    551
    +        while not result.end:
    
    552
    +            result = yield con.get_module('Muclumbus').set_search(
    
    540 553
                     app.settings.get('muclumbus_api_jid'),
    
    541 554
                     self._parameter_form,
    
    542
    -                callback=self._on_search_result,
    
    543
    -                user_data=(con, False))
    
    555
    +                items_per_page=result.max,
    
    556
    +                after=result.last)
    
    557
    +
    
    558
    +            self._process_search_result(result)
    
    544 559
     
    
    560
    +        self._global_search_listbox.end_search()
    
    561
    +
    
    562
    +    @as_task
    
    545 563
         def _start_http_search(self, con, text):
    
    564
    +        _task = yield
    
    565
    +
    
    546 566
             self._keywords = text.split(' ')
    
    547
    -        con.get_module('Muclumbus').set_http_search(
    
    567
    +        result = yield con.get_module('Muclumbus').set_http_search(
    
    548 568
                 app.settings.get('muclumbus_api_http_uri'),
    
    549
    -            self._keywords,
    
    550
    -            callback=self._on_search_result,
    
    551
    -            user_data=(con, True))
    
    569
    +            self._keywords)
    
    552 570
     
    
    553
    -    @ensure_not_destroyed
    
    554
    -    def _parameters_received(self, result, user_data):
    
    555
    -        if is_error_result(result):
    
    556
    -            self._global_search_listbox.remove_progress()
    
    557
    -            self._show_error_page(to_user_string(result))
    
    558
    -            return
    
    571
    +        self._process_search_result(result)
    
    572
    +
    
    573
    +        while not result.end:
    
    574
    +            result = yield con.get_module('Muclumbus').set_http_search(
    
    575
    +                app.settings.get('muclumbus_api_http_uri'),
    
    576
    +                self._keywords,
    
    577
    +                after=result.last)
    
    578
    +
    
    579
    +            self._process_search_result(result)
    
    559 580
     
    
    560
    -        con, text = user_data
    
    561
    -        self._parameter_form = result
    
    562
    -        self._parameter_form.type_ = 'submit'
    
    563
    -        self._start_iq_search(con, text)
    
    581
    +        self._global_search_listbox.end_search()
    
    564 582
     
    
    565
    -    @ensure_not_destroyed
    
    566
    -    def _on_search_result(self, result, user_data):
    
    583
    +    def _process_search_result(self, result, parameters=False):
    
    567 584
             if self._search_stopped:
    
    568
    -            return
    
    585
    +            raise CancelledError()
    
    569 586
     
    
    570
    -        if is_error_result(result):
    
    587
    +        if is_error(result):
    
    571 588
                 self._global_search_listbox.remove_progress()
    
    572 589
                 self._show_error_page(to_user_string(result))
    
    590
    +            raise result
    
    591
    +
    
    592
    +        if parameters:
    
    573 593
                 return
    
    574 594
     
    
    575 595
             for item in result.items:
    
    576 596
                 self._global_search_listbox.add(ResultRow(item))
    
    577 597
     
    
    578
    -        if result.end:
    
    579
    -            self._global_search_listbox.end_search()
    
    580
    -            return
    
    581
    -
    
    582
    -        con, http = user_data
    
    583
    -        if http:
    
    584
    -            self._continue_http_search(result, con)
    
    585
    -        else:
    
    586
    -            self._continue_iq_search(result, con)
    
    587
    -
    
    588
    -    def _continue_iq_search(self, result, con):
    
    589
    -        con.get_module('Muclumbus').set_search(
    
    590
    -            app.settings.get('muclumbus_api_jid'),
    
    591
    -            self._parameter_form,
    
    592
    -            items_per_page=result.max,
    
    593
    -            after=result.last,
    
    594
    -            callback=self._on_search_result,
    
    595
    -            user_data=(con, False))
    
    596
    -
    
    597
    -    def _continue_http_search(self, result, con):
    
    598
    -        con.get_module('Muclumbus').set_http_search(
    
    599
    -            app.settings.get('muclumbus_api_http_uri'),
    
    600
    -            self._keywords,
    
    601
    -            after=result.last,
    
    602
    -            callback=self._on_search_result,
    
    603
    -            user_data=(con, True))
    
    604
    -
    
    605 598
         def _destroy(self, *args):
    
    606 599
             if self._source_id is not None:
    
    607 600
                 GLib.source_remove(self._source_id)
    
    608 601
             self._destroyed = True
    
    602
    +        app.cancel_tasks(self)
    
    609 603
     
    
    610 604
     
    
    611 605
     class ContactRow(Gtk.ListBoxRow):