app_actions.py 9.21 KB
Newer Older
Philipp Hörist's avatar
Philipp Hörist committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright (C) 2017 Philipp Hörist <philipp AT hoerist.com>
#
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
16

Philipp Hörist's avatar
Philipp Hörist committed
17
18
19
from gi.repository import Gtk
from gi.repository import Gdk

20
from gajim.common import app
André's avatar
André committed
21
from gajim.common import helpers
22
from gajim.common.app import interface
André's avatar
André committed
23
from gajim.common.exceptions import GajimGeneralException
pg mr's avatar
pg mr committed
24
from gajim.common.regex import LINK_REGEX
André's avatar
André committed
25
from gajim import dialogs
26

Philipp Hörist's avatar
Philipp Hörist committed
27
28
29
30
31
32
33
from gajim.gui.dialogs import ShortcutsWindow
from gajim.gui.single_message import SingleMessageWindow
from gajim.gui.about import AboutDialog
from gajim.gui.history import HistoryWindow
from gajim.gui.discovery import ServiceDiscoveryWindow
from gajim.gui.util import open_window
from gajim.gui.util import get_app_window
34

Philipp Hörist's avatar
Philipp Hörist committed
35
36
# General Actions

Philipp Hörist's avatar
Philipp Hörist committed
37
38
39
40
def on_add_contact_jid(_action, param):
    contact_jid = param.get_string()
    open_window('AddNewContactWindow', account=None, contact_jid=contact_jid)

Philipp Hörist's avatar
Philipp Hörist committed
41
42
43
44

# Application Menu Actions


Philipp Hörist's avatar
Philipp Hörist committed
45
46
def on_preferences(_action, _param):
    open_window('Preferences')
Philipp Hörist's avatar
Philipp Hörist committed
47
48


Philipp Hörist's avatar
Philipp Hörist committed
49
def on_plugins(_action, _param):
50
    open_window('PluginsWindow')
Philipp Hörist's avatar
Philipp Hörist committed
51
52


Philipp Hörist's avatar
Philipp Hörist committed
53
54
def on_accounts(_action, param):
    window = open_window('AccountsWindow')
Philipp Hörist's avatar
Philipp Hörist committed
55
56
57
58
    account = param.get_string()
    if account:
        window.select_account(account)

Philipp Hörist's avatar
Philipp Hörist committed
59

Philipp Hörist's avatar
Philipp Hörist committed
60
61
def on_history_manager(_action, _param):
    open_window('HistoryManager')
Philipp Hörist's avatar
Philipp Hörist committed
62
63


Philipp Hörist's avatar
Philipp Hörist committed
64
def on_bookmarks(_action, param):
65
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
66
    open_window('Bookmarks', account=account)
Philipp Hörist's avatar
Philipp Hörist committed
67
68


Philipp Hörist's avatar
Philipp Hörist committed
69
def on_quit(_action, _param):
Philipp Hörist's avatar
Philipp Hörist committed
70
71
72
    interface.roster.on_quit_request()


