Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Stolk <github@netripper.nl>2011-03-09 23:44:55 +0300
committerMartijn Stolk <github@netripper.nl>2011-03-09 23:44:55 +0300
commit6d62ae7237eb7c98853d2581cc67f11f2b29bab1 (patch)
treee7c43d68fdce497b842d9f6b802d443a9a6ba474
parent9682d7de1c314bab95355fbf10860f8aec04e0bf (diff)
Overlay: add support for displaying active users
Active users meaning those that are currently talking and users that have recently talked within a configurable amount of time.
-rw-r--r--src/Timer.cpp10
-rw-r--r--src/Timer.h3
-rw-r--r--src/mumble/ClientUser.cpp39
-rw-r--r--src/mumble/ClientUser.h8
-rw-r--r--src/mumble/OverlayUserGroup.cpp35
-rw-r--r--src/mumble/Settings.cpp3
-rw-r--r--src/mumble/Settings.h3
7 files changed, 87 insertions, 14 deletions
diff --git a/src/Timer.cpp b/src/Timer.cpp
index 5c3fc080a..9aa5487e6 100644
--- a/src/Timer.cpp
+++ b/src/Timer.cpp
@@ -31,15 +31,17 @@
#include <QtCore>
#include "Timer.h"
-Timer::Timer() {
- uiStart = now();
+Timer::Timer(bool start) {
+ uiStart = start ? now() : 0;
}
quint64 Timer::elapsed() const {
+ Q_ASSERT(uiStart != 0);
return now() - uiStart;
}
bool Timer::isElapsed(quint64 us) {
+ Q_ASSERT(uiStart != 0);
if (elapsed() > us) {
uiStart += us;
return true;
@@ -54,6 +56,10 @@ quint64 Timer::restart() {
return e;
}
+bool Timer::isStarted() const {
+ return uiStart != 0;
+}
+
#if defined(Q_OS_WIN)
#include <windows.h>
diff --git a/src/Timer.h b/src/Timer.h
index a4f166011..ad61ee48b 100644
--- a/src/Timer.h
+++ b/src/Timer.h
@@ -38,10 +38,11 @@ protected:
quint64 uiStart;
static quint64 now();
public:
- Timer();
+ Timer(bool start = true);
bool isElapsed(quint64 us);
quint64 elapsed() const;
quint64 restart();
+ bool isStarted() const;
};
#endif
diff --git a/src/mumble/ClientUser.cpp b/src/mumble/ClientUser.cpp
index 8ab5237a3..b35a36894 100644
--- a/src/mumble/ClientUser.cpp
+++ b/src/mumble/ClientUser.cpp
@@ -39,13 +39,15 @@ QReadWriteLock ClientUser::c_qrwlUsers;
QList<ClientUser *> ClientUser::c_qlTalking;
QReadWriteLock ClientUser::c_qrwlTalking;
-ClientUser::ClientUser(QObject *p) : QObject(p) {
- tsState = Settings::Passive;
- bLocalMute = false;
- fPowerMin = fPowerMax = 0.0f;
- fAverageAvailable = 0.0f;
- iFrames = 0;
- iSequence = 0;
+ClientUser::ClientUser(QObject *p) : QObject(p),
+ tsState(Settings::Passive),
+ bLocalMute(false),
+ fPowerMin(0.0f),
+ fPowerMax(0.0f),
+ fAverageAvailable(0.0f),
+ iFrames(0),
+ iSequence(0),
+ tLastTalkStateChange(false) {
}
ClientUser *ClientUser::get(unsigned int uiSession) {
@@ -71,6 +73,16 @@ QList<ClientUser *> ClientUser::getTalking() {
return c_qlTalking;
}
+QList<ClientUser *> ClientUser::getActive() {
+ QReadLocker lock(&c_qrwlUsers);
+ QList<ClientUser *> activeUsers;
+ foreach (ClientUser *cu, c_qmUsers) {
+ if (cu->isActive())
+ activeUsers << cu;
+ }
+ return activeUsers;
+}
+
bool ClientUser::isValid(unsigned int uiSession) {
QReadLocker lock(&c_qrwlUsers);
@@ -159,6 +171,7 @@ void ClientUser::setTalking(Settings::TalkState ts) {
nstate = true;
tsState = ts;
+ tLastTalkStateChange.restart();
emit talkingChanged();
if (nstate && cChannel) {
@@ -245,14 +258,22 @@ bool ClientUser::lessThanOverlay(const ClientUser *first, const ClientUser *seco
return Channel::lessThan(first->cChannel, second->cChannel);
}
-
-
void ClientUser::sortUsersOverlay(QList<ClientUser *> &list) {
QReadLocker lock(&c_qrwlUsers);
qSort(list.begin(), list.end(), ClientUser::lessThanOverlay);
}
+bool ClientUser::isActive() {
+ if (tsState != Settings::Passive)
+ return true;
+
+ if (!tLastTalkStateChange.isStarted())
+ return false;
+
+ return tLastTalkStateChange.elapsed() < g.s.os.iActiveTime * 1000000;
+}
+
/* From Channel.h
*/
void Channel::addClientUser(ClientUser *p) {
diff --git a/src/mumble/ClientUser.h b/src/mumble/ClientUser.h
index 939206ce3..9abd4d07d 100644
--- a/src/mumble/ClientUser.h
+++ b/src/mumble/ClientUser.h
@@ -47,6 +47,7 @@ class ClientUser : public QObject, public User {
};
Settings::TalkState tsState;
+ Timer tLastTalkStateChange;
bool bLocalMute;
float fPowerMin, fPowerMax;
@@ -66,12 +67,19 @@ class ClientUser : public QObject, public User {
QString getFlagsString() const;
ClientUser(QObject *p = NULL);
+ /*! Determines whether a user is active or not
+ * A user is active when it is currently speaking or when the user has
+ * spoken within Settings::iActiveTime amount of seconds.
+ */
+ bool isActive();
+
static QHash<unsigned int, ClientUser *> c_qmUsers;
static QReadWriteLock c_qrwlUsers;
static QList<ClientUser *> c_qlTalking;
static QReadWriteLock c_qrwlTalking;
static QList<ClientUser *> getTalking();
+ static QList<ClientUser *> getActive();
static void sortUsersOverlay(QList<ClientUser *> &list);
diff --git a/src/mumble/OverlayUserGroup.cpp b/src/mumble/OverlayUserGroup.cpp
index 8410c5a6a..5e255390c 100644
--- a/src/mumble/OverlayUserGroup.cpp
+++ b/src/mumble/OverlayUserGroup.cpp
@@ -98,6 +98,11 @@ void OverlayUserGroup::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
if (os->osShow == OverlaySettings::Talking)
qaShowTalking->setChecked(true);
+ QAction *qaShowActive = qmShow->addAction(OverlayClient::tr("Talking and recently active"));
+ qaShowActive->setCheckable(true);
+ if (os->osShow == OverlaySettings::Active)
+ qaShowActive->setChecked(true);
+
QAction *qaShowHome = qmShow->addAction(OverlayClient::tr("All in current channel"));
qaShowHome->setCheckable(true);
if (os->osShow == OverlaySettings::HomeChannel)
@@ -112,10 +117,15 @@ void OverlayUserGroup::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QAction *qaShowSelf = qmShow->addAction(OverlayClient::tr("Always show yourself"));
qaShowSelf->setCheckable(true);
- qaShowSelf->setEnabled(os->osShow == OverlaySettings::Talking);
+ qaShowSelf->setEnabled(os->osShow == OverlaySettings::Talking || os->osShow == OverlaySettings::Active);
if (os->bAlwaysSelf)
qaShowSelf->setChecked(true);
+ qmShow->addSeparator();
+
+ QAction *qaConfigureRecentlyActiveTime = qmShow->addAction(OverlayClient::tr("Configure recently active time (%1 seconds)...").arg(os->iActiveTime));
+ qaConfigureRecentlyActiveTime->setEnabled(os->osShow == OverlaySettings::Active);
+
QMenu *qmColumns = qm.addMenu(OverlayClient::tr("Columns"));
QAction *qaColumns[6];
for (unsigned int i=1;i<=5;++i) {
@@ -146,6 +156,9 @@ void OverlayUserGroup::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
} else if (act == qaShowTalking) {
os->osShow = OverlaySettings::Talking;
updateUsers();
+ } else if (act == qaShowActive) {
+ os->osShow = OverlaySettings::Active;
+ updateUsers();
} else if (act == qaShowHome) {
os->osShow = OverlaySettings::HomeChannel;
updateUsers();
@@ -155,6 +168,21 @@ void OverlayUserGroup::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
} else if (act == qaShowSelf) {
os->bAlwaysSelf = ! os->bAlwaysSelf;
updateUsers();
+ } else if (act == qaConfigureRecentlyActiveTime) {
+ // FIXME: This might not be the best place to configure this setting, but currently
+ // there's not really a suitable place to put this. In the future an additional tab
+ // might be added for some advanced overlay options, which could then include this
+ // setting.
+ bool ok;
+ int newValue = QInputDialog::getInt(
+ qm.parentWidget(),
+ OverlayClient::tr("Configure recently active time"),
+ OverlayClient::tr("Amount of seconds users remain active after talking:"),
+ os->iActiveTime, 1, 2147483647, 1, &ok);
+ if (ok) {
+ os->iActiveTime = newValue;
+ }
+ updateUsers();
} else {
for (int i=1;i<=5;++i) {
if (act == qaColumns[i]) {
@@ -276,6 +304,11 @@ void OverlayUserGroup::updateUsers() {
if (! showusers.contains(cu))
showusers << cu;
break;
+ case OverlaySettings::Active:
+ showusers = ClientUser::getActive();
+ if (os->bAlwaysSelf && !showusers.contains(self))
+ showusers << self;
+ break;
default:
showusers = ClientUser::getTalking();
if (os->bAlwaysSelf && (self->tsState == Settings::Passive))
diff --git a/src/mumble/Settings.cpp b/src/mumble/Settings.cpp
index 74360ffea..9c4fdd5b0 100644
--- a/src/mumble/Settings.cpp
+++ b/src/mumble/Settings.cpp
@@ -128,6 +128,7 @@ OverlaySettings::OverlaySettings() {
osShow = LinkedChannels;
bAlwaysSelf = true;
+ iActiveTime = 5;
qcUserName[Settings::Passive] = QColor(170, 170, 170);
qcUserName[Settings::Talking] = QColor(255, 255, 255);
@@ -449,6 +450,7 @@ void OverlaySettings::load(QSettings* settings_ptr) {
LOADENUM(osShow, "show");
SAVELOAD(bAlwaysSelf, "alwaysself");
+ SAVELOAD(iActiveTime, "activetime");
SAVELOAD(fX, "x");
SAVELOAD(fY, "y");
@@ -707,6 +709,7 @@ void OverlaySettings::save(QSettings* settings_ptr) {
SAVELOAD(osShow, "show");
SAVELOAD(bAlwaysSelf, "alwaysself");
+ SAVELOAD(iActiveTime, "activetime");
SAVELOAD(fX, "x");
SAVELOAD(fY, "y");
SAVELOAD(fZoom, "zoom");
diff --git a/src/mumble/Settings.h b/src/mumble/Settings.h
index e0acdfd0d..a52800691 100644
--- a/src/mumble/Settings.h
+++ b/src/mumble/Settings.h
@@ -76,7 +76,7 @@ Q_DECLARE_METATYPE(ShortcutTarget)
struct OverlaySettings {
enum OverlayPresets { AvatarAndName, LargeSquareAvatar };
- enum OverlayShow { Talking, HomeChannel, LinkedChannels };
+ enum OverlayShow { Talking, Active, HomeChannel, LinkedChannels };
bool bEnable;
@@ -84,6 +84,7 @@ struct OverlaySettings {
OverlayShow osShow;
bool bAlwaysSelf;
+ int iActiveTime; // Time in seconds for a user to stay active after talking
float fX;
float fY;