7 Star 21 Fork 14

潜天无水 / BroadCast_QT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
group.cpp 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
潜天无水 提交于 2014-08-11 21:43 . 1 添加初始化文件
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "group.h"
#include "widget/groupwidget.h"
#include "widget/form/groupchatform.h"
#include "friendlist.h"
#include "friend.h"
#include "widget/widget.h"
#include "core.h"
#include <QDebug>
Group::Group(int GroupId, QString Name)
: groupId(GroupId), nPeers{0}, hasPeerInfo{false}
{
widget = new GroupWidget(groupId, Name);
chatForm = new GroupChatForm(this);
connect(&peerInfoTimer, SIGNAL(timeout()), this, SLOT(queryPeerInfo()));
peerInfoTimer.setInterval(500);
peerInfoTimer.setSingleShot(false);
//peerInfoTimer.start();
//in groupchats, we only notify on messages containing your name
hasNewMessages = 0;
userWasMentioned = 0;
}
Group::~Group()
{
delete chatForm;
delete widget;
}
void Group::queryPeerInfo()
{
const Core* core = Widget::getInstance()->getCore();
int nPeersResult = core->getGroupNumberPeers(groupId);
if (nPeersResult == -1)
{
qDebug() << "Group::queryPeerInfo: Can't get number of peers";
return;
}
nPeers = nPeersResult;
widget->onUserListChanged();
chatForm->onUserListChanged();
if (nPeersResult == 0)
return;
bool namesOk = true;
QList<QString> names = core->getGroupPeerNames(groupId);
if (names.isEmpty())
{
qDebug() << "Group::queryPeerInfo: Can't get names of peers";
return;
}
for (int i=0; i<names.size(); i++)
{
QString name = names[i];
if (name.isEmpty())
{
name = "<Unknown>";
namesOk = false;
}
peers[i] = name;
}
nPeers = names.size();
widget->onUserListChanged();
chatForm->onUserListChanged();
if (namesOk)
{
qDebug() << "Group::queryPeerInfo: Successfully loaded names";
hasPeerInfo = true;
peerInfoTimer.stop();
}
}
void Group::addPeer(int peerId, QString name)
{
if (peers.contains(peerId))
qWarning() << "Group::addPeer: peerId already used, overwriting anyway";
if (name.isEmpty())
peers[peerId] = "<Unknown>";
else
peers[peerId] = name;
nPeers++;
widget->onUserListChanged();
chatForm->onUserListChanged();
}
void Group::removePeer(int peerId)
{
peers.remove(peerId);
nPeers--;
widget->onUserListChanged();
chatForm->onUserListChanged();
}
void Group::updatePeer(int peerId, QString name)
{
peers[peerId] = name;
widget->onUserListChanged();
chatForm->onUserListChanged();
}
1
https://gitee.com/xxx7597/BroadCast_QT.git
git@gitee.com:xxx7597/BroadCast_QT.git
xxx7597
BroadCast_QT
BroadCast_QT
master

搜索帮助