mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Mark which peers are playing, styling is open to suggestions
closes #757
This commit is contained in:
parent
407ffef1b9
commit
b6175ac96f
|
@ -242,11 +242,12 @@ void Audio::playMono16Sound(const QByteArray& data)
|
|||
}
|
||||
|
||||
void Audio::playGroupAudioQueued(Tox*,int group, int peer, const int16_t* data,
|
||||
unsigned samples, uint8_t channels, unsigned sample_rate,void*)
|
||||
unsigned samples, uint8_t channels, unsigned sample_rate, void* core)
|
||||
{
|
||||
QMetaObject::invokeMethod(instance, "playGroupAudio", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(int,group), Q_ARG(int,peer), Q_ARG(const int16_t*,data),
|
||||
Q_ARG(unsigned,samples), Q_ARG(uint8_t,channels), Q_ARG(unsigned,sample_rate));
|
||||
emit static_cast<Core*>(core)->groupPeerAudioPlaying(group, peer);
|
||||
}
|
||||
|
||||
void Audio::playGroupAudio(int group, int peer, const int16_t* data,
|
||||
|
|
|
@ -171,6 +171,7 @@ signals:
|
|||
void groupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);
|
||||
void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
void groupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
||||
void groupPeerAudioPlaying(int groupnumber, int peernumber);
|
||||
|
||||
void usernameSet(const QString& username);
|
||||
void statusMessageSet(const QString& message);
|
||||
|
|
|
@ -72,7 +72,6 @@ void Group::updatePeer(int peerId, QString name)
|
|||
QString toxid = id.publicKey;
|
||||
peers[peerId] = name;
|
||||
toxids[toxid] = name;
|
||||
|
||||
Friend *f = FriendList::findFriend(id);
|
||||
if (f)
|
||||
{
|
||||
|
@ -95,17 +94,16 @@ void Group::setName(const QString& name)
|
|||
|
||||
void Group::regeneratePeerList()
|
||||
{
|
||||
QList<QString> peerLst = Core::getInstance()->getGroupPeerNames(groupId);
|
||||
peers.clear();
|
||||
peers = Core::getInstance()->getGroupPeerNames(groupId);
|
||||
toxids.clear();
|
||||
nPeers = peerLst.size();
|
||||
for (int i = 0; i < peerLst.size(); i++)
|
||||
nPeers = peers.size();
|
||||
for (int i = 0; i < nPeers; i++)
|
||||
{
|
||||
ToxID id = Core::getInstance()->getGroupPeerToxID(groupId, i);
|
||||
if (id.isMine())
|
||||
selfPeerNum = i;
|
||||
QString toxid = id.publicKey;
|
||||
peers[i] = peerLst.at(i);
|
||||
toxids[toxid] = peerLst.at(i);
|
||||
|
||||
toxids[toxid] = peers[i];
|
||||
Friend *f = FriendList::findFriend(id);
|
||||
if (f)
|
||||
{
|
||||
|
@ -145,9 +143,12 @@ GroupWidget *Group::getGroupWidget()
|
|||
|
||||
QStringList Group::getPeerList() const
|
||||
{
|
||||
QStringList peerNames(peers.values());
|
||||
peerNames.sort(Qt::CaseInsensitive);
|
||||
return peerNames;
|
||||
return peers;
|
||||
}
|
||||
|
||||
bool Group::isSelfPeerNumber(int num) const
|
||||
{
|
||||
return num == selfPeerNum;
|
||||
}
|
||||
|
||||
void Group::setEventFlag(int f)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#define RETRY_PEER_INFO_INTERVAL 500
|
||||
|
||||
|
@ -39,6 +40,7 @@ public:
|
|||
int getPeersCount() const;
|
||||
void regeneratePeerList();
|
||||
QStringList getPeerList() const;
|
||||
bool isSelfPeerNumber(int peernumber) const;
|
||||
|
||||
GroupChatForm *getChatForm();
|
||||
GroupWidget *getGroupWidget();
|
||||
|
@ -62,11 +64,12 @@ public:
|
|||
private:
|
||||
GroupWidget* widget;
|
||||
GroupChatForm* chatForm;
|
||||
QMap<int, QString> peers;
|
||||
QStringList peers;
|
||||
QMap<QString, QString> toxids;
|
||||
int hasNewMessages, userWasMentioned;
|
||||
int groupId;
|
||||
int nPeers;
|
||||
int selfPeerNum = -1;
|
||||
bool avGroupchat;
|
||||
|
||||
};
|
||||
|
|
|
@ -93,26 +93,27 @@ void Nexus::start()
|
|||
//connect(androidgui, &AndroidGUI::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
||||
//connect(androidgui, &AndroidGUI::changeProfile, core, &Core::switchConfiguration);
|
||||
#else
|
||||
connect(core, &Core::connected, widget, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
||||
connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore);
|
||||
connect(core, &Core::badProxy, widget, &Widget::onBadProxyCore);
|
||||
connect(core, &Core::statusSet, widget, &Widget::onStatusSet);
|
||||
connect(core, &Core::usernameSet, widget, &Widget::setUsername);
|
||||
connect(core, &Core::statusMessageSet, widget, &Widget::setStatusMessage);
|
||||
connect(core, &Core::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||
connect(core, &Core::friendAdded, widget, &Widget::addFriend);
|
||||
connect(core, &Core::failedToAddFriend, widget, &Widget::addFriendFailed);
|
||||
connect(core, &Core::friendUsernameChanged, widget, &Widget::onFriendUsernameChanged);
|
||||
connect(core, &Core::friendStatusChanged, widget, &Widget::onFriendStatusChanged);
|
||||
connect(core, &Core::connected, widget, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, widget, &Widget::onDisconnected);
|
||||
connect(core, &Core::failedToStart, widget, &Widget::onFailedToStartCore);
|
||||
connect(core, &Core::badProxy, widget, &Widget::onBadProxyCore);
|
||||
connect(core, &Core::statusSet, widget, &Widget::onStatusSet);
|
||||
connect(core, &Core::usernameSet, widget, &Widget::setUsername);
|
||||
connect(core, &Core::statusMessageSet, widget, &Widget::setStatusMessage);
|
||||
connect(core, &Core::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||
connect(core, &Core::friendAdded, widget, &Widget::addFriend);
|
||||
connect(core, &Core::failedToAddFriend, widget, &Widget::addFriendFailed);
|
||||
connect(core, &Core::friendUsernameChanged, widget, &Widget::onFriendUsernameChanged);
|
||||
connect(core, &Core::friendStatusChanged, widget, &Widget::onFriendStatusChanged);
|
||||
connect(core, &Core::friendStatusMessageChanged, widget, &Widget::onFriendStatusMessageChanged);
|
||||
connect(core, &Core::friendRequestReceived, widget, &Widget::onFriendRequestReceived);
|
||||
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
||||
connect(core, &Core::receiptRecieved, widget, &Widget::onReceiptRecieved);
|
||||
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
||||
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
||||
connect(core, &Core::groupNamelistChanged, widget, &Widget::onGroupNamelistChanged);
|
||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
||||
connect(core, &Core::friendRequestReceived, widget, &Widget::onFriendRequestReceived);
|
||||
connect(core, &Core::friendMessageReceived, widget, &Widget::onFriendMessageReceived);
|
||||
connect(core, &Core::receiptRecieved, widget, &Widget::onReceiptRecieved);
|
||||
connect(core, &Core::groupInviteReceived, widget, &Widget::onGroupInviteReceived);
|
||||
connect(core, &Core::groupMessageReceived, widget, &Widget::onGroupMessageReceived);
|
||||
connect(core, &Core::groupNamelistChanged, widget, &Widget::onGroupNamelistChanged);
|
||||
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
|
||||
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
||||
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
||||
connect(core, &Core::avInvite, widget, &Widget::playRingtone);
|
||||
connect(core, &Core::blockingClearContacts, widget, &Widget::clearContactsList, Qt::BlockingQueuedConnection);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "src/historykeeper.h"
|
||||
#include "src/misc/flowlayout.h"
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
: group(chatGroup), inCall{false}
|
||||
|
@ -126,19 +127,45 @@ void GroupChatForm::onUserListChanged()
|
|||
delete child->widget();
|
||||
delete child;
|
||||
}
|
||||
peerLabels.clear();
|
||||
|
||||
QStringList names(group->getPeerList());
|
||||
// the list needs peers in peernumber order, nameLayout needs alphabetical
|
||||
QMap<QString, QLabel*> orderizer;
|
||||
|
||||
// first traverse in peer number order, storing the QLabels as necessary
|
||||
QStringList names = group->getPeerList();
|
||||
unsigned nNames = names.size();
|
||||
for (unsigned i=0; i<nNames; ++i)
|
||||
{
|
||||
QString nameStr = names[i];
|
||||
if (i!=nNames-1)
|
||||
nameStr+=", ";
|
||||
QLabel* nameLabel = new QLabel(nameStr);
|
||||
nameLabel->setObjectName("peersLabel");
|
||||
nameLabel->setTextFormat(Qt::PlainText);
|
||||
namesListLayout->addWidget(nameLabel);
|
||||
peerLabels.append(new QLabel(names[i]));
|
||||
peerLabels[i]->setTextFormat(Qt::PlainText);
|
||||
orderizer[names[i]] = peerLabels[i];
|
||||
if (group->isSelfPeerNumber(i))
|
||||
peerLabels[i]->setStyleSheet("QLabel {color : green;}");
|
||||
}
|
||||
// now alphabetize and add to layout
|
||||
names.sort(Qt::CaseInsensitive);
|
||||
for (unsigned i=0; i<nNames; ++i)
|
||||
{
|
||||
QLabel* label = orderizer[names[i]];
|
||||
if (i != nNames - 1)
|
||||
label->setText(label->text() + ", ");
|
||||
namesListLayout->addWidget(label);
|
||||
}
|
||||
}
|
||||
|
||||
void GroupChatForm::peerAudioPlaying(int peer)
|
||||
{
|
||||
peerLabels[peer]->setStyleSheet("QLabel {color : red;}");
|
||||
if (!peerAudioTimers[peer])
|
||||
{
|
||||
peerAudioTimers[peer] = new QTimer(this);
|
||||
peerAudioTimers[peer]->setSingleShot(true);
|
||||
connect(peerAudioTimers[peer], &QTimer::timeout, [=]{this->peerLabels[peer]->setStyleSheet("");
|
||||
delete this->peerAudioTimers[peer];
|
||||
this->peerAudioTimers[peer] = nullptr;});
|
||||
}
|
||||
peerAudioTimers[peer]->start(500);
|
||||
}
|
||||
|
||||
void GroupChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
#define GROUPCHATFORM_H
|
||||
|
||||
#include "genericchatform.h"
|
||||
#include <QMap>
|
||||
|
||||
namespace Ui {class MainWindow;}
|
||||
class Group;
|
||||
class TabCompleter;
|
||||
class FlowLayout;
|
||||
class QTimer;
|
||||
|
||||
class GroupChatForm : public GenericChatForm
|
||||
{
|
||||
|
@ -31,6 +33,7 @@ public:
|
|||
GroupChatForm(Group* chatGroup);
|
||||
|
||||
void onUserListChanged();
|
||||
void peerAudioPlaying(int peer);
|
||||
|
||||
void keyPressEvent(QKeyEvent* ev);
|
||||
void keyReleaseEvent(QKeyEvent* ev);
|
||||
|
@ -51,6 +54,8 @@ protected:
|
|||
|
||||
private:
|
||||
Group* group;
|
||||
QList<QLabel*> peerLabels; // maps peernumbers to the QLabels in namesListLayout
|
||||
QMap<int, QTimer*> peerAudioTimers; // timeout = peer stopped sending audio
|
||||
FlowLayout* namesListLayout;
|
||||
QLabel *nusersLabel;
|
||||
TabCompleter* tabber;
|
||||
|
|
|
@ -906,6 +906,15 @@ void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const Q
|
|||
g->getChatForm()->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber)
|
||||
{
|
||||
Group* g = GroupList::findGroup(groupnumber);
|
||||
if (!g)
|
||||
return;
|
||||
|
||||
g->getChatForm()->peerAudioPlaying(peernumber);
|
||||
}
|
||||
|
||||
void Widget::removeGroup(Group* g, bool fake)
|
||||
{
|
||||
g->getGroupWidget()->setAsInactiveChatroom();
|
||||
|
|
|
@ -102,6 +102,7 @@ public slots:
|
|||
void onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);
|
||||
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
void onGroupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
||||
void onGroupPeerAudioPlaying(int groupnumber, int peernumber);
|
||||
void playRingtone();
|
||||
void onFriendTypingChanged(int friendId, bool isTyping);
|
||||
void nextContact();
|
||||
|
|
Loading…
Reference in New Issue
Block a user