diff --git a/client-frontend/dragon-tea/CMakeLists.txt b/client-frontend/dragon-tea/CMakeLists.txt index 8f2aaeb..179d289 100644 --- a/client-frontend/dragon-tea/CMakeLists.txt +++ b/client-frontend/dragon-tea/CMakeLists.txt @@ -13,10 +13,19 @@ pkg_check_modules(libnotify REQUIRED libnotify) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) -file(GLOB_RECURSE DRAGONTEA_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c" - "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB_RECURSE DRAGONTEA_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB_RECURSE DRAGONTEA_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/src/teauilib/*.c") -add_executable(dragontea) +list(APPEND DRAGONTEA_SOURCES ${DRAGONTEA_HEADERS}) + +add_library(dragontea SHARED) +add_executable(exec ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${DRAGONTEA_HEADERS}) + +set_target_properties(dragontea PROPERTIES OUTPUT_NAME "teauilib") +set_target_properties(exec PROPERTIES OUTPUT_NAME "dragontea") + +target_compile_definitions(dragontea PRIVATE TEA_COMPILLING) # COMPILE BUILTIN SERVERS set(BUILTIN_TEMPLATE_FILE "${CMAKE_BINARY_DIR}/builtin_template.c") @@ -44,7 +53,7 @@ if(EXISTS "${BUILTIN_TEMPLATE_FILE}") BUILTIN_SERVERS_N=${BF_LENGTH}) endif() -target_sources(dragontea PUBLIC ${DRAGONTEA_SOURCES}) +target_sources(dragontea PRIVATE ${DRAGONTEA_SOURCES}) target_include_directories( dragontea @@ -52,10 +61,14 @@ target_include_directories( ${gthread_INCLUDE_DIRS} ${libcurl_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${libnotify_INCLUDE_DIRS}) +target_include_directories(exec PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/) + target_link_libraries( dragontea ${gtk3ui_LIBRARIES} ${libcurl_LIBRARIES} ${json_LIBRARIES} ${gthread_LIBRARIES} ${libnotify_LIBRARIES}) +target_link_libraries(exec dragontea) + target_compile_definitions(dragontea PUBLIC DRAGON_TEA_VERSION="${DRAGON_TEA_VERSION}") @@ -68,5 +81,7 @@ if(UNIX OR LINUX) DESTINATION "${CMAKE_INSTALL_PREFIX}/share") install(FILES "${CMAKE_BINARY_DIR}/dragontea" - DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/") + DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/ + ") + endif() diff --git a/client-frontend/dragon-tea/include/tea_main.h b/client-frontend/dragon-tea/include/tea_main.h new file mode 100644 index 0000000..ee52dce --- /dev/null +++ b/client-frontend/dragon-tea/include/tea_main.h @@ -0,0 +1,26 @@ +#pragma once + +// MSVC/MinGW Compiller +#if _MSC_VER || WIN32 +#define API_EXPORT __declspec(dllexport) +#define API_IMPORT __declspec(dllimport) +#elif __linux__ || __unix__ +// Linux/Unix GNU Compiller +#if defined(__GNUC__) && __GNUC__ >= 4 +#define __GCCAPI__ __attribute__((visibility("default"))) +#else +#define __GCCAPI__ +#endif + +#define API_EXPORT __GCCAPI__ +#define API_IMPORT __GCCAPI__ + +#endif + +#ifdef TEA_COMPILLING +#define TEA_API API_EXPORT +#else +#define TEA_API API_IMPORT +#endif + +int TEA_API tea_main(int argc, char *argv[]); diff --git a/client-frontend/dragon-tea/src/main.c b/client-frontend/dragon-tea/src/main.c index dd58ae6..3215366 100644 --- a/client-frontend/dragon-tea/src/main.c +++ b/client-frontend/dragon-tea/src/main.c @@ -1,79 +1,8 @@ -#include +#include -#include "tea.h" - -#define USE_ONCE_LAUNCH 0 - -#if USE_ONCE_LAUNCH -#include -#define TSEM_KNAME "dragon_tea_lock" -#endif +#include "tea_main.h" int main(int argc, char *argv[]) { - setlocale(LC_ALL, ""); - - bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR); - textdomain(DRAGON_TEA_TEXTDOMAIN); - -// Check runned on Root -#ifdef TEA_OS_LINUX - if(getuid() == 0) - { - printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing.")); - return EXIT_FAILURE; - } -#endif - - // GUI Init - gtk_init(&argc, &argv); - -#if USE_ONCE_LAUNCH - // Check is only one copy runs - sem_t *sem; - - sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1); - if(sem == SEM_FAILED) - { - ui_error("Program already launched."); - return EXIT_FAILURE; - } - - if(sem_wait(sem) == -1) - { - perror("sem_wait"); - return EXIT_FAILURE; - } -#endif - - // Run Dragon Tea Messenger - tea_init(); - - // Window Looping - gtk_main(); - - // Free Unused resources DTM - tea_free(); - -#if USE_ONCE_LAUNCH - // Close launch - if(sem_post(sem) == -1) - { - perror("sem_post"); - return EXIT_FAILURE; - } - if(sem_close(sem) == -1) - { - perror("sem_close"); - return EXIT_FAILURE; - } - - if(sem_unlink(TSEM_KNAME) == -1) - { - perror("sem_unlink"); - return EXIT_FAILURE; - } -#endif - - return EXIT_SUCCESS; + return tea_main(argc, argv); } diff --git a/client-frontend/dragon-tea/src/core/ui.c b/client-frontend/dragon-tea/src/teauilib/core/ui.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui.c rename to client-frontend/dragon-tea/src/teauilib/core/ui.c diff --git a/client-frontend/dragon-tea/src/core/ui_about.c b/client-frontend/dragon-tea/src/teauilib/core/ui_about.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui_about.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_about.c diff --git a/client-frontend/dragon-tea/src/core/ui_authorize.c b/client-frontend/dragon-tea/src/teauilib/core/ui_authorize.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui_authorize.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_authorize.c diff --git a/client-frontend/dragon-tea/src/core/ui_callbacks.c b/client-frontend/dragon-tea/src/teauilib/core/ui_callbacks.c similarity index 98% rename from client-frontend/dragon-tea/src/core/ui_callbacks.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_callbacks.c index 9f7e48f..45aa80c 100644 --- a/client-frontend/dragon-tea/src/core/ui_callbacks.c +++ b/client-frontend/dragon-tea/src/teauilib/core/ui_callbacks.c @@ -144,7 +144,7 @@ gboolean on_chat_message_handler_async(gpointer) if(last_chance_state != CHANCE_TO_LOGOUT) strcpy(buffer, _("Your network has been restored. ")); else - buffer[0] = NULL; + buffer[0] = '\0'; strcat(buffer, _("You're online.")); tea_ui_chat_status_text(buffer); @@ -174,7 +174,7 @@ gboolean on_chat_message_handler_async(gpointer) { gnotify = notify_notification_new( message->sent_user_name, message->message_text, gtk_window_get_icon_name(widgets.main_window)); - notify_notification_add_action(gnotify, "custom_action", _("Read message"), notify_action, NULL, NULL); + notify_notification_add_action(gnotify, "custom_action", _("Read message"), (NotifyActionCallback) notify_action, NULL, NULL); if(!env.old_notify_remove) notify_notification_set_timeout(gnotify, 0); diff --git a/client-frontend/dragon-tea/src/core/ui_chat.c b/client-frontend/dragon-tea/src/teauilib/core/ui_chat.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui_chat.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_chat.c diff --git a/client-frontend/dragon-tea/src/core/ui_logs.c b/client-frontend/dragon-tea/src/teauilib/core/ui_logs.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui_logs.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_logs.c diff --git a/client-frontend/dragon-tea/src/core/ui_settings.c b/client-frontend/dragon-tea/src/teauilib/core/ui_settings.c similarity index 100% rename from client-frontend/dragon-tea/src/core/ui_settings.c rename to client-frontend/dragon-tea/src/teauilib/core/ui_settings.c diff --git a/client-frontend/dragon-tea/src/net/tea_net_api.c b/client-frontend/dragon-tea/src/teauilib/net/tea_net_api.c similarity index 100% rename from client-frontend/dragon-tea/src/net/tea_net_api.c rename to client-frontend/dragon-tea/src/teauilib/net/tea_net_api.c diff --git a/client-frontend/dragon-tea/src/tea.c b/client-frontend/dragon-tea/src/teauilib/tea.c similarity index 100% rename from client-frontend/dragon-tea/src/tea.c rename to client-frontend/dragon-tea/src/teauilib/tea.c diff --git a/client-frontend/dragon-tea/src/teauilib/teauilib.c b/client-frontend/dragon-tea/src/teauilib/teauilib.c new file mode 100644 index 0000000..a8ea8f5 --- /dev/null +++ b/client-frontend/dragon-tea/src/teauilib/teauilib.c @@ -0,0 +1,81 @@ +#include + +#include "tea_main.h" + +#include "tea.h" + +#define USE_ONCE_LAUNCH 0 + +#if USE_ONCE_LAUNCH +#include +#define TSEM_KNAME "dragon_tea_lock" +#endif + +int TEA_API tea_main(int argc, char *argv[]) +{ + setlocale(LC_ALL, ""); + + bindtextdomain(DRAGON_TEA_TEXTDOMAIN, DRAGON_TEA_LOCALE_DIR); + textdomain(DRAGON_TEA_TEXTDOMAIN); + +// Check runned on Root +#ifdef TEA_OS_LINUX + if(getuid() == 0) + { + printf(_("The program is running as root. These privileges can harm the system, please be aware of this. Closing.")); + return EXIT_FAILURE; + } +#endif + + // GUI Init + gtk_init(&argc, &argv); + +#if USE_ONCE_LAUNCH + // Check is only one copy runs + sem_t *sem; + + sem = sem_open(TSEM_KNAME, O_CREAT | O_EXCL, 0644, 1); + if(sem == SEM_FAILED) + { + ui_error("Program already launched."); + return EXIT_FAILURE; + } + + if(sem_wait(sem) == -1) + { + perror("sem_wait"); + return EXIT_FAILURE; + } +#endif + + // Run Dragon Tea Messenger + tea_init(); + + // Window Looping + gtk_main(); + + // Free Unused resources DTM + tea_free(); + +#if USE_ONCE_LAUNCH + // Close launch + if(sem_post(sem) == -1) + { + perror("sem_post"); + return EXIT_FAILURE; + } + if(sem_close(sem) == -1) + { + perror("sem_close"); + return EXIT_FAILURE; + } + + if(sem_unlink(TSEM_KNAME) == -1) + { + perror("sem_unlink"); + return EXIT_FAILURE; + } +#endif + + return EXIT_SUCCESS; +}