Skip to content

Commit

Permalink
Added language change in settings
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Logaev <[email protected]>
  • Loading branch information
mxlgv committed Apr 24, 2024
1 parent 863cbfb commit 4f7809d
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- run: sudo apt-get update
- run: sudo apt-get remove libunwind-14-dev
- run: sudo apt-get install -y build-essential gettext cmake valac libgee-0.8-dev libsqlite3-dev libgtk-4-dev libnotify-dev libgpgme-dev libsoup2.4-dev libgcrypt20-dev libqrencode-dev libnice-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libsrtp2-dev libadwaita-1-dev libsignal-protocol-c-dev libcanberra-dev
- run: ./configure --release --no-debug --with-tests --enable-plugin=notification-sound --prefix=/usr --without-webrtc
- run: ./configure --release --no-debug --with-tests --enable-plugin=notification-sound --prefix=/usr --without-webrtc --enable-select-lang
- run: cmake --build build
- run: cmake --build build --target=test
- name: Build DEB-package
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
- run: sudo apt-get update
- run: sudo apt-get remove libunwind-14-dev
- run: sudo apt-get install -y build-essential gettext libadwaita-1-dev libcanberra-dev libgcrypt20-dev libgee-0.8-dev libgpgme-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libgtk-4-dev libnice-dev libnotify-dev libqrencode-dev libsignal-protocol-c-dev libsoup2.4-dev libsqlite3-dev libsrtp2-dev meson valac
- run: meson setup build -Duse-soup2=true -Dplugin-rtp-webrtc-audio-processing=disabled
- run: meson setup build -Duse-soup2=true -Dplugin-rtp-webrtc-audio-processing=disabled -Dselect-lang=enabled
- run: meson compile -C build
- run: meson test -C build
build-flatpak:
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include(CTest)

option(PLUGIN_RTP_WEBRTC_AUDIO_PROCESSING "Use WebRTC audio processing" ON)
option(WITH_WASAPI "Use wasapi instead of directsound on windows" ON)
option(ENABLE_SELECT_LANG "Add language change to settings" OFF)

# https://gitlab.kitware.com/cmake/cmake/-/issues/19804
if (WIN32)
Expand Down Expand Up @@ -195,7 +196,11 @@ endif (NOT NO_DEBUG)
if (WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=1")
set(CMAKE_VALA_FLAGS "${CMAKE_VALA_FLAGS} --define=_WIN32")
endif(WIN32)
endif (WIN32)

if (ENABLE_SELECT_LANG)
set(CMAKE_VALA_FLAGS "${CMAKE_VALA_FLAGS} --define=ENABLE_SELECT_LANG")
endif (ENABLE_SELECT_LANG)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
3 changes: 2 additions & 1 deletion build-win64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ prepare()
configure_cmake()
{
msg "Running configuration for Windows"
./configure --program-prefix="$DIST_DIR" --no-debug --release --disable-fast-vapi --with-libsoup3 --with-tests
./configure --program-prefix="$DIST_DIR" --no-debug --release --disable-fast-vapi --with-libsoup3 --with-tests --enable-select-lang
msg "Configured!"
}

Expand Down Expand Up @@ -125,6 +125,7 @@ configure_meson()
meson setup ${cmd} --prefix "$DIST_DIR" \
-D crypto-backend=${encr} \
-D plugin-ice=enabled \
-D select-lang=enabled \
$PROJ_DIR $BUILD_DIR
}

Expand Down
5 changes: 5 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

