#ifndef UBL_SETTINGS_SERVICES_H
#define UBL_SETTINGS_SERVICES_H
#include <gtk/gtk.h> 
#include <gdk/gdk.h> 
#include <gtk/gtkx.h> 
#include <locale.h> 
#include <stdio.h> 
#include <unistd.h> 
#include <stdlib.h> 
#include <libintl.h> 
#include <getopt.h> 
#include <libintl.h>
#include <vte/vte.h>
#include <libublsettings.h> 
#include <libublsettings-gtk3.h>
#include <libublsettingsui-gtk3.h> 
#include "ubl-settings-services-systemd.h"
#include <time.h>
#include <json-c/json.h>
#ifdef WEBKIT_FOUND 
    #include <webkit2/webkit2.h> 
#endif  
#include "ubl-strings.h" 
  
#define _(String) gettext(String) 
 
#define glade_path "/com/ublinux/ui/ubl-settings-services.glade"
#define glade_path_log "/com/ublinux/ui/ubl-settings-services-terminal.glade"
 
#define banner_path "/com/ublinux/images/ubl-settings-services-banner.png"
#define CssPath "/com/ublinux/css/ubl-settings-services.css" 
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL) 
 
#define LocalePath "/usr/share/locale"  
#define LocaleName "ubl-settings-services"

#define systemd_config_path "resource:///com/ublinux/csv/systemd_conf.csv"

#define load_services_command \
"systemctl --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,FragmentPath,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic " \
"--no-pager --all --no-legend show -- $( { " \
"systemctl list-units --no-pager --all --plain --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \
"systemctl list-unit-files --no-pager --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \
"} | sed '/@\\./d' | sort -u ) | " \
"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \
"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \
"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \
"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \
"val[\"InactiveEnterTimestampMonotonic\"] \";\" val[\"FragmentPath\"]; delete val }'"

#define load_system_units_command "systemctl list-unit-files --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)(.*)/\\1/'"
#define load_user_units_command yon_char_unite(\
"systemctl --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,FragmentPath,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic " \
"--no-pager --all --no-legend show -- $( { " \
"systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --no-pager --all --plain --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \
"systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-unit-files --no-pager --no-legend | sed -E 's/^([^ ]+).*/\\1/'; " \
"} | sed '/@\\./d' | sort -u ) | " \
"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \
"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \
"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \
"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \
"val[\"InactiveEnterTimestampMonotonic\"] \";\" val[\"FragmentPath\"]; delete val }'",NULL)
#define load_user_services_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --no-pager --all --plain --no-legend |sed -E 's/(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)/\\1;\\2;\\3;\\4;\\5/'",NULL)
#define load_system_services_command "systemctl --system list-units --no-pager --all |grep -E \"^ \" |grep -v \"UNIT\" |sed -e 's/   */;/g' -e 's/^;//g' |cut -f1 -d';'"
#define load_enabled_command "systemctl list-unit-files --no-pager --state=enabled --all |sed -e 's/  */:/g' -e 's/ *: */:/g'|cut -f1 -d:"
#define load_launched_command "systemctl list-units --no-pager --state=active --all --no-legend|sed -e 's/^  //g' -e 's/  */:/g' |cut -f1 -d:"
#define service_start_command(target) yon_char_append("systemctl start ",target)
#define service_stop_command(target) yon_char_append("systemctl stop ",target)
#define service_enable_command(target) yon_char_append("systemctl enable ",target)
#define service_disable_command(target) yon_char_append("systemctl disable ",target)
#define service_kill_command(target) yon_char_append("systemctl kill ",target)
#define service_check_active_command(target) yon_char_append("systemctl is-active ",target)
#define check_enabled_command(target) yon_char_append("systemctl is-enabled ",target)
#define user_check_active_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ is-active ",target,NULL)
#define user_check_enabled_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ is-enabled ",target,NULL)

