Skip to content

Commit

Permalink
merge for avatars and cmd line args
Browse files Browse the repository at this point in the history
  • Loading branch information
High-Voltaged committed Feb 5, 2022
2 parents 4583f29 + 3e44f41 commit 856c0ef
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 12 deletions.
Binary file added client/data/img/user-avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user-avatar2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user-avatar3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user_avatars/avatar1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user_avatars/avatar2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user_avatars/avatar3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/data/img/user_avatars/avatar4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion client/data/styles/leftbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,33 @@
}

.chatlist_item_avatar {
background-color: yellow;
/* background-color: yellow; */
/*PINK*/
/* background-color: rgb(233, 30, 99); */
/*AMBER*/
/* background-color: rgb(255, 193, 7); */
/*YELLOW*/
/* background-color: rgb(255, 235, 59); */
/*LIME*/
/* background-color: rgb(205, 220, 57); */
/*CYAN*/
/* background-color: rgb(0, 188, 212); */
/*ORANGE*/
/* background-color: rgb(255, 152, 0); */
/*GREEN*/
/* background-color: rgb(76, 175, 80); */
/* LIGHT GREEN */
/* background-color: rgb(139, 195, 74); */
/*DEEP PURPLE*/
/* background-color: rgb(103, 58, 183); */
/* PURPLE */
background-color: rgb(156, 39, 176);
/* background-image: url("../img/user-avatar4.png"); */
/* background-size: 25px 25px; */
/* background-size: contain;
background-position: 50% 50%;
background-repeat: no-repeat; */

border-radius: 50%;
}

Expand Down
5 changes: 5 additions & 0 deletions client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <arpa/inet.h>
#include <pthread.h>
#include <gtk/gtk.h>
#include <cairo.h>

#ifdef __MACH__
#include "../../libraries/openssl/openssl/ssl.h"
Expand Down Expand Up @@ -54,6 +55,9 @@ void destroy_popup_window(GtkWidget *widget, gpointer chat_screen);
void build_authorizatioin_window();
void build_chat_window();

//DRAW AVATAR
gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data);

//AUTH
void build_login_menu();
void build_signup_menu();
Expand Down Expand Up @@ -180,6 +184,7 @@ void send_button_click(GtkWidget *widget, gpointer new_message_field);

void build_change_password_window(GtkWidget *widget, gpointer data);
void build_change_login_window(GtkWidget *widget, gpointer data);
void build_change_avatar_window(GtkWidget *widget, gpointer data);
void build_change_chat_name_window(GtkWidget *widget, gpointer data);

void leave_chat_btn_click(GtkWidget *widget, gpointer data);
Expand Down
80 changes: 80 additions & 0 deletions client/src/gui/build_change_avatar_window.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "../../inc/client.h"

void change_avatar_btn_click(GtkWidget *widget, gpointer data) {
GtkWidget *toplevel = gtk_widget_get_toplevel(widget);
(void)data;

GtkWidget *path_field = get_widget_by_name_r(toplevel, "path_field");
GtkWidget *path_notify_label = get_widget_by_name_r(toplevel, "path_notify_label");

char *new_avatar = (char*)gtk_entry_get_text(GTK_ENTRY(path_field));

handle_update_user_image(new_avatar);
handle_get_user_image(utils->current_user->user_id, &utils->current_user->avatar_path);

gtk_widget_destroy(toplevel);
}

