Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
A lot of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar Taran committed Feb 11, 2021
1 parent 6fdcf43 commit fed15c1
Show file tree
Hide file tree
Showing 946 changed files with 222 additions and 179,676 deletions.
8 changes: 0 additions & 8 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 25,6 @@ GTK_LINK_FLAGS = `pkg-config --cflags --libs gtk -3.0`
SDL_INC_FLAGS = -rpath ./frameworks -F ../frameworks \
-framework SDL2 \
-framework SDL2_mixer \
-I ../frameworks/Gtk3.framework/include \
-I ../frameworks/Gtk3.framework/include/atk-1.0 \
-I ../frameworks/Gtk3.framework/include/cairo \
-I ../frameworks/Gtk3.framework/include/gdk-pixbuf-2.0 \
-I ../frameworks/Gtk3.framework/include/gtk-3.0 \
-I ../frameworks/Gtk3.framework/include/glib-2.0 \
-I ../frameworks/Gtk3.framework/include/pango-1.0 \
-I ../frameworks/Gtk3.framework/lib/glib-2.0/include \
-I ../frameworks/SDL2.framework/SDL2 \
-I ../frameworks/SDL2_mixer.framework/Headers

Expand Down
Binary file modified client/data/pokemon-audio/9.wav
Binary file not shown.
6 changes: 5 additions & 1 deletion client/inc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 102,8 @@ struct {
GtkWidget *notificaton;
char *app;
char *user;
char *id;
GApplication *application;
} t_application;

struct // Structure for current user account data
Expand Down Expand Up @@ -294,6 296,7 @@ void get_user(t_user*);
void free_user(t_user*);
void get_chat(t_chat_data*);
void chat_clear_list(t_chat_list**);
void free_uchat();

void load_providers();
void test_autofill();
Expand All @@ -316,7 319,7 @@ void create_gallery(GtkWidget *main);
void create_stickerlist(GtkWidget *main);
void creator_group(GtkWidget *main);
void creator_userprofile(GtkWidget *main, t_user *user, int);
void creator_groupsettings(GtkWidget *main, char *name, bool admin);
void creator_groupsettings(GtkWidget *main, char *name, int chat_id);
void create_notification(GtkWidget *widget, char *text, short type, int x, int y, int w, int h);

char *get_avatar_by_number(int num);
Expand Down Expand Up @@ -368,6 371,7 @@ void arrow_click(GtkWidget *widget, GdkEventButton *event);
void chat_push_back(t_chat_list **list, t_chat_data* chat);
void person_click(GtkWidget *widget, GdkEventButton *event);
void msggroup_click(GtkWidget *widget, GdkEventButton *event, gpointer main);
void userprofile_remove_click(GtkWidget *widget, GdkEventButton *event, gpointer chat_id);

void username_field_change_event(GtkWidget *widget);
void firstname_field_change_event(GtkWidget *widget);
Expand Down
22 changes: 14 additions & 8 deletions client/src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,16 @@ void tooltip(char *str, void *data) {
gtk_widget_set_tooltip_text(data, str);
}

void free_uchat() {
// free(tm_struct); // Freeing time&date struct
mx_strdel(&t_account.username);
mx_strdel(&t_account.password);
mx_strdel(&msg_data.date_prev);
mx_strdel(&msg_data.date);
mx_strdel(&msg_data.time);
mx_strdel(&msg_data.username);
}

