Skip to content
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
48 changes: 3 additions & 45 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
set(BIN_NAME ${PROJECT_NAME} CACHE STRING "Executable name")

set(PROJECT_SOURCES
application.cc
application.hh
dragarea.cc
dragarea.hh
droparea.cc
droparea.hh
main.cc
window.cc
window.hh
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${BIN_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
add_executable(${BIN_NAME}
${PROJECT_SOURCES}
)
endif()

target_link_libraries(
${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
)
target_compile_definitions(
${BIN_NAME} PRIVATE
DRAGDROP_NAME="${BIN_NAME}"
DRAGDROP_VERSION="${PROJECT_VERSION}"
)
target_compile_options(
${BIN_NAME} PRIVATE
$<$<C_COMPILER_ID:MSVC>:/W3>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall>
)

install(TARGETS ${BIN_NAME})

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(qt-cmake-test)
endif()
add_subdirectory(common)
add_subdirectory(dragdrop)
add_subdirectory(dragdrop-dialog)
62 changes: 0 additions & 62 deletions src/application.cc

This file was deleted.

28 changes: 0 additions & 28 deletions src/application.hh

This file was deleted.

22 changes: 22 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_path(GET CMAKE_CURRENT_LIST_DIR FILENAME TARGET_NAME)
file(GLOB SRC CONFIGURE_DEPENDS "*.cc" "*.hh")

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_library(${TARGET_NAME} STATIC ${SRC})
else()
add_library(${TARGET_NAME} ${SRC})
endif()

target_link_libraries(${TARGET_NAME}
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
)
target_include_directories(${TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_options(${TARGET_NAME}
PRIVATE
$<$<C_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wpedantic>
)
58 changes: 58 additions & 0 deletions src/common/fileparser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright © 2025 Fern Zapata
* This file is under the terms of the GNU GPL version 3, or (at your
* option) any later version. If you didn't receive a copy of the GPL
* along with this file, see <https://www.gnu.org/licenses/>. */

#include "fileparser.hh"

namespace DragDrop {

FileParser::FileParser(QIODevice* device, QObject* parent)
: QObject(parent)
, mDevice(device)
{
connect(mDevice, &QIODevice::readyRead, this, &FileParser::onRead);
}

static auto decodeString(QCborStreamReader& reader)
{
QString str;
QCborStreamReader::StringResult<QString> r;
while ((r = reader.readString()).status == QCborStreamReader::Ok) {
str += r.data;
}
if (r.status == QCborStreamReader::Error) {
str.clear();
}
return str;
}

void FileParser::handleStream()
{
switch (mReader.type()) {
case QCborStreamReader::ByteArray:
case QCborStreamReader::String:
emit parsedURL(decodeString(mReader));
break;
case QCborStreamReader::Array:
mReader.enterContainer();
while (not mReader.lastError() and mReader.hasNext()) {
handleStream();
}
if (not mReader.lastError()) {
mReader.leaveContainer();
}
break;
default:
mReader.next();
}
}

void FileParser::onRead()
{
mReader.setDevice(mDevice);
handleStream();
emit finished();
}

}; // namespace DragDrop
36 changes: 36 additions & 0 deletions src/common/fileparser.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright © 2025 Fern Zapata
* This file is under the terms of the GNU GPL version 3, or (at your
* option) any later version. If you didn't receive a copy of the GPL
* along with this file, see <https://www.gnu.org/licenses/>. */

#pragma once

#include <QCborStreamReader>
#include <QFileInfo>
#include <QIODevice>
#include <QUrl>

namespace DragDrop {

class FileParser : public QObject
{
Q_OBJECT

public:
FileParser(QIODevice* device, QObject* parent = nullptr);

signals:
void parsedURL(QUrl url);
void finished();

private:
QIODevice* mDevice;
QCborStreamReader mReader;

void handleStream();

private slots:
void onRead();
};

}; // namespace DragDrop
31 changes: 31 additions & 0 deletions src/dragdrop-dialog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_path(GET CMAKE_CURRENT_LIST_DIR FILENAME BIN_NAME)
file(GLOB SRC CONFIGURE_DEPENDS "*.cc" "*.hh" "*.ui")

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${BIN_NAME} MANUAL_FINALIZATION ${SRC})
else()
add_executable(${BIN_NAME} ${SRC})
endif()

target_link_libraries(${BIN_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
)
target_compile_definitions(${BIN_NAME}
PRIVATE
DRAGDROP_NAME="${BIN_NAME}"
DRAGDROP_VERSION="${PROJECT_VERSION}"
)
target_compile_options(${BIN_NAME}
PRIVATE
$<$<C_COMPILER_ID:MSVC>:/W3>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall>
)

install(TARGETS ${BIN_NAME}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(${BIN_NAME})
endif()
32 changes: 32 additions & 0 deletions src/dragdrop-dialog/application.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright © 2022-2025 Fern Zapata
* This file is under the terms of the GNU GPL ver. 3, or (at your
* option) any later version. If a copy of the GPL wasn't included
* along with this file, see <https://www.gnu.org/licenses/>. */

#include "application.hh"
#include <QFileInfo>

namespace DragDrop {

Application::Application(int& argc, char** argv)
: QApplication(argc, argv)
{
mArgs.addOptions({
{{"o", "once"}, ""},
});
mArgs.process(*this);
}

auto Application::exec() -> int
{
for (auto const& name : mArgs.positionalArguments()) {
mWindow.addFile(QFileInfo(name));
}

mWindow.setOnce(mArgs.isSet(QStringLiteral("once")));
mWindow.show();

return QApplication::exec();
}

}; // namespace DragDrop
27 changes: 27 additions & 0 deletions src/dragdrop-dialog/application.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright © 2022-2025 Fern Zapata
* This file is under the terms of the GNU GPL ver. 3, or (at your
* option) any later version. If a copy of the GPL wasn't included
* along with this file, see <https://www.gnu.org/licenses/>. */

#pragma once

#include "window.hh"
#include <QApplication>
#include <QCommandLineParser>

namespace DragDrop {

class Application : public QApplication
{
Q_OBJECT

public:
Application(int& argc, char** argv);
auto exec() -> int;

private:
QCommandLineParser mArgs;
Window mWindow;
};

}; // namespace DragDrop
Loading