Skip to content

Commit

Permalink
Add option for scale interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Psayker committed Apr 24, 2024
1 parent e6b8ff3 commit f990c1f
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 7 deletions.
42 changes: 42 additions & 0 deletions libdino/src/entity/encryption.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,46 @@ namespace Dino.Entities {
}
}

public enum InterfaceScale {
NONE,
SMALL,
MEDIUM,
LARGE,
EXTRA_LARGE;

public bool is_some() {
return this != NONE;
}

public static InterfaceScale parse(string str) {
switch (str) {
case "DINO_ENTITIES_INTERFACE_SCALE_SMALL":
return SMALL;
case "DINO_ENTITIES_INTERFACE_SCALE_MEDIUM":
return MEDIUM;
case "DINO_ENTITIES_INTERFACE_SCALE_LARGE":
return LARGE;
case "DINO_ENTITIES_INTERFACE_SCALE_EXTRA_LARGE":
return EXTRA_LARGE;
default:
return NONE;
}
}

public static double to_double(InterfaceScale val) {
switch (val) {
case InterfaceScale.SMALL:
return 0.75;
case InterfaceScale.MEDIUM:
return 1;
case InterfaceScale.LARGE:
return 1.5;
case InterfaceScale.EXTRA_LARGE:
return 2;
default:
return 1;
}
}
}

}
23 changes: 23 additions & 0 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ public class Settings : Object {
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
check_spelling = col_to_bool_or_default("check_spelling", true);
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
interface_scale = col_to_interface_scale_or_default("interface_scale", InterfaceScale.MEDIUM);
send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false);
dark_theme = col_to_bool_or_default("dark_theme", false);
}

public signal void update_interface_scale();

private bool col_to_bool_or_default(string key, bool def) {
string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
return val != null ? bool.parse(val) : def;
Expand All @@ -29,6 +32,12 @@ public class Settings : Object {
return val != null ? Encryption.parse(val) : def;
}

private InterfaceScale col_to_interface_scale_or_default(string key, InterfaceScale def) {
var sval = db.settings.value;
string? val = db.settings.select({sval}).with(db.settings.key, "=", key)[sval];
return val != null ? InterfaceScale.parse(val) : def;
}

private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
Expand Down Expand Up @@ -103,6 +112,20 @@ public class Settings : Object {
}
}

private InterfaceScale interface_scale_;
public InterfaceScale interface_scale {
get { return interface_scale_; }
set {
string valstr = value.to_string();
db.settings.upsert()
.value(db.settings.key, "interface_scale", true)
.value(db.settings.value, valstr)
.perform();
interface_scale_ = value;
update_interface_scale();
}
}


public signal void send_button_update(bool visible);
private bool send_button_;
Expand Down
5 changes: 3 additions & 2 deletions main/data/conversation_item_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<property name="row-spacing">2</property>
<child>
<object class="DinoUiAvatarPicture" id="avatar_picture">
<property name="height-request">35</property>
<property name="height-request">35</property> <!-- Size of aatars in conversation -->
<property name="width-request">35</property>
<property name="valign">start</property>
<property name="margin-top">2</property>
Expand All @@ -23,6 +23,7 @@
<property name="xalign">0</property>
<property name="valign">baseline</property>
<attributes>
<attribute name="scale" value="1"/> <!-- Size of nickname if conersation -->
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
<layout>
Expand All @@ -36,7 +37,7 @@
<property name="xalign">0</property>
<property name="valign">baseline</property>
<attributes>
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- size of message time -->
</attributes>
<style>
<class name="dim-label"/>
Expand Down
10 changes: 5 additions & 5 deletions main/data/conversation_row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<property name="margin-end">14</property>
<child>
<object class="DinoUiAvatarPicture" id="picture">
<property name="height-request">35</property>
<property name="height-request">35</property> <!-- Conversation list avatar size -->
<property name="width-request">35</property>
<property name="valign">center</property>
</object>
Expand All @@ -42,7 +42,7 @@
<property name="hexpand">False</property>
<property name="xalign">1</property>
<attributes>
<attribute name="scale" value="0.7"/>
<attribute name="scale" value="0.7"/> <!-- + Conversation list last message time -->
</attributes>
</object>
</child>
Expand All @@ -63,7 +63,7 @@
</style>
<attributes>
<!--<attribute name="weight" value="bold"/>-->
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- + Converstion list last message sender name -->
</attributes>
</object>
</child>
Expand All @@ -76,7 +76,7 @@
<property name="valign">end</property>
<property name="xalign">0</property>
<attributes>
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- Conversation list last message text -->
</attributes>
</object>
</child>
Expand All @@ -91,7 +91,7 @@
<property name="visible">False</property>
<property name="xalign">0.5</property>
<attributes>
<attribute name="scale" value="0.6"/>
<attribute name="scale" value="0.6"/> <!-- Conversation list unread message -->
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
</object>
Expand Down
43 changes: 43 additions & 0 deletions main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,49 @@
<child type="suffix">
<object class="GtkSwitch" id="dark_theme">
<property name="valign">center</property>
<property name="title" translatable="yes">Interface scale</property>
<child>
<object class="GtkBox" id="interface_scale">
<child>
<object class="GtkCheckButton" id="scale_small">
<property name="label" translatable="yes">Small</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_medium">
<property name="label" translatable="yes">Medium</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_large">
<property name="label" translatable="yes">Large</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_xlarge">
<property name="label" translatable="yes">Extra Large</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
set_widget(widget, Plugins.WidgetType.GTK4, 2);
}

Dino.Entities.Settings settings = Dino.Application.get_default().settings;
settings.update_interface_scale.connect(() => {
update_name_label();
update_time();
});

if (item.requires_header) {
// TODO: For MUC messags, use real jid from message if known
avatar_picture.model = new ViewModel.CompatAvatarPictureModel(stream_interactor).add_participant(conversation, item.jid);
Expand Down Expand Up @@ -174,7 +180,12 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
}

private void update_time() {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));

time_label.label = get_relative_time(item.time.to_local()).to_string();
time_label.set_attributes(attr_list);

time_update_timeout = Timeout.add_seconds((int) get_next_time_change(item.time), () => {
if (this.main_grid.parent == null) return false;
Expand All @@ -184,7 +195,11 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
}

private void update_name_label() {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
name_label.label = Util.get_participant_display_name(stream_interactor, conversation, item.jid, true);
name_label.set_attributes(attr_list);
}

private void update_received_mark() {
Expand Down
26 changes: 26 additions & 0 deletions main/src/ui/conversation_selector/conversation_selector_row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ConversationSelectorRow : ListBoxRow {
this.conversation = conversation;
this.stream_interactor = stream_interactor;

Dino.Entities.Settings settings = Dino.Application.get_default().settings;
settings.update_interface_scale.connect(() => {
content_item_received();
});

switch (conversation.type_) {
case Conversation.Type.CHAT:
stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect((account, jid, roster_item) => {
Expand Down Expand Up @@ -103,6 +108,13 @@ public class ConversationSelectorRow : ListBoxRow {
content_item_received();
}

// public AttrList get_scale_attr() {
// Dino.Entities.Settings settings = Dino.Application.get_default().settings;
// Pango.AttrList attr_list = new Pango.AttrList();
// attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
// return attr_list;
// }

public void update() {
update_time_label();
}
Expand All @@ -129,6 +141,10 @@ public class ConversationSelectorRow : ListBoxRow {

protected void update_name_label() {
name_label.label = Util.get_conversation_display_name(stream_interactor, conversation);
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
name_label.set_attributes(attr_list);
}

private void update_pinned_icon() {
Expand All @@ -139,6 +155,10 @@ public class ConversationSelectorRow : ListBoxRow {
if (last_content_item != null) {
time_label.visible = true;
time_label.label = get_relative_time(last_content_item.time.to_local());
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
time_label.set_attributes(attr_list);
}
}

Expand Down Expand Up @@ -207,8 +227,13 @@ public class ConversationSelectorRow : ListBoxRow {
message_label.label = call.direction == Call.DIRECTION_OUTGOING ? _("Outgoing call") : _("Incoming call");
break;
}
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
nick_label.visible = true;
nick_label.set_attributes(attr_list);
message_label.visible = true;
message_label.set_attributes(attr_list);
}
}

Expand Down Expand Up @@ -247,6 +272,7 @@ public class ConversationSelectorRow : ListBoxRow {
} else {
unread_count_label.label = num_unread.to_string();
unread_count_label.visible = true;
// unread_count_label.set_attributes(get_scale_attr());

if (conversation.get_notification_setting(stream_interactor) == Conversation.NotifySetting.ON) {
unread_count_label.add_css_class("unread-count-notify");
Expand Down
33 changes: 33 additions & 0 deletions main/src/ui/settings_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class SettingsDialog : Adw.PreferencesWindow {
[GtkChild] private unowned Switch send_button_switch;
[GtkChild] private unowned Switch enter_newline_switch;
[GtkChild] private unowned Switch dark_theme;
[GtkChild] private unowned CheckButton scale_small;
[GtkChild] private unowned CheckButton scale_medium;
[GtkChild] private unowned CheckButton scale_large;
[GtkChild] private unowned CheckButton scale_xlarge;

Dino.Entities.Settings settings = Dino.Application.get_default().settings;

Expand All @@ -30,6 +34,11 @@ class SettingsDialog : Adw.PreferencesWindow {
encryption_radio_omemo.active = settings.default_encryption == Encryption.OMEMO;
encryption_radio_openpgp.active = settings.default_encryption == Encryption.PGP;

scale_small.active = settings.interface_scale == InterfaceScale.SMALL;
scale_medium.active = settings.interface_scale == InterfaceScale.MEDIUM;
scale_large.active = settings.interface_scale == InterfaceScale.LARGE;
scale_xlarge.active = settings.interface_scale == InterfaceScale.EXTRA_LARGE;

send_button_switch.active = settings.send_button;
enter_newline_switch.active = settings.enter_newline;
enter_newline_switch.sensitive = settings.send_button;
Expand Down Expand Up @@ -59,6 +68,30 @@ class SettingsDialog : Adw.PreferencesWindow {
}
});

scale_small.notify["active"].connect(() => {
if (scale_small.active) {
settings.interface_scale = InterfaceScale.SMALL;
}
});

scale_medium.notify["active"].connect(() => {
if (scale_medium.active) {
settings.interface_scale = InterfaceScale.MEDIUM;
}
});

scale_large.notify["active"].connect(() => {
if (scale_large.active) {
settings.interface_scale = InterfaceScale.LARGE;
}
});

scale_xlarge.notify["active"].connect(() => {
if (scale_xlarge.active) {
settings.interface_scale = InterfaceScale.EXTRA_LARGE;
}
});

send_button_switch.notify["active"].connect(() => { settings.send_button = send_button_switch.active; });
enter_newline_switch.notify["active"].connect(() => { settings.enter_newline = enter_newline_switch.active; });
settings.send_button_update.connect((visible) => {
Expand Down

0 comments on commit f990c1f

Please sign in to comment.