diff options
| -rw-r--r-- | app/qml/pages/ManagerPage.qml | 10 | ||||
| -rw-r--r-- | daemon/daemon.pro | 1 | ||||
| -rw-r--r-- | daemon/manager.cpp | 48 | ||||
| -rw-r--r-- | daemon/manager.h | 7 | ||||
| -rw-r--r-- | daemon/settings.h | 3 | ||||
| -rw-r--r-- | rpm/pebble.yaml | 1 |
6 files changed, 68 insertions, 2 deletions
diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml index af247f5..036897e 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 transliterateMessage: false property bool incomingCallNotification: true property bool notificationsCommhistoryd: true property bool notificationsMissedCall: true @@ -157,6 +158,15 @@ Page { settings.silentWhenConnected = !settings.silentWhenConnected; } } + TextSwitch { + text: qsTr("Transliterate messages") + description: qsTr("Messages will be transliterated to ASCII before sending to Pebble") + checked: settings.transliterateMessage + automaticCheck: false + onClicked: { + settings.transliterateMessage = !settings.transliterateMessage; + } + } Label { text: qsTr("Notifications") diff --git a/daemon/daemon.pro b/daemon/daemon.pro index bc0c2e7..0528ec9 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -9,6 +9,7 @@ PKGCONFIG += mlite5 QMAKE_CXXFLAGS += -std=c++0x LIBS += -llog4qt +LIBS += -licuuc -licui18n DEFINES += APP_VERSION=\\\"$$VERSION\\\" diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 3dd9108..fd31e3d 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -182,14 +182,18 @@ void Manager::onActiveVoiceCallStatusChanged() QString Manager::findPersonByNumber(QString number) { + QString person; numberFilter.setValue(number); const QList<QContact> &found = contacts->contacts(numberFilter); if (found.size() == 1) { - return found[0].detail(QContactDetail::TypeDisplayLabel).value(0).toString(); + person = found[0].detail(QContactDetail::TypeDisplayLabel).value(0).toString(); } - return QString(); + if (settings->property("transliterateMessage").toBool()) { + transliterateMessage(person); + } + return person; } void Manager::onVoiceError(const QString &message) @@ -205,23 +209,40 @@ void Manager::onNotifyError(const QString &message) void Manager::onSmsNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateMessage").toBool()) { + transliterateMessage(sender); + transliterateMessage(data); + } watch->sendSMSNotification(sender, data); } void Manager::onTwitterNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateMessage").toBool()) { + transliterateMessage(sender); + transliterateMessage(data); + } watch->sendTwitterNotification(sender, data); } void Manager::onFacebookNotify(const QString &sender, const QString &data) { + if (settings->property("transliterateMessage").toBool()) { + transliterateMessage(sender); + transliterateMessage(data); + } watch->sendFacebookNotification(sender, data); } void Manager::onEmailNotify(const QString &sender, const QString &data,const QString &subject) { + if (settings->property("transliterateMessage").toBool()) { + transliterateMessage(sender); + transliterateMessage(data); + transliterateMessage(subject); + } watch->sendEmailNotification(sender, data, subject); } @@ -324,3 +345,26 @@ void Manager::applyProfile() } } } + +void Manager::transliterateMessage(const QString &text) +{ + if (transliterator.isNull()) { + UErrorCode status = U_ZERO_ERROR; + transliterator.reset(icu::Transliterator::createInstance(icu::UnicodeString::fromUTF8("Any-Latin; Latin-ASCII"),UTRANS_FORWARD, status)); + if (U_FAILURE(status)) { + logger()->warn() << "Error creaing ICU Transliterator \"Any-Latin; Latin-ASCII\":" << u_errorName(status); + } + } + if (!transliterator.isNull()) { + logger()->debug() << "String before transliteration:" << text; + + icu::UnicodeString uword = icu::UnicodeString::fromUTF8(text.toStdString()); + transliterator->transliterate(uword); + + std::string translited; + uword.toUTF8String(translited); + + const_cast<QString&>(text) = QString::fromStdString(translited); + logger()->debug() << "String after transliteration:" << text; + } +} diff --git a/daemon/manager.h b/daemon/manager.h index a062388..9de5667 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -16,6 +16,8 @@ #include <MNotification> #include <Log4Qt/Logger> +#include <unicode/translit.h> + using namespace QtContacts; class Manager : @@ -50,6 +52,8 @@ class Manager : QString lastSeenMpris; + QScopedPointer<icu::Transliterator> transliterator; + public: explicit Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications, Settings *settings); @@ -59,6 +63,9 @@ public: QVariantMap mprisMetadata; QVariantMap getMprisMetadata() { return mprisMetadata; } +protected: + void transliterateMessage(const QString &text); + signals: void mprisMetadataChanged(QVariantMap); diff --git a/daemon/settings.h b/daemon/settings.h index 03423e4..d6db9b6 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 transliterateMessage MEMBER transliterateMessage NOTIFY transliterateMessageChanged) 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 transliterateMessage; bool incomingCallNotification; bool notificationsCommhistoryd; bool notificationsMissedCall; @@ -35,6 +37,7 @@ public: signals: void silentWhenConnectedChanged(bool); + void transliterateMessageChanged(bool); void incomingCallNotificationChanged(bool); void notificationsCommhistorydChanged(bool); void notificationsMissedCallChanged(bool); diff --git a/rpm/pebble.yaml b/rpm/pebble.yaml index b41bc4b..955d024 100644 --- a/rpm/pebble.yaml +++ b/rpm/pebble.yaml @@ -24,6 +24,7 @@ PkgConfigBR: - sailfishapp >= 0.0.10 PkgBR: - log4qt-devel +- libicu-devel Requires: - sailfishsilica-qt5 >= 0.10.9 - systemd-user-session-targets |
