1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Circles: Fix sort circles on menus, fix groupchat rename through widget, improve activity sort performance

This commit is contained in:
TheSpiritXIII 2015-06-23 14:58:30 -04:00 committed by tux3
parent 484a9ea87e
commit b6df8ce34a
9 changed files with 70 additions and 22 deletions

View File

@ -533,6 +533,15 @@ QVector<ChatLine::Ptr> ChatLog::getLines()
return lines;
}
ChatLine::Ptr ChatLog::getLatestLine() const
{
if (!lines.empty())
{
return lines.last();
}
return nullptr;
}
void ChatLog::clear()
{
clearSelection();

View File

@ -61,6 +61,7 @@ public:
ChatLine::Ptr getTypingNotification() const;
QVector<ChatLine::Ptr> getLines();
ChatLine::Ptr getLatestLine() const;
// repetition interval sender name (sec)
const uint repNameAfter = 5*60;

View File

@ -88,7 +88,6 @@ void Group::updatePeer(int peerId, QString name)
void Group::setName(const QString& name)
{
widget->setName(name);
chatForm->setName(name);
if (widget->isActive())

View File

@ -469,7 +469,10 @@ void Settings::savePersonal(QString profileName, QString password)
ps.setValue("alias", frnd.alias);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("circle", frnd.circleID);
ps.setValue("activity", frnd.activity);
if (getEnableLogging())
ps.setValue("activity", frnd.activity);
index++;
}
ps.endArray();

View File

@ -232,6 +232,23 @@ ChatLog *GenericChatForm::getChatLog() const
return chatWidget;
}
QDate GenericChatForm::getLatestDate() const
{
ChatLine::Ptr chatLine = chatWidget->getLatestLine();
if (chatLine)
{
Timestamp* timestamp = dynamic_cast<Timestamp*>(chatLine->getContent(2));
if (timestamp)
return timestamp->getTime().date();
else
return QDate::currentDate();
}
return QDate();
}
void GenericChatForm::setName(const QString &newName)
{
nameLabel->setText(newName);
@ -360,7 +377,11 @@ void GenericChatForm::onSaveLogClicked()
auto lines = chatWidget->getLines();
for (ChatLine::Ptr l : lines)
{
Timestamp* rightCol = static_cast<Timestamp*>(l->getContent(2));
Timestamp* rightCol = dynamic_cast<Timestamp*>(l->getContent(2));
if (!rightCol)
return;
ChatLineContent* middleCol = l->getContent(1);
ChatLineContent* leftCol = l->getContent(0);

View File

@ -64,6 +64,7 @@ public:
bool isEmpty();
ChatLog* getChatLog() const;
QDate getLatestDate() const;
signals:
void sendMessage(uint32_t, QString);

View File

@ -111,12 +111,7 @@ Time getTime(const QDate date)
QDate getDateFriend(Friend* contact)
{
QDate date = Settings::getInstance().getFriendActivity(contact->getToxId());
if (date.isNull() && Settings::getInstance().getEnableLogging())
date = HistoryKeeper::getInstance()->getLatestDate(contact->getToxId().publicKey);
return date;
return Settings::getInstance().getFriendActivity(contact->getToxId());
}
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)

View File

@ -39,6 +39,7 @@
#include <QFileDialog>
#include <QDebug>
#include <QInputDialog>
#include <QCollator>
#include <cassert>
FriendWidget::FriendWidget(int FriendId, QString id)
@ -93,23 +94,34 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
else
friendList = dynamic_cast<FriendListWidget*>(circleWidget->parentWidget());
circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
newCircleAction = circleMenu->addAction(tr("To new circle"));
newCircleAction = circleMenu->addAction(tr("To new circle"));
if (circleId != -1)
removeCircleAction = circleMenu->addAction(tr("Remove from circle '%1'").arg(Settings::getInstance().getCircleName(circleId)));
if (circleId != -1)
removeCircleAction = circleMenu->addAction(tr("Remove from circle '%1'").arg(Settings::getInstance().getCircleName(circleId)));
circleMenu->addSeparator();
circleMenu->addSeparator();
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
QList<QAction*> circleActionList;
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
{
if (i != circleId)
{
if (i != circleId)
{
QAction* circleAction = circleMenu->addAction(tr("Move to circle \"%1\"").arg(Settings::getInstance().getCircleName(i)));
circleActions[circleAction] = i;
}
circleActionList.push_back(new QAction(tr("Move to circle \"%1\"").arg(Settings::getInstance().getCircleName(i)), circleMenu));
circleActions[circleActionList.back()] = i;
}
}
std::sort(circleActionList.begin(), circleActionList.end(), [](const QAction* lhs, const QAction* rhs) -> bool
{
QCollator collator;
collator.setNumericMode(true);
return collator.compare(lhs->text(), rhs->text()) < 0;
});
circleMenu->addActions(circleActionList);
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
QAction* setAlias = menu.addAction(tr("Set alias..."));

View File

@ -618,6 +618,13 @@ void Widget::addFriend(int friendId, const QString &userId)
{
ToxId userToxId = ToxId(userId);
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
QDate activityDate = Settings::getInstance().getFriendActivity(newfriend->getToxId());
QDate chatDate = newfriend->getChatForm()->getLatestDate();
if (chatDate > activityDate && chatDate.isValid())
Settings::getInstance().setFriendActivity(newfriend->getToxId(), chatDate);
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleID(newfriend->getToxId()));
Core* core = Nexus::getCore();
@ -656,8 +663,6 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved);
qDebug() << HistoryKeeper::getInstance()->getLatestDate(newfriend->getToxId().publicKey);
// Try to get the avatar from the cache
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull())
@ -668,6 +673,7 @@ void Widget::addFriend(int friendId, const QString &userId)
int filter = getFilterCriteria();
newfriend->getFriendWidget()->search(ui->searchContactText->text(), filterOffline(filter));
}
void Widget::addFriendFailed(const QString&, const QString& errorInfo)
@ -1064,6 +1070,7 @@ 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());
contactListWidget->renameGroupWidget(g->getGroupWidget(), title);
g->setName(title);
int filter = getFilterCriteria();
g->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter));
}