#define load_system_service_single(target) yon_char_unite("systemctl --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,FragmentPath,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic --no-pager --all --no-legend show -- ",target,\
"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \
"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \
"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \
"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \
"val[\"InactiveEnterTimestampMonotonic\"] \";\" val[\"FragmentPath\"]; delete val }'",NULL)
#define load_user_service_single(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ --property=Names,Description,LoadState,ActiveState,SubState,UnitFileState,FragmentPath,ActiveEnterTimestampMonotonic,InactiveEnterTimestampMonotonic --no-pager --all --no-legend show -- ",target,\
"awk 'BEGIN { RS=\"\"; FS=\"\\n\" } " \
"{ for (i=1; i<=NF; i++) { split($i, kv, \"=\"); val[kv[1]] = kv[2]; } " \
"print val[\"Names\"] \";\" val[\"LoadState\"] \";\" val[\"ActiveState\"] \";\" val[\"SubState\"] \";\" " \
"val[\"Description\"] \";\" val[\"UnitFileState\"] \";\" val[\"ActiveEnterTimestampMonotonic\"] \";\" " \
"val[\"InactiveEnterTimestampMonotonic\"] \";\" val[\"FragmentPath\"]; delete val }'",NULL)

#define service_info_command(target) yon_char_append("systemctl status -l --no-pager ",target)
#define get_log_command(target) yon_char_append("journalctl --all --no-pager --unit ",target)
#define show_source_command(target) yon_char_append("systemctl edit --full ",target)
#define properties_command(target) yon_char_append("systemctl show --no-pager ",target)

#define user_service_info_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ status -l --no-pager ",target,NULL)
#define user_get_log_command(target) yon_char_unite("usermod -a -G systemd-journal ",yon_ubl_root_user_get(),";journalctl --user -u --all --no-pager --unit ",target,NULL)
#define user_show_source_command(target) yon_char_unite("systemctl edit --full ",target,NULL)
#define user_properties_command(target) yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ show --no-pager ",target,NULL)

#define get_config_files_command "find /etc/systemd -iname *.conf -exec du -sh --time {} \\;|sed -e 's/\t/;/g'"

#define system_services_status_command "systemctl status --no-pager"
#define installed_units_states_command "systemctl list-unit-files --no-pager"
#define list_of_units_states_command "systemctl list-units --all --no-pager"
#define list_of_sockets_states_command "systemctl list-sockets --all --no-pager"
#define list_of_timers_states_command "systemctl list-timers --all --no-pager"
#define get_timers_command "systemctl list-timers --all --no-pager --plain --no-legend --output=json"

#define user_services_status_command !getuid()?yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ status --no-pager",NULL):"systemctl --user status --no-pager"
#define user_installed_units_states_command !getuid()?yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-unit-files --no-pager",NULL):"systemctl --user list-unit-files --no-pager"
#define user_list_of_units_states_command !getuid()?yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-units --all --no-pager",NULL):"systemctl --user list-units --all --no-pager"
#define user_list_of_sockets_states_command !getuid()?yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-sockets --all --no-pager",NULL):"systemctl --user list-sockets --all --no-pager"
#define user_list_of_timers_states_command !getuid()?yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@ list-timers --all --no-pager",NULL):"systemctl --user list-timers --all --no-pager"

#define installed_units_command "systemctl list-unit-files --no-pager| sed -e 's/  */;/g'"
#define list_of_units_command "systemctl list-units --all --no-pager| sed -e 's/  */;/g'"
#define list_of_sockets_command "systemctl list-sockets --all --no-pager| sed -e 's/  */;/g'"
#define list_of_timers_command "systemctl list-timers --all --no-pager| sed -e 's/  */;/g'"
#define list_of_session_command "while IFS=\" \" read -r GET_SESSION GET_UID GET_USER GET_SEAT GET_TTY; do echo -e \"${GET_SESSION} $(loginctl session-status ${GET_SESSION} --no-page | sed -Enr \"s/^\\s*State: (.*)$/\1/p\") ${GET_UID} ${GET_USER} ${GET_SEAT} ${GET_TTY}\"; done < <(loginctl list-sessions --no-legend)"
#define get_activate_deactivate_times(target) yon_char_append("systemctl show --timestamp=utc -p Names -p ActiveEnterTimestamp -p InactiveEnterTimestamp ",target)

#define config_get_command(target) yon_char_append("cat ",target)

#define yon_config_get_custom_command(target) yon_char_unite("ubconfig --source ",target," get system SERVICES_ENABLE SERVICES_DISABLE SERVICES_MASK",NULL)
#define config_get_local_command "ubconfig --source system get system SERVICES_ENABLE SERVICES_DISABLE SERVICES_MASK"
#define config_get_global_command yon_char_new("ubconfig --source global get system SERVICES_ENABLE SERVICES_DISABLE SERVICES_MASK")
#define config_get_default_command "ubconfig --source default get system SERVICES_ENABLE SERVICES_DISABLE SERVICES_MASK"

