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

add backend for autoaccept

This commit is contained in:
dubslow 2014-10-17 22:30:04 -05:00
parent e10e0087a4
commit 3dbbbca587

View File

@ -16,6 +16,7 @@
#include "filetransferinstance.h"
#include "core.h"
#include "misc/settings.h"
#include "misc/style.h"
#include <math.h>
#include <QFileDialog>
@ -204,6 +205,25 @@ bool isFileWritable(QString& path)
void FileTransferInstance::acceptRecvRequest()
{
QString path;
if (!(path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId))).isEmpty())
{
QDir dir(path);
path = dir.filePath(filename);
QFileInfo info(path);
if (info.exists()) // emulate chrome
{
QString name = info.baseName(), ext = info.completeSuffix();
int i = 0;
do
{
path = dir.filePath(name + QString(" (%1)").arg(++i) + "." + ext);
}
while (QFileInfo(path).exists());
}
qDebug() << "File: auto saving to" << path;
}
else
{
while (true)
{
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
@ -211,15 +231,13 @@ void FileTransferInstance::acceptRecvRequest()
return;
else
{
//bool savable = QFileInfo(path).isWritable();
//qDebug() << path << " is writable: " << savable;
//qDebug() << "/home/bill/bliss.pdf writable: " << QFileInfo("/home/bill/bliss.pdf").isWritable();
if (isFileWritable(path))
break;
else
QMessageBox::warning(0, tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
}
}
}
savePath = path;