Skip to content

Commit

Permalink
Fix client API
Browse files Browse the repository at this point in the history
Fix some bug

Signed-off-by: badcast <lmecomposer@gmail.com>
  • Loading branch information
badcast committed Jan 10, 2024
1 parent 26cb7e8 commit 7a83137
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 127 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.10)

project(
DragonTea
VERSION ${DRAGON_TEA_VERSION}
LANGUAGES C)

add_subdirectory(client-frontend/dragon-tea)
5 changes: 0 additions & 5 deletions client-frontend/dragon-tea/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" DRAGON_TEA_VERSION)

string(STRIP "${DRAGON_TEA_VERSION}" DRAGON_TEA_VERSION)

project(
DragonTea
VERSION ${DRAGON_TEA_VERSION}
LANGUAGES C)

find_package(PkgConfig REQUIRED)
pkg_check_modules(gtk3ui REQUIRED gtk+-3.0)
pkg_check_modules(libcurl REQUIRED libcurl)
Expand Down
3 changes: 1 addition & 2 deletions client-frontend/dragon-tea/include/tea.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef DWORD uid_t;
#endif

extern struct tea_net_stats net_stats;
extern struct tea_server_info cur_server;
extern struct tea_settings app_settings;
extern struct tea_app_widgets widgets;

Expand Down Expand Up @@ -114,8 +115,6 @@ int net_api_signin(tea_id_t user_id, tea_login_result *output);

int net_api_signup(const char *nickname, tea_register_result *output);

int net_api_server_info(struct tea_server_info *serverInfo);

void tea_log(const char *message);

void tea_clear_log();
Expand Down
9 changes: 5 additions & 4 deletions client-frontend/dragon-tea/include/tea_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ enum TeaErrorStatus
};

const char *tea_url_server();
const char *tea_url_server_auth();
const char *tea_url_server_register();
const char *tea_url_server_message_handler();
const char *tea_url_server_info();

int tea_switch_server(int newServerID);

int tea_fetch_server();

void tea_read_urls(struct tea_server_urls *wrData);

#endif
24 changes: 23 additions & 1 deletion client-frontend/dragon-tea/include/tea_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ struct tea_net_stats
int error_req;
};

struct tea_server_urls
{
char url[255];
char url_auth[255];
char url_reg[255];
char url_msg_handler[255];
char url_info[255];
};

// Server features
enum
{
// Server can get information
SV_VERFI = 1,
// Server can get First or Last MsgID
SV_MSGFL = 2,
};

struct tea_server_info
{
struct
Expand All @@ -76,7 +94,11 @@ struct tea_server_info
} server_version;

char maintainer[32];
char license[32];
char license[16];

int features;

struct tea_server_urls urls;
};

typedef struct
Expand Down
4 changes: 2 additions & 2 deletions client-frontend/dragon-tea/src/core/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ void tea_ui_init()
g_object_unref(icon_buf);
}

show_log_dialog();

// Init main window
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(main_window), _("Dragon Tea"));
Expand Down Expand Up @@ -77,6 +75,8 @@ void tea_ui_init()
// Probe auto sign in if the exists
tea_try_login();
tea_ui_focus_tab(UI_TAB_AUTH);

show_log_dialog();
}

void tea_ui_update_settings()
Expand Down
14 changes: 0 additions & 14 deletions client-frontend/dragon-tea/src/core/ui_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

void on_entry_edit_message(GtkEntry *entry, gpointer data)
{
// Кнопка отправить доступна, когда длина текста сообщений больше 0
gtk_widget_set_sensitive(widgets.chat_tab.button_send, gtk_entry_get_text_length(entry) > 0);
}

Expand All @@ -14,18 +13,12 @@ void on_button_logout(GtkButton *button, gpointer data)

