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

add global file auto accept

This commit is contained in:
dubslow 2014-10-19 23:25:52 -05:00
parent 6b8ddab84b
commit a1ebf905b2
5 changed files with 42 additions and 3 deletions

View File

@ -209,6 +209,7 @@ bool isFileWritable(QString& path)
void FileTransferInstance::acceptRecvRequest()
{
QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId));
if (path.isEmpty()) path = Settings::getInstance().getGlobalAutoAcceptDir();
if (!path.isEmpty())
{
QDir dir(path);

View File

@ -153,6 +153,7 @@ void Settings::load()
s.endGroup();
s.beginGroup("AutoAccept");
globalAutoAcceptDir = s.value("globalAutoAcceptDir", "").toString();
for (auto& key : s.childKeys())
autoAccept[key] = s.value(key).toString();
s.endGroup();
@ -266,6 +267,7 @@ void Settings::save(QString path)
s.endGroup();
s.beginGroup("AutoAccept");
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
for (auto& id : autoAccept.keys())
s.setValue(id, autoAccept.value(id));
s.endGroup();
@ -504,6 +506,16 @@ void Settings::setAutoAcceptDir(const QString& id, const QString& dir)
autoAccept[id.left(TOX_ID_PUBLIC_KEY_LENGTH)] = dir;
}
QString Settings::getGlobalAutoAcceptDir() const
{
return globalAutoAcceptDir;
}
void Settings::setGlobalAutoAcceptDir(const QString& newValue)
{
globalAutoAcceptDir = newValue;
}
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
widgetSettings[uniqueName] = data;

View File

@ -128,6 +128,9 @@ public:
QString getAutoAcceptDir(const QString& id) const;
void setAutoAcceptDir(const QString&id, const QString& dir);
QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir);
// ChatView
int getFirstColumnHandlePos() const;
void setFirstColumnHandlePos(const int pos);
@ -201,6 +204,7 @@ private:
QHash<QString, QByteArray> widgetSettings;
QHash<QString, QString> autoAccept;
QString globalAutoAcceptDir;
// GUI
bool enableSmoothAnimation;

View File

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

View File

@ -49,9 +49,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
QPoint pos = event->globalPos();
QString id = Core::getInstance()->getFriendAddress(friendId);
QString dir = Settings::getInstance().getAutoAcceptDir(id);
QString globalDir = Settings::getInstance().getGlobalAutoAcceptDir();
QMenu menu;
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
QMenu* inviteMenu = menu.addMenu(tr("Invite in group","Menu to invite a friend in a groupchat"));
QMap<QAction*, Group*> groupActions;
for (Group* group : GroupList::groupList)
{
@ -60,10 +61,15 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
}
if (groupActions.isEmpty())
inviteMenu->setEnabled(false);
menu.addSeparator();
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
QAction* disableAutoAccept = menu.addAction(tr("Diasble auto accepting files", "context menu entry"));
QAction* disableAutoAccept = menu.addAction(tr("Manually accept files from this friend", "context menu entry"));
QAction* globalAA = menu.addAction(tr("Auto accept files from all friends", "context menu entry"));
QAction* disableGlobalAA = menu.addAction(tr("Disable global auto accept", "context menu entry"));
if (dir.isEmpty())
disableAutoAccept->setEnabled(false);
if (globalDir.isEmpty())
disableGlobalAA->setEnabled(false);
menu.addSeparator();
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
@ -98,6 +104,21 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{
Settings::getInstance().setAutoAcceptDir(id, "");
}
else if (selectedItem == globalAA)
{
if (globalDir.isEmpty())
globalDir = QDir::homePath();
globalDir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
if (!globalDir.isEmpty())
{
qDebug() << "FriendWidget: setting global auto accept dir to" << globalDir;
Settings::getInstance().setGlobalAutoAcceptDir(globalDir);
}
}
else if (selectedItem == disableGlobalAA)
{
Settings::getInstance().setGlobalAutoAcceptDir("");
}
else if (groupActions.contains(selectedItem))
{
Group* group = groupActions[selectedItem];