245
248
: mLastEnabledSubViews);
252
void MImOnScreenPlugins::autoDetectActiveSubView()
254
// If no subviews are enabled by the configuration, try to auto-detect
256
if (enabledSubViews().empty()) {
257
autoDetectEnabledSubViews();
260
// If we still don't have an enabled subview, enable the first available
262
if (enabledSubViews().empty()) {
263
MImOnScreenPlugins::SubView subView = mAvailableSubViews.first();
264
setAutoEnabledSubViews(QList<MImOnScreenPlugins::SubView>() << subView);
267
// If we have an active subview in the configuration, check that it is
269
// If we don't have an active subview, auto-activate the first enabled
271
if (mActiveSubView.id.isEmpty() || !isSubViewEnabled(mActiveSubView)) {
272
MImOnScreenPlugins::SubView subView = enabledSubViews().first();
273
setAutoActiveSubView(subView);
278
void MImOnScreenPlugins::autoDetectEnabledSubViews()
280
const QString &plugin = mActiveSubView.plugin;
281
QList<MImOnScreenPlugins::SubView> to_enable;
283
// Try to auto-detect subviews for the selected plugin by looking for
284
// subviews that coincide with the languages selected for use on the
286
// FIXME: This works for the keyboard plugin, but won't work everywhere.
287
// The methodology for auto-configuring subviews should be somehow
289
QStringList langs = QLocale::system().uiLanguages();
290
Q_FOREACH (QString lang, langs) {
291
// Convert to lower case, remove any .utf8 suffix, and use _ as
292
// the separator between language and country.
293
lang = lang.split('.')[0].toLower().replace("-", "_");
295
MImOnScreenPlugins::SubView subView(plugin, lang);
297
// First try the language code as-is
298
if (isSubViewAvailable(subView) && !to_enable.contains(subView)) {
299
to_enable << subView;
303
// See if we get a match if we expand "de" to "de_de"
304
if (!lang.contains('_')) {
305
subView.id = lang + "_" + lang;
306
if (isSubViewAvailable(subView) && !to_enable.contains(subView)) {
307
to_enable << subView;
312
// See if we get a match if we trim "de_at" to "de"
313
subView.id = lang.split("_").first();
314
if (isSubViewAvailable(subView) && !to_enable.contains(subView)) {
315
to_enable << subView;
319
if (!to_enable.isEmpty()) {
320
setAutoEnabledSubViews(to_enable);