You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
381 lines
13 KiB
381 lines
13 KiB
#include "libublsettings-gtk3.h"
|
|
|
|
#include <alpm.h>
|
|
|
|
#ifdef __GTK_H__
|
|
|
|
// GtkEntry section
|
|
// struct entry_pattern_data {
|
|
// GtkEntry *entry;
|
|
// char *pattern; // %d %s
|
|
// };
|
|
|
|
// char *yon_gtk_entry_pattern_format(GtkWidget *target, struct entry_pattern_data *data){
|
|
// if (target){
|
|
// const char *entry_data = gtk_entry_get_text(target);
|
|
// int next_track=0;
|
|
// for (int i=0; i<strlen(data->pattern);i++){
|
|
// char target_letter=-1;
|
|
// target_letter = ;
|
|
// switch (data->pattern[i]){
|
|
// case '%':next_track=1;
|
|
// break;
|
|
// case 'd':if (next_track){
|
|
|
|
// }
|
|
// break;
|
|
// case 's':
|
|
// break;
|
|
// default:
|
|
|
|
// }
|
|
// }
|
|
|
|
// };
|
|
// }
|
|
|
|
// void yon_gtk_entry_set_pattern(GtkEntry *entry, char *pattern){
|
|
// struct entry_pattern_data *data = malloc(sizeof(struct entry_pattern_data));
|
|
// data->entry=entry;
|
|
// data->pattern=pattern;
|
|
// char *current_text = gtk_entry_get_text(entry);
|
|
|
|
// }
|
|
|
|
struct packages {
|
|
alpm_handle_t *packages_handle;
|
|
int init_status;
|
|
} packages_struct = {};
|
|
|
|
int _yon_packages_get_db(){
|
|
const char *root = "/";
|
|
const char *dbpath = "/var/lib/pacman";
|
|
const char *config_path = "/etc/pacman.conf";
|
|
packages_struct.packages_handle = alpm_initialize(root,dbpath,NULL);
|
|
if (!packages_struct.packages_handle){
|
|
packages_struct.init_status=0;
|
|
return 0;
|
|
}
|
|
int size = 0;
|
|
config_str pacman_config = yon_file_open((char*)config_path,&size);
|
|
char *pacman_config_full = yon_char_parsed_to_string(pacman_config,size,"");
|
|
|
|
GRegex *regex = g_regex_new("^\\[.*\\]$",G_REGEX_MULTILINE,0,NULL);
|
|
GMatchInfo *match = NULL;
|
|
g_regex_match(regex,pacman_config_full,G_REGEX_MATCH_DEFAULT,&match);
|
|
|
|
while (g_match_info_matches(match)){
|
|
char *iter = g_match_info_fetch(match,0);
|
|
if (iter[0]=='['){
|
|
free(yon_char_divide(iter,0));
|
|
yon_char_remove_last_symbol(iter,']');
|
|
}
|
|
if (strcmp(iter,"options")){
|
|
alpm_register_syncdb(packages_struct.packages_handle,iter,ALPM_SIG_USE_DEFAULT);
|
|
}
|
|
g_match_info_next(match,NULL);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
alpm_list_t *_yon_packages_get_db_list(enum YON_PACKAGES_DB_TYPE type){
|
|
alpm_list_t *db_list = NULL;
|
|
switch(type){
|
|
case YON_PACKAGES_LOCAL:
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
break;
|
|
|
|
case YON_PACKAGES_SYNC:
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
break;
|
|
|
|
case YON_PACKAGES_ALL:{
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
}
|
|
{
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
if (!db_list) db_list = alpm_list_append(&db_list,database);
|
|
else alpm_list_append(&db_list,database);
|
|
}
|
|
break;
|
|
|
|
}
|
|
return db_list;
|
|
}
|
|
|
|
int yon_packages_init(){
|
|
if (packages_struct.packages_handle) return 0;
|
|
|
|
int status = _yon_packages_get_db();
|
|
if (!status) return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
int yon_packages_check_exist(const char *package_name){
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int yon_packages_check_installed(char *package_name){
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) return 1;
|
|
return 0;
|
|
}
|
|
|
|
int yon_packages_check_updates(char *package_name){
|
|
alpm_pkg_t *sync_db_package = NULL;
|
|
alpm_pkg_t *local_db_package = NULL;
|
|
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) sync_db_package = package;
|
|
}
|
|
{
|
|
alpm_db_t *database = alpm_get_localdb(packages_struct.packages_handle);
|
|
alpm_pkg_t *package = alpm_db_get_pkg(database,package_name);
|
|
if (package) local_db_package = package;
|
|
}
|
|
|
|
if (sync_db_package && local_db_package){
|
|
const char *sync_db_package_version = alpm_pkg_get_version(sync_db_package);
|
|
const char *local_db_package_version = alpm_pkg_get_version(sync_db_package);
|
|
if (strcmp(sync_db_package_version,local_db_package_version)) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
config_str yon_packages_find(enum YON_PACKAGES_DB_TYPE type, const char *search_string, gsize *size){
|
|
(*size)=0;
|
|
if (yon_char_is_empty(search_string)) return NULL;
|
|
|
|
config_str final = NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_list_t *packages = alpm_db_get_pkgcache(database);
|
|
alpm_list_t *iter2 = NULL;
|
|
for (iter2 = packages; iter2; iter2=iter2->next){
|
|
const char *name = alpm_pkg_get_name(iter2->data);
|
|
if (strstr(name,search_string)){
|
|
yon_char_parsed_add_or_create_if_exists(final,(int*)size,(char*)name);
|
|
}
|
|
}
|
|
}
|
|
return final;
|
|
}
|
|
|
|
char *yon_packages_get_version(enum YON_PACKAGES_DB_TYPE type, const char *package){
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
const char *name = alpm_pkg_get_name(pkg);
|
|
if (!strcmp(name,package)){
|
|
return yon_char_new(alpm_pkg_get_version(pkg));
|
|
}
|
|
}
|
|
}
|
|
|
|
char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *package){
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
const char *name = alpm_pkg_get_name(pkg);
|
|
if (!strcmp(name,package)){
|
|
return yon_char_new(alpm_pkg_get_desc(pkg));
|
|
}
|
|
}
|
|
}
|
|
|
|
config_str yon_packages_get_depends(enum YON_PACKAGES_DB_TYPE type, const char *package, int *size){
|
|
(*size)=0;
|
|
if (yon_char_is_empty(package)) return NULL;
|
|
config_str depends = NULL;
|
|
|
|
alpm_list_t *databases = _yon_packages_get_db_list(type);
|
|
alpm_list_t *iter = NULL, *pkg_iter = NULL;
|
|
for (iter = databases; iter; iter=iter->next){
|
|
alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package);
|
|
if (!pkg) continue;
|
|
alpm_list_t *list = alpm_pkg_compute_requiredby(pkg);
|
|
for (pkg_iter = list; pkg_iter; pkg_iter=pkg_iter->next){
|
|
yon_char_parsed_add_or_create_if_exists(depends,size,pkg_iter->data);
|
|
|
|
}
|
|
break;
|
|
}
|
|
|
|
return depends;
|
|
}
|
|
|
|
void yon_packages_update(){
|
|
if (packages_struct.packages_handle) alpm_release(packages_struct.packages_handle);
|
|
packages_struct.packages_handle=NULL;
|
|
_yon_packages_get_db();
|
|
}
|
|
|
|
int yon_packages_install(char *package){
|
|
if (!packages_struct.init_status) return 0;
|
|
// char *command = install_package_command(package);
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
yon_packages_update();
|
|
// free(command);
|
|
}
|
|
|
|
int yon_packages_remove(char *package){
|
|
if (!packages_struct.init_status) return 0;
|
|
// char *command = remove_package_command(package);
|
|
// yon_terminal_window_launch(NULL,command,"","");
|
|
|
|
yon_packages_update();
|
|
// free(command);
|
|
}
|
|
|
|
void yon_packages_finish(){
|
|
if (!packages_struct.init_status) return;
|
|
alpm_release(packages_struct.packages_handle);
|
|
}
|
|
|
|
GList *yon_packages_get_all(){
|
|
if (!packages_struct.init_status) return NULL;
|
|
|
|
GList *list = NULL;
|
|
|
|
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
|
|
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
|
|
alpm_db_t *database = iter->data;
|
|
alpm_list_t *package_list = alpm_db_get_pkgcache(database);
|
|
for (alpm_list_t *iter = package_list;iter;iter=iter->next){
|
|
const char *cur_name = alpm_pkg_get_name(iter->data);
|
|
if (!list) list = g_list_append(list,yon_char_new(cur_name));
|
|
else if (g_list_append(list,yon_char_new(cur_name))){};
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
config_str yon_resource_open_file(const char *path, int *size){
|
|
config_str parsed = NULL;
|
|
char *modules = NULL;
|
|
gsize sz=0;
|
|
GFile *file = g_file_new_for_uri(path);
|
|
g_file_load_contents(file,NULL,&modules,&sz,NULL,NULL);
|
|
g_object_unref(G_OBJECT(file));
|
|
parsed = yon_char_parse(modules,size,"\n");
|
|
return parsed;
|
|
}
|
|
|
|
|
|
struct yon_combo_default_struct {
|
|
char *command;
|
|
GtkComboBoxText *target;
|
|
void *result_callback; // char*(*)(char*)
|
|
char *default_value;
|
|
char *command_value;
|
|
};
|
|
|
|
void _yon_combo_box_set_default_value(struct yon_combo_default_struct *target){
|
|
gtk_combo_box_text_prepend(target->target," ",target->default_value);
|
|
if (!yon_char_is_empty(target->default_value)) free(target->command);
|
|
if (!yon_char_is_empty(target->default_value)) free(target->command_value);
|
|
}
|
|
|
|
void *__yon_combo_set_default(struct yon_combo_default_struct *target){
|
|
int size;
|
|
config_str parameter = yon_config_load(yon_config_parameter_prepare_command(target->command,"default",NULL,NULL),&size);
|
|
if (size&&!yon_char_is_empty(parameter[0])&&strcmp(parameter[0],"(null)\n")){
|
|
yon_char_remove_last_symbol(parameter[0],'\n');
|
|
target->command_value = yon_char_new(parameter[0]);
|
|
target->default_value = ((char*(*)(char*))(target->result_callback))(parameter[0]);
|
|
} else {
|
|
target->default_value = ((char*(*)(char*))(target->result_callback))(NULL);
|
|
}
|
|
g_idle_add_once((GSourceOnceFunc)_yon_combo_box_set_default_value,target);
|
|
|
|
}
|
|
|
|
void yon_combo_box_set_default(GtkComboBoxText *target, char *command, char*(result_callback)(char*)){
|
|
struct yon_combo_default_struct *target_struct = malloc(sizeof(struct yon_combo_default_struct));
|
|
target_struct->result_callback = result_callback;
|
|
target_struct->target = target;
|
|
target_struct->command = yon_char_new(command);
|
|
target_struct->command_value=NULL;
|
|
target_struct->default_value = NULL;
|
|
g_thread_new("combo_get_default",(GThreadFunc)__yon_combo_set_default,target_struct);
|
|
}
|
|
|
|
// dictionary *__yon_config_listeners = NULL;
|
|
// typedef struct {
|
|
// GtkWidget *target;
|
|
// char *widget_parameter;
|
|
// void *check_function;
|
|
// char *parameter;
|
|
// char *save_command;
|
|
// } config_listener;
|
|
|
|
// void __yon_gtk_config_activated(GtkWidget *, config_listener *current){
|
|
// char *parameter;
|
|
|
|
// if (((int (*)(char*, GtkWidget*, char*))(current->check_function))(parameter,current->target, current->parameter)) {
|
|
// }
|
|
|
|
// }
|
|
|
|
// int yon_gtk_config_add_listener (GtkWidget *target, char *parameter, char *save_command,int(check_function)(char*,GtkWidget*,char*)){
|
|
// if (__yon_config_listeners){
|
|
// dictionary *dict;
|
|
// for_dictionaries(dict,__yon_config_listeners){
|
|
// if (target==((config_listener*)dict->data)->target){
|
|
// return 0;
|
|
// }
|
|
// }
|
|
// }
|
|
// config_listener *current = malloc(sizeof(config_listener));
|
|
// current->target=target;
|
|
// current->parameter = parameter;
|
|
// current->save_command = save_command;
|
|
// current->check_function = (void*)check_function;
|
|
// if (GTK_IS_TOGGLE_BUTTON(target)){
|
|
// g_signal_connect(G_OBJECT(target),"toggled",C_CALLBACK(__yon_gtk_config_activated),current);
|
|
|
|
// }
|
|
|
|
// yon_dictionary_add_or_create_if_exists_with_data(__yon_config_listeners,NULL,current);
|
|
// return 0;
|
|
// }
|
|
|
|
#endif |