From 616fb291ee1f62202affbec3a043f741c2c2469c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Oct 2018 17:51:19 +0200 Subject: Login works and showing messages, nothing else --- include/Cache.hpp | 16 ++++++++++++ include/ChannelDataType.hpp | 16 ++++++++++++ include/ChatWindow.hpp | 15 ++++++++++++ include/LoginWindow.hpp | 6 ++++- include/Window.hpp | 24 ++++++++++-------- include/env.hpp | 59 +++++++++++++++++++++++++++++++++++++++++++++ include/types.hpp | 22 +++++++++++++++++ 7 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 include/Cache.hpp create mode 100644 include/ChannelDataType.hpp create mode 100644 include/env.hpp create mode 100644 include/types.hpp (limited to 'include') diff --git a/include/Cache.hpp b/include/Cache.hpp new file mode 100644 index 0000000..97ef495 --- /dev/null +++ b/include/Cache.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace dchat +{ + class Cache + { + public: + Cache(); + ~Cache(); + + // Creates directory if it doesn't exist (recursively). Throws boost exception on failure + static boost::filesystem::path getDchatDir(); + }; +} diff --git a/include/ChannelDataType.hpp b/include/ChannelDataType.hpp new file mode 100644 index 0000000..398e716 --- /dev/null +++ b/include/ChannelDataType.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "types.hpp" + +namespace dchat +{ + enum class ChannelDataType : u8 + { + ADD_MESSAGE, + EDIT_MESSAGE, + DELETE_MESSAGE, + NICKNAME_CHANGE, + CHANGE_AVATAR, + CHANGE_CHANNEL_NAME, + }; +} \ No newline at end of file diff --git a/include/ChatWindow.hpp b/include/ChatWindow.hpp index 2d45b76..b13046e 100644 --- a/include/ChatWindow.hpp +++ b/include/ChatWindow.hpp @@ -1,12 +1,14 @@ #pragma once #include +#include #include #include #include #include #include #include +#include namespace dchat { @@ -14,6 +16,8 @@ namespace dchat { public: ChatWindow(); + void addChannel(const odhtdb::Hash &nodeHash); + void addLocalMessage(const odhtdb::Hash &channelId, Glib::ustring msg); private: void setupTopBar(); void setupLeftPanel(Gtk::Paned *sidePanels); @@ -22,8 +26,19 @@ namespace dchat private: Gtk::Grid topbar; Gtk::Entry topbarSearchBar; + Gtk::Grid leftPanelChannels; Gtk::Label currentChannelTitle; Gtk::ScrolledWindow chatArea; + Gtk::Grid chatAreaLayout; Gtk::TextView chatInput; + + struct ChannelData + { + Gtk::Button *button; + int messageCount; + }; + + odhtdb::MapHash channelDataById; + int channelCount; }; } \ No newline at end of file diff --git a/include/LoginWindow.hpp b/include/LoginWindow.hpp index b60dddb..b842eb5 100644 --- a/include/LoginWindow.hpp +++ b/include/LoginWindow.hpp @@ -7,15 +7,19 @@ namespace dchat { + using LoginHandler = std::function; + class LoginWindow : public Gtk::Grid { public: LoginWindow(); - void setLoginHandler(std::function loginHandler); + void setLoginHandler(LoginHandler loginHandler); private: Gtk::Entry usernameInput; Gtk::Entry passwordInput; Gtk::Button loginButton; + std::function loginHandler; + LoginHandler loginHandlerUser; }; } \ No newline at end of file diff --git a/include/Window.hpp b/include/Window.hpp index 2810bbd..96197c6 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -4,17 +4,21 @@ #include "LoginWindow.hpp" #include #include +#include +#include namespace dchat { - class Window : public Gtk::Window - { - public: - Window(); - virtual ~Window(); - protected: - Gtk::Stack stack; - LoginWindow loginWindow; - ChatWindow chatWindow; - }; + class Window : public Gtk::Window + { + public: + Window(); + virtual ~Window(); + protected: + std::unique_ptr database; + std::mutex databaseCallbackMutex; + Gtk::Stack stack; + LoginWindow loginWindow; + ChatWindow chatWindow; + }; } \ No newline at end of file diff --git a/include/env.hpp b/include/env.hpp new file mode 100644 index 0000000..abaedd8 --- /dev/null +++ b/include/env.hpp @@ -0,0 +1,59 @@ +#pragma once + +#define OS_FAMILY_WINDOWS 0 +#define OS_FAMILY_POSIX 1 + +#define OS_TYPE_WINDOWS 0 +#define OS_TYPE_LINUX 1 + +#if defined(_WIN32) || defined(_WIN64) + #if defined(_WIN64) + #define SYS_ENV_64BIT + #else + #define SYS_ENV_32BIT + #endif + #define OS_FAMILY OS_FAMILY_WINDOWS + #define OS_TYPE OS_TYPE_WINDOWS + + #ifndef UNICODE + #define UNICODE + #endif + + #ifndef _UNICODE + #define _UNICODE + #endif + + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + + #include +#endif + +#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) || defined(_POSIX_VERSION) + #define OS_FAMILY OS_FAMILY_POSIX +#endif + +#ifdef __linux__ + #define OS_TYPE OS_TYPE_LINUX +#endif + +#if defined(__GNUC__) + #if defined(__x86_64__) || defined(__pc64__) + #define SYS_ENV_64BIT + #else + #define SYS_ENV_32BIT + #endif +#endif + +#if !defined(SYS_ENV_32BIT) && !defined(SYS_ENV_64BIT) + #error "System is not detected as either 32-bit or 64-bit" +#endif + +#if !defined(OS_FAMILY) + #error "System not supported. Only Windows and Posix systems supported right now" +#endif + +#if !defined(OS_TYPE) + #error "System not supported. Only Windows and linux systems supported right now" +#endif diff --git a/include/types.hpp b/include/types.hpp new file mode 100644 index 0000000..762dab1 --- /dev/null +++ b/include/types.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace dchat +{ + typedef int8_t i8; + typedef int16_t i16; + typedef int32_t i32; + typedef int64_t i64; + + typedef uint8_t u8; + typedef uint16_t u16; + typedef uint32_t u32; + typedef uint64_t u64; + + typedef float f32; + typedef double f64; + + typedef intptr_t ssize; + typedef uintptr_t usize; +} -- cgit v1.2.3