Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve graphical user interface #19

Merged
merged 9 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)

list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

project(mediacopier VERSION 2.1.0)
project(MediaCopier VERSION 2.1.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
33 changes: 30 additions & 3 deletions mediacopier-cli/source/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

#include "config.hpp"

#include <CLI/CLI.hpp>
#include <mediacopier/version.hpp>

#include <CLI/CLI.hpp>
#include <spdlog/spdlog.h>
#include <toml.hpp>

#include <mediacopier/version.hpp>

#include <filesystem>
#include <fstream>

Expand Down Expand Up @@ -96,3 +95,31 @@ void Config::finalize() noexcept
pattern = DEFAULT_PATTERN;
}
}

bool Config::validate() const noexcept
{
bool result = false;
if (pattern.empty()) {
spdlog::error("No pattern specified!");
result = true;
}
try {
if (fs::absolute(outputDir).empty() || !fs::is_directory(inputDir)) {
spdlog::error("Input directory does not exist!");
result = true;
}
} catch(const fs::filesystem_error& err) {
spdlog::error("Failed to validate input directory path: " + std::string{err.what()});
result = true;
}
try {
if (fs::absolute(outputDir).empty()) {
spdlog::error("No output directory specified");
result = true;
}
} catch(const fs::filesystem_error& err) {
spdlog::error("Failed to validate output directory path: " + std::string{err.what()});
result = true;
}
return result;
}
1 change: 1 addition & 0 deletions mediacopier-cli/source/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct Config
void loadPersistentConfig();
void storePersistentConfig() const;
void finalize() noexcept;
bool validate() const noexcept;

Command cmd = Command::Copy;
std::filesystem::path inputDir;
Expand Down
11 changes: 8 additions & 3 deletions mediacopier-cli/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ auto exec(const Config& config) -> void
});

spdlog::info("Checking input directory..");
auto reg = mc::FileRegister{config.outputDir, config.pattern};
auto fileRegister = mc::FileRegister{config.outputDir, config.pattern};
std::optional<fs::path> dest;

for (auto file : valid_media_files(config.inputDir)) {
Expand All @@ -69,7 +69,7 @@ auto exec(const Config& config) -> void
break;
}
try {
if ((dest = reg.add(file)).has_value()) {
if ((dest = fileRegister.add(file)).has_value()) {
spdlog::info("Processing: {} -> {}",
file->path().string(),
dest.value().string());
Expand All @@ -82,7 +82,7 @@ auto exec(const Config& config) -> void
}

spdlog::info("Removing duplicates in destination directory..");
reg.removeDuplicates();
fileRegister.removeDuplicates();

spdlog::info("Done");
std::signal(SIGINT, SIG_DFL);
Expand All @@ -98,6 +98,11 @@ int main(int argc, char *argv[])
config.loadPersistentConfig();
config.finalize();

if (config.validate()) {
spdlog::error("Invalid configuration");
return 1;
}

switch (config.cmd) {
case Config::Command::Copy:
exec<mediacopier::FileOperationCopyJpeg>(config);
Expand Down
8 changes: 7 additions & 1 deletion mediacopier-lib/source/operation_simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@
#include <mediacopier/file_info_video.hpp>
#include <spdlog/spdlog.h>

#include <chrono>
#include <thread>

namespace mediacopier {

auto FileOperationSimulate::dumpFilePaths(const AbstractFileInfo& file) const -> void
{
spdlog::info(m_destination.string() + " (from " + file.path().string() + ")");
spdlog::info("{} -> {}", file.path().string(), m_destination.string());
}

auto FileOperationSimulate::visit(const FileInfoImage& file) -> void
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
dumpFilePaths(file);
}

auto FileOperationSimulate::visit(const FileInfoImageJpeg& file) -> void
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
dumpFilePaths(file);
}

auto FileOperationSimulate::visit(const FileInfoVideo& file) -> void
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
dumpFilePaths(file);
}

Expand Down
5 changes: 5 additions & 0 deletions mediacopier-qt/lang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
You can update the translations via

```sh
linguist-qt5 mediacopier-qt/lang/lang_de.ts
```
31 changes: 15 additions & 16 deletions mediacopier-qt/lang/lang_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
<name>Command</name>
<message>
<location filename="../source/config.cpp" line="35"/>
<location filename="../source/config.cpp" line="36"/>
<source>Copy</source>
<translation>Kopieren</translation>
</message>
<message>
<location filename="../source/config.cpp" line="37"/>
<location filename="../source/config.cpp" line="38"/>
<location filename="../source/config.cpp" line="36"/>
<source>Move</source>
<translation>Verschieben</translation>
</message>
<message>
<location filename="../source/config.cpp" line="39"/>
<source>Simulate</source>
<translation>Simulation</translation>
</message>
</context>
<context>
<name>KMediaCopierJob</name>
Expand All @@ -45,41 +38,47 @@
<context>
<name>MediaCopierParamWidget</name>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="30"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="89"/>
<source>Operation</source>
<translation></translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="40"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="30"/>
<source>Input</source>
<translation>Quellverzeichnis</translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="50"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="76"/>
<source>Pattern</source>
<translation>Schema</translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="60"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="66"/>
<source>Output</source>
<translation>Zielverzeichnis</translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="73"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="83"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="139"/>
<source>Update</source>
<translatorcomment>Ändern</translatorcomment>
<translation>Ändern</translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="46"/>
<location filename="../source/gui/MediaCopierParamWidget.ui" line="53"/>
<source>...</source>
<translation></translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="../source/gui/MediaCopierParamWidget.cpp" line="98"/>
<location filename="../source/gui/MediaCopierParamWidget.cpp" line="132"/>
<source>Source folder</source>
<translation>Quellverzeichnis</translation>
</message>
<message>
<location filename="../source/gui/MediaCopierParamWidget.cpp" line="103"/>
<location filename="../source/gui/MediaCopierParamWidget.cpp" line="137"/>
<source>Destination folder</source>
<translation>Zielverzeichnis</translation>
</message>
Expand Down
68 changes: 28 additions & 40 deletions mediacopier-qt/source/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@
namespace fs = std::filesystem;

static constexpr const char* CONFIG_FILE = ".mediacopier";
static constexpr const char* DEFAULT_PATTERN = "%Y/%W/IMG_%Y%m%d_%H%M%S";

static const std::map<QString, Config::Command> commands = {
{"copy", Config::Command::COPY_JPEG},
{"move", Config::Command::MOVE_JPEG},
{"sim", Config::Command::SIMULATE}
{"copy", Config::Command::COPY},
{"move", Config::Command::MOVE}
};

static const std::map<Config::Command, QString> commandStrings = {
{Config::Command::COPY, QT_TRANSLATE_NOOP("Command", "Copy")},
{Config::Command::COPY_JPEG, QT_TRANSLATE_NOOP("Command", "Copy")},
{Config::Command::MOVE, QT_TRANSLATE_NOOP("Command", "Move")},
{Config::Command::MOVE_JPEG, QT_TRANSLATE_NOOP("Command", "Move")},
{Config::Command::SIMULATE, QT_TRANSLATE_NOOP("Command", "Simulate")}
{Config::Command::MOVE, QT_TRANSLATE_NOOP("Command", "Move")}
};

Config::Config(const QApplication& app)
Expand All @@ -45,52 +42,38 @@ Config::Config(const QApplication& app)

parser.setApplicationDescription(
app.applicationName() +
", Copyright (C) 2020-2023 Patrick Ziegler");

", Copyright (C) 2020-2024 Patrick Ziegler");
parser.addPositionalArgument(
"CMD", "Available commands: copy (default), move", "[CMD");
parser.addPositionalArgument(
"SRC", "Input directory", "[SRC");