static void before_exit_jobs() {
upd_data.suspend = true;// Forbid to getting updates

Expand All @@ -19,16 29,11 @@ static void before_exit_jobs() {
mx_strdel(&result);
cJSON_Delete(json_offline);

//g_object_unref(icon); // Destroying icon
// g_object_unref(t_application.icon); // Destroying icon
Mix_CloseAudio(); // Closing SDL Mixer
SDL_Quit(); // Closing SDL
// free(tm_struct); // Freeing time&date struct
mx_strdel(&t_account.username);
mx_strdel(&t_account.password);
mx_strdel(&msg_data.date_prev);
mx_strdel(&msg_data.date);
mx_strdel(&msg_data.time);
mx_strdel(&msg_data.username);

free_uchat();
unsetenv("UCHAT_HOST");
unsetenv("UCHAT_PORT");
}
Expand All @@ -47,6 52,7 @@ int main(int argc, char *argv[]) {
gtk_init(&argc, &argv); // Initializing GTK
SDL_Init(SDL_INIT_AUDIO); // Initializing SDL
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048); // Initializing SDL Mixer
srand(time(NULL));

t_application.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); // Creating main window
gtk_window_set_title(GTK_WINDOW(t_application.window), "PokeChat"); // Setting window title
Expand Down
5 changes: 4 additions & 1 deletion client/src/client_auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,9 @@ void test_autofill()
t_msg.current = "here..."; // Имя выбранного пользователя в плейсхолдере
msg_data.content = NULL;

t_application.app = "PokeChat beta 0.9.7";
t_application.app = "PokeChat beta 0.9.9";
t_application.user = getenv("USER");
t_application.id = "org.ucode.uchat";
t_application.application = g_application_new(t_application.id, G_APPLICATION_FLAGS_NONE);
g_application_register(t_application.application, NULL, NULL);
}
184 changes: 58 additions & 126 deletions client/src/creator_groupsettings.c
Original file line number Diff line number Diff line change
@@ -1,93 1,29 @@
#include "../inc/client.h"

// static void remove_person(GtkWidget *widget, GdkEventButton *event, gpointer user_id) {
// if(event->type == GDK_BUTTON_PRESS && event->button == 1) {
// gtk_widget_destroy(GTK_WIDGET(widget));
// new_group->count = new_group->count - 1;
// int *temp = malloc(sizeof(int*) * new_group->count);
// for (int i = 0, j = 0; i < new_group->count 1; i )
// if (new_group->users_id[i] != (int)(intptr_t)user_id)
// temp[j ] = new_group->users_id[i];
// free(new_group->users_id);
// new_group->users_id = malloc(sizeof(int*) * new_group->count);
// for (int i = 0; i < new_group->count; i )
// new_group->users_id[i] = temp[i];
// free(temp);
// create_notification(t_application.messanger, "User deleted", 0, 461, 110, 420, 10);
// }
// }

// static GtkWidget *create_single_person(char *name, int avatar_id) {
// GtkWidget *single_event = gtk_event_box_new();
// gtk_widget_set_name(GTK_WIDGET(single_event), "crlist_person");
// gtk_event_box_set_above_child(GTK_EVENT_BOX(single_event), TRUE);

// GtkWidget *single = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
// gtk_widget_set_name(GTK_WIDGET(single), "crlist_person_h");
// gtk_container_add(GTK_CONTAINER(single_event), single);

// GtkWidget *avatar = gtk_drawing_area_new();
// gtk_widget_set_size_request(GTK_WIDGET(avatar), 34, 34);
// g_signal_connect(G_OBJECT(avatar), "draw", G_CALLBACK(draw_event_avatar), (gpointer)(intptr_t)avatar_id);
// gtk_widget_set_halign(avatar, GTK_ALIGN_START);
// gtk_widget_set_valign(avatar, GTK_ALIGN_CENTER);
// gtk_box_pack_start(GTK_BOX(single), avatar, FALSE, FALSE, 6);

// GtkWidget *nickname = gtk_label_new(name);
// gtk_widget_set_name(GTK_WIDGET(nickname), "nickname");
// gtk_box_pack_start(GTK_BOX(single), nickname, FALSE, FALSE, 5);

// return single_event;
// }

// static void add_person(GtkWidget *widget, GdkEventButton *event) {
// if(widget) {}
// if(event->type == GDK_BUTTON_PRESS && event->button == 1) {
// char *name = (char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY((GtkWidget*)new_group->search_field)));
// if(name != NULL)
// name = mx_del_extra_spaces(name);
// if(!strcmp(name, "") || !strcmp(name, " "))
// return;

// GList *parent = gtk_container_get_children(GTK_CONTAINER(t_msg.crlist));
// while(parent != NULL) {
// GList *children = gtk_container_get_children(GTK_CONTAINER(parent->data));
// GList *children2 = gtk_container_get_children(GTK_CONTAINER(children->data));
// children2 = children2->next;
// char* copy = (char*)gtk_label_get_text(GTK_LABEL(children2->data));

