Commit 1d289809 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app/DefaultTranslator): check linphone contexts

parent e689cb46
...@@ -38,6 +38,7 @@ public slots: ...@@ -38,6 +38,7 @@ public slots:
private: private:
App (int &argc, char **argv); App (int &argc, char **argv);
~App () = default;
void initContentApp (); void initContentApp ();
......
#include <QDirIterator>
#include <QtDebug> #include <QtDebug>
#include "DefaultTranslator.hpp" #include "DefaultTranslator.hpp"
// =================================================================== // ===================================================================
DefaultTranslator::DefaultTranslator () {
QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
QFileInfo info(it.next());
if (info.suffix() == "qml") {
QString basename = info.baseName();
if (m_contexts.contains(basename))
qWarning() << QStringLiteral("QML file `%1` already exists in context list.").arg(basename);
else
m_contexts << basename;
}
}
}
QString DefaultTranslator::translate ( QString DefaultTranslator::translate (
const char *context, const char *context,
const char *source_text, const char *source_text,
const char *disambiguation, const char *disambiguation,
int n int n
) const { ) const {
if (!m_contexts.contains(context))
return "";
QString translation = QTranslator::translate(context, source_text, disambiguation, n); QString translation = QTranslator::translate(context, source_text, disambiguation, n);
if (translation.length() == 0) if (translation.length() == 0)
......
#ifndef DEFAULT_TRANSLATOR_H_ #ifndef DEFAULT_TRANSLATOR_H_
#define DEFAULT_TRANSLATOR_H_ #define DEFAULT_TRANSLATOR_H_
#include <QSet>
#include <QTranslator> #include <QTranslator>
// =================================================================== // ===================================================================
class DefaultTranslator : public QTranslator { class DefaultTranslator : public QTranslator {
public:
DefaultTranslator ();
~DefaultTranslator () = default;
QString translate ( QString translate (
const char *context, const char *context,
const char *source_text, const char *source_text,
const char *disambiguation = Q_NULLPTR, const char *disambiguation = Q_NULLPTR,
int n = -1 int n = -1
) const override; ) const override;
private:
QSet<QString> m_contexts;
}; };
#endif #endif
#include <algorithm> #include <algorithm>
#include <QDateTime> #include <QDateTime>
#include <QSet>
#include <linphone++/linphone.hh> #include <linphone++/linphone.hh>
#include "../../utils.hpp" #include "../../utils.hpp"
...@@ -89,17 +90,17 @@ void TimelineModel::init_entries () { ...@@ -89,17 +90,17 @@ void TimelineModel::init_entries () {
} }
// Insert calls events. // Insert calls events.
QHash<QString, bool> address_done; QSet<QString> address_done;
for (const auto &call_log : core->getCallLogs()) { for (const auto &call_log : core->getCallLogs()) {
// Get a sip uri to check. // Get a sip uri to check.
QString address = Utils::linphoneStringToQString( QString address = Utils::linphoneStringToQString(
call_log->getRemoteAddress()->asString() call_log->getRemoteAddress()->asString()
); );
if (address_done.value(address)) if (address_done.contains(address))
continue; // Already used. continue; // Already used.
address_done[address] = true; address_done << address;
// Make a new map. // Make a new map.
QVariantMap map; QVariantMap map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment