Philipp Hörist pushed to branch master at gajim / gajim
Commits: d0ee3674 by Daniel Brötzmann at 2020-04-25T14:36:18+02:00 Settings: Add color setting
- - - - - 1ebe0d0d by Daniel Brötzmann at 2020-04-25T14:45:51+02:00 Accounts: Add account colors
- - - - - 962e10f5 by Daniel Brötzmann at 2020-04-25T14:45:54+02:00 Migration: Add color for each account
- - - - - 39acfc20 by Daniel Brötzmann at 2020-04-25T14:45:54+02:00 Raise Gajim version to 1.1.95
- - - - -
8 changed files:
- gajim/__init__.py - gajim/common/config.py - gajim/common/optparser.py - gajim/gtk/accounts.py - gajim/gtk/const.py - gajim/gtk/settings.py - gajim/gtk/util.py - gajim/gui_interface.py
Changes:
===================================== gajim/__init__.py ===================================== @@ -1,7 +1,7 @@ import os import subprocess
-__version__ = "1.1.94" +__version__ = "1.1.95"
IS_FLATPAK = False if os.path.exists('/app/share/run-as-flatpak'):
===================================== gajim/common/config.py ===================================== @@ -270,6 +270,7 @@ class Config: 'accounts': ({ 'name': [opt_str, '', '', True], 'account_label': [opt_str, '', '', False], + 'account_color': [opt_color, 'rgb(85, 85, 85)'], 'hostname': [opt_str, '', '', True], 'anonymous_auth': [opt_bool, False], 'avatar_sha': [opt_str, '', '', False],
===================================== gajim/common/optparser.py ===================================== @@ -29,10 +29,12 @@ import re import logging from pathlib import Path
+from gi.repository import Gdk +from nbxmpp.util import text_to_color + from gajim.common import app from gajim.common.i18n import _
- log = logging.getLogger('gajim.c.optparser')
@@ -149,6 +151,8 @@ class OptionsParser: self.update_config_to_1193() if old < [1, 1, 94] and new >= [1, 1, 94]: self.update_config_to_1194() + if old < [1, 1, 95] and new >= [1, 1, 95]: + self.update_config_to_1195()
app.config.set('version', new_version)
@@ -230,3 +234,18 @@ class OptionsParser: app.config.del_per('accounts', account, 'proxy')
app.config.set('version', '1.1.94') + + def update_config_to_1195(self): + # Add account color for every account + for account in self.old_values['accounts'].keys(): + username = self.old_values['accounts'][account]['name'] + domain = self.old_values['accounts'][account]['hostname'] + if not (username is None or domain is None): + account_string = '%s@%s' % (username, domain) + # We cannot get the preferred theme at this point + background = (1, 1, 1) + col_r, col_g, col_b = text_to_color(account_string, background) + rgba = Gdk.RGBA(red=col_r, green=col_g, blue=col_b) + color = rgba.to_string() + app.config.set_per('accounts', account, 'account_color', color) + app.config.set('version', '1.1.95')
===================================== gajim/gtk/accounts.py ===================================== @@ -604,6 +604,10 @@ class GeneralPage(GenericSettingPage): SettingType.ACCOUNT_CONFIG, 'account_label', callback=self._on_account_name_change),
+ Setting(SettingKind.COLOR, _('Color'), + SettingType.ACCOUNT_CONFIG, 'account_color', + desc=_('Recognize your account by color')), + Setting(SettingKind.LOGIN, _('Login'), SettingType.DIALOG, props={'dialog': LoginDialog}),
===================================== gajim/gtk/const.py ===================================== @@ -58,6 +58,7 @@ class SettingKind(IntEnum): CHANGEPASSWORD = 11 COMBO = 12 CHATSTATE_COMBO = 13 + COLOR = 14
@unique
===================================== gajim/gtk/settings.py ===================================== @@ -88,6 +88,7 @@ class SettingsBox(Gtk.ListBox): SettingKind.SPIN: SpinSetting, SettingKind.DIALOG: DialogSetting, SettingKind.ENTRY: EntrySetting, + SettingKind.COLOR: ColorSetting, SettingKind.ACTION: ActionSetting, SettingKind.LOGIN: LoginSetting, SettingKind.FILECHOOSER: FileChooserSetting, @@ -98,7 +99,7 @@ class SettingsBox(Gtk.ListBox): SettingKind.CHANGEPASSWORD: ChangePasswordSetting, SettingKind.COMBO: ComboSetting, SettingKind.CHATSTATE_COMBO: ChatstateComboSetting, - } + }
if extend is not None: for setting, callback in extend: @@ -336,6 +337,36 @@ class EntrySetting(GenericSetting): self.entry.grab_focus()
+class ColorSetting(GenericSetting): + + __gproperties__ = { + "setting-value": (str, 'Color Value', '', '', + GObject.ParamFlags.READWRITE), + } + + def __init__(self, *args): + GenericSetting.__init__(self, *args) + + rgba = Gdk.RGBA() + rgba.parse(self.setting_value) + self.color_button = Gtk.ColorButton() + self.color_button.set_rgba(rgba) + self.color_button.connect('color-set', self.on_color_set) + self.color_button.set_valign(Gtk.Align.CENTER) + self.color_button.set_halign(Gtk.Align.END) + + self.setting_box.pack_end(self.color_button, True, True, 0) + + self.show_all() + + def on_color_set(self, button): + rgba = button.get_rgba() + self.set_value(rgba.to_string()) + + def on_row_activated(self): + self.color_button.grab_focus() + + class DialogSetting(GenericSetting):
__gproperties__ = {
===================================== gajim/gtk/util.py ===================================== @@ -646,6 +646,12 @@ def text_to_color(text): return nbxmpp.util.text_to_color(text, background)
+def get_color_for_account(account: str) -> str: + col_r, col_g, col_b = text_to_color(account) + rgba = Gdk.RGBA(red=col_r, green=col_g, blue=col_b) + return rgba.to_string() + + def scale_with_ratio(size, width, height): if height == width: return size, size
===================================== gajim/gui_interface.py ===================================== @@ -106,6 +106,7 @@ from gajim.gtk.util import get_show_in_systray from gajim.gtk.util import open_window from gajim.gtk.util import get_app_window from gajim.gtk.util import get_app_windows +from gajim.gtk.util import get_color_for_account from gajim.gtk.const import ControlType
@@ -1669,6 +1670,8 @@ class Interface: config['name'] = username config['resource'] = 'gajim.%s' % helpers.get_random_string(8) config['account_label'] = '%s@%s' % (username, domain) + config['account_color'] = get_color_for_account( + '%s@%s' % (username, domain)) config['hostname'] = domain config['savepass'] = True config['password'] = password
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/24d89658f6e0502d0dd101ac28509fa4...