diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b7880e..4c11b52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,7 @@ add_subdirectory(src/delete) add_subdirectory(src/locate) add_subdirectory(src/navigate) add_subdirectory(src/tag) +add_subdirectory(src/gui) #Tests if (BUILD_TESTING) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt new file mode 100644 index 0000000..0b445a6 --- /dev/null +++ b/src/gui/CMakeLists.txt @@ -0,0 +1,35 @@ +project(${bare_name}-gui CXX) + +set(CMAKE_AUTOMOC ON) +find_package(Qt5Qml 5.1 REQUIRED) +find_package(Qt5Widgets 5.1 REQUIRED) + +add_executable(${PROJECT_NAME} + main.cpp + searcher.cpp +) + +target_include_directories(${PROJECT_NAME} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. + PRIVATE ${CMAKE_SOURCE_DIR}/lib/glob2regex/include +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE ${bare_name}-if + PRIVATE ${bare_name}-machinery + PRIVATE ${bare_name}-common + PRIVATE Qt5::Qml + PRIVATE Qt5::Widgets + PRIVATE glob2regex +) + +string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}") +target_compile_definitions(${PROJECT_NAME} + PRIVATE ACTION_NAME="${ACTION_NAME}" +) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION lib + RUNTIME DESTINATION ${ACTIONS_PATH_INSTALL} + ARCHIVE DESTINATION lib/static +) diff --git a/src/gui/main.cpp b/src/gui/main.cpp new file mode 100644 index 0000000..e3a19d4 --- /dev/null +++ b/src/gui/main.cpp @@ -0,0 +1,47 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "searcher.hpp" +#include "dindexerConfig.h" +#include "dindexer-common/settings.hpp" +#include +#include +#include +#include +#include + +int main (int parArgc, char* parArgv[]) { + QApplication app(parArgc, parArgv); + QQmlApplicationEngine engine; + engine.load(QUrl::fromLocalFile("/home/michele/dev/code/cpp/dindexer/src/gui/qml/mainwin.qml")); + + dinlib::Settings settings; + try { + dinlib::load_settings(CONFIG_FILE_PATH, settings); + } + catch (const std::runtime_error& err) { + std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ":\n"; + std::cerr << err.what() << '\n'; + return 1; + } + + QObject* const obj = engine.rootObjects()[0]; + assert(obj); + din::Searcher searcher(settings.backend_plugin.backend()); + QObject::connect(obj, SIGNAL(locate(const QString&)), &searcher, SLOT(on_locate(const QString&))); + return app.exec(); +} diff --git a/src/gui/qml/mainwin.qml b/src/gui/qml/mainwin.qml new file mode 100644 index 0000000..0239e70 --- /dev/null +++ b/src/gui/qml/mainwin.qml @@ -0,0 +1,51 @@ +import QtQuick 2.1 +import QtQuick.Controls 1.4 +import QtQuick.Window 2.2 +import QtQuick.Layouts 1.0 + +ApplicationWindow { + id: mainWin + visible: true + title: "dindexer gui" + width: 640 + height: 480 + + menuBar: MenuBar { + id: menu + Menu { + id: menuFile + title: qsTr("File") + + //MenuSeparator { + //} + + MenuItem { + text: qsTr("Exit") + shortcut: "Ctrl+q" + onTriggered: Qt.quit(); + } + } + } + + Rectangle { + id: rectagleMain + TextField { + id: searchBox + maximumLength: 256 + placeholderText: qsTr("Locate glob"); + text: "*.ogg" + onEditingFinished: if (text.length >= 1) { locate(text); } + } + } + + statusBar: StatusBar { + RowLayout { + Label { + id: statusLabel + text: qsTr("dindexer idle") + } + } + } + + signal locate(string glob) +} diff --git a/src/gui/searcher.cpp b/src/gui/searcher.cpp new file mode 100644 index 0000000..7c9b955 --- /dev/null +++ b/src/gui/searcher.cpp @@ -0,0 +1,52 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "searcher.hpp" +#include "glob2regex/glob2regex.hpp" +#include "backends/db_backend.hpp" +#if !defined(NDEBUG) +# include +#endif +#include +#include + +namespace dindb { + std::ostream & + operator<<(std::ostream &parStream, const LocatedItem &parItem) { + parStream << parItem.group_id << '\t' << parItem.id << '\t' + << parItem.path; + return parStream; + } +} //namespace dindb + +namespace din { + Searcher::Searcher (dindb::Backend& parBackend) : + m_backend(parBackend) + { + } + + void Searcher::on_locate (const QString& parSearch) const { + const auto search = parSearch.toStdString(); + const auto regex_str = g2r::convert(search, false); +#if !defined(NDEBUG) + std::cout << "Searcher::on_locate() called with \"" << search << "\" --> \"" << regex_str << "\"\n"; +#endif + + const auto results = m_backend.locate_in_db(regex_str, dindb::TagList()); + std::copy(results.begin(), results.end(), std::ostream_iterator(std::cout, "\n")); + } +} //namespace din diff --git a/src/gui/searcher.hpp b/src/gui/searcher.hpp new file mode 100644 index 0000000..d58a133 --- /dev/null +++ b/src/gui/searcher.hpp @@ -0,0 +1,36 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include + +namespace dindb { + class Backend; +} //namespace dindb + +namespace din { + class Searcher : public QObject { + Q_OBJECT + public: + explicit Searcher ( dindb::Backend& parBackend ); + + public slots: + void on_locate (const QString& parSearch) const; + + private: + dindb::Backend& m_backend; + }; +} //namespace din