Commit 1764df4e authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Daniel Brötzmann
Browse files

AccountWizard: Add account badge preview

parent 53bdee6c
Pipeline #7741 failed with stages
in 5 minutes and 5 seconds
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="gtk+" version="3.22"/>
<object class="GtkBox" id="account_label_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Optional: Add a name and color for your account</property>
<property name="wrap">True</property>
<property name="max_width_chars">50</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkEntry" id="account_name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">Account Name...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="account_color_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-down-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="badge_preview">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<style>
<class name="badge"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<object class="GtkGrid" id="advanced_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
......
......@@ -49,7 +49,8 @@
from .dataform import DataFormWidget
from .util import get_builder
from .util import open_window
from .util import get_color_for_account
from .util import get_app_window
log = logging.getLogger('gajim.gui.account_wizard')
......@@ -962,14 +963,66 @@ def __init__(self):
self.set_heading(_('Account has been added successfully'))
self._account = None
self._our_jid = None
self._label = None
self._color = None
self._ui = get_builder('account_wizard.ui')
self.pack_start(self._ui.account_label_box, True, True, 0)
self._provider = self._add_css_provider()
self._ui.account_name_entry.connect('changed', self._on_name_changed)
self._ui.account_color_button.connect('color-set', self._on_color_set)
self.show_all()
def set_account(self, account):
self._account = account
self._our_jid = app.get_jid_from_account(account)
self._ui.badge_preview.set_text(self._our_jid)
rgba = Gdk.RGBA()
rgba.parse(get_color_for_account(self._our_jid))
self._ui.account_color_button.set_rgba(rgba)
self._color = rgba.to_string()
self._set_badge_color(self._color)
@property
def account(self):
return self._account
def _add_css_provider(self):
context = self._ui.badge_preview.get_style_context()
provider = Gtk.CssProvider()
context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
return provider
def _on_name_changed(self, entry):
self._label = entry.get_text()
self._ui.badge_preview.set_text(self._label or self._our_jid)
self._save_config()
def _on_color_set(self, button):
rgba = button.get_rgba()
self._color = rgba.to_string()
self._set_badge_color(self._color)
self._save_config()
def _set_badge_color(self, color):
css = '.badge { background-color: %s }' % color
self._provider.load_from_data(bytes(css.encode()))
def _save_config(self):
app.settings.set_account_setting(
self._account, 'account_color', self._color)
if self._label:
app.settings.set_account_setting(
self._account, 'account_label', self._label)
app.css_config.refresh()
window = get_app_window('AccountsWindow')
if window is not None:
window.update_account_label(self._account)
def get_visible_buttons(self):
return ['connect']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment