| 2237 | | |
| 2238 | | # check if we have unread messages |
| 2239 | | unread = gajim.events.get_nb_events() |
| 2240 | | if not gajim.config.get('notify_on_all_muc_messages'): |
| 2241 | | unread_not_to_notify = gajim.events.get_nb_events(['printed_gc_msg']) |
| 2242 | | unread -= unread_not_to_notify |
| 2243 | | |
| 2244 | | # check if we have recent messages |
| 2245 | | recent = False |
| 2246 | | for win in gajim.interface.msg_win_mgr.windows(): |
| 2247 | | for ctrl in win.controls(): |
| 2248 | | fjid = ctrl.get_full_jid() |
| 2249 | | if gajim.last_message_time[ctrl.account].has_key(fjid): |
| 2250 | | if time.time() - gajim.last_message_time[ctrl.account][fjid] < 2: |
| 2251 | | recent = True |
| 2252 | | break |
| 2253 | | if recent: |
| 2254 | | break |
| 2255 | | |
| 2256 | | if unread or recent: |
| 2257 | | dialog = dialogs.ConfirmationDialog(_('You have unread messages'), |
| 2258 | | _('Messages will only be available for reading them later if you' |
| 2259 | | ' have history enabled and contact is in your roster.')) |
| 2260 | | if dialog.get_response() != gtk.RESPONSE_OK: |
| 2261 | | return |
| 2262 | | |
| 2263 | | self.quit_on_next_offline = 0 |
| 2264 | | for acct in accounts: |
| 2265 | | if gajim.connections[acct].connected: |
| 2266 | | self.quit_on_next_offline += 1 |
| 2267 | | self.send_status(acct, 'offline', message) |
| 2268 | | |
| 2269 | | if not self.quit_on_next_offline: |
| 2270 | | self.quit_gtkgui_interface() |
| | 2240 | # check if we have unread messages |
| | 2241 | unread = gajim.events.get_nb_events() |
| | 2242 | if not gajim.config.get('notify_on_all_muc_messages'): |
| | 2243 | unread_not_to_notify = gajim.events.get_nb_events( |
| | 2244 | ['printed_gc_msg']) |
| | 2245 | unread -= unread_not_to_notify |
| | 2246 | |
| | 2247 | # check if we have recent messages |
| | 2248 | recent = False |
| | 2249 | for win in gajim.interface.msg_win_mgr.windows(): |
| | 2250 | for ctrl in win.controls(): |
| | 2251 | fjid = ctrl.get_full_jid() |
| | 2252 | if gajim.last_message_time[ctrl.account].has_key(fjid): |
| | 2253 | if time.time() - gajim.last_message_time[ctrl.account][fjid] < 2: |
| | 2254 | recent = True |
| | 2255 | break |
| | 2256 | if recent: |
| | 2257 | break |
| | 2258 | |
| | 2259 | if unread or recent: |
| | 2260 | dialog = dialogs.ConfirmationDialog(_('You have unread messages'), |
| | 2261 | _('Messages will only be available for reading them later if you' |
| | 2262 | ' have history enabled and contact is in your roster.')) |
| | 2263 | if dialog.get_response() != gtk.RESPONSE_OK: |
| | 2264 | return |
| | 2265 | |
| | 2266 | self.quit_on_next_offline = 0 |
| | 2267 | for acct in accounts: |
| | 2268 | if gajim.connections[acct].connected: |
| | 2269 | self.quit_on_next_offline += 1 |
| | 2270 | self.send_status(acct, 'offline', message) |
| | 2271 | |
| | 2272 | if not self.quit_on_next_offline: |
| | 2273 | self.quit_gtkgui_interface() |
| | 2274 | |
| | 2275 | if get_msg: |
| | 2276 | self.get_status_message('offline', on_continue) |
| | 2277 | else: |
| | 2278 | self.on_continue('') |
| 2517 | | model = self.modelfilter |
| 2518 | | accounts = [] |
| 2519 | | msg = self.get_status_message('offline') |
| 2520 | | if group_list is None: |
| 2521 | | jid = model[titer][C_JID].decode('utf-8') |
| 2522 | | account = model[titer][C_ACCOUNT].decode('utf-8') |
| 2523 | | accounts.append(account) |
| 2524 | | self.send_status(account, 'offline', msg, to = jid) |
| 2525 | | new_rule = {'order': u'1', 'type': u'jid', 'action': u'deny', |
| 2526 | | 'value' : jid, 'child': [u'message', u'iq', u'presence-out']} |
| 2527 | | gajim.connections[account].blocked_list.append(new_rule) |
| 2528 | | # needed for draw_contact: |
| 2529 | | gajim.connections[account].blocked_contacts.append(jid) |
| 2530 | | self.draw_contact(jid, account) |
| 2531 | | else: |
| 2532 | | if titer is None: |
| 2533 | | for (contact, account) in group_list: |
| 2534 | | if account not in accounts: |
| 2535 | | if not gajim.connections[account].privacy_rules_supported: |
| 2536 | | continue |
| 2537 | | accounts.append(account) |
| 2538 | | self.send_status(account, 'offline', msg, to=contact.jid) |
| 2539 | | new_rule = {'order': u'1', 'type': u'jid', |
| 2540 | | 'action': u'deny', 'value' : contact.jid, |
| 2541 | | 'child': [u'message', u'iq', u'presence-out']} |
| | 2525 | def on_continue(msg): |
| | 2526 | if msg is None: |
| | 2527 | # user pressed Cancel to change status message dialog |
| | 2528 | return |
| | 2529 | model = self.modelfilter |
| | 2530 | accounts = [] |
| | 2531 | if group_list is None: |
| | 2532 | jid = model[titer][C_JID].decode('utf-8') |
| | 2533 | account = model[titer][C_ACCOUNT].decode('utf-8') |
| | 2534 | accounts.append(account) |
| | 2535 | self.send_status(account, 'offline', msg, to = jid) |
| | 2536 | new_rule = {'order': u'1', 'type': u'jid', 'action': u'deny', |
| | 2537 | 'value' : jid, 'child': [u'message', u'iq', u'presence-out']} |
| | 2538 | gajim.connections[account].blocked_list.append(new_rule) |
| | 2539 | # needed for draw_contact: |
| | 2540 | gajim.connections[account].blocked_contacts.append(jid) |
| | 2541 | self.draw_contact(jid, account) |
| | 2542 | else: |
| | 2543 | if titer is None: |
| | 2544 | for (contact, account) in group_list: |
| | 2545 | if account not in accounts: |
| | 2546 | if not gajim.connections[account].privacy_rules_supported: |
| | 2547 | continue |
| | 2548 | accounts.append(account) |
| | 2549 | self.send_status(account, 'offline', msg, to=contact.jid) |
| | 2550 | new_rule = {'order': u'1', 'type': u'jid', |
| | 2551 | 'action': u'deny', 'value' : contact.jid, |
| | 2552 | 'child': [u'message', u'iq', u'presence-out']} |
| | 2553 | gajim.connections[account].blocked_list.append(new_rule) |
| | 2554 | # needed for draw_contact: |
| | 2555 | gajim.connections[account].blocked_contacts.append( |
| | 2556 | contact.jid) |
| | 2557 | self.draw_contact(contact.jid, account) |
| | 2558 | else: |
| | 2559 | group = model[titer][C_JID].decode('utf-8') |
| | 2560 | for (contact, account) in group_list: |
| | 2561 | if account not in accounts: |
| | 2562 | if not gajim.connections[account].privacy_rules_supported: |
| | 2563 | continue |
| | 2564 | accounts.append(account) |
| | 2565 | # needed for draw_group: |
| | 2566 | gajim.connections[account].blocked_groups.append(group) |
| | 2567 | self.draw_group(group, account) |
| | 2568 | self.send_status(account, 'offline', msg, to=contact.jid) |
| | 2569 | self.draw_contact(contact.jid, account) |
| | 2570 | new_rule = {'order': u'1', 'type': u'group', 'action': u'deny', |
| | 2571 | 'value' : group, 'child': [u'message', u'iq', |
| | 2572 | u'presence-out']} |
| 2543 | | # needed for draw_contact: |
| 2544 | | gajim.connections[account].blocked_contacts.append(contact.jid) |
| 2545 | | self.draw_contact(contact.jid, account) |
| 2546 | | else: |
| 2547 | | group = model[titer][C_JID].decode('utf-8') |
| 2548 | | for (contact, account) in group_list: |
| 2549 | | if account not in accounts: |
| 2550 | | if not gajim.connections[account].privacy_rules_supported: |
| 2551 | | continue |
| 2552 | | accounts.append(account) |
| 2553 | | # needed for draw_group: |
| 2554 | | gajim.connections[account].blocked_groups.append(group) |
| 2555 | | self.draw_group(group, account) |
| 2556 | | self.send_status(account, 'offline', msg, to=contact.jid) |
| 2557 | | self.draw_contact(contact.jid, account) |
| 2558 | | new_rule = {'order': u'1', 'type': u'group', 'action': u'deny', |
| 2559 | | 'value' : group, 'child': [u'message', u'iq', u'presence-out']} |
| 2560 | | gajim.connections[account].blocked_list.append(new_rule) |
| 2561 | | for account in accounts: |
| 2562 | | gajim.connections[account].set_privacy_list( |
| 2563 | | 'block', gajim.connections[account].blocked_list) |
| 2564 | | if len(gajim.connections[account].blocked_list) == 1: |
| 2565 | | gajim.connections[account].set_active_list('block') |
| 2566 | | gajim.connections[account].set_default_list('block') |
| 2567 | | gajim.connections[account].get_privacy_list('block') |
| | 2574 | for account in accounts: |
| | 2575 | gajim.connections[account].set_privacy_list( |
| | 2576 | 'block', gajim.connections[account].blocked_list) |
| | 2577 | if len(gajim.connections[account].blocked_list) == 1: |
| | 2578 | gajim.connections[account].set_active_list('block') |
| | 2579 | gajim.connections[account].set_default_list('block') |
| | 2580 | gajim.connections[account].get_privacy_list('block') |
| | 2581 | |
| | 2582 | self.get_status_message('offline', on_continue) |
| 3065 | | dlg = dialogs.ChangeStatusMessageDialog(show) |
| 3066 | | message = dlg.run() |
| 3067 | | if not message: |
| 3068 | | return True |
| 3069 | | for acct in gajim.connections: |
| 3070 | | if not gajim.config.get_per('accounts', acct, |
| 3071 | | 'sync_with_global_status'): |
| 3072 | | continue |
| 3073 | | current_show = gajim.SHOW_LIST[gajim.connections[acct].connected] |
| 3074 | | self.send_status(acct, current_show, message) |
| | 3080 | def on_response(message): |
| | 3081 | if message is None: |
| | 3082 | return True |
| | 3083 | for acct in gajim.connections: |
| | 3084 | if not gajim.config.get_per('accounts', acct, |
| | 3085 | 'sync_with_global_status'): |
| | 3086 | continue |
| | 3087 | current_show = gajim.SHOW_LIST[gajim.connections[acct].\ |
| | 3088 | connected] |
| | 3089 | self.send_status(acct, current_show, message) |
| | 3090 | dialogs.ChangeStatusMessageDialog(on_response, show) |
| 3208 | | dlg = dialogs.ChangeStatusMessageDialog(status) |
| 3209 | | message = dlg.run() |
| 3210 | | if message is not None: # None if user pressed Cancel |
| 3211 | | for account in accounts: |
| 3212 | | if not gajim.config.get_per('accounts', account, |
| 3213 | | 'sync_with_global_status'): |
| 3214 | | continue |
| 3215 | | current_show = gajim.SHOW_LIST[ |
| 3216 | | gajim.connections[account].connected] |
| 3217 | | self.send_status(account, current_show, message) |
| 3218 | | self.combobox_callback_active = False |
| 3219 | | self.status_combobox.set_active( |
| 3220 | | self.previous_status_combobox_active) |
| 3221 | | self.combobox_callback_active = True |
| | 3225 | def on_response(message): |
| | 3226 | if message is not None: # None if user pressed Cancel |
| | 3227 | for account in accounts: |
| | 3228 | if not gajim.config.get_per('accounts', account, |
| | 3229 | 'sync_with_global_status'): |
| | 3230 | continue |
| | 3231 | current_show = gajim.SHOW_LIST[ |
| | 3232 | gajim.connections[account].connected] |
| | 3233 | self.send_status(account, current_show, message) |
| | 3234 | self.combobox_callback_active = False |
| | 3235 | self.status_combobox.set_active( |
| | 3236 | self.previous_status_combobox_active) |
| | 3237 | self.combobox_callback_active = True |
| | 3238 | dialogs.ChangeStatusMessageDialog(on_response, status) |
| 3248 | | message = self.get_status_message(status) |
| 3249 | | if message is None: # user pressed Cancel to change status message dialog |
| | 3265 | |
| | 3266 | def on_continue(message): |
| | 3267 | if message is None: |
| | 3268 | # user pressed Cancel to change status message dialog |
| | 3269 | self.update_status_combobox() |
| | 3270 | return |
| | 3271 | global_sync_accounts = [] |
| | 3272 | for acct in accounts: |
| | 3273 | if gajim.config.get_per('accounts', acct, |
| | 3274 | 'sync_with_global_status'): |
| | 3275 | global_sync_accounts.append(acct) |
| | 3276 | global_sync_connected_accounts = \ |
| | 3277 | gajim.get_number_of_connected_accounts(global_sync_accounts) |
| | 3278 | for account in accounts: |
| | 3279 | if not gajim.config.get_per('accounts', account, |
| | 3280 | 'sync_with_global_status'): |
| | 3281 | continue |
| | 3282 | # we are connected (so we wanna change show and status) |
| | 3283 | # or no account is connected and we want to connect with new show |
| | 3284 | # and status |
| | 3285 | |
| | 3286 | if not global_sync_connected_accounts > 0 or \ |
| | 3287 | gajim.connections[account].connected > 0: |
| | 3288 | self.send_status(account, status, message) |
| 3251 | | return |
| 3252 | | global_sync_accounts = [] |
| 3253 | | for acct in accounts: |
| 3254 | | if gajim.config.get_per('accounts', acct, 'sync_with_global_status'): |
| 3255 | | global_sync_accounts.append(acct) |
| 3256 | | global_sync_connected_accounts = gajim.get_number_of_connected_accounts( |
| 3257 | | global_sync_accounts) |
| 3258 | | for account in accounts: |
| 3259 | | if not gajim.config.get_per('accounts', account, |
| 3260 | | 'sync_with_global_status'): |
| 3261 | | continue |
| 3262 | | # we are connected (so we wanna change show and status) |
| 3263 | | # or no account is connected and we want to connect with new show and |
| 3264 | | # status |
| 3265 | | |
| 3266 | | if not global_sync_connected_accounts > 0 or \ |
| 3267 | | gajim.connections[account].connected > 0: |
| 3268 | | self.send_status(account, status, message) |
| 3269 | | self.update_status_combobox() |
| | 3290 | |
| | 3291 | self.get_status_message(status, on_continue) |