#define config_get_global_only_parameters ""
#define config_get_local_only_parameters ""

#define SERVICES_ENABLE_get_command "ubconfig --source global get [system] SERVICES_ENABLE"
#define SERVICES_DISABLE_get_command "ubconfig --source global get [system] SERVICES_DISABLE"
#define CONSOLE_FONT_get_command "ubconfig --source global get [locale] CONSOLE_FONT"

#define play_icon_path "com.ublinux.ubl-settings-services.play-symbolic"
#define stop_icon_path "com.ublinux.ubl-settings-services.stop-symbolic"
#define block_icon_path "com.ublinux.libublsettingsui-gtk3.changes-prevent-symbolic"
#define unlock_icon_path "com.ublinux.libublsettingsui-gtk3.changes-allow-symbolic"
#define end_icon_path "com.ublinux.libublsettingsui-gtk3.move-away-symbolic"
#define switch_icon_path "com.ublinux.libublsettingsui-gtk3.move-in-symbolic"
#define start_icon_path "com.ublinux.ubl-settings-services.launch-symbolic"
#define update_icon_path "com.ublinux.ubl-settings-services.sync-symbolic"
#define launch_icon_path "com.ublinux.ubl-settings-services.check-symbolic"
#define log_icon_path "com.ublinux.ubl-settings-services.lookup-symbolic"
#define source_icon_path "com.ublinux.ubl-settings-services.source-symbolic"
#define properties_icon_path "com.ublinux.ubl-settings-services.properties-symbolic"
#define status_icon_path "com.ublinux.ubl-settings-services.important-symbolic"
#define relaunch_icon_path "com.ublinux.ubl-settings-services.sync-time-symbolic"

#define restart_command(target) yon_char_append("systemctl restart ",target)

#define reload_systemd_root_command "systemctl daemon-reload"
#define reexec_systemd_root_command "systemctl daemon-reexec"

#define reload_systemd_user_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@  daemon-reload",NULL)
#define reexec_systemd_user_command yon_char_unite("systemctl --user --machine=",yon_ubl_root_user_get(),"@  daemon-reexec",NULL)

#define session_activate_session(target) yon_char_append("loginctl activate ",target)
#define session_terminate_session(target) yon_char_append("loginctl terminate-session ",target)
#define session_lock_session(target) yon_char_append("loginctl lock-session ",target)
#define session_unlock_session(target) yon_char_append("loginctl unlock-session ",target)

#define SERVICES_ENABLE_PARAMETER "SERVICES_ENABLE"
#define SERVICES_DISABLE_PARAMETER "SERVICES_DISABLE"
#define SERVICES_MASK_parameter "SERVICES_MASK"
#define SERVICES_MASK_parameter_command "ubconfig --source global get [system] SERVICES_MASK"

typedef char* string; 

__attribute__((unused)) static \
string version_application;
 
enum YON_UNIT_TYPE {
    YON_UNIT_SERVICE=0,
    YON_UNIT_SWAP,
    YON_UNIT_SOCKET,
    YON_UNIT_DEVICE,
    YON_UNIT_TARGET,
    YON_UNIT_MOUNT,
    YON_UNIT_TIMER,
    YON_UNIT_PATH,
    YON_UNIT_SLICE,
    YON_UNIT_SCOPE,
    YON_UNIT_UNRECOGNISED
};

typedef struct systemd_struct{
	char *name;
	char *description;
	int enable;
	int active;
	char *state;
	int load;
}systemd_struct;

 
typedef struct { 
    template_config_fields
    int rmb_clicked;
    GtkTreeModel *ServiceFilter;
    GtkTreeModel *SocketFilter;
    GtkTreeModel *AutolaunchFilter;
    GtkTreeModel *StoppedFilter;
    GtkTreeModel *BlockedFilter;

    GtkTreeModel *SourceFilter;
    int update_thread_active;
	config_str launch_arguments;
	int launch_size;
	int save_config;
    
} config; 
 
