mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-07-01 14:15:24 +02:00

Implement the hunspell spellchecker for Windows and MacOS. It also changes the base implementation for Linux. The system dictionaries (if any) are aggregated with those installed from the LibreOffice repository via Jami's dictionary management interface. This commit implements a major refactoring of the spellcheck system to improve UI responsiveness and user experience: Core Changes: - Used QAbstractListModel to represent the list of dictionaries - Added new QML components: - DictionaryInstallView.qml - ManageDictionariesDialog.qml - SpellCheckLanguageComboBox.qml - Updated property names for clarity - Fixed a bug in the settings combo box custom component that caused out-of-range errors for filtered models GitLab: #1997 Change-Id: Ibd0879f957f27f4c7c5720762ace553ca84e2bc3
96 lines
3.2 KiB
QML
96 lines
3.2 KiB
QML
/*
|
|
* Copyright (C) 2025 Savoir-faire Linux Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import QtQuick.Controls
|
|
import Qt5Compat.GraphicalEffects
|
|
import net.jami.Models 1.1
|
|
import net.jami.Adapters 1.1
|
|
import net.jami.Enums 1.1
|
|
import net.jami.Constants 1.1
|
|
import net.jami.Helpers 1.1
|
|
import SortFilterProxyModel 0.2
|
|
import "../../commoncomponents"
|
|
import "../../mainview/components"
|
|
|
|
SettingsComboBox {
|
|
id: root
|
|
height: JamiTheme.preferredFieldHeight
|
|
labelText: JamiStrings.textLanguage
|
|
tipText: JamiStrings.textLanguage
|
|
comboModel: SortFilterProxyModel {
|
|
id: installedDictionariesModel
|
|
sourceModel: SpellCheckAdapter.getDictionaryListModel()
|
|
|
|
// Filter to show only installed dictionaries
|
|
filters: ValueFilter {
|
|
roleName: "Installed"
|
|
value: true
|
|
}
|
|
|
|
// Sort alphabetically by native name
|
|
sorters: RoleSorter {
|
|
roleName: "NativeName"
|
|
sortOrder: Qt.AscendingOrder
|
|
}
|
|
Component.onCompleted: {
|
|
// Ensure the model is updated with the latest dictionaries
|
|
root.enabled = Qt.binding(function () {
|
|
return installedDictionariesModel.count > 0;
|
|
});
|
|
}
|
|
}
|
|
role: "NativeName"
|
|
|
|
// Show placeholder when disabled
|
|
placeholderText: JamiStrings.none
|
|
|
|
function getCurrentLocaleIndex() {
|
|
var currentLang = UtilsAdapter.getAppValue(Settings.Key.SpellLang);
|
|
for (var i = 0; i < comboModel.count; i++) {
|
|
var item = comboModel.get(i);
|
|
if (item.Locale === currentLang)
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// Set initial selection based on current spell language setting
|
|
Component.onCompleted: modelIndex = getCurrentLocaleIndex()
|
|
|
|
property string locale
|
|
function setForIndex(index) {
|
|
var selectedDict = comboModel.get(index);
|
|
if (selectedDict && selectedDict.Locale && selectedDict.Installed) {
|
|
locale = selectedDict.Locale;
|
|
}
|
|
}
|
|
onLocaleChanged: SpellCheckAdapter.setDictionary(locale)
|
|
|
|
// When the count changes, we might need to update the model index
|
|
readonly property int count: installedDictionariesModel.count
|
|
onCountChanged: {
|
|
modelIndex = getCurrentLocaleIndex();
|
|
// If the new index is -1 and we still have dictionaries, use the first one
|
|
if (modelIndex === -1 && installedDictionariesModel.count > 0) {
|
|
modelIndex = 0;
|
|
}
|
|
}
|
|
|
|
// If the model index changes programmatically, we need to update the dictionary path
|
|
onModelIndexChanged: setForIndex(modelIndex)
|
|
}
|