// g_list_free(g_steal_pointer(&children2));
// g_list_free(g_steal_pointer(&children));
// if(!strcmp(copy, name))
// return;
// parent = parent->next;
// }
// g_list_free(g_steal_pointer(&parent));

// int avatar = 0, user_id = 0;
// if (!add_user_to_group(name, &user_id, &avatar)) {
// create_notification(t_application.messanger, "Invalid username!", 1, 461, 110, 420, 10);
// return;
// }

// gtk_entry_set_text(GTK_ENTRY(new_group->search_field), "");
// GtkWidget *single = create_single_person(name, avatar);
// gtk_box_pack_start(GTK_BOX(t_msg.crlist), single, FALSE, FALSE, 0);
// gtk_widget_show_all(GTK_WIDGET(t_msg.crlist));
// create_notification(t_application.messanger, mx_strjoin(name, " added!"), 0, 461, 110, 420, 10);

// g_signal_connect(G_OBJECT(single), "enter-notify-event", G_CALLBACK(event_enter_notify), NULL);
// g_signal_connect(G_OBJECT(single), "leave-notify-event", G_CALLBACK(event_leave_notify), NULL);
// g_signal_connect(G_OBJECT(single), "button_press_event", G_CALLBACK(remove_person), (gpointer)(intptr_t)user_id);
// tooltip("Remove",single);
// }
// }

// static void apply_group_button_click(GtkWidget *widget) {
// if(widget) {}
// }

void creator_groupsettings(GtkWidget *main, char *name, bool admin)
static void apply_group_button_click(GtkWidget *widget, gpointer p_chat_data) {
if(widget) {}
if(!upd_data.busy) {
upd_data.suspend = true;
t_chat_data *chat_data = (t_chat_data*)p_chat_data;
cJSON *json = cJSON_CreateObject();
cJSON *json_rename_group = cJSON_CreateObject();
cJSON_AddNumberToObject(json_rename_group, "sender_id", t_account.id);
cJSON_AddNumberToObject(json_rename_group, "chat_id", chat_data->chat_id);
cJSON_AddStringToObject(json_rename_group, "title", chat_data->title);
cJSON_AddItemToObject(json, "rename_group", json_rename_group);
char *json_string = cJSON_PrintUnformatted(json);
char *result = NULL;
ssl_client(json_string, &result);
mx_strdel(&result);
mx_strdel(&json_string);
cJSON_Delete(json);
free(chat_data);
gtk_widget_destroy(t_msg.background);
upd_data.suspend = false;
}
}