typedef struct { 
    template_window_fields
	GtkListStore *UserList;
	GtkListStore *TimersList;
	GtkListStore *SessionsList;
	GtkListStore *ConfigList;
	GtkListStore *SystemList;
	GtkWidget *BoxMain;

	GtkWidget *SystemSearchEntry;
	GtkWidget *SystemFiltersCombo;
    GtkWidget *SystemInactiveShowCheck;
    GtkWidget *SystemUnloadedShowCheck;
	GtkWidget *SystemUpperTree;
	GtkWidget *SystemUnitsTree;
	GtkWidget *SystemPrevButton;
	GtkWidget *SystemUpdateButton;
	GtkWidget *SystemServiceUpdateButton;
	GtkWidget *SystemUpdateServiceButton;
	GtkWidget *SystemInfoButton;
	GtkWidget *SystemLogButton;
	GtkWidget *SystemEditButton;
	GtkWidget *SystemPropertiesButton;
	GtkWidget *SystemStatusButton;
    rmb_menu_window *SystemMenu;
    GtkWidget *SystemServiceLabel;
    GtkWidget *SystemDescriptionLabel;
    GtkWidget *SystemLoadingOverlay;
    GtkWidget *SystemLoadingSpinner;
    GtkWidget *UserLoadingOverlay;
    GtkWidget *UserLoadingSpinner;
    GtkWidget *ConfigLoadingOverlay;
    GtkWidget *ConfigLoadingSpinner;
    GtkWidget *SessionsLoadingOverlay;
    GtkWidget *SessionsLoadingSpinner;
    GtkWidget *TimersLoadingOverlay;
    GtkWidget *TimersLoadingSpinner;
    
	GtkWidget *UserSearchEntry;
	GtkWidget *UserFiltersCombo;
    GtkWidget *UserInactiveShowCheck;
    GtkWidget *UserUnloadedShowCheck;
	GtkWidget *UsersUpperTree;
	GtkWidget *UserUnitsTree;
	GtkWidget *UserPrevButton;
	GtkWidget *UserUpdateButton;
	GtkWidget *UserServiceUpdateButton;
	GtkWidget *UserUpdateServiceButton;
	GtkWidget *UserInfoButton;
	GtkWidget *UserLogButton;
	GtkWidget *UserEditButton;
	GtkWidget *UserStatusButton;
    rmb_menu_window *UserMenu;
    GtkWidget *UserServiceLabel;
    GtkWidget *UserDescriptionLabel;
    GtkWidget *AutostartLabel;
    GtkWidget *TooltipStatusLabel;

	GtkWidget *ConfigEditButton;
	GtkWidget *ConfigUpdateButton;
	GtkWidget *ConfigMainTree;

    GtkWidget *SessionRestartButton;
    GtkWidget *SessionMainTree;
    GtkWidget *SessionSwitchButton;
    GtkWidget *SessionStartButton;
    GtkWidget *SessionStopButton;
    GtkWidget *SessionBlockButton;
    rmb_menu_window *SessionMenu;

    GtkWidget *TimersMainTree;
    GtkWidget *TimersUpdateButton;
	GtkWidget *MainNotebook;

	GtkWidget *SystemServicesStatusMenuItem;
	GtkWidget *InstalledUnitsStatusMenuItem;
	GtkWidget *UnitsStatusListMenuItem;
	GtkWidget *SocketsStatusListMenuItem;
	GtkWidget *TimersStatusListMenuItem;

	GtkWidget *UserServicesStatusMenuItem;
	GtkWidget *UserInstalledUnitsStatusMenuItem;
	GtkWidget *UserUnitsStatusListMenuItem;
	GtkWidget *UserSocketsStatusListMenuItem;
	GtkWidget *UserTimersStatusListMenuItem;

	GtkWidget *TooltipBox;
	GtkWidget *NameLabel;
	GtkWidget *DescriptionLabel;
	GtkWidget *UnitLabel;
	GtkWidget *StatusQueryLabel;
	GtkWidget *ActivateLabel;
	GtkWidget *DeactivateLabel;

	GtkTreeModelFilter *SystemFilter;
	GtkTreeModelSort *SystemSort;
	GtkTreeModelFilter *UserFilter;
	GtkTreeModelSort *UserSort;
 
	GtkCellRenderer *ConfigAutostartCell;
	GtkCellRenderer *ConfigAutostopCell;
	GtkCellRenderer *ConfigBlockCell;
	GtkCellRenderer *SystemAutostartCell;
	GtkCellRenderer *SystemLaunchedCell;

	GtkCellRenderer *UserConfigAutostartCell;
	GtkCellRenderer *UserConfigAutostopCell;
	GtkCellRenderer *UserConfigBlockCell;
	GtkCellRenderer *UserSystemAutostartCell;
	GtkCellRenderer *UserSystemLaunchedCell;
} main_window;

