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

Commits:

12 changed files:

Changes:

  • gajim/common/application.py
    ... ... @@ -50,6 +50,8 @@
    50 50
     from gajim.common.client import Client
    
    51 51
     from gajim.common.helpers import make_http_request
    
    52 52
     from gajim.common.helpers import get_random_string
    
    53
    +from gajim.common.helpers import get_global_show
    
    54
    +from gajim.common.helpers import from_one_line
    
    53 55
     from gajim.common.storage.events import EventStorage
    
    54 56
     from gajim.common.task_manager import TaskManager
    
    55 57
     from gajim.common.settings import Settings
    
    ... ... @@ -59,6 +61,9 @@
    59 61
     from gajim.common.storage.draft import DraftStorage
    
    60 62
     from gajim.common.storage.archive import MessageArchiveStorage
    
    61 63
     
    
    64
    +from gajim.plugins import PluginManager
    
    65
    +from gajim.plugins.repository import PluginRepository
    
    66
    +
    
    62 67
     
    
    63 68
     class CoreApplication(ged.EventHelper):
    
    64 69
         def __init__(self) -> None:
    
    ... ... @@ -113,6 +118,15 @@ def _init_core(self) -> None:
    113 118
             for account in app.settings.get_active_accounts():
    
    114 119
                 app.connections[account] = Client(account)
    
    115 120
     
    
    121
    +        app.plugin_manager = PluginManager()
    
    122
    +        app.plugin_manager.init_plugins()
    
    123
    +        app.plugin_repository = PluginRepository()
    
    124
    +
    
    125
    +        for client in app.get_clients():
    
    126
    +            client.get_module('Roster').load_roster()
    
    127
    +
    
    128
    +        GLib.timeout_add_seconds(5, self._remote_init)
    
    129
    +
    
    116 130
             self.register_events([
    
    117 131
                 ('signed-in', ged.CORE, self._on_signed_in),
    
    118 132
             ])
    
    ... ... @@ -153,6 +167,35 @@ def _core_command_line(self, options: GLib.VariantDict) -> None:
    153 167
             if options.contains('warnings'):
    
    154 168
                 self._show_warnings()
    
    155 169
     
    
    170
    +    def _auto_connect(self) -> None:
    
    171
    +        for client in app.get_clients():
    
    172
    +            account = client.account
    
    173
    +            if not app.settings.get_account_setting(account,
    
    174
    +                                                    'autoconnect'):
    
    175
    +                continue
    
    176
    +
    
    177
    +            status = 'online'
    
    178
    +            status_message = ''
    
    179
    +
    
    180
    +            if app.settings.get_account_setting(account, 'restore_last_status'):
    
    181
    +                status = app.settings.get_account_setting(
    
    182
    +                    account, 'last_status')
    
    183
    +                status_message = app.settings.get_account_setting(
    
    184
    +                    account, 'last_status_msg')
    
    185
    +                status_message = from_one_line(status_message)
    
    186
    +
    
    187
    +            client.change_status(status, status_message)
    
    188
    +
    
    189
    +    def _remote_init(self) -> None:
    
    190
    +        if not app.settings.get('remote_control'):
    
    191
    +            return
    
    192
    +
    
    193
    +        try:
    
    194
    +            from gajim.common.dbus import remote_control
    
    195
    +            remote_control.GajimRemote()
    
    196
    +        except Exception:
    
    197
    +            self._log.exception('Failed to init remote control')
    
    198
    +
    
    156 199
         def start_profiling(self) -> None:
    
    157 200
             self._log.info('Start profiling')
    
    158 201
             self._profiling_session = cProfile.Profile()
    
    ... ... @@ -376,3 +419,34 @@ def _on_signed_in(self, event: SignedIn) -> None:
    376 419
     
    
    377 420
             if client.get_module('MAM').available:
    
    378 421
                 client.get_module('MAM').request_archive_on_signin()
    
    422
    +
    
    423
    +    def change_status(self,
    
    424
    +                      status: str,
    
    425
    +                      account: Optional[str] = None
    
    426
    +                      ) -> None:
    
    427
    +
    
    428
    +        if status is None:
    
    429
    +            status = get_global_show()
    
    430
    +
    
    431
    +        if account is not None:
    
    432
    +            self._change_status(account, status)
    
    433
    +            return
    
    434
    +
    
    435
    +        for client in app.get_clients():
    
    436
    +            if not app.settings.get_account_setting(client.account,
    
    437
    +                                                    'sync_with_global_status'):
    
    438
    +                continue
    
    439
    +
    
    440
    +            self._change_status(client.account, status)
    
    441
    +
    
    442
    +    @staticmethod
    
    443
    +    def _change_status(account: str, status: str) -> None:
    
    444
    +        client = app.get_client(account)
    
    445
    +        message = client.status_message
    
    446
    +
    
    447
    +        if status == 'offline':
    
    448
    +            # TODO delete pep
    
    449
    +            # self.delete_pep(app.get_jid_from_account(account), account)
    
    450
    +            pass
    
    451
    +
    
    452
    +        client.change_status(status, message)

  • gajim/common/config.py
    ... ... @@ -415,7 +415,6 @@ def set(self, optname, value):
    415 415
                 return
    
    416 416
     
    
    417 417
             self.__options[1][optname] = value
    
    418
    -        self._timeout_save()
    
    419 418
     
    
    420 419
         def get(self, optname=None):
    
    421 420
             if not optname:
    
    ... ... @@ -457,7 +456,6 @@ def add_per(self, typename, name): # per_group_of_option
    457 456
             opt[1][name] = {}
    
    458 457
             for o in opt[0]:
    
    459 458
                 opt[1][name][o] = opt[0][o][Option.VAL]
    
    460
    -        self._timeout_save()
    
    461 459
     
    
    462 460
         def del_per(self, typename, name, subname=None): # per_group_of_option
    
    463 461
             if typename not in self.__options_per_key:
    
    ... ... @@ -469,7 +467,6 @@ def del_per(self, typename, name, subname=None): # per_group_of_option
    469 467
             # if subname is specified, delete the item in the group.
    
    470 468
             elif subname in opt[1][name]:
    
    471 469
                 del opt[1][name][subname]
    
    472
    -        self._timeout_save()
    
    473 470
     
    
    474 471
         def del_all_per(self, typename, subname):
    
    475 472
             # Deletes all settings per typename
    
    ... ... @@ -483,7 +480,6 @@ def del_all_per(self, typename, subname):
    483 480
                     del opt[1][name][subname]
    
    484 481
                 except KeyError:
    
    485 482
                     pass
    
    486
    -        self._timeout_save()
    
    487 483
     
    
    488 484
         def set_per(self, optname, key, subname, value): # per_group_of_option
    
    489 485
             if optname not in self.__options_per_key:
    
    ... ... @@ -501,7 +497,6 @@ def set_per(self, optname, key, subname, value): # per_group_of_option
    501 497
             if value is None:
    
    502 498
                 return
    
    503 499
             obj[subname] = value
    
    504
    -        self._timeout_save()
    
    505 500
     
    
    506 501
         def get_per(self, optname, key=None, subname=None, default=None): # per_group_of_option
    
    507 502
             if optname not in self.__options_per_key:
    
    ... ... @@ -591,11 +586,6 @@ def _really_save(self):
    591 586
             self.save_timeout_id = None
    
    592 587
             return False
    
    593 588
     
    
    594
    -    def _timeout_save(self):
    
    595
    -        if self.save_timeout_id:
    
    596
    -            return
    
    597
    -        self.save_timeout_id = GLib.timeout_add(1000, self._really_save)
    
    598
    -
    
    599 589
         def __init__(self):
    
    600 590
             #init default values
    
    601 591
             self._init_options()
    

  • gajim/common/helpers.py
    ... ... @@ -1033,7 +1033,7 @@ def open_uri(uri: Union[URI, str], account: Optional[str] = None) -> None:
    1033 1033
                 Gio.AppInfo.launch_default_for_uri(uri.data)
    
    1034 1034
     
    
    1035 1035
         elif uri.type == URIType.AT:
    
    1036
    -        app.interface.start_chat_from_jid(account, uri.data)
    
    1036
    +        app.window.start_chat_from_jid(account, uri.data)
    
    1037 1037
     
    
    1038 1038
         elif uri.type == URIType.XMPP:
    
    1039 1039
             if account is None:
    
    ... ... @@ -1052,7 +1052,7 @@ def open_uri(uri: Union[URI, str], account: Optional[str] = None) -> None:
    1052 1052
                     'groupchat-join',
    
    1053 1053
                     GLib.Variant('as', [account, jid]))
    
    1054 1054
             elif uri.action == URIAction.MESSAGE:
    
    1055
    -            app.interface.start_chat_from_jid(account, jid, message=message)
    
    1055
    +            app.window.start_chat_from_jid(account, jid, message=message)
    
    1056 1056
             else:
    
    1057 1057
                 log.warning('Cant open URI: %s', uri)
    
    1058 1058
     
    

  • gajim/gtk/application.py
    ... ... @@ -274,6 +274,8 @@ def _startup(self) -> None:
    274 274
             from gajim.gui.main import MainWindow
    
    275 275
             MainWindow()
    
    276 276
     
    
    277
    +        GLib.timeout_add(100, self._auto_connect)
    
    278
    +
    
    277 279
         def _open_uris(self, uris: list[str]) -> None:
    
    278 280
             accounts = app.settings.get_active_accounts()
    
    279 281
             if not accounts:
    
    ... ... @@ -326,7 +328,7 @@ def _open_uris(self, uris: list[str]) -> None:
    326 328
                         except Exception:
    
    327 329
                             app.log('uri_handler').error('Invalid URI: %s', cmd)
    
    328 330
     
    
    329
    -                app.interface.start_chat_from_jid(accounts[0], jid, message)
    
    331
    +                app.window.start_chat_from_jid(accounts[0], jid, message)
    
    330 332
     
    
    331 333
         def _shutdown(self, _application: GajimApplication) -> None:
    
    332 334
             self._shutdown_core()
    
    ... ... @@ -737,7 +739,7 @@ def _on_join_support_chat(_action: Gio.SimpleAction,
    737 739
                                   _param: Optional[GLib.Variant]) -> None:
    
    738 740
             accounts = app.settings.get_active_accounts()
    
    739 741
             if len(accounts) == 1:
    
    740
    -            app.interface.show_add_join_groupchat(
    
    742
    +            app.window.show_add_join_groupchat(
    
    741 743
                     accounts[0], GAJIM_SUPPORT_JID)
    
    742 744
                 return
    
    743 745
             open_window('StartChatDialog', initial_jid=GAJIM_SUPPORT_JID)
    
    ... ... @@ -827,7 +829,7 @@ def _on_copy_text_action(_action: Gio.SimpleAction,
    827 829
         def _on_open_chat_action(_action: Gio.SimpleAction,
    
    828 830
                                  param: GLib.Variant) -> None:
    
    829 831
             account, jid = param.get_strv()
    
    830
    -        app.interface.start_chat_from_jid(account, jid)
    
    832
    +        app.window.start_chat_from_jid(account, jid)
    
    831 833
     
    
    832 834
         @staticmethod
    
    833 835
         @structs.actionfunction
    

  • gajim/gtk/discovery.py
    ... ... @@ -1358,7 +1358,7 @@ def _on_join_button_clicked(self, widget):
    1358 1358
             if not iter_:
    
    1359 1359
                 return
    
    1360 1360
             service = model[iter_][0]
    
    1361
    -        app.interface.show_add_join_groupchat(self.account, service)
    
    1361
    +        app.window.show_add_join_groupchat(self.account, service)
    
    1362 1362
     
    
    1363 1363
         def update_actions(self):
    
    1364 1364
             if self.execute_button:
    
    ... ... @@ -1720,7 +1720,7 @@ def _on_join_button_clicked(self, *args):
    1720 1720
             if not iter_:
    
    1721 1721
                 return
    
    1722 1722
             service = model[iter_][0]
    
    1723
    -        app.interface.show_add_join_groupchat(self.account, service)
    
    1723
    +        app.window.show_add_join_groupchat(self.account, service)
    
    1724 1724
     
    
    1725 1725
         def update_actions(self):
    
    1726 1726
             sens = \
    

  • gajim/gtk/groupchat_invitation.py
    ... ... @@ -116,7 +116,7 @@ def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
    116 116
     
    
    117 117
         def _on_join(self, _button: Gtk.Button) -> None:
    
    118 118
             nickname = self._nick_chooser.get_text()
    
    119
    -        app.interface.show_add_join_groupchat(
    
    119
    +        app.window.show_add_join_groupchat(
    
    120 120
                 self.account, self._room_jid, nickname=nickname)
    
    121 121
             self.destroy()
    
    122 122
     
    

  • gajim/gtk/groupchat_join.py
    ... ... @@ -150,7 +150,7 @@ def _set_error_from_code(self, error_code: str) -> None:
    150 150
         def _on_join(self, _button: Gtk.Button) -> None:
    
    151 151
             nickname = self._nick_chooser.get_text()
    
    152 152
     
    
    153
    -        app.interface.show_add_join_groupchat(
    
    153
    +        app.window.show_add_join_groupchat(
    
    154 154
                 self.account, self.jid, nickname=nickname)
    
    155 155
             self.destroy()
    
    156 156
     
    

  • gajim/gtk/main.py
    ... ... @@ -947,6 +947,37 @@ def _on_window_active(self,
    947 947
             if control.get_autoscroll():
    
    948 948
                 self.mark_as_read(control.contact.account, control.contact.jid)
    
    949 949
     
    
    950
    +    def show_add_join_groupchat(self,
    
    951
    +                                account: str,
    
    952
    +                                jid: str,
    
    953
    +                                nickname: Optional[str] = None,
    
    954
    +                                password: Optional[str] = None
    
    955
    +                                ) -> None:
    
    956
    +
    
    957
    +        if not self.chat_exists(account, JID.from_string(jid)):
    
    958
    +            client = app.get_client(account)
    
    959
    +            client.get_module('MUC').join(
    
    960
    +                jid, nick=nickname, password=password)
    
    961
    +
    
    962
    +        self.add_group_chat(account, JID.from_string(jid), select=True)
    
    963
    +
    
    964
    +    def start_chat_from_jid(self,
    
    965
    +                            account: str,
    
    966
    +                            jid: str,
    
    967
    +                            message: Optional[str] = None
    
    968
    +                            ) -> None:
    
    969
    +
    
    970
    +        jid_ = JID.from_string(jid)
    
    971
    +        if self.chat_exists(account, jid_):
    
    972
    +            self.select_chat(account, jid_)
    
    973
    +            if message is not None:
    
    974
    +                message_input = self.get_chat_stack().get_message_input()
    
    975
    +                message_input.insert_text(message)
    
    976
    +            return
    
    977
    +
    
    978
    +        app.app.activate_action(
    
    979
    +            'start-chat', GLib.Variant('as', [str(jid), message or '']))
    
    980
    +
    
    950 981
         @staticmethod
    
    951 982
         def contact_info(account: str, jid: str) -> None:
    
    952 983
             client = app.get_client(account)
    

  • gajim/gtk/start_chat.py
    ... ... @@ -478,7 +478,7 @@ def _on_join_clicked(self, *args: Any) -> None:
    478 478
             jid = self._muc_info_box.get_jid()
    
    479 479
             nickname = self._nick_chooser.get_text()
    
    480 480
             assert account
    
    481
    -        app.interface.show_add_join_groupchat(
    
    481
    +        app.window.show_add_join_groupchat(
    
    482 482
                 account, str(jid), nickname=nickname)
    
    483 483
     
    
    484 484
             self.ready_to_destroy = True
    

  • gajim/gtk/status_icon.py
    ... ... @@ -203,7 +203,7 @@ def _on_quit(_widget: Gtk.MenuItem) -> None:
    203 203
     
    
    204 204
         @staticmethod
    
    205 205
         def _on_show(_widget: Gtk.MenuItem, show: str) -> None:
    
    206
    -        app.interface.change_status(status=show)
    
    206
    +        app.app.change_status(status=show)
    
    207 207
     
    
    208 208
     
    
    209 209
     class GtkStatusIcon(GtkMenuBackend):
    

  • gajim/gtk/status_selector.py
    ... ... @@ -132,7 +132,7 @@ def _create_popover(self) -> None:
    132 132
         def _on_change_status(self, button: Gtk.Button) -> None:
    
    133 133
             self._status_popover.popdown()
    
    134 134
             new_status = button.get_name()
    
    135
    -        app.interface.change_status(status=new_status, account=self._account)
    
    135
    +        app.app.change_status(status=new_status, account=self._account)
    
    136 136
     
    
    137 137
         def update(self) -> None:
    
    138 138
             if self._account is None:
    

  • gajim/gui_interface.py
    ... ... @@ -53,7 +53,6 @@
    53 53
     from gajim.common import exceptions
    
    54 54
     from gajim.common import proxy65_manager
    
    55 55
     from gajim.common import socks5
    
    56
    -from gajim.common import helpers
    
    57 56
     
    
    58 57
     from gajim.common.events import FileCompleted
    
    59 58
     from gajim.common.events import FileHashError
    
    ... ... @@ -74,7 +73,7 @@
    74 73
     from gajim.gui.file_transfer_send import SendFileDialog
    
    75 74
     from gajim.gui.filetransfer import FileTransfersWindow
    
    76 75
     from gajim.gui.control import ChatControl
    
    77
    -from gajim.plugins.repository import PluginRepository
    
    76
    +
    
    78 77
     
    
    79 78
     log = logging.getLogger('gajim.interface')
    
    80 79
     
    
    ... ... @@ -332,90 +331,6 @@ def start_file_transfer(self,
    332 331
                     contact)
    
    333 332
                 SendFileDialog(contact, send_callback, app.window, [path])
    
    334 333
     
    
    335
    -    @staticmethod
    
    336
    -    def show_add_join_groupchat(account: str,
    
    337
    -                                jid: str,
    
    338
    -                                nickname: Optional[str] = None,
    
    339
    -                                password: Optional[str] = None
    
    340
    -                                ) -> None:
    
    341
    -        if not app.window.chat_exists(account, JID.from_string(jid)):
    
    342
    -            client = app.get_client(account)
    
    343
    -            client.get_module('MUC').join(
    
    344
    -                jid, nick=nickname, password=password)
    
    345
    -
    
    346
    -        app.window.add_group_chat(account, JID.from_string(jid), select=True)
    
    347
    -
    
    348
    -    @staticmethod
    
    349
    -    def start_chat_from_jid(account: str,
    
    350
    -                            jid: str,
    
    351
    -                            message: Optional[str] = None
    
    352
    -                            ) -> None:
    
    353
    -
    
    354
    -        jid_ = JID.from_string(jid)
    
    355
    -        if app.window.chat_exists(account, jid_):
    
    356
    -            app.window.select_chat(account, jid_)
    
    357
    -            if message is not None:
    
    358
    -                message_input = app.window.get_chat_stack().get_message_input()
    
    359
    -                message_input.insert_text(message)
    
    360
    -            return
    
    361
    -
    
    362
    -        app.app.activate_action(
    
    363
    -            'start-chat', GLib.Variant('as', [str(jid), message or '']))
    
    364
    -
    
    365
    -    def autoconnect(self) -> None:
    
    366
    -        '''
    
    367
    -        Auto connect at startup
    
    368
    -        '''
    
    369
    -
    
    370
    -        for client in app.get_clients():
    
    371
    -            account = client.account
    
    372
    -            if not app.settings.get_account_setting(account,
    
    373
    -                                                    'autoconnect'):
    
    374
    -                continue
    
    375
    -
    
    376
    -            status = 'online'
    
    377
    -            status_message = ''
    
    378
    -
    
    379
    -            if app.settings.get_account_setting(account, 'restore_last_status'):
    
    380
    -                status = app.settings.get_account_setting(
    
    381
    -                    account, 'last_status')
    
    382
    -                status_message = app.settings.get_account_setting(
    
    383
    -                    account, 'last_status_msg')
    
    384
    -                status_message = helpers.from_one_line(status_message)
    
    385
    -
    
    386
    -            client.change_status(status, status_message)
    
    387
    -
    
    388
    -    def change_status(self,
    
    389
    -                      status: str,
    
    390
    -                      account: Optional[str] = None
    
    391
    -                      ) -> None:
    
    392
    -
    
    393
    -        if status is None:
    
    394
    -            status = helpers.get_global_show()
    
    395
    -
    
    396
    -        if account is not None:
    
    397
    -            self._change_status(account, status)
    
    398
    -            return
    
    399
    -
    
    400
    -        for client in app.get_clients():
    
    401
    -            if not app.settings.get_account_setting(client.account,
    
    402
    -                                                    'sync_with_global_status'):
    
    403
    -                continue
    
    404
    -
    
    405
    -            self._change_status(client.account, status)
    
    406
    -
    
    407
    -    @staticmethod
    
    408
    -    def _change_status(account: str, status: str) -> None:
    
    409
    -        client = app.get_client(account)
    
    410
    -        message = client.status_message
    
    411
    -
    
    412
    -        if status == 'offline':
    
    413
    -            # TODO delete pep
    
    414
    -            # self.delete_pep(app.get_jid_from_account(account), account)
    
    415
    -            pass
    
    416
    -
    
    417
    -        client.change_status(status, message)
    
    418
    -
    
    419 334
         def process_connections(self) -> bool:
    
    420 335
             '''
    
    421 336
             Called each foo (200) milliseconds. Check for idlequeue timeouts
    
    ... ... @@ -443,10 +358,6 @@ def process_connections(self) -> bool:
    443 358
                 raise
    
    444 359
             return True  # renew timeout (loop for ever)
    
    445 360
     
    
    446
    -    @staticmethod
    
    447
    -    def save_config() -> None:
    
    448
    -        app.settings.save()
    
    449
    -
    
    450 361
         def save_avatar(self, data: bytes) -> Optional[str]:
    
    451 362
             return app.app.avatar_storage.save_avatar(data)
    
    452 363
     
    
    ... ... @@ -454,20 +365,9 @@ def avatar_exists(self, filename: str) -> bool:
    454 365
             return app.app.avatar_storage.get_avatar_path(filename) is not None
    
    455 366
     
    
    456 367
         def run(self, _application: Gtk.Application) -> None:
    
    457
    -        # Creating plugin manager
    
    458
    -        from gajim import plugins
    
    459
    -        app.plugin_manager = plugins.PluginManager()
    
    460
    -        app.plugin_manager.init_plugins()
    
    461
    -
    
    462
    -        app.plugin_repository = PluginRepository()
    
    463
    -
    
    464
    -        for client in app.get_clients():
    
    465
    -            client.get_module('Roster').load_roster()
    
    466
    -
    
    467 368
             # get instances for windows/dialogs that will show_all()/hide()
    
    468 369
             self.instances['file_transfers'] = FileTransfersWindow()
    
    469 370
     
    
    470
    -        GLib.timeout_add(100, self.autoconnect)
    
    471 371
             if sys.platform == 'win32':
    
    472 372
                 timeout, in_seconds = 20, None
    
    473 373
             else:
    
    ... ... @@ -478,16 +378,6 @@ def run(self, _application: Gtk.Application) -> None:
    478 378
             else:
    
    479 379
                 GLib.timeout_add(timeout, self.process_connections)
    
    480 380
     
    
    481
    -        def remote_init():
    
    482
    -            if app.settings.get('remote_control'):
    
    483
    -                try:
    
    484
    -                    from gajim.common.dbus import remote_control
    
    485
    -                    remote_control.GajimRemote()
    
    486
    -                except Exception:
    
    487
    -                    log.exception('Failed to init remote control')
    
    488
    -
    
    489
    -        GLib.timeout_add_seconds(5, remote_init)
    
    490
    -
    
    491 381
     
    
    492 382
     class ThreadInterface:
    
    493 383
         def __init__(self, func, func_args=(), callback=None, callback_args=()):