void creator_groupsettings(GtkWidget *main, char *name, int chat_id)
{
t_msg.background = gtk_event_box_new();
gtk_widget_set_name(GTK_WIDGET(t_msg.background), "crgroup");
Expand Down Expand Up @@ -126,41 62,37 @@ void creator_groupsettings(GtkWidget *main, char *name, bool admin)
gtk_entry_set_max_length(GTK_ENTRY(group_name), MAX_USERNAME);
gtk_box_pack_start(GTK_BOX(infobox), group_name, TRUE, TRUE, 10);

if(admin) {
GtkWidget* delete_group = gtk_event_box_new();
gtk_widget_set_size_request(GTK_WIDGET(delete_group), 40, 40);
gtk_widget_set_name(GTK_WIDGET(delete_group), "trash_delete");
gtk_box_pack_start(GTK_BOX(infobox), delete_group, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(delete_group), "enter-notify-event", G_CALLBACK(event_enter_notify), NULL);
g_signal_connect(G_OBJECT(delete_group), "leave-notify-event", G_CALLBACK(event_leave_notify), NULL);
//g_signal_connect(G_OBJECT(delete_group), "button_press_event", G_CALLBACK(add_person), NULL);
tooltip("Delete group",delete_group);
}
//
GtkWidget* delete_group = gtk_event_box_new();
gtk_widget_set_size_request(GTK_WIDGET(delete_group), 40, 40);
gtk_widget_set_name(GTK_WIDGET(delete_group), "trash_delete");
gtk_box_pack_start(GTK_BOX(infobox), delete_group, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(delete_group), "enter-notify-event", G_CALLBACK(event_enter_notify), NULL);
g_signal_connect(G_OBJECT(delete_group), "leave-notify-event", G_CALLBACK(event_leave_notify), NULL);
g_signal_connect(G_OBJECT(delete_group), "button_press_event", G_CALLBACK(userprofile_remove_click), (gpointer)(intptr_t)chat_id);
tooltip("Delete group",delete_group);

GtkWidget *search_block = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(search_block), "crgroup_search_block");
gtk_widget_set_size_request(GTK_WIDGET(search_block), 350, 40);
gtk_box_pack_start(GTK_BOX(box), search_block, FALSE, TRUE, 0);
GtkWidget *search_field = gtk_entry_new();
gtk_widget_set_name(GTK_WIDGET(search_field), "crgroup_search_field");
gtk_entry_set_placeholder_text(GTK_ENTRY(search_field), "Add some people...");
g_signal_connect(G_OBJECT(search_field), "insert-text", G_CALLBACK(all_input_event), NULL);
gtk_entry_set_max_length(GTK_ENTRY(search_field), MAX_USERNAME);
gtk_box_pack_start(GTK_BOX(search_block), search_field, TRUE, TRUE, 0);
GtkWidget *adduser = gtk_event_box_new();
gtk_widget_set_name(GTK_WIDGET(adduser), "adduser");
gtk_widget_set_size_request(GTK_WIDGET(adduser), 22, 22);
gtk_box_pack_start(GTK_BOX(search_block), adduser, FALSE, FALSE, 10);
gtk_widget_set_halign(GTK_WIDGET(adduser), GTK_ALIGN_END);
gtk_widget_set_valign(GTK_WIDGET(adduser), GTK_ALIGN_CENTER);

g_signal_connect(G_OBJECT(adduser), "enter-notify-event", G_CALLBACK(event_enter_notify), NULL);
g_signal_connect(G_OBJECT(adduser), "leave-notify-event", G_CALLBACK(event_leave_notify), NULL);
// g_signal_connect(G_OBJECT(adduser), "button_press_event", G_CALLBACK(add_person), NULL); // TODO or not TODO...
tooltip("Add",adduser);

if(admin) {
GtkWidget *search_block = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
gtk_widget_set_name(GTK_WIDGET(search_block), "crgroup_search_block");
gtk_widget_set_size_request(GTK_WIDGET(search_block), 350, 40);
gtk_box_pack_start(GTK_BOX(box), search_block, FALSE, TRUE, 0);
GtkWidget *search_field = gtk_entry_new();
gtk_widget_set_name(GTK_WIDGET(search_field), "crgroup_search_field");
gtk_entry_set_placeholder_text(GTK_ENTRY(search_field), "Add some people...");
g_signal_connect(G_OBJECT(search_field), "insert-text", G_CALLBACK(all_input_event), NULL);
gtk_entry_set_max_length(GTK_ENTRY(search_field), MAX_USERNAME);
gtk_box_pack_start(GTK_BOX(search_block), search_field, TRUE, TRUE, 0);
GtkWidget *adduser = gtk_event_box_new();
gtk_widget_set_name(GTK_WIDGET(adduser), "adduser");
gtk_widget_set_size_request(GTK_WIDGET(adduser), 22, 22);
gtk_box_pack_start(GTK_BOX(search_block), adduser, FALSE, FALSE, 10);
gtk_widget_set_halign(GTK_WIDGET(adduser), GTK_ALIGN_END);
gtk_widget_set_valign(GTK_WIDGET(adduser), GTK_ALIGN_CENTER);

g_signal_connect(G_OBJECT(adduser), "enter-notify-event", G_CALLBACK(event_enter_notify), NULL);
g_signal_connect(G_OBJECT(adduser), "leave-notify-event", G_CALLBACK(event_leave_notify), NULL);
//g_signal_connect(G_OBJECT(adduser), "button_press_event", G_CALLBACK(add_person), NULL);
tooltip("Add",adduser);
}

