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

Check that file transfer target is writable

This commit is contained in:
Bill Winslow 2014-07-22 02:51:20 -05:00
parent f0b0110cfc
commit e31b4457c9
2 changed files with 34 additions and 4 deletions

View File

@ -2697,7 +2697,7 @@ QSplitter:handle{
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>(button inactive currently)</string>
<string>View completed file transfers</string>
</property>
<property name="text">
<string/>

View File

@ -21,6 +21,7 @@
#include <QFileDialog>
#include <QPixmap>
#include <QPainter>
#include <QMessageBox>
FileTransfertWidget::FileTransfertWidget(ToxFile File)
: lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0},
@ -265,11 +266,40 @@ void FileTransfertWidget::rejectRecvRequest()
onFileTransferCancelled(friendId, fileNum, direction);
}
// for whatever the fuck reason, QFileInfo::isWritable() always fails for files that don't exist
// which makes it useless for our case
// since QDir doesn't have an isWritable(), the only option I can think of is to make/delete the file
// surely this is a common problem that has a qt-implemented solution?
bool isWritable(QString& path)
{
QFile file(path);
bool exists = file.exists();
bool out = file.open(QIODevice::WriteOnly);
file.close();
if (!exists)
file.remove();
return out;
}
void FileTransfertWidget::acceptRecvRequest()
{
QString path = QFileDialog::getSaveFileName(0,tr("Save a file","Title of the file saving dialog"),QDir::currentPath()+'/'+filename->text());
if (path.isEmpty())
return;
QString path;
while (true)
{
path = QFileDialog::getSaveFileName(0,tr("Save a file","Title of the file saving dialog"),QDir::currentPath()+'/'+filename->text());
if (path.isEmpty())
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 (isWritable(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;