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

Updated the completed transfers widget to work as advertised

This commit is contained in:
dubslow 2014-07-15 21:37:08 -04:00
parent 4bb2ec3356
commit 1644f8c139
4 changed files with 35 additions and 26 deletions

View File

@ -664,9 +664,9 @@ void Core::setStatus(Status status)
void Core::onFileTransferFinished(ToxFile file) void Core::onFileTransferFinished(ToxFile file)
{ {
if (file.direction == file.SENDING) if (file.direction == file.SENDING)
emit fileUploadFinished(QString(file.fileName)); emit fileUploadFinished(file.filePath);
else else
emit fileDownloadFinished(QString(file.fileName)); emit fileDownloadFinished(file.filePath);
} }
void Core::bootstrapDht() void Core::bootstrapDht()
@ -952,6 +952,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
removeFileFromQueue(true, file->friendId, file->fileNum); removeFileFromQueue(true, file->friendId, file->fileNum);
return; return;
} }
qDebug() << "chunkSize: " << chunkSize;
chunkSize = std::min(chunkSize, file->filesize); chunkSize = std::min(chunkSize, file->filesize);
uint8_t* data = new uint8_t[chunkSize]; uint8_t* data = new uint8_t[chunkSize];
file->file->seek(file->bytesSent); file->file->seek(file->bytesSent);

View File

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

View File

@ -27,18 +27,25 @@ FilesForm::FilesForm()
head->setLayout(&headLayout); head->setLayout(&headLayout);
headLayout.addWidget(&headLabel); headLayout.addWidget(&headLabel);
main.addTab(&recvd, tr("Downloads")); recvd = new QListWidget;
main.addTab(&sent, tr("Uploads")); sent = new QListWidget;
connect(&sent, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onUploadFileActivated(QListWidgetItem*))); main.addTab(recvd, tr("Downloads"));
connect(&recvd, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onDownloadFileActivated(QListWidgetItem*))); main.addTab(sent, tr("Uploads"));
connect(sent, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onFileActivated(QListWidgetItem*)));
connect(recvd, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onFileActivated(QListWidgetItem*)));
} }
FilesForm::~FilesForm() FilesForm::~FilesForm()
{ {
//delete head; #if 0
// having this line caused a SIGABRT because free() received an invalid pointer delete recvd; // docs claim this will clean up children
delete sent;
delete head;
#endif
// having these lines caused a SIGABRT because free() received an invalid pointer
// but since this is only called on program shutdown anyways, // but since this is only called on program shutdown anyways,
// I'm not too bummed about removing it // I'm not too bummed about removing it
} }
@ -53,14 +60,16 @@ void FilesForm::show(Ui::Widget& ui)
void FilesForm::onFileDownloadComplete(const QString& path) void FilesForm::onFileDownloadComplete(const QString& path)
{ {
QListWidgetItem* tmp = new QListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), path); ListWidgetItem* tmp = new ListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), QFileInfo(path).fileName());
recvd.addItem(tmp); tmp->path = path;
recvd->addItem(tmp);
} }
void FilesForm::onFileUploadComplete(const QString& path) void FilesForm::onFileUploadComplete(const QString& path)
{ {
QListWidgetItem* tmp = new QListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), path); ListWidgetItem* tmp = new ListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), QFileInfo(path).fileName());
sent.addItem(tmp); tmp->path = path;
sent->addItem(tmp);
} }
// sadly, the ToxFile struct in core only has the file name, not the file path... // sadly, the ToxFile struct in core only has the file name, not the file path...
@ -68,16 +77,10 @@ void FilesForm::onFileUploadComplete(const QString& path)
// whenever they're not saved anywhere custom, thanks to the hack) // whenever they're not saved anywhere custom, thanks to the hack)
// I could do some digging around, but for now I'm tired and others already // I could do some digging around, but for now I'm tired and others already
// might know it without me needing to dig, so... // might know it without me needing to dig, so...
void FilesForm::onDownloadFileActivated(QListWidgetItem* item) void FilesForm::onFileActivated(QListWidgetItem* item)
{ {
QUrl url = QUrl::fromLocalFile("./" + item->text()); ListWidgetItem* tmp = dynamic_cast<ListWidgetItem*> (item);
qDebug() << "Opening '" << url << "'"; QUrl url = QUrl::fromLocalFile(tmp->path);
QDesktopServices::openUrl(url);
}
void FilesForm::onUploadFileActivated(QListWidgetItem* item)
{
QUrl url = QUrl::fromLocalFile(item->text());
qDebug() << "Opening '" << url << "'"; qDebug() << "Opening '" << url << "'";
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }

View File

@ -27,6 +27,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QUrl> #include <QUrl>
#include <QDebug> #include <QDebug>
#include <QFileInfo>
class FilesForm : public QObject class FilesForm : public QObject
{ {
@ -43,8 +44,7 @@ public slots:
void onFileUploadComplete(const QString& path); void onFileUploadComplete(const QString& path);
private slots: private slots:
void onDownloadFileActivated(QListWidgetItem* item); void onFileActivated(QListWidgetItem* item);
void onUploadFileActivated(QListWidgetItem* item);
private: private:
QWidget* head; QWidget* head;
@ -55,10 +55,15 @@ private:
I should really look into the new fangled list thingy, to deactivate I should really look into the new fangled list thingy, to deactivate
specific items in the list */ specific items in the list */
QTabWidget main; QTabWidget main;
QListWidget sent, recvd; QListWidget* sent, * recvd;
}; };
#include "ui_widget.h" class ListWidgetItem : public QListWidgetItem
{
using QListWidgetItem::QListWidgetItem;
public:
QString path;
};
#endif // FILESFORM_H #endif // FILESFORM_H