GtkWidget *scrollable = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_size_request(GTK_WIDGET(scrollable), 400, 200);
Expand All @@ -170,16 102,16 @@ void creator_groupsettings(GtkWidget *main, char *name, bool admin)
gtk_widget_set_name(GTK_WIDGET(t_msg.crlist), "crlist");
gtk_container_add(GTK_CONTAINER(scrollable), t_msg.crlist);

// GtkWidget *single = create_single_person(name, avatar);
// gtk_box_pack_start(GTK_BOX(t_msg.crlist), single, FALSE, FALSE, 0);
// gtk_widget_show_all(GTK_WIDGET(t_msg.crlist));
t_chat_data *chat_data = malloc(sizeof(t_chat_data));
chat_data->chat_id = chat_id;
chat_data->title = (char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(group_name)));

GtkWidget *apply_group_button = gtk_button_new_with_label("Apply changes");
gtk_widget_set_name(GTK_WIDGET(apply_group_button), "crgroup_button");
gtk_button_set_relief(GTK_BUTTON(apply_group_button), GTK_RELIEF_NONE);
gtk_widget_set_size_request(GTK_WIDGET(apply_group_button), 100, 10);
gtk_box_pack_start(GTK_BOX(box), apply_group_button, FALSE, FALSE, 0);
//g_signal_connect(G_OBJECT(apply_group_button), "clicked", G_CALLBACK(apply_group_button_click), group_name);
g_signal_connect(G_OBJECT(apply_group_button), "clicked", G_CALLBACK(apply_group_button_click), (gpointer)chat_data);

gtk_widget_show_all(GTK_WIDGET(t_msg.background));
}
2 changes: 1 addition & 1 deletion client/src/creator_userprofile.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,7 @@ static void userprofile_send_click(GtkWidget *widget, gpointer chat_id) {
}
}

static void userprofile_remove_click(GtkWidget *widget, GdkEventButton *event, gpointer chat_id) {
void userprofile_remove_click(GtkWidget *widget, GdkEventButton *event, gpointer chat_id) {
if(widget) {}
if(event->button == 1 && !upd_data.busy) {
upd_data.suspend = true;
Expand Down
5 changes: 2 additions & 3 deletions client/src/events_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 251,11 @@ void person_click(GtkWidget *widget, GdkEventButton *event) {
char* user_id_from_label = (char*)gtk_label_get_text(GTK_LABEL(children->data));
printf("%s %s %s\n", username, chat_id_from_label, user_id_from_label);

int chat_id = atoi(chat_id_from_label);
if (atoi(user_id_from_label) == 0) {
bool admin = 0;
creator_groupsettings(t_msg.main, username, admin);
creator_groupsettings(t_msg.main, username, chat_id);
}
else {
int chat_id = atoi(chat_id_from_label);
t_user *user = malloc(sizeof(t_user));
user->id = atoi(user_id_from_label);
get_user(user);
Expand Down
3 changes: 0 additions & 3 deletions client/src/random.c
Original file line number Diff line number Diff line change
@@ -1,7 1,6 @@
#include "../inc/client.h"

void avatar_random() {
srand(time(NULL)); // Initialization, should only be called once.
int pick = rand() % 100 1; // Returns a pseudo-random integer between 0 and RAND_MAX.
t_avatar.avatar_num = pick;
t_avatar.avatar_generated = mx_strjoin(t_avatar.avatar_generated, mx_itoa(pick));
Expand Down Expand Up @@ -47,7 46,6 @@ void pokemon_random() {

// CHOOSING IMAGE

srand(time(NULL));
int pick = rand() % num 1;
dir = NULL;
sd = NULL;
Expand All @@ -61,7 59,6 @@ void pokemon_random() {

char* random_phrase()
{
srand(time(NULL));
int num = rand() % 57 1;
char *phrase[] = {"There's no one here!",
"Hey, I know. I’ll use my trusty frying pan as a drying pan.",
Expand Down
Loading

0 comments on commit fed15c1

Please sign in to comment.