Commit d8ff1b14 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components): replace `broghammerus_reticulatus` variables by `camelusBactrianus`

parent c714ad8d
......@@ -34,7 +34,7 @@ using namespace std;
class AssistantModel::Handlers : public linphone::AccountCreatorListener {
public:
Handlers (AssistantModel *assistant) {
m_assistant = assistant;
mAssistant = assistant;
}
void onCreateAccount (
......@@ -43,14 +43,14 @@ public:
const string &
) override {
if (status == linphone::AccountCreatorStatusAccountCreated)
emit m_assistant->createStatusChanged("");
emit mAssistant->createStatusChanged("");
else {
if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->createStatusChanged(tr("requestFailed"));
emit mAssistant->createStatusChanged(tr("requestFailed"));
else if (status == linphone::AccountCreatorStatusServerError)
emit m_assistant->createStatusChanged(tr("cannotSendSms"));
emit mAssistant->createStatusChanged(tr("cannotSendSms"));
else
emit m_assistant->createStatusChanged(tr("accountAlreadyExists"));
emit mAssistant->createStatusChanged(tr("accountAlreadyExists"));
}
}
......@@ -61,12 +61,12 @@ public:
) override {
if (status == linphone::AccountCreatorStatusAccountExist || status == linphone::AccountCreatorStatusAccountExistWithAlias) {
CoreManager::getInstance()->getCore()->addProxyConfig(creator->configure());
emit m_assistant->loginStatusChanged("");
emit mAssistant->loginStatusChanged("");
} else {
if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->loginStatusChanged(tr("requestFailed"));
emit mAssistant->loginStatusChanged(tr("requestFailed"));
else
emit m_assistant->loginStatusChanged(tr("loginWithUsernameFailed"));
emit mAssistant->loginStatusChanged(tr("loginWithUsernameFailed"));
}
}
......@@ -79,12 +79,12 @@ public:
status == linphone::AccountCreatorStatusAccountActivated ||
status == linphone::AccountCreatorStatusAccountAlreadyActivated
)
emit m_assistant->activateStatusChanged("");
emit mAssistant->activateStatusChanged("");
else {
if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->activateStatusChanged(tr("requestFailed"));
emit mAssistant->activateStatusChanged(tr("requestFailed"));
else
emit m_assistant->activateStatusChanged(tr("smsActivationFailed"));
emit mAssistant->activateStatusChanged(tr("smsActivationFailed"));
}
}
......@@ -96,12 +96,12 @@ public:
if (status == linphone::AccountCreatorStatusAccountActivated) {
CoreManager::getInstance()->getAccountSettingsModel()->addOrUpdateProxyConfig(creator->configure());
emit m_assistant->activateStatusChanged("");
emit mAssistant->activateStatusChanged("");
} else {
if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->activateStatusChanged(tr("requestFailed"));
emit mAssistant->activateStatusChanged(tr("requestFailed"));
else
emit m_assistant->activateStatusChanged(tr("emailActivationFailed"));
emit mAssistant->activateStatusChanged(tr("emailActivationFailed"));
}
}
......@@ -142,40 +142,40 @@ public:
// ) override {}
private:
AssistantModel *m_assistant;
AssistantModel *mAssistant;
};
// -----------------------------------------------------------------------------
AssistantModel::AssistantModel (QObject *parent) : QObject(parent) {
m_handlers = make_shared<AssistantModel::Handlers>(this);
mHandlers = make_shared<AssistantModel::Handlers>(this);
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
m_account_creator = core->createAccountCreator(
mAccountCreator = core->createAccountCreator(
core->getConfig()->getString("assistant", "xmlrpc_url", DEFAULT_XMLRPC_URL)
);
m_account_creator->setListener(m_handlers);
mAccountCreator->setListener(mHandlers);
}
// -----------------------------------------------------------------------------
void AssistantModel::activate () {
if (m_account_creator->getEmail().empty())
m_account_creator->activateAccount();
if (mAccountCreator->getEmail().empty())
mAccountCreator->activateAccount();
else
m_account_creator->isAccountActivated();
mAccountCreator->isAccountActivated();
}
void AssistantModel::create () {
m_account_creator->createAccount();
mAccountCreator->createAccount();
}
void AssistantModel::login () {
m_account_creator->isAccountExist();
mAccountCreator->isAccountExist();
}
void AssistantModel::reset () {
m_account_creator->reset();
mAccountCreator->reset();
emit emailChanged("", "");
emit passwordChanged("", "");
......@@ -186,14 +186,14 @@ void AssistantModel::reset () {
// -----------------------------------------------------------------------------
QString AssistantModel::getEmail () const {
return ::Utils::linphoneStringToQString(m_account_creator->getEmail());
return ::Utils::linphoneStringToQString(mAccountCreator->getEmail());
}
void AssistantModel::setEmail (const QString &email) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error;
switch (m_account_creator->setEmail(::Utils::qStringToLinphoneString(email))) {
switch (mAccountCreator->setEmail(::Utils::qStringToLinphoneString(email))) {
case linphone::AccountCreatorEmailStatusOk:
break;
case linphone::AccountCreatorEmailStatusMalformed:
......@@ -208,14 +208,14 @@ void AssistantModel::setEmail (const QString &email) {
}
QString AssistantModel::getPassword () const {
return ::Utils::linphoneStringToQString(m_account_creator->getPassword());
return ::Utils::linphoneStringToQString(mAccountCreator->getPassword());
}
void AssistantModel::setPassword (const QString &password) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error;
switch (m_account_creator->setPassword(::Utils::qStringToLinphoneString(password))) {
switch (mAccountCreator->setPassword(::Utils::qStringToLinphoneString(password))) {
case linphone::AccountCreatorPasswordStatusOk:
break;
case linphone::AccountCreatorPasswordStatusTooShort:
......@@ -238,27 +238,27 @@ void AssistantModel::setPassword (const QString &password) {
}
QString AssistantModel::getPhoneNumber () const {
return ::Utils::linphoneStringToQString(m_account_creator->getPhoneNumber());
return ::Utils::linphoneStringToQString(mAccountCreator->getPhoneNumber());
}
void AssistantModel::setPhoneNumber (const QString &phone_number) {
void AssistantModel::setPhoneNumber (const QString &phoneNumber) {
// shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error;
// TODO: use the future wrapped function: `set_phone_number`.
emit phoneNumberChanged(phone_number, error);
emit phoneNumberChanged(phoneNumber, error);
}
QString AssistantModel::getUsername () const {
return ::Utils::linphoneStringToQString(m_account_creator->getUsername());
return ::Utils::linphoneStringToQString(mAccountCreator->getUsername());
}
void AssistantModel::setUsername (const QString &username) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error;
switch (m_account_creator->setUsername(::Utils::qStringToLinphoneString(username))) {
switch (mAccountCreator->setUsername(::Utils::qStringToLinphoneString(username))) {
case linphone::AccountCreatorUsernameStatusOk:
break;
case linphone::AccountCreatorUsernameStatusTooShort:
......
......@@ -50,7 +50,7 @@ public:
signals:
void emailChanged (const QString &email, const QString &error);
void passwordChanged (const QString &password, const QString &error);
void phoneNumberChanged (const QString &phone_number, const QString &error);
void phoneNumberChanged (const QString &phoneNumber, const QString &error);
void usernameChanged (const QString &username, const QString &error);
void activateStatusChanged (const QString &error);
......@@ -65,13 +65,13 @@ private:
void setPassword (const QString &password);
QString getPhoneNumber () const;
void setPhoneNumber (const QString &phone_number);
void setPhoneNumber (const QString &phoneNumber);
QString getUsername () const;
void setUsername (const QString &username);
std::shared_ptr<linphone::AccountCreator> m_account_creator;
std::shared_ptr<Handlers> m_handlers;
std::shared_ptr<linphone::AccountCreator> mAccountCreator;
std::shared_ptr<Handlers> mHandlers;
};
#endif // ASSISTANT_MODEL_H_
......@@ -61,14 +61,14 @@ public:
Q_ENUM(CallStatus);
CallModel (std::shared_ptr<linphone::Call> linphone_call);
CallModel (std::shared_ptr<linphone::Call> linphoneCall);
~CallModel () = default;
std::shared_ptr<linphone::Call> getLinphoneCall () const {
return m_linphone_call;
return mLinphoneCall;
}
static void setRecordFile (std::shared_ptr<linphone::CallParams> &call_params);
static void setRecordFile (std::shared_ptr<linphone::CallParams> &callParams);
Q_INVOKABLE void accept ();
Q_INVOKABLE void acceptWithVideo ();
......@@ -96,7 +96,7 @@ private:
CallStatus getStatus () const;
bool isOutgoing () const {
return m_linphone_call->getDir() == linphone::CallDirOutgoing;
return mLinphoneCall->getDir() == linphone::CallDirOutgoing;
}
int getDuration () const;
......@@ -117,11 +117,11 @@ private:
bool getRecording () const;
bool m_paused_by_remote = false;
bool m_paused_by_user = false;
bool m_recording = false;
bool mPausedByRemote = false;
bool mPausedByUser = false;
bool mRecording = false;
std::shared_ptr<linphone::Call> m_linphone_call;
std::shared_ptr<linphone::Call> mLinphoneCall;
};
#endif // CALL_MODEL_H_
......@@ -38,11 +38,11 @@ using namespace std;
inline QList<CallModel *>::iterator findCall (
QList<CallModel *> &list,
const shared_ptr<linphone::Call> &linphone_call
const shared_ptr<linphone::Call> &linphoneCall
) {
return find_if(
list.begin(), list.end(), [linphone_call](CallModel *call) {
return linphone_call == call->getLinphoneCall();
list.begin(), list.end(), [linphoneCall](CallModel *call) {
return linphoneCall == call->getLinphoneCall();
}
);
}
......@@ -50,24 +50,24 @@ inline QList<CallModel *>::iterator findCall (
// -----------------------------------------------------------------------------
CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) {
m_core_handlers = CoreManager::getInstance()->getHandlers();
mCoreHandlers = CoreManager::getInstance()->getHandlers();
QObject::connect(
&(*m_core_handlers), &CoreHandlers::callStateChanged,
this, [this](const shared_ptr<linphone::Call> &linphone_call, linphone::CallState state) {
&(*mCoreHandlers), &CoreHandlers::callStateChanged,
this, [this](const shared_ptr<linphone::Call> &linphoneCall, linphone::CallState state) {
switch (state) {
case linphone::CallStateIncomingReceived:
case linphone::CallStateOutgoingInit:
addCall(linphone_call);
addCall(linphoneCall);
break;
case linphone::CallStateEnd:
case linphone::CallStateError:
removeCall(linphone_call);
removeCall(linphoneCall);
break;
case linphone::CallStateStreamsRunning: {
int index = static_cast<int>(distance(m_list.begin(), findCall(m_list, linphone_call)));
emit callRunning(index, &linphone_call->getData<CallModel>("call-model"));
int index = static_cast<int>(distance(mList.begin(), findCall(mList, linphoneCall)));
emit callRunning(index, &linphoneCall->getData<CallModel>("call-model"));
}
break;
......@@ -79,7 +79,7 @@ CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) {
}
int CallsListModel::rowCount (const QModelIndex &) const {
return m_list.count();
return mList.count();
}
QHash<int, QByteArray> CallsListModel::roleNames () const {
......@@ -91,25 +91,25 @@ QHash<int, QByteArray> CallsListModel::roleNames () const {
QVariant CallsListModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (!index.isValid() || row < 0 || row >= m_list.count())
if (!index.isValid() || row < 0 || row >= mList.count())
return QVariant();
if (role == Qt::DisplayRole)
return QVariant::fromValue(m_list[row]);
return QVariant::fromValue(mList[row]);
return QVariant();
}
CallModel *CallsListModel::getCall (const shared_ptr<linphone::Call> &linphone_call) const {
auto it = findCall(*(const_cast<QList<CallModel *> *>(&m_list)), linphone_call);
return it != m_list.end() ? *it : nullptr;
CallModel *CallsListModel::getCall (const shared_ptr<linphone::Call> &linphoneCall) const {
auto it = findCall(*(const_cast<QList<CallModel *> *>(&mList)), linphoneCall);
return it != mList.end() ? *it : nullptr;
}
// -----------------------------------------------------------------------------
void CallsListModel::launchAudioCall (const QString &sip_uri) const {
void CallsListModel::launchAudioCall (const QString &sipUri) const {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::Address> address = core->interpretUrl(::Utils::qStringToLinphoneString(sip_uri));
shared_ptr<linphone::Address> address = core->interpretUrl(::Utils::qStringToLinphoneString(sipUri));
if (!address)
return;
......@@ -121,9 +121,9 @@ void CallsListModel::launchAudioCall (const QString &sip_uri) const {
core->inviteAddressWithParams(address, params);
}
void CallsListModel::launchVideoCall (const QString &sip_uri) const {
void CallsListModel::launchVideoCall (const QString &sipUri) const {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::Address> address = core->interpretUrl(::Utils::qStringToLinphoneString(sip_uri));
shared_ptr<linphone::Address> address = core->interpretUrl(::Utils::qStringToLinphoneString(sipUri));
if (!address)
return;
......@@ -155,13 +155,13 @@ bool CallsListModel::removeRow (int row, const QModelIndex &parent) {
bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent) {
int limit = row + count - 1;
if (row < 0 || count < 0 || limit >= m_list.count())
if (row < 0 || count < 0 || limit >= mList.count())
return false;
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i)
m_list.takeAt(row)->deleteLater();
mList.takeAt(row)->deleteLater();
endRemoveRows();
......@@ -170,38 +170,38 @@ bool CallsListModel::removeRows (int row, int count, const QModelIndex &parent)
// -----------------------------------------------------------------------------
void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphone_call) {
if (linphone_call->getDir() == linphone::CallDirOutgoing)
void CallsListModel::addCall (const shared_ptr<linphone::Call> &linphoneCall) {
if (linphoneCall->getDir() == linphone::CallDirOutgoing)
App::getInstance()->getCallsWindow()->show();
CallModel *call = new CallModel(linphone_call);
CallModel *call = new CallModel(linphoneCall);
qInfo() << "Add call:" << call;
App::getInstance()->getEngine()->setObjectOwnership(call, QQmlEngine::CppOwnership);
linphone_call->setData("call-model", *call);
linphoneCall->setData("call-model", *call);
int row = m_list.count();
int row = mList.count();
beginInsertRows(QModelIndex(), row, row);
m_list << call;
mList << call;
endInsertRows();
}
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &linphone_call) {
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &linphoneCall) {
// TODO: It will be (maybe) necessary to use a single scheduled function in the future.
QTimer::singleShot(
DELAY_BEFORE_REMOVE_CALL, this, [this, linphone_call]() {
CallModel *call = &linphone_call->getData<CallModel>("call-model");
linphone_call->unsetData("call-model");
DELAY_BEFORE_REMOVE_CALL, this, [this, linphoneCall]() {
CallModel *call = &linphoneCall->getData<CallModel>("call-model");
linphoneCall->unsetData("call-model");
qInfo() << "Removing call:" << call;
int index = m_list.indexOf(call);
int index = mList.indexOf(call);
if (index == -1 || !removeRow(index))
qWarning() << "Unable to remove call:" << call;
if (m_list.empty())
if (mList.empty())
App::getInstance()->getCallsWindow()->close();
}
);
......
......@@ -43,10 +43,10 @@ public:
QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
CallModel *getCall (const std::shared_ptr<linphone::Call> &linphone_call) const;
CallModel *getCall (const std::shared_ptr<linphone::Call> &linphoneCall) const;
Q_INVOKABLE void launchAudioCall (const QString &sip_uri) const;
Q_INVOKABLE void launchVideoCall (const QString &sip_uri) const;
Q_INVOKABLE void launchAudioCall (const QString &sipUri) const;
Q_INVOKABLE void launchVideoCall (const QString &sipUri) const;
Q_INVOKABLE int getRunningCallsNumber () const;
......@@ -59,12 +59,12 @@ private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
void addCall (const std::shared_ptr<linphone::Call> &linphone_call);
void removeCall (const std::shared_ptr<linphone::Call> &linphone_call);
void addCall (const std::shared_ptr<linphone::Call> &linphoneCall);
void removeCall (const std::shared_ptr<linphone::Call> &linphoneCall);
QList<CallModel *> m_list;
QList<CallModel *> mList;
std::shared_ptr<CoreHandlers> m_core_handlers;
std::shared_ptr<CoreHandlers> mCoreHandlers;
};
#endif // CALLS_LIST_MODEL_H_
......@@ -47,24 +47,24 @@ struct ContextInfo {
// -----------------------------------------------------------------------------
CameraRenderer::CameraRenderer () {
m_context_info = new ContextInfo();
mContextInfo = new ContextInfo();
}
CameraRenderer::~CameraRenderer () {
qInfo() << QStringLiteral("Delete context info:") << m_context_info;
qInfo() << QStringLiteral("Delete context info:") << mContextInfo;
CoreManager *core = CoreManager::getInstance();
core->lockVideoRender();
if (m_is_preview)
if (mIsPreview)
CoreManager::getInstance()->getCore()->setNativePreviewWindowId(nullptr);
else if (m_linphone_call)
m_linphone_call->setNativeVideoWindowId(nullptr);
else if (mLinphoneCall)
mLinphoneCall->setNativeVideoWindowId(nullptr);
core->unlockVideoRender();
delete m_context_info;
delete mContextInfo;
}
QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &size) {
......@@ -78,10 +78,10 @@ QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &
// It's not the same thread as render.
core->lockVideoRender();
m_context_info->width = size.width();
m_context_info->height = size.height();
m_context_info->functions = MSFunctions::getInstance()->getFunctions();
m_update_context_info = true;
mContextInfo->width = size.width();
mContextInfo->height = size.height();
mContextInfo->functions = MSFunctions::getInstance()->getFunctions();
mUpdateContextInfo = true;
updateWindowId();
......@@ -91,7 +91,7 @@ QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &
}
void CameraRenderer::render () {
if (!m_linphone_call)
if (!mLinphoneCall)
return;
// Draw with ms filter.
......@@ -102,48 +102,48 @@ void CameraRenderer::render () {
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CoreManager *core = CoreManager::getInstance();
MSFunctions *ms_functions = MSFunctions::getInstance();
MSFunctions *msFunctions = MSFunctions::getInstance();
core->lockVideoRender();
ms_functions->bind(f);
m_linphone_call->oglRender(m_is_preview);
ms_functions->bind(nullptr);
msFunctions->bind(f);
mLinphoneCall->oglRender(mIsPreview);
msFunctions->bind(nullptr);
core->unlockVideoRender();
}
// Synchronize opengl calls with QML.
if (m_window)
m_window->resetOpenGLState();
if (mWindow)
mWindow->resetOpenGLState();
}
void CameraRenderer::synchronize (QQuickFramebufferObject *item) {
// No mutex needed here. It's a synchronized area.
m_window = item->window();
mWindow = item->window();
Camera *camera = qobject_cast<Camera *>(item);
m_linphone_call = camera->getCall()->getLinphoneCall();
m_is_preview = camera->m_is_preview;
mLinphoneCall = camera->getCall()->getLinphoneCall();
mIsPreview = camera->mIsPreview;
updateWindowId();
}
void CameraRenderer::updateWindowId () {
if (!m_update_context_info)
if (!mUpdateContextInfo)
return;
m_update_context_info = false;
mUpdateContextInfo = false;
qInfo() << "Thread" << QThread::currentThread() << QStringLiteral("Set context info (width: %1, height: %2, is_preview: %3):")
.arg(m_context_info->width).arg(m_context_info->height).arg(m_is_preview) << m_context_info;
.arg(mContextInfo->width).arg(mContextInfo->height).arg(mIsPreview) << mContextInfo;
if (m_is_preview)
CoreManager::getInstance()->getCore()->setNativePreviewWindowId(m_context_info);
else if (m_linphone_call)
m_linphone_call->setNativeVideoWindowId(m_context_info);
if (mIsPreview)
CoreManager::getInstance()->getCore()->setNativePreviewWindowId(mContextInfo);
else if (mLinphoneCall)
mLinphoneCall->setNativeVideoWindowId(mContextInfo);
}
// -----------------------------------------------------------------------------
......@@ -155,16 +155,16 @@ Camera::Camera (QQuickItem *parent) : QQuickFramebufferObject(parent) {
// The fbo content must be y-mirrored because the ms rendering is y-inverted.
setMirrorVertically(true);
m_refresh_timer = new QTimer(this);
m_refresh_timer->setInterval(1 / MAX_FPS * 1000);
mRefreshTimer = new QTimer(this);
mRefreshTimer->setInterval(1 / MAX_FPS * 1000);
QObject::connect(
m_refresh_timer, &QTimer::timeout,
mRefreshTimer, &QTimer::timeout,
this, &QQuickFramebufferObject::update,
Qt::DirectConnection
);
m_refresh_timer->start();
mRefreshTimer->start();
}
QQuickFramebufferObject::Renderer *Camera::createRenderer () const {
......@@ -178,25 +178,25 @@ void Camera::mousePressEvent (QMouseEvent *) {
// -----------------------------------------------------------------------------
CallModel *Camera::getCall () const {
return m_call;
return mCall;
}
void Camera::setCall (CallModel *call) {
if (m_call != call) {
m_call = call;
if (mCall != call) {
mCall = call;
update();
emit callChanged(m_call);
emit callChanged(mCall);
}
}
bool Camera::getIsPreview () const {
return m_is_preview;
return mIsPreview;
}
void Camera::setIsPreview (bool status) {
if (m_is_preview != status) {
m_is_preview = status;
if (mIsPreview != status) {
mIsPreview = status;
update();
emit isPreviewChanged(status);
......
......@@ -53,13 +53,13 @@ protected:
private:
void updateWindowId ();
ContextInfo *m_context_info;
bool m_update_context_info = false;
ContextInfo *mContextInfo;
bool mUpdateContextInfo = false;
bool m_is_preview = false;
std::shared_ptr<linphone::Call> m_linphone_call;
bool mIsPreview = false;
std::shared_ptr<linphone::Call> mLinphoneCall;
QQuickWindow *m_window;
QQuickWindow *mWindow;
};
// -----------------------------------------------------------------------------
......@@ -80,7 +80,7 @@ public:
signals:
void callChanged (CallModel *call);
void isPreviewChanged (bool is_preview);
void isPreviewChanged (bool isPreview);
protected:
void mousePressEvent (QMouseEvent *event) override;
......@@ -92,10 +92,10 @@ private:
bool getIsPreview () const;
void setIsPreview (bool status);
bool m_is_preview = false;
CallModel *m_call = nullptr;
bool mIsPreview = false;
CallModel *mCall = nullptr;
QTimer *m_refresh_timer;
QTimer *mRefreshTimer;
};
#endif // CAMERA_H_
......@@ -27,12 +27,12 @@
// =============================================================================
MSFunctions *MSFunctions::m_instance = nullptr;
MSFunctions *MSFunctions::mInstance = nullptr;
// -----------------------------------------------------------------------------
MSFunctions::MSFunctions () {
OpenGlFunctions *f = m_functions = new OpenGlFunctions();
OpenGlFunctions *f = mFunctions = new OpenGlFunctions();
f->glActiveTexture = qtResolveGlActiveTexture;
f->glAttachShader = qtResolveGlAttachShader;
......@@ -73,5 +73,5 @@ MSFunctions::MSFunctions () {
}
MSFunctions::~MSFunctions () {
delete m_functions;
delete mFunctions;
}
......@@ -26,16 +26,16 @@
#include <QOpenGLFunctions>
#define GL_ASSERT() \
Q_ASSERT(m_instance->m_q_functions != NULL); \
Q_ASSERT(QOpenGLContext::currentContext()->functions() == m_instance->m_q_functions);
Q_ASSERT(mInstance->mQtFunctions != NULL); \
Q_ASSERT(QOpenGLContext::currentContext()->functions() == mInstance->mQtFunctions);
#define GL_CALL(CALL) \
GL_ASSERT() \
m_instance->m_q_functions->CALL;
mInstance->mQtFunctions->CALL;
#define GL_CALL_RET(CALL) \
GL_ASSERT() \
return m_instance->m_q_functions->CALL;
return mInstance->mQtFunctions->CALL;
// =============================================================================
......@@ -46,20 +46,20 @@ public:
~MSFunctions ();
void bind (QOpenGLFunctions *f) {
m_q_functions = f; // Qt functions.
mQtFunctions = f; // Qt functions.
}
OpenGlFunctions *getFunctions () {
return m_functions; // Own implementation.
return mFunctions; // Own implementation.
}
// ---------------------------------------------------------------------------
static MSFunctions *getInstance () {
if (!m_instance)
m_instance = new MSFunctions();
if (!mInstance)
mInstance = new MSFunctions();
return m_instance;
return mInstance;
}
// ---------------------------------------------------------------------------
......@@ -213,10 +213,10 @@ public:
private:
MSFunctions ();
OpenGlFunctions *m_functions = nullptr;
QOpenGLFunctions *m_q_functions = nullptr;
OpenGlFunctions *mFunctions = nullptr;
QOpenGLFunctions *mQtFunctions = nullptr;
static MSFunctions *m_instance;
static MSFunctions *mInstance;
};
#undef GL_CALL
......
......@@ -86,7 +86,7 @@ public:
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
QString getSipAddress () const;
void setSipAddress (const QString &sip_address);
void setSipAddress (const QString &sipAddress);
void removeEntry (int id);
void removeAllEntries ();
......@@ -97,10 +97,10 @@ public:
void sendFileMessage (const QString &path);
void downloadFile (int id, const QString &download_path);
void downloadFile (int id, const QString &downloadPath);
signals:
void sipAddressChanged (const QString &sip_address);
void sipAddressChanged (const QString &sipAddress);
void allEntriesRemoved ();
void messageSent (const std::shared_ptr<linphone::ChatMessage> &message);
......@@ -112,12 +112,12 @@ private:
typedef QPair<QVariantMap, std::shared_ptr<void> > ChatEntryData;
void fillMessageEntry (QVariantMap &dest, const std::shared_ptr<linphone::ChatMessage> &message);
void fillCallStartEntry (QVariantMap &dest, const std::shared_ptr<linphone::CallLog> &call_log);
void fillCallEndEntry (QVariantMap &dest, const std::shared_ptr<linphone::CallLog> &call_log);
void fillCallStartEntry (QVariantMap &dest, const std::shared_ptr<linphone::CallLog> &callLog);
void fillCallEndEntry (QVariantMap &dest, const std::shared_ptr<linphone::CallLog> &callLog);
void removeEntry (ChatEntryData &pair);
void insertCall (const std::shared_ptr<linphone::CallLog> &call_log);
void insertCall (const std::shared_ptr<linphone::CallLog> &callLog);
void insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message);
void resetMessagesCount ();
......@@ -125,11 +125,11 @@ private:
void handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
QList<ChatEntryData> m_entries;
std::shared_ptr<linphone::ChatRoom> m_chat_room;
QList<ChatEntryData> mEntries;
std::shared_ptr<linphone::ChatRoom> mChatRoom;
std::shared_ptr<CoreHandlers> m_core_handlers;
std::shared_ptr<MessageHandlers> m_message_handlers;
std::shared_ptr<CoreHandlers> mCoreHandlers;
std::shared_ptr<MessageHandlers> mMessageHandlers;
};
#endif // CHAT_MODEL_H_
......@@ -30,32 +30,32 @@ using namespace std;
class ChatProxyModel::ChatModelFilter : public QSortFilterProxyModel {
public:
ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(&m_chat_model);
setSourceModel(&mChatModel);
}
ChatModel::EntryType getEntryTypeFilter () {
return m_entry_type_filter;
return mEntryTypeFilter;
}
void setEntryTypeFilter (ChatModel::EntryType type) {
m_entry_type_filter = type;
mEntryTypeFilter = type;
invalidate();
}
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &) const override {
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
bool filterAcceptsRow (int sourceRow, const QModelIndex &) const override {
if (mEntryTypeFilter == ChatModel::EntryType::GenericEntry)
return true;
QModelIndex index = sourceModel()->index(source_row, 0, QModelIndex());
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
const QVariantMap &data = index.data().toMap();
return data["type"].toInt() == m_entry_type_filter;
return data["type"].toInt() == mEntryTypeFilter;
}
private:
ChatModel m_chat_model;
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
ChatModel mChatModel;
ChatModel::EntryType mEntryTypeFilter = ChatModel::EntryType::GenericEntry;
};
// =============================================================================
......@@ -63,34 +63,34 @@ private:
const int ChatProxyModel::ENTRIES_CHUNK_SIZE = 50;
ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
m_chat_model_filter = new ChatModelFilter(this);
mChatModelFilter = new ChatModelFilter(this);
setSourceModel(m_chat_model_filter);
setSourceModel(mChatModelFilter);
ChatModel *chat = static_cast<ChatModel *>(m_chat_model_filter->sourceModel());
ChatModel *chat = static_cast<ChatModel *>(mChatModelFilter->sourceModel());
QObject::connect(
chat, &ChatModel::messageReceived, this, [this](const shared_ptr<linphone::ChatMessage> &) {
m_n_max_displayed_entries++;
mMaxDisplayedEntries++;
}
);
QObject::connect(
chat, &ChatModel::messageSent, this, [this](const shared_ptr<linphone::ChatMessage> &) {
m_n_max_displayed_entries++;
mMaxDisplayedEntries++;
}
);
}
void ChatProxyModel::loadMoreEntries () {
int count = rowCount();
int parent_count = m_chat_model_filter->rowCount();
int parentCount = mChatModelFilter->rowCount();
if (count < parent_count) {
// Do not increase `m_n_max_displayed_entries` if it's not necessary...
if (count < parentCount) {
// Do not increase `mMaxDisplayedEntries` if it's not necessary...
// Limit qml calls.
if (count == m_n_max_displayed_entries)
m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE;
if (count == mMaxDisplayedEntries)
mMaxDisplayedEntries += ENTRIES_CHUNK_SIZE;
invalidateFilter();
......@@ -101,59 +101,59 @@ void ChatProxyModel::loadMoreEntries () {
}
void ChatProxyModel::setEntryTypeFilter (ChatModel::EntryType type) {
if (m_chat_model_filter->getEntryTypeFilter() != type) {
m_chat_model_filter->setEntryTypeFilter(type);
if (mChatModelFilter->getEntryTypeFilter() != type) {
mChatModelFilter->setEntryTypeFilter(type);
emit entryTypeFilterChanged(type);
}
}
void ChatProxyModel::removeEntry (int id) {
QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->removeEntry(
m_chat_model_filter->mapToSource(source_index).row()
QModelIndex sourceIndex = mapToSource(index(id, 0));
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->removeEntry(
mChatModelFilter->mapToSource(sourceIndex).row()
);
}
void ChatProxyModel::removeAllEntries () {
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->removeAllEntries();
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->removeAllEntries();
}
void ChatProxyModel::sendMessage (const QString &message) {
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->sendMessage(message);
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->sendMessage(message);
}
void ChatProxyModel::resendMessage (int id) {
QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->resendMessage(
m_chat_model_filter->mapToSource(source_index).row()
QModelIndex sourceIndex = mapToSource(index(id, 0));
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->resendMessage(
mChatModelFilter->mapToSource(sourceIndex).row()
);
}
void ChatProxyModel::sendFileMessage (const QString &path) {
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->sendFileMessage(path);
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->sendFileMessage(path);
}
void ChatProxyModel::downloadFile (int id, const QString &download_path) {
QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->downloadFile(
m_chat_model_filter->mapToSource(source_index).row(), download_path
void ChatProxyModel::downloadFile (int id, const QString &downloadPath) {
QModelIndex sourceIndex = mapToSource(index(id, 0));
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->downloadFile(
mChatModelFilter->mapToSource(sourceIndex).row(), downloadPath
);
}
// -----------------------------------------------------------------------------
bool ChatProxyModel::filterAcceptsRow (int source_row, const QModelIndex &) const {
return m_chat_model_filter->rowCount() - source_row <= m_n_max_displayed_entries;
bool ChatProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &) const {
return mChatModelFilter->rowCount() - sourceRow <= mMaxDisplayedEntries;
}
// -----------------------------------------------------------------------------
QString ChatProxyModel::getSipAddress () const {
return static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->getSipAddress();
return static_cast<ChatModel *>(mChatModelFilter->sourceModel())->getSipAddress();
}
void ChatProxyModel::setSipAddress (const QString &sip_address) {
static_cast<ChatModel *>(m_chat_model_filter->sourceModel())->setSipAddress(
sip_address
void ChatProxyModel::setSipAddress (const QString &sipAddress) {
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->setSipAddress(
sipAddress
);
}
......@@ -50,23 +50,23 @@ public:
Q_INVOKABLE void sendFileMessage (const QString &path);
Q_INVOKABLE void downloadFile (int id, const QString &download_path);
Q_INVOKABLE void downloadFile (int id, const QString &downloadPath);
signals:
void sipAddressChanged (const QString &sip_address);
void sipAddressChanged (const QString &sipAddress);
void moreEntriesLoaded (int n);
void entryTypeFilterChanged (ChatModel::EntryType type);
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
private:
QString getSipAddress () const;
void setSipAddress (const QString &sip_address);
void setSipAddress (const QString &sipAddress);
ChatModelFilter *m_chat_model_filter;
int m_n_max_displayed_entries = ENTRIES_CHUNK_SIZE;
ChatModelFilter *mChatModelFilter;
int mMaxDisplayedEntries = ENTRIES_CHUNK_SIZE;
static const int ENTRIES_CHUNK_SIZE;
};
......
......@@ -38,7 +38,7 @@ inline shared_ptr<linphone::PayloadType> getCodecFromMap (const QVariantMap &map
AbstractCodecsModel::AbstractCodecsModel (QObject *parent) : QAbstractListModel(parent) {}
int AbstractCodecsModel::rowCount (const QModelIndex &) const {
return m_codecs.count();
return mCodecs.count();
}
QHash<int, QByteArray> AbstractCodecsModel::roleNames () const {
......@@ -50,11 +50,11 @@ QHash<int, QByteArray> AbstractCodecsModel::roleNames () const {
QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (!index.isValid() || row < 0 || row >= m_codecs.count())
if (!index.isValid() || row < 0 || row >= mCodecs.count())
return QVariant();
if (role == Qt::DisplayRole)
return m_codecs[row];
return mCodecs[row];
return QVariant();
}
......@@ -62,9 +62,9 @@ QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const {
// -----------------------------------------------------------------------------
void AbstractCodecsModel::enableCodec (int id, bool status) {
Q_ASSERT(id >= 0 && id < m_codecs.count());
Q_ASSERT(id >= 0 && id < mCodecs.count());
QVariantMap &map = m_codecs[id];
QVariantMap &map = mCodecs[id];
shared_ptr<linphone::PayloadType> codec = getCodecFromMap(map);
codec->enable(status);
......@@ -78,9 +78,9 @@ void AbstractCodecsModel::moveCodec (int source, int destination) {
}
void AbstractCodecsModel::setBitrate (int id, int bitrate) {
Q_ASSERT(id >= 0 && id < m_codecs.count());
Q_ASSERT(id >= 0 && id < mCodecs.count());
QVariantMap &map = m_codecs[id];
QVariantMap &map = mCodecs[id];
shared_ptr<linphone::PayloadType> codec = getCodecFromMap(map);
codec->setNormalBitrate(bitrate);
......@@ -89,13 +89,13 @@ void AbstractCodecsModel::setBitrate (int id, int bitrate) {
emit dataChanged(index(id, 0), index(id, 0));
}
void AbstractCodecsModel::setRecvFmtp (int id, const QString &recv_fmtp) {
Q_ASSERT(id >= 0 && id < m_codecs.count());
void AbstractCodecsModel::setRecvFmtp (int id, const QString &recvFmtp) {
Q_ASSERT(id >= 0 && id < mCodecs.count());
QVariantMap &map = m_codecs[id];
QVariantMap &map = mCodecs[id];
shared_ptr<linphone::PayloadType> codec = getCodecFromMap(map);
codec->setRecvFmtp(::Utils::qStringToLinphoneString(recv_fmtp));
codec->setRecvFmtp(::Utils::qStringToLinphoneString(recvFmtp));
map["recvFmtp"] = ::Utils::linphoneStringToQString(codec->getRecvFmtp());
emit dataChanged(index(id, 0), index(id, 0));
......@@ -104,43 +104,43 @@ void AbstractCodecsModel::setRecvFmtp (int id, const QString &recv_fmtp) {
// -----------------------------------------------------------------------------
bool AbstractCodecsModel::moveRows (
const QModelIndex &source_parent,
int source_row,
const QModelIndex &sourceParent,
int sourceRow,
int count,
const QModelIndex &destination_parent,
int destination_child
const QModelIndex &destinationParent,
int destinationChild
) {
int limit = source_row + count - 1;
int limit = sourceRow + count - 1;
{
int n_codecs = m_codecs.count();
int nCodecs = mCodecs.count();
if (
source_row < 0 ||
destination_child < 0 ||
sourceRow < 0 ||
destinationChild < 0 ||
count < 0 ||
destination_child > n_codecs ||
limit >= n_codecs ||
(source_row <= destination_child && source_row + count >= destination_child)
destinationChild > nCodecs ||
limit >= nCodecs ||
(sourceRow <= destinationChild && sourceRow + count >= destinationChild)
)
return false;
}
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
beginMoveRows(sourceParent, sourceRow, limit, destinationParent, destinationChild);
// Update UI.
if (destination_child > source_row) {
--destination_child;
for (int i = source_row; i <= limit; ++i) {
m_codecs.move(source_row, destination_child + i - source_row);
if (destinationChild > sourceRow) {
--destinationChild;
for (int i = sourceRow; i <= limit; ++i) {
mCodecs.move(sourceRow, destinationChild + i - sourceRow);
}
} else {
for (int i = source_row; i <= limit; ++i)
m_codecs.move(source_row + i - source_row, destination_child + i - source_row);
for (int i = sourceRow; i <= limit; ++i)
mCodecs.move(sourceRow + i - sourceRow, destinationChild + i - sourceRow);
}
// Update linphone codecs list.
list<shared_ptr<linphone::PayloadType> > codecs;
for (const auto &map : m_codecs)
for (const auto &map : mCodecs)
codecs.push_back(getCodecFromMap(map));
updateCodecs(codecs);
......@@ -151,7 +151,7 @@ bool AbstractCodecsModel::moveRows (
// -----------------------------------------------------------------------------
void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &codec) {
void AbstractCodecsModel::addCodec (shared_ptr<linphone::PayloadType> &codec) {
QVariantMap map;
map["bitrate"] = codec->getNormalBitrate();
......@@ -167,5 +167,5 @@ void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &code
map["recvFmtp"] = ::Utils::linphoneStringToQString(codec->getRecvFmtp());
map["__codec"] = QVariant::fromValue(codec);
m_codecs << map;
mCodecs << map;
}
......@@ -49,15 +49,15 @@ public:
Q_INVOKABLE void moveCodec (int source, int destination);
Q_INVOKABLE void setBitrate (int id, int bitrate);
Q_INVOKABLE void setRecvFmtp (int id, const QString &recv_fmtp);
Q_INVOKABLE void setRecvFmtp (int id, const QString &recvFmtp);
protected:
bool moveRows (
const QModelIndex &source_parent,
int source_row,
const QModelIndex &sourceParent,
int sourceRow,
int count,
const QModelIndex &destination_parent,
int destination_child
const QModelIndex &destinationParent,
int destinationChild
) override;
void addCodec (std::shared_ptr<linphone::PayloadType> &codec);
......@@ -65,7 +65,7 @@ protected:
virtual void updateCodecs (std::list<std::shared_ptr<linphone::PayloadType> > &codecs) = 0;
private:
QList<QVariantMap> m_codecs;
QList<QVariantMap> mCodecs;
};
Q_DECLARE_METATYPE(std::shared_ptr<linphone::PayloadType> );
......
......@@ -30,12 +30,12 @@ using namespace std;
// =============================================================================
ContactModel::ContactModel (QObject *parent, shared_ptr<linphone::Friend> linphone_friend) : QObject(parent) {
m_linphone_friend = linphone_friend;
m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());
ContactModel::ContactModel (QObject *parent, shared_ptr<linphone::Friend> linphoneFriend) : QObject(parent) {
mLinphoneFriend = linphoneFriend;
mVcard = make_shared<VcardModel>(linphoneFriend->getVcard());
App::getInstance()->getEngine()->setObjectOwnership(m_vcard.get(), QQmlEngine::CppOwnership);
m_linphone_friend->setData("contact-model", *this);
App::getInstance()->getEngine()->setObjectOwnership(mVcard.get(), QQmlEngine::CppOwnership);
mLinphoneFriend->setData("contact-model", *this);
}
ContactModel::ContactModel (QObject *parent, VcardModel *vcard) : QObject(parent) {
......@@ -45,17 +45,17 @@ ContactModel::ContactModel (QObject *parent, VcardModel *vcard) : QObject(parent
if (engine->objectOwnership(vcard) == QQmlEngine::CppOwnership)
throw invalid_argument("A contact is already linked to this vcard.");
m_linphone_friend = linphone::Friend::newFromVcard(vcard->m_vcard);
m_linphone_friend->setData("contact-model", *this);
mLinphoneFriend = linphone::Friend::newFromVcard(vcard->mVcard);
mLinphoneFriend->setData("contact-model", *this);
m_vcard.reset(vcard);
mVcard.reset(vcard);
engine->setObjectOwnership(vcard, QQmlEngine::CppOwnership);
}
void ContactModel::refreshPresence () {
Presence::PresenceStatus status = static_cast<Presence::PresenceStatus>(
m_linphone_friend->getConsolidatedPresence()
mLinphoneFriend->getConsolidatedPresence()
);
emit presenceStatusChanged(status);
......@@ -63,41 +63,41 @@ void ContactModel::refreshPresence () {
}
void ContactModel::startEdit () {
m_linphone_friend->edit();
m_old_sip_addresses = m_vcard->getSipAddresses();
mLinphoneFriend->edit();
mOldSipAddresses = mVcard->getSipAddresses();
}
void ContactModel::endEdit () {
m_linphone_friend->done();
mLinphoneFriend->done();
QVariantList sip_addresses = m_vcard->getSipAddresses();
QVariantList sipAddresses = mVcard->getSipAddresses();
QSet<QString> done;
for (const auto &variant_a : m_old_sip_addresses) {
for (const auto &variantA : mOldSipAddresses) {
next:
const QString &sip_address = variant_a.toString();
if (done.contains(sip_address))
const QString &sipAddress = variantA.toString();
if (done.contains(sipAddress))
continue;
done.insert(sip_address);
done.insert(sipAddress);
// Check if old sip address exists in new set => No changes.
for (const auto &variant_b : sip_addresses) {
if (sip_address == variant_b.toString())
for (const auto &variantB : sipAddresses) {
if (sipAddress == variantB.toString())
goto next;
}
emit sipAddressRemoved(sip_address);
emit sipAddressRemoved(sipAddress);
}
m_old_sip_addresses.clear();
mOldSipAddresses.clear();
for (const auto &variant : sip_addresses) {
const QString &sip_address = variant.toString();
if (done.contains(sip_address))
for (const auto &variant : sipAddresses) {
const QString &sipAddress = variant.toString();
if (done.contains(sipAddress))
continue;
done.insert(sip_address);
done.insert(sipAddress);
emit sipAddressAdded(sip_address);
emit sipAddressAdded(sipAddress);
}
emit contactUpdated();
......@@ -105,14 +105,14 @@ next:
void ContactModel::abortEdit () {
// TODO: call linphone friend abort function when available.
// m_linphone_friend->abort();
m_old_sip_addresses.clear();
// mLinphoneFriend->abort();
mOldSipAddresses.clear();
emit contactUpdated();
}
Presence::PresenceStatus ContactModel::getPresenceStatus () const {
return static_cast<Presence::PresenceStatus>(m_linphone_friend->getConsolidatedPresence());
return static_cast<Presence::PresenceStatus>(mLinphoneFriend->getConsolidatedPresence());
}
Presence::PresenceLevel ContactModel::getPresenceLevel () const {
......
......@@ -40,12 +40,12 @@ class ContactModel : public QObject {
friend class SmartSearchBarModel;
public:
ContactModel (QObject *parent, std::shared_ptr<linphone::Friend> linphone_friend);
ContactModel (QObject *parent, std::shared_ptr<linphone::Friend> linphoneFriend);
ContactModel (QObject *parent, VcardModel *vcard);
~ContactModel () = default;
std::shared_ptr<VcardModel> getVcardModel () const {
return m_vcard;
return mVcard;
}
void refreshPresence ();
......@@ -58,21 +58,21 @@ signals:
void contactUpdated ();
void presenceStatusChanged (Presence::PresenceStatus status);
void presenceLevelChanged (Presence::PresenceLevel level);
void sipAddressAdded (const QString &sip_address);
void sipAddressRemoved (const QString &sip_address);
void sipAddressAdded (const QString &sipAddress);
void sipAddressRemoved (const QString &sipAddress);
private:
Presence::PresenceStatus getPresenceStatus () const;
Presence::PresenceLevel getPresenceLevel () const;
VcardModel *getVcardModelPtr () const {
return m_vcard.get();
return mVcard.get();
}
QVariantList m_old_sip_addresses;
QVariantList mOldSipAddresses;
std::shared_ptr<VcardModel> m_vcard;
std::shared_ptr<linphone::Friend> m_linphone_friend;
std::shared_ptr<VcardModel> mVcard;
std::shared_ptr<linphone::Friend> mLinphoneFriend;
};
Q_DECLARE_METATYPE(ContactModel *);
......
......@@ -42,32 +42,32 @@ class VcardModel : public QObject {
friend class ContactModel;
public:
VcardModel (std::shared_ptr<linphone::Vcard> vcard) : m_vcard(vcard) {}
VcardModel (std::shared_ptr<linphone::Vcard> vcard) : mVcard(vcard) {}
~VcardModel ();
QString getUsername () const;
QVariantList getSipAddresses () const;
Q_INVOKABLE bool addSipAddress (const QString &sip_address);
Q_INVOKABLE void removeSipAddress (const QString &sip_address);
Q_INVOKABLE bool updateSipAddress (const QString &old_sip_address, const QString &sip_address);
Q_INVOKABLE bool addSipAddress (const QString &sipAddress);
Q_INVOKABLE void removeSipAddress (const QString &sipAddress);
Q_INVOKABLE bool updateSipAddress (const QString &oldSipAddress, const QString &sipAddress);
Q_INVOKABLE bool addCompany (const QString &company);
Q_INVOKABLE void removeCompany (const QString &company);
Q_INVOKABLE bool updateCompany (const QString &old_company, const QString &company);
Q_INVOKABLE bool updateCompany (const QString &oldCompany, const QString &company);
Q_INVOKABLE bool addEmail (const QString &email);
Q_INVOKABLE void removeEmail (const QString &email);
Q_INVOKABLE bool updateEmail (const QString &old_email, const QString &email);
Q_INVOKABLE bool updateEmail (const QString &oldEmail, const QString &email);
Q_INVOKABLE bool addUrl (const QString &url);
Q_INVOKABLE void removeUrl (const QString &url);
Q_INVOKABLE bool updateUrl (const QString &old_url, const QString &url);
Q_INVOKABLE bool updateUrl (const QString &oldUrl, const QString &url);
Q_INVOKABLE void setStreet (const QString &street);
Q_INVOKABLE void setLocality (const QString &locality);
Q_INVOKABLE void setPostalCode (const QString &postal_code);
Q_INVOKABLE void setPostalCode (const QString &postalCode);
Q_INVOKABLE void setCountry (const QString &country);
signals:
......@@ -84,7 +84,7 @@ private:
QVariantList getEmails () const;
QVariantList getUrls () const;
std::shared_ptr<linphone::Vcard> m_vcard;
std::shared_ptr<linphone::Vcard> mVcard;
};
Q_DECLARE_METATYPE(VcardModel *);
......
......@@ -33,11 +33,11 @@ using namespace std;
// =============================================================================
ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(parent) {
m_linphone_friends = CoreManager::getInstance()->getCore()->getFriendsLists().front();
mLinphoneFriends = CoreManager::getInstance()->getCore()->getFriendsLists().front();
// Init contacts with linphone friends list.
for (const auto &friend_ : m_linphone_friends->getFriends()) {
ContactModel *contact = new ContactModel(this, friend_);
for (const auto &_friend : mLinphoneFriends->getFriends()) {
ContactModel *contact = new ContactModel(this, _friend);
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
......@@ -48,7 +48,7 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare
}
int ContactsListModel::rowCount (const QModelIndex &) const {
return m_list.count();
return mList.count();
}
QHash<int, QByteArray> ContactsListModel::roleNames () const {
......@@ -60,11 +60,11 @@ QHash<int, QByteArray> ContactsListModel::roleNames () const {
QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (!index.isValid() || row < 0 || row >= m_list.count())
if (!index.isValid() || row < 0 || row >= mList.count())
return QVariant();
if (role == Qt::DisplayRole)
return QVariant::fromValue(m_list[row]);
return QVariant::fromValue(mList[row]);
return QVariant();
}
......@@ -76,15 +76,15 @@ bool ContactsListModel::removeRow (int row, const QModelIndex &parent) {
bool ContactsListModel::removeRows (int row, int count, const QModelIndex &parent) {
int limit = row + count - 1;
if (row < 0 || count < 0 || limit >= m_list.count())
if (row < 0 || count < 0 || limit >= mList.count())
return false;
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) {
ContactModel *contact = m_list.takeAt(row);
ContactModel *contact = mList.takeAt(row);
m_linphone_friends->removeFriend(contact->m_linphone_friend);
mLinphoneFriends->removeFriend(contact->mLinphoneFriend);
emit contactRemoved(contact);
contact->deleteLater();
......@@ -104,7 +104,7 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
qInfo() << "Add contact:" << contact;
if (
m_linphone_friends->addFriend(contact->m_linphone_friend) !=
mLinphoneFriends->addFriend(contact->mLinphoneFriend) !=
linphone::FriendListStatus::FriendListStatusOK
) {
qWarning() << "Unable to add friend from vcard:" << vcard;
......@@ -112,7 +112,7 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
return nullptr;
}
int row = m_list.count();
int row = mList.count();
beginInsertRows(QModelIndex(), row, row);
addContact(contact);
......@@ -126,7 +126,7 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
void ContactsListModel::removeContact (ContactModel *contact) {
qInfo() << "Removing contact:" << contact;
int index = m_list.indexOf(contact);
int index = mList.indexOf(contact);
if (index == -1 || !removeRow(index))
qWarning() << "Unable to remove contact:" << contact;
}
......@@ -141,15 +141,15 @@ void ContactsListModel::addContact (ContactModel *contact) {
}
);
QObject::connect(
contact, &ContactModel::sipAddressAdded, this, [this, contact](const QString &sip_address) {
emit sipAddressAdded(contact, sip_address);
contact, &ContactModel::sipAddressAdded, this, [this, contact](const QString &sipAddress) {
emit sipAddressAdded(contact, sipAddress);
}
);
QObject::connect(
contact, &ContactModel::sipAddressRemoved, this, [this, contact](const QString &sip_address) {
emit sipAddressRemoved(contact, sip_address);
contact, &ContactModel::sipAddressRemoved, this, [this, contact](const QString &sipAddress) {
emit sipAddressRemoved(contact, sipAddress);
}
);
m_list << contact;
mList << contact;
}
......@@ -56,14 +56,14 @@ signals:
void contactRemoved (const ContactModel *contact);
void contactUpdated (ContactModel *contact);
void sipAddressAdded (ContactModel *contact, const QString &sip_address);
void sipAddressRemoved (ContactModel *contact, const QString &sip_address);
void sipAddressAdded (ContactModel *contact, const QString &sipAddress);
void sipAddressRemoved (ContactModel *contact, const QString &sipAddress);
private:
void addContact (ContactModel *contact);
QList<ContactModel *> m_list;
std::shared_ptr<linphone::FriendList> m_linphone_friends;
QList<ContactModel *> mList;
std::shared_ptr<linphone::FriendList> mLinphoneFriends;
};
#endif // CONTACTS_LIST_MODEL_H_
......@@ -51,7 +51,7 @@ using namespace std;
// a separator like ` word`.
//
// - [_.-;@ ] is the main pattern (a separator).
const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
const QRegExp ContactsListProxyModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]");
// -----------------------------------------------------------------------------
......@@ -63,38 +63,38 @@ ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterPr
// -----------------------------------------------------------------------------
void ContactsListProxyModel::setFilter (const QString &pattern) {
m_filter = pattern;
mFilter = pattern;
invalidate();
}
// -----------------------------------------------------------------------------
bool ContactsListProxyModel::filterAcceptsRow (
int source_row,
const QModelIndex &source_parent
int sourceRow,
const QModelIndex &sourceParent
) const {
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
const ContactModel *contact = index.data().value<ContactModel *>();
m_weights[contact] = static_cast<unsigned int>(round(computeContactWeight(contact)));
mWeights[contact] = static_cast<unsigned int>(round(computeContactWeight(contact)));
return m_weights[contact] > 0 && (
!m_use_connected_filter ||
return mWeights[contact] > 0 && (
!mUseConnectedFilter ||
contact->getPresenceLevel() != Presence::PresenceLevel::White
);
}
bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
const ContactModel *contact_a = sourceModel()->data(left).value<ContactModel *>();
const ContactModel *contact_b = sourceModel()->data(right).value<ContactModel *>();
const ContactModel *contactA = sourceModel()->data(left).value<ContactModel *>();
const ContactModel *contactB = sourceModel()->data(right).value<ContactModel *>();
unsigned int weight_a = m_weights[contact_a];
unsigned int weight_b = m_weights[contact_b];
unsigned int weightA = mWeights[contactA];
unsigned int weightB = mWeights[contactB];
// Sort by weight and name.
return weight_a > weight_b || (
weight_a == weight_b &&
contact_a->m_linphone_friend->getName() <= contact_b->m_linphone_friend->getName()
return weightA > weightB || (
weightA == weightB &&
contactA->mLinphoneFriend->getName() <= contactB->mLinphoneFriend->getName()
);
}
......@@ -105,12 +105,12 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float
int offset = -1;
// Search pattern.
while ((index = string.indexOf(m_filter, index + 1, Qt::CaseInsensitive)) != -1) {
while ((index = string.indexOf(mFilter, index + 1, Qt::CaseInsensitive)) != -1) {
// Search n chars between one separator and index.
int tmp_offset = index - string.lastIndexOf(m_search_separators, index) - 1;
int tmpOffset = index - string.lastIndexOf(mSearchSeparators, index) - 1;
if ((tmp_offset != -1 && tmp_offset < offset) || offset == -1)
if ((offset = tmp_offset) == 0) break;
if ((tmpOffset != -1 && tmpOffset < offset) || offset == -1)
if ((offset = tmpOffset) == 0) break;
}
switch (offset) {
......@@ -129,7 +129,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel *contact)
float weight = computeStringWeight(contact->getVcardModel()->getUsername(), USERNAME_WEIGHT);
// Get all contact's addresses.
const list<shared_ptr<linphone::Address> > addresses = contact->m_linphone_friend->getAddresses();
const list<shared_ptr<linphone::Address> > addresses = contact->mLinphoneFriend->getAddresses();
float size = static_cast<float>(addresses.size());
for (auto it = addresses.cbegin(); it != addresses.cend(); ++it)
......@@ -143,9 +143,9 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel *contact)
// -----------------------------------------------------------------------------
void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) {
if (use_connected_filter != m_use_connected_filter) {
m_use_connected_filter = use_connected_filter;
void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) {
if (useConnectedFilter != mUseConnectedFilter) {
mUseConnectedFilter = useConnectedFilter;
invalidate();
}
}
......@@ -46,7 +46,7 @@ public:
Q_INVOKABLE void setFilter (const QString &pattern);
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
private:
......@@ -54,19 +54,19 @@ private:
float computeContactWeight (const ContactModel *contact) const;
bool isConnectedFilterUsed () const {
return m_use_connected_filter;
return mUseConnectedFilter;
}
void setConnectedFilter (bool use_connected_filter);
void setConnectedFilter (bool useConnectedFilter);
QString m_filter;
bool m_use_connected_filter = false;
QString mFilter;
bool mUseConnectedFilter = false;
// It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`.
mutable QHash<const ContactModel *, unsigned int> m_weights;
mutable QHash<const ContactModel *, unsigned int> mWeights;
static const QRegExp m_search_separators;
static const QRegExp mSearchSeparators;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H_
......@@ -34,10 +34,10 @@ using namespace std;
void CoreHandlers::onAuthenticationRequested (
const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::AuthInfo> &auth_info,
const shared_ptr<linphone::AuthInfo> &authInfo,
linphone::AuthMethod
) {
emit authenticationRequested(auth_info);
emit authenticationRequested(authInfo);
}
void CoreHandlers::onCallStateChanged (
......@@ -57,9 +57,9 @@ void CoreHandlers::onMessageReceived (
const shared_ptr<linphone::ChatRoom> &,
const shared_ptr<linphone::ChatMessage> &message
) {
const string content_type = message->getContentType();
const string contentType = message->getContentType();
if (content_type == "text/plain" || content_type == "application/vnd.gsma.rcs-ft-http+xml") {
if (contentType == "text/plain" || contentType == "application/vnd.gsma.rcs-ft-http+xml") {
emit messageReceived(message);
const App *app = App::getInstance();
......@@ -71,24 +71,24 @@ void CoreHandlers::onMessageReceived (
void CoreHandlers::onNotifyPresenceReceivedForUriOrTel (
const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::Friend> &,
const string &uri_or_tel,
const shared_ptr<const linphone::PresenceModel> &presence_model
const string &uriOrTel,
const shared_ptr<const linphone::PresenceModel> &presenceModel
) {
emit presenceReceived(::Utils::linphoneStringToQString(uri_or_tel), presence_model);
emit presenceReceived(::Utils::linphoneStringToQString(uriOrTel), presenceModel);
}
void CoreHandlers::onNotifyPresenceReceived (
const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::Friend> &linphone_friend
const shared_ptr<linphone::Friend> &linphoneFriend
) {
linphone_friend->getData<ContactModel>("contact-model").refreshPresence();
linphoneFriend->getData<ContactModel>("contact-model").refreshPresence();
}
void CoreHandlers::onRegistrationStateChanged (
const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::ProxyConfig> &proxy_config,
const shared_ptr<linphone::ProxyConfig> &proxyConfig,
linphone::RegistrationState state,
const string &
) {
emit registrationStateChanged(proxy_config, state);
emit registrationStateChanged(proxyConfig, state);
}
......@@ -34,16 +34,16 @@ class CoreHandlers :
Q_OBJECT;
signals:
void authenticationRequested (const std::shared_ptr<linphone::AuthInfo> &auth_info);
void authenticationRequested (const std::shared_ptr<linphone::AuthInfo> &authInfo);
void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void messageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
void presenceReceived (const QString &sip_address, const std::shared_ptr<const linphone::PresenceModel> &presence_model);
void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxy_config, linphone::RegistrationState state);
void presenceReceived (const QString &sipAddress, const std::shared_ptr<const linphone::PresenceModel> &presenceModel);
void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig, linphone::RegistrationState state);
private:
void onAuthenticationRequested (
const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::AuthInfo> &auth_info,
const std::shared_ptr<linphone::AuthInfo> &authInfo,
linphone::AuthMethod method
) override;
......@@ -62,19 +62,19 @@ private:
void onNotifyPresenceReceivedForUriOrTel (
const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::Friend> &linphone_friend,
const std::string &uri_or_tel,
const std::shared_ptr<const linphone::PresenceModel> &presence_model
const std::shared_ptr<linphone::Friend> &linphoneFriend,
const std::string &uriOrTel,
const std::shared_ptr<const linphone::PresenceModel> &presenceModel
) override;
void onNotifyPresenceReceived (
const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::Friend> &linphone_friend
const std::shared_ptr<linphone::Friend> &linphoneFriend
) override;
void onRegistrationStateChanged (
const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::ProxyConfig> &proxy_config,
const std::shared_ptr<linphone::ProxyConfig> &proxyConfig,
linphone::RegistrationState state,
const std::string &message
) override;
......
......@@ -34,42 +34,42 @@ using namespace std;
// =============================================================================
CoreManager *CoreManager::m_instance = nullptr;
CoreManager *CoreManager::mInstance = nullptr;
CoreManager::CoreManager (QObject *parent, const QString &config_path) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
m_promise_build = QtConcurrent::run(this, &CoreManager::createLinphoneCore, config_path);
CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject(parent), mHandlers(make_shared<CoreHandlers>()) {
mPromiseBuild = QtConcurrent::run(this, &CoreManager::createLinphoneCore, configPath);
QObject::connect(
&m_promise_watcher, &QFutureWatcher<void>::finished, this, []() {
m_instance->m_calls_list_model = new CallsListModel(m_instance);
m_instance->m_contacts_list_model = new ContactsListModel(m_instance);
m_instance->m_sip_addresses_model = new SipAddressesModel(m_instance);
m_instance->m_settings_model = new SettingsModel(m_instance);
m_instance->m_account_settings_model = new AccountSettingsModel(m_instance);
emit m_instance->linphoneCoreCreated();
&mPromiseWatcher, &QFutureWatcher<void>::finished, this, []() {
mInstance->mCallsListModel = new CallsListModel(mInstance);
mInstance->mContactsListModel = new ContactsListModel(mInstance);
mInstance->mSipAddressesModel = new SipAddressesModel(mInstance);
mInstance->mSettingsModel = new SettingsModel(mInstance);
mInstance->mAccountSettingsModel = new AccountSettingsModel(mInstance);
emit mInstance->linphoneCoreCreated();
}
);
m_promise_watcher.setFuture(m_promise_build);
mPromiseWatcher.setFuture(mPromiseBuild);
}
void CoreManager::enableHandlers () {
m_cbs_timer->start();
mCbsTimer->start();
}
// -----------------------------------------------------------------------------
void CoreManager::init (QObject *parent, const QString &config_path) {
if (m_instance)
void CoreManager::init (QObject *parent, const QString &configPath) {
if (mInstance)
return;
m_instance = new CoreManager(parent, config_path);
mInstance = new CoreManager(parent, configPath);
QTimer *timer = m_instance->m_cbs_timer = new QTimer(m_instance);
QTimer *timer = mInstance->mCbsTimer = new QTimer(mInstance);
timer->setInterval(20);
QObject::connect(timer, &QTimer::timeout, m_instance, &CoreManager::iterate);
QObject::connect(timer, &QTimer::timeout, mInstance, &CoreManager::iterate);
}
// -----------------------------------------------------------------------------
......@@ -80,27 +80,27 @@ VcardModel *CoreManager::createDetachedVcardModel () {
void CoreManager::forceRefreshRegisters () {
qInfo() << QStringLiteral("Refresh registers.");
m_instance->m_core->refreshRegisters();
mInstance->mCore->refreshRegisters();
}
// -----------------------------------------------------------------------------
void CoreManager::setDatabasesPaths () {
m_core->setFriendsDatabasePath(Paths::getFriendsListFilepath());
m_core->setCallLogsDatabasePath(Paths::getCallHistoryFilepath());
m_core->setChatDatabasePath(Paths::getMessageHistoryFilepath());
mCore->setFriendsDatabasePath(Paths::getFriendsListFilepath());
mCore->setCallLogsDatabasePath(Paths::getCallHistoryFilepath());
mCore->setChatDatabasePath(Paths::getMessageHistoryFilepath());
}
void CoreManager::setOtherPaths () {
m_core->setZrtpSecretsFile(Paths::getZrtpSecretsFilepath());
mCore->setZrtpSecretsFile(Paths::getZrtpSecretsFilepath());
// This one is actually a database but it MUST be set after the zrtp secrets
// as it allows automatic migration from old version(secrets, xml) to new version (data, sqlite).
m_core->setZrtpCacheDatabasePath(Paths::getZrtpDataFilepath());
mCore->setZrtpCacheDatabasePath(Paths::getZrtpDataFilepath());
m_core->setUserCertificatesPath(Paths::getUserCertificatesDirpath());
mCore->setUserCertificatesPath(Paths::getUserCertificatesDirpath());
m_core->setRootCa(Paths::getRootCaFilepath());
mCore->setRootCa(Paths::getRootCaFilepath());
}
void CoreManager::setResourcesPaths () {
......@@ -111,7 +111,7 @@ void CoreManager::setResourcesPaths () {
// -----------------------------------------------------------------------------
void CoreManager::createLinphoneCore (const QString &config_path) {
void CoreManager::createLinphoneCore (const QString &configPath) {
qInfo() << QStringLiteral("Launch async linphone core creation.");
// TODO: activate migration when ready to switch to this new version
......@@ -119,10 +119,10 @@ void CoreManager::createLinphoneCore (const QString &config_path) {
setResourcesPaths();
m_core = linphone::Factory::get()->createCore(m_handlers, Paths::getConfigFilepath(config_path), Paths::getFactoryConfigFilepath());
mCore = linphone::Factory::get()->createCore(mHandlers, Paths::getConfigFilepath(configPath), Paths::getFactoryConfigFilepath());
m_core->setVideoDisplayFilter("MSOGL");
m_core->usePreviewWindow(true);
mCore->setVideoDisplayFilter("MSOGL");
mCore->usePreviewWindow(true);
setDatabasesPaths();
setOtherPaths();
......@@ -131,7 +131,7 @@ void CoreManager::createLinphoneCore (const QString &config_path) {
// -----------------------------------------------------------------------------
void CoreManager::iterate () {
m_instance->lockVideoRender();
m_instance->m_core->iterate();
m_instance->unlockVideoRender();
mInstance->lockVideoRender();
mInstance->mCore->iterate();
mInstance->unlockVideoRender();
}
......@@ -48,11 +48,11 @@ public:
void enableHandlers ();
std::shared_ptr<linphone::Core> getCore () {
return m_core;
return mCore;
}
std::shared_ptr<CoreHandlers> getHandlers () {
return m_handlers;
return mHandlers;
}
// ---------------------------------------------------------------------------
......@@ -60,11 +60,11 @@ public:
// ---------------------------------------------------------------------------
void lockVideoRender () {
m_mutex_video_render.lock();
mMutexVideoRender.lock();
}
void unlockVideoRender () {
m_mutex_video_render.unlock();
mMutexVideoRender.unlock();
}
// ---------------------------------------------------------------------------
......@@ -72,33 +72,33 @@ public:
// ---------------------------------------------------------------------------
CallsListModel *getCallsListModel () const {
return m_calls_list_model;
return mCallsListModel;
}
ContactsListModel *getContactsListModel () const {
return m_contacts_list_model;
return mContactsListModel;
}
SipAddressesModel *getSipAddressesModel () const {
return m_sip_addresses_model;
return mSipAddressesModel;
}
SettingsModel *getSettingsModel () const {
return m_settings_model;
return mSettingsModel;
}
AccountSettingsModel *getAccountSettingsModel () const {
return m_account_settings_model;
return mAccountSettingsModel;
}
// ---------------------------------------------------------------------------
// Initialization.
// ---------------------------------------------------------------------------
static void init (QObject *parent, const QString &config_path);
static void init (QObject *parent, const QString &configPath);
static CoreManager *getInstance () {
return m_instance;
return mInstance;
}
// ---------------------------------------------------------------------------
......@@ -113,33 +113,33 @@ signals:
void linphoneCoreCreated ();
private:
CoreManager (QObject *parent, const QString &config_path);
CoreManager (QObject *parent, const QString &configPath);
void setDatabasesPaths ();
void setOtherPaths ();
void setResourcesPaths ();
void createLinphoneCore (const QString &config_path);
void createLinphoneCore (const QString &configPath);
void iterate ();
std::shared_ptr<linphone::Core> m_core;
std::shared_ptr<CoreHandlers> m_handlers;
std::shared_ptr<linphone::Core> mCore;
std::shared_ptr<CoreHandlers> mHandlers;
CallsListModel *m_calls_list_model;
ContactsListModel *m_contacts_list_model;
SipAddressesModel *m_sip_addresses_model;
SettingsModel *m_settings_model;
AccountSettingsModel *m_account_settings_model;
CallsListModel *mCallsListModel;
ContactsListModel *mContactsListModel;
SipAddressesModel *mSipAddressesModel;
SettingsModel *mSettingsModel;
AccountSettingsModel *mAccountSettingsModel;
QTimer *m_cbs_timer;
QTimer *mCbsTimer;
QFuture<void> m_promise_build;
QFutureWatcher<void> m_promise_watcher;
QFuture<void> mPromiseBuild;
QFutureWatcher<void> mPromiseWatcher;
QMutex m_mutex_video_render;
QMutex mMutexVideoRender;
static CoreManager *m_instance;
static CoreManager *mInstance;
};
#endif // CORE_MANAGER_H_
......@@ -59,10 +59,10 @@ using namespace std;
inline int getNotificationSize (const QObject &object, const char *property) {
QVariant variant = object.property(property);
bool so_far_so_good;
bool soFarSoGood;
int size = variant.toInt(&so_far_so_good);
if (!so_far_so_good || size < 0) {
int size = variant.toInt(&soFarSoGood);
if (!soFarSoGood || size < 0) {
qWarning() << "Unable to get notification size.";
return -1;
}
......@@ -89,13 +89,13 @@ Notifier::Notifier (QObject *parent) :
QQmlEngine *engine = App::getInstance()->getEngine();
// Build components.
m_components[Notifier::MessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_MESSAGE));
m_components[Notifier::FileMessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_FILE_MESSAGE));
m_components[Notifier::CallReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_CALL));
mComponents[Notifier::MessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_MESSAGE));
mComponents[Notifier::FileMessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_FILE_MESSAGE));
mComponents[Notifier::CallReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_CALL));
// Check errors.
for (int i = 0; i < Notifier::MaxNbTypes; ++i) {
QQmlComponent *component = m_components[i];
QQmlComponent *component = mComponents[i];
if (component->isError()) {
qWarning() << QStringLiteral("Errors found in `Notification` component %1:").arg(i) << component->errors();
abort();
......@@ -105,37 +105,37 @@ Notifier::Notifier (QObject *parent) :
Notifier::~Notifier () {
for (int i = 0; i < Notifier::MaxNbTypes; ++i)
delete m_components[i];
delete mComponents[i];
}
// -----------------------------------------------------------------------------
QObject *Notifier::createNotification (Notifier::NotificationType type) {
m_mutex.lock();
mMutex.lock();
Q_ASSERT(m_n_instances <= N_MAX_NOTIFICATIONS);
Q_ASSERT(mInstancesNumber <= N_MAX_NOTIFICATIONS);
// Check existing instances.
if (m_n_instances == N_MAX_NOTIFICATIONS) {
if (mInstancesNumber == N_MAX_NOTIFICATIONS) {
qWarning() << "Unable to create another notification";
m_mutex.unlock();
mMutex.unlock();
return nullptr;
}
// Create instance and set attributes.
QObject *object = m_components[type]->create();
QObject *object = mComponents[type]->create();
int offset = getNotificationSize(*object, NOTIFICATION_PROPERTY_HEIGHT);
if (offset == -1 || !::setProperty(*object, NOTIFICATION_PROPERTY_OFFSET, m_offset)) {
if (offset == -1 || !::setProperty(*object, NOTIFICATION_PROPERTY_OFFSET, mOffset)) {
delete object;
m_mutex.unlock();
mMutex.unlock();
return nullptr;
}
m_offset = (offset + m_offset) + NOTIFICATION_SPACING;
m_n_instances++;
mOffset = (offset + mOffset) + NOTIFICATION_SPACING;
mInstancesNumber++;
m_mutex.unlock();
mMutex.unlock();
return object;
}
......@@ -166,13 +166,13 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// -----------------------------------------------------------------------------
void Notifier::deleteNotification (QVariant notification) {
m_mutex.lock();
mMutex.lock();
QObject *instance = notification.value<QObject *>();
// Notification marked destroyed.
if (instance->property("__valid").isValid()) {
m_mutex.unlock();
mMutex.unlock();
return;
}
......@@ -181,13 +181,13 @@ void Notifier::deleteNotification (QVariant notification) {
instance->setProperty("__valid", true);
instance->property(NOTIFICATION_PROPERTY_TIMER).value<QTimer *>()->stop();
m_n_instances--;
if (m_n_instances == 0)
m_offset = 0;
mInstancesNumber--;
if (mInstancesNumber == 0)
mOffset = 0;
Q_ASSERT(m_n_instances >= 0);
Q_ASSERT(mInstancesNumber >= 0);
m_mutex.unlock();
mMutex.unlock();
instance->deleteLater();
}
......
......@@ -56,11 +56,11 @@ private:
QObject *createNotification (NotificationType type);
void showNotification (QObject *notification, int timeout);
QQmlComponent *m_components[MaxNbTypes];
QQmlComponent *mComponents[MaxNbTypes];
int m_offset = 0;
int m_n_instances = 0;
QMutex m_mutex;
int mOffset = 0;
int mInstancesNumber = 0;
QMutex mMutex;
};
#endif // NOTIFIER_H_
......@@ -55,21 +55,21 @@ public:
AccountSettingsModel (QObject *parent = Q_NULLPTR);
~AccountSettingsModel () = default;
bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig);
Q_INVOKABLE QVariantMap getProxyConfigDescription (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
Q_INVOKABLE QVariantMap getProxyConfigDescription (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig);
Q_INVOKABLE void setDefaultProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
Q_INVOKABLE void setDefaultProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig);
Q_INVOKABLE bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config, const QVariantMap &data);
Q_INVOKABLE void removeProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
Q_INVOKABLE bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig, const QVariantMap &data);
Q_INVOKABLE void removeProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig);
Q_INVOKABLE std::shared_ptr<linphone::ProxyConfig> createProxyConfig ();
Q_INVOKABLE void addAuthInfo (
const std::shared_ptr<linphone::AuthInfo> &auth_info,
const std::shared_ptr<linphone::AuthInfo> &authInfo,
const QString &password,
const QString &user_id
const QString &userId
);
Q_INVOKABLE void eraseAllPasswords ();
......@@ -105,7 +105,7 @@ private:
// ---------------------------------------------------------------------------
void handleRegistrationStateChanged (
const std::shared_ptr<linphone::ProxyConfig> &proxy_config,
const std::shared_ptr<linphone::ProxyConfig> &proxyConfig,
linphone::RegistrationState state
);
};
......
......@@ -35,7 +35,7 @@ using namespace std;
const string SettingsModel::UI_SECTION("ui");
SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
m_config = CoreManager::getInstance()->getCore()->getConfig();
mConfig = CoreManager::getInstance()->getCore()->getConfig();
}
// =============================================================================
......@@ -103,13 +103,13 @@ QString SettingsModel::getRingPath () const {
}
void SettingsModel::setRingPath (const QString &path) {
QString cleaned_path = QDir::cleanPath(path);
QString cleanedPath = QDir::cleanPath(path);
CoreManager::getInstance()->getCore()->setRing(
::Utils::qStringToLinphoneString(cleaned_path)
::Utils::qStringToLinphoneString(cleanedPath)
);
emit ringPathChanged(cleaned_path);
emit ringPathChanged(cleanedPath);
}
// -----------------------------------------------------------------------------
......@@ -182,22 +182,22 @@ void SettingsModel::setVideoFramerate (int framerate) {
// =============================================================================
int SettingsModel::getAutoAnswerDelay () const {
return m_config->getInt(UI_SECTION, "auto_answer_delay", 0);
return mConfig->getInt(UI_SECTION, "auto_answer_delay", 0);
}
void SettingsModel::setAutoAnswerDelay (int delay) {
m_config->setInt(UI_SECTION, "auto_answer_delay", delay);
mConfig->setInt(UI_SECTION, "auto_answer_delay", delay);
emit autoAnswerDelayChanged(delay);
}
// -----------------------------------------------------------------------------
bool SettingsModel::getAutoAnswerStatus () const {
return !!m_config->getInt(UI_SECTION, "auto_answer", 0);
return !!mConfig->getInt(UI_SECTION, "auto_answer", 0);
}
void SettingsModel::setAutoAnswerStatus (bool status) {
m_config->setInt(UI_SECTION, "auto_answer", status);
mConfig->setInt(UI_SECTION, "auto_answer", status);
emit autoAnswerStatusChanged(status);
}
......@@ -429,10 +429,10 @@ bool SettingsModel::getIceEnabled () const {
}
void SettingsModel::setIceEnabled (bool status) {
shared_ptr<linphone::NatPolicy> nat_policy = CoreManager::getInstance()->getCore()->getNatPolicy();
shared_ptr<linphone::NatPolicy> natPolicy = CoreManager::getInstance()->getCore()->getNatPolicy();
nat_policy->enableIce(status);
nat_policy->enableStun(status);
natPolicy->enableIce(status);
natPolicy->enableStun(status);
emit iceEnabledChanged(status);
}
......@@ -456,9 +456,9 @@ QString SettingsModel::getStunServer () const {
);
}
void SettingsModel::setStunServer (const QString &stun_server) {
void SettingsModel::setStunServer (const QString &stunServer) {
CoreManager::getInstance()->getCore()->getNatPolicy()->setStunServer(
::Utils::qStringToLinphoneString(stun_server)
::Utils::qStringToLinphoneString(stunServer)
);
}
......@@ -482,28 +482,28 @@ void SettingsModel::setTurnUser (const QString &user) {
QString SettingsModel::getTurnPassword () const {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::NatPolicy> nat_policy = core->getNatPolicy();
shared_ptr<const linphone::AuthInfo> auth_info = core->findAuthInfo(nat_policy->getStunServerUsername(), "", "");
shared_ptr<linphone::NatPolicy> natPolicy = core->getNatPolicy();
shared_ptr<const linphone::AuthInfo> authInfo = core->findAuthInfo(natPolicy->getStunServerUsername(), "", "");
return auth_info ? ::Utils::linphoneStringToQString(auth_info->getPasswd()) : "";
return authInfo ? ::Utils::linphoneStringToQString(authInfo->getPasswd()) : "";
}
void SettingsModel::setTurnPassword (const QString &password) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::NatPolicy> nat_policy = core->getNatPolicy();
shared_ptr<linphone::NatPolicy> natPolicy = core->getNatPolicy();
const string &username = nat_policy->getStunServerUsername();
shared_ptr<const linphone::AuthInfo> auth_info = core->findAuthInfo(username, "", "");
const string &username = natPolicy->getStunServerUsername();
shared_ptr<const linphone::AuthInfo> authInfo = core->findAuthInfo(username, "", "");
if (auth_info) {
shared_ptr<linphone::AuthInfo> auth_info_clone = auth_info->clone();
auth_info_clone->setPasswd(::Utils::qStringToLinphoneString(password));
if (authInfo) {
shared_ptr<linphone::AuthInfo> clonedAuthInfo = authInfo->clone();
clonedAuthInfo->setPasswd(::Utils::qStringToLinphoneString(password));
core->removeAuthInfo(auth_info);
core->addAuthInfo(auth_info_clone);
core->removeAuthInfo(authInfo);
core->addAuthInfo(clonedAuthInfo);
} else {
auth_info = linphone::Factory::get()->createAuthInfo(username, username, ::Utils::qStringToLinphoneString(password), "", "", "");
core->addAuthInfo(auth_info);
authInfo = linphone::Factory::get()->createAuthInfo(username, username, ::Utils::qStringToLinphoneString(password), "", "", "");
core->addAuthInfo(authInfo);
}
emit turnPasswordChanged(password);
......@@ -545,16 +545,16 @@ void SettingsModel::setDscpVideo (int dscp) {
QString SettingsModel::getSavedScreenshotsFolder () const {
return QDir::cleanPath(
::Utils::linphoneStringToQString(
m_config->getString(UI_SECTION, "saved_screenshots_folder", Paths::getCapturesDirpath())
mConfig->getString(UI_SECTION, "saved_screenshots_folder", Paths::getCapturesDirpath())
)
) + QDir::separator();
}
void SettingsModel::setSavedScreenshotsFolder (const QString &folder) {
QString cleaned_folder = QDir::cleanPath(folder) + QDir::separator();
QString cleanedFolder = QDir::cleanPath(folder) + QDir::separator();
m_config->setString(UI_SECTION, "saved_screenshots_folder", ::Utils::qStringToLinphoneString(cleaned_folder));
emit savedScreenshotsFolderChanged(cleaned_folder);
mConfig->setString(UI_SECTION, "saved_screenshots_folder", ::Utils::qStringToLinphoneString(cleanedFolder));
emit savedScreenshotsFolderChanged(cleanedFolder);
}
// -----------------------------------------------------------------------------
......@@ -562,7 +562,7 @@ void SettingsModel::setSavedScreenshotsFolder (const QString &folder) {
QString SettingsModel::getSavedVideosFolder () const {
return QDir::cleanPath(
::Utils::linphoneStringToQString(
m_config->getString(UI_SECTION, "saved_videos_folder", Paths::getCapturesDirpath())
mConfig->getString(UI_SECTION, "saved_videos_folder", Paths::getCapturesDirpath())
)
) + QDir::separator();
}
......@@ -570,6 +570,6 @@ QString SettingsModel::getSavedVideosFolder () const {
void SettingsModel::setSavedVideosFolder (const QString &folder) {
QString _folder = QDir::cleanPath(folder) + QDir::separator();
m_config->setString(UI_SECTION, "saved_videos_folder", ::Utils::qStringToLinphoneString(_folder));
mConfig->setString(UI_SECTION, "saved_videos_folder", ::Utils::qStringToLinphoneString(_folder));
emit savedVideosFolderChanged(_folder);
}
......@@ -220,7 +220,7 @@ public:
void setTurnEnabled (bool status);
QString getStunServer () const;
void setStunServer (const QString &stun_server);
void setStunServer (const QString &stunServer);
QString getTurnUser () const;
void setTurnUser (const QString &user);
......@@ -315,7 +315,7 @@ signals:
void savedVideosFolderChanged (const QString &folder);
private:
std::shared_ptr<linphone::Config> m_config;
std::shared_ptr<linphone::Config> mConfig;
};
#endif // SETTINGS_MODEL_H_
......@@ -24,30 +24,30 @@
// =============================================================================
SipAddressObserver::SipAddressObserver (const QString &sip_address) {
m_sip_address = sip_address;
SipAddressObserver::SipAddressObserver (const QString &sipAddress) {
mSipAddress = sipAddress;
}
void SipAddressObserver::setContact (ContactModel *contact) {
if (contact == m_contact)
if (contact == mContact)
return;
m_contact = contact;
mContact = contact;
emit contactChanged(contact);
}
void SipAddressObserver::setPresenceStatus (const Presence::PresenceStatus &presence_status) {
if (presence_status == m_presence_status)
void SipAddressObserver::setPresenceStatus (const Presence::PresenceStatus &presenceStatus) {
if (presenceStatus == mPresenceStatus)
return;
m_presence_status = presence_status;
emit presenceStatusChanged(presence_status);
mPresenceStatus = presenceStatus;
emit presenceStatusChanged(presenceStatus);
}
void SipAddressObserver::setUnreadMessagesCount (int unread_messages_count) {
if (unread_messages_count == m_unread_messages_count)
void SipAddressObserver::setUnreadMessagesCount (int unreadMessagesCount) {
if (unreadMessagesCount == mUnreadMessagesCount)
return;
m_unread_messages_count = unread_messages_count;
emit unreadMessagesCountChanged(unread_messages_count);
mUnreadMessagesCount = unreadMessagesCount;
emit unreadMessagesCountChanged(unreadMessagesCount);
}
......@@ -39,7 +39,7 @@ class SipAddressObserver : public QObject {
Q_PROPERTY(int unreadMessagesCount READ getUnreadMessagesCount NOTIFY unreadMessagesCountChanged);
public:
SipAddressObserver (const QString &sip_address);
SipAddressObserver (const QString &sipAddress);
~SipAddressObserver () = default;
signals:
......@@ -49,13 +49,13 @@ signals:
private:
QString getSipAddress () const {
return m_sip_address;
return mSipAddress;
}
// ---------------------------------------------------------------------------
ContactModel *getContact () const {
return m_contact;
return mContact;
}
void setContact (ContactModel *contact);
......@@ -63,24 +63,24 @@ private:
// ---------------------------------------------------------------------------
Presence::PresenceStatus getPresenceStatus () const {
return m_presence_status;
return mPresenceStatus;
}
void setPresenceStatus (const Presence::PresenceStatus &presence_status);
void setPresenceStatus (const Presence::PresenceStatus &presenceStatus);
// ---------------------------------------------------------------------------
int getUnreadMessagesCount () const {
return m_unread_messages_count;
return mUnreadMessagesCount;
}
void setUnreadMessagesCount (int unread_messages_count);
void setUnreadMessagesCount (int unreadMessagesCount);
QString m_sip_address;
QString mSipAddress;
ContactModel *m_contact = nullptr;
Presence::PresenceStatus m_presence_status = Presence::PresenceStatus::Offline;
int m_unread_messages_count = 0;
ContactModel *mContact = nullptr;
Presence::PresenceStatus mPresenceStatus = Presence::PresenceStatus::Offline;
int mUnreadMessagesCount = 0;
};
Q_DECLARE_METATYPE(SipAddressObserver *);
......
......@@ -45,20 +45,20 @@ public:
QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
void connectToChatModel (ChatModel *chat_model);
void connectToChatModel (ChatModel *chatModel);
Q_INVOKABLE ContactModel *mapSipAddressToContact (const QString &sip_address) const;
Q_INVOKABLE SipAddressObserver *getSipAddressObserver (const QString &sip_address);
Q_INVOKABLE ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
Q_INVOKABLE SipAddressObserver *getSipAddressObserver (const QString &sipAddress);
// ---------------------------------------------------------------------------
// Sip addresses helpers.
// ---------------------------------------------------------------------------
Q_INVOKABLE QString interpretUrl (const QString &sip_address) const;
Q_INVOKABLE QString interpretUrl (const QString &sipAddress) const;
Q_INVOKABLE QString getTransportFromSipAddress (const QString &sip_address) const;
Q_INVOKABLE QString addTransportToSipAddress (const QString &sip_address, const QString &transport) const;
Q_INVOKABLE bool sipAddressIsValid (const QString &sip_address) const;
Q_INVOKABLE QString getTransportFromSipAddress (const QString &sipAddress) const;
Q_INVOKABLE QString addTransportToSipAddress (const QString &sipAddress, const QString &transport) const;
Q_INVOKABLE bool sipAddressIsValid (const QString &sipAddress) const;
// ---------------------------------------------------------------------------
......@@ -71,16 +71,16 @@ private:
void handleContactAdded (ContactModel *contact);
void handleContactRemoved (const ContactModel *contact);
void handleSipAddressAdded (ContactModel *contact, const QString &sip_address);
void handleSipAddressRemoved (ContactModel *contact, const QString &sip_address);
void handleSipAddressAdded (ContactModel *contact, const QString &sipAddress);
void handleSipAddressRemoved (ContactModel *contact, const QString &sipAddress);
void handleMessageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
void handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void handlePresenceReceived (const QString &sip_address, const std::shared_ptr<const linphone::PresenceModel> &presence_model);
void handlePresenceReceived (const QString &sipAddress, const std::shared_ptr<const linphone::PresenceModel> &presenceModel);
void handleAllEntriesRemoved (const QString &sip_address);
void handleAllEntriesRemoved (const QString &sipAddress);
void handleMessageSent (const std::shared_ptr<linphone::ChatMessage> &message);
void handleMessagesCountReset (const QString &sip_address);
void handleMessagesCountReset (const QString &sipAddress);
// ---------------------------------------------------------------------------
......@@ -91,24 +91,24 @@ private:
void addOrUpdateSipAddress (QVariantMap &map, const std::shared_ptr<linphone::ChatMessage> &message);
template<class T>
void addOrUpdateSipAddress (const QString &sip_address, T data);
void addOrUpdateSipAddress (const QString &sipAddress, T data);
// ---------------------------------------------------------------------------
void removeContactOfSipAddress (const QString &sip_address);
void removeContactOfSipAddress (const QString &sipAddress);
void initSipAddresses ();
void updateObservers (const QString &sip_address, ContactModel *contact);
void updateObservers (const QString &sip_address, const Presence::PresenceStatus &presence_status);
void updateObservers (const QString &sip_address, int messages_count);
void updateObservers (const QString &sipAddress, ContactModel *contact);
void updateObservers (const QString &sipAddress, const Presence::PresenceStatus &presenceStatus);
void updateObservers (const QString &sipAddress, int messagesCount);
QHash<QString, QVariantMap> m_sip_addresses;
QList<const QVariantMap *> m_refs;
QHash<QString, QVariantMap> mSipAddresses;
QList<const QVariantMap *> mRefs;
QMultiHash<QString, SipAddressObserver *> m_observers;
QMultiHash<QString, SipAddressObserver *> mObservers;
std::shared_ptr<CoreHandlers> m_core_handlers;
std::shared_ptr<CoreHandlers> mCoreHandlers;
};
#endif // SIP_ADDRESSES_MODEL_H_
......@@ -32,7 +32,7 @@
// =============================================================================
const QRegExp SmartSearchBarModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
const QRegExp SmartSearchBarModel::mSearchSeparators("^[^_.-;@ ][_.-;@ ]");
// -----------------------------------------------------------------------------
......@@ -50,54 +50,54 @@ QHash<int, QByteArray> SmartSearchBarModel::roleNames () const {
// -----------------------------------------------------------------------------
void SmartSearchBarModel::setFilter (const QString &pattern) {
m_filter = pattern;
mFilter = pattern;
invalidate();
}
// -----------------------------------------------------------------------------
bool SmartSearchBarModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
bool SmartSearchBarModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
return computeEntryWeight(index.data().toMap()) > 0;
}
bool SmartSearchBarModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
const QVariantMap &map_a = sourceModel()->data(left).toMap();
const QVariantMap &map_b = sourceModel()->data(right).toMap();
const QVariantMap &mapA = sourceModel()->data(left).toMap();
const QVariantMap &mapB = sourceModel()->data(right).toMap();
const QString &sip_address_a = map_a["sipAddress"].toString();
const QString &sip_address_b = map_b["sipAddress"].toString();
const QString &sipAddressA = mapA["sipAddress"].toString();
const QString &sipAddressB = mapB["sipAddress"].toString();
// TODO: Use a cache, do not compute the same value as `filterAcceptsRow`.
int weight_a = computeEntryWeight(map_a);
int weight_b = computeEntryWeight(map_b);
int weightA = computeEntryWeight(mapA);
int weightB = computeEntryWeight(mapB);
// 1. Not the same weight.
if (weight_a != weight_b)
return weight_a > weight_b;
if (weightA != weightB)
return weightA > weightB;
const ContactModel *contact_a = map_a.value("contact").value<ContactModel *>();
const ContactModel *contact_b = map_b.value("contact").value<ContactModel *>();
const ContactModel *contactA = mapA.value("contact").value<ContactModel *>();
const ContactModel *contactB = mapB.value("contact").value<ContactModel *>();
// 2. No contacts.
if (!contact_a && !contact_b)
return sip_address_a <= sip_address_b;
if (!contactA && !contactB)
return sipAddressA <= sipAddressB;
// 3. No contact for a or b.
if (!contact_a || !contact_b)
return !!contact_a;
if (!contactA || !contactB)
return !!contactA;
// 4. Same contact (address).
if (contact_a == contact_b)
return sip_address_a <= sip_address_b;
if (contactA == contactB)
return sipAddressA <= sipAddressB;
// 5. Not the same contact name.
int diff = contact_a->m_linphone_friend->getName().compare(contact_b->m_linphone_friend->getName());
int diff = contactA->mLinphoneFriend->getName().compare(contactB->mLinphoneFriend->getName());
if (diff)
return diff <= 0;
// 6. Same contact name, so compare sip addresses.
return sip_address_a <= sip_address_b;
return sipAddressA <= sipAddressB;
}
int SmartSearchBarModel::computeEntryWeight (const QVariantMap &entry) const {
......@@ -114,10 +114,10 @@ int SmartSearchBarModel::computeStringWeight (const QString &string) const {
int index = -1;
int offset = -1;
while ((index = string.indexOf(m_filter, index + 1, Qt::CaseInsensitive)) != -1) {
int tmp_offset = index - string.lastIndexOf(m_search_separators, index) - 1;
if ((tmp_offset != -1 && tmp_offset < offset) || offset == -1)
if ((offset = tmp_offset) == 0) break;
while ((index = string.indexOf(mFilter, index + 1, Qt::CaseInsensitive)) != -1) {
int tmpOffset = index - string.lastIndexOf(mSearchSeparators, index) - 1;
if ((tmpOffset != -1 && tmpOffset < offset) || offset == -1)
if ((offset = tmpOffset) == 0) break;
}
switch (offset) {
......
......@@ -39,15 +39,15 @@ public:
Q_INVOKABLE void setFilter (const QString &pattern);
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
private:
int computeEntryWeight (const QVariantMap &entry) const;
int computeStringWeight (const QString &string) const;
QString m_filter;
static const QRegExp m_search_separators;
QString mFilter;
static const QRegExp mSearchSeparators;
};
#endif // SMART_SEARCH_BAR_MODEL_H_
......@@ -41,8 +41,8 @@ QHash<int, QByteArray> TimelineModel::roleNames () const {
// -----------------------------------------------------------------------------
bool TimelineModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
bool TimelineModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
return index.data().toMap().contains("timestamp");
}
......
......@@ -37,7 +37,7 @@ public:
QHash<int, QByteArray> roleNames () const override;
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
};
......
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