core: make getCloudURL() return an std::string

Let's use std::string in the core. Notably, I'd like to make
the numerous main() functions mostly independent of Qt. Some
things will have to remain, such as argument parsing, of course.

This changes the API: instead of returning an error code and
taking a pointer to the actual return-value, return an
std::optional<std::string>> that is set if the function succeeds.

Returning an empty string in the error case might be simpler,
but oh well...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-24 22:05:28 +01:00 committed by bstoeger
parent 8e106b0449
commit c6cd10a43f
7 changed files with 54 additions and 48 deletions

View file

@ -567,11 +567,11 @@ void QMLManager::finishSetup()
// Initialize cloud credentials.
git_local_only = !prefs.cloud_auto_sync;
QString url;
std::optional<std::string> url;
if (!qPrefCloudStorage::cloud_storage_email().isEmpty() &&
!qPrefCloudStorage::cloud_storage_password().isEmpty() &&
getCloudURL(url) == 0) {
openLocalThenRemote(url);
(url = getCloudURL())) {
openLocalThenRemote(QString::fromStdString(*url));
} else if (!existing_filename.empty() &&
qPrefCloudStorage::cloud_verification_status() != qPrefCloudStorage::CS_UNKNOWN) {
rememberOldStatus();
@ -781,13 +781,13 @@ void QMLManager::deleteAccount()
void QMLManager::loadDivesWithValidCredentials()
{
QString url;
if (getCloudURL(url)) {
auto url = getCloudURL();
if (!url) {
setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(consumeError()) + END_FONT);
revertToNoCloudIfNeeded();
return;
}
QByteArray fileNamePrt = QFile::encodeName(url);
QByteArray fileNamePrt = QFile::encodeName(QString::fromStdString(*url));
struct git_info info;
int error;