diff options
| author | Basil Semuonov <basil.semuonov@gmail.com> | 2014-08-10 13:27:57 +0400 |
|---|---|---|
| committer | Basil Semuonov <basil.semuonov@gmail.com> | 2014-08-10 13:27:57 +0400 |
| commit | e0c926bd934d857e84faecd970b9e78f7a9e0dcd (patch) | |
| tree | 718c68851e83ec9ed0d3c860548ebd16bdd637bd | |
| parent | 3d797fa577b640efc524467092ac502e783203f5 (diff) | |
Transliterate russian cyrillic
| -rw-r--r-- | app/qml/pages/ManagerPage.qml | 9 | ||||
| -rw-r--r-- | daemon/manager.cpp | 55 | ||||
| -rw-r--r-- | daemon/manager.h | 3 | ||||
| -rw-r--r-- | daemon/settings.h | 3 |
4 files changed, 70 insertions, 0 deletions
diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml index 303c2fa..14a6165 100644 --- a/app/qml/pages/ManagerPage.qml +++ b/app/qml/pages/ManagerPage.qml @@ -41,6 +41,7 @@ Page { id: settings path: "/org/pebbled/settings" property bool silentWhenConnected: false + property bool transliterateCyrillic: false property bool incomingCallNotification: true property bool notificationsCommhistoryd: true property bool notificationsMissedCall: true @@ -157,6 +158,14 @@ Page { settings.silentWhenConnected = !settings.silentWhenConnected; } } + TextSwitch { + text: qsTr("Transliterate Cyrillic") + checked: settings.transliterateCyrillic + automaticCheck: false + onClicked: { + settings.transliterateCyrillic = !settings.transliterateCyrillic; + } + } Label { text: qsTr("Notifications") diff --git a/daemon/manager.cpp b/daemon/manager.cpp index e80673d..14d2020 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -204,23 +204,40 @@ void Manager::onNotifyError(const QString &message) void Manager::onSmsNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateCyrillic").toBool()) { + transliterateCyrillic(sender); + transliterateCyrillic(data); + } watch->sendSMSNotification(sender, data); } void Manager::onTwitterNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateCyrillic").toBool()) { + transliterateCyrillic(sender); + transliterateCyrillic(data); + } watch->sendTwitterNotification(sender, data); } void Manager::onFacebookNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateCyrillic").toBool()) { + transliterateCyrillic(sender); + transliterateCyrillic(data); + } watch->sendFacebookNotification(sender, data); } void Manager::onEmailNotify(const QString &sender, const QString &data,const QString &subject) { + if (settings->property("transliterateCyrillic").toBool()) { + transliterateCyrillic(sender); + transliterateCyrillic(data); + transliterateCyrillic(subject); + } watch->sendEmailNotification(sender, data, subject); } @@ -323,3 +340,41 @@ void Manager::applyProfile() } } } + +void Manager::transliterateCyrillic(const QString &text) +{ + QString translit; + int ru; + static QString rusUpper; + static QString rusLower; + static QStringList latUpper; + static QStringList latLower; + if (rusLower.isEmpty()) { + rusLower = QString::fromUtf8("абвгдеёжзийклмнопрстуфхцчшщыэюя"); + rusUpper = QString::fromUtf8("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ"); + latUpper <<"A"<<"B"<<"V"<<"G"<<"D"<<"E"<<"Jo"<<"Zh"<<"Z"<<"I"<<"J"<<"K"<<"L"<<"M"<<"N" + <<"O"<<"P"<<"R"<<"S"<<"T"<<"U"<<"F"<<"H"<<"C"<<"Ch"<<"Sh"<<"Sh"<<"I"<<"E"<<"Ju"<<"Ja"; + latLower <<"a"<<"b"<<"v"<<"g"<<"d"<<"e"<<"jo"<<"zh"<<"z"<<"i"<<"j"<<"k"<<"l"<<"m"<<"n" + <<"o"<<"p"<<"r"<<"s"<<"t"<<"u"<<"f"<<"h"<<"c"<<"ch"<<"sh"<<"sh"<<"i"<<"e"<<"ju"<<"ja"; + } + for (int i=0; i < text.size(); ++i){ + QChar ch = text[i]; + if (ch.isLetter()) { + if (ch.isUpper()) { + ru = rusUpper.indexOf(ch); + if (ru >= 0) { + translit.append(latUpper[ru]); + continue; + } + } else if (ch.isLower()) { + ru = rusLower.indexOf(ch); + if (ru >= 0) { + translit.append(latLower[ru]); + continue; + } + } + } + translit.append(text[i]); + } + const_cast<QString&>(text) = translit; +} diff --git a/daemon/manager.h b/daemon/manager.h index a062388..cf40aed 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -59,6 +59,9 @@ public: QVariantMap mprisMetadata; QVariantMap getMprisMetadata() { return mprisMetadata; } +protected: + void transliterateCyrillic(const QString &text); + signals: void mprisMetadataChanged(QVariantMap); diff --git a/daemon/settings.h b/daemon/settings.h index 03423e4..87e4919 100644 --- a/daemon/settings.h +++ b/daemon/settings.h @@ -8,6 +8,7 @@ class Settings : public MDConfGroup Q_OBJECT Q_PROPERTY(bool silentWhenConnected MEMBER silentWhenConnected NOTIFY silentWhenConnectedChanged) + Q_PROPERTY(bool transliterateCyrillic MEMBER transliterateCyrillic NOTIFY transliterateCyrillicChanged) Q_PROPERTY(bool incomingCallNotification MEMBER incomingCallNotification NOTIFY incomingCallNotificationChanged) Q_PROPERTY(bool notificationsCommhistoryd MEMBER notificationsCommhistoryd NOTIFY notificationsCommhistorydChanged) Q_PROPERTY(bool notificationsMissedCall MEMBER notificationsMissedCall NOTIFY notificationsMissedCallChanged) @@ -18,6 +19,7 @@ class Settings : public MDConfGroup Q_PROPERTY(bool notificationsOther MEMBER notificationsOther NOTIFY notificationsOtherChanged) Q_PROPERTY(bool notificationsAll MEMBER notificationsAll NOTIFY notificationsAllChanged) bool silentWhenConnected; + bool transliterateCyrillic; bool incomingCallNotification; bool notificationsCommhistoryd; bool notificationsMissedCall; @@ -35,6 +37,7 @@ public: signals: void silentWhenConnectedChanged(bool); + void transliterateCyrillicChanged(bool); void incomingCallNotificationChanged(bool); void notificationsCommhistorydChanged(bool); void notificationsMissedCallChanged(bool); |