GtkWidget *create_chat_widget()
{
// Создание верхнего уровня окна
GtkWidget *place_widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
// Создание верхнего статуса
GtkWidget *top_horz_box = widgets.chat_tab.top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
// Создание вертикального контейнера (GtkBox)
GtkWidget *vertical_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
// Создание горизонтального контейнера (GtkBox)
GtkWidget *horizontal_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
// Создание контейнер статуса
GtkWidget *status_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);

// Создание верхнего поля отображение информаций
gtk_box_pack_start(
GTK_BOX(top_horz_box),
widgets.chat_tab.top_button_logout = gtk_button_new_from_icon_name("system-log-out", GTK_ICON_SIZE_BUTTON),
Expand All @@ -37,7 +30,6 @@ GtkWidget *create_chat_widget()
gtk_box_pack_start(GTK_BOX(top_horz_box), widgets.chat_tab.top_label_user_state = gtk_label_new(NULL), FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(place_widget), top_horz_box, FALSE, TRUE, 0);

// Создание текстового поля (GtkTextView) и установка его в вертикальный контейнер
GtkWidget *scrolled_text = widgets.chat_tab.scrolled_window_chat = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_text), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_text), GTK_SHADOW_IN);
Expand All @@ -47,32 +39,26 @@ GtkWidget *create_chat_widget()
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_CHAR);
gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);

// init tags
gtk_container_add(GTK_CONTAINER(scrolled_text), text_view);

gtk_box_pack_start(GTK_BOX(vertical_box), scrolled_text, TRUE, TRUE, 10);

// Создание поля ввода текста (GtkEntry)
GtkWidget *entry = widgets.chat_tab.entry_message_set = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(horizontal_box), entry, TRUE, TRUE, 0);
gtk_entry_set_max_length(GTK_ENTRY(entry), TEA_MAXLEN_MESSAGE - 1);
g_signal_connect(entry, "activate", G_CALLBACK(on_chat_send_button), entry);
g_signal_connect(entry, "changed", G_CALLBACK(on_entry_edit_message), NULL);

// Создание кнопки для отправки
GtkWidget *button = widgets.chat_tab.button_send = gtk_button_new();
gtk_widget_set_sensitive(button, FALSE);
gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_icon_name("mail-send-symbolic", GTK_ICON_SIZE_BUTTON));

gtk_box_pack_start(GTK_BOX(horizontal_box), button, FALSE, FALSE, 0);

// Подключение обработчика сигнала "clicked" (нажатие кнопки)
g_signal_connect(button, "clicked", G_CALLBACK(on_chat_send_button), entry);

// Добавление вертикального контейнера в окно
gtk_box_pack_end(GTK_BOX(place_widget), vertical_box, TRUE, TRUE, 0);

// Добавление горизонтального контейнера в вертикальный контейнер
gtk_box_pack_start(GTK_BOX(vertical_box), horizontal_box, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(vertical_box), status_box, FALSE, FALSE, 0);

Expand Down
6 changes: 5 additions & 1 deletion client-frontend/dragon-tea/src/core/ui_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ void tea_ui_clear_buffer(GtkWidget *, gpointer)

void show_log_dialog()
{
gint x, y, w;
gtk_window_get_position(widgets.main_window, &x, &y);
gtk_window_get_size(widgets.main_window, &w, NULL);

GtkWindow *log_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(log_window, 300, 400);

gtk_window_move(log_window, x + w, y);
GtkBox *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

GtkWidget *scrolled_text = gtk_scrolled_window_new(NULL, NULL);
Expand Down
5 changes: 4 additions & 1 deletion client-frontend/dragon-tea/src/core/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ void apply_changes()
tea_logout();

int selected = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets.settings_tab.combx_server_list));
app_settings.active_server = tea_get_server_id(app_settings.servers[selected]);

// Switch server
tea_switch_server(tea_get_server_id(app_settings.servers[selected]));

tea_ui_focus_tab(UI_TAB_AUTH);
tea_try_login();
}
Expand Down
Loading

0 comments on commit 7a83137

Please sign in to comment.