diff --git a/.gitignore b/.gitignore index 3a308bb..d82dd62 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ compile/ *# terminal-commands/ source/ubl-cmake.h -vgcore* \ No newline at end of file +vgcore* +.BUILD.md +.updatebuild.sh +.install.sh \ No newline at end of file diff --git a/VERSION.md b/VERSION.md deleted file mode 100644 index 48eea8c..0000000 --- a/VERSION.md +++ /dev/null @@ -1 +0,0 @@ -VERSION 1.3 diff --git a/source/ubl-settings-usergroups.c b/source/ubl-settings-usergroups.c index b149b9c..e38b415 100644 --- a/source/ubl-settings-usergroups.c +++ b/source/ubl-settings-usergroups.c @@ -107,77 +107,29 @@ void on_toggle_button_switched(GtkToggleButton *self, GtkWidget *widget){ //functions -void on_uid_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->uid = atoi(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->UserUIDEntry)))); -} - -void on_username_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->username = (char*)(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->userUserNameEntry)))); -} - -void on_login_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->login = (char*)(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->userLoginEntry)))); -} - -void on_password_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->password = (char*)(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->userPasswordEntry)))); -} - -void on_group_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->main_group = (char*)(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->userGroupsEntry)))); -} - -void on_hash_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->password_hash = gtk_combo_box_get_active(GTK_COMBO_BOX(window->userPasswordHashAlgorithmCombo)); -} - -void on_extra_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->extra_options = (char*)(gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(window->userExtraOptionsEntry)))); -} - -void on_user_def_password_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->password=NULL; - user_cfg->password_default = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self)); - on_toggle_button_switched(GTK_TOGGLE_BUTTON(self),window->userPasswordEntry); -} - -void on_auto_uid_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->uid=0; - user_cfg->uid_default = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self)); - on_toggle_button_switched(GTK_TOGGLE_BUTTON(self),window->UserUIDEntry); -} - -void on_SAMBA_changed(GtkWidget *self, dictionary *dict){ - user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - user_cfg->sync_SAMBA=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self)); -} - void on_user_accept(GtkWidget *self, dictionary * dict){ user_window *window = yon_dictionary_get_data(dict->first,user_window*); - user_config *user_cfg = yon_dictionary_get_data(dict->first->next,user_config*); - main_window *widgets = yon_dictionary_get_data(dict->first->next->next,main_window*); + main_window *widgets = yon_dictionary_get_data(dict->first->next,main_window*); GtkTreeIter iter; gtk_list_store_append(main_config.usersListStore,&iter); - gtk_list_store_set(main_config.usersListStore,&iter,(user_cfg->uid_default==0) ? 0 : 1,(user_cfg->uid_default==0) ? user_cfg->uid : 1,2,user_cfg->login, 3,(user_cfg->password_default==0) ? "*******" : _("Default"),5,user_cfg->username,-1); + int auto_id = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userUIDAutoCheck)); + int system_id = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userUIDSystemCheck)); + int unique_id = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userUIDUniqueCheck)); + int user_id = atoi(gtk_entry_get_text(GTK_ENTRY(window->UserUIDEntry))); + const char *user_name = gtk_entry_get_text(GTK_ENTRY(window->userUserNameEntry)); + const char *login = gtk_entry_get_text(GTK_ENTRY(window->userLoginEntry)); + int default_password = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userPasswordDefaultCheck)); + const char *password = gtk_entry_get_text(GTK_ENTRY(window->userPasswordEntry)); + int own_group = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userPasswordDefaultCheck)); + const char *groups = gtk_entry_get_text(GTK_ENTRY(window->userGroupsEntry)); + const char *user_shell = NULL; + if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->userShellCombo))>=0) + user_shell = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->userShellCombo)); + int home_dir_create = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userPasswordDefaultCheck)); + const char *home_dir = gtk_entry_get_text(GTK_ENTRY(window->userHomeFolderEntry)); + int samba = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->userPasswordDefaultCheck)); + const char *extra_options = gtk_entry_get_text(GTK_ENTRY(window->userExtraOptionsEntry)); + gtk_list_store_set(main_config.usersListStore,&iter,0,user_id,1,auto_id,2,unique_id,3,system_id,4,user_name,5,login,6,password,7,default_password,8,groups,9,own_group,10,user_shell,11,home_dir,12,home_dir_create,-1); // widgets->MainUserTree; on_close_subwindow(self); } @@ -252,47 +204,42 @@ void on_user_add(GtkWidget *self, main_window *widgets){ window->UserCancelButton = yon_gtk_builder_get_widget(builder,"UserCancelButton"); window->UserOkButton = yon_gtk_builder_get_widget(builder,"UserOkButton"); - window->UserUIDAutoCheck = yon_gtk_builder_get_widget(builder,"userUIDAutoCheck"); + window->userUIDSystemCheck = yon_gtk_builder_get_widget(builder,"userUIDSystemCheck"); + window->userUIDAutoCheck = yon_gtk_builder_get_widget(builder,"userUIDAutoCheck"); + window->userUIDUniqueCheck = yon_gtk_builder_get_widget(builder,"userUIDUniqueCheck"); window->UserUIDEntry = yon_gtk_builder_get_widget(builder,"userUIDEntry"); + window->userUserNameEntry = yon_gtk_builder_get_widget(builder,"userUserNameEntry"); + window->userLoginEntry = yon_gtk_builder_get_widget(builder,"userLoginEntry"); + window->userPasswordDefaultCheck = yon_gtk_builder_get_widget(builder,"userPasswordDefaultCheck"); window->userPasswordEntry = yon_gtk_builder_get_widget(builder,"userPasswordEntry"); + + window->userGroupsCheck = yon_gtk_builder_get_widget(builder,"userGroupsCheck"); window->userGroupsEntry = yon_gtk_builder_get_widget(builder,"userGroupsEntry"); - window->userPasswordHashAlgorithmCombo = yon_gtk_builder_get_widget(builder,"userPasswordHashAlgorithmCombo"); + window->UserAdditionalGroupsButton = yon_gtk_builder_get_widget(builder,"UserAdditionalGroupsButton"); + window->UserAdditionalGroupsMultipleButton = yon_gtk_builder_get_widget(builder,"UserAdditionalGroupsMultipleButton"); + + window->userShellCombo = yon_gtk_builder_get_widget(builder,"userShellCombo"); + + window->userCreateHomeFolderCheck = yon_gtk_builder_get_widget(builder,"userCreateHomeFolderCheck"); + window->userHomeFolderEntry = yon_gtk_builder_get_widget(builder,"userHomeFolderEntry"); + window->userHomeFolderButton = yon_gtk_builder_get_widget(builder,"userHomeFolderButton"); + window->userSyncSAMBACheck = yon_gtk_builder_get_widget(builder,"userSyncSAMBACheck"); window->userExtraOptionsEntry = yon_gtk_builder_get_widget(builder,"userExtraOptionsEntry"); - user_config *user_cfg=malloc(sizeof(user_config)); - user_cfg->username=NULL; - user_cfg->login=NULL; - user_cfg->password=NULL; - user_cfg->main_group=NULL; - user_cfg->additional_groups=NULL; - user_cfg->extra_options=NULL; - user_cfg->uid=-1; - user_cfg->password_default=0; - user_cfg->password_hash=-1; - user_cfg->sync_SAMBA=0; dictionary *dict = NULL; yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window) - yon_dictionary_add_or_create_if_exists_with_data(dict,"config",user_cfg); yon_dictionary_add_or_create_if_exists_with_data(dict,"widgets",widgets); + g_signal_connect(G_OBJECT(window->UserCancelButton),"clicked",G_CALLBACK(on_close_subwindow),NULL); g_signal_connect(G_OBJECT(window->UserOkButton),"clicked",G_CALLBACK(on_user_accept),dict); - // g_signal_connect(G_OBJECT(window->UserUIDAutoCheck),"clicked",G_CALLBACK(on_toggle_button_switched),window->UserUIDEntry); - // g_signal_connect(G_OBJECT(window->userPasswordDefaultCheck),"clicked",G_CALLBACK(on_toggle_button_switched),window->UserPasswordEntry); - g_signal_connect(G_OBJECT(window->UserAdditionalGroupsButton),"clicked",G_CALLBACK(on_groups_open),NULL); + g_signal_connect(G_OBJECT(window->UserAdditionalGroupsButton),"clicked",G_CALLBACK(on_def_groups_open),window); - g_signal_connect(G_OBJECT(window->UserUIDAutoCheck),"toggled",G_CALLBACK(on_auto_uid_changed),dict); - g_signal_connect(G_OBJECT(window->UserUIDEntry),"changed",G_CALLBACK(on_uid_changed),dict); - g_signal_connect(G_OBJECT(window->userUserNameEntry),"changed",G_CALLBACK(on_username_changed),dict); - g_signal_connect(G_OBJECT(window->userLoginEntry),"changed",G_CALLBACK(on_login_changed),dict); - g_signal_connect(G_OBJECT(window->userPasswordDefaultCheck),"toggled",G_CALLBACK(on_user_def_password_changed),dict); - g_signal_connect(G_OBJECT(window->userPasswordEntry),"changed",G_CALLBACK(on_password_changed),dict); - g_signal_connect(G_OBJECT(window->userGroupsEntry),"changed",G_CALLBACK(on_group_changed),dict); - g_signal_connect(G_OBJECT(window->userPasswordHashAlgorithmCombo),"changed",G_CALLBACK(on_hash_changed),dict); - g_signal_connect(G_OBJECT(window->userSyncSAMBACheck),"toggled",G_CALLBACK(on_SAMBA_changed),dict); - g_signal_connect(G_OBJECT(window->userExtraOptionsEntry),"changed",G_CALLBACK(on_extra_changed),dict); + + g_signal_connect(G_OBJECT(window->userUIDAutoCheck),"clicked",G_CALLBACK(on_toggle_button_switched),window->UserUIDEntry); + g_signal_connect(G_OBJECT(window->userUIDAutoCheck),"clicked",G_CALLBACK(on_toggle_button_switched),window->userUIDUniqueCheck); gtk_widget_show(window->Window); } @@ -304,34 +251,6 @@ void on_user_delete(){ } -void on_def_groups_edit(GtkCellEditable *self, main_window *widgets){ - main_config.default_groups=(char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(widgets->MainDefaultGroupsEntry))); -} - -void on_def_user_edit(GtkCellEditable *self, main_window *widgets){ - main_config.default_user_name=(char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(widgets->MainDefaultUserNameEntry))); - -} - -void on_def_admin_edit(GtkWidget *self, main_window *widgets){ - main_config.is_1000_administrator=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->MainDefaultUserAdministratorCheck)); - -} - -void on_def_password_edit(GtkCellEditable *self, main_window *widgets){ - main_config.default_password=(char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(widgets->MainDefaultPasswordEntry))); -} - -void on_root_password_edit(GtkCellEditable *self, main_window *widgets){ - main_config.root_password=(char*)gtk_entry_buffer_get_text(gtk_entry_get_buffer(GTK_ENTRY(widgets->MainRootPasswordEntry))); - -} - -void on_hash_edit(GtkWidget *self, main_window *widgets){ - main_config.hash_alg=gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->MainPasswordHashCombo)); - -} - // standard functions void config_init(){ @@ -426,12 +345,6 @@ main_window *setup_window(){ g_signal_connect(G_OBJECT(widgets->MainEditUserButton),"clicked",G_CALLBACK(on_user_edit),NULL); g_signal_connect(G_OBJECT(widgets->MainDeleteUserButton),"clicked",G_CALLBACK(on_user_delete),NULL); g_signal_connect(G_OBJECT(widgets->MainEditGroupsButton),"clicked",G_CALLBACK(on_def_groups_open),widgets); - g_signal_connect(G_OBJECT(widgets->MainDefaultGroupsEntry),"changed",G_CALLBACK(on_def_groups_edit),widgets); - g_signal_connect(G_OBJECT(widgets->MainDefaultUserNameEntry),"changed",G_CALLBACK(on_def_user_edit),widgets); - g_signal_connect(G_OBJECT(widgets->MainDefaultUserAdministratorCheck),"toggled",G_CALLBACK(on_def_admin_edit),widgets); - g_signal_connect(G_OBJECT(widgets->MainDefaultPasswordEntry),"changed",G_CALLBACK(on_def_password_edit),widgets); - g_signal_connect(G_OBJECT(widgets->MainRootPasswordEntry),"changed",G_CALLBACK(on_root_password_edit),widgets); - g_signal_connect(G_OBJECT(widgets->MainPasswordHashCombo),"changed",G_CALLBACK(on_hash_edit),widgets); gtk_widget_show(widgets->Window); diff --git a/source/ubl-settings-usergroups.h b/source/ubl-settings-usergroups.h index c13f3c0..f6eae4e 100644 --- a/source/ubl-settings-usergroups.h +++ b/source/ubl-settings-usergroups.h @@ -65,6 +65,7 @@ typedef struct { GtkWidget *Window; GtkWidget *HatLabel; GtkWidget *PlugBox; + GtkWidget *MainDefaultGroupsEntry; GtkWidget *HeadOverlay; GtkWidget *HeadImage; @@ -96,7 +97,6 @@ typedef struct { GtkWidget *MainEditGroupsButton; - GtkWidget *MainDefaultGroupsEntry; GtkWidget *MainDefaultUserNameEntry; GtkWidget *MainDefaultUserAdministratorCheck; GtkWidget *MainDefaultPasswordEntry; @@ -171,18 +171,31 @@ typedef struct { typedef struct { GtkWidget *Window; - GtkWidget *UserAdditionalGroupsButton; GtkWidget *UserCancelButton; GtkWidget *UserOkButton; + GtkWidget *userGroupsEntry; - GtkWidget *UserUIDAutoCheck; + GtkWidget *userUIDSystemCheck; + GtkWidget *userUIDAutoCheck; + GtkWidget *userUIDUniqueCheck; GtkWidget *UserUIDEntry; + GtkWidget *userUserNameEntry; GtkWidget *userLoginEntry; + GtkWidget *userPasswordDefaultCheck; GtkWidget *userPasswordEntry; - GtkWidget *userGroupsEntry; - GtkWidget *userPasswordHashAlgorithmCombo; + + GtkWidget *userGroupsCheck; + GtkWidget *UserAdditionalGroupsButton; + GtkWidget *UserAdditionalGroupsMultipleButton; + + GtkWidget *userShellCombo; + + GtkWidget *userCreateHomeFolderCheck; + GtkWidget *userHomeFolderEntry; + GtkWidget *userHomeFolderButton; + GtkWidget *userSyncSAMBACheck; GtkWidget *userExtraOptionsEntry; } user_window; diff --git a/source/ubl-utils.c b/source/ubl-utils.c index 7358272..66ed085 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -2,7 +2,7 @@ // dictionary functions -/**yon_dictionary_create_empty(): +/**yon_dictionary_new(): * [EN] * Creates and returns empty dictionary * [RU] @@ -20,7 +20,7 @@ dictionary *yon_dictionary_new() return dict; } -/**yon_dictionary_copy_deep(dictionary *dict) +/**yon_dictionary_copy(dictionary *dict) * [EN] * * [RU] @@ -29,6 +29,7 @@ dictionary *yon_dictionary_new() dictionary *yon_dictinoary_copy(dictionary *dict){ dictionary *dct = yon_dictionary_new_with_data(dict->key,dict->data); dct->data_type= dict->data_type; + return dct; } /**yon_dictionary_copy_deep(dictionary *dict) @@ -47,22 +48,49 @@ dictionary *yon_dictionary_copy_deep(dictionary *dict){ return newone->first; } +/**int yon_dictionary_set_data(dictionary *dict, void *data) + * [EN] + * + * [RU] + * Установить элементу словаря [dict] значение [data] +*/ int yon_dictionary_set_data(dictionary *dict, void *data){ dict->data=data; } +/**int yon_dictionary_set_key(dictionary *dict, char *key) + * [EN] + * + * [RU] + * Изменяет ключ элемента словаря [dict] на [key] +*/ int yon_dictionary_set_key(dictionary *dict, char *key){ dict->key=key; + return 1; } +/** int yon_dictionary_set(dictionary *dict, char *key, void *data) + * [EN] + * + * [RU] +* Устанавливает значение ключа элемента словаря [dict] на [key] и его данные на [data] +*/ int yon_dictionary_set(dictionary *dict, char *key, void *data){ dict->key=key; dict->data=data; + return 1; } +/**int yon_dictionary_empty(dictionary *dict) + * [EN] + * + * [RU] + * Очищает элемент словаря [dict] от данных +*/ int yon_dictionary_empty(dictionary *dict){ dict->data=NULL; dict->data_type=DICTIONARY_OTHER_TYPE; + return 1; } /**yon_dictionary_switch_to_last(dictionary **dict) @@ -409,6 +437,13 @@ dictionary *yon_dictionary_get_nth(dictionary *dict, int place) // char functions +int yon_char_find_last(char *source, char find){ + int size = strlen(source); + int i=size; + for (;source[i]!=find&&i>0;i--); + return i; +} + /**[EN] * * creates new char string by combining two char strings. @@ -420,9 +455,9 @@ char *yon_char_append(char *source, char *append) int size = strlen(source) + strlen(append) + 1; char *final = malloc(size); memset(final, 0, size); - if (strstr(source, "%%")) - sprintf(final, source, append); - else + // if (strstr(source, "%%")) + // sprintf(final, source, append); + // else sprintf(final, "%s%s", source, append); return final; } @@ -445,8 +480,12 @@ char *yon_char_new(char *chr) return NULL; } -// char *yon_char_unite(char *source, ...) - +/**yon_char_unite(char *source, ...) + * [En] + * + * [RU] + * Объединяет строку [source] со всеми строками, написанными в [...] +*/ char *yon_char_unite(char *source, ...){ va_list arglist; char *new_char=NULL; @@ -494,6 +533,12 @@ char *yon_char_divide(char *source, int dividepos) return cut; } +/**yon_char_find_count(char *source, char *find) + * [EN] + * + * [RU] + * Считает количество символов [find] в строке [source] +*/ int yon_char_find_count(char *source, char *find){ char *working_string=yon_char_new(source); int i=0; @@ -536,9 +581,8 @@ char *yon_char_divide_search(char *source, char *dividepos, int delete_divider) cut = yon_char_divide(source, leng); return cut; } - else - return source; } + return source; } /**yon_char_from_int(int int_to_convert) @@ -563,52 +607,95 @@ char *yon_char_from_int(int int_to_convert) return ch; } +/**yon_char_from_float(int int_to_convert) + * [EN] + * converts float to char*. + * + * [RU] + * Конвертирует float в char* + */ +char *yon_char_from_float(float int_to_convert) +{ + int i = 1; + float convert_check = (float)int_to_convert; + for (i = 1; convert_check >= 10; i++) + { + convert_check = convert_check / 10; + } + char *ch = g_malloc0((i + 9)* sizeof(char)); + sprintf(ch, "%.2f", int_to_convert); + return ch; +} + +/**yon_char_from_long(int int_to_convert) + * [EN] + * converts long to char*. + * + * [RU] + * Конвертирует long в char* + */ +char *yon_char_from_long(long int_to_convert) +{ + int i = 1; + double convert_check = (double)int_to_convert; + for (i = 1; convert_check >= 10; i++) + { + convert_check = convert_check / 10; + } + char *ch = g_malloc0(i * sizeof(char) + 1); + sprintf(ch, "%ld", int_to_convert); + return ch; +} + /**yon_char_replace(char *source, char *find, char*replace) * [EN] * * [RU] * Заменяет в строке [source] все вхождения строки [find] на [replace] */ -char *yon_char_replace(char *source, char *find, char*replace){ - char *final=NULL; - char *temp=NULL; - if(!strstr(replace,find)){ - while ((final=strstr(source,find))){ - temp=malloc(strlen(source)-strlen(final)); - memset(temp,0,strlen(source)-strlen(final)+strlen(replace)); - memcpy(temp,source,strlen(source)-strlen(final)); - temp=yon_char_append(temp,replace); - source=yon_char_append(temp,final+1); +char *yon_char_replace(char *source, char *find, char*replace){ + if (!strstr(replace,find)){ + + + char *final=NULL; + char *temp=NULL; + if(!strstr(replace,find)){ + while ((final=strstr(source,find))){ + temp=malloc(strlen(source)-strlen(final)+strlen(replace)); + memset(temp,0,strlen(source)-strlen(final)+strlen(replace)); + memcpy(temp,source,strlen(source)-strlen(final)); + temp=yon_char_append(temp,replace); + source=yon_char_append(temp,final+strlen(find)); + } + } - return source; } + return source; } -/**[EN] - * char **yon_char_parse(char *parameters, int *size, char *divider) +/**yon_char_parse(char *parameters, int *size, char *divider) + * [EN] * Parses string [parameters], divided by [divider], * then returns parsed string array and sets [size] to * size of returned array */ char **yon_char_parse(char *parameters, int *size, char *divider){ - char **string=NULL; - int i=1; - string=malloc(sizeof(char*)); - char *paramline=yon_char_new(parameters); - char *param; - while ((param=yon_char_divide_search(paramline,divider,1))){ - string=realloc(string,sizeof(char*)*i); - string[i-1]=yon_char_new(param); - i++; - if (strcmp(param,paramline)==0) break; - } - string=realloc(string,sizeof(char*)*i); - string[i-1]=yon_char_new(paramline); - i++; - // printf("%d\n",i); - *size=i-1; - return string; - + if (parameters){ + char **string=NULL; + *size=0; + char *paramline=yon_char_new(parameters); + char *param = strstr(paramline,divider); + for (;param;param=strstr(paramline,divider)){ + string = yon_remalloc(string,sizeof(char*)*((*size)+1)); + string[(*size)]=yon_char_divide(paramline,strlen(paramline)-strlen(param)); + *size=(*size)+1; + } + string = yon_remalloc(string,sizeof(char*)*((*size)+1)); + string[(*size)]=paramline; + (*size)+=1; + return string; + } + return NULL; } /**yon_char_parsed_rip(char **char_string, int *size, int item_to_delete) @@ -657,6 +744,30 @@ int yon_char_parsed_check_exist(char **parameters, int size, char *param){ return -1; } +/**yon_char_parsed_check_repeats(char **parameters, int size) + * [EN] + * Checks if [parameters] string array of length [size] + * has repeated elements; + * [RU] + * Проверяет есть ли в массиве строк [parameters], размера [size] + * повторения +*/ +int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overlap, int *second_overlap){ + if (parameters){ + *first_overlap=0; + *second_overlap=0; + for ((*first_overlap)=0;(*first_overlap)pw_name,NULL); + else { + user_list = yon_char_parsed_append(user_list,user_size,user->pw_name); + } + } + endpwent(); + return user_list; +} + // parsing functions +/** yon_size_convert_automatic(int bytes, int *size) + * [EN] + * + * [RU] + * +*/ +float yon_size_convert_automatic(int bytes, int *size){ + float byte_float=bytes; + for (*size=-1;byte_float>1024;*size=*size+1){ + byte_float=byte_float/1024; + } + if (*size==-1) { + *size=0; + byte_float=byte_float/1024; + } + return byte_float; +} apps *yon_apps_scan_and_parse_desktops(int *sizef) { @@ -867,8 +1042,73 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size) return NULL; }; + +/** + * yon_dir_get_contents(char *dir_path, int *size) + * [EN] + * + * [RU] + * Проверяет существует ли папка [dir_path] и + * возвращает список всех вложенных файлов и папок, + * передавая в [size] длину списка. +*/ +config_str yon_dir_get_contents(char *dir_path, int *size){ + config_str dir = NULL; + *size=0; + if (!access(dir_path,F_OK)){ + DIR *directory = opendir(dir_path); + struct dirent *de; + while ((de = readdir(directory))){ + if (dir) yon_char_parsed_append(dir,size,de->d_name); + else dir = yon_char_parsed_new(size,de->d_name,NULL); + } + closedir(directory); + } + return dir; +} + //config functions +typedef struct yon_config_parameter +{ + char *key; + void *data; + struct yon_config_parameter *next; + struct yon_config_parameter *prev; + struct yon_config_parameter *first; + DICT_TYPE data_type; + int flag1; + char *section; +} yon_config_parameter; + +yon_config_parameter *yon_config_parameter_new_with_data(char *key, void *data){ + yon_config_parameter *param = yon_remalloc(NULL,sizeof(yon_config_parameter)); + param->data=data; + param->data_type=DICTIONARY_CHAR_TYPE; + param->first=param; + param->flag1=0; + param->key=yon_char_new(key); + param->next=NULL; + param->prev=NULL; + param->section=NULL; + return param; +} + +yon_config_parameter *yon_config_parameter_append_with_data(yon_config_parameter *dict, char *key, void *data){ + yon_config_parameter *param = yon_config_parameter_new_with_data(key,data); + param->first=dict->first; + (param->prev)=(yon_config_parameter*)yon_dictionary_get_last((dictionary*)dict); + dict->next=param; + return param; +} + + +static yon_config_parameter *__yon__config__strings = NULL; +#define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE) +#define for_config dictionary temp = NULL; for_dictionary(temp,(dictionary*)__yon__config__strings) +#define yon_config_parameter_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_config_parameter_new_with_data(key,data); \ + else dict=yon_config_parameter_append_with_data(dict,key,data);} + /**yon_config_load_register(char *command) * [EN] * @@ -876,28 +1116,48 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size) * Выполняет команду [command]. * Полученные данные парсятся и регистрируются в конфиг. */ -int yon_config_load_register(char *command){ +int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...){ if (__yon__config__strings){ - __yon__config__strings = yon_dictionary_free_all(__yon__config__strings,NULL); + __yon__config__strings = yon_dictionary_free_all((dictionary*)__yon__config__strings,NULL); } - FILE *output = popen(command, "r"); - char **output_strings = NULL; - output_strings = malloc(sizeof(char)); - int i = 0; - char str[4096]; - memset(str, 0, 4096); - while (fgets(str, 4096, output)) + va_list args; + va_start(args,parameter); + char *arg; + dictionary *sections = NULL; { - if (strcmp(str, "") != 0&& strcmp(str,"(null)\n")!=0) + if (sections&&yon_dictionary_get(§ions,section)) sections->data=(void*)yon_char_unite(yon_dictionary_get_data(sections,char*)," ",parameter,NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections,section,parameter); + } + while (arg=va_arg(args,char*)){ + char *key = va_arg(args,char*); + if (sections&&yon_dictionary_get(§ions,arg)) sections->data=(void*)yon_char_unite(yon_dictionary_get_data(sections,char*)," ",key,NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections,arg,key); + } + char *command=NULL; + dictionary *dict; + for_dictionaries(dict,sections){ + command = yon_char_unite(ubconfig_load_command,config_type==YON_CONFIG_GLOBAL ? " global get " : " system get ", dict->key," ", yon_dictionary_get_data(dict,char*),NULL); + FILE *output = popen(command, "r"); + char **output_strings = NULL; + output_strings = malloc(sizeof(char*)); + int i = 0; + char str[4096]; + memset(str, 0, 4096); + while (fgets(str, 4096, output)) { - char *key = yon_char_divide_search(str,"=",-1); - yon_dictionary_add_or_create_if_exists_with_data(__yon__config__strings,key,str); - __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE; + if (strcmp(str, "") != 0&& strcmp(str,"(null)\n")!=0) + { + char *key = yon_char_divide_search(str,"=",-1); + char *final_str=yon_char_divide_search(str,"\n",-1); + yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,yon_char_new(final_str)); + __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE; + __yon__config__strings->section=dict->key; + } } } check_config - return 0; - else return 1; + return 1; + else return 0; } /**yon_config_remove_by_key(char *key) @@ -908,35 +1168,15 @@ int yon_config_load_register(char *command){ */ int yon_config_remove_by_key(char *key){ check_config{ - dictionary *dict = yon_dictionary_get(&__yon__config__strings,key); + dictionary *dict = yon_dictionary_get((dictionary**)&__yon__config__strings,key); if (dict){ - yon_dictionary_rip(dict); + ((yon_config_parameter*)dict)->flag1=-1; return 1; }else return 0; } return 0; } -/**yon_config_remove_by_data(void *data) - * [EN] - * - * [RU] - * Производит поиск по конфигу на наличие параметра со значением [data] и удаляет найденное значение из конфига. -*/ -int yon_config_remove_by_data(void *data){ - check_config{ - dictionary *dict = NULL; - for_dictionaries(dict,__yon__config__strings){ - if (dict->data==data){ - yon_dictionary_rip(dict); - return 1; - } - } - return 0; - } - return 0; -} - /**yon_config_remove_element(char *key, char *deleted) * [EN] * @@ -945,7 +1185,7 @@ int yon_config_remove_by_data(void *data){ */ int yon_config_remove_element(char *key, char *deleted){ check_config{ - dictionary *dict = yon_dictionary_get(&__yon__config__strings,key); + yon_config_parameter *dict = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key); char *data = (char*)dict->data; char *found = strstr(data,deleted); int size=strlen(data)-strlen(found)+1; @@ -959,7 +1199,6 @@ int yon_config_remove_element(char *key, char *deleted){ new_data = yon_char_append(new_data,found+strlen(deleted)); } dict->data=(void*)(new_data); - free(data); dict->flag1=1; return 1; } else return 0; @@ -974,8 +1213,8 @@ int yon_config_remove_element(char *key, char *deleted){ void *yon_config_get_by_key(char *key){ check_config{ dictionary *dict = NULL; - for_dictionaries(dict, __yon__config__strings){ - if (strcmp(dict->key,key)==0){ + for_dictionaries(dict, (dictionary*)__yon__config__strings){ + if (strcmp(dict->key,key)==0&&((yon_config_parameter*)dict)->flag1!=-1){ return dict->data; } } @@ -983,6 +1222,21 @@ void *yon_config_get_by_key(char *key){ return NULL; } +void *yon_config_get_all_by_key(char *key, int *size){ + check_config{ + config_str ret_data=NULL; + dictionary *dict = NULL; + for_dictionaries(dict, (dictionary*)__yon__config__strings){ + if (strstr(dict->key,key)&&((yon_config_parameter*)dict)->flag1!=-1) { + char *ret_string = yon_char_unite(dict->key,"=",(char*)dict->data,NULL); + if (ret_data) ret_data = yon_char_parsed_append(ret_data,size,ret_string); + else ret_data = yon_char_parsed_new(size,ret_string,NULL); + } + } + return ret_data; + } +} + /**yon_config_get_key_by_data(char *data) * [EN] * @@ -993,7 +1247,7 @@ void *yon_config_get_by_key(char *key){ char *yon_config_get_key_by_data(char *data){ check_config{ dictionary *dict = NULL; - for_dictionaries(dict, __yon__config__strings){ + for_dictionaries(dict, (dictionary*)__yon__config__strings){ if (strcmp(((char*)dict->data),data)==0){ return dict->key; } @@ -1010,12 +1264,32 @@ char *yon_config_get_key_by_data(char *data){ */ int yon_config_set(char *key, void *data){ check_config{ - dictionary *dict = yon_dictionary_get(&__yon__config__strings,key); + yon_config_parameter *dict = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key); dict->data=data; + dict->flag1=1; return 1; } else return 0; } + +/**yon_config_append(char *key, void *data) + * [EN] + * + * [RU] + * Производит поиск по конфигу и дополняет значение параметра с ключом [key] значением [data]; +*/ +int yon_config_append(char *key, char *data){ + check_config{ + yon_config_parameter *dict = (yon_config_parameter*)yon_dictionary_get((dictionary**)&__yon__config__strings,key); + if (strcmp(((char*)dict->data),"")!=0) + dict->data=(void*)(yon_char_unite((char*)dict->data," ",data,NULL)); + else dict->data=(void*)data; + dict->flag1=1; + return 1; + } else return 0; +} + + /**yon_config_clean() * [EN] * Erase all parameters from config; @@ -1024,7 +1298,7 @@ int yon_config_set(char *key, void *data){ */ int yon_config_clean(){ check_config{ - __yon__config__strings = yon_dictionary_free_all(__yon__config__strings, NULL); + __yon__config__strings = (yon_config_parameter*)yon_dictionary_free_all((dictionary*)__yon__config__strings, NULL); return 1; } else return 0; @@ -1038,9 +1312,14 @@ int yon_config_clean(){ * [key] - ключ параметра; * [data] - значение параметра; */ -void yon_config_register(char *key, void *data){ - yon_dictionary_add_or_create_if_exists_with_data(__yon__config__strings,key,data); +void yon_config_register(char *key, char *config_section, void *data){ + if (!__yon__config__strings||!yon_dictionary_get((dictionary**)&__yon__config__strings,key)){ + yon_config_parameter_add_or_create_if_exists_with_data(__yon__config__strings,key,data); + } + else if (yon_dictionary_get((dictionary**)&__yon__config__strings,key)) __yon__config__strings->data=data; __yon__config__strings->data_type=DICTIONARY_CHAR_TYPE; + __yon__config__strings->flag1=1; + __yon__config__strings->section=yon_char_new(config_section); } /**yon_config_load(char *command, int *str_len) @@ -1062,7 +1341,6 @@ config_str yon_config_load(char *command, int *str_len){ if (strcmp(str, "") != 0) { output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); - // printf("%s\n", str); output_strings[i] = NULL; output_strings[i] = yon_char_new(str); memset(str, 0, 4096); @@ -1078,22 +1356,93 @@ config_str yon_config_load(char *command, int *str_len){ } } -/**int yon_config_save(char *command) +/**int yon_config_save_registered(char *path) * [EN] - * Saves config with [command] + * Saves config at [path] config. + * [path] can be: + * system + * global * [RU] - * Выполняет команду [command], добавляя в конец все записи конфига в таком виде: - * [ПАРАМЕТР1]="[значения1]" [ПАРАМЕТР2]="[значения2]" + * Сохраняет конфигурацию в [path] конфиг. + * [path] может быть + * system - локальный конфиг + * global - глобальный конфиг */ -int yon_config_save(char *command){ +int yon_config_save_registered(char *path){ check_config{ - dictionary *dict = NULL; - for_dictionaries(dict,__yon__config__strings){ - command = yon_char_unite(command, " ", yon_dictionary_get_data(dict,char*), NULL); + dictionary *dct; + dictionary *sections_add=NULL; + dictionary *sections_remove=NULL; + for_dictionaries(dct,(dictionary*)__yon__config__strings){ + if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){ + if (((yon_config_parameter*)dct)->flag1==1){ + ((yon_config_parameter*)dct)->flag1=0; + if (sections_add&&yon_dictionary_get(§ions_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL)); + } else if (((yon_config_parameter*)dct)->flag1==-1){ + ((yon_config_parameter*)dct)->flag1=0; + if (sections_remove&&yon_dictionary_get(§ions_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL)); + yon_dictionary_rip(dct); + } + } } - if (popen(command, "r")) return 1; - else return 0; - } else return 0; + if (sections_add) + for_dictionaries(dct,sections_add){ + char *command = yon_dictionary_get_data(dct,char*); + yon_launch(command); + } + if (sections_remove) + for_dictionaries(dct,sections_remove){ + char *command = yon_dictionary_get_data(dct,char*); + yon_launch(command); + } + return 1; + } else return 1; +} + +/**int yon_config_force_save_registered(char *path, char *section) + * [EN] + * Force config to save at [path] config ignoring parameter save status. + * [path] can be: + * system + * global + * [RU] + * Принудительно сохраняет конфигурацию в [path] конфиг игнорируя статус параметра. + * [path] может быть + * system - локальный конфиг + * global - глобальный конфиг +*/ +int yon_config_force_save_registered(char *path){ + check_config{ + dictionary *dct; + dictionary *sections_add=NULL; + dictionary *sections_remove=NULL; + for_dictionaries(dct,(dictionary*)__yon__config__strings){ + if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){ + if (((yon_config_parameter*)dct)->flag1==1||((yon_config_parameter*)dct)->flag1==0){ + if (sections_add&&yon_dictionary_get(§ions_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL)); + } else if (((yon_config_parameter*)dct)->flag1==-1){ + if (sections_remove&&yon_dictionary_get(§ions_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_remove,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " remove ", ((yon_config_parameter*)dct)->section, " ",dct->key,NULL)); + } + } + } + if (sections_add) + for_dictionaries(dct,sections_add){ + char *command = yon_dictionary_get_data(dct,char*); + yon_launch(command); + } + if (sections_remove) + for_dictionaries(dct,sections_remove){ + char *command = yon_dictionary_get_data(dct,char*); + yon_launch(command); + } + + + return 1; + } else return 1; } /**yon_config_get_all(int *size) @@ -1108,29 +1457,18 @@ config_str yon_config_get_all(int *size){ *size = 1; config_str conf = NULL; dictionary *dict = NULL; - for_dictionaries(dict,__yon__config__strings){ + for_dictionaries(dict,(dictionary*)__yon__config__strings){ conf = yon_remalloc(conf,sizeof(char*)*(*size)); conf[(*size)-1] = yon_char_unite(dict->key,"=",(char*)dict->data,NULL); - size++; + (*size)++; } - conf = yon_remalloc(conf,sizeof(char*)*(*size+1)); - conf[*size] = NULL; + conf = yon_remalloc(conf,sizeof(char*)*(*size)); + conf[*size-1] = NULL; + (*size)=(*size)-1; return conf; } else return NULL; } -/**[EN] - * int yon_config_save(char *command) - * Saves config with [command] - * [RU] - * Выполняет команду [command] -*/ -// int yon_config_save(char *command) -// { -// FILE *output = popen(command, "r"); -// return 1; -// } - /**char *yon_config_get_parameter(config parameters, int size, char *param) * [EN] * Gets parameter [param] from parameter list [parameters] of size [size]; @@ -1164,7 +1502,71 @@ char *yon_config_get_parameter(config_str parameters, int size, char *param) return NULL; } +config_str yon_file_open(char *file_path, int *size){ + *size=0; + FILE *file = fopen(file_path,"r"); + if (file){ + char str_loaded[4098]; + config_str final_string = NULL; + while (fgets(str_loaded,4098,file)){ + final_string = final_string ? yon_char_parsed_append(final_string,size,str_loaded) : yon_char_parsed_new(size,str_loaded,NULL); + } + return final_string; + } +} +/**yon_file_create(char *path, char *name, int rules) + * [EN] + * + * [RU] + * Создать файл с названием [name], находящимся по пути [path] + * С правами доступа [rules] (от 0000 до 0777) +*/ +int yon_file_create(char *path, char *name, int rules){ + if (path&&name){ + char *full_path = yon_char_unite(path,"/",name,NULL); + if (access(full_path,F_OK)){ + FILE *fl = fopen(full_path,"w"); + if (fl){ + chmod(full_path,rules); + fclose(fl); + return 1; + } else { + return 0; + } + } else { + return -1; + } + } else { + return 0; + } +} + +/**yon_file_create_full_path(char *path, char *name, int rules) + * [EN] + * + * [RU] + * Создать файл по пути [path] + * С правами доступа [rules] (от 0000 до 0777) +*/ +int yon_file_create_full_path(char *path, int rules){ + if (path){ + if (access(path,F_OK)){ + FILE *fl = fopen(path,"w"); + if (fl){ + chmod(path,rules); + fclose(fl); + return 1; + } else { + return 0; + } + } else { + return -1; + } + } else { + return 0; + } +} // terminal-using functions @@ -1235,8 +1637,7 @@ void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, voi VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL); vte_terminal_set_pty(VTE_TERMINAL(terminal),pty); gtk_container_add(GTK_CONTAINER(place_to_show),terminal); - char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command," ; sleep 5;exit 0","\n",NULL); - printf("%s\n",install_command); + char *install_command=yon_char_unite("clear;tput cup 0 0 && tput ed; ",command," ; sleep 5;exit 0","\n",NULL); if(endwork_function) g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); vte_terminal_spawn_async(VTE_TERMINAL(terminal), @@ -1289,7 +1690,7 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end vte_terminal_set_size(VTE_TERMINAL(terminal),10,15); VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL); vte_terminal_set_pty(VTE_TERMINAL(terminal),pty); - char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command," ; sleep 5;exit 0","\n",NULL); + char *install_command=yon_char_unite("clear;tput cup 0 0 && tput ed; ",command," ; sleep 5; stty -echo; unset PS1","\n",NULL); if(endwork_function) g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument); vte_terminal_spawn_async(VTE_TERMINAL(terminal), @@ -1315,21 +1716,42 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end NULL, NULL, NULL); - vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), 100); + vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1); vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE); vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE); gtk_widget_show_all(terminal); } #endif + // Window config functions + #define check_window_config_setup if(__yon_window_config_target_window) + + typedef struct { + char *parameter_name; + enum YON_TYPE containing_type; + GtkWidget *track_widget; + char *property_name; + } __yon_listener_parameter; + + typedef struct { + char *parameter_name; + char *section; + enum YON_TYPE containing_type; + void *property; + } __yon_custom_parameter; + struct { int x; int y; int width; int height; int fullscreen; + dictionary *custom_listeners; + dictionary *custom_parameters; + dictionary *deleted_parameters; } __yon_main_window_config; + static GtkWindow *__yon_window_config_target_window = NULL; static GKeyFile *__yon_window_config_file = NULL; static char *__yon_window_config_path = NULL; @@ -1340,15 +1762,63 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end g_key_file_set_integer(__yon_window_config_file,"window","WindowWidth",__yon_main_window_config.width); g_key_file_set_integer(__yon_window_config_file,"window","WindowHeight",__yon_main_window_config.height); g_key_file_set_integer(__yon_window_config_file,"window","fullscreen",__yon_main_window_config.fullscreen); + dictionary *dict=NULL; + if (__yon_main_window_config.deleted_parameters) + for_dictionaries(dict,__yon_main_window_config.deleted_parameters){ + __yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); + g_key_file_remove_key(__yon_window_config_file,param->section,param->parameter_name,NULL); + } + if (__yon_main_window_config.custom_listeners) + for_dictionaries(dict,__yon_main_window_config.custom_listeners){ + __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); + GValue *val = g_malloc0(sizeof(GValue)); + g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); + switch(param->containing_type){ + case YON_TYPE_STRING: + g_key_file_set_string(__yon_window_config_file,"window",param->parameter_name, g_value_get_string(val)); + break; + case YON_TYPE_INT: + g_key_file_set_integer(__yon_window_config_file,"window",param->parameter_name, g_value_get_int(val)); + break; + case YON_TYPE_BOOLEAN: + g_key_file_set_boolean(__yon_window_config_file,"window",param->parameter_name, g_value_get_boolean(val)); + break; + case YON_TYPE_OTHER:printf("\033[0;31mCannot save %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; + } + } + if (__yon_main_window_config.custom_parameters) + for_dictionaries(dict,__yon_main_window_config.custom_parameters){ + __yon_custom_parameter *param = yon_dictionary_get_data(dict,__yon_custom_parameter*); + switch (param->containing_type){ + case YON_TYPE_STRING: + g_key_file_set_string(__yon_window_config_file,param->section,param->parameter_name, (char*)param->property); + break; + case YON_TYPE_INT: + g_key_file_set_integer(__yon_window_config_file,param->section,param->parameter_name, *(int*)param->property); + break; + case YON_TYPE_BOOLEAN: + g_key_file_set_boolean(__yon_window_config_file,param->section,param->parameter_name, *(gboolean*)param->property); + break; + default: + break; + } + } + g_key_file_save_to_file(__yon_window_config_file,__yon_window_config_path,NULL); } void yon_get_is_fullscreen(){ gtk_window_is_maximized(__yon_window_config_target_window); __yon_main_window_config.fullscreen = gtk_window_is_maximized(__yon_window_config_target_window); + if (!__yon_main_window_config.fullscreen) gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y); } - + /**yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event) + * [EN] + * + * [RU] + * Сохраняет настройки основного окна. Вызывается когда основное окно уничтожается. + */ void yon_on_configured_window_destroy(GtkWidget* self,GdkEvent* event){ check_window_config_setup{ yon_get_is_fullscreen(); @@ -1366,6 +1836,12 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end } } + /**yon_window_config_setup(GtkWindow *window) + * [EN] + * + * [RU] + * Устанавливает указатель на окно для отслеживания его положения и размера + */ void yon_window_config_setup(GtkWindow *window){ __yon_window_config_target_window = window; g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_configured_window_destroy),NULL); @@ -1377,6 +1853,12 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end if(__yon_main_window_config.fullscreen ==1) gtk_window_maximize(__yon_window_config_target_window); } + /**yon_window_config_load(char *path) + * [EN] + * + * [RU] + * Загружает конфиг окна и инициализирует отслеживание его параметров + */ int yon_window_config_load(char *path){ __yon_window_config_file = g_key_file_new(); __yon_window_config_path=yon_char_new(path); @@ -1390,6 +1872,7 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end } FILE *fp; fp=fopen(__yon_window_config_path,"w"); + chmod(__yon_window_config_path,0777); fclose(fp); g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL); } @@ -1398,6 +1881,27 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end __yon_main_window_config.width = g_key_file_get_integer(__yon_window_config_file,"window","WindowWidth",NULL); __yon_main_window_config.height = g_key_file_get_integer(__yon_window_config_file,"window","WindowHeight",NULL); __yon_main_window_config.fullscreen = g_key_file_get_integer(__yon_window_config_file,"window","fullscreen",NULL); + dictionary *dict=NULL; + if (__yon_main_window_config.custom_listeners) + for_dictionaries(dict,__yon_main_window_config.custom_listeners){ + __yon_listener_parameter *param = yon_dictionary_get_data(dict,__yon_listener_parameter*); + GValue *val = g_malloc0(sizeof(GValue)); + g_object_get_property(G_OBJECT(param->track_widget),param->property_name,val); + switch(param->containing_type){ + case YON_TYPE_STRING: + g_value_set_string(val,g_key_file_get_string(__yon_window_config_file,"window",param->parameter_name, NULL)); + break; + case YON_TYPE_INT: + g_value_set_int(val,g_key_file_get_integer(__yon_window_config_file,"window",param->parameter_name, NULL)); + break; + case YON_TYPE_BOOLEAN: + gboolean res = g_key_file_get_boolean(__yon_window_config_file,"window",param->parameter_name, NULL); + g_value_set_boolean(val,res); + break; + default:printf("\033[0;31mCannot load %s property with %s key\033[0m\n",param->property_name,param->parameter_name);break; + } + g_object_set_property(G_OBJECT(param->track_widget),param->property_name,val); + } if (__yon_main_window_config.width==0) __yon_main_window_config.width=800; if (__yon_main_window_config.height==0) __yon_main_window_config.height=600; gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); @@ -1413,7 +1917,200 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end gtk_window_resize(__yon_window_config_target_window,__yon_main_window_config.width,__yon_main_window_config.height); } -int yon_gtk_combo_box_text_fill(GtkWidget *combo, config_str parameters,int size){ + config_str yon_window_config_get_section(char *section, gsize *size){ + config_str key = g_key_file_get_keys(__yon_window_config_file,section,size,NULL); + return key; + } + + /**yon_window_config_add_custom_parameter(GtkWidget *widget, char *param_name, char *widget_property) + * [EN] + * + * [RU] + * Добавляет параметр виджета [widget] по названию [widget_property] для отслеживания и сохраняет его в конфиг под ключом [param_name]. + */ + void yon_window_config_add_listener(GtkWidget *widget, char *param_name, char *widget_property, enum YON_TYPE val_type){ + __yon_listener_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_listener_parameter)); + param->parameter_name = yon_char_new(param_name); + param->track_widget = widget; + param->property_name = yon_char_new(widget_property); + param->containing_type = val_type; + yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_listeners,param->parameter_name,param); + } + + void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ + __yon_custom_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_custom_parameter)); + param->parameter_name = yon_char_new(param_name); + param->section=section; + param->property = tracked_value; + param->containing_type = val_type; + yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.custom_parameters,param->parameter_name,param); + dictionary *dict=NULL; + if (__yon_main_window_config.deleted_parameters) + for_dictionaries(dict,__yon_main_window_config.deleted_parameters){ + if (strcmp(dict->key,param->parameter_name)) + yon_dictionary_rip(dict); + } + } + + void yon_window_config_add_instant_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type){ + switch (val_type){ + case YON_TYPE_BOOLEAN: g_key_file_set_boolean(__yon_window_config_file,section,param_name,*((gboolean*)tracked_value)); + break; + case YON_TYPE_INT: g_key_file_set_integer(__yon_window_config_file,section,param_name,*((int*)tracked_value)); + break; + case YON_TYPE_STRING: g_key_file_set_string(__yon_window_config_file,section,param_name,(char*)tracked_value); + break; + } + } + + void yon_window_config_erase_custom_parameter(char *param_name, char *section){ + __yon_custom_parameter *param = NULL; + param = yon_remalloc(param,sizeof(__yon_custom_parameter)); + param->parameter_name=param_name; + param->section=section; + yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.deleted_parameters,param->parameter_name,param); + } + + int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){ + GError *err=NULL; + switch (type){ + case YON_TYPE_BOOLEAN: + *((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_INT: + *((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING: + *((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING_LIST: + gsize size=0; + *((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err); + *((char***)return_value)=yon_remalloc(return_value,size+1); + *((char***)return_value)[size]=NULL; + if (err) return 0; else return 1; + break; + } + } + + void yon_on_window_config_custom_window_destroy(GtkWindow *window, char *window_name){ + if (!gtk_window_is_maximized(window)){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + + } + } + + void yon_on_window_config_custom_window_resize(GtkWindow *window, char *window_name){ + if (!gtk_window_is_maximized(window)){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_size(window,&width,&height); + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + } + + } + + void yon_window_config_custom_window_setup(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); + if (width&&height) + gtk_window_resize(window,width,height); + if (X&&Y) + gtk_window_move(window,X,Y); + char *signals_window_name = yon_char_new(window_name); + g_signal_connect(G_OBJECT(window),"check-resize",G_CALLBACK(yon_on_window_config_custom_window_resize),signals_window_name); + g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(yon_on_window_config_custom_window_destroy),signals_window_name); + } + + void yon_window_config_custom_window_get(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + yon_window_config_get_parameter("window",yon_char_append(window_name,"Width"),&width,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"Height"),&height,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosX"),&X,YON_TYPE_INT); + yon_window_config_get_parameter("window",yon_char_append(window_name,"PosY"),&Y,YON_TYPE_INT); + if (width&&height) + gtk_window_resize(window,width,height); + if (X&&Y) + gtk_window_move(window,X,Y); + } + + void yon_window_config_custom_window_set(GtkWindow *window, char *window_name){ + int height=0; + int width=0; + int X=0; + int Y=0; + gtk_window_get_size(window,&width,&height); + gtk_window_get_position(window,&X,&Y); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Width"),"window",&width,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"Height"),"window",&height,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosX"),"window",&X,YON_TYPE_INT); + yon_window_config_add_instant_parameter(yon_char_append(window_name,"PosY"),"window",&Y,YON_TYPE_INT); + } + +GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){ + GtkWidget *menu_item = gtk_menu_item_new(); + gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitembottom"); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *label = gtk_label_new(buttonname); + GtkWidget *image = gtk_image_new_from_icon_name("dialog-information-symbolic",GTK_ICON_SIZE_BUTTON); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + gtk_box_pack_start(GTK_BOX(box),image,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(GTK_CONTAINER(menu_item),box); + gtk_widget_show_all(menu_item); + return menu_item; +} + +GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname){ + GtkWidget *menu_item = gtk_menu_item_new(); + gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitemmiddle"); + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *label = gtk_label_new(buttonname); + GtkWidget *image = gtk_image_new_from_icon_name("dialog-question-symbolic",GTK_ICON_SIZE_BUTTON); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + gtk_box_pack_start(GTK_BOX(box),image,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(GTK_CONTAINER(menu_item),box); + gtk_widget_show_all(menu_item); + return menu_item; +} + + +// other Gtk functions + +/**yon_gtk_combo_box_fill(GtkWidget *combo, config_str parameters,int size) + * [EN] + * + * [RU] + * Добавляет в Комбобокс [combo] все строки из массива строк [parameters] размера [size] +*/ +int yon_gtk_combo_box_fill(GtkWidget *combo, config_str parameters,int size){ if (combo&¶meters){ for (int i=0;i0 ? 1 : 0); +} + +void yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target){ + gtk_widget_set_sensitive(target,!gtk_combo_box_get_active(toggle)>0 ? 0 : 1); +} void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) { @@ -1520,6 +2254,115 @@ void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type){ _yon_ubl_status_box_render(text,type); } +void _yon_ubl_status_highlight_incorrect(GtkWidget *widget){ + gtk_style_context_add_class(gtk_widget_get_style_context(widget),"errorBox"); + sleep(5); + gtk_style_context_remove_class(gtk_widget_get_style_context(widget),"errorBox"); +} + +void yon_ubl_status_highlight_incorrect(GtkWidget *widget){ + GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_highlight_incorrect,widget); +} + +void _yon_ubl_status_list_store_highlight_incorrect(GtkWidget **widget_pack){ + GtkListStore *list = (GtkListStore*)widget_pack[0]; + GtkTreeIter *iter = (GtkTreeIter*)widget_pack[1]; + GdkRGBA rgba,rgba2; + rgba.alpha=1; + rgba.blue=153.0/255.0; + rgba.green=153.0/255.0; + rgba.red=234.0/255.0; + rgba2.alpha=1; + rgba2.blue=0; + rgba2.green=0; + rgba2.red=0; + gtk_list_store_set(list,iter,1,gdk_rgba_to_string(&rgba2),2,gdk_rgba_to_string(&rgba),-1); + sleep(5); + gtk_list_store_set(list,iter,1,NULL,2,NULL,-1); +} + +void yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter){ + GtkWidget **pack = malloc(sizeof(GtkWidget *)*2); + pack[0]=(GtkWidget*)list; + pack[1]=(GtkWidget*)iter; + GThread *thread = g_thread_new(NULL,(GThreadFunc)_yon_ubl_status_list_store_highlight_incorrect,pack); +} + +struct temp_statusbox { + int times; + GtkWidget *revealer; + }; + +void _yon_ubl_status_box_timed_remove(struct temp_statusbox *statusstruct){ + sleep(statusstruct->times); + if (status_thread_busy){ + gtk_revealer_set_reveal_child(GTK_REVEALER(statusstruct->revealer),0); + sleep(1); + gtk_widget_destroy(statusstruct->revealer); + + } + status_thread_busy=0; +} + +void __yon_ubl_status_box_destroyed(){ + status_thread_busy=0; +} + +void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ + if (!status_thread_busy){ + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + GtkWidget *revealer = gtk_revealer_new(); + GtkWidget *label = gtk_label_new(""); + GtkWidget *icon = gtk_image_new(); + gtk_container_add(GTK_CONTAINER(revealer),box); + gtk_box_pack_start(GTK_BOX(box),icon,0,0,5); + gtk_box_pack_start(GTK_BOX(box),label,0,0,5); + gtk_container_add(container,revealer); + + gtk_widget_show_all(revealer); + gtk_revealer_set_reveal_child(GTK_REVEALER(revealer),1); + g_signal_connect(G_OBJECT(revealer),"destroy", G_CALLBACK(__yon_ubl_status_box_destroyed),NULL); + + gtk_widget_set_margin_bottom(label,9); + gtk_widget_set_margin_top(label,9); + gtk_label_set_xalign(GTK_LABEL(label),0.0); + PangoAttrList *attributes = pango_attr_list_new(); + PangoAttribute *boldAttr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); + pango_attr_list_insert(attributes, boldAttr); + gtk_label_set_attributes(GTK_LABEL(label),attributes); + + GdkRGBA textColor; + gdk_rgba_parse(&textColor, "#4d4d4d4d4d4d"); + PangoAttribute *colorAttr = pango_attr_foreground_new( + (int)(textColor.red * 65535), + (int)(textColor.green * 65535), + (int)(textColor.blue * 65535) + ); + pango_attr_list_insert(attributes, colorAttr); + + GtkIconTheme *ictheme = gtk_icon_theme_get_default(); + if (type == BACKGROUND_IMAGE_SUCCESS_TYPE||! type) + { + gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessError"); + gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.ubl-settings-logging.checked", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); + } + else if (type == BACKGROUND_IMAGE_FAIL_TYPE) + { + gtk_style_context_remove_class(gtk_widget_get_style_context(box), "boxInfoMessOK"); + gtk_style_context_add_class(gtk_widget_get_style_context(box), "boxInfoMessError"); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.ubl-settings-logging.warning", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, NULL)); + } + if (display_text) + gtk_label_set_text(GTK_LABEL(label),display_text); + struct temp_statusbox *statusstruct = malloc(sizeof(struct temp_statusbox)); + statusstruct->revealer = revealer; + statusstruct->times = timeout; + GThread *thread = g_thread_new("StatusThread",(GThreadFunc)_yon_ubl_status_box_timed_remove,statusstruct); + status_thread_busy=1; + } +} + /**yon_ubl_setup_sockets(GtkWidget *main_window, GtkWidget *left_window, GtkWidget *right_window, int socket_main_id, int socket_left_id, int socket_right_id) * [EN] * Set up plugs for using with GtkSockets insine ubl-settings-manager. diff --git a/source/ubl-utils.h b/source/ubl-utils.h index 01281cd..2fef789 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -9,9 +9,13 @@ #include #include #include +#include +#include #include #include #include +#include +#include #include "../compile/ubl-cmake.h" #ifdef WEBKIT_FOUND @@ -24,7 +28,7 @@ #define new(type) malloc(sizeof(type)) #define new_arr(type,size) malloc(sizeof(type)*size) -#define get_pkexec_user_command "getent passwd $PKEXEC_UID | cut -d: -f1" +#define get_home_dir_command yon_char_unite("getent passwd \"",yon_ubl_root_user_get(),"\" | cut -d: -f6",NULL) typedef enum { @@ -46,9 +50,11 @@ typedef struct dictionary struct dictionary *prev; struct dictionary *first; DICT_TYPE data_type; - int flag1; } dictionary; + + + typedef struct apps { char *Name; @@ -62,13 +68,8 @@ typedef struct apps typedef char** config_str; -static dictionary *__yon__config__strings = NULL; -#define check_config if(__yon__config__strings&&__yon__config__strings->data_type==DICTIONARY_CHAR_TYPE) - #define config(key) yon_config_get_by_key(key) -#define for_config dictionary temp = NULL; for_dictionary(temp,__yon__config__strings) - #define yon_remalloc(pointer, size) (!pointer) ? malloc(size) : realloc(pointer, size) // dictionary functions @@ -122,6 +123,12 @@ void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(vo // char functions +#define yon_char_divide_search_self(str,find,delete_divider) {char *temp = str; str = yon_char_divide_search(str,find,delete_divider); free(temp);} + +#define yon_char_is_empty(string) !(string&&strcmp(string,"")) + +int yon_char_find_last(char *source, char find); + char *yon_char_append(char *source, char *append); char *yon_char_new(char *chr); @@ -136,6 +143,10 @@ char *yon_char_divide_search(char *source, char *dividepos, int delete_divider); char *yon_char_from_int(int int_to_convert); +char *yon_char_from_float(float int_to_convert); + +char *yon_char_from_long(long int_to_convert); + char *yon_char_replace(char *source, char *find, char*replace); char **yon_char_parse(char *parameters, int *size, char *divider); @@ -144,12 +155,16 @@ char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete); int yon_char_parsed_check_exist(char **parameters, int size, char *param); +int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overlap, int *second_overlap); + int yon_char_find_count(char *source, char *find); int yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size); config_str yon_char_parsed_new (int *size, ...); +void yon_char_parsed_free(config_str source, int size); + void yon_char_parsed_copy(config_str *source, config_str *to_copy); config_str yon_char_parsed_append(config_str parsed, int *size, char *string); @@ -158,8 +173,14 @@ int yon_ubl_check_root(); char *yon_ubl_root_user_get(); +char *yon_ubl_user_get_home_directory(); + +config_str yon_ubl_get_all_users(int *user_size); + // parsing functions +float yon_size_convert_automatic(int bytes, int *size); + config_str philos_list_user(int* size); apps *yon_apps_scan_and_parse_desktops(int *sizef); @@ -168,13 +189,34 @@ void yon_apps_sort(apps *applist, int size); apps *yon_apps_get_by_name(apps *applist, char *name, int size); +config_str yon_file_open(char *file_path, int *size); + +int yon_file_create(char *path, char *name, int rules); + +int yon_file_create_full_path(char *path, int rules); + +config_str yon_dir_get_contents(char *dir_path, int *size); + +//config functions + +#define ubconfig_save_command "ubconfig" +#define ubconfig_load_command "ubconfig --source" + +typedef enum { + YON_CONFIG_LOCAL=0, + YON_CONFIG_GLOBAL, + YON_CONFIG_BOTH +} YON_CONFIG_TYPE; + config_str yon_config_load(char *command, int *str_len); -int yon_config_save(char *command); +int yon_config_save_registered(char *path); + +int yon_config_force_save_registered(char *path); char *yon_config_get_parameter(config_str parameters, int size, char *param); -int yon_config_load_register(char *command); +int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...); int yon_config_remove_by_key(char *key); @@ -184,13 +226,15 @@ int yon_config_remove_element(char *key, char *deleted); void *yon_config_get_by_key(char *key); +void *yon_config_get_all_by_key(char *key, int *size); + char *yon_config_get_key_by_data(char *data); int yon_config_set(char *key, void *data); int yon_config_clean(); -void yon_config_register(char *key, void *data); +void yon_config_register(char *key, char* config_section, void *data); config_str yon_config_get_all(); @@ -210,6 +254,17 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end #endif +enum YON_TYPE{ + YON_TYPE_STRING, + YON_TYPE_STRING_LIST, + YON_TYPE_INT, + YON_TYPE_BOOLEAN, + YON_TYPE_OTHER +}; + +GtkWidget *yon_ubl_menu_item_about_new(char *buttonname); +GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname); + /**yon_gtk_builder_get_widget(builder, widget_name) * [EN] * Returns GtkWidget from GtkBuilder *[builder]. @@ -230,10 +285,28 @@ void yon_window_config_setup(GtkWindow *window); int yon_window_config_load(char *path); +config_str yon_window_config_get_section(char *section, gsize *size); + +void yon_window_config_add_listener(GtkWidget *widget, char *param_name, char *widget_property, enum YON_TYPE val_type); + +void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type); + +void yon_window_config_erase_custom_parameter(char *param_name, char *section); + +int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type); + +void yon_window_config_custom_window_setup(GtkWindow *window, char *window_name); + +void yon_window_config_custom_window_get(GtkWindow *window, char *window_name); + +void yon_window_config_custom_window_set(GtkWindow *window, char *window_name); + int yon_gtk_combo_box_fill(GtkWidget *combo, char **parameters,int size); int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find); +void yon_gtk_column_minimal_fixed_size_set(GtkTreeViewColumn *column); + int yon_gtk_icon_view_hide_empty(dictionary *icon_view_segment); int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...); @@ -241,6 +314,10 @@ int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...); +void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target); +void yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target); +void yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target); +void yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target); typedef enum { @@ -288,6 +365,13 @@ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label); */ void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type); +void yon_ubl_status_highlight_incorrect(GtkWidget *widget); + +void yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter); + +static int status_thread_busy; +void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type); + #ifdef __cplusplus /**yon_ubl_header_setup(overlay, head, image, imag_path) diff --git a/ubl-settings-usergroups-additional-settings.glade b/ubl-settings-usergroups-additional-settings.glade new file mode 100644 index 0000000..6305632 --- /dev/null +++ b/ubl-settings-usergroups-additional-settings.glade @@ -0,0 +1,364 @@ + + + + + + True + False + com.ublinux.ubl-settings-usergroups.cancel-symbolic + + + True + False + com.ublinux.ubl-settings-usergroups.accept-symbolic + + + 600 + 350 + False + False + com.ublinux.ubl-settings-usergroups + + + True + False + 5 + 5 + 5 + vertical + 5 + + + True + False + vertical + + + + + + False + True + 0 + + + + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + 5 + 5 + Default user name (if there's no another): + 0 + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + False + True + 0 + + + + + User with ID 1000 is administrator + True + True + False + True + + + False + True + 1 + + + + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + 5 + 5 + Default user password: + 0 + + + False + True + 0 + + + + + True + False + + Default + No password required + Set a password + Endrypted password + + + + True + True + 1 + + + + + True + True + 30 + False + + password + + + True + True + 2 + + + + + False + True + 0 + + + + + True + False + 5 + + + True + False + Root user password: + 0 + + + False + True + 0 + + + + + True + False + + Default + No password required + Set a password + Encrypted password + + + + True + True + 1 + + + + + True + True + 30 + False + + password + + + True + True + end + 2 + + + + + False + True + 3 + + + + + False + True + 3 + + + + + True + False + 5 + + + True + False + 5 + 5 + Password hash algorythm: + 0 + + + False + True + 0 + + + + + True + False + 0 + + md5 + yescrypt + ghost-yescrypt + scrypt + bf + bcrypt + bcrypt-a + sha512crypt + sha256crypt + sunmd5 + md5crypt + bsdicrypt + desctrypt + nt + + + + True + True + 1 + + + + + False + True + 4 + + + + + False + True + 1 + + + + + True + False + end + 5 + + + Deny + True + True + True + image1 + + + False + True + 0 + + + + + Accept + True + True + True + image2 + + + False + True + 1 + + + + + False + True + end + 2 + + + + + + + True + False + True + + + True + False + Users and groups + + + + + + + + + + + + + + + + diff --git a/ubl-settings-usergroups-group-creation.glade b/ubl-settings-usergroups-group-creation.glade new file mode 100644 index 0000000..8b5f35c --- /dev/null +++ b/ubl-settings-usergroups-group-creation.glade @@ -0,0 +1,271 @@ + + + + + + False + False + True + 450 + com.ublinux.ubl-settings-usergroups + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + vertical + 10 + + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + UID: + 0 + + + False + True + 0 + + + + + Automatically + True + True + False + True + + + False + True + 2 + + + + + True + True + 1001 + number + + + True + True + 4 + + + + + False + True + 0 + + + + + True + False + 5 + + + True + False + Login: + 0 + + + False + True + 0 + + + + + True + True + login + + + True + True + 1 + + + + + False + True + 2 + + + + + True + False + 5 + + + True + False + Main group: + 0 + + + False + True + 0 + + + + + True + True + + + True + True + 2 + + + + + True + True + True + image1 + + + + False + True + 3 + + + + + False + True + 4 + + + + + False + True + 0 + + + + + True + False + 30 + True + + + Cancel + True + True + True + image4 + + + + True + True + 0 + + + + + Save + True + True + True + image5 + + + + True + True + 1 + + + + + False + True + end + 1 + + + + + + + True + False + + + True + False + Users and groups + + + + + + + + + + + + + + + + + + + + + + True + False + avatar-default-symbolic + + + True + False + process-stop-symbolic + + + True + False + emblem-ok-symbolic + + diff --git a/ubl-settings-usergroups-system.glade b/ubl-settings-usergroups-system.glade new file mode 100644 index 0000000..9936330 --- /dev/null +++ b/ubl-settings-usergroups-system.glade @@ -0,0 +1,211 @@ + + + + + + True + False + gtk-missing-image + + + True + False + gtk-missing-image + + + + + 800 + 600 + False + False + com.ublinux.ubl-settings-usergroups + + + True + False + 5 + 5 + 5 + 5 + 5 + + + True + False + vertical + 5 + + + True + True + True + image1 + + + + False + True + 0 + + + + + True + True + True + image2 + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + True + + + True + True + liststore2 + + + + + + Blocked + + + + + UID + + + + + Login + + + + + Username + + + + + Primary group + + + + + Additional groups + + + + + Home directory + + + + + + + True + False + Users + + + False + + + + + True + True + liststore1 + + + + + + UID + + + + + + + + Group + + + + + + + + Group users + + + + + + + + 1 + + + + + True + False + Groups + + + 1 + False + + + + + True + True + 1 + + + + + + + True + False + True + + + True + False + Users and groups + + + + + + + + + diff --git a/ubl-settings-usergroups-user.glade b/ubl-settings-usergroups-user.glade index 8719198..566a9f3 100644 --- a/ubl-settings-usergroups-user.glade +++ b/ubl-settings-usergroups-user.glade @@ -2,11 +2,27 @@ + + + True + False + avatar-default-symbolic + True False emblem-ok-symbolic + + True + False + document-edit-symbolic + + + True + False + gtk-missing-image + True False @@ -54,6 +70,20 @@ 0 + + + System + True + True + False + True + + + False + True + 1 + + Automatically @@ -65,7 +95,21 @@ False True - 1 + 2 + + + + + Unique + True + True + False + True + + + False + True + 3 @@ -78,7 +122,7 @@ True True - 2 + 4 @@ -236,6 +280,20 @@ 0 + + + Own groups + True + True + False + True + + + False + True + 1 + + True @@ -244,20 +302,39 @@ True True - 1 + 2 - Additional groups True True True + image1 + False True - 2 + 3 + + + + + True + True + True + image3 + + + + False + True + 4 @@ -273,10 +350,10 @@ False 5 - + True False - Password hash algorythm: + User shell: 0 @@ -286,21 +363,14 @@ - + True False - 0 - - sha256 - AIX md5 - md5 (apache variant) - md5 - True True - 1 + 2 @@ -310,6 +380,72 @@ 5 + + + True + False + 5 + + + True + False + Home directory: + 0 + + + False + True + 0 + + + + + Create + True + True + False + True + + + False + True + 1 + + + + + True + True + + + True + True + 2 + + + + + True + True + True + image2 + + + + False + True + 3 + + + + + False + True + 6 + + Sync with SAMBA user @@ -321,7 +457,7 @@ False True - 6 + 8 @@ -357,7 +493,7 @@ False True - 7 + 9 @@ -371,47 +507,58 @@ True False - 30 - True - - Cancel + True - True - True - image7 - + False + 5 + True + + + Cancel + True + True + True + image7 + + + + False + True + 0 + + + + + Save + True + True + True + image10 + + + + False + True + 1 + + - True + False True + end 0 - - - Save - True - True - True - image10 - - - - True - True - 1 - - False True - end 1 @@ -443,6 +590,8 @@ + + diff --git a/ubl-settings-usergroups.glade b/ubl-settings-usergroups.glade index 1645544..b05fbee 100644 --- a/ubl-settings-usergroups.glade +++ b/ubl-settings-usergroups.glade @@ -204,16 +204,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + + + + + - - + + + + + + + + @@ -221,6 +233,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. False value-increase-symbolic + + True + False + value-increase-symbolic + + + True + False + value-increase-symbolic + + + True + False + value-increase-symbolic + + + True + False + value-increase-symbolic + True False @@ -236,6 +268,246 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. False document-edit-symbolic + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + 5 + Default user groups: + 0 + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + True + True + True + image4 + + + False + True + 2 + + + + + False + True + 0 + + + + + True + False + 5 + + + True + False + 5 + Default user name (if there's no another): + 0 + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + False + True + 1 + + + + + User with ID 1000 is administrator + True + True + False + True + + + False + True + 2 + + + + + True + False + 5 + + + True + False + 5 + Default user password: + 0 + + + False + True + 0 + + + + + True + True + 30 + False + + password + + + False + True + 1 + + + + + True + True + end + 30 + False + + password + + + False + True + end + 2 + + + + + True + False + Root user password: + + + False + True + end + 3 + + + + + False + True + 3 + + + + + True + False + 5 + + + True + False + 5 + Password hash algorythm: + 0 + + + False + True + 0 + + + + + True + False + 0 + + md5 + yescrypt + ghost-yescrypt + scrypt + bf + bcrypt + bcrypt-a + sha512crypt + sha256crypt + sunmd5 + md5crypt + bsdicrypt + desctrypt + nt + + + + True + True + 1 + + + + + False + True + 4 + + + + + + + + + + + True False @@ -640,7 +912,6 @@ translated and supported by community. 5 True True - vertical 5 @@ -649,48 +920,14 @@ translated and supported by community. vertical 5 - + True - False - 5 - - - True - False - 5 - Default user groups: - 0 - - - False - True - 0 - - - - - True - True - - - True - True - 1 - - - - - True - True - True - image4 - - - False - True - 2 - - + True + True + image12 + False @@ -699,35 +936,14 @@ translated and supported by community. - + True - False - 5 - - - True - False - 5 - Default user name (if there's no another): - 0 - - - False - True - 0 - - - - - True - True - - - True - True - 1 - - + True + True + image11 + False @@ -736,12 +952,14 @@ translated and supported by community. - - User with ID 1000 is administrator + True True - False - True + True + image10 + False @@ -750,69 +968,14 @@ translated and supported by community. - + True - False - 5 - - - True - False - 5 - Default user password: - 0 - - - False - True - 0 - - - - - True - True - 30 - False - - password - - - False - True - 1 - - - - - True - True - end - 30 - False - - password - - - False - True - end - 2 - - - - - True - False - Root user password: - - - False - True - end - 3 - - + True + True + image1 + False @@ -821,42 +984,14 @@ translated and supported by community. - + True - False - 5 - - - True - False - 5 - Password hash algorythm: - 0 - - - False - True - 0 - - - - - True - False - 0 - - sha256 - AIX md5 - md5 (apache variant) - md5 - - - - True - True - 1 - - + True + True + image2 + False @@ -864,6 +999,38 @@ translated and supported by community. 4 + + + True + True + True + image3 + + + + False + True + 5 + + + + + True + True + True + image13 + + + + False + True + 6 + + False @@ -872,138 +1039,222 @@ translated and supported by community. - + True - False - 5 + True - + True - True - external - in + False + 5 + 5 + 5 + 5 + 5 - + True True - UserList - - - + external + in - - UID + + True + True + UserList + 0 + + + - - - 0 - + + Block + - - - - - Login - - - 2 - + + UID + + + + 0 + + + - - - - - Password - - - 3 - + + Login + + + + 5 + + + + + + + User name + + + + 4 + + + - - - - - User name - - - 5 - + + Main group + + + + + + + + Additional groups + + + + + + + + Additional parameters + + + + + + + + Password status + + + True + True + 1 + + + + + True + False + Users + - True - True - 0 + False True False - vertical + 5 + 5 + 5 + 5 5 - + True True - True - image1 - + external + in + + + True + True + UserList + 0 + + + + + + GID + + + + 0 + + + + + + + Group name + + + + 2 + + + + + + + Group users + + + + 3 + + + + + + + Additional parameters + + + + 5 + + + + + + + Password status + + + + + + + - False + True True 0 - - - True - True - True - image2 - - - - False - True - 1 - - - - - True - True - True - image3 - - - - False - True - 2 - - - False - True 1 + + + True + False + Groups + + + 1 + False + + True @@ -1197,12 +1448,4 @@ translated and supported by community. - - - - - - - -