Новое начало

This commit is contained in:
2025-03-09 10:13:52 +05:00
parent 11ea3a8cd8
commit 4fbe63701f
11 changed files with 108 additions and 196 deletions

108
.gitignore vendored
View File

@@ -1,38 +1,82 @@
# user ignore
build
opds.db
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
# ---> C++
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.orig
*.rej
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
*.qbs.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# Directories with generated files
.moc/
.obj/
.pch/
.rcc/
.uic/
/build*/

View File

@@ -1,58 +0,0 @@
cmake_minimum_required(VERSION 3.16)
project(cpp-opds)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ODB_INCLUDE_DIRS /usr/include)
set(ODB_LIBRARY_DIRS /usr/lib/x86_64-linux-gnu)
include_directories(${ODB_INCLUDE_DIRS})
link_directories(${ODB_LIBRARY_DIRS})
find_package(Qt6 REQUIRED COMPONENTS Core Sql Network)
# find_package(ODB REQUIRED)
# find_package(SQLite3 REQUIRED)
find_library(ODB_LIBRARIES NAMES odb HINTS ${ODB_LIBRARY_DIRS})
find_library(ODB_SQLITE_LIBRARIES NAMES odb-sqlite HINTS ${ODB_LIBRARY_DIRS})
set(CMAKE_AUTOMOC ON) # <-- Включаем автоматическую генерацию MOC-файлов
# include_directories(${ODB_INCLUDE_DIRS} ${SQLite3_INCLUDE_DIRS})
# link_directories(${ODB_LIBRARY_DIRS} ${SQLite3_LIBRARY_DIRS})
# add_executable(cpp-opds
# src/main.cpp
# include/backend.cpp
# )
set(SOURCE_FILES
src/main.cpp
# src/database.cpp
# src/book.cpp
# src/author.hpp
)
set(ODB_SOURCES
src/book
src/author
)
# Генерация ODB файлов
foreach(file ${ODB_SOURCES})
add_custom_command(
OUTPUT ${file}.odb.cpp ${file}.odb.hpp
COMMAND odb --generate-query --generate-schema --database sqlite ${file}.hpp
DEPENDS ${file}.hpp
COMMENT "Running ODB on ${file}.hpp"
)
list(APPEND SOURCE_FILES ${file}.odb.cpp)
endforeach()
add_executable(cpp-opds ${SOURCE_FILES})
target_include_directories(cpp-opds PRIVATE include)
# target_link_libraries(cpp-opds Qt6::Core Qt6::Sql Qt6::Network ${ODB_LIBRARIES} ${SQLite3_LIBRARIES})
target_link_libraries(cpp-opds Qt6::Core Qt6::Sql Qt6::Network ${ODB_LIBRARIES} ${ODB_SQLITE_LIBRARIES})

13
cpp-opds.qbs Normal file
View File

@@ -0,0 +1,13 @@
QtApplication {
cpp.defines: [
// You can make your code fail to compile if it uses deprecated APIs.
// In order to do so, uncomment the following line.
//"QT_DISABLE_DEPRECATED_BEFORE=0x060000" // disables all the APIs deprecated before Qt 6.0.0
]
consoleApplication: true
install: true
files: [
"main.cpp",
]
}

View File

@@ -1,25 +0,0 @@
#include "backend.h"
#include <QtCore/QDebug>
Backend::Backend(QObject* parent) :
QObject(parent)
{
// Используем SQLite по умолчанию, для PostgreSQL потребуется изменить параметры подключения
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("opds.db");
if (!db.open())
{
qDebug() << "Error: Unable to open database";
}
}
Backend::~Backend()
{
qDebug() << "Backend stoped.";
}
void Backend::start()
{
qDebug() << "Backend started.";
}

View File

@@ -1,21 +0,0 @@
#ifndef BACKEND_H
#define BACKEND_H
#include <QObject>
#include <QtSql>
class Backend : public QObject
{
Q_OBJECT
public:
explicit Backend(QObject* parent = nullptr);
~Backend() override;
void start();
private:
QSqlDatabase db;
};
#endif // BACKEND_H

19
main.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Set up code that uses the Qt event loop here.
// Call a.quit() or a.exit() to quit the application.
// A not very useful example would be including
// #include <QTimer>
// near the top of the file and calling
// QTimer::singleShot(5000, &a, &QCoreApplication::quit);
// which quits the application after 5 seconds.
// If you do not need a running Qt event loop, remove the call
// to a.exec() or use the Non-Qt Plain C++ Application template.
return a.exec();
}

View File

@@ -1,13 +0,0 @@
#pragma db object
class Author {
public:
Author() = default;
Author(const std::string& name) : name(name) {}
const std::string& getName() const { return name; }
private:
#pragma db id auto
int id;
std::string name;
};

View File

@@ -1,22 +0,0 @@
#pragma db object
class Book {
public:
Book() = default;
Book(const std::string& title, const std::string& author, const std::string& filePath,
int fileSize, const std::string& format);
const std::string& getTitle() const { return title; }
const std::string& getAuthor() const { return author; }
const std::string& getFilePath() const { return filePath; }
int getFileSize() const { return fileSize; }
const std::string& getFormat() const { return format; }
private:
#pragma db id auto
int id;
std::string title;
std::string author;
std::string filePath;
int fileSize;
std::string format;
};

View File

@@ -1,13 +0,0 @@
#include "database.h"
#include <odb/sqlite/database.hxx>
#include <odb/schema-catalog.hxx>
#include "book-odb.hxx"
#include "author-odb.hxx"
std::unique_ptr<odb::sqlite::database> initializeDatabase(const std::string& dbPath) {
auto db = std::make_unique<odb::sqlite::database>(dbPath, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
odb::transaction t(db->begin());
odb::schema_catalog::create_schema(*db);
t.commit();
return db;
}

View File

View File

@@ -1,12 +0,0 @@
#include <QCoreApplication>
#include "backend.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Backend backend;
backend.start();
return a.exec();
}