mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-12-02 02:05:41 +00:00
Stub implementation of a qt5 gui that can run locate command.
This commit is contained in:
parent
08a6c0d73d
commit
705bf615ba
6 changed files with 222 additions and 0 deletions
|
@ -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)
|
||||
|
|
35
src/gui/CMakeLists.txt
Normal file
35
src/gui/CMakeLists.txt
Normal file
|
@ -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
|
||||
)
|
47
src/gui/main.cpp
Normal file
47
src/gui/main.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "searcher.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include <QApplication>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
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();
|
||||
}
|
51
src/gui/qml/mainwin.qml
Normal file
51
src/gui/qml/mainwin.qml
Normal file
|
@ -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)
|
||||
}
|
52
src/gui/searcher.cpp
Normal file
52
src/gui/searcher.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "searcher.hpp"
|
||||
#include "glob2regex/glob2regex.hpp"
|
||||
#include "backends/db_backend.hpp"
|
||||
#if !defined(NDEBUG)
|
||||
# include <iostream>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
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<dindb::LocatedItem>(std::cout, "\n"));
|
||||
}
|
||||
} //namespace din
|
36
src/gui/searcher.hpp
Normal file
36
src/gui/searcher.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
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
|
Loading…
Reference in a new issue