Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
877da996
Commit
877da996
authored
Oct 04, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): new Presence type
parent
9b98924c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
107 additions
and
82 deletions
+107
-82
linphone.pro
tests/linphone.pro
+1
-0
ContactModel.cpp
tests/src/components/contacts/ContactModel.cpp
+0
-11
ContactModel.hpp
tests/src/components/contacts/ContactModel.hpp
+10
-27
ContactsListModel.cpp
tests/src/components/contacts/ContactsListModel.cpp
+15
-14
ContactsListModel.hpp
tests/src/components/contacts/ContactsListModel.hpp
+0
-4
ContactsListProxyModel.cpp
tests/src/components/contacts/ContactsListProxyModel.cpp
+27
-19
ContactsListProxyModel.hpp
tests/src/components/contacts/ContactsListProxyModel.hpp
+1
-1
PresenceModel.hpp
tests/src/components/presence/PresenceModel.hpp
+47
-0
main.cpp
tests/src/main.cpp
+2
-2
PresenceLevel.qml
tests/ui/modules/Linphone/Contact/PresenceLevel.qml
+4
-4
No files found.
tests/linphone.pro
View file @
877da996
...
...
@@ -23,6 +23,7 @@ HEADERS = \
src
/
components
/
contacts
/
ContactsListModel
.
hpp
\
src
/
components
/
contacts
/
ContactsListProxyModel
.
hpp
\
src
/
components
/
notification
/
Notification
.
hpp
\
src
/
components
/
presence
/
PresenceModel
.
hpp
\
src
/
components
/
settings
/
AccountSettingsListModel
.
hpp
\
src
/
components
/
settings
/
AccountSettingsModel
.
hpp
\
src
/
components
/
settings
/
SettingsModel
.
hpp
\
...
...
tests/src/components/contacts/ContactModel.cpp
View file @
877da996
#include "ContactModel.hpp"
// ===================================================================
ContactModel
::
PresenceLevel
ContactModel
::
getPresenceLevel
()
const
{
if
(
m_presence
==
Online
)
return
Green
;
if
(
m_presence
==
DoNotDisturb
)
return
Red
;
if
(
m_presence
==
Offline
)
return
White
;
return
Orange
;
}
tests/src/components/contacts/ContactModel.hpp
View file @
877da996
...
...
@@ -3,6 +3,8 @@
#include <QObject>
#include "../presence/PresenceModel.hpp"
// ===================================================================
class
ContactModel
:
public
QObject
{
...
...
@@ -25,13 +27,13 @@ class ContactModel : public QObject {
);
Q_PROPERTY
(
Presence
presence
Presence
Model
::
Presence
presence
READ
getPresence
CONSTANT
);
Q_PROPERTY
(
PresenceLevel
presenceLevel
Presence
Model
::
Presence
Level
presenceLevel
READ
getPresenceLevel
CONSTANT
);
...
...
@@ -44,32 +46,11 @@ class ContactModel : public QObject {
);
public:
enum
Presence
{
Online
,
BeRightBack
,
Away
,
OnThePhone
,
OutToLunch
,
DoNotDisturb
,
Moved
,
UsingAnotherMessagingService
,
Offline
};
Q_ENUM
(
Presence
);
enum
PresenceLevel
{
Green
,
Orange
,
Red
,
White
};
Q_ENUM
(
PresenceLevel
);
ContactModel
(
QObject
*
parent
=
Q_NULLPTR
)
:
QObject
(
parent
)
{
}
ContactModel
(
const
QString
&
username
,
const
QString
&
avatar
,
const
Presence
&
presence
,
const
Presence
Model
::
Presence
&
presence
,
const
QStringList
&
sip_addresses
)
:
ContactModel
()
{
m_username
=
username
;
...
...
@@ -98,11 +79,13 @@ private:
m_avatar
=
avatar
;
}
Presence
getPresence
()
const
{
Presence
Model
::
Presence
getPresence
()
const
{
return
m_presence
;
}
PresenceLevel
getPresenceLevel
()
const
;
PresenceModel
::
PresenceLevel
getPresenceLevel
()
const
{
return
PresenceModel
::
getPresenceLevel
(
m_presence
);
}
QStringList
getSipAddresses
()
const
{
return
m_sip_addresses
;
...
...
@@ -114,7 +97,7 @@ private:
QString
m_username
;
QString
m_avatar
;
Presence
m_presence
=
Online
;
Presence
Model
::
Presence
m_presence
=
PresenceModel
::
Online
;
QStringList
m_sip_addresses
;
};
...
...
tests/src/components/contacts/ContactsListModel.cpp
View file @
877da996
...
...
@@ -3,18 +3,19 @@
// ===================================================================
ContactsListModel
::
ContactsListModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{
m_list
<<
new
ContactModel
(
"Toto Roi"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Mary Boreno"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Cecelia Cyler"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Daniel Elliott"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Effie Forton"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Agnes Hurner"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Luke Lemin"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Claire Manning"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Isabella Ahornton"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Mary Boreno"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Aman Than"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
" abdoul"
,
""
,
ContactModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
// TMP.
m_list
<<
new
ContactModel
(
"Toto Roi"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Mary Boreno"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Cecelia Cyler"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Daniel Elliott"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Effie Forton"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Agnes Hurner"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Luke Lemin"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Claire Manning"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Isabella Ahornton"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Mary Boreno"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
"Aman Than"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
m_list
<<
new
ContactModel
(
" abdoul"
,
""
,
PresenceModel
::
Online
,
QStringList
(
"toto.linphone.sip.linphone.org"
));
}
...
...
@@ -24,7 +25,7 @@ int ContactsListModel::rowCount (const QModelIndex &) const {
QHash
<
int
,
QByteArray
>
ContactsListModel
::
roleNames
()
const
{
QHash
<
int
,
QByteArray
>
roles
;
roles
[
Contact
Role
]
=
"$contact"
;
roles
[
Qt
::
Display
Role
]
=
"$contact"
;
return
roles
;
}
...
...
@@ -34,7 +35,7 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
if
(
row
<
0
||
row
>=
m_list
.
count
())
return
QVariant
();
if
(
role
==
Contact
Role
)
if
(
role
==
Qt
::
Display
Role
)
return
QVariant
::
fromValue
(
m_list
[
row
]);
return
QVariant
();
...
...
tests/src/components/contacts/ContactsListModel.hpp
View file @
877da996
...
...
@@ -13,10 +13,6 @@ class ContactsListModel : public QAbstractListModel {
Q_OBJECT
;
public:
enum
Roles
{
ContactRole
=
Qt
::
UserRole
+
1
};
ContactsListModel
(
QObject
*
parent
=
Q_NULLPTR
);
int
rowCount
(
const
QModelIndex
&
)
const
;
...
...
tests/src/components/contacts/ContactsListProxyModel.cpp
View file @
877da996
...
...
@@ -6,6 +6,11 @@
#define MAIN_SIP_ADDRESS_WEIGHT 30.0
#define OTHER_SIP_ADDRESSES_WEIGHT 20.0
#define FACTOR_POS_1 0.90
#define FACTOR_POS_2 0.80
#define FACTOR_POS_3 0.70
#define FACTOR_POS_OTHER 0.60
// ===================================================================
ContactsListModel
*
ContactsListProxyModel
::
m_list
=
nullptr
;
...
...
@@ -18,8 +23,8 @@ ContactsListModel *ContactsListProxyModel::m_list = nullptr;
// - [^_.-;@ ] is used to search patterns which starts with
// a separator like ` word`.
//
// - [_.-;@ ] is the main pattern.
const
QRegExp
ContactsListProxyModel
::
search_separators
(
"^[^_.-;@ ][_.-;@ ]"
);
// - [_.-;@ ] is the main pattern
(a separator)
.
const
QRegExp
ContactsListProxyModel
::
m_
search_separators
(
"^[^_.-;@ ][_.-;@ ]"
);
// -------------------------------------------------------------------
...
...
@@ -43,19 +48,21 @@ void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
bool
ContactsListProxyModel
::
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
{
QModelIndex
index
=
sourceModel
()
->
index
(
source_row
,
0
,
source_parent
);
const
ContactModel
*
contact
=
qvariant_cast
<
ContactModel
*>
(
index
.
data
(
ContactsListModel
::
ContactRole
)
index
.
data
()
);
int
weight
=
m_weights
[
contact
]
=
static_cast
<
int
>
(
computeContactWeight
(
*
contact
));
int
weight
=
m_weights
[
contact
]
=
static_cast
<
int
>
(
computeContactWeight
(
*
contact
)
);
return
weight
>
0
;
}
bool
ContactsListProxyModel
::
lessThan
(
const
QModelIndex
&
left
,
const
QModelIndex
&
right
)
const
{
const
ContactModel
*
contact_a
=
qvariant_cast
<
ContactModel
*>
(
sourceModel
()
->
data
(
left
,
ContactsListModel
::
ContactRole
)
sourceModel
()
->
data
(
left
)
);
const
ContactModel
*
contact_b
=
qvariant_cast
<
ContactModel
*>
(
sourceModel
()
->
data
(
right
,
ContactsListModel
::
ContactRole
)
sourceModel
()
->
data
(
right
)
);
float
weight_a
=
m_weights
[
contact_a
];
...
...
@@ -63,46 +70,49 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde
// Sort by weight and name.
return
(
weight_a
>
weight_b
||
(
weight_a
==
weight_b
&&
contact_a
->
m_username
<=
contact_b
->
m_username
)
weight_a
>
weight_b
||
(
weight_a
==
weight_b
&&
contact_a
->
m_username
<=
contact_b
->
m_username
)
);
}
// -------------------------------------------------------------------
float
ContactsListProxyModel
::
computeStringWeight
(
const
QString
&
string
,
float
percentage
)
const
{
const
static
int
max
=
std
::
numeric_limits
<
int
>::
max
();
int
index
=
-
1
;
int
offset
=
-
1
;
// Search pattern.
while
((
index
=
filterRegExp
().
indexIn
(
string
,
index
+
1
))
!=
-
1
)
{
// Search n chars between one separator and index.
int
tmp_offset
=
index
-
string
.
lastIndexOf
(
search_separators
,
index
)
-
1
;
int
tmp_offset
=
index
-
string
.
lastIndexOf
(
m_
search_separators
,
index
)
-
1
;
qDebug
()
<<
string
<<
string
.
lastIndexOf
(
search_separators
,
index
)
<<
tmp_offset
;
if
((
tmp_offset
!=
-
1
&&
tmp_offset
<
offset
)
||
offset
==
-
1
)
offset
=
tmp_offset
;
if
((
offset
=
tmp_offset
)
==
0
)
// Little optimization.
break
;
}
// No weight.
if
(
offset
==
-
1
)
return
0
;
// Weight & offset.
switch
(
offset
)
{
case
0
:
return
percentage
;
case
1
:
return
percentage
*
0.90
;
case
2
:
return
percentage
*
0.80
;
case
3
:
return
percentage
*
0.70
;
case
1
:
return
percentage
*
FACTOR_POS_1
;
case
2
:
return
percentage
*
FACTOR_POS_2
;
case
3
:
return
percentage
*
FACTOR_POS_3
;
default:
break
;
}
return
percentage
*
0.60
;
return
percentage
*
FACTOR_POS_OTHER
;
}
float
ContactsListProxyModel
::
computeContactWeight
(
const
ContactModel
&
contact
)
const
{
float
weight
=
computeStringWeight
(
contact
.
m_username
,
USERNAME_WEIGHT
);
// It exists at least one sip address.
const
QStringList
&
addresses
=
contact
.
m_sip_addresses
;
weight
+=
computeStringWeight
(
addresses
[
0
],
MAIN_SIP_ADDRESS_WEIGHT
);
...
...
@@ -112,7 +122,5 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
for
(
auto
it
=
++
addresses
.
constBegin
();
it
!=
addresses
.
constEnd
();
++
it
)
weight
+=
computeStringWeight
(
*
it
,
OTHER_SIP_ADDRESSES_WEIGHT
/
size
);
qDebug
()
<<
contact
.
m_username
<<
weight
;
return
weight
;
}
tests/src/components/contacts/ContactsListProxyModel.hpp
View file @
877da996
...
...
@@ -22,7 +22,7 @@ private:
float
computeStringWeight
(
const
QString
&
string
,
float
percentage
)
const
;
float
computeContactWeight
(
const
ContactModel
&
contact
)
const
;
static
const
QRegExp
search_separators
;
static
const
QRegExp
m_
search_separators
;
// The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`.
...
...
tests/src/components/presence/PresenceModel.hpp
0 → 100644
View file @
877da996
#ifndef PRESENCE_MODEL_H_
#define PRESENCE_MODEL_H_
#include <QObject>
// ===================================================================
class
PresenceModel
:
public
QObject
{
Q_OBJECT
;
public:
enum
Presence
{
Online
,
BeRightBack
,
Away
,
OnThePhone
,
OutToLunch
,
DoNotDisturb
,
Moved
,
UsingAnotherMessagingService
,
Offline
};
Q_ENUM
(
Presence
);
enum
PresenceLevel
{
Green
,
Orange
,
Red
,
White
};
Q_ENUM
(
PresenceLevel
);
PresenceModel
(
QObject
*
parent
=
Q_NULLPTR
)
{
}
static
PresenceLevel
getPresenceLevel
(
const
Presence
&
presence
)
{
if
(
presence
==
Online
)
return
Green
;
if
(
presence
==
DoNotDisturb
)
return
Red
;
if
(
presence
==
Offline
)
return
White
;
return
Orange
;
}
};
#endif // PRESENCE_MODEL_H_
tests/src/main.cpp
View file @
877da996
...
...
@@ -50,8 +50,8 @@ void setTrayIcon (QQmlApplicationEngine &engine) {
}
void
registerTypes
()
{
qmlRegisterUncreatableType
<
Contact
Model
>
(
"Linphone"
,
1
,
0
,
"
ContactModel"
,
"ContactModel
is uncreatable"
qmlRegisterUncreatableType
<
Presence
Model
>
(
"Linphone"
,
1
,
0
,
"
Presence"
,
"Presence
is uncreatable"
);
ContactsListProxyModel
::
initContactsListModel
(
new
ContactsListModel
());
...
...
tests/ui/modules/Linphone/Contact/PresenceLevel.qml
View file @
877da996
...
...
@@ -8,16 +8,16 @@ Icon {
property
int
level
:
-
1
function
_getColorString
()
{
if
(
level
===
ContactModel
.
Green
)
{
if
(
level
===
Presence
.
Green
)
{
return
'
green
'
}
if
(
level
===
ContactModel
.
Orange
)
{
if
(
level
===
Presence
.
Orange
)
{
return
'
orange
'
}
if
(
level
===
ContactModel
.
Red
)
{
if
(
level
===
Presence
.
Red
)
{
return
'
red
'
}
if
(
level
===
ContactModel
.
White
)
{
if
(
level
===
Presence
.
White
)
{
return
'
white
'
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment