app_actions.py 10.4 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
24
from gajim.common.exceptions import GajimGeneralException
from gajim import dialogs
25

26
27
import gajim.plugins.gui

28
from gajim.gtk.dialogs import ShortcutsWindow
29
from gajim.gtk.history_sync import HistorySyncAssistant
30
from gajim.gtk.server_info import ServerInfoDialog
Philipp Hörist's avatar
Philipp Hörist committed
31
from gajim.gtk.mam_preferences import MamPreferences
32
from gajim.gtk.preferences import Preferences
33
from gajim.gtk.groupchat_creation import CreateGroupchatWindow
34
35
36
37
38
from gajim.gtk.start_chat import StartChatDialog
from gajim.gtk.add_contact import AddNewContactWindow
from gajim.gtk.single_message import SingleMessageWindow
from gajim.gtk.about import AboutDialog
from gajim.gtk.privacy_list import PrivacyListsWindow
39
from gajim.gtk.bookmarks import Bookmarks
40
41
42
from gajim.gtk.features import FeaturesDialog
from gajim.gtk.account_wizard import AccountCreationWizard
from gajim.gtk.history import HistoryWindow
43
from gajim.gtk.accounts import AccountsWindow
44
from gajim.gtk.proxies import ManageProxies
45
from gajim.gtk.discovery import ServiceDiscoveryWindow
Philipp Hörist's avatar
Philipp Hörist committed
46
from gajim.gtk.blocking import BlockingList
47
from gajim.gtk.xml_console import XMLConsoleWindow
48
from gajim.gtk.groupchat_join import GroupchatJoin
49

Philipp Hörist's avatar
Philipp Hörist committed
50
51
52
# General Actions

def on_add_contact_jid(action, param):
53
    AddNewContactWindow(None, param.get_string())
Philipp Hörist's avatar
Philipp Hörist committed
54
55
56
57
58

# Application Menu Actions


def on_preferences(action, param):
59
60
61
    window = app.get_app_window(Preferences)
    if window is None:
        Preferences()
Philipp Hörist's avatar
Philipp Hörist committed
62
    else:
63
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
64
65
66
67
68
69
70
71
72
73


def on_plugins(action, param):
    if 'plugins' in interface.instances:
        interface.instances['plugins'].window.present()
    else:
        interface.instances['plugins'] = gajim.plugins.gui.PluginsWindow()


def on_accounts(action, param):
74
75
    window = app.get_app_window(AccountsWindow)
    if window is None:
Philipp Hörist's avatar
Philipp Hörist committed
76
        window = AccountsWindow()
Philipp Hörist's avatar
Philipp Hörist committed
77
    else:
78
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
79

Philipp Hörist's avatar
Philipp Hörist committed
80
81
82
83
    account = param.get_string()
    if account:
        window.select_account(account)

Philipp Hörist's avatar
Philipp Hörist committed
84
85
86
87
88
89

def on_history_manager(action, param):
    from gajim.history_manager import HistoryManager
    HistoryManager()


90
91
92
93
94
95
96
def on_bookmarks(action, param):
    account = param.get_string()
    window = app.get_app_window(Bookmarks, account=account)
    if window is None:
        window = Bookmarks(account)
    else:
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
97
98
99
100
101
102


def on_quit(action, param):
    interface.roster.on_quit_request()


103
104
105
106
107
def on_new_chat(_action, param):
    search_text = param.get_string()
    window = app.get_app_window(StartChatDialog)
    if window is None:
        window = StartChatDialog()
Philipp Hörist's avatar
Philipp Hörist committed
108
    else:
109
110
111
112
113
        window.present()

    if search_text:
        window.set_search_text(search_text)

Philipp Hörist's avatar
Philipp Hörist committed
114
115
116
117
118
119
120
121
122
123
124
125

# Accounts Actions


def on_profile(action, param):
    interface.edit_own_details(param.get_string())


def on_send_server_message(action, param):
    account = param.get_string()
    server = app.config.get_per('accounts', account, 'hostname')
    server += '/announce/online'
126
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
127
128
129
130
131
132
133
134
135
136
137


def on_service_disco(action, param):
    account = param.get_string()
    server_jid = app.config.get_per('accounts', account, 'hostname')
    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
138
            ServiceDiscoveryWindow(account, address_entry=True)
Philipp Hörist's avatar
Philipp Hörist committed
139
140
141
        except GajimGeneralException:
            pass

142
143
144
145
146
147
148
149
def on_create_gc(_action, param):
    window = app.get_app_window(CreateGroupchatWindow)
    if window is None:
        CreateGroupchatWindow(param.get_string() or None)
    else:
        window.present()


Philipp Hörist's avatar
Philipp Hörist committed
150
151
152
153
154
def on_add_contact(_action, param):
    account, jid = param.get_strv()
    if not jid:
        jid = None
    window = app.get_app_window(AddNewContactWindow, account)
Sophie Herold's avatar
Sophie Herold committed
155
    if window is None:
Philipp Hörist's avatar
Philipp Hörist committed
156
        AddNewContactWindow(account, jid)
Sophie Herold's avatar
Sophie Herold committed
157
158
    else:
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
159
160
161


def on_single_message(action, param):
162
    SingleMessageWindow(param.get_string(), action='send')
Philipp Hörist's avatar
Philipp Hörist committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181


def on_merge_accounts(action, param):
    action.set_state(param)
    value = param.get_boolean()
    app.config.set('mergeaccounts', value)
    # 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()


def on_add_account(action, param):
    if 'account_creation_wizard' in app.interface.instances:
        app.interface.instances['account_creation_wizard'].window.present()
    else:
        app.interface.instances['account_creation_wizard'] = \
182
            AccountCreationWizard()
