Commit e61c6cd8 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): many coding style changes

parent d308d0a3
...@@ -22,10 +22,10 @@ class VcardModel : public QObject { ...@@ -22,10 +22,10 @@ class VcardModel : public QObject {
public: public:
VcardModel (std::shared_ptr<linphone::Vcard> vcard) : m_vcard(vcard) {} VcardModel (std::shared_ptr<linphone::Vcard> vcard) : m_vcard(vcard) {}
QString getUsername () const;
~VcardModel () = default; ~VcardModel () = default;
QString getUsername () const;
public slots: public slots:
bool addSipAddress (const QString &sip_address); bool addSipAddress (const QString &sip_address);
void removeSipAddress (const QString &sip_address); void removeSipAddress (const QString &sip_address);
......
...@@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel { ...@@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel {
public: public:
ContactsListModel (QObject *parent = Q_NULLPTR); ContactsListModel (QObject *parent = Q_NULLPTR);
~ContactsListModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override; int rowCount (const QModelIndex &index = QModelIndex()) const override;
......
#include <QDebug> #include <QDebug>
#include "../../utils.hpp" #include "../../utils.hpp"
#include "../contact/ContactModel.hpp"
#include "ContactsListModel.hpp"
#include "ContactsListProxyModel.hpp" #include "ContactsListProxyModel.hpp"
...@@ -131,7 +129,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) ...@@ -131,7 +129,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
return weight; return weight;
} }
// ------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) { void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) {
if (use_connected_filter != m_use_connected_filter) { if (use_connected_filter != m_use_connected_filter) {
......
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
class ContactModel; #include "ContactsListModel.hpp"
class ContactsListModel;
// =================================================================== // =============================================================================
class ContactsListProxyModel : public QSortFilterProxyModel { class ContactsListProxyModel : public QSortFilterProxyModel {
Q_OBJECT; Q_OBJECT;
...@@ -19,6 +18,8 @@ class ContactsListProxyModel : public QSortFilterProxyModel { ...@@ -19,6 +18,8 @@ class ContactsListProxyModel : public QSortFilterProxyModel {
public: public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR); ContactsListProxyModel (QObject *parent = Q_NULLPTR);
~ContactsListProxyModel () = default;
static void initContactsListModel (ContactsListModel *list); static void initContactsListModel (ContactsListModel *list);
static ContactsListModel *getContactsListModel () { static ContactsListModel *getContactsListModel () {
return m_list; return m_list;
...@@ -44,17 +45,17 @@ private: ...@@ -44,17 +45,17 @@ private:
void setConnectedFilter (bool use_connected_filter); void setConnectedFilter (bool use_connected_filter);
static const QRegExp m_search_separators;
// The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`.
static ContactsListModel *m_list;
// It's just a cache to save values computed by `filterAcceptsRow` // It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`. // and reused by `lessThan`.
mutable QHash<const ContactModel *, unsigned int> m_weights; mutable QHash<const ContactModel *, unsigned int> m_weights;
bool m_use_connected_filter; bool m_use_connected_filter;
static const QRegExp m_search_separators;
// The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`.
static ContactsListModel *m_list;
}; };
#endif // CONTACTS_LIST_PROXY_MODEL_H_ #endif // CONTACTS_LIST_PROXY_MODEL_H_
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
#include "CoreManager.hpp" #include "CoreManager.hpp"
// =================================================================== using namespace std;
// =============================================================================
CoreManager *CoreManager::m_instance = nullptr; CoreManager *CoreManager::m_instance = nullptr;
...@@ -16,7 +18,7 @@ VcardModel *CoreManager::createDetachedVcardModel () { ...@@ -16,7 +18,7 @@ VcardModel *CoreManager::createDetachedVcardModel () {
} }
void CoreManager::setDatabasesPaths () { void CoreManager::setDatabasesPaths () {
std::string database_path; string database_path;
database_path = Database::getFriendsListPath(); database_path = Database::getFriendsListPath();
if (database_path.length() == 0) if (database_path.length() == 0)
......
...@@ -6,12 +6,18 @@ ...@@ -6,12 +6,18 @@
#include "../contact/VcardModel.hpp" #include "../contact/VcardModel.hpp"
// =================================================================== // =============================================================================
class CoreManager : public QObject { class CoreManager : public QObject {
Q_OBJECT; Q_OBJECT;
public: public:
~CoreManager () = default;
std::shared_ptr<linphone::Core> getCore () {
return m_core;
}
static void init () { static void init () {
if (!m_instance) { if (!m_instance) {
m_instance = new CoreManager(); m_instance = new CoreManager();
...@@ -22,11 +28,9 @@ public: ...@@ -22,11 +28,9 @@ public:
return m_instance; return m_instance;
} }
std::shared_ptr<linphone::Core> getCore () {
return m_core;
}
public slots: public slots:
// Must be used in a qml scene.
// The ownership of `VcardModel` is `QQmlEngine::JavaScriptOwnership` by default.
VcardModel *createDetachedVcardModel (); VcardModel *createDetachedVcardModel ();
private: private:
......
#include <QQuickWindow> #include <QQuickWindow>
#include <QTimer>
#include <QtDebug> #include <QtDebug>
#include <QTimer>
#include "../../app/App.hpp" #include "../../app/App.hpp"
...@@ -12,14 +12,15 @@ ...@@ -12,14 +12,15 @@
#define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight" #define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight"
#define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset" #define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset"
#define QML_NOTIFICATION_PATH "qrc:/ui/modules/Linphone/Notifications/CallNotification.qml"
// Arbitrary hardcoded values. // Arbitrary hardcoded values.
#define NOTIFICATION_SPACING 10 #define NOTIFICATION_SPACING 10
#define N_MAX_NOTIFICATIONS 15 #define N_MAX_NOTIFICATIONS 15
#define MAX_TIMEOUT 60000 #define MAX_TIMEOUT 60000
// =================================================================== // =============================================================================
// Helpers.
inline int getNotificationSize (const QObject &object, const char *property) { inline int getNotificationSize (const QObject &object, const char *property) {
QVariant variant(object.property(property)); QVariant variant(object.property(property));
bool so_far_so_good; bool so_far_so_good;
...@@ -38,30 +39,28 @@ bool setProperty (QObject &object, const char *property, const T &value) { ...@@ -38,30 +39,28 @@ bool setProperty (QObject &object, const char *property, const T &value) {
QVariant qvariant(value); QVariant qvariant(value);
if (!object.setProperty(property, qvariant)) { if (!object.setProperty(property, qvariant)) {
qWarning() << "Unable to set property `" << property << "`."; qWarning() << QStringLiteral("Unable to set property: `%1`.").arg(property);
return false; return false;
} }
return true; return true;
} }
// ------------------------------------------------------------------- // -----------------------------------------------------------------------------
Notifier::Notifier (QObject *parent) : Notifier::Notifier (QObject *parent) :
QObject(parent) { QObject(parent) {
QQmlEngine *engine = App::getInstance()->getEngine(); QQmlEngine *engine = App::getInstance()->getEngine();
// Build components. // Build components.
m_components[Notifier::Call] = new QQmlComponent( m_components[Notifier::Call] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH));
engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml")
);
// Check errors. // Check errors.
for (int i = 0; i < Notifier::MaxNbTypes; i++) { for (int i = 0; i < Notifier::MaxNbTypes; i++) {
QQmlComponent &component = *m_components[i]; QQmlComponent *component = m_components[i];
if (component.isError()) { if (component->isError()) {
qWarning() << "Errors found in `Notification` component " qWarning() << QStringLiteral("Errors found in `Notification` component %1:").arg(i) <<
<< i << ":" << component.errors(); component->errors();
abort(); abort();
} }
} }
...@@ -72,7 +71,7 @@ Notifier::~Notifier () { ...@@ -72,7 +71,7 @@ Notifier::~Notifier () {
delete m_components[i]; delete m_components[i];
} }
// ------------------------------------------------------------------- // -----------------------------------------------------------------------------
QObject *Notifier::createNotification (Notifier::NotificationType type) { QObject *Notifier::createNotification (Notifier::NotificationType type) {
m_mutex.lock(); m_mutex.lock();
...@@ -88,10 +87,7 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { ...@@ -88,10 +87,7 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) {
QObject *object = m_components[type]->create(); QObject *object = m_components[type]->create();
int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY); int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY);
if ( if (offset == -1 || !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset)) {
offset == -1 ||
!::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset)
) {
delete object; delete object;
m_mutex.unlock(); m_mutex.unlock();
return nullptr; return nullptr;
...@@ -123,10 +119,11 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -123,10 +119,11 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// Called explicitly (by a click on notification for example) // Called explicitly (by a click on notification for example)
// or when single shot happen and if notification is visible. // or when single shot happen and if notification is visible.
QObject::connect(window, &QQuickWindow::visibleChanged, [this](const bool &value) { QObject::connect(
qDebug() << "Update notifications counter, hidden notification detected."; window, &QQuickWindow::visibleChanged, [this](const bool &visible) {
qInfo() << "Update notifications counter, hidden notification detected.";
if (value) if (visible)
qFatal("A notification cannot be visible twice!"); qFatal("A notification cannot be visible twice!");
m_mutex.lock(); m_mutex.lock();
...@@ -141,24 +138,18 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -141,24 +138,18 @@ void Notifier::showNotification (QObject *notification, int timeout) {
); );
// Destroy it after timeout. // Destroy it after timeout.
QTimer::singleShot(timeout, this, [notification]() { QTimer::singleShot(
delete notification; timeout, this, [notification]() {
}); delete notification;
}
);
} }
// ------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Notifier::showCallMessage (
int timeout,
const QString &sip_address
) {
qDebug() << "Show call notification message. (addr=" <<
sip_address << ")";
void Notifier::showCallMessage (int timeout, const QString &) {
QObject *object = createNotification(Notifier::Call); QObject *object = createNotification(Notifier::Call);
if (!object) if (object)
return; showNotification(object, timeout);
showNotification(object, timeout);
} }
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
#include <QObject> #include <QObject>
#include <QQmlComponent> #include <QQmlComponent>
// =================================================================== // =============================================================================
class Notifier : public QObject { class Notifier : public QObject {
Q_OBJECT; Q_OBJECT;
public: public:
Notifier (QObject *parent = Q_NULLPTR); Notifier (QObject *parent = Q_NULLPTR);
virtual ~Notifier (); ~Notifier ();
enum NotificationType { enum NotificationType {
Call, Call,
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <QObject> #include <QObject>
// =================================================================== // =============================================================================
class Presence : public QObject { class Presence : public QObject {
Q_OBJECT; Q_OBJECT;
...@@ -20,6 +20,7 @@ public: ...@@ -20,6 +20,7 @@ public:
UsingAnotherMessagingService, UsingAnotherMessagingService,
Offline Offline
}; };
Q_ENUM(PresenceStatus); Q_ENUM(PresenceStatus);
enum PresenceLevel { enum PresenceLevel {
...@@ -28,9 +29,12 @@ public: ...@@ -28,9 +29,12 @@ public:
Red, Red,
White White
}; };
Q_ENUM(PresenceLevel); Q_ENUM(PresenceLevel);
Presence (QObject *parent = Q_NULLPTR): QObject(parent) { } Presence (QObject *parent = Q_NULLPTR) : QObject(parent) {}
~Presence () = default;
static PresenceLevel getPresenceLevel (const PresenceStatus &presenceStatus) { static PresenceLevel getPresenceLevel (const PresenceStatus &presenceStatus) {
if (presenceStatus == Online) if (presenceStatus == Online)
......
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