73
def on_new_chat(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
74
    window = open_window('StartChatDialog')
75
76
77
78
    search_text = param.get_string()
    if search_text:
        window.set_search_text(search_text)

Philipp Hörist's avatar
Philipp Hörist committed
79
80
81
82

# Accounts Actions


Philipp Hörist's avatar
Philipp Hörist committed
83
84
85
def on_profile(_action, param):
    account = param.get_string()
    open_window('ProfileWindow', account=account)
Philipp Hörist's avatar
Philipp Hörist committed
86
87


Philipp Hörist's avatar
Philipp Hörist committed
88
def on_send_server_message(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
89
    account = param.get_string()
90
    server = app.settings.get_account_setting(account, 'hostname')
Philipp Hörist's avatar
Philipp Hörist committed
91
    server += '/announce/online'
92
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
93
94


Philipp Hörist's avatar
Philipp Hörist committed
95
def on_service_disco(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
96
    account = param.get_string()
97
    server_jid = app.settings.get_account_setting(account, 'hostname')
Philipp Hörist's avatar
Philipp Hörist committed
98
99
100
101
102
103
    if server_jid in interface.instances[account]['disco']:
        interface.instances[account]['disco'][server_jid].\
            window.present()
    else:
        try:
            # Object will add itself to the window dict
104
            ServiceDiscoveryWindow(account, address_entry=True)
Philipp Hörist's avatar
Philipp Hörist committed
105
106
107
        except GajimGeneralException:
            pass

108
def on_create_gc(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
109
110
    account = param.get_string()
    open_window('CreateGroupchatWindow', account=account or None)
111
112


Philipp Hörist's avatar
Philipp Hörist committed
113
def on_add_contact(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
114
115
116
117
    account, contact_jid = param.get_strv()
    if not contact_jid:
        contact_jid = None
    open_window('AddNewContactWindow', account=account, contact_jid=contact_jid)
Philipp Hörist's avatar
Philipp Hörist committed
118
119


Philipp Hörist's avatar
Philipp Hörist committed
120
121
122
def on_single_message(_action, param):
    account = param.get_string()
    open_window('SingleMessageWindow', account=account, action='send')
Philipp Hörist's avatar
Philipp Hörist committed
123
124
125
126
127


def on_merge_accounts(action, param):
    action.set_state(param)
    value = param.get_boolean()
Philipp Hörist's avatar
Philipp Hörist committed
128
    app.settings.set('mergeaccounts', value)
Philipp Hörist's avatar
Philipp Hörist committed
129
130
131
132
133
134
135
136
    # Do not merge accounts if only one active
    if len(app.connections) >= 2:
        app.interface.roster.regroup = value
    else:
        app.interface.roster.regroup = False
    app.interface.roster.setup_and_draw_roster()


137
138
def on_add_account(action, _param):
    open_window('AccountWizard')
Philipp Hörist's avatar
Philipp Hörist committed
139
140


Philipp Hörist's avatar
Philipp Hörist committed
141
def on_import_contacts(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
142
143
144
145
146
147
148
    account = param.get_string()
    if 'import_contacts' in app.interface.instances:
        app.interface.instances['import_contacts'].dialog.present()
    else:
        app.interface.instances['import_contacts'] = \
            dialogs.SynchroniseSelectAccountDialog(account)

149

Philipp Hörist's avatar
Philipp Hörist committed
150
151
# Advanced Actions

Philipp Hörist's avatar
Philipp Hörist committed
152
def on_pep_config(_action, param):
153
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
154
    open_window('PEPConfig', account=account)
155

Philipp Hörist's avatar
Philipp Hörist committed
156

Philipp Hörist's avatar
Philipp Hörist committed
157
def on_mam_preferences(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
158
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
159
    open_window('MamPreferences', account=account)
Philipp Hörist's avatar
Philipp Hörist committed
160
161


Philipp Hörist's avatar
Philipp Hörist committed
162
def on_blocking_list(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
163
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
164
    open_window('BlockingList', account=account)
Philipp Hörist's avatar
Philipp Hörist committed
165
166


Philipp Hörist's avatar
Philipp Hörist committed
167
def on_history_sync(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
168
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
169
170
171
    open_window('HistorySyncAssistant',
                account=account,
                parent=interface.roster.window)
Philipp Hörist's avatar
Philipp Hörist committed
172
173


Philipp Hörist's avatar
Philipp Hörist committed
174
def on_server_info(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
175
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
176
    open_window('ServerInfo', account=account)
Philipp Hörist's avatar
Philipp Hörist committed
177
178


Philipp Hörist's avatar
Philipp Hörist committed
179
180
def on_xml_console(_action, _param):
    open_window('XMLConsoleWindow')
181

Philipp Hörist's avatar
Philipp Hörist committed
182

Philipp Hörist's avatar
Philipp Hörist committed
183
184
def on_manage_proxies(_action, _param):
    open_window('ManageProxies')
Philipp Hörist's avatar
Philipp Hörist committed
185
186
187
188
189


# Admin Actions


Philipp Hörist's avatar
Philipp Hörist committed
190
def on_set_motd(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
191
    account = param.get_string()
192
    server = app.settings.get_account_setting(account, 'hostname')
Philipp Hörist's avatar
Philipp Hörist committed
193
    server += '/announce/motd'
194
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
195
196


Philipp Hörist's avatar
Philipp Hörist committed
197
def on_update_motd(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
198
    account = param.get_string()
199
    server = app.settings.get_account_setting(account, 'hostname')
Philipp Hörist's avatar
Philipp Hörist committed
200
    server += '/announce/motd/update'
201
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
202
203


Philipp Hörist's avatar
Philipp Hörist committed
204
def on_delete_motd(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
205
    account = param.get_string()
206
    app.connections[account].get_module('Announce').delete_motd()
Philipp Hörist's avatar
Philipp Hörist committed
207
208
209
210

# Help Actions


Philipp Hörist's avatar
Philipp Hörist committed
211
def on_contents(_action, _param):
212
    helpers.open_uri('https://dev.gajim.org/gajim/gajim/wikis')
Philipp Hörist's avatar
Philipp Hörist committed
213
214


Philipp Hörist's avatar
Philipp Hörist committed
215
def on_faq(_action, _param):
216
    helpers.open_uri('https://dev.gajim.org/gajim/gajim/wikis/help/gajimfaq')
Philipp Hörist's avatar
Philipp Hörist committed
217
218


Philipp Hörist's avatar
Philipp Hörist committed
219
def on_keyboard_shortcuts(_action, _param):
220
    ShortcutsWindow()
Philipp Hörist's avatar
Philipp Hörist committed
221
222


Philipp Hörist's avatar
Philipp Hörist committed
223
def on_features(_action, _param):
224
    open_window('Features')
Philipp Hörist's avatar
Philipp Hörist committed
225
226


Philipp Hörist's avatar
Philipp Hörist committed
227
def on_about(_action, _param):
228
    AboutDialog()
Philipp Hörist's avatar
Philipp Hörist committed
229
230
231
232

# View Actions


Philipp Hörist's avatar
Philipp Hörist committed
233
def on_file_transfers(_action, _param):
Philipp Hörist's avatar
Philipp Hörist committed
234
235
236
237
238
239
240
241
    if interface.instances['file_transfers']. \
            window.get_property('visible'):
        interface.instances['file_transfers'].window.present()
    else:
        interface.instances['file_transfers'].window.show_all()


def on_history(action, param):
242
    on_browse_history(action, param)
Philipp Hörist's avatar
Philipp Hörist committed
243
244


Philipp Hörist's avatar
Philipp Hörist committed
245
def on_open_event(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
246
247
248
249
250
    dict_ = param.unpack()
    app.interface.handle_event(
        dict_['account'], dict_['jid'], dict_['type_'])


251
252
253
254
255
256
257
258
259
260
def on_remove_event(_action, param):
    dict_ = param.unpack()
    account, jid, type_ = dict_['account'], dict_['jid'], dict_['type_']
    event = app.events.get_first_event(account, jid, type_)
    app.events.remove_events(account, jid, event)
    win = app.interface.msg_win_mgr.get_window(jid, account)
    if win:
        win.redraw_tab(win.get_control(jid, account))
        win.show_title()

pg mr's avatar
pg mr committed
261
262
263
264
265
266
267
268
269
270
271
272
def on_open_link_from_msg_event(_action, param):
    dict_ = param.unpack()
    account, jid, type_ = dict_['account'], dict_['jid'], dict_['type_']
    to_search = app.events.get_events(account,jid)[-1].message # something better might be needed
    search_result =LINK_REGEX.search(to_search).group()
    if search_result is not None:
        if search_result.startswith("www."): #for "legacy_prefixes"
            search_result = "http://%s"%search_result
        if search_result.startswith("ftp."): #for "legacy_prefixes"
            search_result = "ftp://%s"%search_result
        Gtk.show_uri_on_window(None,search_result,Gdk.CURRENT_TIME)

Philipp Hörist's avatar
Philipp Hörist committed
273
274
# Other Actions

Philipp Hörist's avatar
Philipp Hörist committed
275
def toggle_ipython(_action, _param):
Philipp Hörist's avatar
Philipp Hörist committed
276
277
278
279
280
281
282
283
284
285
    """
    Show/hide the ipython window
    """
    win = app.ipython_window
    if win and win.window.is_visible():
        win.present()
    else:
        app.interface.create_ipython_window()


Philipp Hörist's avatar
Philipp Hörist committed
286
def show_next_pending_event(_action, _param):
Philipp Hörist's avatar
Philipp Hörist committed
287
288
289
290
291
292
    """
    Show the window(s) with next pending event in tabbed/group chats
    """
    if app.events.get_nb_events():
        account, jid, event = app.events.get_first_systray_event()
        if not event:
293
            return
Philipp Hörist's avatar
Philipp Hörist committed
294
        app.interface.handle_event(account, jid, event.type_)
Philipp Hörist's avatar
Philipp Hörist committed
295
296


Philipp Hörist's avatar
Philipp Hörist committed
297
def open_mail(_action, param):
298
    uri = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
299
300
    if not uri.startswith('mailto:'):
        uri = 'mailto:%s' % uri
301
    helpers.open_uri(uri)
Philipp Hörist's avatar
Philipp Hörist committed
302
303


Philipp Hörist's avatar
Philipp Hörist committed
304
def open_link(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
305
    account, uri = param.get_strv()
Philipp Hörist's avatar
Philipp Hörist committed
306
307
308
    helpers.open_uri(uri, account=account)


309
def copy_text(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
310
311
312
313
314
315
316
317
318
319
    text = param.get_string()
    clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    clip.set_text(text, -1)


def start_chat(_action, param):
    account, jid = param.get_strv()
    app.interface.new_chat_from_jid(account, jid)


320
321
322
323
324
325
326
def on_browse_history(_action, param):
    jid, account = None, None
    if param is not None:
        dict_ = param.unpack()
        jid = dict_.get('jid')
        account = dict_.get('account')

Philipp Hörist's avatar
Philipp Hörist committed
327
    window = get_app_window(HistoryWindow)
328
329
330
331
332
333
    if window is None:
        HistoryWindow(jid, account)
    else:
        window.present()
        if jid is not None and account is not None:
            window.open_history(jid, account)
334
335
336
337


def on_groupchat_join(_action, param):
    account, jid = param.get_strv()
Philipp Hörist's avatar
Philipp Hörist committed
338
    open_window('GroupchatJoin', account=account, jid=jid)