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

Merge branch 'pr790'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-17 11:47:52 +01:00
commit 83de276fe1
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
5 changed files with 41 additions and 31 deletions

View File

@ -18,6 +18,8 @@
#include "core.h"
#include "misc/settings.h"
#include "misc/style.h"
#include "src/friendlist.h"
#include "src/friend.h"
#include <math.h>
#include <QFileDialog>
#include <QMessageBox>
@ -208,7 +210,7 @@ bool isFileWritable(QString& path)
void FileTransferInstance::acceptRecvRequest()
{
QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId));
QString path = Settings::getInstance().getAutoAcceptDir(FriendList::findFriend(friendId)->getToxID());
if (path.isEmpty())
path = Settings::getInstance().getGlobalAutoAcceptDir();

View File

@ -98,13 +98,14 @@ void Settings::load()
friendLst.clear();
s.beginGroup("Friends");
int size = s.beginReadArray("fullAddresses");
int size = s.beginReadArray("Friend");
for (int i = 0; i < size; i ++)
{
s.setArrayIndex(i);
friendProp fp;
fp.addr = s.value("addr").toString();
fp.alias = s.value("alias").toString();
fp.autoAcceptDir = s.value("autoAcceptDir").toString();
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
}
s.endArray();
@ -126,6 +127,10 @@ void Settings::load()
checkUpdates = s.value("checkUpdates", false).toBool();
showInFront = s.value("showInFront", false).toBool();
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
globalAutoAcceptDir = s.value("globalAutoAcceptDir",
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)
).toString();
s.endGroup();
s.beginGroup("Advanced");
@ -178,16 +183,6 @@ void Settings::load()
encryptTox = s.value("encryptTox", false).toBool();
s.endGroup();
s.beginGroup("AutoAccept");
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
globalAutoAcceptDir = s.value("globalAutoAcceptDir",
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)
).toString();
for (auto& key : s.childKeys())
autoAccept[key] = s.value(key).toString();
s.endGroup();
s.beginGroup("Audio");
inDev = s.value("inDev", "").toString();
outDev = s.value("outDev", "").toString();
@ -244,13 +239,14 @@ void Settings::save(QString path)
s.endGroup();
s.beginGroup("Friends");
s.beginWriteArray("fullAddresses", friendLst.size());
s.beginWriteArray("Friend", friendLst.size());
int index = 0;
for (auto &frnd : friendLst)
{
s.setArrayIndex(index);
s.setValue("addr", frnd.addr);
s.setValue("alias", frnd.alias);
s.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++;
}
s.endArray();
@ -272,6 +268,8 @@ void Settings::save(QString path)
s.setValue("checkUpdates", checkUpdates);
s.setValue("showInFront", showInFront);
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
s.endGroup();
s.beginGroup("Advanced");
@ -316,13 +314,6 @@ void Settings::save(QString path)
s.setValue("encryptTox", encryptTox);
s.endGroup();
s.beginGroup("AutoAccept");
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
for (auto& id : autoAccept.keys())
s.setValue(id, autoAccept.value(id));
s.endGroup();
s.beginGroup("Audio");
s.setValue("inDev", inDev);
s.setValue("outDev", outDev);
@ -634,17 +625,31 @@ void Settings::setAutoAwayTime(int newValue)
autoAwayTime = newValue;
}
QString Settings::getAutoAcceptDir(const QString& id) const
QString Settings::getAutoAcceptDir(const ToxID& id) const
{
return autoAccept.value(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
return it->autoAcceptDir;
}
return QString();
}
void Settings::setAutoAcceptDir(const QString& id, const QString& dir)
void Settings::setAutoAcceptDir(const ToxID &id, const QString& dir)
{
if (dir.isEmpty())
autoAccept.remove(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
else
autoAccept[id.left(TOX_ID_PUBLIC_KEY_LENGTH)] = dir;
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->autoAcceptDir = dir;
} else {
updateFriendAdress(id.toString());
setAutoAcceptDir(id, dir);
}
}
QString Settings::getGlobalAutoAcceptDir() const
@ -865,6 +870,7 @@ void Settings::updateFriendAdress(const QString &newAddr)
friendProp fp;
fp.addr = newAddr;
fp.alias = "";
fp.autoAcceptDir = "";
friendLst[newAddr] = fp;
}
}
@ -892,6 +898,7 @@ void Settings::setFriendAlias(const ToxID &id, const QString &alias)
friendProp fp;
fp.addr = key;
fp.alias = alias;
fp.autoAcceptDir = "";
friendLst[key] = fp;
}
}

View File

@ -164,8 +164,8 @@ public:
int getEmojiFontPointSize() const;
void setEmojiFontPointSize(int value);
QString getAutoAcceptDir(const QString& id) const;
void setAutoAcceptDir(const QString&id, const QString& dir);
QString getAutoAcceptDir(const ToxID& id) const;
void setAutoAcceptDir(const ToxID&id, const QString& dir);
QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir);
@ -295,6 +295,7 @@ private:
{
QString alias;
QString addr;
QString autoAcceptDir;
};
QHash<QString, friendProp> friendLst;

View File

@ -217,7 +217,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
QTime::currentTime().toString("hh:mm"), false)));
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
if (!Settings::getInstance().getAutoAcceptDir(f->getToxID()).isEmpty()
|| Settings::getInstance().getAutoSaveEnabled())
fileTrans->pressFromHtml("btnB");
}

View File

@ -49,7 +49,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{
QPoint pos = event->globalPos();
QString id = Core::getInstance()->getFriendAddress(friendId);
ToxID id = FriendList::findFriend(friendId)->getToxID();
QString dir = Settings::getInstance().getAutoAcceptDir(id);
QMenu menu;
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));