parser.addPositionalArgument(
"DST", "Output directory", "[DST]]");

QCommandLineOption optCommand(
"c", "Available commands: copy (default), move, sim",
"command");

QCommandLineOption optPattern(
"f", "Pattern to be used for creating new filenames",
"pattern");

"DST", "Output directory", "[DST]]]");
QCommandLineOption optSlimGui(
"slim-gui", "Pattern to be used for creating new filenames");

QCommandLineOption optNoGui(
"no-gui", "Pattern to be used for creating new filenames");

parser.addOptions({optCommand, optPattern, optSlimGui, optNoGui});
parser.addOptions({optSlimGui, optNoGui});
parser.addVersionOption();
parser.addHelpOption();
parser.process(app);

if (parser.positionalArguments().length() > 0)
setInputDir(parser.positionalArguments().at(0));

if (parser.positionalArguments().length() > 1)
setOutputDir(parser.positionalArguments().at(1));

readConfigFile();

if (parser.isSet("f"))
setPattern(parser.value("f"));

if (parser.isSet("c"))
setCommand(parser.value("c"));

if (parser.isSet("slim-gui"))
m_ui = UI::SlimGui;
if (parser.positionalArguments().length() > 0) {
setCommand(parser.positionalArguments().at(0));
}
if (parser.positionalArguments().length() > 1) {
setInputDir(parser.positionalArguments().at(1));
}
if (parser.positionalArguments().length() > 2) {
setOutputDir(parser.positionalArguments().at(2));
readConfigFile();
}
if (parser.isSet("slim-gui")) {
m_guiType = GuiType::Slim;
}

if (parser.isSet("no-gui"))
m_ui = UI::NoGui;
m_pattern = DEFAULT_PATTERN;
}

bool Config::readConfigFile() noexcept
Expand Down Expand Up @@ -141,6 +124,11 @@ void Config::setPattern(const QString& pattern)
m_pattern = pattern.toStdString();
}

void Config::resetPattern()
{
m_pattern = DEFAULT_PATTERN;
}

void Config::setInputDir(const QString& inputDir)
{
m_inputDir = inputDir.toStdString();
Expand Down
21 changes: 9 additions & 12 deletions mediacopier-qt/source/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ class Config {
public:
enum class Command {
COPY,
MOVE,
COPY_JPEG,
MOVE_JPEG,
SIMULATE
MOVE
};

enum class UI {
FullGui,
SlimGui,
NoGui
enum class GuiType {
Full,
Slim,
};

Config(const QApplication& app);
Expand All @@ -44,21 +40,22 @@ class Config {
void setCommand(const Command& command);
void setCommand(const QString& command);
void setPattern(const QString& pattern);
void resetPattern();
void setInputDir(const QString& inputDir);
void setOutputDir(const QString& outputDir);

static const QString commandString(const Command& command);

const Command& command() const { return m_command; }
const UI& ui() const { return m_ui; }
const GuiType& guiType() const { return m_guiType; }
const std::string& pattern() const { return m_pattern; }
const std::filesystem::path& inputDir() const { return m_inputDir; }
const std::filesystem::path& outputDir() const { return m_outputDir; }

private:
Command m_command = Command::COPY_JPEG;
UI m_ui = UI::FullGui;
std::string m_pattern = "%Y/%W/IMG_%Y%m%d_%H%M%S";
Command m_command = Command::COPY;
GuiType m_guiType = GuiType::Full;
std::string m_pattern;
std::filesystem::path m_inputDir;
std::filesystem::path m_outputDir;
};
Loading
Loading