typedef struct { 
    GtkWidget *Window; 
     
    GtkWidget *AlwaysOpenCheck; 
 
    GtkWidget *CloseButton; 
    GtkWidget *AcceptButton; 
} documentation_confirmation_window; 
 
typedef struct{
	GtkListStore *liststore1;
	GtkListStore *liststore2;
	GtkWidget *BoxMain;
	GtkWidget *ServiceSourceCombo;
	GtkWidget *ServiceTypeCombo;
	GtkWidget *SearchEntry;
	GtkWidget *UpdateButton;
	GtkWidget *ConfigAutostartButton;
	GtkWidget *ConfigAutostopButton;
	GtkWidget *ConfigBlockButton;
	GtkWidget *SystemAutostartButton;
	GtkWidget *SystemLaunchButton;
	GtkWidget *InfoButton;
	GtkWidget *LogButton;
	GtkWidget *MainUpperTree;
	GtkWidget *MainTree;
} bl_settings_services_window;

typedef struct {
    GtkWidget *Window;
    GtkWidget *SystemTerminal;
    GtkWidget *TerminalScroll;
    GtkWidget *TextEditor;
    GtkWidget *webHeaderNameLabel;
	GtkWidget *UpdateButton;
	GtkWidget *SaveButton;
	GtkWidget *StatusBox;
	GtkAdjustment *adjustment;
    char *target;
} log_window;

gboolean on_tooltip_show(GtkWidget* self, gint x, gint y, gboolean keyboard_mode, GtkTooltip* tooltip, main_window *widgets);

void on_config_local_load(GtkWidget *self,main_window *widgets);

void on_config_global_load(GtkWidget *self,main_window *widgets);

void on_config_custom_load(GtkWidget *self,main_window *widgets);

void on_config_global_local_save();

void on_config_local_save();

void on_config_global_save();

void on_config_custom_save(GtkWidget *self, main_window *widgets);

void on_service_constant_update();

log_window *yon_log_window_new();

gboolean yon_filter(GtkTreeModel* model, GtkTreeIter *iter, main_window *widgets);
void on_filter_changed(GtkWidget *self, main_window *widgets);

void on_sessions_selection_changed(GtkWidget *self, main_window *widgets);

void on_system_services_status(GtkWidget *self, main_window *widgets);

void on_user_services_status(GtkWidget *self, main_window *widgets);

void on_units_status(GtkWidget *self, main_window *widgets);

void on_units_list_status(GtkWidget *self, main_window *widgets);

void on_sockets_list_status(GtkWidget *self, main_window *widgets);

void on_timers_list_status(GtkWidget *self, main_window *widgets);

void* yon_interface_update(main_window *widgets);

void on_interface_update(GtkWidget *self, main_window *widgets);

GtkWidget *yon_menu_button_create(char *icon_name, char *text);

void on_column_resize(GtkTreeViewColumn *self,GParamSpec *pspec,main_window *widgets);

gboolean on_context_menu_open(GtkWidget *self,GdkEventButton *event, main_window *widgets);

GtkWidget *yon_menu_separator_create();

void on_config_autostart_clicked(GtkCellRenderer *self, char *path, main_window *widgets);

void on_activate(GtkTreeView *self, main_window *widgets);

void on_config_autostop_clicked(GtkCellRenderer *self, char *path, main_window *widgets);

void on_config_block_clicked(GtkCellRenderer *self, char *path, main_window *widgets);

void on_system_autostart_clicked(GtkCellRenderer *self, char *path, main_window *widgets);

void on_system_kill_confirmed(GtkWidget *self,char *service_name);

void on_system_launch_clicked(GtkWidget *self, char *path, main_window *widgets);

void on_system_restart_clicked(GtkWidget *self, main_window *widgets);

void on_source_show();

void on_properties_show();

void on_system_autostart_confirmed(GtkWidget *self,char *service_command);

void on_service_restart_confirmed(GtkWidget *self,char *service_name);

