summaryrefslogtreecommitdiff
path: root/src/filerenamer.cpp
diff options
context:
space:
mode:
authorJeremy Rimpo <jrim@rimpo.org>2019-08-02 01:49:33 -0500
committerGitHub <noreply@github.com>2019-08-02 01:49:33 -0500
commitcff526415d781cb8a7761961ae2bd1fb6775c376 (patch)
treecf5ff4f0d7bdd3767155a8a3e251201861284f89 /src/filerenamer.cpp
parentbdf45aea69ab7df0b01eb87cc80a2641ea4261d0 (diff)
parente4cf2c314d6397c5d73bcf567d4420171238bd29 (diff)
Merge pull request #807 from isanae/logging-rework
Logging rework
Diffstat (limited to 'src/filerenamer.cpp')
-rw-r--r--src/filerenamer.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/filerenamer.cpp b/src/filerenamer.cpp
index c5c6782b..a97d7742 100644
--- a/src/filerenamer.cpp
+++ b/src/filerenamer.cpp
@@ -1,13 +1,16 @@
#include "filerenamer.h"
+#include <log.h>
#include <QMessageBox>
#include <QFileInfo>
+using namespace MOBase;
+
FileRenamer::FileRenamer(QWidget* parent, QFlags<RenameFlags> flags)
: m_parent(parent), m_flags(flags)
{
// sanity check for flags
if ((m_flags & (HIDE|UNHIDE)) == 0) {
- qCritical("renameFile() missing hide flag");
+ log::error("renameFile() missing hide flag");
// doesn't really matter, it's just for text
m_flags = HIDE;
}
@@ -15,10 +18,10 @@ FileRenamer::FileRenamer(QWidget* parent, QFlags<RenameFlags> flags)
FileRenamer::RenameResults FileRenamer::rename(const QString& oldName, const QString& newName)
{
- qDebug().nospace() << "renaming " << oldName << " to " << newName;
+ log::debug("renaming {} to {}", oldName, newName);
if (QFileInfo(newName).exists()) {
- qDebug().nospace() << newName << " already exists";
+ log::debug("{} already exists", newName);
// target file already exists, confirm replacement
auto answer = confirmReplace(newName);
@@ -26,24 +29,25 @@ FileRenamer::RenameResults FileRenamer::rename(const QString& oldName, const QSt
switch (answer) {
case DECISION_SKIP: {
// user wants to skip this file
- qDebug().nospace() << "skipping " << oldName;
+ log::debug("skipping {}", oldName);
return RESULT_SKIP;
}
case DECISION_REPLACE: {
- qDebug().nospace() << "removing " << newName;
+ log::debug("removing {}", newName);
+
// user wants to replace the file, so remove it
if (!QFile(newName).remove()) {
- qWarning().nospace() << "failed to remove " << newName;
+ log::warn("failed to remove '{}'", newName);
// removal failed, warn the user and allow canceling
if (!removeFailed(newName)) {
- qDebug().nospace() << "canceling " << oldName;
+ log::debug("canceling {}", oldName);
// user wants to cancel
return RESULT_CANCEL;
}
// ignore this file and continue on
- qDebug().nospace() << "skipping " << oldName;
+ log::debug("skipping {}", oldName);
return RESULT_SKIP;
}
@@ -53,7 +57,7 @@ FileRenamer::RenameResults FileRenamer::rename(const QString& oldName, const QSt
case DECISION_CANCEL: // fall-through
default: {
// user wants to stop
- qDebug().nospace() << "canceling";
+ log::debug("canceling");
return RESULT_CANCEL;
}
}
@@ -62,22 +66,22 @@ FileRenamer::RenameResults FileRenamer::rename(const QString& oldName, const QSt
// target either didn't exist or was removed correctly
if (!QFile::rename(oldName, newName)) {
- qWarning().nospace() << "failed to rename " << oldName << " to " << newName;
+ log::warn("failed to rename '{}' to '{}'", oldName, newName);
// renaming failed, warn the user and allow canceling
if (!renameFailed(oldName, newName)) {
// user wants to cancel
- qDebug().nospace() << "canceling";
+ log::debug("canceling");
return RESULT_CANCEL;
}
// ignore this file and continue on
- qDebug().nospace() << "skipping " << oldName;
+ log::debug("skipping {}", oldName);
return RESULT_SKIP;
}
// everything worked
- qDebug().nospace() << "successfully renamed " << oldName << " to " << newName;
+ log::debug("successfully renamed {} to {}", oldName, newName);
return RESULT_OK;
}
@@ -85,12 +89,12 @@ FileRenamer::RenameDecision FileRenamer::confirmReplace(const QString& newName)
{
if (m_flags & REPLACE_ALL) {
// user wants to silently replace all
- qDebug().nospace() << "user has selected replace all";
+ log::debug("user has selected replace all");
return DECISION_REPLACE;
}
else if (m_flags & REPLACE_NONE) {
// user wants to silently skip all
- qDebug().nospace() << "user has selected replace none";
+ log::debug("user has selected replace none");
return DECISION_SKIP;
}
@@ -114,28 +118,28 @@ FileRenamer::RenameDecision FileRenamer::confirmReplace(const QString& newName)
switch (answer) {
case QMessageBox::Yes:
- qDebug().nospace() << "user wants to replace";
+ log::debug("user wants to replace");
return DECISION_REPLACE;
case QMessageBox::No:
- qDebug().nospace() << "user wants to skip";
+ log::debug("user wants to skip");
return DECISION_SKIP;
case QMessageBox::YesToAll:
- qDebug().nospace() << "user wants to replace all";
+ log::debug("user wants to replace all");
// remember the answer
m_flags |= REPLACE_ALL;
return DECISION_REPLACE;
case QMessageBox::NoToAll:
- qDebug().nospace() << "user wants to replace none";
+ log::debug("user wants to replace none");
// remember the answer
m_flags |= REPLACE_NONE;
return DECISION_SKIP;
case QMessageBox::Cancel: // fall-through
default:
- qDebug().nospace() << "user wants to cancel";
+ log::debug("user wants to cancel");
return DECISION_CANCEL;
}
}
@@ -155,12 +159,12 @@ bool FileRenamer::removeFailed(const QString& name)
if (answer == QMessageBox::Cancel) {
// user wants to stop
- qDebug().nospace() << "user wants to cancel";
+ log::debug("user wants to cancel");
return false;
}
// skip this one and continue
- qDebug().nospace() << "user wants to skip";
+ log::debug("user wants to skip");
return true;
}
@@ -179,11 +183,11 @@ bool FileRenamer::renameFailed(const QString& oldName, const QString& newName)
if (answer == QMessageBox::Cancel) {
// user wants to stop
- qDebug().nospace() << "user wants to cancel";
+ log::debug("user wants to cancel");
return false;
}
// skip this one and continue
- qDebug().nospace() << "user wants to skip";
+ log::debug("user wants to skip");
return true;
}