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

Save on event instead of timer trigger

This commit is contained in:
Kevin Flynn 2014-07-03 10:38:30 -07:00
parent f1d30cbc14
commit 16df8e553e
3 changed files with 13 additions and 5 deletions

View File

@ -39,14 +39,14 @@ Core::Core(Camera* cam) :
{
toxTimer = new QTimer(this);
toxTimer->setSingleShot(true);
saveTimer = new QTimer(this);
saveTimer->start(TOX_SAVE_INTERVAL);
//saveTimer = new QTimer(this);
//saveTimer->start(TOX_SAVE_INTERVAL);
//fileTimer = new QTimer(this);
//fileTimer->start(TOX_FILE_INTERVAL);
bootstrapTimer = new QTimer(this);
bootstrapTimer->start(TOX_BOOTSTRAP_INTERVAL);
connect(toxTimer, &QTimer::timeout, this, &Core::process);
connect(saveTimer, &QTimer::timeout, this, &Core::saveConfiguration);
//connect(saveTimer, &QTimer::timeout, this, &Core::saveConfiguration); //Disable save timer in favor of saving on events
//connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat);
connect(bootstrapTimer, &QTimer::timeout, this, &Core::onBootstrapTimer);
connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::bootstrapDht);
@ -317,6 +317,7 @@ void Core::acceptFriendRequest(const QString& userId)
if (friendId == -1) {
emit failedToAddFriend(userId);
} else {
saveConfiguration();
emit friendAdded(friendId, userId);
}
}
@ -537,6 +538,7 @@ void Core::removeFriend(int friendId)
if (tox_del_friend(tox, friendId) == -1) {
emit failedToRemoveFriend(friendId);
} else {
saveConfiguration();
emit friendRemoved(friendId);
}
}
@ -553,6 +555,7 @@ void Core::setUsername(const QString& username)
if (tox_set_name(tox, cUsername.data(), cUsername.size()) == -1) {
emit failedToSetUsername(username);
} else {
saveConfiguration();
emit usernameSet(username);
}
}
@ -564,6 +567,7 @@ void Core::setStatusMessage(const QString& message)
if (tox_set_status_message(tox, cMessage.data(), cMessage.size()) == -1) {
emit failedToSetStatusMessage(message);
} else {
saveConfiguration();
emit statusMessageSet(message);
}
}
@ -587,6 +591,7 @@ void Core::setStatus(Status status)
}
if (tox_set_user_status(tox, userstatus) == 0) {
saveConfiguration();
emit statusSet(status);
} else {
emit failedToSetStatus(status);

3
core.h
View File

@ -119,6 +119,8 @@ public:
void quitGroupChat(int groupId) const;
void dispatchVideoFrame(vpx_image img) const;
void saveConfiguration();
public slots:
void start();
void process();
@ -261,7 +263,6 @@ private:
void onBootstrapTimer();
void loadConfiguration();
void saveConfiguration();
void loadFriends();
static void sendAllFileData(Core* core, ToxFile* file);

View File

@ -227,6 +227,7 @@ Widget::Widget(QWidget *parent) :
Widget::~Widget()
{
core->saveConfiguration();
instance = nullptr;
coreThread->exit();
coreThread->wait();
@ -428,6 +429,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
core->saveConfiguration();
}
void Widget::addFriendFailed(const QString&)
@ -763,7 +765,7 @@ bool Widget::event(QEvent * e)
Group* g = GroupList::findGroup(activeGroupWidget->groupId);
g->hasNewMessages = 0;
g->userWasMentioned = 0;
g->widget->statusPic.setPixmap(QPixmap("img/status/dot_groupchat.png"));
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
}
}
else if (e->type() == QEvent::WindowDeactivate && !useNativeTheme)