Skip to content

Commit

Permalink
Fixed even more code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Nov 6, 2023
1 parent 6ae5e24 commit 46aa939
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 69 deletions.
9 changes: 4 additions & 5 deletions app/ui/FileDialog/filedialogbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ void FileDialogBackend::updateFileList()
isLoading(true);

m_currentFuture = File::listAsync(currentDir(), !folderMode(), true);
m_currentFuture.then([this](FileListResult &&result) { onFileListReceived(std::move(result)); })
.onCanceled([this]() {
qCDebug(gmFileDialog()) << "file list update was cancelled.";
isLoading(false);
});
m_currentFuture.then([this](const FileListResult &result) { onFileListReceived(result); }).onCanceled([this]() {
qCDebug(gmFileDialog()) << "file list update was cancelled.";
isLoading(false);
});
}

void FileDialogBackend::clearFileList()
Expand Down
7 changes: 3 additions & 4 deletions src/addons/addonrepositorymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ auto AddonRepositoryManager::parseRepositoryData(const QByteArray &data) -> std:
auto release = getNewestCompatibleRelease(entry["releases"_L1].toArray());
if (release.isEmpty()) continue;

result.emplace_back(AddonReleaseInfo(entry["id"_L1].toString(), entry["name"_L1].toString(),
entry["name_short"_L1].toString(), release["version"_L1].toString(),
entry["author"_L1].toString(), entry["description"_L1].toString(),
release["download"_L1].toString()));
result.emplace_back(entry["id"_L1].toString(), entry["name"_L1].toString(), entry["name_short"_L1].toString(),
release["version"_L1].toString(), entry["author"_L1].toString(),
entry["description"_L1].toString(), release["download"_L1].toString());
}

return result;
Expand Down
4 changes: 1 addition & 3 deletions src/filesystem/fileaccesslocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ auto FileAccessLocal::move(const QString &oldPath, const QString &newPath) -> Fi
}
}

QFile f(oldPath);

