[set_location] Various changes

- Remove log_calls decorator
- Fix some pylint errors
- Light refactor
This commit is contained in:
lovetox
2020-05-02 10:16:37 +02:00
parent c46ef69b61
commit b4c5c60b5f

View File

@@ -11,7 +11,6 @@ from nbxmpp.structs import LocationData
from gajim.plugins.gui import GajimPluginConfigDialog from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.plugins import GajimPlugin from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _ from gajim.plugins.plugins_i18n import _
from gajim.plugins.helpers import log_calls
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged
from gajim.common import helpers from gajim.common import helpers
@@ -38,9 +37,9 @@ except:
class SetLocationPlugin(GajimPlugin): class SetLocationPlugin(GajimPlugin):
@log_calls('SetLocationPlugin')
def init(self): def init(self):
self.description = _('Set information about your current geographical ' self.description = _(
'Set information about your current geographical '
'or physical location. \nTo be able to set your location on the ' 'or physical location. \nTo be able to set your location on the '
'built-in map, you need to have gir1.2-gtkchamplain and ' 'built-in map, you need to have gir1.2-gtkchamplain and '
'gir1.2-gtkclutter-1.0 installed') 'gir1.2-gtkclutter-1.0 installed')
@@ -64,43 +63,43 @@ class SetLocationPlugin(GajimPlugin):
'uri': ('http://beta.plazes.com/plazes/1940:jabber_inc', ''), 'uri': ('http://beta.plazes.com/plazes/1940:jabber_inc', ''),
'presets': ({'default': {}}, ''), } 'presets': ({'default': {}}, ''), }
@log_calls('SetLocationPlugin')
def activate(self): def activate(self):
app.ged.register_event_handler('signed-in', ged.POSTGUI, app.ged.register_event_handler('signed-in',
self.on_signed_in) ged.POSTGUI,
self.on_signed_in)
self.send_locations() self.send_locations()
@log_calls('SetLocationPlugin')
def deactivate(self): def deactivate(self):
self._data = {}
for acct in app.connections: for acct in app.connections:
app.connections[acct].get_module('UserLocation').set_location(None) app.connections[acct].get_module('UserLocation').set_location(None)
app.ged.remove_event_handler('signed-in', ged.POSTGUI, app.ged.remove_event_handler('signed-in',
self.on_signed_in) ged.POSTGUI,
self.on_signed_in)
def on_signed_in(self, network_event): def on_signed_in(self, event):
self.send_locations(network_event.conn.name) self.send_locations(account=event.account)
def send_locations(self, acct=False): def send_locations(self, account=None):
self._data = {} data = {}
timestamp = time.time() timestamp = time.time()
timestamp = datetime.utcfromtimestamp(timestamp) timestamp = datetime.utcfromtimestamp(timestamp)
timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') timestamp = timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')
self._data['timestamp'] = timestamp data['timestamp'] = timestamp
for name in self.config_default_values: for name in self.config_default_values:
if name == 'presets': if name == 'presets':
continue continue
self._data[name] = self.config[name] data[name] = self.config[name]
if not acct: if account is None:
# Set geo for all accounts # Set geo for all accounts
for acct in app.connections: for acct in app.connections:
if app.config.get_per('accounts', acct, 'publish_location'): if app.config.get_per('accounts', acct, 'publish_location'):
app.connections[acct].get_module('UserLocation').set_location( app.connections[acct].get_module('UserLocation').set_location(
LocationData(**self._data)) LocationData(**data))
elif app.config.get_per('accounts', acct, 'publish_location'):
app.connections[acct].get_module('UserLocation').set_location( elif app.config.get_per('accounts', account, 'publish_location'):
LocationData(**self._data)) app.connections[account].get_module('UserLocation').set_location(
LocationData(**data))
class SetLocationPluginConfigDialog(GajimPluginConfigDialog): class SetLocationPluginConfigDialog(GajimPluginConfigDialog):
@@ -124,10 +123,7 @@ class SetLocationPluginConfigDialog(GajimPluginConfigDialog):
cellrenderer = Gtk.CellRendererText() cellrenderer = Gtk.CellRendererText()
self.preset_combo.pack_start(cellrenderer, True) self.preset_combo.pack_start(cellrenderer, True)
self.preset_combo.add_attribute(cellrenderer, 'text', 0) self.preset_combo.add_attribute(cellrenderer, 'text', 0)
#self.plugin.config['presets'] = {'default': {}}
@log_calls('SetLocationPlugin.SetLocationPluginConfigDialog')
def on_run(self): def on_run(self):
if not self.is_active: if not self.is_active:
pres_keys = sorted(self.plugin.config['presets'].keys()) pres_keys = sorted(self.plugin.config['presets'].keys())