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;
|
||||
updateWidget(file);
|
||||
|
||||
// preview
|
||||
setFixedHeight(64);
|
||||
}
|
||||
|
||||
|
@ -340,6 +339,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file)
|
|||
setBackgroundColor(Style::getColor(Style::Green), true);
|
||||
break;
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -372,6 +372,7 @@ void FileTransferWidget::updateWidgetText(ToxFile const& file)
|
|||
case ToxFile::FINISHED:
|
||||
break;
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -396,6 +397,7 @@ void FileTransferWidget::updatePreview(ToxFile const& file)
|
|||
showPreview(file.filePath);
|
||||
break;
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -442,6 +444,7 @@ void FileTransferWidget::updateFileProgress(ToxFile const& file)
|
|||
break;
|
||||
}
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -464,6 +467,7 @@ void FileTransferWidget::updateSignals(ToxFile const& file)
|
|||
case ToxFile::TRANSMITTING:
|
||||
break;
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -532,6 +536,7 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
|
||||
break;
|
||||
default:
|
||||
qCritical() << "Invalid file status";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
@ -583,7 +588,6 @@ void FileTransferWidget::showPreview(const QString& filename)
|
|||
|
||||
QFile imageFile(filename);
|
||||
if (!imageFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file for preview";
|
||||
return;
|
||||
}
|
||||
const QByteArray imageFileData = imageFile.readAll();
|
||||
|
|
|
@ -279,7 +279,8 @@ void History::onFileInsertionReady(FileDbInsertionData data)
|
|||
// Copy to pass into labmda for later
|
||||
auto fileId = data.fileId;
|
||||
queries +=
|
||||
RawDatabase::Query(QStringLiteral("INSERT INTO file_transfers (chat_id, file_restart_id, "
|
||||
RawDatabase::Query(QStringLiteral(
|
||||
"INSERT INTO file_transfers (chat_id, file_restart_id, "
|
||||
"file_path, file_name, file_hash, file_size, direction, file_state) "
|
||||
"VALUES (%1, ?, ?, ?, ?, %2, %3, %4);")
|
||||
.arg(peerId)
|
||||
|
@ -307,7 +308,8 @@ void History::onFileInserted(int64_t dbId, QString fileId)
|
|||
{
|
||||
auto& fileInfo = fileInfos[fileId];
|
||||
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);
|
||||
} else {
|
||||
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;
|
||||
if (filePath.length()) {
|
||||
|
@ -406,7 +409,8 @@ void History::addNewMessage(const QString& friendPk, const QString& message, con
|
|||
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];
|
||||
if (fileInfo.fileId == -1) {
|
||||
|
@ -704,13 +708,17 @@ void History::dbSchemaUpgrade()
|
|||
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
|
||||
db.reset();
|
||||
return;
|
||||
} else if (databaseSchemaVersion == SCHEMA_VERSION) {
|
||||
// No work to do
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure to handle the un-created case as well in the following upgrade code
|
||||
switch (databaseSchemaVersion) {
|
||||
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;"));
|
||||
// fallthrough
|
||||
// case 1:
|
||||
|
|
|
@ -913,6 +913,7 @@ ChatMessage::Ptr ChatForm::chatMessageFromHistMessage(History::HistMessage const
|
|||
break;
|
||||
}
|
||||
default:
|
||||
qCritical() << "Invalid HistMessageContentType";
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
@ -1206,12 +1207,10 @@ void ChatForm::onExportChat()
|
|||
ToxPk authorPk(ToxId(it.sender).getPublicKey());
|
||||
QString author = getMsgAuthorDispName(authorPk, it.dispName);
|
||||
|
||||
if (it.content.getType() == HistMessageContentType::message) {
|
||||
buffer = buffer
|
||||
% QString{datestamp % '\t' % timestamp % '\t' % author % '\t'
|
||||
% it.content.asMessage() % '\n'};
|
||||
}
|
||||
}
|
||||
file.write(buffer.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user