if (!f.rename(newPath))
if (QFile f(oldPath); !f.rename(newPath))
{
auto errorMessage =
u"Could not move %1 to %2: %3 %4"_s.arg(oldPath, newPath, QString::number(f.error()), f.errorString());
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/fileaccesslocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FileAccessLocal : public FileAccess
{
public:
FileAccessLocal() = default;
virtual ~FileAccessLocal() = default;
~FileAccessLocal() override = default;
Q_DISABLE_COPY_MOVE(FileAccessLocal)

auto getDataAsync(const QString &path, bool allowCache) -> QFuture<FileDataResult> override;
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/fileaccessnextcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileAccessNextcloud : public FileAccess
{
public:
explicit FileAccessNextcloud(Services::NextCloud &nextcloud);
virtual ~FileAccessNextcloud() = default;
~FileAccessNextcloud() override = default;
Q_DISABLE_COPY_MOVE(FileAccessNextcloud)

auto getDataAsync(const QString &path, bool allowCache) -> QFuture<FileDataResult> override;
Expand Down
2 changes: 1 addition & 1 deletion src/services/nextcloud/nextcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void NextCloud::disconnectService()

SettingsManager::setPassword(loginName(), ""_L1, serviceName());

disconnect();
connected(false);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/services/rest/restserviceconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ auto RESTServiceConnector::enqueueRequest(RestRequest &&request, QPromise<RestRe
auto future = reply.future();
request.id(m_nextQueueId);
m_nextQueueId++;
m_requestQueue.emplace(std::make_pair(std::move(reply), std::move(request)));
m_requestQueue.emplace(std::move(reply), std::move(request));

// try to dispatch request
dequeueRequests();
Expand All @@ -154,7 +154,7 @@ auto RESTServiceConnector::markRequestActive(RestRequest &&request, QPromise<Res
{
auto id = request.id();
auto future = reply.future();
m_activeRequests.try_emplace(id, std::make_pair(std::move(reply), std::move(request)));
m_activeRequests.try_emplace(id, std::move(reply), std::move(request));
return future;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/rest/restserviceconnectorlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected slots:
auto makeRequestor() -> O2Requestor *;
void sendRequest(RestRequest &&container, QPromise<RestReply> &&promise) override;

[[nodiscard]] virtual auto getAccessToken() -> QString override;
[[nodiscard]] auto getAccessToken() -> QString override;
void refreshAccessToken(bool /*updateAuthentication*/ = false) override;
};

Expand Down
6 changes: 0 additions & 6 deletions src/services/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ Service::Service(const QString &name, QObject *parent)
connect(this, &Service::connectedChanged, this, &Service::onConnectedChanged);
}

void Service::disconnect()
{
SettingsManager::instance()->set(u"connected"_s, false, a_serviceName);
connected(false);
}

void Service::updateStatus(Status::Type type, const QString &message)
{
a_status->type(type);
Expand Down
3 changes: 0 additions & 3 deletions src/services/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public slots:
virtual void connectService() = 0;
virtual void disconnectService() = 0;

protected:
void disconnect();

protected slots:
void updateStatus(Status::Type type, const QString &message);

Expand Down
8 changes: 4 additions & 4 deletions src/services/spotify/api/albumapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ auto AlbumAPI::getAlbum(const QString &id) -> QFuture<SpotifyAlbum>
query.addQueryItem(u"market"_s, u"from_token"_s);
url.setQuery(query);

const auto callback = [this](RestReply &&reply) {
const auto callback = [this](const RestReply &reply) {
if (reply.hasError())
{
qCWarning(gmSpotifyAlbums()) << "getAlbum():" << reply.errorText();
Expand Down Expand Up @@ -65,7 +65,7 @@ auto AlbumAPI::getAlbumTracks(const QString &id) -> QFuture<SpotifyTrackList>
query.addQueryItem(u"market"_s, u"from_token"_s);
url.setQuery(query);

auto callback = [this](RestReply &&reply) -> QFuture<SpotifyTrackList> {
auto callback = [this](const RestReply &reply) -> QFuture<SpotifyTrackList> {
if (reply.hasError())
{
qCWarning(gmSpotifyAlbums()) << reply.errorText();
Expand All @@ -89,7 +89,7 @@ auto AlbumAPI::getAlbumTracks(SpotifyAlbum &&album) -> QFuture<SpotifyAlbum>

const QUrl url(album.tracks.next);

const auto callback = [this, album](RestReply &&reply) mutable {
const auto callback = [this, album](const RestReply &reply) mutable {
if (reply.hasError())
{
qCWarning(gmSpotifyAlbums()) << reply.errorText();
Expand All @@ -111,7 +111,7 @@ auto AlbumAPI::getAlbumTracks(SpotifyTrackList &&tracklist) -> QFuture<SpotifyTr
{
const QUrl url(tracklist.next);

const auto callback = [this, tracklist](RestReply &&reply) mutable {
const auto callback = [this, tracklist](const RestReply &reply) mutable {
if (reply.hasError())
{
qCWarning(gmSpotifyAlbums()) << reply.errorText();
Expand Down
7 changes: 3 additions & 4 deletions src/services/spotify/api/playerapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ auto PlayerAPI::play(const QString &deviceId, const QJsonObject &body) const ->

auto PlayerAPI::play(const QString &uri) const -> QFuture<RestReply>
{
const auto type = SpotifyUtils::getUriType(uri);

if (type == SpotifyUtils::SpotifyType::Track || type == SpotifyUtils::SpotifyType::Episode)
if (const auto type = SpotifyUtils::getUriType(uri);
type == SpotifyUtils::SpotifyType::Track || type == SpotifyUtils::SpotifyType::Episode)
{
return play(makePlayBody(u""_s, {uri}, -1, -1));
}
Expand Down Expand Up @@ -180,7 +179,7 @@ auto PlayerAPI::getState(const QStringList &additionalTypes, const QString &mark

url.setQuery(query);

const auto callback = [](RestReply &&reply) -> QFuture<SpotifyPlaybackState> {
const auto callback = [](const RestReply &reply) -> QFuture<SpotifyPlaybackState> {
if (reply.hasError())
{
qCWarning(gmSpotifyPlayer()) << reply.errorText();
Expand Down
5 changes: 3 additions & 2 deletions src/tools/audio/audiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ AudioTool::AudioTool(QQmlEngine *engine, QObject *parent)
});
connect(&mprisManager, &MprisManager::next, this, [this]() { next(); });
connect(&mprisManager, &MprisManager::previous, this, [this]() { again(); });
connect(&mprisManager, &MprisManager::changeVolume, this, [this](double volume) { setMusicVolume(volume); });
connect(&mprisManager, &MprisManager::changeVolume, this,
[this](double volume) { setMusicVolume(static_cast<int>(volume)); });
#endif
}

Expand Down Expand Up @@ -300,7 +301,7 @@ auto AudioTool::playlistQml() -> QQmlListProperty<AudioFile>
* @brief Get index of current song in playlist
* @return Index as integer
*/
auto AudioTool::index() const -> int
auto AudioTool::index() const -> qsizetype
{
if (m_musicElementType == AudioElement::Type::Music)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/audio/audiotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AudioTool : public AbstractTool
{
return metaDataReader.metaData();
}
[[nodiscard]] auto index() const -> int;
[[nodiscard]] auto index() const -> qsizetype;
[[nodiscard]] auto playlistQml() -> QQmlListProperty<AudioFile>;

public slots:
Expand Down
4 changes: 2 additions & 2 deletions src/tools/audio/editor/audioeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace Services;

Q_LOGGING_CATEGORY(gmAudioEditor, "gm.audio.editor")

AudioEditor::AudioEditor(QQmlEngine *engine, QObject *parent)
AudioEditor::AudioEditor(const QQmlEngine *engine, QObject *parent)
: AbstractTool(parent), m_addonElementManager(this), m_audioExporter(this), m_fileBrowser(this),
m_unsplashParser(engine, this), m_fileModel(this)
{
Expand Down Expand Up @@ -99,7 +99,7 @@ auto AudioEditor::projectIndex() const -> int
{
if (!m_currentProject || a_projects.isEmpty()) return -1;

return a_projects.indexOf(m_currentProject);
return static_cast<int>(a_projects.indexOf(m_currentProject));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tools/audio/editor/audioeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AudioEditor : public AbstractTool
AUTO_PROPERTY_VAL2(bool, isSaved, true)

public:
explicit AudioEditor(QQmlEngine *engine, QObject *parent = nullptr);
explicit AudioEditor(const QQmlEngine *engine, QObject *parent = nullptr);

[[nodiscard]] auto exporter() -> AudioExporter *
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/audio/editor/audioeditorfilebrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void AudioEditorFileBrowser::removeElement(const QStringList &path)
{
foreach (auto *element, m_fileModel.elements())
{
auto *file = qobject_cast<AudioEditorFile *>(element);
const auto *file = qobject_cast<AudioEditorFile *>(element);

if ((file->path() == path) ||
FileUtils::dirFromFolders(file->path()).startsWith(FileUtils::dirFromFolders(path)))
Expand Down
3 changes: 1 addition & 2 deletions src/tools/audio/project/audioscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ auto AudioScenario::moveScenario(AudioScenario *scenario, int steps) -> bool
}

const auto from = a_scenarios.indexOf(scenario);
const auto to = from + steps;

if (Utils::isInBounds(a_scenarios, to))
if (const auto to = from + steps; Utils::isInBounds(a_scenarios, to))
{
a_scenarios.move(from, to);
emit scenariosChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/characters/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Character : public QObject

signals:
void fileListLoaded(const QList<CharacterFile *> &files);
void fileDataLoaded(int index, const QByteArray &data);
void fileDataLoaded(qsizetype index, const QByteArray &data);

private:
QList<CharacterFile *> m_files;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/characters/viewers/characterimageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CharacterImageViewer::onCharacterFileListLoaded(const QList<CharacterFile *
if (!m_categories.isEmpty()) setCurrentCategory(0);
}

void CharacterImageViewer::onCharacterFileDataLoaded(int index, const QByteArray &data)
void CharacterImageViewer::onCharacterFileDataLoaded(qsizetype index, const QByteArray &data)
{
qCDebug(gmCharactersImageViewer()) << "File data was loaded.";

Expand All @@ -62,7 +62,7 @@ void CharacterImageViewer::onCharacterFileDataLoaded(int index, const QByteArray
break;

case 1: // PDF
loadPDF(index, data);
loadPDF(static_cast<int>(index), data);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/characters/viewers/characterimageviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ class CharacterImageViewer : public CharacterViewer

private slots:
void onCharacterFileListLoaded(const QList<CharacterFile *> &files);
void onCharacterFileDataLoaded(int index, const QByteArray &data);
void onCharacterFileDataLoaded(qsizetype index, const QByteArray &data);
};
24 changes: 12 additions & 12 deletions src/tools/maps/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Map::Map(QObject *parent) : QObject(parent), m_markers(this)
Map::Map(const QString &name, const QString &path, QObject *parent)
: QObject(parent), a_name(name), a_path(path), m_markers(this)
{
Files::File::getDataAsync(path).then([this](Files::FileDataResult &&result) {
Files::File::getDataAsync(path).then([this](const Files::FileDataResult &result) {
if (!result.success()) return;

QPixmap pixmap;
Expand Down Expand Up @@ -52,15 +52,15 @@ void Map::saveMarkers() const
void Map::loadMarkers()
{
const auto filePath = path() + ".json";
Files::File::checkAsync(filePath).then([this, filePath](Files::FileCheckResult &&result) {
if (!result.success() || !result.exists()) return;
Files::File::checkAsync(filePath).then([this, filePath](const Files::FileCheckResult &checkResult) {
if (!checkResult.success() || !checkResult.exists()) return;

Files::File::getDataAsync(filePath).then([this](Files::FileDataResult &&result) {
if (!result.success()) return;
Files::File::getDataAsync(filePath).then([this](const Files::FileDataResult &dataResult) {
if (!dataResult.success()) return;

auto markers = QJsonDocument::fromJson(result.data()).object()["markers"_L1].toArray();
auto markers = QJsonDocument::fromJson(dataResult.data()).object()["markers"_L1].toArray();

for (const auto &marker : markers)
foreach (const auto &marker, markers)
{
addMarker(new MapMarker(marker.toObject(), this));
}
Expand Down Expand Up @@ -107,7 +107,7 @@ void MapCategory::loadMaps()

const auto path = FileUtils::fileInDir(name(), SettingsManager::getPath(u"maps"_s));

Files::File::listAsync(path, true, false).then([this, path](Files::FileListResult &&result) {
Files::File::listAsync(path, true, false).then([this, path](const Files::FileListResult &result) {
if (!result.success()) return;

foreach (const auto &file, result.files())
Expand Down Expand Up @@ -135,7 +135,7 @@ void MapListModel::insert(QObject *item)
endInsertRows();
}

void MapListModel::remove(QObject *item)
void MapListModel::remove(const QObject *item)
{
for (int i = 0; i < m_items.size(); ++i)
{
Expand Down Expand Up @@ -165,12 +165,12 @@ void MapListModel::clear()
}
}

void MapListModel::setElements(QList<Map *> elements)
void MapListModel::setElements(const QList<Map *> &elements)
{
clear();

for (int i = elements.size() - 1; i > -1; i--)
for (auto i = elements.size() - 1; i > -1; i--)
{
insert(elements[i]);
insert(elements.at(i));
}
}
4 changes: 2 additions & 2 deletions src/tools/maps/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MapListModel : public QAbstractListModel
return static_cast<int>(m_items.size());
}

void setElements(QList<Map *> elements);
void setElements(const QList<Map *> &elements);
void clear();

[[nodiscard]] auto elements() const -> QList<Map *>
Expand All @@ -83,7 +83,7 @@ class MapListModel : public QAbstractListModel

public slots:
void insert(QObject *item);
void remove(QObject *item);
void remove(const QObject *item);

protected:
[[nodiscard]] auto roleNames() const -> QHash<int, QByteArray> override;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/notes/markdownhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void MarkdownHighlighter::applyRegexMatch(const QString &text, const QString &re
{
auto match = iterator.next();

for (auto i = match.capturedStart(group); i < match.capturedEnd(group); i++)
for (auto i = static_cast<int>(match.capturedStart(group)); i < match.capturedEnd(group); i++)
{
setFormat(static_cast<int>(i), 1, combineFormats(format(i), charFormat));
setFormat(i, 1, combineFormats(format(i), charFormat));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/notes/notessaveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void NotesSaveLoad::loadPages()

qCDebug(gmNotesSaveLoad()) << "Loading pages in" << directory;

Files::File::listAsync(directory, true, false).then([this, chapter](Files::FileListResult &&result) {
Files::File::listAsync(directory, true, false).then([this, chapter](const Files::FileListResult &result) {
if (!chapter) return;
buildPages(result.files(), *chapter);
});
Expand Down
2 changes: 1 addition & 1 deletion src/tools/notes/notestool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void NotesTool::encrypt()
/**
* Export the current page as PDF document
*/
void NotesTool::exportPdf()
void NotesTool::exportPdf() const
{
if (editMode() || !m_currentPage || !m_qmlTextDoc) return;

Expand Down
Loading

0 comments on commit 46aa939

Please sign in to comment.