#1 Add some READMEs, add logger class, rearrange to use Core class
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,)
|
||||
set(
|
||||
CMAKE_CXX_CLANG_TIDY
|
||||
clang-tidy
|
||||
-checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,-modernize-use-trailing-return-type
|
||||
)
|
||||
|
||||
project(JAMCS)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
add_subdirectory(logger)
|
||||
add_subdirectory(ui)
|
||||
|
||||
add_executable(
|
||||
@@ -9,6 +10,7 @@ target_link_libraries(
|
||||
JAMCS
|
||||
PRIVATE
|
||||
UI
|
||||
Logger
|
||||
)
|
||||
|
||||
add_definitions (${GTK_CFLAGS_OTHER})
|
||||
|
||||
17
src/README.md
Normal file
17
src/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## JAMCS
|
||||
JAMCS is separated into components which take care of individual functions of the JAMCS software:
|
||||
- Core
|
||||
- Core object which holds references to the different components, used to talk between components
|
||||
- UI
|
||||
- Sets up the UI for display on the camera, i.e. viewfinder, gallery
|
||||
- Camera
|
||||
- Handles connecting to and controlling the physical camera device
|
||||
- Processing
|
||||
- Handles the images once a picture has been taken:
|
||||
- Applies any image effects
|
||||
- Saves the image to disk
|
||||
- Uploads the image to a cloud service
|
||||
- Web UI
|
||||
- Runs the Web UI for JAMCS, allowing the entire app to be controlled remotely
|
||||
- Logger
|
||||
- Handles logging output to the console or a file
|
||||
17
src/core/core.h
Normal file
17
src/core/core.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// Header only core which has references to the instances of classes
|
||||
#ifndef _CORE_H
|
||||
#define _CORE_H
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <memory>
|
||||
|
||||
#include "../logger/logger.h"
|
||||
|
||||
class Core
|
||||
{
|
||||
public:
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
std::unique_ptr<Logger> logger;
|
||||
};
|
||||
|
||||
#endif // _CORE_H
|
||||
5
src/logger/CMakeLists.txt
Normal file
5
src/logger/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_library(
|
||||
Logger
|
||||
STATIC
|
||||
logger.cpp
|
||||
)
|
||||
43
src/logger/logger.cpp
Normal file
43
src/logger/logger.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "logger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Logger::Logger(LogLevel logLevel)
|
||||
{
|
||||
this->SetLogLevel(logLevel);
|
||||
}
|
||||
|
||||
void Logger::SetLogLevel(LogLevel logLevel)
|
||||
{
|
||||
this->level = logLevel;
|
||||
}
|
||||
|
||||
void Logger::Log(std::wstring msg, LogLevel msgLevel)
|
||||
{
|
||||
// Check if the log level matches
|
||||
if (msgLevel <= this->level)
|
||||
{
|
||||
// For now just print
|
||||
std::wcout << msgLevel << L" : " << msg << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::Debug(std::wstring msg)
|
||||
{
|
||||
this->Log(msg, LogLevel::DEBUG);
|
||||
}
|
||||
|
||||
void Logger::Info(std::wstring msg)
|
||||
{
|
||||
this->Log(msg, LogLevel::INFO);
|
||||
}
|
||||
|
||||
void Logger::Error(std::wstring msg)
|
||||
{
|
||||
this->Log(msg, LogLevel::ERROR);
|
||||
}
|
||||
|
||||
void Logger::Critical(std::wstring msg)
|
||||
{
|
||||
this->Log(msg, LogLevel::CRITICAL);
|
||||
}
|
||||
29
src/logger/logger.h
Normal file
29
src/logger/logger.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _LOGGER_H
|
||||
#define _LOGGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
enum LogLevel
|
||||
{
|
||||
DEBUG,
|
||||
INFO,
|
||||
ERROR,
|
||||
CRITICAL
|
||||
};
|
||||
|
||||
class Logger
|
||||
{
|
||||
private:
|
||||
LogLevel level;
|
||||
void Log(std::wstring msg, LogLevel msgLevel);
|
||||
|
||||
public:
|
||||
Logger(LogLevel logLevel = LogLevel::INFO);
|
||||
void SetLogLevel(LogLevel logLevel);
|
||||
void Debug(std::wstring msg);
|
||||
void Info(std::wstring msg);
|
||||
void Error(std::wstring msg);
|
||||
void Critical(std::wstring msg);
|
||||
};
|
||||
|
||||
#endif // _LOGGER_H
|
||||
15
src/main.cpp
15
src/main.cpp
@@ -1,6 +1,8 @@
|
||||
#include <gtkmm.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/core.h"
|
||||
#include "logger/logger.h"
|
||||
#include "ui/jamcswindow.h"
|
||||
|
||||
// Default size for JAMCS window
|
||||
@@ -10,10 +12,17 @@ const static int DEFAULT_WINDOW_HEIGHT = 480;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
auto app = Gtk::Application::create("org.gtkmm.examples.base");
|
||||
auto core = std::make_shared<Core>(Core());
|
||||
core->logger = std::make_unique<Logger>(Logger());
|
||||
|
||||
JamcsWindow window(app, "JAMCS", DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
|
||||
core->logger->Info(L"Starting JAMCS");
|
||||
|
||||
// Create camera object and pass to core
|
||||
|
||||
core->app = Gtk::Application::create("org.gtkmm.examples.base");
|
||||
|
||||
JamcsWindow window(core, "JAMCS", DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
|
||||
window.show_all();
|
||||
|
||||
return app->run(window);
|
||||
return core->app->run(window);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
add_subdirectory(common)
|
||||
add_subdirectory(viewfinder)
|
||||
|
||||
add_library(
|
||||
UI
|
||||
STATIC
|
||||
jamcswindow.cpp
|
||||
viewfinder.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
UI
|
||||
PUBLIC
|
||||
CommonUI
|
||||
Viewfinder
|
||||
)
|
||||
|
||||
2
src/ui/README.md
Normal file
2
src/ui/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## UI
|
||||
This directory contains the code defining the camera UI.
|
||||
2
src/ui/common/README.md
Normal file
2
src/ui/common/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## Common
|
||||
Common UI elements used across multiple screens
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr)
|
||||
CloseButton::CloseButton(std::shared_ptr<Core> appCore, const Glib::ustring &label) : core(appCore)
|
||||
{
|
||||
set_label(label);
|
||||
|
||||
@@ -11,5 +11,5 @@ CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Applicati
|
||||
|
||||
void CloseButton::on_button_clicked()
|
||||
{
|
||||
this->app.get()->quit();
|
||||
this->core->app.get()->quit();
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
#define _CLOSEBUTTON_H
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <memory>
|
||||
|
||||
#include "../../core/core.h"
|
||||
|
||||
class CloseButton : public Gtk::Button
|
||||
{
|
||||
private:
|
||||
void on_button_clicked();
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
std::shared_ptr<Core> core;
|
||||
public:
|
||||
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> appPtr);
|
||||
CloseButton(std::shared_ptr<Core> appCore, const Glib::ustring &label);
|
||||
};
|
||||
|
||||
#endif // _CLOSEBUTTON_H
|
||||
|
||||
@@ -2,17 +2,20 @@
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "viewfinder.h"
|
||||
#include "../core/core.h"
|
||||
#include "viewfinder/viewfinder.h"
|
||||
|
||||
JamcsWindow::JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height) : app(appPtr)
|
||||
JamcsWindow::JamcsWindow(std::shared_ptr<Core> appCore, const Glib::ustring &title, int width, int height) : core(appCore)
|
||||
{
|
||||
this->core->logger->Info(L"Initializing UI");
|
||||
|
||||
set_title(title);
|
||||
set_default_size(width, height);
|
||||
|
||||
this->viewfinder = std::unique_ptr<Viewfinder>(new Viewfinder(app));
|
||||
this->viewfinder = std::make_unique<Viewfinder>(Viewfinder(this->core));
|
||||
this->stack.add(*this->viewfinder, "viewfinder");
|
||||
|
||||
this->stack.set_visible_child("viewfinder");
|
||||
|
||||
this->add(this->stack);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,16 +4,17 @@
|
||||
#include <gtkmm.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "viewfinder.h"
|
||||
#include "../core/core.h"
|
||||
#include "viewfinder/viewfinder.h"
|
||||
|
||||
class JamcsWindow : public Gtk::Window
|
||||
{
|
||||
private:
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
Gtk::Stack stack;
|
||||
std::shared_ptr<Core> core = nullptr;
|
||||
std::unique_ptr<Viewfinder> viewfinder = nullptr;
|
||||
public:
|
||||
JamcsWindow(Glib::RefPtr<Gtk::Application> appPtr, const Glib::ustring &title, int width, int height);
|
||||
JamcsWindow(std::shared_ptr<Core> appCore, const Glib::ustring &title, int width, int height);
|
||||
};
|
||||
|
||||
#endif // _WINDOW_H
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#include "viewfinder.h"
|
||||
|
||||
#include "common/common.h"
|
||||
|
||||
Viewfinder::Viewfinder(Glib::RefPtr<Gtk::Application> appPtr) : app(appPtr)
|
||||
{
|
||||
this->close_button = std::unique_ptr<CloseButton>(new CloseButton("X", app));
|
||||
this->add(*this->close_button);
|
||||
|
||||
this->show_all();
|
||||
}
|
||||
10
src/ui/viewfinder/CMakeLists.txt
Normal file
10
src/ui/viewfinder/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_library(
|
||||
Viewfinder
|
||||
STATIC
|
||||
viewfinder.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
Viewfinder
|
||||
PUBLIC
|
||||
CommonUI
|
||||
)
|
||||
2
src/ui/viewfinder/README.md
Normal file
2
src/ui/viewfinder/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## Viewfinder
|
||||
Main viewfinder screen used to take pictures and videos.
|
||||
14
src/ui/viewfinder/viewfinder.cpp
Normal file
14
src/ui/viewfinder/viewfinder.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "viewfinder.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../../core/core.h"
|
||||
#include "../common/common.h"
|
||||
|
||||
Viewfinder::Viewfinder(std::shared_ptr<Core> appCore) : core(appCore)
|
||||
{
|
||||
this->close_button = std::unique_ptr<CloseButton>(new CloseButton(this->core, "X"));
|
||||
this->add(*this->close_button);
|
||||
|
||||
this->show_all();
|
||||
}
|
||||
@@ -3,15 +3,16 @@
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "common/common.h"
|
||||
#include "../common/common.h"
|
||||
#include "../../core/core.h"
|
||||
|
||||
class Viewfinder : public Gtk::Box
|
||||
{
|
||||
private:
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
std::shared_ptr<Core> core;
|
||||
std::unique_ptr<CloseButton> close_button = nullptr;
|
||||
public:
|
||||
Viewfinder(Glib::RefPtr<Gtk::Application> appPtr);
|
||||
Viewfinder(std::shared_ptr<Core> appCore);
|
||||
};
|
||||
|
||||
#endif // _VIEWFINDER_H
|
||||
Reference in New Issue
Block a user