mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Save circle settings after each modification
This commit is contained in:
parent
38fa6fc291
commit
ac2263b3e8
|
@ -351,7 +351,6 @@ void Core::start()
|
|||
}
|
||||
|
||||
ready = true;
|
||||
emit started();
|
||||
|
||||
// If we created a new profile earlier,
|
||||
// now that we're ready save it and ONLY THEN broadcast the new ID.
|
||||
|
|
|
@ -158,7 +158,6 @@ signals:
|
|||
void disconnected();
|
||||
|
||||
void blockingClearContacts();
|
||||
void started();
|
||||
|
||||
void friendRequestReceived(const QString& userId, const QString& message);
|
||||
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);
|
||||
|
|
|
@ -295,7 +295,7 @@ void Settings::loadPersonnal(Profile* profile)
|
|||
fp.addr = ps.value("addr").toString();
|
||||
fp.alias = ps.value("alias").toString();
|
||||
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
|
||||
fp.circleIndex = ps.value("circle", -1).toInt();
|
||||
fp.circleID = ps.value("circle", -1).toInt();
|
||||
friendLst[ToxId(fp.addr).publicKey] = fp;
|
||||
}
|
||||
ps.endArray();
|
||||
|
@ -466,7 +466,7 @@ void Settings::savePersonal(QString profileName, QString password)
|
|||
ps.setValue("addr", frnd.addr);
|
||||
ps.setValue("alias", frnd.alias);
|
||||
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
|
||||
ps.setValue("circle", frnd.circleIndex);
|
||||
ps.setValue("circle", frnd.circleID);
|
||||
index++;
|
||||
}
|
||||
ps.endArray();
|
||||
|
@ -1285,31 +1285,32 @@ void Settings::setFriendAlias(const ToxId &id, const QString &alias)
|
|||
}
|
||||
}
|
||||
|
||||
int Settings::getFriendCircleIndex(const ToxId &id) const
|
||||
int Settings::getFriendCircleID(const ToxId &id) const
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
if (it != friendLst.end())
|
||||
return it->circleIndex;
|
||||
return it->circleID;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Settings::setFriendCircleIndex(const ToxId &id, int index)
|
||||
void Settings::setFriendCircleID(const ToxId &id, int circleID)
|
||||
{
|
||||
QString key = id.publicKey;
|
||||
auto it = friendLst.find(key);
|
||||
if (it != friendLst.end())
|
||||
it->circleIndex = index;
|
||||
it->circleID = circleID;
|
||||
else
|
||||
{
|
||||
friendProp fp;
|
||||
fp.addr = key;
|
||||
fp.alias = "";
|
||||
fp.autoAcceptDir = "";
|
||||
fp.circleIndex = index;
|
||||
fp.circleID = circleID;
|
||||
friendLst[key] = fp;
|
||||
}
|
||||
savePersonal();
|
||||
}
|
||||
|
||||
void Settings::removeFriendSettings(const ToxId &id)
|
||||
|
@ -1360,14 +1361,15 @@ int Settings::getCircleCount() const
|
|||
return circleLst.size();
|
||||
}
|
||||
|
||||
QString Settings::getCircleName(int index) const
|
||||
QString Settings::getCircleName(int id) const
|
||||
{
|
||||
return circleLst[index].name;
|
||||
return circleLst[id].name;
|
||||
}
|
||||
|
||||
void Settings::setCircleName(int index, const QString &name)
|
||||
void Settings::setCircleName(int id, const QString &name)
|
||||
{
|
||||
circleLst[index].name = name;
|
||||
circleLst[id].name = name;
|
||||
save();
|
||||
}
|
||||
|
||||
int Settings::addCircle(const QString &name)
|
||||
|
@ -1376,25 +1378,28 @@ int Settings::addCircle(const QString &name)
|
|||
cp.name = name;
|
||||
cp.expanded = false;
|
||||
circleLst.append(cp);
|
||||
savePersonal();
|
||||
return circleLst.count() - 1;
|
||||
}
|
||||
|
||||
bool Settings::getCircleExpanded(int index) const
|
||||
bool Settings::getCircleExpanded(int id) const
|
||||
{
|
||||
return circleLst[index].expanded;
|
||||
return circleLst[id].expanded;
|
||||
}
|
||||
|
||||
void Settings::setCircleExpanded(int index, bool expanded)
|
||||
void Settings::setCircleExpanded(int id, bool expanded)
|
||||
{
|
||||
circleLst[index].expanded = expanded;
|
||||
circleLst[id].expanded = expanded;
|
||||
save();
|
||||
}
|
||||
|
||||
int Settings::removeCircle(int index)
|
||||
int Settings::removeCircle(int id)
|
||||
{
|
||||
// Replace index with last one and remove last one instead.
|
||||
// This gives you contiguous ids all the time.
|
||||
circleLst[index] = circleLst.last();
|
||||
circleLst[id] = circleLst.last();
|
||||
circleLst.pop_back();
|
||||
savePersonal();
|
||||
return circleLst.count();
|
||||
}
|
||||
|
||||
|
|
|
@ -228,8 +228,8 @@ public:
|
|||
QString getFriendAlias(const ToxId &id) const;
|
||||
void setFriendAlias(const ToxId &id, const QString &alias);
|
||||
|
||||
int getFriendCircleIndex(const ToxId &id) const;
|
||||
void setFriendCircleIndex(const ToxId &id, int index);
|
||||
int getFriendCircleID(const ToxId &id) const;
|
||||
void setFriendCircleID(const ToxId &id, int circleID);
|
||||
|
||||
void removeFriendSettings(const ToxId &id);
|
||||
|
||||
|
@ -247,11 +247,11 @@ public:
|
|||
|
||||
int getCircleCount() const;
|
||||
int addCircle(const QString &name);
|
||||
int removeCircle(int index);
|
||||
QString getCircleName(int index) const;
|
||||
void setCircleName(int index, const QString &name);
|
||||
bool getCircleExpanded(int index) const;
|
||||
void setCircleExpanded(int index, bool expanded);
|
||||
int removeCircle(int id);
|
||||
QString getCircleName(int id) const;
|
||||
void setCircleName(int id, const QString &name);
|
||||
bool getCircleExpanded(int id) const;
|
||||
void setCircleExpanded(int id, bool expanded);
|
||||
|
||||
// Assume all widgets have unique names
|
||||
// Don't use it to save every single thing you want to save, use it
|
||||
|
@ -368,7 +368,7 @@ private:
|
|||
QString alias;
|
||||
QString addr;
|
||||
QString autoAcceptDir;
|
||||
int circleIndex = -1;
|
||||
int circleID = -1;
|
||||
};
|
||||
|
||||
struct circleProp
|
||||
|
|
|
@ -118,40 +118,31 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
|||
if (isNew)
|
||||
renameCircle();
|
||||
|
||||
listWidget->setVisible(Settings::getInstance().getCircleExpanded(id));
|
||||
setExpanded(Settings::getInstance().getCircleExpanded(id));
|
||||
}
|
||||
|
||||
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
||||
{
|
||||
listLayout->addFriendWidget(w, s);
|
||||
updateStatus();
|
||||
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId(), id);
|
||||
qDebug() << Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId()) << " WITH " << id;
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), id);
|
||||
qDebug() << Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId()) << " WITH " << id;
|
||||
}
|
||||
|
||||
void CircleWidget::expand()
|
||||
void CircleWidget::setExpanded(bool isExpanded)
|
||||
{
|
||||
if (expanded)
|
||||
return;
|
||||
toggle();
|
||||
}
|
||||
|
||||
void CircleWidget::toggle()
|
||||
expanded = isExpanded;
|
||||
listWidget->setVisible(isExpanded);
|
||||
if (isExpanded)
|
||||
{
|
||||
expanded = !expanded;
|
||||
listWidget->setVisible(expanded);
|
||||
if (expanded)
|
||||
{
|
||||
//fullLayout->addLayout(listLayout);
|
||||
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
||||
}
|
||||
else
|
||||
{
|
||||
//fullLayout->removeItem(listLayout);
|
||||
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
||||
}
|
||||
|
||||
Settings::getInstance().setCircleExpanded(id, expanded);
|
||||
Settings::getInstance().setCircleExpanded(id, isExpanded);
|
||||
}
|
||||
|
||||
void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline)
|
||||
|
@ -189,14 +180,14 @@ bool CircleWidget::cycleContacts(bool forward)
|
|||
{
|
||||
if (listLayout->getLayoutOnline()->count() != 0)
|
||||
{
|
||||
expand();
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOnline(), 0);
|
||||
qDebug() << "emmited 1";
|
||||
return true;
|
||||
}
|
||||
else if (listLayout->getLayoutOffline()->count() != 0)
|
||||
{
|
||||
expand();
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOffline(), 0);
|
||||
qDebug() << "emmited 2";
|
||||
return true;
|
||||
|
@ -206,14 +197,14 @@ bool CircleWidget::cycleContacts(bool forward)
|
|||
{
|
||||
if (listLayout->getLayoutOffline()->count() != 0)
|
||||
{
|
||||
expand();
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
|
||||
qDebug() << "emmited 3";
|
||||
return true;
|
||||
}
|
||||
else if (listLayout->getLayoutOnline()->count() != 0)
|
||||
{
|
||||
expand();
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1);
|
||||
qDebug() << "emmited 4";
|
||||
return true;
|
||||
|
@ -374,7 +365,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
|
|||
void CircleWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
toggle();
|
||||
setExpanded(!expanded);
|
||||
}
|
||||
|
||||
void CircleWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
@ -395,8 +386,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
if (!expanded)
|
||||
toggle();
|
||||
setExpanded(true);
|
||||
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
Friend *f = FriendList::findFriend(friendId);
|
||||
|
@ -406,7 +396,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
assert(widget != nullptr);
|
||||
|
||||
// Update old circle after moved.
|
||||
CircleWidget *circleWidget = getFromID(Settings::getInstance().getFriendCircleIndex(f->getToxId()));
|
||||
CircleWidget *circleWidget = getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
|
||||
addFriendWidget(widget, f->getStatus());
|
||||
|
||||
|
@ -438,7 +428,7 @@ void CircleWidget::updateID(int index)
|
|||
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(listLayout->getLayoutOnline()->itemAt(i));
|
||||
if (friendWidget != nullptr)
|
||||
{
|
||||
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < listLayout->getLayoutOffline()->count(); ++i)
|
||||
|
@ -446,7 +436,7 @@ void CircleWidget::updateID(int index)
|
|||
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(listLayout->getLayoutOffline()->itemAt(i));
|
||||
if (friendWidget != nullptr)
|
||||
{
|
||||
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false);
|
||||
|
||||
void expand();
|
||||
void toggle();
|
||||
void setExpanded(bool isExpanded);
|
||||
|
||||
void updateStatus();
|
||||
|
||||
|
|
|
@ -91,13 +91,13 @@ int FriendListLayout::friendTotalCount() const
|
|||
|
||||
bool FriendListLayout::hasChatrooms() const
|
||||
{
|
||||
return !(friendOfflineLayout.getLayout()->isEmpty() && friendOfflineLayout.getLayout()->isEmpty());
|
||||
return !(friendOfflineLayout.getLayout()->isEmpty() && friendOnlineLayout.getLayout()->isEmpty());
|
||||
}
|
||||
|
||||
void FriendListLayout::searchChatrooms(const QString& searchString, bool hideOnline, bool hideOffline)
|
||||
{
|
||||
friendOfflineLayout.search(searchString, hideOffline);
|
||||
friendOnlineLayout.search(searchString, hideOnline);
|
||||
friendOfflineLayout.search(searchString, hideOffline);
|
||||
}
|
||||
|
||||
QLayout* FriendListLayout::getLayoutOnline() const
|
||||
|
|
|
@ -88,7 +88,7 @@ void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
|
|||
if (friendWidget != nullptr)
|
||||
{
|
||||
circleWidget->addFriendWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus());
|
||||
circleWidget->toggle();
|
||||
circleWidget->setExpanded(true);
|
||||
}
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
|
||||
if (friendWidget != nullptr)
|
||||
{
|
||||
circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId()));
|
||||
circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId()));
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
if (circleWidget->cycleContacts(friendWidget, forward))
|
||||
|
@ -275,7 +275,7 @@ void FriendListWidget::dropEvent(QDropEvent *event)
|
|||
assert(widget != nullptr);
|
||||
|
||||
// Update old circle after moved.
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(f->getToxId()));
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
|
||||
listLayout->addFriendWidget(widget, f->getStatus());
|
||||
|
||||
|
@ -289,13 +289,13 @@ void FriendListWidget::dropEvent(QDropEvent *event)
|
|||
|
||||
void FriendListWidget::moveWidget(FriendWidget *w, Status s, bool add)
|
||||
{
|
||||
int circleId = Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId());
|
||||
int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId());
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
if (circleWidget == nullptr || add)
|
||||
{
|
||||
if (circleId != -1)
|
||||
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId(), -1);
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), -1);
|
||||
listLayout->addFriendWidget(w, s);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
if (groupActions.isEmpty())
|
||||
inviteMenu->setEnabled(false);
|
||||
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(friendId)->getToxId()));
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()));
|
||||
|
||||
QAction* newCircleAction = circleMenu->addAction(tr("To new circle"));
|
||||
QAction *removeCircleAction;
|
||||
|
@ -170,7 +170,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
|
||||
CircleWidget* circle = circleActions[selectedItem];
|
||||
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
||||
circle->expand();
|
||||
circle->setExpanded(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,9 +215,9 @@ void FriendWidget::updateStatusLight()
|
|||
|
||||
if (f->getEventFlag())
|
||||
{
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(friendId)->getToxId()));
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()));
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->expand();
|
||||
circleWidget->setExpanded(true);
|
||||
}
|
||||
|
||||
if (!f->getEventFlag())
|
||||
|
|
|
@ -585,7 +585,7 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||
qDebug() << "ADDING FRIEND ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;";
|
||||
ToxId userToxId = ToxId(userId);
|
||||
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
|
||||
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleIndex(newfriend->getToxId()));
|
||||
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleID(newfriend->getToxId()));
|
||||
|
||||
Core* core = Nexus::getCore();
|
||||
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
|
||||
|
|
Loading…
Reference in New Issue
Block a user