Initial commit
This commit is contained in:
commit
fd3ce483f0
78
.gitignore
vendored
Normal file
78
.gitignore
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.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*
|
||||||
|
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
|
||||||
|
|
||||||
|
# CLion
|
||||||
|
|
||||||
|
cmake-build-debug/
|
||||||
|
.idea/
|
||||||
39
CMakeLists.txt
Normal file
39
CMakeLists.txt
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(AutoCatQt VERSION 0.1 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_PREFIX_PATH "/home/selim/qt/6.4.3/gcc_64/lib/cmake")
|
||||||
|
|
||||||
|
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
|
||||||
|
find_package(nlohmann_json REQUIRED)
|
||||||
|
|
||||||
|
qt_standard_project_setup()
|
||||||
|
|
||||||
|
qt_add_executable(appAutoCatQt
|
||||||
|
main.cpp
|
||||||
|
services/Settings.cpp services/Settings.h models/User.cpp models/User.h)
|
||||||
|
|
||||||
|
qt_add_qml_module(appAutoCatQt
|
||||||
|
URI AutoCatQt
|
||||||
|
VERSION 1.0
|
||||||
|
QML_FILES views/LoginWindow.qml
|
||||||
|
QML_FILES views/MainWindow.qml
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(appAutoCatQt PROPERTIES
|
||||||
|
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||||
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||||
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
|
MACOSX_BUNDLE TRUE
|
||||||
|
WIN32_EXECUTABLE TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(appAutoCatQt
|
||||||
|
PRIVATE Qt6::Quick
|
||||||
|
PRIVATE nlohmann_json::nlohmann_json
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS appAutoCatQt
|
||||||
|
BUNDLE DESTINATION .
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
25
main.cpp
Normal file
25
main.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "services/Settings.h"
|
||||||
|
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQuickWindow>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
|
||||||
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
|
QQmlApplicationEngine engine;
|
||||||
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||||
|
&app, []() { QCoreApplication::exit(-1); },
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
|
auto settings = Settings::instance();
|
||||||
|
if(settings.user().token.empty()) {
|
||||||
|
engine.load(QUrl(u"qrc:/AutoCatQt/views/LoginWindow.qml"_qs));
|
||||||
|
} else {
|
||||||
|
engine.load(QUrl(u"qrc:/AutoCatQt/views/MainWindow.qml"_qs));
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
9
models/User.cpp
Normal file
9
models/User.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 5/6/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "User.h"
|
||||||
|
|
||||||
|
User::User(std::string_view email, std::string_view token): email(email), token(token) {
|
||||||
|
|
||||||
|
}
|
||||||
28
models/User.h
Normal file
28
models/User.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 5/6/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AUTOCATQT_USER_H
|
||||||
|
#define AUTOCATQT_USER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
class User {
|
||||||
|
public:
|
||||||
|
std::string email;
|
||||||
|
std::string token;
|
||||||
|
std::optional<std::string> googleIdToken;
|
||||||
|
std::optional<std::string> googleRefreshToken;
|
||||||
|
|
||||||
|
public:
|
||||||
|
User() = default;
|
||||||
|
User(const User& user) = default;
|
||||||
|
User(User&&) = default;
|
||||||
|
User(std::string_view email, std::string_view token);
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE(User, email, token)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //AUTOCATQT_USER_H
|
||||||
68
services/Settings.cpp
Normal file
68
services/Settings.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 5/6/23.
|
||||||
|
//
|
||||||
|
#include "Settings.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
fs::path Settings::getDataPath() {
|
||||||
|
auto dataDir = std::getenv("XDG_DATA_HOME");
|
||||||
|
if(dataDir) {
|
||||||
|
return fs::path(dataDir) / "autocat";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto home = std::getenv("HOME");
|
||||||
|
if(home) {
|
||||||
|
return fs::path(home) / ".local" / "share" / "autocat";
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error("Failed to find data home directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string readString(const fs::path& path) {
|
||||||
|
std::ifstream stream(path);
|
||||||
|
stream.seekg(0, std::ios::end);
|
||||||
|
auto size = stream.tellg();
|
||||||
|
std::string buffer(size, ' ');
|
||||||
|
stream.seekg(0);
|
||||||
|
stream.read(&buffer[0], size);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeString(const fs::path& path, const std::string& text) {
|
||||||
|
std::ofstream stream(path);
|
||||||
|
stream << text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings Settings::instance() {
|
||||||
|
static Settings instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::Settings() {
|
||||||
|
_dataPath = getDataPath();
|
||||||
|
if(!fs::exists(_dataPath)) {
|
||||||
|
fs::create_directories(_dataPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
User Settings::user() const {
|
||||||
|
auto userFile = _dataPath / "user.json";
|
||||||
|
if(fs::exists(userFile)) {
|
||||||
|
auto jsonText = readString(userFile);
|
||||||
|
std::cout << "User json text: " << jsonText << std::endl;
|
||||||
|
return nlohmann::json::parse(jsonText).get<User>();
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setUser(const User &user) {
|
||||||
|
auto userFile = _dataPath / "user.json";
|
||||||
|
nlohmann::json json = user;
|
||||||
|
auto userString = json.dump(4);
|
||||||
|
writeString(userFile, userString);
|
||||||
|
}
|
||||||
26
services/Settings.h
Normal file
26
services/Settings.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by selim on 5/6/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef AUTOCATQT_SETTINGS_H
|
||||||
|
#define AUTOCATQT_SETTINGS_H
|
||||||
|
|
||||||
|
#include "../models/User.h"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
private:
|
||||||
|
fs::path _dataPath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Settings instance();
|
||||||
|
Settings();
|
||||||
|
static fs::path getDataPath();
|
||||||
|
|
||||||
|
[[nodiscard]] User user() const;
|
||||||
|
void setUser(const User& user);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //AUTOCATQT_SETTINGS_H
|
||||||
9
views/LoginWindow.qml
Normal file
9
views/LoginWindow.qml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Window
|
||||||
|
|
||||||
|
Window {
|
||||||
|
height: 480
|
||||||
|
width: 640
|
||||||
|
title: "Login"
|
||||||
|
visible: true
|
||||||
|
}
|
||||||
9
views/MainWindow.qml
Normal file
9
views/MainWindow.qml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Window
|
||||||
|
|
||||||
|
Window {
|
||||||
|
height: 480
|
||||||
|
title: "Main window"
|
||||||
|
visible: true
|
||||||
|
width: 640
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user