Commit 37c15e9f authored by Ronan Abhamon's avatar Ronan Abhamon

fix(app): many changes, expose locale and use it with dates, use...

fix(app): many changes, expose locale and use it with dates, use qmlRegisterSingletonType instead of context properties
parent bfe32c44
...@@ -70,19 +70,43 @@ void App::registerTypes () { ...@@ -70,19 +70,43 @@ void App::registerTypes () {
"Linphone", 1, 0, "Presence", "Presence is uncreatable" "Linphone", 1, 0, "Presence", "Presence is uncreatable"
); );
qmlRegisterSingletonType<App>(
"Linphone", 1, 0, "App",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return App::getInstance();
}
);
qmlRegisterSingletonType<CoreManager>(
"Linphone", 1, 0, "CoreManager",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return CoreManager::getInstance();
}
);
ContactsListProxyModel::initContactsListModel(new ContactsListModel()); ContactsListProxyModel::initContactsListModel(new ContactsListModel());
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel"); qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
// Expose the static functions of ContactsListModel.
qmlRegisterSingletonType<ContactsListModel>( qmlRegisterSingletonType<ContactsListModel>(
"Linphone", 1, 0, "ContactsListModel", "Linphone", 1, 0, "ContactsListModel",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{ [](QQmlEngine *, QJSEngine *) -> QObject *{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return ContactsListProxyModel::getContactsListModel(); return ContactsListProxyModel::getContactsListModel();
} }
); );
qmlRegisterSingletonType<AccountSettingsModel>(
"Linphone", 1, 0, "AccountSettingsModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new AccountSettingsModel();
}
);
qmlRegisterSingletonType<TimelineModel>(
"Linphone", 1, 0, "TimelineModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new TimelineModel();
}
);
} }
void App::addContextProperties () { void App::addContextProperties () {
...@@ -96,13 +120,6 @@ void App::addContextProperties () { ...@@ -96,13 +120,6 @@ void App::addContextProperties () {
//context->setContextProperty("CallsWindow", component.create()); //context->setContextProperty("CallsWindow", component.create());
} }
// Models.
context->setContextProperty("AccountSettingsModel", new AccountSettingsModel());
context->setContextProperty("TimelineModel", new TimelineModel());
// Other.
context->setContextProperty("CoreManager", CoreManager::getInstance());
m_notifier = new Notifier(); m_notifier = new Notifier();
context->setContextProperty("Notifier", m_notifier); context->setContextProperty("Notifier", m_notifier);
} }
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
// =================================================================== // ===================================================================
class App : public QApplication { class App : public QApplication {
Q_OBJECT;
public: public:
static void init (int &argc, char **argv) { static void init (int &argc, char **argv) {
if (!m_instance) { if (!m_instance) {
...@@ -28,6 +30,11 @@ public: ...@@ -28,6 +30,11 @@ public:
return &m_engine; return &m_engine;
} }
public slots:
QString locale () const {
return m_locale;
}
private: private:
App (int &argc, char **argv); App (int &argc, char **argv);
...@@ -43,6 +50,7 @@ private: ...@@ -43,6 +50,7 @@ private:
QTranslator m_translator; QTranslator m_translator;
Notifier *m_notifier = nullptr; Notifier *m_notifier = nullptr;
QString m_locale;
static App *m_instance; static App *m_instance;
}; };
......
...@@ -80,7 +80,11 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { ...@@ -80,7 +80,11 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
m_entries.insert(search_entry(map), map); m_entries.insert(search_entry(map), map);
else if (map["timestamp"] > (*it)["timestamp"]) { else if (map["timestamp"] > (*it)["timestamp"]) {
// Remove old entry and insert. // Remove old entry and insert.
it = m_entries.erase(it) - 1; it = m_entries.erase(it);
if (it != m_entries.cbegin())
it--;
m_entries.insert(search_entry(map, &it), map); m_entries.insert(search_entry(map, &it), map);
} }
} }
......
...@@ -4,7 +4,7 @@ import QtQuick 2.7 ...@@ -4,7 +4,7 @@ import QtQuick 2.7
MouseArea { MouseArea {
property alias text: tooltip.text property alias text: tooltip.text
property var toolTipParent: this property var tooltipParent: this
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
...@@ -14,7 +14,7 @@ MouseArea { ...@@ -14,7 +14,7 @@ MouseArea {
Tooltip { Tooltip {
id: tooltip id: tooltip
parent: toolTipParent parent: tooltipParent
visible: containsMouse visible: containsMouse
} }
} }
...@@ -97,13 +97,17 @@ ColumnLayout { ...@@ -97,13 +97,17 @@ ColumnLayout {
: TimelineStyle.contact.username.color.normal : TimelineStyle.contact.username.color.normal
} }
MouseArea { Loader {
anchors.fill: parent anchors.fill: parent
cursorShape: containsMouse sourceComponent: TooltipArea {
? Qt.PointingHandCursor text: $timelineEntry.timestamp.toLocaleString(
: Qt.ArrowCursor Qt.locale(App.locale()), Locale.ShortFormat
hoverEnabled: true )
}
}
MouseArea {
anchors.fill: parent
onClicked: { onClicked: {
view.currentIndex = index view.currentIndex = index
timeline.entrySelected(parent.contact) timeline.entrySelected(parent.contact)
......
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