OPTS=`getopt -o "h" --long \
help,fetch-only,no-debug,disable-fast-vapi,with-tests,release,with-libsoup3,without-webrtcdsp,\
enable-select-lang,\
enable-plugin:,disable-plugin:,\
prefix:,program-prefix:,exec-prefix:,lib-suffix:,\
bindir:,libdir:,includedir:,datadir:,\
Expand All @@ -18,6 +19,7 @@ DISABLED_PLUGINS=
BUILD_TESTS=no
BUILD_TYPE=Debug
DISABLE_FAST_VAPI=
ENABLE_SELECT_LANG=no
LIB_SUFFIX=
NO_DEBUG=
USE_SOUP3=
Expand Down Expand Up @@ -52,6 +54,7 @@ Configuration:
builds (during development).
--fetch-only Only fetch the files required to run ./configure
without network access later and exit.
--enable-select-lang enable language switching for the settings menu
--no-debug Build without debug symbols
--release Configure to build an optimized release version
--with-libsoup3 Build with libsoup-3.0
Expand Down Expand Up @@ -113,6 +116,7 @@ while true; do
--with-libsoup3 ) USE_SOUP3=yes; shift ;;
--without-webrtcdsp ) PLUGIN_RTP_WEBRTC_AUDIO_PROCESSING=no; shift ;;
--disable-fast-vapi ) DISABLE_FAST_VAPI=yes; shift ;;
--enable-select-lang) ENABLE_SELECT_LANG=yes; shift ;;
--no-debug ) NO_DEBUG=yes; shift ;;
--release ) BUILD_TYPE=RelWithDebInfo; shift ;;
--with-tests ) BUILD_TESTS=yes; shift ;;
Expand Down Expand Up @@ -223,6 +227,7 @@ cmake -G "$cmake_type" \
-DINCLUDE_INSTALL_DIR="$INCLUDEDIR" \
-DLIB_INSTALL_DIR="$LIBDIR" \
-DPLUGIN_RTP_WEBRTC_AUDIO_PROCESSING="$PLUGIN_RTP_WEBRTC_AUDIO_PROCESSING" \
-DENABLE_SELECT_LANG="$ENABLE_SELECT_LANG" \
-Wno-dev \
.. || exit 9

Expand Down
4 changes: 4 additions & 0 deletions libdino/src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public interface Application : GLib.Application {
this.settings = new Dino.Entities.Settings.from_db(db);
this.stream_interactor = new StreamInteractor(db);

#if ENABLE_SELECT_LANG
Environment.set_variable("LANGUAGE", settings.ui_language, true);
#endif

MessageProcessor.start(stream_interactor, db);
MessageStorage.start(stream_interactor, db);
PresenceManager.start(stream_interactor);
Expand Down
20 changes: 20 additions & 0 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Settings : Object {
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false);
ui_language_ = col_to_string_or_default("ui_language", "en");
}

private bool col_to_bool_or_default(string key, bool def) {
Expand All @@ -28,6 +29,12 @@ public class Settings : Object {
return val != null ? Encryption.parse(val) : def;
}

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

private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
Expand Down Expand Up @@ -128,6 +135,19 @@ public class Settings : Object {
enter_newline_ = value;
}
}

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

}
19 changes: 19 additions & 0 deletions main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="select_lang_group">
<property name="visible">False</property>
<child>
<object class="AdwComboRow" id="select_lang_comborow">
<property name="title" translatable="yes">Select language</property>
<property name="subtitle" translatable="yes">Application restart required</property>
<property name="model">
<object class="GtkStringList" id="select_lang_list">
<items>
<item>English</item>
<item>Русский</item>
</items>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
Expand Down
8 changes: 8 additions & 0 deletions main/po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ msgstr ""
msgid "Check spelling"
msgstr ""

#: main/data/settings_dialog.ui:148
msgid "Select language"
msgstr ""

#: main/data/settings_dialog.ui:149
msgid "Application restart required"
msgstr ""

#: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions main/po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,14 @@ msgstr "Превращать смайлы в эмодзи"
msgid "Check spelling"
msgstr "Проверка орфографии"

#: main/data/settings_dialog.ui:148
msgid "Select language"
msgstr "Выбор языка"

#: main/data/settings_dialog.ui:149
msgid "Application restart required"
msgstr "Требуется перезапуск приложения"

#: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client"
msgstr "Современный XMPP клиент"
Expand Down
19 changes: 19 additions & 0 deletions main/src/ui/settings_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class SettingsDialog : Adw.PreferencesWindow {
[GtkChild] private unowned CheckButton encryption_radio_openpgp;
[GtkChild] private unowned Switch send_button_switch;
[GtkChild] private unowned Switch enter_newline_switch;
#if ENABLE_SELECT_LANG
[GtkChild] private unowned Adw.ComboRow select_lang_comborow;
[GtkChild] private unowned Adw.PreferencesGroup select_lang_group;
#endif

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

Expand Down Expand Up @@ -65,6 +69,21 @@ class SettingsDialog : Adw.PreferencesWindow {
enter_newline_switch.active = visible;
}
});

#if ENABLE_SELECT_LANG
var lang_short_list = new Gee.ArrayList<string>();
lang_short_list.add("en");
lang_short_list.add("ru");

select_lang_comborow.set_selected(lang_short_list.index_of(settings.ui_language));

select_lang_comborow.notify["selected-item"].connect(() => {
settings.ui_language = lang_short_list.get((int)select_lang_comborow.get_selected());
});

select_lang_group.visible = true;
#endif

}
}

Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ else
endforeach
endif

if get_option('select-lang').allowed()
add_project_arguments('-D', 'ENABLE_SELECT_LANG', language: 'vala')
endif

if get_option('crypto-backend') == 'auto'
# Prefer libgcrypt/gnutls over openssl because glib-networking is usually
# built with gnutls anyway.
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ option('plugin-rtp-webrtc-audio-processing', type: 'feature', description: 'Voic

option('use-soup2', type: 'boolean', value: false, description: 'Use libsoup version 2 instead of 3')
option('with-wasapi', type: 'boolean', value: true, description: 'Use wasapi insted of directsound on windows')

option('select-lang', type: 'feature', value: 'disabled', description: 'Enable language change in settings')

0 comments on commit 4f7809d

Please sign in to comment.