File indexing completed on 2025-02-09 05:17:56

0001 /* SPDX-FileCopyrightText: 2023 Noah Davis <noahadvs@gmail.com>
0002  * SPDX-License-Identifier: LGPL-2.0-or-later
0003  */
0004 
0005 #pragma once
0006 
0007 #include <KConfigGroup>
0008 #include <KConfigSkeleton>
0009 
0010 /**
0011  * A small collection of functions to help prevent duplicating the implementations of custom code used by the Settings class.
0012  */
0013 
0014 /**
0015  * Gets a translated string, but the string is only translated once.
0016  * Mainly meant to keep file paths consistent.
0017  */
0018 inline QString onceTranslatedString(KConfigSkeleton *kcs, const QString &groupName, const char *entryName, const QString &localizedDefault)
0019 {
0020     auto config = kcs->sharedConfig();
0021     auto group = config->group(groupName);
0022     QString entry = group.readEntry(entryName);
0023     if (entry.isEmpty()) {
0024         entry = localizedDefault;
0025         group.writeEntry(entryName, entry);
0026         config->sync();
0027     }
0028     return entry;
0029 }