~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to src/mimonscreenplugins.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "mimonscreenplugins.h"
16
16
#include "config.h"
17
17
 
 
18
#include <QLocale>
18
19
#include <QString>
19
20
#include <QSet>
20
21
#include <QDebug>
155
156
void MImOnScreenPlugins::updateAvailableSubViews(const QList<SubView> &availableSubViews)
156
157
{
157
158
    mAvailableSubViews = availableSubViews;
 
159
 
 
160
    autoDetectActiveSubView();
158
161
}
159
162
 
160
163
bool MImOnScreenPlugins::isSubViewAvailable(const SubView &subview) const
245
248
                                               : mLastEnabledSubViews);
246
249
    }
247
250
}
 
251
 
 
252
void MImOnScreenPlugins::autoDetectActiveSubView()
 
253
{
 
254
    // If no subviews are enabled by the configuration, try to auto-detect
 
255
    // them.
 
256
    if (enabledSubViews().empty()) {
 
257
        autoDetectEnabledSubViews();
 
258
    }
 
259
 
 
260
    // If we still don't have an enabled subview, enable the first available
 
261
    // one.
 
262
    if (enabledSubViews().empty()) {
 
263
        MImOnScreenPlugins::SubView subView = mAvailableSubViews.first();
 
264
        setAutoEnabledSubViews(QList<MImOnScreenPlugins::SubView>() << subView);
 
265
    }
 
266
 
 
267
    // If we have an active subview in the configuration, check that it is
 
268
    // enabled
 
269
    // If we don't have an active subview, auto-activate the first enabled
 
270
    // one.
 
271
    if (mActiveSubView.id.isEmpty() || !isSubViewEnabled(mActiveSubView)) {
 
272
        MImOnScreenPlugins::SubView subView = enabledSubViews().first();
 
273
        setAutoActiveSubView(subView);
 
274
    }
 
275
 
 
276
}
 
277
 
 
278
void MImOnScreenPlugins::autoDetectEnabledSubViews()
 
279
{
 
280
    const QString &plugin = mActiveSubView.plugin;
 
281
    QList<MImOnScreenPlugins::SubView> to_enable;
 
282
 
 
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
 
285
    // system.
 
286
    // FIXME: This works for the keyboard plugin, but won't work everywhere.
 
287
    // The methodology for auto-configuring subviews should be somehow
 
288
    // plugin-dictated.
 
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("-", "_");
 
294
 
 
295
        MImOnScreenPlugins::SubView subView(plugin, lang);
 
296
 
 
297
        // First try the language code as-is
 
298
        if (isSubViewAvailable(subView) && !to_enable.contains(subView)) {
 
299
            to_enable << subView;
 
300
            continue;
 
301
        }
 
302
 
 
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;
 
308
            }
 
309
            continue;
 
310
        }
 
311
 
 
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;
 
316
        }
 
317
    }
 
318
 
 
319
    if (!to_enable.isEmpty()) {
 
320
        setAutoEnabledSubViews(to_enable);
 
321
    }
 
322
}