-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flashback: create base for importer and client
- Loading branch information
1 parent
c091408
commit 839d18a
Showing
14 changed files
with
192 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.30) | ||
cmake_minimum_required(VERSION 3.28) | ||
project(Milestone VERSION 0.4 LANGUAGES CXX DESCRIPTION "Knowledge Training Application") | ||
|
||
enable_testing() | ||
|
||
set(CMAKE_CXX_STANDARD 23) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) | ||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
find_package(Boost COMPONENTS program_options) | ||
find_package(GTest) | ||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Quick Controls WebView) | ||
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Quick Controls WebView) | ||
find_package(Boost CONFIG REQUIRED COMPONENTS program_options) | ||
find_package(PostgreSQL REQUIRED) | ||
find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick) | ||
find_package(GTest REQUIRED) | ||
|
||
file(GLOB common_source RELATIVE src/*.cpp) | ||
file(GLOB common_test RELATIVE test/*.cpp) | ||
|
||
add_library(common ${common_source}) | ||
target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
add_executable(test-common ${common_test}) | ||
target_link_libraries(test-common PRIVATE common gtest) | ||
|
||
add_test(NAME common COMMAND $<TARGET_FILE:test-common>) | ||
|
||
list(APPEND source_files main.cpp) | ||
file(GLOB qml_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.qml) | ||
|
||
qt_standard_project_setup(REQUIRES 6.5) | ||
qt_add_executable(flashback ${source_files}) | ||
qt_add_qml_module(flashback URI flashback VERSION 1.0 QML_FILES ${qml_files}) | ||
|
||
set_target_properties(flashback PROPERTIES | ||
MACOSX_BUNDLE_GUI_IDENTIFIER com.milestone.project | ||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} | ||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} | ||
MACOSX_BUNDLE TRUE | ||
WIN32_EXECUTABLE TRUE | ||
) | ||
target_compile_definitions(flashback PRIVATE PROGRAM_VERSION="${CMAKE_PROJECT_VERSION}") | ||
target_link_libraries(flashback PRIVATE Qt6::Quick Qt6::WebView) | ||
|
||
include(GNUInstallDirs) | ||
|
||
install(TARGETS flashback | ||
BUNDLE DESTINATION . | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
add_subdirectory(importer) | ||
add_subdirectory(flashback) | ||
add_subdirectory(client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,12 @@ | ||
# Flashback | ||
# Miletsone | ||
|
||
Recollection program to help learners review technical references and practice on subjects. | ||
Knowledge training application. | ||
|
||
## Introduction | ||
|
||
Using Flashback you can write technical notes in order to frequently review them and | ||
practice the subjects of your interest, so that you are always ready for a challenge. | ||
|
||
## Setup | ||
|
||
You can build and optionally install the program by following these instructions: | ||
|
||
- First get the source of the program using [Git](https://git-scm.com/downloads): | ||
|
||
```sh | ||
git clone https://github.com/briansalehi/flashback.git | ||
``` | ||
|
||
- Then configure the project with [CMake](https://cmake.org/download/): | ||
|
||
```sh | ||
cmake -S flashback -B flashback-build -D CMAKE_BUILD_TYPE:STRING=release | ||
``` | ||
|
||
- And then build the program as follows: | ||
|
||
```sh | ||
cmake --build flashback-build --target all --parallel | ||
``` | ||
|
||
- **(optional)** If you want Flashback permanently on your system: | ||
|
||
```sh | ||
cmake --install flashback-build --prefix $HOME/.local | ||
``` | ||
|
||
## Usage | ||
|
||
Start using Flashback by running its command: | ||
|
||
```sh | ||
flashback | ||
``` | ||
|
||
## License | ||
|
||
This work is licensed under [GNU General Public License Version 3](LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
file(GLOB source_files RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) | ||
file(GLOB qml_files RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} *.qml) | ||
|
||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
qt_standard_project_setup(REQUIRES 6.5) | ||
qt_add_executable(milestone ${source_files}) | ||
qt_add_qml_module(milestone URI Milestone VERSION 1.0 QML_FILES Main.qml) | ||
target_link_libraries(milestone PRIVATE Qt6::Core Qt6::Quick) | ||
target_include_directories(milestone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
install(TARGETS milestone | ||
BUNDLE DESTINATION . | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import QtQuick | ||
import QtQuick.Controls | ||
import QtQuick.Controls.Material | ||
|
||
ApplicationWindow { | ||
title: qsTr("Milestone") | ||
visible: true | ||
visibility: Window.Maximized | ||
Material.theme: Material.Dark | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <QGuiApplication> | ||
#include <QQmlApplicationEngine> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QGuiApplication app(argc, argv); | ||
|
||
QQmlApplicationEngine engine; | ||
QObject::connect( | ||
&engine, | ||
&QQmlApplicationEngine::objectCreationFailed, | ||
&app, | ||
[]() { QCoreApplication::exit(-1); }, | ||
Qt::QueuedConnection); | ||
engine.loadFromModule("Milestone", "Main"); | ||
|
||
return app.exec(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
file(GLOB source_files RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} src/main.cpp) | ||
add_executable(importer ${source_files}) | ||
target_link_libraries(importer PUBLIC Boost::program_options pq pqxx) | ||
target_include_directories(importer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
target_compile_definitions(importer PRIVATE PROGRAM_VERSION="${CMAKE_PROJECT_VERSION}") | ||
|
||
add_executable(test-importer EXCLUDE_FROM_ALL test/importer.cpp ${source_files}) | ||
target_link_libraries(test-importer PUBLIC gtest program_options pq pqxx) | ||
target_include_directories(test-importer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
add_test(NAME test-importer COMMAND test-importer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <flashback/record.hpp> | ||
#include <boost/program_options.hpp> | ||
#include <pqxx/pqxx> | ||
|
||
namespace flashback | ||
{ | ||
class importer | ||
{ | ||
public: | ||
explicit importer(int argc, char** argv); | ||
std::vector<record> records() const noexcept; | ||
}; | ||
} // flashback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
namespace flashback | ||
{ | ||
struct record | ||
{ | ||
std::string content; | ||
}; | ||
} // flashback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
namespace flashback | ||
{ | ||
class importer; | ||
|
||
void store(importer const& ); | ||
} // flashback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <flashback/importer.hpp> | ||
|
||
namespace flashback | ||
{ | ||
explicit importer::importer(int argc, char** argv) | ||
{ | ||
} | ||
|
||
std::vector<record> importer::records() const | ||
{ | ||
return m_records; | ||
} | ||
|
||
void importer::store(record const& ) | ||
{ | ||
pqxx::connection connection{"postgres://localhost/flashback"}; | ||
pqxx::work task{connection}; | ||
pqxx::result result = task.exec("select now()"); | ||
} | ||
} // flashback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <boost/program_options.hpp> | ||
#include <pqxx/pqxx> | ||
#include <filesystem> | ||
#include <exception> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
#include <ios> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
try | ||
{ | ||
boost::program_options::options_description description{"Options"}; | ||
boost::program_options::positional_options_description positional{}; | ||
description.add_options()("help,h", "show help menu")("base,b", boost::program_options::value<std::string>(), "records directory path"); | ||
positional.add("base", -1); | ||
boost::program_options::variables_map options{}; | ||
boost::program_options::basic_command_line_parser<char> parser = boost::program_options::command_line_parser(argc, argv); | ||
boost::program_options::basic_parsed_options<char> parsed = parser.options(description).positional(positional).run(); | ||
boost::program_options::store(parsed, options); | ||
boost::program_options::notify(options); | ||
|
||
if (argc == 1 || options.count("help") > 0) | ||
{ | ||
std::cerr << std::filesystem::path{argv[0]}.filename().string() << " <path/to/records>\n\n"; | ||
std::cerr << description << std::endl; | ||
return 1; | ||
} | ||
|
||
if (options.count("base") == 0) | ||
{ | ||
throw std::invalid_argument{"records directory path should be specified."}; | ||
} | ||
|
||
std::filesystem::path records_path{options["base"].as<std::string>()}; | ||
|
||
pqxx::connection connection{"postgres://localhost/flashback"}; | ||
pqxx::work task{connection}; | ||
std::size_t imported{}; | ||
|
||
for (auto const& entry: std::filesystem::directory_iterator{records_path}) | ||
{ | ||
if (entry.path().extension().string() == ".sql") | ||
{ | ||
std::filesystem::path record_path = entry.path().lexically_normal(); | ||
std::ifstream file{record_path}; | ||
std::streamoff size{file.tellg()}; | ||
std::string buffer(size, '\0'); | ||
file.seekg(0); | ||
file.read(&buffer[0], size); | ||
task.exec(std::move(buffer)); | ||
imported++; | ||
} | ||
} | ||
|
||
std::cerr << imported << " records added.\n"; | ||
} | ||
catch (std::exception const& exp) | ||
{ | ||
std::cerr << exp.what() << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <flashback/store.hpp> | ||
#include <flashback/importer.hpp> | ||
|
||
namespace flashback | ||
{ | ||
} // flashback |
Empty file.