diff --git a/CMakeLists.txt b/CMakeLists.txt index e10c9f5..92d808e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 907d319..ec1a5a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}) diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..191a738 --- /dev/null +++ b/src/README.md @@ -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 diff --git a/src/core/core.h b/src/core/core.h new file mode 100644 index 0000000..27d43d3 --- /dev/null +++ b/src/core/core.h @@ -0,0 +1,17 @@ +// Header only core which has references to the instances of classes +#ifndef _CORE_H +#define _CORE_H + +#include +#include + +#include "../logger/logger.h" + +class Core +{ +public: + Glib::RefPtr app; + std::unique_ptr logger; +}; + +#endif // _CORE_H diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt new file mode 100644 index 0000000..4d527cc --- /dev/null +++ b/src/logger/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library( + Logger + STATIC + logger.cpp +) diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp new file mode 100644 index 0000000..e69d260 --- /dev/null +++ b/src/logger/logger.cpp @@ -0,0 +1,43 @@ +#include "logger.h" + +#include + +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); +} diff --git a/src/logger/logger.h b/src/logger/logger.h new file mode 100644 index 0000000..dca83bb --- /dev/null +++ b/src/logger/logger.h @@ -0,0 +1,29 @@ +#ifndef _LOGGER_H +#define _LOGGER_H + +#include + +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 diff --git a/src/main.cpp b/src/main.cpp index dc47c7f..29b441e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include +#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->logger = std::make_unique(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); } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 5c928ca..d31e742 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -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 ) diff --git a/src/ui/README.md b/src/ui/README.md new file mode 100644 index 0000000..6669824 --- /dev/null +++ b/src/ui/README.md @@ -0,0 +1,2 @@ +## UI +This directory contains the code defining the camera UI. diff --git a/src/ui/common/README.md b/src/ui/common/README.md new file mode 100644 index 0000000..67824d4 --- /dev/null +++ b/src/ui/common/README.md @@ -0,0 +1,2 @@ +## Common +Common UI elements used across multiple screens diff --git a/src/ui/common/closebutton.cpp b/src/ui/common/closebutton.cpp index 2102393..5e8554d 100644 --- a/src/ui/common/closebutton.cpp +++ b/src/ui/common/closebutton.cpp @@ -2,7 +2,7 @@ #include -CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr appPtr) : app(appPtr) +CloseButton::CloseButton(std::shared_ptr appCore, const Glib::ustring &label) : core(appCore) { set_label(label); @@ -11,5 +11,5 @@ CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtrapp.get()->quit(); + this->core->app.get()->quit(); } diff --git a/src/ui/common/closebutton.h b/src/ui/common/closebutton.h index bf9d68d..abedae5 100644 --- a/src/ui/common/closebutton.h +++ b/src/ui/common/closebutton.h @@ -2,14 +2,17 @@ #define _CLOSEBUTTON_H #include +#include + +#include "../../core/core.h" class CloseButton : public Gtk::Button { private: void on_button_clicked(); - Glib::RefPtr app; + std::shared_ptr core; public: - CloseButton(const Glib::ustring &label, Glib::RefPtr appPtr); + CloseButton(std::shared_ptr appCore, const Glib::ustring &label); }; #endif // _CLOSEBUTTON_H diff --git a/src/ui/jamcswindow.cpp b/src/ui/jamcswindow.cpp index c60760c..dcee267 100644 --- a/src/ui/jamcswindow.cpp +++ b/src/ui/jamcswindow.cpp @@ -2,17 +2,20 @@ #include -#include "viewfinder.h" +#include "../core/core.h" +#include "viewfinder/viewfinder.h" -JamcsWindow::JamcsWindow(Glib::RefPtr appPtr, const Glib::ustring &title, int width, int height) : app(appPtr) +JamcsWindow::JamcsWindow(std::shared_ptr 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(new Viewfinder(app)); + this->viewfinder = std::make_unique(Viewfinder(this->core)); this->stack.add(*this->viewfinder, "viewfinder"); this->stack.set_visible_child("viewfinder"); this->add(this->stack); -} +}; diff --git a/src/ui/jamcswindow.h b/src/ui/jamcswindow.h index 1b4ebce..d5ca140 100644 --- a/src/ui/jamcswindow.h +++ b/src/ui/jamcswindow.h @@ -4,16 +4,17 @@ #include #include -#include "viewfinder.h" +#include "../core/core.h" +#include "viewfinder/viewfinder.h" class JamcsWindow : public Gtk::Window { private: - Glib::RefPtr app; Gtk::Stack stack; + std::shared_ptr core = nullptr; std::unique_ptr viewfinder = nullptr; public: - JamcsWindow(Glib::RefPtr appPtr, const Glib::ustring &title, int width, int height); + JamcsWindow(std::shared_ptr appCore, const Glib::ustring &title, int width, int height); }; #endif // _WINDOW_H diff --git a/src/ui/viewfinder.cpp b/src/ui/viewfinder.cpp deleted file mode 100644 index 4788465..0000000 --- a/src/ui/viewfinder.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "viewfinder.h" - -#include "common/common.h" - -Viewfinder::Viewfinder(Glib::RefPtr appPtr) : app(appPtr) -{ - this->close_button = std::unique_ptr(new CloseButton("X", app)); - this->add(*this->close_button); - - this->show_all(); -} diff --git a/src/ui/viewfinder/CMakeLists.txt b/src/ui/viewfinder/CMakeLists.txt new file mode 100644 index 0000000..5fe4d54 --- /dev/null +++ b/src/ui/viewfinder/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library( + Viewfinder + STATIC + viewfinder.cpp +) +target_link_libraries( + Viewfinder + PUBLIC + CommonUI +) diff --git a/src/ui/viewfinder/README.md b/src/ui/viewfinder/README.md new file mode 100644 index 0000000..e82a37b --- /dev/null +++ b/src/ui/viewfinder/README.md @@ -0,0 +1,2 @@ +## Viewfinder +Main viewfinder screen used to take pictures and videos. diff --git a/src/ui/viewfinder/viewfinder.cpp b/src/ui/viewfinder/viewfinder.cpp new file mode 100644 index 0000000..8265b3e --- /dev/null +++ b/src/ui/viewfinder/viewfinder.cpp @@ -0,0 +1,14 @@ +#include "viewfinder.h" + +#include + +#include "../../core/core.h" +#include "../common/common.h" + +Viewfinder::Viewfinder(std::shared_ptr appCore) : core(appCore) +{ + this->close_button = std::unique_ptr(new CloseButton(this->core, "X")); + this->add(*this->close_button); + + this->show_all(); +} diff --git a/src/ui/viewfinder.h b/src/ui/viewfinder/viewfinder.h similarity index 59% rename from src/ui/viewfinder.h rename to src/ui/viewfinder/viewfinder.h index 8293e8c..cefc29b 100644 --- a/src/ui/viewfinder.h +++ b/src/ui/viewfinder/viewfinder.h @@ -3,15 +3,16 @@ #include -#include "common/common.h" +#include "../common/common.h" +#include "../../core/core.h" class Viewfinder : public Gtk::Box { private: - Glib::RefPtr app; + std::shared_ptr core; std::unique_ptr close_button = nullptr; public: - Viewfinder(Glib::RefPtr appPtr); + Viewfinder(std::shared_ptr appCore); }; #endif // _VIEWFINDER_H