From e61c6cd8933127f791ba065471449d7ecc5c58da Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 15 Dec 2016 14:56:51 +0100 Subject: [PATCH] feat(app): many coding style changes --- tests/src/components/contact/VcardModel.hpp | 4 +- .../components/contacts/ContactsListModel.hpp | 1 + .../contacts/ContactsListProxyModel.cpp | 4 +- .../contacts/ContactsListProxyModel.hpp | 19 +++--- tests/src/components/core/CoreManager.cpp | 6 +- tests/src/components/core/CoreManager.hpp | 14 +++-- tests/src/components/notifier/Notifier.cpp | 61 ++++++++----------- tests/src/components/notifier/Notifier.hpp | 4 +- tests/src/components/presence/Presence.hpp | 8 ++- 9 files changed, 61 insertions(+), 60 deletions(-) diff --git a/tests/src/components/contact/VcardModel.hpp b/tests/src/components/contact/VcardModel.hpp index 3606fca63..2d85d3398 100644 --- a/tests/src/components/contact/VcardModel.hpp +++ b/tests/src/components/contact/VcardModel.hpp @@ -22,10 +22,10 @@ class VcardModel : public QObject { public: VcardModel (std::shared_ptr vcard) : m_vcard(vcard) {} - QString getUsername () const; - ~VcardModel () = default; + QString getUsername () const; + public slots: bool addSipAddress (const QString &sip_address); void removeSipAddress (const QString &sip_address); diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index 524a984d6..de3055780 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel { public: ContactsListModel (QObject *parent = Q_NULLPTR); + ~ContactsListModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index d4286242f..81a78b224 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -1,8 +1,6 @@ #include #include "../../utils.hpp" -#include "../contact/ContactModel.hpp" -#include "ContactsListModel.hpp" #include "ContactsListProxyModel.hpp" @@ -131,7 +129,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) return weight; } -// ------------------------------------------------------------------- +// ----------------------------------------------------------------------------- void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) { if (use_connected_filter != m_use_connected_filter) { diff --git a/tests/src/components/contacts/ContactsListProxyModel.hpp b/tests/src/components/contacts/ContactsListProxyModel.hpp index 81669931f..b4c695ece 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.hpp +++ b/tests/src/components/contacts/ContactsListProxyModel.hpp @@ -3,10 +3,9 @@ #include -class ContactModel; -class ContactsListModel; +#include "ContactsListModel.hpp" -// =================================================================== +// ============================================================================= class ContactsListProxyModel : public QSortFilterProxyModel { Q_OBJECT; @@ -19,6 +18,8 @@ class ContactsListProxyModel : public QSortFilterProxyModel { public: ContactsListProxyModel (QObject *parent = Q_NULLPTR); + ~ContactsListProxyModel () = default; + static void initContactsListModel (ContactsListModel *list); static ContactsListModel *getContactsListModel () { return m_list; @@ -44,17 +45,17 @@ private: 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` // and reused by `lessThan`. mutable QHash m_weights; 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_ diff --git a/tests/src/components/core/CoreManager.cpp b/tests/src/components/core/CoreManager.cpp index 4132187b3..c71931782 100644 --- a/tests/src/components/core/CoreManager.cpp +++ b/tests/src/components/core/CoreManager.cpp @@ -2,7 +2,9 @@ #include "CoreManager.hpp" -// =================================================================== +using namespace std; + +// ============================================================================= CoreManager *CoreManager::m_instance = nullptr; @@ -16,7 +18,7 @@ VcardModel *CoreManager::createDetachedVcardModel () { } void CoreManager::setDatabasesPaths () { - std::string database_path; + string database_path; database_path = Database::getFriendsListPath(); if (database_path.length() == 0) diff --git a/tests/src/components/core/CoreManager.hpp b/tests/src/components/core/CoreManager.hpp index cb6b26a62..bd4723f45 100644 --- a/tests/src/components/core/CoreManager.hpp +++ b/tests/src/components/core/CoreManager.hpp @@ -6,12 +6,18 @@ #include "../contact/VcardModel.hpp" -// =================================================================== +// ============================================================================= class CoreManager : public QObject { Q_OBJECT; public: + ~CoreManager () = default; + + std::shared_ptr getCore () { + return m_core; + } + static void init () { if (!m_instance) { m_instance = new CoreManager(); @@ -22,11 +28,9 @@ public: return m_instance; } - std::shared_ptr getCore () { - return m_core; - } - public slots: + // Must be used in a qml scene. + // The ownership of `VcardModel` is `QQmlEngine::JavaScriptOwnership` by default. VcardModel *createDetachedVcardModel (); private: diff --git a/tests/src/components/notifier/Notifier.cpp b/tests/src/components/notifier/Notifier.cpp index 8f9002181..dc78964a2 100644 --- a/tests/src/components/notifier/Notifier.cpp +++ b/tests/src/components/notifier/Notifier.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include "../../app/App.hpp" @@ -12,14 +12,15 @@ #define NOTIFICATION_HEIGHT_PROPERTY "notificationHeight" #define NOTIFICATION_OFFSET_PROPERTY_NAME "notificationOffset" +#define QML_NOTIFICATION_PATH "qrc:/ui/modules/Linphone/Notifications/CallNotification.qml" + // Arbitrary hardcoded values. #define NOTIFICATION_SPACING 10 #define N_MAX_NOTIFICATIONS 15 #define MAX_TIMEOUT 60000 -// =================================================================== +// ============================================================================= -// Helpers. inline int getNotificationSize (const QObject &object, const char *property) { QVariant variant(object.property(property)); bool so_far_so_good; @@ -38,30 +39,28 @@ bool setProperty (QObject &object, const char *property, const T &value) { QVariant qvariant(value); if (!object.setProperty(property, qvariant)) { - qWarning() << "Unable to set property `" << property << "`."; + qWarning() << QStringLiteral("Unable to set property: `%1`.").arg(property); return false; } return true; } -// ------------------------------------------------------------------- +// ----------------------------------------------------------------------------- Notifier::Notifier (QObject *parent) : QObject(parent) { QQmlEngine *engine = App::getInstance()->getEngine(); // Build components. - m_components[Notifier::Call] = new QQmlComponent( - engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml") - ); + m_components[Notifier::Call] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH)); // Check errors. for (int i = 0; i < Notifier::MaxNbTypes; i++) { - QQmlComponent &component = *m_components[i]; - if (component.isError()) { - qWarning() << "Errors found in `Notification` component " - << i << ":" << component.errors(); + QQmlComponent *component = m_components[i]; + if (component->isError()) { + qWarning() << QStringLiteral("Errors found in `Notification` component %1:").arg(i) << + component->errors(); abort(); } } @@ -72,7 +71,7 @@ Notifier::~Notifier () { delete m_components[i]; } -// ------------------------------------------------------------------- +// ----------------------------------------------------------------------------- QObject *Notifier::createNotification (Notifier::NotificationType type) { m_mutex.lock(); @@ -88,10 +87,7 @@ QObject *Notifier::createNotification (Notifier::NotificationType type) { QObject *object = m_components[type]->create(); int offset = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY); - if ( - offset == -1 || - !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset) - ) { + if (offset == -1 || !::setProperty(*object, NOTIFICATION_OFFSET_PROPERTY_NAME, m_offset)) { delete object; m_mutex.unlock(); return nullptr; @@ -123,10 +119,11 @@ void Notifier::showNotification (QObject *notification, int timeout) { // Called explicitly (by a click on notification for example) // or when single shot happen and if notification is visible. - QObject::connect(window, &QQuickWindow::visibleChanged, [this](const bool &value) { - qDebug() << "Update notifications counter, hidden notification detected."; + QObject::connect( + 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!"); m_mutex.lock(); @@ -141,24 +138,18 @@ void Notifier::showNotification (QObject *notification, int timeout) { ); // Destroy it after timeout. - QTimer::singleShot(timeout, this, [notification]() { - delete notification; - }); + QTimer::singleShot( + 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); - if (!object) - return; - - showNotification(object, timeout); + if (object) + showNotification(object, timeout); } diff --git a/tests/src/components/notifier/Notifier.hpp b/tests/src/components/notifier/Notifier.hpp index a3edbce3c..5535322ec 100644 --- a/tests/src/components/notifier/Notifier.hpp +++ b/tests/src/components/notifier/Notifier.hpp @@ -5,14 +5,14 @@ #include #include -// =================================================================== +// ============================================================================= class Notifier : public QObject { Q_OBJECT; public: Notifier (QObject *parent = Q_NULLPTR); - virtual ~Notifier (); + ~Notifier (); enum NotificationType { Call, diff --git a/tests/src/components/presence/Presence.hpp b/tests/src/components/presence/Presence.hpp index ce921f9d2..d736b4cfd 100644 --- a/tests/src/components/presence/Presence.hpp +++ b/tests/src/components/presence/Presence.hpp @@ -3,7 +3,7 @@ #include -// =================================================================== +// ============================================================================= class Presence : public QObject { Q_OBJECT; @@ -20,6 +20,7 @@ public: UsingAnotherMessagingService, Offline }; + Q_ENUM(PresenceStatus); enum PresenceLevel { @@ -28,9 +29,12 @@ public: Red, White }; + 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) { if (presenceStatus == Online)