Skip to content

Commit

Permalink
WIP LoginPage and profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrePTJ committed Dec 10, 2024
1 parent e6d778b commit d8e28f7
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 122 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ if (KEMAI_BUILD_LOCAL_DEPENDENCIES)
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.0
OVERRIDE_FIND_PACKAGE)
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
OVERRIDE_FIND_PACKAGE)
endif (KEMAI_BUILD_LOCAL_DEPENDENCIES)

# Find external dependencies
find_package(fmt REQUIRED)
find_package(json REQUIRED)
find_package(magic_enum REQUIRED)
find_package(spdlog REQUIRED)

Expand Down
14 changes: 13 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ set(KEMAI_QML_FILES

set(KEMAI_RESX_FILES
images/kimai_logo_transparent.svg
images/visibility_off.svg
images/visibility_on.svg
qml/requests.js
)

set(KEMAI_CPP_FILES
cpp/main.cpp
cpp/data/profile.h
cpp/model/profile.cpp
cpp/model/profile.h
)

#
Expand All @@ -25,6 +31,11 @@ qt_standard_project_setup(

qt_add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${KEMAI_CPP_FILES})

set_target_properties(${PROJECT_NAME} PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)

qt_add_qml_module(${PROJECT_NAME}
URI kemai
QML_FILES ${KEMAI_QML_FILES}
Expand All @@ -42,14 +53,15 @@ qt_add_resources(
FILES "qtquickcontrols2.conf")

configure_file(cpp/kemaiConfig.h.in ${PROJECT_BINARY_DIR}/cpp/kemaiConfig.h)

target_include_directories(${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/cpp ${CMAKE_CURRENT_SOURCE_DIR}/cpp)

target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

target_link_libraries(${PROJECT_NAME}
PRIVATE Qt6::Gui Qt6::Quick spdlog::spdlog)
PRIVATE Qt6::Gui Qt6::Quick spdlog::spdlog nlohmann_json::nlohmann_json magic_enum::magic_enum)

#
# Install
Expand Down
15 changes: 15 additions & 0 deletions src/cpp/data/profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

// STL headers
#include <string>

namespace kemai {

struct Profile
{
std::string name;
std::string host;
std::string token;
};

} // namespace kemai
52 changes: 52 additions & 0 deletions src/cpp/model/profile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "profile.h"

// magic_enum headers
#include <magic_enum/magic_enum.hpp>

namespace kemai {

ProfileModel::ProfileModel(QObject* parent) : QAbstractListModel(parent) {}

ProfileModel::~ProfileModel() = default;

void ProfileModel::setProfiles(const std::vector<Profile>& profiles)
{
beginResetModel();
m_profiles = profiles;
endResetModel();
}

int ProfileModel::rowCount(const QModelIndex& parent) const
{
return static_cast<int>(m_profiles.size());
}

QVariant ProfileModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || index.row() > m_profiles.size())
{
return {};
}

const auto& profile = m_profiles[index.row()];
switch (static_cast<ProfileRole>(role))
{
case ProfileRole::Name:
return QString::fromStdString(profile.name);
case ProfileRole::Host:
return QString::fromStdString(profile.host);
case ProfileRole::Token:
return QString::fromStdString(profile.token);
default:
return {};
}
}

QHash<int, QByteArray> ProfileModel::roleNames() const
{
return {{magic_enum::enum_integer(ProfileRole::Name), "name"},
{magic_enum::enum_integer(ProfileRole::Host), "host"},
{magic_enum::enum_integer(ProfileRole::Token), "token"}};
}

} // namespace kemai
39 changes: 39 additions & 0 deletions src/cpp/model/profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

// STL headers
#include <vector>

// Qt headers
#include <QAbstractListModel>

// Project headers
#include <data/profile.h>

namespace kemai {

class ProfileModel : public QAbstractListModel
{
Q_OBJECT

public:
enum class ProfileRole
{
Name = Qt::UserRole + 1,
Host,
Token
};

explicit ProfileModel(QObject* parent = nullptr);
~ProfileModel() override;

void setProfiles(const std::vector<Profile>& profiles);

int rowCount(const QModelIndex& parent) const override;
QVariant data(const QModelIndex& index, int role) const override;
QHash<int, QByteArray> roleNames() const override;

private:
std::vector<Profile> m_profiles;
};

} // namespace kemai
1 change: 1 addition & 0 deletions src/images/visibility_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/visibility_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d8e28f7

Please sign in to comment.