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 () {
"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());
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
// Expose the static functions of ContactsListModel.
qmlRegisterSingletonType<ContactsListModel>(
"Linphone", 1, 0, "ContactsListModel",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
[](QQmlEngine *, QJSEngine *) -> QObject *{
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 () {
......@@ -96,13 +120,6 @@ void App::addContextProperties () {
//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();
context->setContextProperty("Notifier", m_notifier);
}
......
......@@ -12,6 +12,8 @@
// ===================================================================
class App : public QApplication {
Q_OBJECT;
public:
static void init (int &argc, char **argv) {
if (!m_instance) {
......@@ -28,6 +30,11 @@ public:
return &m_engine;
}
public slots:
QString locale () const {
return m_locale;
}
private:
App (int &argc, char **argv);
......@@ -43,6 +50,7 @@ private:
QTranslator m_translator;
Notifier *m_notifier = nullptr;
QString m_locale;
static App *m_instance;
};
......
......@@ -80,7 +80,11 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
m_entries.insert(search_entry(map), map);
else if (map["timestamp"] > (*it)["timestamp"]) {
// 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);
}
}
......
......@@ -4,7 +4,7 @@ import QtQuick 2.7
MouseArea {
property alias text: tooltip.text
property var toolTipParent: this
property var tooltipParent: this
anchors.fill: parent
hoverEnabled: true
......@@ -14,7 +14,7 @@ MouseArea {
Tooltip {
id: tooltip
parent: toolTipParent
parent: tooltipParent
visible: containsMouse
}
}
......@@ -97,13 +97,17 @@ ColumnLayout {
: TimelineStyle.contact.username.color.normal
}
MouseArea {
Loader {
anchors.fill: parent
cursorShape: containsMouse
? Qt.PointingHandCursor
: Qt.ArrowCursor
hoverEnabled: true
sourceComponent: TooltipArea {
text: $timelineEntry.timestamp.toLocaleString(
Qt.locale(App.locale()), Locale.ShortFormat
)
}
}
MouseArea {
anchors.fill: parent
onClicked: {
view.currentIndex = index
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