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

@ -46,25 +46,23 @@ extern "C" void print_version()
extern "C" void print_files()
{
struct git_info info;
const char *filename;
std::optional<std::string> filename;
printf("\nFile locations:\n\n");
printf("Cloud email:%s\n", prefs.cloud_storage_email);
if (!empty_string(prefs.cloud_storage_email) && !empty_string(prefs.cloud_storage_password)) {
filename = cloud_url();
is_git_repository(filename, &info);
} else {
/* strdup so the free below works in either case */
filename = strdup("No valid cloud credentials set.\n");
filename = getCloudURL();
if (filename)
is_git_repository(filename->c_str(), &info);
}
if (!filename)
filename = std::string("No valid cloud credentials set.\n");
if (!info.localdir.empty()) {
printf("Local git storage: %s\n", info.localdir.c_str());
} else {
printf("Unable to get local git directory\n");
}
printf("Cloud URL: %s\n", filename);
free((void *)filename);
printf("Cloud URL: %s\n", filename->c_str());
char *tmp = hashfile_name_string();
printf("Image filename table: %s\n", tmp);
free(tmp);