void on_system_system_restart_clicked(GtkWidget *self, main_window *widgets);

gboolean yon_sessions_update(main_window *widgets);

void on_session_unlock(GtkWidget *self, main_window *widgets);

void on_session_activate();

void on_session_end();

void on_session_block();

void yon_system_systemd_restart(GtkWidget *self, main_window *widgets);
void yon_user_systemd_restart(GtkWidget *self, main_window *widgets);

void on_system_update_hz_clicked(GtkWidget *self, main_window *widgets);

void yon_system_systemd_reexec(GtkWidget *self, main_window *widgets);

void on_system_update_clicked(GtkWidget *self, main_window *widgets);

void on_system_info_clicked(GtkWidget *self, main_window *widgets);

void on_system_log_clicked(GtkWidget *self, main_window *widgets);

gboolean on_terminal_relaunch(log_window *window);
void on_save_clicked(GtkWidget *self, log_window *window);
void on_update_clicked(GtkWidget *self, log_window *window);
void on_system_edit_clicked(GtkWidget *self, main_window *widgets);

void on_filter_changed(GtkWidget *self, main_window *widgets);

void on_system_status_clicked(GtkWidget *self, main_window *widgets);

void on_user_update_hz_clicked(GtkWidget *self, main_window *widgets);

void on_user_update_clicked(GtkWidget *self, main_window *widgets);

void on_user_info_clicked(GtkWidget *self, main_window *widgets);

void on_user_log_clicked(GtkWidget *self, main_window *widgets);

void on_user_edit_clicked(GtkWidget *self, main_window *widgets);

void on_user_status_clicked(GtkWidget *self, main_window *widgets);

void on_config_log_save(GtkWidget *self, log_window *window);
void on_config_edit_clicked(GtkWidget *self, main_window *widgets);

gboolean yon_service_source_check(GtkTreeModel *model, GtkTreeIter *iter, void *data);

gboolean yon_service_type_check(GtkTreeModel *model, GtkTreeIter *iter,void *data);

void on_type_changed(GtkWidget *self, main_window *widgets);

void on_search();

void on_info_clicked();

void *yon_unthreaded_config_load(void *widgets);

void on_update();

void on_status_show();

void yon_load_proceed(YON_CONFIG_TYPE type);

 void config_init();

void on_tree_selection_changed(GtkWidget *self, main_window *widgets);

void yon_main_window_complete(main_window *widgets);

void on_log_show();

void *update_delay(main_window *widgets);

gboolean on_service_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_socket_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_autostart_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_stopped_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_blocked_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_source_user_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

gboolean on_source_system_filter(GtkTreeModel *model, GtkTreeIter *iter,void *data);

void on_root_get_root(char *argline);
void on_root_access(GtkWidget *self, main_window *widgets);

void on_save_done(main_window *widgets, config_str output, int size);


struct system_services_data{
    main_window *widgets;
    int SystemAutostart;
    int SystemLaunched;
    char *Name;
    char *Descr;
    enum YON_UNIT_TYPE Type;
    int Loaded;
    int Active;
    char *State;

};

struct system_user_data{
    main_window *widgets;
    int SystemAutostart;
    int SystemLaunched;
    char *Name;
    char *Descr;
    enum YON_UNIT_TYPE Type;
    int Loaded;
    int Active;
    char *State;

};

struct system_config_data{
    main_window *widgets;
    char *Name;
    char *Descr;
    char *Date;

};

struct system_timers_data{
    main_window *widgets;
    const char *unit;
    const char *next;
    const char *left;
    const char *last;
    const char *passed;
    const char *activates;

};

gboolean yon_interface_update_finish(main_window *widgets);
gboolean yon_timers_set(struct system_timers_data *data);
gboolean yon_system_config_set(struct system_config_data *data);
gboolean yon_user_set(struct system_user_data *data);
gboolean yon_system_set(struct system_services_data *data);
gboolean yon_interface_list_models_connect(main_window *widgets);
gboolean yon_interface_list_models_disconnect(main_window *widgets);
void on_sort_activate(GtkTreeViewColumn *self, main_window *widgets);
gboolean sort_bool(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,gpointer col);
gboolean sort_string(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,gpointer col);
void yon_service_update(main_window *widgets);
void on_configs_selection_changed(GtkWidget *,main_window *widgets);
#endif