Commit e61c6cd8 authored by Ronan's avatar Ronan
Browse files

feat(app): many coding style changes

parent d308d0a3
......@@ -22,10 +22,10 @@ class VcardModel : public QObject {
public:
VcardModel (std::shared_ptr<linphone::Vcard> 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);
......
......@@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel {
public:
ContactsListModel (QObject *parent = Q_NULLPTR);
~ContactsListModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override;
......
#include <QDebug>
#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) {
......
......@@ -3,10 +3,9 @@
#include <QSortFilterProxyModel>
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<const ContactModel *, unsigned int> 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_
......@@ -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)
......
......@@ -6,12 +6,18 @@
#include "../contact/VcardModel.hpp"
// ===================================================================
// =============================================================================
class CoreManager : public QObject {
Q_OBJECT;
public:
~CoreManager () = default;
std::shared_ptr<linphone::Core> 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<linphone::Core> 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:
......
#include <QQuickWindow>
#include <QTimer>
#include <QtDebug>
#include <QTimer>
#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);
}
......@@ -5,14 +5,14 @@
#include <QObject>
#include <QQmlComponent>
// ===================================================================
// =============================================================================
class Notifier : public QObject {
Q_OBJECT;
public:
Notifier (QObject *parent = Q_NULLPTR);
virtual ~Notifier ();
~Notifier ();
enum NotificationType {
Call,
......
......@@ -3,7 +3,7 @@
#include <QObject>
// ===================================================================
// =============================================================================
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)
......
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