diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2014-08-10 14:50:04 +0200 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2014-08-10 14:50:04 +0200 |
| commit | ff2a3a520f6562bc127fdcbb9b68029783bc3dcc (patch) | |
| tree | 3b3c50c1f8861f5570175ee0bd32f6cfc2ddd067 /daemon | |
| parent | 96ad10715d2f28913d102ed95bde44184cd512fd (diff) | |
| parent | 7c35daca74fb4a4f8ed7e2fadc22ec18e0295744 (diff) | |
Merge pull request #15 from custodian/transliteration
Transliterate messages before sending to Pebble
Diffstat (limited to 'daemon')
| -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 |
4 files changed, 57 insertions, 2 deletions
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); |