void build_change_avatar_window(GtkWidget *widget, gpointer data) {
if (widget){};
(void)data;

GtkWidget *popup_window = create_popup_window(450, 0);
GtkWidget *change_login_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

gtk_container_add(GTK_CONTAINER(popup_window), change_login_box);
add_class(change_login_box, "popup_menu");

GtkWidget *change_avatar_title = gtk_label_new("Change avatar");
gtk_widget_set_halign(GTK_WIDGET(change_avatar_title), GTK_ALIGN_CENTER);
add_class(change_avatar_title, "popup_window_title");

GtkWidget *path_label = gtk_label_new("New avatar path:");
gtk_widget_set_halign(GTK_WIDGET(path_label), GTK_ALIGN_START);
add_class(path_label, "input-field_title");
GtkWidget *path_field = gtk_entry_new();
gtk_widget_set_name(path_field, "path_field");
gtk_entry_set_placeholder_text(GTK_ENTRY(path_field), "Avatar path");
// g_signal_connect(G_OBJECT(path_field), "focus-out-event", G_CALLBACK(focus_out_login_field), NULL);
add_class(path_field, "input-field");
add_class(path_field, "input-field--name");

GtkWidget *path_notify_label = gtk_label_new(" ");
gtk_widget_set_halign(path_notify_label, GTK_ALIGN_START);
gtk_widget_set_name(path_notify_label, "path_notify_label");
add_class(path_notify_label, "notify-label");

//btn box
GtkWidget *btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_widget_set_halign(GTK_WIDGET(btn_box), GTK_ALIGN_CENTER);
add_class(btn_box, "popup_btn_box");

GtkWidget *change_login_btn = gtk_button_new_with_label("Submit");
gtk_widget_set_size_request(GTK_WIDGET(change_login_btn), 150, 50);
g_signal_connect(G_OBJECT(change_login_btn), "enter-notify-event", G_CALLBACK(on_crossing), NULL);
g_signal_connect(G_OBJECT(change_login_btn), "leave-notify-event", G_CALLBACK(on_crossing), NULL);
g_signal_connect(G_OBJECT(change_login_btn), "clicked", G_CALLBACK(change_avatar_btn_click), NULL);
add_class(change_login_btn, "btn");
add_class(change_login_btn, "btn--blue");

GtkWidget *cancel_btn = gtk_button_new_with_label("Cancel");
gtk_widget_set_size_request(GTK_WIDGET(cancel_btn), 150, 50);
g_signal_connect(G_OBJECT(cancel_btn), "enter-notify-event", G_CALLBACK(on_crossing), NULL);
g_signal_connect(G_OBJECT(cancel_btn), "leave-notify-event", G_CALLBACK(on_crossing), NULL);
g_signal_connect(G_OBJECT(cancel_btn), "clicked", G_CALLBACK(destroy_popup_window), NULL);
add_class(cancel_btn, "btn");
add_class(cancel_btn, "btn--dark-blue");

gtk_box_pack_end(GTK_BOX(btn_box), change_login_btn, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(btn_box), cancel_btn, FALSE, FALSE, 0);
//

gtk_box_pack_start(GTK_BOX(change_login_box), change_avatar_title, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(change_login_box), path_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(change_login_box), path_field, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(change_login_box), path_notify_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(change_login_box), btn_box, FALSE, FALSE, 0);

gtk_widget_show_all(popup_window);
gtk_widget_grab_focus(popup_window);
}
6 changes: 6 additions & 0 deletions client/src/gui/build_change_login_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ void change_login_btn_click(GtkWidget *widget, gpointer data) {

int response_code = handle_edit_username_request(new_login);
handle_edit_username_response_code(response_code, login_field, login_notify_label);

if (response_code == R_SUCCESS)
{
GtkWidget *leftbar_footer_username = get_widget_by_name_r(main_window, "leftbar_footer_username");
gtk_label_set_text(GTK_LABEL(leftbar_footer_username), utils->current_user->name);
}
}

void build_change_login_window(GtkWidget *widget, gpointer data) {
Expand Down
7 changes: 5 additions & 2 deletions client/src/gui/build_chat_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void build_leftbar(GtkWidget *chat_screen)
GtkWidget *leftbar_footer = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
add_class(leftbar_footer, "leftbar_footer");

GtkWidget *user_avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *user_avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(user_avatar), 27, 27);
g_signal_connect(G_OBJECT(user_avatar), "draw", G_CALLBACK(draw_user_avatar), (gpointer)27); // Получить avatar пользовтеля
gtk_widget_set_halign(user_avatar, GTK_ALIGN_START);
gtk_widget_set_valign(user_avatar, GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(leftbar_footer), user_avatar, FALSE, FALSE, 0);
add_class(user_avatar, "chatlist_item_avatar");

GtkWidget *username = gtk_label_new(utils->current_user->name);
gtk_widget_set_name(username, "leftbar_footer_username");
Expand Down Expand Up @@ -106,6 +106,9 @@ void build_leftbar(GtkWidget *chat_screen)
GtkWidget *change_password_btn = gtk_menu_item_new_with_label("Change password");
g_signal_connect(change_password_btn, "activate", G_CALLBACK(build_change_password_window), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), change_password_btn);
GtkWidget *change_avatar_btn = gtk_menu_item_new_with_label("Change avatar");
g_signal_connect(change_avatar_btn, "activate", G_CALLBACK(build_change_avatar_window), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), change_avatar_btn);
GtkWidget *delete_account_btn = gtk_menu_item_new_with_label("Delete account");
g_signal_connect(delete_account_btn, "activate", G_CALLBACK(build_confirm_delete_account_window), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), delete_account_btn);
Expand Down
34 changes: 31 additions & 3 deletions client/src/gui/chatlist.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
#include "../../inc/client.h"