Philipp Hörist's avatar
Philipp Hörist committed
183
184
185
186
187
188
189
190
191
192
193
194
195


def on_import_contacts(action, param):
    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)

# Advanced Actions


Philipp Hörist's avatar
Philipp Hörist committed
196
def on_mam_preferences(action, param):
Philipp Hörist's avatar
Philipp Hörist committed
197
    account = param.get_string()
Philipp Hörist's avatar
Philipp Hörist committed
198
199
200
    window = app.get_app_window(MamPreferences, account)
    if window is None:
        MamPreferences(account)
Philipp Hörist's avatar
Philipp Hörist committed
201
    else:
Philipp Hörist's avatar
Philipp Hörist committed
202
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
203
204


Philipp Hörist's avatar
Philipp Hörist committed
205
206
207
208
209
210
211
212
213
def on_blocking_list(action, param):
    account = param.get_string()
    window = app.get_app_window(MamPreferences, account)
    if window is None:
        BlockingList(account)
    else:
        window.present()


Philipp Hörist's avatar
Philipp Hörist committed
214
215
def on_history_sync(action, param):
    account = param.get_string()
216
217
218
    window = app.get_app_window(HistorySyncAssistant, account)
    if window is None:
        HistorySyncAssistant(account, interface.roster.window)
Philipp Hörist's avatar
Philipp Hörist committed
219
    else:
220
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
221
222
223
224
225
226
227
228


def on_privacy_lists(action, param):
    account = param.get_string()
    if 'privacy_lists' in interface.instances[account]:
        interface.instances[account]['privacy_lists'].window.present()
    else:
        interface.instances[account]['privacy_lists'] = \
229
            PrivacyListsWindow(account)
Philipp Hörist's avatar
Philipp Hörist committed
230
231
232
233
234
235
236
237
238
239
240
241
242


def on_server_info(action, param):
    account = param.get_string()
    if 'server_info' in interface.instances[account]:
        interface.instances[account]['server_info'].present()
    else:
        interface.instances[account]['server_info'] = \
            ServerInfoDialog(account)


def on_xml_console(action, param):
    account = param.get_string()
243
244
245
    window = app.get_app_window(XMLConsoleWindow, account)
    if window is None:
        XMLConsoleWindow(account)
Philipp Hörist's avatar
Philipp Hörist committed
246
    else:
247
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
248
249
250


def on_manage_proxies(action, param):
251
252
253
    window = app.get_app_window(ManageProxies)
    if window is None:
        ManageProxies()
Philipp Hörist's avatar
Philipp Hörist committed
254
    else:
255
        window.present()
Philipp Hörist's avatar
Philipp Hörist committed
256
257
258
259
260
261
262
263

# Admin Actions


def on_set_motd(action, param):
    account = param.get_string()
    server = app.config.get_per('accounts', account, 'hostname')
    server += '/announce/motd'
264
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
265
266
267
268
269
270


def on_update_motd(action, param):
    account = param.get_string()
    server = app.config.get_per('accounts', account, 'hostname')
    server += '/announce/motd/update'
271
    SingleMessageWindow(account, server, 'send')
Philipp Hörist's avatar
Philipp Hörist committed
272
273
274
275


def on_delete_motd(action, param):
    account = param.get_string()
276
    app.connections[account].get_module('Announce').delete_motd()
Philipp Hörist's avatar
Philipp Hörist committed
277
278
279
280
281

# Help Actions


def on_contents(action, param):
282
    helpers.open_uri('https://dev.gajim.org/gajim/gajim/wikis')
Philipp Hörist's avatar
Philipp Hörist committed
283
284
285


def on_faq(action, param):
286
    helpers.open_uri('https://dev.gajim.org/gajim/gajim/wikis/help/gajimfaq')
Philipp Hörist's avatar
Philipp Hörist committed
287
288
289


def on_keyboard_shortcuts(action, param):
290
    ShortcutsWindow()
Philipp Hörist's avatar
Philipp Hörist committed
291
292
293


def on_features(action, param):
294
    FeaturesDialog()
Philipp Hörist's avatar
Philipp Hörist committed
295
296
297


def on_about(action, param):
298
    AboutDialog()
Philipp Hörist's avatar
Philipp Hörist committed
299
300
301
302
303
304
305
306
307
308
309
310
311

# View Actions


def on_file_transfers(action, param):
    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):
312
    on_browse_history(action, param)
Philipp Hörist's avatar
Philipp Hörist committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340


def on_open_event(action, param):
    dict_ = param.unpack()
    app.interface.handle_event(
        dict_['account'], dict_['jid'], dict_['type_'])


# Other Actions

def toggle_ipython(action, param):
    """
    Show/hide the ipython window
    """
    win = app.ipython_window
    if win and win.window.is_visible():
        win.present()
    else:
        app.interface.create_ipython_window()


def show_next_pending_event(action, param):
    """
    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:
341
            return
Philipp Hörist's avatar
Philipp Hörist committed
342
        app.interface.handle_event(account, jid, event.type_)
Philipp Hörist's avatar
Philipp Hörist committed
343
344
345


def open_link(_action, param):
346
347
    uri = param.get_string()
    helpers.open_uri(uri)
Philipp Hörist's avatar
Philipp Hörist committed
348
349


350
def copy_text(_action, param):
Philipp Hörist's avatar
Philipp Hörist committed
351
352
353
354
355
356
357
358
359
360
    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)


361
362
363
364
365
366
367
368
369
370
371
372
373
374
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')

    window = app.get_app_window(HistoryWindow)
    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)
375
376
377
378
379
380
381
382
383


def on_groupchat_join(_action, param):
    account, jid = param.get_strv()
    window = app.get_app_window(GroupchatJoin, account=account, jid=jid)
    if window is None:
        GroupchatJoin(account, jid)
    else:
        window.present()