#include "ubl-utils.h" #ifndef UBL_UTILS typedef enum { DICTIONARY_ACTION_WIDGETS_TYPE, DICTIONARY_IVGRAPHICALS_TYPE, DICTIONARY_OTHER_TYPE } DICT_TYPE; typedef struct dictionary { char *key; void *data; struct dictionary *next; struct dictionary *prev; struct dictionary *first; DICT_TYPE data_type; } dictionary; typedef struct apps{ char *Name; int Type; char *Categories; char *Exec; char *Icon; int Pluggable; int DualPluggable; } apps; typedef struct { char *command; int *exitcode; } thread_output; #ifdef __GTK_H__ typedef struct IVGrapgicals{ char *sectionName; char *categories; GtkListStore *LV; GtkWidget *Box; GtkWidget *IV; GtkWidget *label; GtkWidget *sep; GtkCellRendererPixbuf *iconRender; } IVGraphicals; #endif #endif //dictionary functions dictionary *yon_dictionary_create_empty(){ dictionary *dict=malloc(sizeof(dictionary)); dict->data=NULL; dict->key=NULL; dict->next=NULL; dict->prev=NULL; dict->first=dict; dict->data_type=DICTIONARY_OTHER_TYPE; return dict; } void yon_dictionary_switch_to_last(dictionary **dict){ if ((*dict)->next!=NULL) for ((*dict)=(*dict)->first;(*dict)->next!=NULL;(*dict)=(*dict)->next){} } dictionary * yon_dictionary_create_conneced(dictionary *targetdict){ yon_dictionary_switch_to_last(&targetdict); targetdict->next=yon_dictionary_create_empty(); targetdict->next->prev=targetdict; targetdict->next->first=targetdict->first; targetdict->next->data_type=DICTIONARY_OTHER_TYPE; return targetdict->next; } dictionary *yon_dictionary_get_last(dictionary *dict){ dictionary *dct=NULL; for (dct=dict->first;dct->next!=NULL;dct=dct->next){} return dct; } dictionary *yon_dictionary_switch_places(dictionary *dict,int aim){ if (aim<0){ if (dict->prev){ if (dict->prev->prev){ dictionary *next = dict->next,*prev=dict->prev,*preprev=prev->prev; if (next){ preprev->next=dict; dict->prev=preprev; dict->next=prev; prev->prev=dict; prev->next=next; next->prev=prev; } else { preprev->next=dict; dict->prev=preprev; dict->next=prev; prev->prev=dict; prev->next=NULL; } return prev; } else { dictionary *next = dict->next,*prev=dict->prev; if (next){ yon_dictionary_make_first(dict); dict->prev=NULL; dict->next=prev; prev->prev=dict; prev->next=next; next->prev=prev; } else { dict->prev=NULL; dict->next=prev; prev->prev=dict; prev->next=NULL; } return prev; } } } else if (aim>0){ if (dict->next){ if (dict->next->next){ dictionary *next = dict->next,*prev=dict->prev,*afnext=next->next; if (prev){ prev->next=next; next->prev=prev; next->next=dict; dict->prev=next; dict->next=afnext; afnext->prev=dict; } else { yon_dictionary_make_first(next); next->prev=NULL; next->next=dict; dict->prev=next; dict->next=afnext; afnext->prev=dict; } return next; } else { dictionary *next = dict->next,*prev=dict->prev; if (prev){ prev->next=next; next->prev=prev; next->next=dict; dict->prev=next; dict->next=NULL; } else { next->prev=NULL; next->next=dict; dict->prev=next; dict->next=NULL; } } } } } void yon_dictionary_make_first(dictionary *dict){ for (dictionary *dct=dict->first;dct!=NULL;dct=dct->next){ dct->first=dict; } } void yon_dictionary_make_nth(dictionary *dict, int nth){ dictionary *dct=dict->first; for (int i=0;inext;} yon_dictionary_rip(dict); dictionary *prev=dct->prev; prev->next=dict; dict->prev=prev; dict->next=dct; dct->prev=dict; } dictionary *yon_dictionary_create_with_data(char *key, void *data){ dictionary *dct=yon_dictionary_create_empty(); dct->key=key; dct->data=data; dct->data_type=DICTIONARY_OTHER_TYPE; return dct; } dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data){ dictionary *dct=yon_dictionary_create_conneced(dict); dct->key=key; dct->data=data; dct->data_type=DICTIONARY_OTHER_TYPE; return dct; } dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect){ dictionary *dict=yon_dictionary_get_last(old); dict->next=toconnect; toconnect->prev=dict; toconnect->first=dict->first; return toconnect; } dictionary *yon_dictionary_find(dictionary **dict, char *key){ dictionary *dct=*dict; for (dictionary *pointer=dct->first;pointer!=NULL;pointer=pointer->next){ if (strcmp(pointer->key,key)==0){ *dict=pointer; return pointer; } } return NULL; } dictionary *yon_dictionary_rip(dictionary *dict){ if (!dict->next){ dictionary *prev=dict->prev; if (prev){ prev->next=NULL; return prev; } else return dict; } else if (!dict->prev){ dictionary *next=dict->next; if (next){ yon_dictionary_make_first(next); next->prev=NULL; return next; } else return dict; } else { dictionary *next=dict->next, *prev=dict->prev; next->prev=prev; prev->next=next; return next; } } dictionary *yon_dictionary_get_nth(dictionary *dict, int place){ for (int i=0;inext; return dict; } //char functions char *yon_char_get_augumented(char *source, char *append){ int size=strlen(source)+strlen(append)+1; char *final=malloc(size); memset(final,0,size); sprintf(final,"%s%s",source,append); return final; } char *yon_char_new(char *chr){ char *newchar=malloc(strlen(chr)+1); memset(newchar,0,strlen(chr)+1); memcpy(newchar,chr,strlen(chr)); return newchar; } char *yon_cut(char *source, int size, int startpos){ char *cut=NULL; cut=malloc(size+1); memset(cut,0,size+1); memcpy(cut,source+startpos,size); return cut; } char *yon_char_divide(char *source, int dividepos){ char *cut=malloc(dividepos+1); memset(cut,0,dividepos+1); memcpy(cut,source,dividepos); char *left=malloc(strlen(source)-strlen(cut)); memset(left,0,strlen(source)-strlen(cut)); memcpy(left,source+dividepos+1,(strlen(source)-dividepos)); memset(source,0,strlen(source)); memcpy(source,left,strlen(left)); return cut; } char *yon_char_divide_search(char *source, char* dividepos, int delete_divider){ char *cut=strstr(source,dividepos); int leng=strlen(source)-strlen(cut); cut=yon_char_divide(source,leng); return cut; } char *yon_char_from_int(int 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=malloc(i*sizeof(char)+1); sprintf(ch,"%d",int_to_convert); return ch; } //parsing functions apps *yon_apps_scan_and_parse_desktops(int *sizef){ int size=0; struct apps *applist; { DIR *directory=opendir(DesktopPath); struct dirent *de; while ((de = readdir(directory))) { FILE *file; char *path=yon_char_get_augumented(DesktopPath,de->d_name); file=fopen(path,"r"); if (strlen(de->d_name)>9) { char *extension=strstr(path,"."); if (extension!=NULL) { if (strcmp(extension,".desktop")==0) { apps tempapp; GKeyFile *gfile=g_key_file_new(); g_key_file_load_from_file(gfile,path,G_KEY_FILE_KEEP_TRANSLATIONS,NULL); char *Type=g_key_file_get_string(gfile,"Desktop Entry", "Type",NULL); if (strcmp(Type,"Application")==0) tempapp.Type=1; else if (strcmp(Type,"pyApplication")==0) tempapp.Type=2; else continue; tempapp.Name=g_key_file_get_locale_string(gfile,"Desktop Entry","Name",setlocale(LC_ALL,NULL),NULL); if (tempapp.Name==NULL) continue; tempapp.Categories=g_key_file_get_string(gfile,"Desktop Entry", "Categories",NULL); if (tempapp.Categories==NULL) continue; tempapp.Exec=g_key_file_get_string(gfile,"Desktop Entry", "Exec",NULL); if (tempapp.Exec==NULL) continue; tempapp.Icon=g_key_file_get_string(gfile,"Desktop Entry", "Icon",NULL); if (tempapp.Icon==NULL) continue; tempapp.Pluggable=g_key_file_get_boolean(gfile,"Desktop Entry", "Pluggable",NULL); if (!tempapp.Pluggable) tempapp.Pluggable=g_key_file_get_boolean(gfile,"Desktop Entry", "X-XfcePluggable",NULL); if (tempapp.Pluggable) tempapp.DualPluggable=g_key_file_get_boolean(gfile,"Desktop Entry", "X-UBLPluggable",NULL); if (g_key_file_get_boolean(gfile,"Desktop Entry", "X-UBL-SettingsManager-Hidden",NULL)==0) if (size==0){ applist=(apps*)malloc(size+1*sizeof(apps)); applist[0].Name=yon_char_new(tempapp.Name); applist[0].Categories=yon_char_new(tempapp.Categories); applist[0].Exec=yon_char_new(tempapp.Exec); applist[0].Icon=yon_char_new(tempapp.Icon); applist[0].Type=tempapp.Type; applist[0].Pluggable=tempapp.Pluggable; applist[0].DualPluggable=tempapp.DualPluggable; size++; } else { applist=(apps*)realloc(applist,(size+1)*sizeof(apps)); applist[size].Name=yon_char_new(tempapp.Name); applist[size].Categories=yon_char_new(tempapp.Categories); applist[size].Exec=yon_char_new(tempapp.Exec); applist[size].Icon=yon_char_new(tempapp.Icon); applist[size].Pluggable=tempapp.Pluggable; applist[size].DualPluggable=tempapp.DualPluggable; applist[size].Type=tempapp.Type; size++; } } } } } } *sizef=size; return applist; }; void yon_apps_sort(apps *applist,int size){ apps tmp; if (size>2) { for (int i=1;icommand=path; thread->exitcode=malloc(sizeof(int)); pthread_t thread_id; pthread_create(&thread_id, NULL, (void*)yon_launch, thread); return *thread->exitcode; }; int yon_launch_app_with_arguments(char *name, char *args){ char *path=yon_char_get_augumented("/usr/bin/",name); path=yon_char_get_augumented(path," "); path=yon_char_get_augumented(path,args); pthread_t thread_id; thread_output *thread=malloc(sizeof(thread_output)); thread->command=path; thread->exitcode=malloc(sizeof(int)); pthread_create(&thread_id, NULL, (void*)yon_launch, thread); return *thread->exitcode; }; int yon_launch(thread_output *thread){ int a=0; a=system(thread->command); *thread->exitcode=a; return *thread->exitcode; } //Gtk functions #ifdef __GTK_H__ GtkWidget *yon_gtk_socket_create_new_with_connect(GtkWidget *container, gpointer data){ GtkWidget *socket; socket = gtk_socket_new(); g_signal_connect(G_OBJECT(socket),"plug-added",G_CALLBACK(yon_on_plug_added),data); g_signal_connect(G_OBJECT(socket),"plug-removed",G_CALLBACK(yon_on_plug_removed),data); g_signal_connect(G_OBJECT(socket),"destroy",G_CALLBACK(yon_on_plug_removed),data); gtk_box_pack_start(GTK_BOX(container),socket,1,1,0); return socket; }; int yon_gtk_icon_view_hide_empty(dictionary *icon_view_segment){ if (icon_view_segment->data_type==DICTIONARY_IVGRAPHICALS_TYPE){ for (dictionary *icvd=icon_view_segment->first;icvd!=NULL;icvd=icvd->next){ IVGraphicals *icv=icvd->data; GtkTreeIter iter; if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(icv->LV),&iter)==0){ gtk_widget_hide(icv->Box); // gtk_widget_hide(GTK_WIDGET(icv->sep)); } } } } int yon_dictionary_gtk_pack_start_multiple_widgets(dictionary *dict, GtkWidget *destination, gboolean expand, gboolean fill, int padding){ for (dictionary *dct=dict->first; dct!=NULL;dct=dct->next){ gtk_box_pack_start(GTK_BOX(destination),(GtkWidget*)dct->data,expand,fill,padding); } return 1; } int yon_dictionary_gtk_pack_end_multiple_widgets(dictionary *dict, GtkWidget *destination, gboolean expand, gboolean fill, int padding){ for (dictionary *dct=dict->first; dct!=NULL;dct=dct->next){ gtk_box_pack_end(GTK_BOX(destination),(GtkWidget*)dct->data,expand,fill,padding); } return 1; } #endif