static gboolean da_expose(GtkWidget *widget, cairo_t *cr, gpointer data)
{
char* a = "client/data/img/user_avatars/avatar4.png";
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(a, 42, 42, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
g_object_unref(G_OBJECT(pixbuf));

double x = 0,
y = 0,
width = 42,
height = 42,
aspect = 1.0, /* aspect ratio */
corner_radius = height / 2.0; /* and corner curvature radius */
double radius = corner_radius / aspect;
double degrees = 3.14159265358979 / 180.0;

cairo_new_sub_path (cr);
cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
cairo_close_path (cr);

cairo_fill(cr);
if (widget) {}
return FALSE;
}

void add_chatlist_item(int id, char *chat_name)
{
GtkWidget *chatlist_container = get_widget_by_name_r(main_window, "chatlist");
Expand All @@ -24,10 +52,10 @@ void add_chatlist_item(int id, char *chat_name)
add_class(chatlist_item_id, "hidden");
gtk_box_pack_start(GTK_BOX(chatlist_item), chatlist_item_id, FALSE, FALSE, 0);

// GtkWidget *avatar = gtk_drawing_area_new();
GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *avatar = gtk_drawing_area_new();
// GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 42, 42);
// g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (gpointer)(intptr_t)list->avatar); // Получить avatar пользовтеля
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(da_expose), NULL); // Получить avatar пользовтеля
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
add_class(avatar, "chatlist_item_avatar");
Expand Down
31 changes: 31 additions & 0 deletions client/src/gui/draw_avatar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "../../inc/client.h"

gboolean draw_user_avatar(GtkWidget *widget, cairo_t *cr, gpointer data)
{
if (widget) {}
// (void)data;
int size = (int)data;
// char* a = utils->current_user->avatar_path;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale(utils->current_user->avatar_path, size, size, FALSE, NULL); // get_pixbuf_with_size(a, 34, 34);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
g_object_unref(G_OBJECT(pixbuf));

double x = 0,
y = 0,
width = size,
height = size,
aspect = 1.0, /* aspect ratio */
corner_radius = height / 2.0; /* and corner curvature radius */
double radius = corner_radius / aspect;
double degrees = 3.14159265358979 / 180.0;

cairo_new_sub_path (cr);
cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
cairo_close_path (cr);

cairo_fill(cr);
return FALSE;
}
4 changes: 2 additions & 2 deletions client/src/gui/join_chat_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void add_join_chat_item(int id, char *chat_name)

// GtkWidget *avatar = gtk_drawing_area_new();
GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 34, 34);
gtk_widget_set_size_request(GTK_WIDGET(avatar), 42, 42);
// g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (gpointer)(intptr_t)list->avatar); // Получить avatar пользовтеля
gtk_widget_set_halign(avatar, GTK_ALIGN_START);
gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
Expand All @@ -60,7 +60,7 @@ void add_join_chat_item(int id, char *chat_name)
add_class(chatlist_item_text, "chatlist_item_text");

GtkWidget *chatlist_item_title = gtk_label_new(chat_name);
// gtk_widget_set_name(chatlist_item_title, "chat_name");
add_class(chatlist_item_title, "chatlist_item_title");
gtk_widget_set_halign(GTK_WIDGET(chatlist_item_title), GTK_ALIGN_START);
gtk_box_pack_start(GTK_BOX(chatlist_item_text), chatlist_item_title, false, false, 0);

Expand Down
6 changes: 2 additions & 4 deletions client/src/gui/update_chat_field.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "../../inc/client.h"



void add_message(t_msg *message) {
GtkWidget *chat_field = get_widget_by_name_r(main_window, "chat_field");

Expand All @@ -14,14 +12,14 @@ void add_message(t_msg *message) {
add_class(message_box, "msg_box");
gtk_box_pack_start(GTK_BOX(chat_field), message_box, FALSE, FALSE, 0);

GtkWidget *avatar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *avatar = gtk_drawing_area_new();
gtk_widget_set_size_request(GTK_WIDGET(avatar), 27, 27);
g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_user_avatar), (gpointer)27); // Получить avatar пользовтеля
gtk_widget_set_halign(avatar, cur_user ? GTK_ALIGN_START : GTK_ALIGN_END);
gtk_widget_set_valign(avatar, GTK_ALIGN_START);
if (!cur_user) {
gtk_box_pack_start(GTK_BOX(message_box), avatar, FALSE, FALSE, 0);
}
add_class(avatar, "chatlist_item_avatar");

GtkWidget *message_text = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_halign(GTK_WIDGET(message_text), cur_user ? GTK_ALIGN_START : GTK_ALIGN_END);
Expand Down

0 comments on commit 856c0ef

Please sign in to comment.