mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(db): File transfer history review comments
This commit is contained in:
parent
8427be6678
commit
25005c5c19
@ -108,7 +108,6 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file)
|
|||||||
lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED;
|
lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED;
|
||||||
updateWidget(file);
|
updateWidget(file);
|
||||||
|
|
||||||
// preview
|
|
||||||
setFixedHeight(64);
|
setFixedHeight(64);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,6 +339,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file)
|
|||||||
setBackgroundColor(Style::getColor(Style::Green), true);
|
setBackgroundColor(Style::getColor(Style::Green), true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,6 +372,7 @@ void FileTransferWidget::updateWidgetText(ToxFile const& file)
|
|||||||
case ToxFile::FINISHED:
|
case ToxFile::FINISHED:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,6 +397,7 @@ void FileTransferWidget::updatePreview(ToxFile const& file)
|
|||||||
showPreview(file.filePath);
|
showPreview(file.filePath);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,6 +444,7 @@ void FileTransferWidget::updateFileProgress(ToxFile const& file)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,6 +467,7 @@ void FileTransferWidget::updateSignals(ToxFile const& file)
|
|||||||
case ToxFile::TRANSMITTING:
|
case ToxFile::TRANSMITTING:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,6 +536,7 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid file status";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -583,7 +588,6 @@ void FileTransferWidget::showPreview(const QString& filename)
|
|||||||
|
|
||||||
QFile imageFile(filename);
|
QFile imageFile(filename);
|
||||||
if (!imageFile.open(QIODevice::ReadOnly)) {
|
if (!imageFile.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Failed to open file for preview";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QByteArray imageFileData = imageFile.readAll();
|
const QByteArray imageFileData = imageFile.readAll();
|
||||||
|
@ -279,9 +279,10 @@ void History::onFileInsertionReady(FileDbInsertionData data)
|
|||||||
// Copy to pass into labmda for later
|
// Copy to pass into labmda for later
|
||||||
auto fileId = data.fileId;
|
auto fileId = data.fileId;
|
||||||
queries +=
|
queries +=
|
||||||
RawDatabase::Query(QStringLiteral("INSERT INTO file_transfers (chat_id, file_restart_id, "
|
RawDatabase::Query(QStringLiteral(
|
||||||
"file_path, file_name, file_hash, file_size, direction, file_state) "
|
"INSERT INTO file_transfers (chat_id, file_restart_id, "
|
||||||
"VALUES (%1, ?, ?, ?, ?, %2, %3, %4);")
|
"file_path, file_name, file_hash, file_size, direction, file_state) "
|
||||||
|
"VALUES (%1, ?, ?, ?, ?, %2, %3, %4);")
|
||||||
.arg(peerId)
|
.arg(peerId)
|
||||||
.arg(data.size)
|
.arg(data.size)
|
||||||
.arg(static_cast<int>(data.direction))
|
.arg(static_cast<int>(data.direction))
|
||||||
@ -307,7 +308,8 @@ void History::onFileInserted(int64_t dbId, QString fileId)
|
|||||||
{
|
{
|
||||||
auto& fileInfo = fileInfos[fileId];
|
auto& fileInfo = fileInfos[fileId];
|
||||||
if (fileInfo.finished) {
|
if (fileInfo.finished) {
|
||||||
db->execLater(generateFileFinished(dbId, fileInfo.success, fileInfo.filePath, fileInfo.fileHash));
|
db->execLater(
|
||||||
|
generateFileFinished(dbId, fileInfo.success, fileInfo.filePath, fileInfo.fileHash));
|
||||||
fileInfos.remove(fileId);
|
fileInfos.remove(fileId);
|
||||||
} else {
|
} else {
|
||||||
fileInfo.finished = false;
|
fileInfo.finished = false;
|
||||||
@ -315,7 +317,8 @@ void History::onFileInserted(int64_t dbId, QString fileId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawDatabase::Query History::generateFileFinished(int64_t id, bool success, const QString& filePath, const QByteArray& fileHash)
|
RawDatabase::Query History::generateFileFinished(int64_t id, bool success, const QString& filePath,
|
||||||
|
const QByteArray& fileHash)
|
||||||
{
|
{
|
||||||
auto file_state = success ? ToxFile::FINISHED : ToxFile::CANCELED;
|
auto file_state = success ? ToxFile::FINISHED : ToxFile::CANCELED;
|
||||||
if (filePath.length()) {
|
if (filePath.length()) {
|
||||||
@ -406,7 +409,8 @@ void History::addNewMessage(const QString& friendPk, const QString& message, con
|
|||||||
insertIdCallback));
|
insertIdCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void History::setFileFinished(const QString& fileId, bool success, const QString& filePath, const QByteArray& fileHash)
|
void History::setFileFinished(const QString& fileId, bool success, const QString& filePath,
|
||||||
|
const QByteArray& fileHash)
|
||||||
{
|
{
|
||||||
auto& fileInfo = fileInfos[fileId];
|
auto& fileInfo = fileInfos[fileId];
|
||||||
if (fileInfo.fileId == -1) {
|
if (fileInfo.fileId == -1) {
|
||||||
@ -704,13 +708,17 @@ void History::dbSchemaUpgrade()
|
|||||||
qWarning() << "Database version is newer than we currently support. Please upgrade qTox";
|
qWarning() << "Database version is newer than we currently support. Please upgrade qTox";
|
||||||
// We don't know what future versions have done, we have to disable db access until we re-upgrade
|
// We don't know what future versions have done, we have to disable db access until we re-upgrade
|
||||||
db.reset();
|
db.reset();
|
||||||
|
return;
|
||||||
} else if (databaseSchemaVersion == SCHEMA_VERSION) {
|
} else if (databaseSchemaVersion == SCHEMA_VERSION) {
|
||||||
// No work to do
|
// No work to do
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure to handle the un-created case as well in the following upgrade code
|
||||||
switch (databaseSchemaVersion) {
|
switch (databaseSchemaVersion) {
|
||||||
case 0:
|
case 0:
|
||||||
|
// This will generate a warning on new profiles, but we have no easy way to chain execs. I
|
||||||
|
// don't want to block the rest of the program on db creation so I guess we can just live with the warning for now
|
||||||
db->execLater(RawDatabase::Query("ALTER TABLE history ADD file_id INTEGER;"));
|
db->execLater(RawDatabase::Query("ALTER TABLE history ADD file_id INTEGER;"));
|
||||||
// fallthrough
|
// fallthrough
|
||||||
// case 1:
|
// case 1:
|
||||||
|
@ -913,6 +913,7 @@ ChatMessage::Ptr ChatForm::chatMessageFromHistMessage(History::HistMessage const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
qCritical() << "Invalid HistMessageContentType";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,11 +1207,9 @@ void ChatForm::onExportChat()
|
|||||||
ToxPk authorPk(ToxId(it.sender).getPublicKey());
|
ToxPk authorPk(ToxId(it.sender).getPublicKey());
|
||||||
QString author = getMsgAuthorDispName(authorPk, it.dispName);
|
QString author = getMsgAuthorDispName(authorPk, it.dispName);
|
||||||
|
|
||||||
if (it.content.getType() == HistMessageContentType::message) {
|
buffer = buffer
|
||||||
buffer = buffer
|
% QString{datestamp % '\t' % timestamp % '\t' % author % '\t'
|
||||||
% QString{datestamp % '\t' % timestamp % '\t' % author % '\t'
|
% it.content.asMessage() % '\n'};
|
||||||
% it.content.asMessage() % '\n'};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
file.write(buffer.toUtf8());
|
file.write(buffer.toUtf8());
|
||||||
file.close();
|
file.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user