Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(db): File transfer history review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sphaerophoria committed Dec 6, 2018
1 parent 8427be6 commit 25005c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/chatlog/content/filetransferwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, ToxFile file)
lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED;
updateWidget(file);

// preview
setFixedHeight(64);
}

Expand Down Expand Up @@ -340,6 +339,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file)
setBackgroundColor(Style::getColor(Style::Green), true);
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand Down Expand Up @@ -372,6 +372,7 @@ void FileTransferWidget::updateWidgetText(ToxFile const& file)
case ToxFile::FINISHED:
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand All @@ -396,6 +397,7 @@ void FileTransferWidget::updatePreview(ToxFile const& file)
showPreview(file.filePath);
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand Down Expand Up @@ -442,6 +444,7 @@ void FileTransferWidget::updateFileProgress(ToxFile const& file)
break;
}
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand All @@ -464,6 +467,7 @@ void FileTransferWidget::updateSignals(ToxFile const& file)
case ToxFile::TRANSMITTING:
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand Down Expand Up @@ -532,6 +536,7 @@ void FileTransferWidget::setupButtons(ToxFile const& file)

break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 14 additions & 6 deletions src/persistence/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ 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, "
"file_path, file_name, file_hash, file_size, direction, file_state) "
"VALUES (%1, ?, ?, ?, ?, %2, %3, %4);")
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)
.arg(data.size)
.arg(static_cast<int>(data.direction))
Expand All @@ -307,15 +308,17 @@ 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;
fileInfo.fileId = dbId;
}
}

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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ ChatMessage::Ptr ChatForm::chatMessageFromHistMessage(History::HistMessage const
break;
}
default:
qCritical() << "Invalid HistMessageContentType";
assert(false);
}

Expand Down Expand Up @@ -1206,11 +1207,9 @@ 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'};
}
buffer = buffer
% QString{datestamp % '\t' % timestamp % '\t' % author % '\t'
% it.content.asMessage() % '\n'};
}
file.write(buffer.toUtf8());
file.close();
Expand Down

0 comments on commit 25005c5

Please sign in to comment.