Added startup loading of repos

pull/7/head
parent 3acbb6a350
commit 50299f2431

@ -98,6 +98,20 @@ void on_about(){
gtk_widget_show(window);
}
void on_load(){
gsize size=0;
config_str repos = yon_window_config_get_section("repos",&size);
gtk_tree_store_clear(main_config.tree_store);
for (int i=0;i<size;i++){
char *name = yon_char_new(repos[i]);
char *path = yon_char_divide(name,yon_char_find_last(name,'/'));
GtkTreeIter iter;
gtk_tree_store_append(main_config.tree_store,&iter,NULL);
gtk_tree_store_set(main_config.tree_store,&iter,0,folder_no_edits,1,name,3,path,4,0,5,0,-1);
}
}
void on_save(){
char *command = "repo-manager";
char *remove_command=NULL;
@ -113,8 +127,11 @@ void on_save(){
add_flagged = NULL;
int repostatus=0;
gboolean renamed=0;
int *add = g_malloc0(sizeof(int));
*(add) = 1;
char *old_name=NULL;
gtk_tree_model_get(GTK_TREE_MODEL(main_config.tree_store),&iter,1,&name_flagged,3,&origin_flagged,4,&repostatus,6,&old_name,7,&renamed,-1);
yon_window_config_add_custom_parameter(yon_char_unite(origin_flagged,"/",name_flagged,NULL),"repos",add,YON_TYPE_INT);
if (repostatus==-1) {
remove_command = yon_char_unite("rm -rdf ",origin_flagged,"/",name_flagged,NULL);
system (remove_command);
@ -179,12 +196,7 @@ void on_tree_selection_changed(GtkWidget *self,main_window *widgets){
}
}
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;
}
void on_repo_add_new(GtkWidget *self, dictionary *dict){
main_window *widgets = yon_dictionary_get_data(dict->first,main_window*);
@ -196,7 +208,7 @@ void on_repo_add_new(GtkWidget *self, dictionary *dict){
window->path = yon_char_divide(name,yon_char_find_last(window->path, '/'));
if (!name||strcmp(name,"")!=0){
GtkTreeIter *iter = yon_repo_append(widgets, name, YON_REPO_LINE_REPO_TYPE);
gtk_tree_store_set(main_config.tree_store,iter,0,"com.ublinux.ubl-settings-repomanager.folder-green-symbolic",2,window->BranchesListStore,3,window->path,-1);
gtk_tree_store_set(main_config.tree_store,iter,0,folder_added,2,window->BranchesListStore,3,window->path,-1);
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
} else {
yon_ubl_status_box_render(EMPTY_NAME_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
@ -314,7 +326,6 @@ void on_repo_load_local(GtkWidget *self, main_window *widgets){
GtkTreeIter *yon_repo_append(main_window *widgets, char *name, YON_REPO_LINE_TYPE type){
GtkTreeIter *retIter=g_malloc0(sizeof(GtkTreeIter));
GtkTreeIter iter,parentIter;
GdkPixbuf *icon = NULL;
GtkIconTheme *theme = gtk_icon_theme_get_default();
char *name_short = yon_char_new(name);
gboolean fls = 0;
@ -325,23 +336,21 @@ GtkTreeIter *yon_repo_append(main_window *widgets, char *name, YON_REPO_LINE_TYP
GtkTreeModel *model = GTK_TREE_MODEL(main_config.tree_store);
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&model,&parentIter)){
if (type==YON_REPO_LINE_REPO_TYPE){
icon = gtk_icon_theme_load_icon_for_scale(theme,"com.ublinux.ubl-settings-repomanager.folder-symbolic",16,1,GTK_ICON_LOOKUP_FORCE_SIZE,NULL);
gtk_tree_store_append(main_config.tree_store,&iter,NULL);
gtk_tree_store_set(main_config.tree_store,&iter,0, "com.ublinux.ubl-settings-repomanager.folder-symbolic", 1, name_short,3,name,4,1,5,fls,-1);
gtk_tree_store_set(main_config.tree_store,&iter,0, folder_no_edits, 1, name_short,3,name,4,1,5,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
}
else if (type==YON_REPO_LINE_FILE_TYPE){
GtkTreeIter branch;
icon = gtk_icon_theme_load_icon_for_scale(theme,"com.ublinux.ubl-settings-repomanager.follder-symbolic",16,1,GTK_ICON_LOOKUP_FORCE_SIZE,NULL);
if (gtk_tree_model_iter_parent(model,&branch,&parentIter)){
GtkTreeIter repo;
gtk_tree_store_append(main_config.tree_store,&iter,&branch);
gtk_tree_store_set(main_config.tree_store,&iter,0, "com.ublinux.ubl-settings-repomanager.document-symbolic", 1, name_short,3,name,4,1,5,fls,-1);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,3,name,4,1,5,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
} else {
gtk_tree_store_append(main_config.tree_store,&iter,&parentIter);
gtk_tree_store_set(main_config.tree_store,&iter,0, "com.ublinux.ubl-settings-repomanager.document-symbolic", 1, name_short,3,name,4,1,5,fls,-1);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,3,name,4,1,5,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
}
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
@ -349,9 +358,8 @@ GtkTreeIter *yon_repo_append(main_window *widgets, char *name, YON_REPO_LINE_TYP
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&iter);
}
else if (type==YON_REPO_LINE_REPO_TYPE){
icon = gtk_icon_theme_load_icon_for_scale(theme,"com.ublinux.ubl-settings-repomanager.folder-symbolic",16,1,GTK_ICON_LOOKUP_FORCE_SIZE,NULL);
gtk_tree_store_append(main_config.tree_store,&iter,NULL);
gtk_tree_store_set(main_config.tree_store,&iter,0, "com.ublinux.ubl-settings-repomanager.folder-symbolic", 1, name_short,3,name,4,1,5,fls,-1);
gtk_tree_store_set(main_config.tree_store,&iter,0, folder_no_edits, 1, name_short,3,name,4,1,5,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&iter);
} else {
@ -371,7 +379,7 @@ void yon_repo_remove_package(main_window *widgets){
gtk_tree_model_get(GTK_TREE_MODEL(main_config.tree_store),&iter,4,&status,-1);
if (status != 1){
gtk_tree_store_set(main_config.tree_store,&iter,4,-1,-1);
gtk_tree_store_set(main_config.tree_store,&iter,0,"com.ublinux.ubl-settings-repomanager.document-red-symbolic",-1);
gtk_tree_store_set(main_config.tree_store,&iter,0,document_deleted,-1);
} else gtk_tree_store_remove(main_config.tree_store,&iter);
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}else yon_ubl_status_box_render(CHOOSE_PACK_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
@ -383,7 +391,7 @@ void yon_repo_remove(main_window *widgets){
GtkTreeModel *model = GTK_TREE_MODEL(main_config.tree_store);
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&model,&iter)){
if(gtk_tree_store_iter_depth(main_config.tree_store,&iter)==0){
gtk_tree_store_set(main_config.tree_store,&iter,4,-1,0,"com.ublinux.ubl-settings-repomanager.folder-red-symbolic",-1);
gtk_tree_store_set(main_config.tree_store,&iter,4,-1,0,folder_deleted,-1);
}else yon_ubl_status_box_render(CHOOSE_REPO_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
} else yon_ubl_status_box_render(NOTHING_CHOSEN_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
}
@ -413,7 +421,7 @@ void yon_add_file(main_window *widgets){
else if (strstr(p,"Architecture")) packarch = yon_char_new(cur_string);
}
GtkTreeIter *iter = yon_repo_append(widgets,filename,YON_REPO_LINE_FILE_TYPE);
gtk_tree_store_set(main_config.tree_store,iter,0,"com.ublinux.ubl-settings-repomanager.document-green-symbolic",11,packname,12,packver,13,packarch,-1);
gtk_tree_store_set(main_config.tree_store,iter,0,document_added,11,packname,12,packver,13,packarch,-1);
}
on_close_subwindow(chooser);
@ -447,6 +455,7 @@ main_window *setup_window(){
widgets->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
widgets->HatLabel = yon_gtk_builder_get_widget(builder,"headerTopic");
widgets->PlugBox = yon_gtk_builder_get_widget(builder,"plugBox");
widgets->MovePaned = yon_gtk_builder_get_widget(builder,"MovePaned");
widgets->HeadOverlay = yon_gtk_builder_get_widget(builder,"HeadOverlay");
widgets->HeadImage = yon_gtk_builder_get_widget(builder,"HeadBackgroundImage");
@ -536,6 +545,10 @@ main_window *setup_window(){
}
}
/* Widget registration for config monitoring | Регистрация виджетов для мониторинга конфига */
yon_window_config_add_listener(widgets->MovePaned,"pane_position","position",YON_TYPE_INT);
/* Signal connection | Присоединение сигналов */
g_signal_connect(G_OBJECT(widgets->Window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(widgets->DocumentationMenuItem),"activate",G_CALLBACK(on_open_documentation_confirmation),WIKI_LINK);
@ -636,12 +649,12 @@ int main(int argc, char *argv[]){
main_window *widgets = setup_window();
yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
yon_window_config_setup(GTK_WINDOW(widgets->Window));
yon_window_config_load(config_path);
on_load();
GtkCssProvider *css=gtk_css_provider_new();
gtk_css_provider_load_from_resource(css,CssPath);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),

@ -26,6 +26,13 @@
#define CssPath "/com/ublinux/css/ubl-settings-repomanager.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define folder_no_edits "com.ublinux.ubl-settings-repomanager.folder-symbolic"
#define folder_deleted "com.ublinux.ubl-settings-repomanager.folder-red-symbolic"
#define folder_added "com.ublinux.ubl-settings-repomanager.folder-green-symbolic"
#define document_no_edits "com.ublinux.ubl-settings-repomanager.document-symbolic"
#define document_deleted "com.ublinux.ubl-settings-repomanager.document-red-symbolic"
#define document_added "com.ublinux.ubl-settings-repomanager.document-green-symbolic"
#define LocalePath "/usr/share/locale"
#define LocaleName "ubl-settings-repomanager"
typedef char* string;
@ -58,6 +65,8 @@ typedef struct {
GtkWidget *HatLabel;
GtkWidget *PlugBox;
GtkWidget *MovePaned;
GtkWidget *HeadOverlay;
GtkWidget *HeadImage;
GtkWidget *HeadBox;

@ -2,7 +2,7 @@
// dictionary functions
/**yon_dictionary_create_empty():
/**yon_dictionary_new():
* [EN]
* Creates and returns empty dictionary
* [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)
@ -65,6 +66,7 @@ int yon_dictionary_set_data(dictionary *dict, void *data){
*/
int yon_dictionary_set_key(dictionary *dict, char *key){
dict->key=key;
return 1;
}
/** int yon_dictionary_set(dictionary *dict, char *key, void *data)
@ -76,6 +78,7 @@ int yon_dictionary_set_key(dictionary *dict, char *key){
int yon_dictionary_set(dictionary *dict, char *key, void *data){
dict->key=key;
dict->data=data;
return 1;
}
/**int yon_dictionary_empty(dictionary *dict)
@ -87,6 +90,7 @@ int yon_dictionary_set(dictionary *dict, char *key, void *data){
int yon_dictionary_empty(dictionary *dict){
dict->data=NULL;
dict->data_type=DICTIONARY_OTHER_TYPE;
return 1;
}
/**yon_dictionary_switch_to_last(dictionary **dict)
@ -433,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.
@ -570,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)
@ -603,19 +613,24 @@ char *yon_char_from_int(int int_to_convert)
* [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));
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);
}
}
return source;
}
return source;
}
/**yon_char_parse(char *parameters, int *size, char *divider)
@ -1374,12 +1389,28 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end
#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;
} __yon_main_window_config;
static GtkWindow *__yon_window_config_target_window = NULL;
@ -1392,6 +1423,42 @@ 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.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);
}
@ -1468,6 +1535,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);
@ -1483,6 +1571,37 @@ 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);
}
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);
}
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");

@ -124,6 +124,8 @@ void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(vo
// char functions
int yon_char_find_last(char *source, char find);
char *yon_char_append(char *source, char *append);
char *yon_char_new(char *chr);
@ -214,6 +216,13 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end
#endif
enum YON_TYPE{
YON_TYPE_STRING,
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);
@ -237,6 +246,12 @@ 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);
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);

@ -684,7 +684,7 @@ translated and supported by community.</property>
</packing>
</child>
<child>
<object class="GtkPaned">
<object class="GtkPaned" id="MovePaned">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="position">395</property>

Loading…
Cancel
Save