diff --git a/.gitignore b/.gitignore index 50e2ca3..370ce61 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,22 @@ Module.symvers Mkfile.old dkms.conf +# Ubl projects output +.vscode/ +ubl-settings-TEMPLATE +*~ +build/ +*compile/ +*# +terminal-commands/ +source/ubl-cmake.h +vgcore* +.BUILD.md +.updatebuild.sh +.install.sh +ublsettings-ui-debug +.install-debug.sh + # ---> C++ # Prerequisites *.d @@ -114,3 +130,18 @@ _deps pkg/ src/ +# Ubl project output +.vscode/ +ubl-settings-TEMPLATE +*~ +build/ +*compile/ +*# +terminal-commands/ +source/ubl-cmake.h +vgcore* +.BUILD.md +.updatebuild.sh +.install.sh +ublsettings-ui-debug +.install-debug.sh \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b68851 --- /dev/null +++ b/Makefile @@ -0,0 +1,178 @@ +#!/usr/bin/make -f + +#SHELL := /bin/bash +MAKEFILE_FILEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MAKEFILE_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_FILEPATH)))) +MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH)) + +CMAKE_UI_COMMAND = cmake +CMAKE_UTILS_COMMAND = cmake +CMAKE_UI_SOURCE_DIR = $(MAKEFILE_PATH)source +CMAKE_UTILS_SOURCE_DIR = $(MAKEFILE_PATH)ubl-utils +CMAKE_UI_BUILD_DIR = $(MAKEFILE_PATH)ui-compile +CMAKE_UTILS_BUILD_DIR = $(MAKEFILE_PATH)utils-compile +DEPENDS = /bin/cmake +PREFIX ?= /usr/local +PKGNAME = $(MAKEFILE_DIR) +FILE_VER = source/${PKGNAME}.h +PKGIDENT=$(subst /,-,${PREFIX}) + +default_target: all + +.PHONY: all init depend debug prepare check build uninstall install clean help + +all: init build + +init: + @echo "Initialize ..."; \ + if [ -d ".git" ]; then \ + LATEST_TAG=$$(git describe --abbrev=0 --tags | sed 's/^v//'); \ + if [ -z "$${LATEST_TAG}" ]; \ + then \ + LATEST_TAG=$$"0.0"; \ + echo "$${LATEST_TAG} is empty"; \ + fi; \ + else \ + LATEST_TAG="Development"; \ + fi; \ + sed -r "s/^(string version_application).*/\1 = \"$${LATEST_TAG}\";/" -i ${FILE_VER}; \ + echo "-- Build path: ${CMAKE_UI_BUILD_DIR}" + +depend: + @echo "Check depends ..." + @for FILE_DEPEND in $(DEPENDS); do \ + if [ ! -f $${FILE_DEPEND} ]; then \ + echo "ERROR: Depend '$${FILE_DEPEND}' not found !"; \ + exit 1; \ + fi; \ + done; \ + $(CMAKE_UI_COMMAND) -DCMAKE_INSTALL_PREFIX=/usr -S$(CMAKE_UI_SOURCE_DIR) -B${CMAKE_UI_BUILD_DIR} --check-build-system CMakeFiles/Makefile.cmake 1 || exit 1; \ + $(CMAKE_UTILS_COMMAND) -DCMAKE_INSTALL_PREFIX=/usr -S$(CMAKE_UTILS_SOURCE_DIR) -B${CMAKE_UTILS_BUILD_DIR} --check-build-system CMakeFiles/Makefile.cmake 1 || exit 1; \ + echo "Check depends: OK" + +debug: + @echo "Debug ..." + if [ ! -d ${CMAKE_UI_BUILD_DIR} ]; then \ + $(CMAKE_UI_COMMAND) -S${CMAKE_UI_SOURCE_DIR} -B${CMAKE_UI_BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \ + fi; \ + echo "Debug: OK" + +prepare: + @echo "Prepare ..."; \ + if [ ! -d ${CMAKE_UI_BUILD_DIR} ]; then \ + $(CMAKE_UI_COMMAND) -DCMAKE_INSTALL_PREFIX=/usr -S${CMAKE_UI_SOURCE_DIR} -B${CMAKE_UI_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \ + $(CMAKE_UTILS_COMMAND) -DCMAKE_INSTALL_PREFIX=/usr -S${CMAKE_UTILS_SOURCE_DIR} -B${CMAKE_UTILS_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \ + fi; \ + echo "Prepare: OK" + +check: + @echo "Check ..."; \ + if [ -f ${CMAKE_UTILS_BUILD_DIR}/libubl-utils.so ]; then \ + echo "Check: OK"; \ + else \ + echo "Check: ${CMAKE_UI_BUILD_DIR}/libubl-utils.so not found !"; \ + exit 1; \ + fi + +build: depend prepare build-utils + @echo "Build ..."; \ + sed -r "s/^(string version_application).*/\1;/" -i ${FILE_VER}; \ + echo "Build: OK" + +build-ui: + @cd ./ubl-utils; \ + $(MAKE_COMMAND) --directory=${CMAKE_UI_BUILD_DIR}; \ + cd ../ + + +build-utils: + @cd ./source; \ + $(MAKE_COMMAND) --directory=${CMAKE_UTILS_BUILD_DIR}; \ + cd ../ + +uninstall: uninstall-ui uninstall-util + @echo "Uninstall ..." + @for FILE_PO in $(wildcard *.po); do \ + LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \ + FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \ + PATH_FILE_MO="${DESTDIR}/usr/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \ + $(RM) "$${PATH_FILE_MO}"; \ + done + @for SIZE in 16x16 32x32 48x48 scalable; do \ + $(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/$${SIZE}/apps/com.ublinux.${PKGNAME}.svg"; \ + $(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/$${SIZE}/apps/com.ublinux.${PKGNAME}.png"; \ + done + @for FILE_SVG in $(wildcard *.svg); do \ + for SIZE in 16x16 32x32 48x48 scalable; do \ + $(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/$${SIZE}/status/$${FILE_SVG%.*}".{svg,png,jpg}; \ + done; \ + done + @$(RM) "${DESTDIR}${PREFIX}/share/applications/${PKGNAME}.desktop" + @$(RM) "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/com.ublinux.${PKGNAME}.svg" + @$(RM) "${DESTDIR}/usr/share/polkit-1/actions/com.ublinux.${PKGNAME}${PKGIDENT}.policy" + @if [ -z ${DESTDIR} ]; then \ + [ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \ + update-desktop-database --quiet &>/dev/null || true; \ + [ -d "${DESTDIR}${PREFIX}/share/applications" ] && touch "${DESTDIR}${PREFIX}/share/applications" &>/dev/null || true; \ + fi + @echo "Uninstall: OK" + +uninstall-ui: + @echo "Uninstall ..."; \ + $(RM) -r /usr/local/lib/libublsettings-ui.a*; \ + $(RM) -r /usr/local/include/*ublsettings-ui.h* + +uninstall-util: + @echo "Uninstall ..."; \ + $(RM) -r /usr/local/lib/libubl-utils.so*; \ + $(RM) -r /usr/local/include/*ubl-utils.h* + +install: check install-util build-ui install-ui + @echo "Install ..." + @for FILE_PO in $(wildcard *.po); do \ + LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \ + install -dm755 "${DESTDIR}/usr/share/locale/$${LANG}/LC_MESSAGES"; \ + FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \ + PATH_FILE_MO="${DESTDIR}/usr/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \ + echo "$${FILE_PO}"; \ + msgfmt "$${FILE_PO}" -v -f -o "$${PATH_FILE_MO}"; \ + done + @for SIZE in 16 32 48; do \ + install -dm755 "${DESTDIR}${PREFIX}/share/icons/hicolor/$${SIZE}x$${SIZE}/apps"; \ + rsvg-convert -w $${SIZE} -h $${SIZE} -f svg --keep-image-data "com.ublinux.${PKGNAME}.svg" -o "${DESTDIR}${PREFIX}/share/icons/hicolor/$${SIZE}x$${SIZE}/apps/com.ublinux.${PKGNAME}.svg"; \ + done + @install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/" "com.ublinux.${PKGNAME}.svg" + @if [ -z ${DESTDIR} ]; then \ + [ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \ + update-desktop-database --quiet &>/dev/null || true; \ + [ -d "${DESTDIR}${PREFIX}/share/applications" ] && touch "${DESTDIR}${PREFIX}/share/applications" &>/dev/null || true; \ + fi + @echo "Install: OK" + + +install-ui: uninstall-ui + @$(MAKE_COMMAND) install --directory=${CMAKE_UI_BUILD_DIR} + +install-util: uninstall-util + @$(MAKE_COMMAND) install --directory=${CMAKE_UTILS_BUILD_DIR} + +clean: + @echo "Clean ..." + @$(RM) -rd ${CMAKE_UI_BUILD_DIR} + @$(RM) -rd ${CMAKE_UTILS_BUILD_DIR} + @if [ -d ${CMAKE_UI_BUILD_DIR} ]; then \ + echo "Clean: error, compile directory exist ${CMAKE_UI_BUILD_DIR}"; \ + else \ + echo "Clean: OK"; \ + fi + +help: + @echo "The following are some of the valid targets for this Makefile:"; \ + echo "... all (the default if no target is provided)"; \ + echo "... init"; \ + echo "... debug"; \ + echo "... prepare"; \ + echo "... compile"; \ + echo "... install"; \ + echo "... uninstall"; \ + echo "... clean" \ No newline at end of file diff --git a/README.md b/README.md index 578fcb3..a81545b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,66 @@ # libublsettings-ui +# ubl-settings-logging +# Выполнить +# Build +In order to build ubl-settings-logging you will need: + +- CMake +- C compiler +- GTK+ 3 & dependencies +- webkit2gtk (optional) +- vte-2.91 + +Once you have all the necessary dependencies, you can use: +```sh +$ make +``` + +# Installation +After a successful build, just use: +```sh +$ sudo make install clean +``` + +# Uninstallation +After a successful build, just use: +```sh +$ sudo make uninstall +``` +# Library usage +Libublsettings-ui provides 2 libraries: +```C + #include + #include +``` +## ublsettings-ui +Ublsettings-ui provides API to use ubl-settings- applications shared interface: main window, about dialog, confirmation window. +First of all, you need to connect config structure to standard interface: +```C + _template_config config; + yon_ubl_connect_config(config); +``` +Next step you should initialize all necceccary information for standard interface: +```C +yon_ubl_window_init("Title of util","Description of util",".po file name","path to css file (must be connected as resource)","filename of your util","Version of util","About dialog wiki link"); +``` +And finaly you get interface structure: +```C + template_main_window *widgets = yon_ubl_window_setup(); +``` + +## ubl-utils +Ubl-utils provides various utility functions used in ubl-settings- applications. They are divided into sections as: +**Dictionary functions** yon_dictionary; +**String functions** yon_char; +**String array functions** yon_char_parsed; +**UBL misc functions** yon_ubl +**Parsing functions** +**File manipulating functions** yon_file +**UBconfig manipulation functions** yon_config +**Terminal functions** yon_launch +**GTK functions** yon_gtk and yon_ubl_gtk +**GTK VTE functions** yon_terminal +**GTK Webkit functions** yon_ubl_browser +**GTK window configuration manipulation and saving functions** yon_window_config +**GTK status line renderer functions** yon_ubl_status \ No newline at end of file diff --git a/com.ublinux.ublsettings-ui.checked.svg b/com.ublinux.ublsettings-ui.checked.svg new file mode 100644 index 0000000..e3cab42 --- /dev/null +++ b/com.ublinux.ublsettings-ui.checked.svg @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + diff --git a/com.ublinux.ublsettings-ui.svg b/com.ublinux.ublsettings-ui.svg new file mode 100644 index 0000000..f636c26 --- /dev/null +++ b/com.ublinux.ublsettings-ui.svg @@ -0,0 +1,4957 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.ublinux.ublsettings-ui.warning.svg b/com.ublinux.ublsettings-ui.warning.svg new file mode 100644 index 0000000..9a90dba --- /dev/null +++ b/com.ublinux.ublsettings-ui.warning.svg @@ -0,0 +1,55 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/gresource.xml b/gresource.xml new file mode 100644 index 0000000..ce32b3b --- /dev/null +++ b/gresource.xml @@ -0,0 +1,17 @@ + + + + ublsettings-ui.glade + ublsettings-ui-about.glade + ublsettings-ui-documentation.glade + ublsettings-ui-save-confirmation.glade + + + ublsettings-ui.css + + + ublsettings-ui-banner.png + com.ublinux.ublsettings-ui.checked.svg + com.ublinux.ublsettings-ui.warning.svg + + \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..495d810 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,100 @@ +cmake_minimum_required(VERSION 3.9) +project(ublsettings-ui VERSION 3.1) +include(GNUInstallDirs) + +find_package(PkgConfig REQUIRED) + +pkg_check_modules(GTK REQUIRED gtk+-3.0) +include_directories(${GTK_INCLUDE_DIRS}) +link_directories(${GTK_LIBRARY_DIRS}) +add_definitions(${GTK_CFLAGS_OTHER}) + +pkg_check_modules(VTE291 REQUIRED vte-2.91) +include_directories(${VTE291_INCLUDE_DIRS}) +link_directories(${VTE291_LIBRARY_DIRS}) +add_definitions(${VTE291_CFLAGS_OTHER}) + +find_library(WEBKIT_LIBRARIES_FOUND webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + +option(WEBKIT_FOUND "No" OFF) +if(WEBKIT_LIBRARIES_FOUND) + option(WEBKIT_FOUND "Yes" ON) + PKG_CHECK_MODULES(WEBKIT REQUIRED webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + include_directories(${WEBKIT_INCLUDE_DIRS}) + link_directories(${WEBKIT_LIBRARY_DIRS}) + add_definitions(${WEBKIT_CFLAGS_OTHER}) +endif() + +set(GRESOURCE_C resources.c) +set(GRESOURCE_XML gresource.xml) + +find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED) +add_custom_target(GLADE ublsettings-ui.glade) + +set(DEPENDFILES + ../ublsettings-ui.glade + ../ublsettings-ui-about.glade + ../ublsettings-ui-documentation.glade + ../ublsettings-ui-save-confirmation.glade + ../gresource.xml + ../ublsettings-ui-banner.png + ../ublsettings-ui.css + ../com.ublinux.ublsettings-ui.checked.svg + ../com.ublinux.ublsettings-ui.warning.svg + ) + +file(COPY ${DEPENDFILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +add_custom_command( + OUTPUT ${GRESOURCE_C} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${GLIB_COMPILE_RESOURCES} + ARGS + --generate-source + --target=${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} + ${GRESOURCE_XML} + VERBATIM + MAIN_DEPENDENCY ${GRESOURCE_XML} + DEPENDS + ${GLADE} +) +add_custom_target( + dummy-resource + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} +) + +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a") +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -lm") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \ + -O2 -pipe -fno-plt -fexceptions \ + -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ + -fstack-clash-protection -fcf-protection") + +add_library(${PROJECT_NAME} SHARED + ublsettings-ui.c + ublsettings-ui.h + ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}) + + +set(LIBRARIES + ${GTK_LIBRARIES} + ${WEBKIT_LIBRARIES} + ${VTE291_LIBRARIES} + ubl-utils + pthread) + + message(${CMAKE_INSTALL_LIBDIR}) +target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR}) + +target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARIES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) +set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER ${PROJECT_NAME}.h) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +# Set pkg-config file to install. \ No newline at end of file diff --git a/source/ublsettings-ui.c b/source/ublsettings-ui.c new file mode 100644 index 0000000..ee7681f --- /dev/null +++ b/source/ublsettings-ui.c @@ -0,0 +1,175 @@ +#include "ublsettings-ui.h" + + + +//signal emmit handlers - no header initialization + +void on_subwindow_close(GtkWidget *self){ + gtk_widget_destroy(gtk_widget_get_toplevel(self)); +} + +void yon_open_browser(GtkWidget *self, char *link){ + yon_ubl_browser_window_open(link,template_app_information.app_title); +} + +void on_open_documentation_confirmation(GtkWidget *self, char *link){ + if (template_app_information.always_open_documentation==0){ + GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_documentation); + template_documentation_confirmation_window *window = malloc(sizeof(template_documentation_confirmation_window)); + window->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow"); + window->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton"); + window->CloseButton = yon_gtk_builder_get_widget(builder,"CancelHelpButton"); + window->HeaderLabel = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel"); + window->AlwaysOpenCheck = yon_gtk_builder_get_widget(builder,"AlwaysOpenDocumentationCheckbox"); + gtk_label_set_text(GTK_LABEL(window->HeaderLabel),template_app_information.app_title); + gtk_widget_show_all(window->Window); + g_signal_connect(G_OBJECT(window->CloseButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); + g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(yon_open_browser),yon_char_new(link)); + g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); + + + } else { + yon_open_browser(self,link); + } +} + +/**on_link(GtkWidget *self, char* uri, gpointer user_data) + * [EN] + * Signal for hadnling AboutDialog links. + * Connect to "activate-link" signal. + * [self] is AboutDialog window; + * [uri] is activated link; + * [user_data] is pointer for user data, hasn't used in standard handler; + * [RU] + * Функция для обработки сигнала нажатия на ссылку окна AboutDialog. + * Присоединять к сигналу "activate-link". + * [self] - окно AboutDialog; + * [uri] - ссылка, по которой совершается переход; + * [user_data] - указатель на любые другие данные, не используется в стандартном обработчике; +*/ +void on_link(GtkWidget *self, char* uri, gpointer user_data){ + gtk_widget_destroy(self); + on_open_documentation_confirmation(self,uri); +} + +void on_about(GtkWidget *self, char *version_application){ + GtkBuilder *builder=gtk_builder_new_from_resource(ui_glade_path_about); + GtkWidget *window=yon_gtk_builder_get_widget(builder,"AboutWindow"); + GtkWidget *title=yon_gtk_builder_get_widget(builder,"headerAboutTopic"); + GtkWidget *hideButtonBox=yon_gtk_builder_get_widget(builder,"buttonBoxHide"); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),version_application); + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window),template_app_information.app_title); + gtk_label_set_text(GTK_LABEL(title),template_app_information.app_title); + g_signal_connect(G_OBJECT(window),"activate-link",G_CALLBACK(on_link),NULL); + gtk_widget_set_visible(hideButtonBox,0); + gtk_widget_destroy(hideButtonBox); + gtk_widget_show(window); +} + +//functions + +void yon_load_proceed(char *command){ + yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + +} + +// standard functions + +int yon_ubl_connect_config(_template_config *config){ + int replaces; + if(!template_config) + replaces=0; + else + replaces=1; + template_config = config; + return replaces; +} + +template_main_window *setup_window(){ + /* Widgets getting | Получение виджетов */ + template_main_window *widgets = malloc(sizeof(template_main_window)); + GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path); + widgets->Window = yon_gtk_builder_get_widget(builder,"MainWindow"); + widgets->HeadLabel = yon_gtk_builder_get_widget(builder,"headerTopic"); + widgets->PlugBox = yon_gtk_builder_get_widget(builder,"plugBox"); + + widgets->HeadOverlay = yon_gtk_builder_get_widget(builder,"HeadOverlay"); + widgets->HeadImage = yon_gtk_builder_get_widget(builder,"HeadBackgroundImage"); + widgets->HeadBox = yon_gtk_builder_get_widget(builder,"HeaderBox"); + widgets->HeadTitleLabel = yon_gtk_builder_get_widget(builder,"HeaderTitleLabel"); + widgets->HeadInfoLabel = yon_gtk_builder_get_widget(builder,"HeaderInfoLabel"); + + widgets->StatusBox = yon_gtk_builder_get_widget(builder,"mainStatusBox"); + widgets->StatusIcon = yon_gtk_builder_get_widget(builder,"mainStatusIcon"); + widgets->StatusLabel = yon_gtk_builder_get_widget(builder,"mainStatusLabel"); + + widgets->SaveMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalLocalConfigurationMenuItem"); + widgets->SaveGlobalMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalConfigurationMenuItem"); + widgets->SaveLocalMenuItem = yon_gtk_builder_get_widget(builder,"SaveLocalConfigurationMenuItem"); + widgets->RightBox = yon_gtk_builder_get_widget(builder,"HeaderRightBox"); + + widgets->LoadGlobalMenuItem = yon_gtk_builder_get_widget(builder,"LoadGlobalConfigurationMenuItem"); + widgets->LoadLocalMenuItem = yon_gtk_builder_get_widget(builder,"LoadLocalConfigurationMenuItem"); + widgets->LeftBox = yon_gtk_builder_get_widget(builder,"HeaderLeftBox"); + + widgets->DocumentationMenuItem = yon_ubl_menu_item_documentation_new(DOCUMENTATION_LABEL); + widgets->AboutMenuItem = yon_ubl_menu_item_about_new(ABOUT_LABEL); + + gtk_window_set_title(GTK_WINDOW(widgets->Window),template_app_information.app_title); + gtk_label_set_text(GTK_LABEL(widgets->HeadLabel),template_app_information.app_title); + gtk_label_set_text(GTK_LABEL(widgets->HeadTitleLabel),template_app_information.app_title); + gtk_label_set_text(GTK_LABEL(widgets->HeadInfoLabel),template_app_information.app_description); + + GtkWidget *menu = yon_gtk_builder_get_widget(builder,"menu2"); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->DocumentationMenuItem); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->AboutMenuItem); + + /* Widget registration for config monitoring | Регистрация виджетов для мониторинга конфига */ + // yon_window_config_add_listener(widgets->HeadInfoLabel,"head-text","label",YON_TYPE_STRING); + + /* 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),template_app_information.wiki_link); + g_signal_connect(G_OBJECT(widgets->AboutMenuItem),"activate",G_CALLBACK(on_about),NULL); + + + gtk_widget_show(widgets->Window); + return widgets; +} + +int yon_ubl_window_init(char *app_title, char *app_description, char *locale, char *css, char *tech_name, char *version, char *wiki){ + template_app_information.app_title=app_title; + template_app_information.css_path=css; + template_app_information.app_tech_name=tech_name; + template_app_information.app_version=version; + template_app_information.wiki_link=wiki; + template_app_information.app_description=app_description; + + template_app_information.app_locale=locale; +} + +template_main_window *yon_ubl_window_setup(){ + textdomain (template_ui_LocaleName); + setlocale(LC_ALL,""); + + template_main_window *widgets = setup_window(); + yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,ui_banner_path); + + if (yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel)){ + if (getuid()!=0) + yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); + else + yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + } + if(template_config) + yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,template_config->socket_id,template_config->load_socket_id,template_config->save_socket_id); + yon_window_config_setup(GTK_WINDOW(widgets->Window)); + yon_window_config_load(ui_config_path); + GtkCssProvider *css=gtk_css_provider_new(); + gtk_css_provider_load_from_resource(css,ui_CssPath); + gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), + GTK_STYLE_PROVIDER(css), + -1); + + return widgets; +} diff --git a/source/ublsettings-ui.h b/source/ublsettings-ui.h new file mode 100644 index 0000000..debdfb3 --- /dev/null +++ b/source/ublsettings-ui.h @@ -0,0 +1,195 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include + +#define ui_WIKI_LINK "https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/ublsettings-ui" + +#define _(String) gettext(String) + +#define ui_glade_path "/com/ublinux/ui/ublsettings-ui.glade" +#define ui_glade_path_documentation "/com/ublinux/ui/ublsettings-ui-documentation.glade" +#define ui_glade_path_about "/com/ublinux/ui/ublsettings-ui-about.glade" +#define ui_banner_path "/com/ublinux/images/ublsettings-ui-banner.png" +#define ui_CssPath "/com/ublinux/css/ublsettings-ui.css" +#define ui_config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",template_app_information.app_tech_name,"/",template_app_information.app_tech_name,".conf",NULL) + +#ifndef UBL_UI + #define template_ui_LocalePath "/usr/share/locale" + #define template_ui_LocaleName "ublsettings-ui" + + #define SUCCESS_LABEL _("Operation succeeded") + #define ROOT_WARNING_LABEL _("Warning! Application was launched without root - root-dependent actions are locked") + + #define ABOUT_LABEL _("About") + #define DOCUMENTATION_LABEL _("Documentation") + + #define SAVE_LOCAL_LABEL _("Save to local configuration") + #define SAVE_GLOBAL_LABEL _("Save to global configuration") + #define SAVE_CONFIGURATION_LABEL _("Save configuration") + #define SAVE_LABEL _("Save") + + #define LOAD_LOCAL_LABEL _("Load local configuration") + #define LOAD_GLOBAL_LABEL _("Load global configuration") + #define LOAD_LABEL _("Load") + + #define CANCEL_LABEL _("Cancel") + #define ACCEPT_LABEL _("Accept") + + #define HELP_TITLE_LABEL _("Would you like to read documentation in the Web?") + #define HELP_INFO_LABEL _("You will be redirected to documentation website where documentation is\ntranslated and supported by community.") + #define HELP_ALWAYS_OPEN_LABEL _("Always redirect to online documentation") + #define OPEN_HELP_LABEL _("Open documentation") + #define PROJECT_HOME_LABEL _("Project Home Page") + #define NOTHING_CHOSEN_LABEL _("Nothing were chosen") + + + #define GLOBAL_LOAD_SUCCESS_LABEL _("Global configuration loading succeeded.") + #define LOCAL_LOAD_SUCCESS_LABEL _("Local configuration loading succeeded.") + #define LOAD_FAILED_LABEL _("Config loading failed") + + #define GLOBAL_LOCAL_SAVE_SUCCESS_LABEL _("Local and global configuration saving succeeded.") + #define GLOBAL_SAVE_SUCCESS_LABEL _("Global configuration saving succeeded.") + #define LOCAL_SAVE_SUCCESS_LABEL _("Local configuration saving succeeded.") +#endif + +typedef struct { + GtkWidget *interface; + + char *app_locale; + char *css_path; + + char *app_title; + char *app_description; + + char *app_tech_name; + char *app_version; + char *wiki_link; + + gboolean always_open_documentation; +} template_app_info; +static template_app_info template_app_information; + +typedef struct { + int socket_id; + int load_socket_id; + int save_socket_id; + + int lock_help; + int lock_save_local; + int lock_save_global; + int lock_load_global; + + int always_open_documentation; +} _template_config; +static _template_config *template_config; + +typedef struct { + GtkWidget *Window; + GtkWidget *HeadLabel; + GtkWidget *PlugBox; + + GtkWidget *HeadOverlay; + GtkWidget *HeadImage; + GtkWidget *HeadBox; + GtkWidget *HeadTitleLabel; + GtkWidget *HeadInfoLabel; + + GtkWidget *StatusBox; + GtkWidget *StatusIcon; + GtkWidget *StatusLabel; + + GtkWidget *SaveMenuItem; + GtkWidget *SaveGlobalMenuItem; + GtkWidget *SaveLocalMenuItem; + GtkWidget *RightBox; + + GtkWidget *LoadGlobalMenuItem; + GtkWidget *LoadLocalMenuItem; + GtkWidget *LeftBox; + + GtkWidget *DocumentationMenuItem; + GtkWidget *AboutMenuItem; +} template_main_window; + + +typedef struct { + GtkWidget *Window; + GtkWidget *HeaderLabel; + + GtkWidget *AlwaysOpenCheck; + + GtkWidget *CloseButton; + GtkWidget *AcceptButton; +} template_documentation_confirmation_window; + +/**yon_open_browser(GtkWidget *self, char *link) + * [EN] + * Opens browser with [link] link. + * [RU] + * Открывает браузер с [link] ссылкой. +*/ +void yon_open_browser(GtkWidget *self, char *link); + +/**yon_ubl_connect_config(_template_config *config) + * [EN] + * + * [RU] + * Присоединяет конфиг основной утилиты (struct config) к стандартному интерфейсу. +*/ +int yon_ubl_connect_config(_template_config *config); + +/**yon_ubl_window_init(int argc, char *argv[]) + * [EN] + * + * [RU] + * Создаёт и настраивает основное окно приложения. +*/ +template_main_window *yon_ubl_window_setup(); + +/**yon_ubl_window_setup(GtkWidget *interface, char *app_title, char *app_description, char *locale, char *css, char *tech_name, char *version, char *wiki) + * [EN] + * + * [RU] + * Установить важные значения для конфига; + * [app_title] - оботражаемое имя утилиты; + * [app_description] - отображаемое описание утилиты; + * [css] - путь к ресурсу css файла; + * [tech_name] - техническое имя утилиты (ubl-settings-) + * [version] - строка с версией приложения; + * [wiki] - ссылка на вики страницу; +*/ +int yon_ubl_window_init(char *app_title, char *app_description, char *locale, char *css, char *tech_name, char *version, char *wiki); + +/**on_about() + * [EN] + * Function for setting up and showing AboutDialog. + * Connect it to "activate" signal of Documentation MenuItem. + * [RU] + * Функиця для настройки и показа окна AboutDialog. + * Присоединять к сигналу "activate" кнопки справки типа MenuItem. +*/ +void on_about(GtkWidget *self, char *version_application); + +/**on_open_documentation_confirmation(GtkWidget *self, char *link) + * [EN] + * Opens confirmation window for [link] link. + * [RU] + * Открывает окно подтверждения перехода по ссылке [link]. +*/ +void on_open_documentation_confirmation(GtkWidget *self, char *link); + +/**on_subwindow_close(GtkWidget *self) + * [EN] + * Closes window in which [self] is contained. + * [RU] + * Закрывает окно, в котором расположен виджет [self]. +*/ +void on_subwindow_close(GtkWidget *self); \ No newline at end of file diff --git a/ubl-utils/CMakeLists.txt b/ubl-utils/CMakeLists.txt new file mode 100644 index 0000000..def0f63 --- /dev/null +++ b/ubl-utils/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.9) +project(ubl-utils VERSION 3.1) +include(GNUInstallDirs) + +find_package(PkgConfig REQUIRED) + +pkg_check_modules(GTK REQUIRED gtk+-3.0) +include_directories(${GTK_INCLUDE_DIRS}) +link_directories(${GTK_LIBRARY_DIRS}) +add_definitions(${GTK_CFLAGS_OTHER}) + +pkg_check_modules(VTE291 REQUIRED vte-2.91) +include_directories(${VTE291_INCLUDE_DIRS}) +link_directories(${VTE291_LIBRARY_DIRS}) +add_definitions(${VTE291_CFLAGS_OTHER}) + +find_library(WEBKIT_LIBRARIES_FOUND webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + +option(WEBKIT_FOUND "No" OFF) +if(WEBKIT_LIBRARIES_FOUND) + option(WEBKIT_FOUND "Yes" ON) + PKG_CHECK_MODULES(WEBKIT REQUIRED webkit2gtk-4.0 webkit2gtk-web-extension-4.0) + include_directories(${WEBKIT_INCLUDE_DIRS}) + link_directories(${WEBKIT_LIBRARY_DIRS}) + add_definitions(${WEBKIT_CFLAGS_OTHER}) +endif() + + +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a") +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -lm") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \ + -O2 -pipe -fno-plt -fexceptions \ + -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ + -fstack-clash-protection -fcf-protection") + +add_library(${PROJECT_NAME} SHARED + ubl-utils.c + ubl-utils.h) + + +set(LIBRARIES +${GTK_LIBRARIES} +${WEBKIT_LIBRARIES} +${VTE291_LIBRARIES} +pthread) + +message(${CMAKE_INSTALL_LIBDIR}) + +target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR}) + +target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARIES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) +set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) +set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER ${PROJECT_NAME}.h) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +# Set pkg-config file to install. \ No newline at end of file diff --git a/ubl-utils/ubl-utils.c b/ubl-utils/ubl-utils.c new file mode 100644 index 0000000..95c5662 --- /dev/null +++ b/ubl-utils/ubl-utils.c @@ -0,0 +1,1936 @@ +#include "ubl-utils.h" + +// dictionary functions + +dictionary *yon_dictionary_new() +{ + 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; +} + +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; +} + +dictionary *yon_dictionary_copy_deep(dictionary *dict){ + dictionary *dct = NULL; + dictionary *newone=NULL; + for_dictionaries(dct,dict){ + yon_dictionary_add_or_create_if_exists_with_data(newone,dct->key,dct->data); + newone->data_type=dct->data_type; + } + return newone->first; +} + +int yon_dictionary_set_data(dictionary *dict, void *data){ + dict->data=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){ + dict->key=key; + dict->data=data; + return 1; +} + +int yon_dictionary_empty(dictionary *dict){ + dict->data=NULL; + dict->data_type=DICTIONARY_OTHER_TYPE; + return 1; +} + +void yon_dictionary_switch_to_last(dictionary **dict) +{ + dictionary *dct=NULL, *dact=*dict; + for_dictionaries(dct,dact); +} + +dictionary *yon_dictionary_append(dictionary *targetdict) +{ + targetdict = yon_dictionary_get_last(targetdict); + targetdict->next = yon_dictionary_new(); + 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) +{ + if (dict->next){ + dictionary *dct = NULL; + for_dictionaries(dct,dict); + return dct; + } else return dict; +} + +dictionary *yon_dictionary_swap(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; i < nth; i++) + { + if (dct == NULL) + return; + else + dct = dct->next; + } + yon_dictionary_rip(dict); + dictionary *prev = dct->prev; + prev->next = dict; + dict->prev = prev; + dict->next = dct; + dct->prev = dict; +} + +dictionary *yon_dictionary_new_with_data(char *key, void *data) +{ + dictionary *dct = yon_dictionary_new(); + dct->key = yon_char_new(key); + dct->data = data; + dct->data_type = DICTIONARY_OTHER_TYPE; + return dct; +} + +void *yon_dictionary_free_all(dictionary *dictionary_to_free,void (*data_manipulation)(void*)){ + dictionary *dict=NULL; + for_dictionaries(dict,dictionary_to_free){ + if(data_manipulation) + data_manipulation(dict->data); + if(dict->prev) + free(dict->prev); + } + free(dict); + return NULL; +} + +dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *data) +{ + dictionary *dct = yon_dictionary_append(dict); + dct->key = yon_char_new(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_get(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&&!dict->prev) return NULL; + else 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) +{ + if (dict){ + dict = dict->first; + int i = 0; + for (i = 0; i < place; i++) + if (dict->next) + dict = dict->next; + else + break; + if (i == place) + return dict; + else + return NULL; + } else return NULL; +} + +// 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; +} + +char *yon_char_append(char *source, char *append) +{ + if (source && append) + { + int size = strlen(source) + strlen(append) + 1; + char *final = malloc(size); + memset(final, 0, size); + // if (strstr(source, "%%")) + // sprintf(final, source, append); + // else + sprintf(final, "%s%s", source, append); + return final; + } + else + return NULL; +} + +char *yon_char_new(char *chr) +{ + if (chr){ + char *newchar = malloc(strlen(chr) + 1); + memset(newchar, 0, strlen(chr) + 1); + memcpy(newchar, chr, strlen(chr)); + return newchar; + } else + return NULL; +} + +char *yon_char_unite(char *source, ...){ + va_list arglist; + char *new_char=NULL; + char *unite_char=NULL; + new_char=yon_char_new(source); + va_start(arglist,source); + unite_char = va_arg(arglist,char*); + while(unite_char){ + new_char = yon_char_append(new_char,unite_char); + unite_char = va_arg(arglist,char*); + } + va_end(arglist); + return new_char; +} + +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) +{ + if (source){ + 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; + } + return NULL; +} + +int yon_char_find_count(char *source, char *find){ + char *working_string=yon_char_new(source); + int i=0; + int size=0; + int pos=0; + config_str rtn = yon_char_parse(working_string,&size,"\n"); + for (int j=0;j= 10; i++) + { + convert_check = convert_check / 10; + } + char *ch = g_malloc0(i * sizeof(char) + 1); + sprintf(ch, "%d", int_to_convert); + return ch; +} + +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; +} + +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; +} + +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; +} + +char **yon_char_parse(char *parameters, int *size, char *divider){ + 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; +} + +char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete){ + char **new_char_parsed=NULL; + new_char_parsed=malloc(sizeof(char*)*((*size)-1)); + int flag = 0; + for (int i=0;i < (*size);i++){ + if (i==item_to_delete) { + flag = 1; + } + if (flag == 0) { + new_char_parsed[i]=yon_char_new(char_string[i]); + } + else if (flag == 1 && i!=item_to_delete) { + new_char_parsed[i-1]=yon_char_new(char_string[i]); + } + } + (*size)=(*size)-1; + return new_char_parsed; +} + +int yon_char_parsed_check_exist(char **parameters, int size, char *param){ + + for (int i=0;ipw_name,NULL); + else { + user_list = yon_char_parsed_append(user_list,user_size,user->pw_name); + } + } + endpwent(); + return user_list; +} + +// parsing functions + +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) +{ + int size = 0; + struct apps *applist; + { + DIR *directory = opendir(DesktopPath); + struct dirent *de; + while ((de = readdir(directory))) + { + FILE *file; + char *path = yon_char_append(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(); + GError *err = NULL; + 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", &err); + if (err) + { + printf("%s\n", err->message); + } + 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; i < size; i++) + { + for (int j = 1; j < size; j++) + { + if (strcmp(applist[j].Name, applist[j - 1].Name) < 0) + { + tmp = applist[j]; + applist[j] = applist[j - 1]; + applist[j - 1] = tmp; + }; + } + }; + } +}; + +apps *yon_apps_get_by_name(apps *applist, char *name, int size) +{ + for (int i = 0; i < size; i++) + { + if (strcmp(applist[i].Name, name) == 0) + return &applist[i]; + } + return NULL; +}; + +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);} + +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((dictionary*)__yon__config__strings,NULL); + } + va_list args; + va_start(args,parameter); + char *arg; + dictionary *sections = NULL; + { + 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)) + { + 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 1; + else return 0; +} + +int yon_config_remove_by_key(char *key){ + check_config{ + dictionary *dict = yon_dictionary_get((dictionary**)&__yon__config__strings,key); + if (dict){ + ((yon_config_parameter*)dict)->flag1=-1; + return 1; + }else return 0; + } + return 0; +} + +int yon_config_remove_element(char *key, char *deleted){ + check_config{ + 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; + char *new_data = malloc(size); + memset(new_data,0,size); + if (strlen(found)!=strlen(deleted)){ + memcpy(new_data,data,size-1); + new_data = yon_char_append(new_data,found+strlen(deleted)+1); + } else { + memcpy(new_data,data,size-2); + new_data = yon_char_append(new_data,found+strlen(deleted)); + } + dict->data=(void*)(new_data); + dict->flag1=1; + return 1; + } else return 0; +} + +void *yon_config_get_by_key(char *key){ + check_config{ + dictionary *dict = NULL; + for_dictionaries(dict, (dictionary*)__yon__config__strings){ + if (strcmp(dict->key,key)==0&&((yon_config_parameter*)dict)->flag1!=-1){ + return dict->data; + } + } + } + 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; + } +} + +int yon_config_set(char *key, void *data){ + check_config{ + 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; +} + +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; +} + +int yon_config_clean(){ + check_config{ + __yon__config__strings = (yon_config_parameter*)yon_dictionary_free_all((dictionary*)__yon__config__strings, NULL); + return 1; + } + else return 0; +} + +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); +} + +config_str yon_config_load(char *command, int *str_len){ + 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)) + { + if (strcmp(str, "") != 0) + { + output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); + output_strings[i] = NULL; + output_strings[i] = yon_char_new(str); + memset(str, 0, 4096); + i++; + } + } + if (i>0){ + *str_len = i; + return output_strings; + } else{ + *str_len=-1; + return NULL; + } +} + +int yon_config_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){ + ((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 (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){ + 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; +} + +config_str yon_config_get_all(int *size){ + check_config{ + *size = 1; + config_str conf = NULL; + dictionary *dict = NULL; + 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)++; + } + conf = yon_remalloc(conf,sizeof(char*)*(*size)); + conf[*size-1] = NULL; + (*size)=(*size)-1; + return conf; + } else return NULL; +} + +char *yon_config_get_parameter(config_str parameters, int size, char *param) +{ + if (param[0]==' ') + yon_char_divide_search(param," ",-1); + param=yon_char_divide_search(yon_char_new(param)," ",-1); + + char *str = NULL; + for (int j = 0; j < size; j++) + { + char *name = yon_char_divide_search(yon_char_new(parameters[j]), "=", 1); + if (name) + { + if (strcmp(name, param) == 0) + { + str = yon_char_divide_search(yon_char_new(parameters[j]), "\n", 1); + if (strcmp(str, "") != 0 && strcmp(str, "(null)") != 0) + return str; + else + return NULL; + } + } + } + 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; + } +} + +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; + } +} + +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 + +int yon_launch_app_with_arguments(char *name, char *args) +{ + char *path = yon_char_unite("/usr/bin/", name, " ", args,NULL); + pthread_t thread_id; + char *command = NULL; + command = path; + pthread_create(&thread_id, NULL, (void *)yon_launch, command); +}; + +void yon_launch(char *command) +{ + system(command); +} + +// Gtk functions + +static render_data render; + +static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data) +{ + if (!terminal) return; + if (pid == -1) printf("Error\n\n\n"); + else vte_terminal_feed_child(VTE_TERMINAL(terminal),(char*)user_data,strlen((char*)user_data)); +} + +void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument){ + char **commands=new_arr(char*,2); + gchar **envp = g_get_environ(); + commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL")); + commands[1]=NULL; + char **env=new_arr(char*,2); + env[0]=""; + env[1]=NULL; + GtkWidget *terminal = vte_terminal_new(); + 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); + gtk_container_add(GTK_CONTAINER(place_to_show),terminal); + 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), + VTE_PTY_DEFAULT, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + child_ready, + install_command); + vte_pty_spawn_async(pty, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + NULL, + NULL); + 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); + } + +void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){ + char **commands=new_arr(char*,2); + gchar **envp = g_get_environ(); + commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL")); + commands[1]=NULL; + char **env=new_arr(char*,2); + env[0]=""; + env[1]=NULL; + 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("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), + VTE_PTY_DEFAULT, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + child_ready, + install_command); + vte_pty_spawn_async(pty, + NULL, + commands, + NULL, + 0, + NULL, NULL, + NULL, + -1, + NULL, + NULL, + NULL); + 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); + } + + // 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; + + void yon_window_config_save(){ + g_key_file_set_integer(__yon_window_config_file,"window","WindowPosX",__yon_main_window_config.x); + g_key_file_set_integer(__yon_window_config_file,"window","WindowPosY",__yon_main_window_config.y); + 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(); + yon_window_config_save(); + } + gtk_main_quit(); + } + + void __yon_window_config_on_resize(){ + int max=0; + max=gtk_window_is_maximized(__yon_window_config_target_window); + if(max==0){ + gtk_window_get_size(__yon_window_config_target_window,&__yon_main_window_config.width,&__yon_main_window_config.height); + gtk_window_get_position(__yon_window_config_target_window,&__yon_main_window_config.x,&__yon_main_window_config.y); + } + } + + 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); + g_signal_connect(G_OBJECT(window),"check-resize"/*"configure-event"*/,G_CALLBACK(__yon_window_config_on_resize),NULL); + } + + void _yon_maximize(void *data){ + g_usleep(G_USEC_PER_SEC/10); + if(__yon_main_window_config.fullscreen ==1) gtk_window_maximize(__yon_window_config_target_window); + } + + int yon_window_config_load(char *path){ + __yon_window_config_file = g_key_file_new(); + __yon_window_config_path=yon_char_new(path); + if (!g_key_file_load_from_file(__yon_window_config_file,__yon_window_config_path,G_KEY_FILE_NONE,NULL)){ + struct stat st; + int size; + config_str conf = yon_char_parse(yon_char_new(__yon_window_config_path),&size,"/"); + char *path = yon_char_unite(conf[0],"/",conf[1],"/",conf[2],"/",conf[3],"/",conf[4],"/",NULL); + if (stat(path, &st) == -1) { + mkdir(path, 0777); + } + 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); + } + __yon_main_window_config.x = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosX",NULL); + __yon_main_window_config.y = g_key_file_get_integer(__yon_window_config_file,"window","WindowPosY",NULL); + __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); + gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); + pthread_t tid; + pthread_create(&tid,NULL,(void *)_yon_maximize,NULL); + return 1; + } + + void yon_window_config_apply(){ + dictionary *dict=NULL; + gtk_window_move(__yon_window_config_target_window,__yon_main_window_config.x,__yon_main_window_config.y); + 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; + } + + 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 + +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) +{ + gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); + gtk_image_set_from_file(GTK_IMAGE(Image), image_path); +} + +void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) +{ + gtk_overlay_add_overlay(GTK_OVERLAY(Overlay), Head); + gtk_image_set_from_resource(GTK_IMAGE(Image), image_path); +} + +int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label) +{ + if(icon&&box&&label){ + render.icon=icon; + render.box=box; + render.label=label; + return 1; + } else return 0; +} + +void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type) +{ + render_data data = render; + GtkIconTheme *ictheme = gtk_icon_theme_get_default(); + GError *err = NULL; + if (err) + { + printf("%s\n", err->message); + g_error_free(err); + } + if (type == BACKGROUND_IMAGE_SUCCESS_TYPE||! type) + { + gtk_style_context_remove_class(gtk_widget_get_style_context(data.box), "boxInfoMessError"); + gtk_style_context_add_class(gtk_widget_get_style_context(data.box), "boxInfoMessOK"); + gtk_image_set_from_pixbuf(GTK_IMAGE(data.icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.ubl-settings-video.checked", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, &err)); + } + else if (type == BACKGROUND_IMAGE_FAIL_TYPE) + { + gtk_style_context_remove_class(gtk_widget_get_style_context(data.box), "boxInfoMessOK"); + gtk_style_context_add_class(gtk_widget_get_style_context(data.box), "boxInfoMessError"); + gtk_image_set_from_pixbuf(GTK_IMAGE(data.icon), gtk_icon_theme_load_icon_for_scale(ictheme, "com.ublinux.ubl-settings-video.warning", 25, 1, GTK_ICON_LOOKUP_FORCE_SIZE, &err)); + } + if (text) + gtk_label_set_text(GTK_LABEL(data.label), text); +} + +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; + } +} + +void 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){ + if (main_window&&socket_main_id>-1){ + gtk_widget_hide(gtk_widget_get_toplevel(main_window)); + GtkWidget *plug_main=gtk_plug_new(socket_main_id); + GtkWidget *plug_left=NULL; + GtkWidget *plug_right=NULL; + GtkWidget *box=NULL; + g_signal_connect(G_OBJECT(plug_main), "destroy", G_CALLBACK(gtk_main_quit),NULL); + if (socket_left_id>-1&&left_window){ + plug_left=gtk_plug_new(socket_left_id); + g_object_ref(left_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); + gtk_container_add(GTK_CONTAINER(plug_left),left_window); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"primary-toolbar"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"button"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"opacited"); + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"color"); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_left),"noborder"); + gtk_widget_show(plug_left); + } + else if (left_window){ + if (box==NULL){ + box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); + gtk_box_reorder_child(GTK_BOX(main_window),box,0); + gtk_widget_show(box); + } + gtk_style_context_add_class(gtk_widget_get_style_context(left_window),"inherited"); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(left_window)),left_window); + gtk_box_pack_end(GTK_BOX(box),left_window,0,0,5); + } + if (socket_right_id>-1&&right_window){ + plug_right=gtk_plug_new(socket_right_id); + g_object_ref(right_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); + gtk_container_add(GTK_CONTAINER(plug_right),right_window); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"primary-toolbar"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"button"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"opacited"); + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"color"); + gtk_style_context_add_class(gtk_widget_get_style_context(plug_right),"noborder"); + gtk_widget_show(plug_right); + } + else if (right_window){ + if (box==NULL){ + box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); + gtk_box_pack_start(GTK_BOX(main_window),box,0,0,5); + gtk_box_reorder_child(GTK_BOX(main_window),box,0); + gtk_widget_show(box); + } + gtk_style_context_add_class(gtk_widget_get_style_context(right_window),"inherited"); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(right_window)),right_window); + gtk_box_pack_start(GTK_BOX(box),right_window,0,0,5); + } + g_object_ref(main_window); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(main_window)),main_window); + gtk_container_add(GTK_CONTAINER(plug_main),main_window); + gtk_widget_show(plug_main); + } +} + +void yon_ubl_browser_window_open(char *link, char *browser_window_name){ + GtkWidget *browser=gtk_window_new(GTK_WINDOW_TOPLEVEL); + GtkWidget *web_place=gtk_box_new(GTK_ORIENTATION_VERTICAL,0); + GtkWidget *header=gtk_header_bar_new(); + GtkWidget *header_label=gtk_label_new(browser_window_name); + GtkWidget *WebView=webkit_web_view_new(); + gtk_container_add(GTK_CONTAINER(browser),web_place); + gtk_window_set_titlebar(GTK_WINDOW(browser),header); + gtk_window_set_title(GTK_WINDOW(browser),browser_window_name); + gtk_widget_set_size_request(browser,800,600); + gtk_header_bar_set_custom_title(GTK_HEADER_BAR(header),header_label); + gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header),1); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(WebView),link); + gtk_box_pack_start(GTK_BOX(web_place),WebView,1,1,0); + gtk_widget_show_all(browser); +} \ No newline at end of file diff --git a/ubl-utils/ubl-utils.h b/ubl-utils/ubl-utils.h new file mode 100644 index 0000000..059aaf1 --- /dev/null +++ b/ubl-utils/ubl-utils.h @@ -0,0 +1,1090 @@ +#ifndef UBL_UTILS +#define UBL_UTILS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + #include +#define DesktopPath "/usr/share/applications/" + +/**for_dictionaries(element, stack) + * [EN] + * + * [RU] + * Работает как for, но нужен для перечисления элементов словаря типа dictioary [stack]. Каждый цикл текущий элемент попадает в [element] +*/ +#define for_dictionaries(element, stack) for (element = stack->first; element != NULL; element = element->next) + +#define new(type) malloc(sizeof(type)) +#define new_arr(type,size) malloc(sizeof(type)*size) + +#define get_home_dir_command yon_char_unite("getent passwd \"",yon_ubl_root_user_get(),"\" | cut -d: -f6",NULL) + +typedef enum +{ + DICTIONARY_GTK_WIDGETS_TYPE, + DICTIONARY_OTHER_TYPE=0, + DICTIONARY_CHAR_TYPE, + DICTIONARY_INT_TYPE, + DICTIONARY_BOOL_TYPE, + +} DICT_TYPE; + +/** + * Структура именованого списка. + * [key] - ключ элемента + * [data] - хранимое значение + * [next] - следующий элемент списка + * [prev] - предыдущий элемент списка + * [first] - первый элемент списка + * [data_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 char** config_str; + +/**config(key) + * Возвращает элемент конфигурации ubconfig с ключом [key] или NULL если такого нет +*/ +#define config(key) yon_config_get_by_key(key) + +#define yon_remalloc(pointer, size) (!pointer) ? malloc(size) : realloc(pointer, size) +// dictionary functions + +/**yon_dictionary_get_data(dictionary, type) + * [EN] + * Gets data from dictionary. + * [dictionary] is dictionary, from which data should be extracted; + * [type] is type of data, [dictionary] contains. + * [RU] + * Возвращает данные из словаря. + * [dictionary] - словарь из которого достаются данные. + * [type] - тип данных, хранящихся в словаре [dictionary]. +*/ +#define yon_dictionary_get_data(dictionary, type) ((type)dictionary->data) + +/**yon_dictionary_add_or_create_if_exists_with_data(dict,key,data) + * [EN] + * + * [RU] + * Добавляет элемент словаря в конец словаря [dict] c ключом [key] и данными [data]. + * Если словарь не существует, создаёт его +*/ +#define yon_dictionary_add_or_create_if_exists_with_data(dict,key,data) {if (!dict) dict=yon_dictionary_new_with_data(key,data); \ + else dict=yon_dictionary_append_with_data(dict,key,data);} + +/**yon_dictionary_new(): + * [EN] + * Creates and returns empty dictionary + * [RU] + * Создаёт и возвращает пустой словарь. + */ +dictionary *yon_dictionary_new(); + +/**yon_dictionary_copy(dictionary *dict) + * [EN] + * + * [RU] + * Создаёт и возвращает копию элемента словаря [dict] +*/ +dictionary *yon_dictinoary_copy(dictionary *dict); + +/**yon_dictionary_copy_deep(dictionary *dict) + * [EN] + * + * [RU] + * Создаёт полную копию словаря [dict] и возвращает первый элемент +*/ +dictionary *yon_dictionary_copy_deep(dictionary *dict); + +/**int yon_dictionary_set_data(dictionary *dict, void *data) + * [EN] + * + * [RU] + * Установить элементу словаря [dict] значение [data] +*/ +int yon_dictionary_set_data(dictionary *dict, void *data); + +/**int yon_dictionary_set_key(dictionary *dict, char *key) + * [EN] + * + * [RU] + * Изменяет ключ элемента словаря [dict] на [key] +*/ +int yon_dictionary_set_key(dictionary *dict, char *key); + +/** 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); + +/**int yon_dictionary_empty(dictionary *dict) + * [EN] + * + * [RU] + * Очищает элемент словаря [dict] от данных +*/ +int yon_dictionary_empty(dictionary *dict); + +/**yon_dictionary_switch_to_last(dictionary **dict) + * [EN] + * + * [RU] + * Переключает словарь [dict] на последний элемент. +*/ +void yon_dictionary_switch_to_last(dictionary **dict); + +/**yon_dictionary_create_conneced(dictionary *targetdict) + * [EN] + * + * [RU] + * Создаёт новый элемент словаря [targetdict] +*/ +dictionary *yon_dictionary_append(dictionary *targetdict); + +/**yon_dictionary_get_last(dictionary *dict) + * [EN] + * + * [RU] + * Возвращает последний элемент словаря [dict]. + * В отличае от yon_dictionary_switch_to_last() + * словарь [dict] остаётся на прежнем элементе. +*/ +dictionary *yon_dictionary_get_last(dictionary *dict); + +/**yon_dictionary_switch_places(dictionary *dict, int aim) + * [EN] + * + * [RU] + * Меняет элемент словаря [dict] местами с другим элементом. + * если [aim]<0 элемент меняется местами с левым элементом; + * если [aim]>0 элемент меняется местами с правым элементом; +*/ +dictionary *yon_dictionary_swap(dictionary *dict, int aim); + +/**yon_dictionary_make_first(dictionary *dict) + * [EN] + * + * [RU] + * Устанавливает указатель первого элемента словаря [dict] + * на текущий элемент. Не использовать. +*/ +void yon_dictionary_make_first(dictionary *dict); + +/**yon_dictionary_make_nth(dictionary *dict, int nth) + * [EN] + * + * [RU] + * Перемещает элемент словаря [dict] на позицию [nth]. +*/ +void yon_dictionary_make_nth(dictionary *dict, int nth); + +/**yon_dictionary_create_with_data(char *key, void *data) + * [EN] + * + * [RU] + * Создаёт новый словарь с ключом [key] и указателем на данные [data] +*/ +dictionary *yon_dictionary_new_with_data(char *key, void *data); + +/**yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data) + * [EN] + * + * [RU] + * Создаёт новый элемент словаря, присоединяемый в конец словаря [dict] + * с ключом [key] и указателем на данные [data] +*/ +dictionary *yon_dictionary_append_with_data(dictionary *dict, char *key, void *data); + +/**yon_dictionary_connect(dictionary *old, dictionary *toconnect) + * [EN] + * + * [RU] + * Присоединяет словарь [toconnect] в конец словаря [old]. +*/ +dictionary *yon_dictionary_connect(dictionary *old, dictionary *toconnect); + +/**yon_dictionary_get(dictionary **dict, char *key) + * [EN] + * + * [RU] + * Возвращает элемент словаря [dict] с ключом [key]. + * Если такого элемента не было обнаружено, возвращается NULL +*/ +dictionary *yon_dictionary_get(dictionary **dict, char *key); + +/**yon_dictionary_rip(dictionary *dict) + * [EN] + * + * [RU] + * Вырезает элемент из словаря и возвращает вырезанный элемент. +*/ +dictionary *yon_dictionary_rip(dictionary *dict); + +/**yon_dictionary_get_nth(dictionary *dict, int place) + * [EN] + * + * [RU] + * Возвращает [place]-й элемент словаря [dict] +*/ +dictionary *yon_dictionary_get_nth(dictionary *dict, int place); + +/** void *yon_dictionary_free_all(dictionary *dictionary,void *data_manipulation) + * [EN] + * Frees whole [dictionary] and activates [data_manipulation] function if not NULL with [dictionary]->data argument for each dictionary. + * [RU] + * Освобождает память для всех элементов словаря [dictionary] и активирует функцию [data_manipulation], если она была передана, с аргументом [dictionary]->data на каждый элемент словаря. +*/ +void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*)); + +// 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); + +/**[EN] + * + * creates new char string by combining two char strings. + */ +char *yon_char_append(char *source, char *append); + +/**[EN] + * + * creates new char string by copying another char. + */ +char *yon_char_new(char *chr); + +/**yon_char_unite(char *source, ...) + * [En] + * + * [RU] + * Объединяет строку [source] со всеми строками, написанными в [...]. Последний элемент должен быть NULL +*/ +char *yon_char_unite(char *source, ...); + +/**yon_cut(char *source, int size, int startpos) + * [EN] + * cuts source string by size length from startpos position. + */ +char *yon_cut(char *source, int size, int startpos); + +/**yon_char_divide(char *source, int dividepos) + * [EN] + * divides source string in dividepos position, + * returning left part of divided string and + * inserting right part to source string. + */ +char *yon_char_divide(char *source, int dividepos); + +/**yon_char_divide_search(char *source, char *dividepos, int delete_divider) + * [EN] + * char *yon_char_divide_search(char *source, char *dividepos, int delete_divider) + * searches string [dividepos] in [source] string and divides it, + * returning left part of divided string and + * inserting right part to [source] string. + * if [delete_divider] is 0, left part will contain [delete_divider] substring, else + * if [delete_divider] is 1 it will stay in right part, else + * if [delete_divider] is -1 it will be deleted from string. + * + * [RU] + * char *yon_char_divide_search(char *source, char *dividepos, int delete_divider) + * Ищет строку [dividepos] в строке [source] и делит её в этом месте, + * возвращая левую часть разделённой строки и устанавливает в [source] правую часть. + * Если [delete_divider] равен 0, [dividepos] останется в левой строке, иначе + * если [delete_divider] равен 1, [dividepos] останется в правой строке, иначе + * если [delete_divider] равен -1, [dividepos] удаляется из строки. + */ +char *yon_char_divide_search(char *source, char *dividepos, int delete_divider); + +/**yon_char_from_int(int int_to_convert) + * [EN] + * char *yon_char_from_int(int int_to_convert) + * converts int to char*. + * + * [RU] + * char *yon_char_from_int(int int_to_convert) + * Конвертирует int в char* + */ +char *yon_char_from_int(int int_to_convert); + +/**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); + +/**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); + +/**yon_char_replace(char *source, char *find, char*replace) + * [EN] + * + * [RU] + * Заменяет в строке [source] все вхождения строки [find] на [replace] +*/ +char *yon_char_replace(char *source, char *find, char*replace); + +/**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); + +/**yon_char_parsed_rip(char **char_string, int *size, int item_to_delete) + * [EN] + * + * [RU] + * Удаляет элемент [item_to_delete] из массива строк [char_string], размера [size] + * Возвращает получившийся массив, в [size] загружается размер нового массива. +*/ +char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete); + +/**yon_char_parsed_check_exist(char **parameters, int size, char *param) + * [EN] + * Checks if [parameters] string array of length [size] + * has [param] element; + * [RU] + * Проверяет есть ли в массиве строк [parameters], размера [size] + * элемент [param] +*/ +int yon_char_parsed_check_exist(char **parameters, int size, char *param); + +/**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); + +/**yon_char_find_count(char *source, char *find) + * [EN] + * + * [RU] + * Считает количество символов [find] в строке [source] +*/ +int yon_char_find_count(char *source, char *find); + +/**yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size) + * [EN] + * + * [RU] + * Проверяет, включает ли в себя [source] размера [source_size] + * массив строк [to_check] размера [check_size] +*/ +int yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size); + +/**yon_char_parsed_new (config_str old, int *old_size, ...) + * [EN] + * + * [RU] + * Создаёт новый массив строк. В [size] выгружается его размер + * [...] - неограниченное количество строк. +*/ +config_str yon_char_parsed_new (int *size, ...); + +void yon_char_parsed_free(config_str source, int size); + +/**yon_char_parsed_copy(config_str *source, config_str *to_copy) + * [EN] + * + * [RU] + * Копирует массив строк [to_copy] в [source] +*/ +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) + * [EN] + * Adds [string] at the end of [parsed] string array of [size] length. + * [RU] + * Добавляет строку [string] в конец массива строк [parsed] с длинной [size]. +*/ +config_str yon_char_parsed_append(config_str parsed, int *size, char *string); + +/**yon_ubl_check_root() + * [EN] + * + * [RU] + * Возвращает 1 если приложение было запущено от root +*/ +int yon_ubl_check_root(); + +/**yon_ubl_root_user_get() + * [EN] + * + * [RU] + * Возвращает имя пользователя. + * Если пользователь запустил приложение через root, выводится имя пользователя, запустившего приложение через root +*/ +char *yon_ubl_root_user_get(); + +/** yon_ubl_user_get_home_directory() + * [EN] + * + * [RU] + * Возвращает домашний каталог пользователя. + * Если пользователь открыл утилиту с правами суперпользователя, всё равно возвращает каталог пользователя, а не root +*/ +char *yon_ubl_user_get_home_directory(); + +/** yon_ubl_get_all_users(int *user_size) + * [EN] + * + * [RU] + * Возвращает массив всех пользователей в системе и записывает его размер в [user_size] +*/ +config_str yon_ubl_get_all_users(int *user_size); + +// parsing functions + +/** yon_size_convert_automatic(int bytes, int *size) + * [EN] + * + * [RU] + * Делит число [bytes] на 1024 пока оно не станет меньше 1024. + * Возвращает получившееся число и устанавливает [size] равным количеству делений. +*/ +float yon_size_convert_automatic(int bytes, int *size); + +apps *yon_apps_scan_and_parse_desktops(int *sizef); + +void yon_apps_sort(apps *applist, int size); + +apps *yon_apps_get_by_name(apps *applist, char *name, int size); + +/**yon_file_open(char *file_path, int *size) + * [EN] + * + * [RU] + * Открывает файл [file_path], возвращает содержимое в виде массива строк размера [size] +*/ +config_str yon_file_open(char *file_path, int *size); + +/**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); + +/**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); + +/** 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 functions + +#define ubconfig_save_command "ubconfig" +#define ubconfig_load_command "ubconfig --source" + +/** + * Типы конфигураций ubconfig-а +*/ +typedef enum { + YON_CONFIG_LOCAL=0, + YON_CONFIG_GLOBAL, + YON_CONFIG_BOTH +} YON_CONFIG_TYPE; + +/**yon_config_load(char *command, int *str_len) + * [EN] + * + * [RU] + * Выполняет команду [command] и возвращает результат выполнения команды, разделяя на строки. + * В [str_len] возвращается длина возвращаемого массива +*/ +config_str yon_config_load(char *command, int *str_len); + +/**int yon_config_save_registered(char *path) + * [EN] + * Saves config at [path] config. + * [path] can be: + * system + * global + * [RU] + * Сохраняет конфигурацию в [path] конфиг. + * [path] может быть + * system - локальный конфиг + * global - глобальный конфиг +*/ +int yon_config_save_registered(char *path); + +/**char *yon_config_get_parameter(config parameters, int size, char *param) + * [EN] + * Gets parameter [param] from parameter list [parameters] of size [size]; + * or NULL if nothing were found + * [RU] + * Возвращает параметр [param] из массива строк [parameters] размером [size] + * или NULL если такой не был найден +*/ +char *yon_config_get_parameter(config_str parameters, int size, char *param); + +/**yon_config_load_register(char *command) + * [EN] + * + * [RU] + * Выполняет команду [command]. + * Полученные данные парсятся и регистрируются в конфиг. +*/ +int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...); + +/**yon_config_remove_by_key(char *key) + * [EN] + * + * [RU] + * Удаляет параметр конфига по ключу [key] +*/ +int yon_config_remove_by_key(char *key); + +/**yon_config_remove_element(char *key, char *deleted) + * [EN] + * + * [RU] + * Удаляет элемент [deleted] из массива параметров с ключом [key] +*/ +int yon_config_remove_element(char *key, char *deleted); + +/**yon_config_get_key_by_key(char *data) + * [EN] + * + * [RU] + * Возвращает значение параметра конфига с ключом [key]. + * Если параметр с таким значением не найден, возвращается NULL +*/ +void *yon_config_get_by_key(char *key); + +/**yon_config_get_all_by_key(char *data) + * [EN] + * + * [RU] + * Возвращает значение всех параметров конфига с ключом включающем строку [key]. + * Если параметр с таким значением не найден, возвращается NULL +*/ +void *yon_config_get_all_by_key(char *key, int *size); + +/**yon_config_set(char *key, void *data) + * [EN] + * + * [RU] + * Производит поиск по конфигу и заменяет значение параметра с ключом [key] на новое значение [data]; +*/ +int yon_config_set(char *key, void *data); + +/**yon_config_append(char *key, void *data) + * [EN] + * + * [RU] + * Производит поиск по конфигу и дополняет значение параметра с ключом [key] значением [data]; +*/ +int yon_config_append(char *key, char *data); + +/**yon_config_clean() + * [EN] + * Erase all parameters from config; + * [RU] + * Удаляет все параметры из конфига; +*/ +int yon_config_clean(); + +/**yon_config_register(char *key, void *data) + * [EN] + * + * [RU] + * Регистрирует новый параметр конфига. + * [key] - ключ параметра; + * [data] - значение параметра; +*/ +void yon_config_register(char *key, char* config_section, void *data); + +/**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); + +/**yon_config_get_all(int *size) + * [EN] + * + * [RU] + * Возвращает массив со всеми параметрами конфига, оканчивающаяся NULL + * [size] - указатель, в который выгружается длина массива +*/ +config_str yon_config_get_all(); + +// terminal-using functions + +/**yon_launch_app_with_arguments(char *name, char *args) + * [EN] + * Execute [command] in separate thread; + * [RU] + * Выполнить команду [command] в отдельном потоке; +*/ +int yon_launch_app_with_arguments(char *name, char *args); + +/**yon_launch(char *command) + * [EN] + * Execute command [command] + * [RU] + * Выполнить команду [command] +*/ +void yon_launch(char *command); + +// Gtk functions + +/** + * void yon_terminal_integrated_launch(GtkWidget *place_to_show, void *endwork_function, void* endwork_function_argument) + * [EN] + * launches terminal with specific [command], + * terminal is shown in [place_to_show] container, + * after terminal done its work [endwork_function] is called with [endwork_function_argument] argument. + * [RU] + * Запускает терминал с командой [command], + * терминал добавляется в контейнер [place_to_show] виджета, + * после завершения работы терминала вызывается функция [endwork_function] с аргументом [endwork_function_argument]. +*/ +void yon_terminal_integrated_launch(GtkWidget *place_to_show, char* command, void *endwork_function, void* endwork_function_argument); + +/**yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument) + * [EN] + * launches terminal with specific [command], + * terminal is shown in [place_to_show] container, + * after terminal done its work [endwork_function] is called with [endwork_function_argument] argument. + * [RU] + * Запускает терминал с командой [command], + * терминал добавляется в контейнер [place_to_show] виджета, + * после завершения работы терминала вызывается функция [endwork_function] с аргументом [endwork_function_argument]. +*/ +void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument); + +/**YON_TYPE + * [EN] + * + * [RU] + * Типы, поддерживаемые функциями сохранения/загрузки конфигурации утилиты +*/ +enum YON_TYPE{ + YON_TYPE_STRING, + YON_TYPE_STRING_LIST, + YON_TYPE_INT, + YON_TYPE_BOOLEAN, + YON_TYPE_OTHER}; + +/**yon_gtk_builder_get_widget(builder, widget_name) + * [EN] + * Returns GtkWidget from GtkBuilder *[builder]. + * [builder] is GtkBuilder*; + * [widget_name] is id of widget; + * [RU] + * Возвращает виджет GtkWidget c id [widget_name] из [builder] +*/ +#define yon_gtk_builder_get_widget(builder, widget_name) GTK_WIDGET(gtk_builder_get_object(builder, widget_name)) + +/**yon_window_config_setup(GtkWindow *window) + * [EN] + * + * [RU] + * Устанавливает указатель на окно для отслеживания его положения и размера +*/ +void yon_window_config_setup(GtkWindow *window); + +/**yon_window_config_load(char *path) + * [EN] + * + * [RU] + * Загружает конфиг окна и инициализирует отслеживание его параметров +*/ +int yon_window_config_load(char *path); + +/**yon_window_config_get_section(char *section, gsize *size) + * [EN] + * + * [RU] + * Возвращает все параметры раздела [section] конфига утилиты и записывает в [size] количество считанных параметров. +*/ +config_str yon_window_config_get_section(char *section, gsize *size); + +/**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_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type) + * [EN] + * + * [RU] + * Добавить параметр в конфиг утилиты. + * Параметр [param_name] добавляется в раздел [section] конфига утилиты со значением [tracked value]. + * Тип указывается в [type] +*/ +void yon_window_config_add_custom_parameter(char *param_name, char *section, void *tracked_value, enum YON_TYPE val_type); + +/**yon_window_config_erase_custom_parameter(char *param_name, char *section) + * [EN] + * + * [RU] + * Удаляет параметр из конфига утилиты. + * Удаляет параметр [param_name] из раздела [section] конфига утилиты. +*/ +void yon_window_config_erase_custom_parameter(char *param_name, char *section); + +/**yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type) + * [EN] + * + * [RU] + * Возвращает параметр из конфига утилиты. + * Параметр [config_parameter] из раздела [section] возвращается в [return_value] + * Возвращаемый тип указывается в [type] +*/ +int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type); + +/**yon_window_config_custom_window_setup(GtkWindow *window, char *window_name) + * [EN] + * + * [RU] + * Зарегистрировать окно [window] в конфиге утилиты под именем [window_name] +*/ +void yon_window_config_custom_window_setup(GtkWindow *window, char *window_name); + +/**yon_window_config_custom_window_set(GtkWindow *window, char *window_name) + * [EN] + * + * [RU] + * Загрузить и применить параметры окна [window], сохранёнными в конфигурации утилиты под именем [window_name] +*/ +void yon_window_config_custom_window_get(GtkWindow *window, char *window_name); + +/**yon_window_config_custom_window_set(GtkWindow *window, char *window_name) + * [EN] + * + * [RU] + * Сохранить параметры окна [window] в конфигурацию утилиты под именем [window_name] +*/ +void yon_window_config_custom_window_set(GtkWindow *window, char *window_name); + +int yon_gtk_icon_view_hide_empty(dictionary *icon_view_segment); + +/**yon_ubl_menu_item_documentation_new(char *buttonname) + * [EN] + * + * [RU] + * Создаёт элемент меню GtkMenu с текстом [buttonname]. Кнопка настроена для отображения диалогового окна информации об утилите +*/ +GtkWidget *yon_ubl_menu_item_about_new(char *buttonname); + +/**yon_ubl_menu_item_documentation_new(char *buttonname) + * [EN] + * + * [RU] + * Создаёт элемент меню GtkMenu с текстом [buttonname]. Кнопка настроена для отображения диалогового окна подтверждения перехода на страницу wiki +*/ +GtkWidget *yon_ubl_menu_item_documentation_new(char *buttonname); + +// 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, char **parameters,int size); + +/**yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find) + * [EN] + * + * [RU] + * Проивзодит поиск по GtkComboBoxText [combo_box] + * возвращает 1 если элемент [text_to_find] найден, иначе возвращает 0 +*/ +int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find); + +/**yon_gtk_column_minimal_fixed_size_set(GtkTreeViewColumn *column) + * [EN] + * + * [RU] + * Установить минимальный размер колонки [column] равным размеру заголовка. +*/ +void yon_gtk_column_minimal_fixed_size_set(GtkTreeViewColumn *column); + +/**yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...) + * [EN] + * + * [RU] + * Добвляет [destination] все виджеты, прописанные после [padding]. Добавление происходит с начала контейнера. + * [expand] - расширяемость выделенного для виджетов места + * [fill] - заполнять ли виджетом всё ему выделенное место + * [padding] - отступ од других элементов +*/ +int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...); + +/**yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...) + * [EN] + * + * [RU] + * Добвляет в [destination] все виджеты, прописанные после [padding]. Добавление происходит с конца контейнера. + * [expand] - расширяемость выделенного для виджетов места + * [fill] - заполнять ли виджетом всё ему выделенное место + * [padding] - отступ од других элементов +*/ +int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...); + + + +/**yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target) + * [EN] + * + * [RU] + * Выставляет чуствительность виджета [target] в зависимости от состояния комбобокса [toggle]. + * Чувствительность виджета [target] повторяет статус чекбоска. +*/ +void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target); + +/**yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target) + * [EN] + * + * [RU] + * Выставляет чуствительность виджета [target] в зависимости от состояния чекбоска [toggle]. + * Если чекбокс вктивен, [target] становится нечувствительным и наоборот. +*/ +void yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target); + +/**yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target); + * [EN] + * + * [RU] + * Выставляет чуствительность виджета [target] в зависимости от состояния комбобокса [toggle]. + * Если выбран первый элемент списка, [target] становится чувствительным, любое другое значение сделает его нечувствительным. +*/ +void yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target); + +/**yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target); + * [EN] + * + * [RU] + * Выставляет чуствительность виджета [target] в зависимости от состояния комбобокса [toggle]. + * Если выбран первый элемент списка, [target] становится нечувствительным, любое другое значение сделает его чувствительным. +*/ +void yon_gtk_widget_set_sensitive_from_combo_box_inversed(GtkComboBox *toggle, GtkWidget *target); + +typedef enum +{ + BACKGROUND_IMAGE_SUCCESS_TYPE, + BACKGROUND_IMAGE_FAIL_TYPE +} BACKGROUND_IMAGE_TYPE; + +typedef struct { + BACKGROUND_IMAGE_TYPE type; + GtkWidget *icon; + GtkWidget *box; + GtkWidget *label; + char* text_to_render; +} render_data; + + +/**yon_ubl_status_box_setup(render,icon,box,label) + * [EN] + * Sets up [render] structure of type render_data. + * [icon] is GtkImage widget of status box for showing status icons; + * [box] is GtkBox widget of status box for showing status color; + * [label] is GtkLabel widget of status box for showing status text; + * [RU] + * Настраивает структуру [render] типа render_data. + * [icon] - виджет типа GtkIcon в котором будут отображаться статусные иконки; + * [box] - виджет типа GtkBox в котором будет отображаться цвет статуса; + * [label] - виджет типа GtkLabel в котором будет отображаться текст статусного сообщения; +*/ +int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label); + +/**yon_ubl_status_box_render(render,text,type) + * [EN] + * Renders message in status box; + * [render] is render_data structure of status box; + * [text] is text to be shown in status box; + * [type] if type of message. Can be BACKGROUND_IMAGE_FAIL_TYPE or BACKGROUND_IMAGE_SUCCESS_TYPE + * [RU] + * Отображает сообщение в статусном окне. + * [render] - структура типа render_data для нужного статусного окна; + * [text] - текст, отображаемый в статусном окне; + * [type] - тип сообщения. Может быть: + * BACKGROUND_IMAGE_FAIL_TYPE (красный фон,иконка - восклицательный знак) + * или + * BACKGROUND_IMAGE_SUCCESS_TYPE (Жёлтный фон, иконка - галка) +*/ +void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type); + +/**yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter) + * [EN] + * + * [RU] + * Подсвечивает красным цветом [widget] на 5 секунд +*/ +void yon_ubl_status_highlight_incorrect(GtkWidget *widget); + +/**yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter) + * [EN] + * + * [RU] + * Подсвечивает красным цветом [iter] элемент списка [list] на 5 секунд +*/ +void yon_ubl_status_list_store_highlight_incorrect(GtkListStore *list, GtkTreeIter *iter); + +static int status_thread_busy; + +/**yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type); + * [EN] + * + * [RU] + * Создаёт статусную строку в контейнере [container], отображая текст [display_text]. + * Строка удаляется через [timeout] секунд. + * [type] - тип сообщения. Может быть: + * BACKGROUND_IMAGE_FAIL_TYPE (красный фон,иконка - восклицательный знак) + * или + * BACKGROUND_IMAGE_SUCCESS_TYPE (Жёлтный фон, иконка - галка) +*/ +void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type); + +/**yon_ubl_header_setup(overlay, head, image, imag_path) + * [EN] + * Sets up header of app. + * [overlay] is overlay for app header; + * [head] is box of header, which connects to [overlay] + * [image] is header background image; + * [imag_path] is path of image, shown in [image] + * [RU] + * Настраивает заголовок приложения. + * [overlay] - оверлей заголовка приложения; + * [head] - шапка заголовка, присоединяемая к [overlay] + * [image] - виджет картинки для заднего фона; + * [imag_path] - путь до картинки, загружаемой в [image] +*/ +#define yon_ubl_header_setup(overlay, head, image, imag_path) _yon_ubl_header_setup(GTK_WIDGET(overlay), GTK_WIDGET(head), GTK_WIDGET(image), (char *)imag_path) + +/**yon_ubl_header_setup_resource(overlay, head, image, imag_path) + * [EN] + * Sets up header of app. + * [overlay] is overlay for app header; + * [head] is box of header, which connects to [overlay] + * [image] is header background image; + * [imag_path] is path of image, shown in [image] + * [RU] + * Настраивает заголовок приложения. + * [overlay] - оверлей заголовка приложения; + * [head] - шапка заголовка, присоединяемая к [overlay] + * [image] - виджет картинки для заднего фона; + * [imag_path] - путь до картинки в ресурсах утилиты, загружаемой в [image] +*/ +#define yon_ubl_header_setup_resource(overlay, head, image, imag_path) _yon_ubl_header_setup_resource(GTK_WIDGET(overlay), GTK_WIDGET(head), GTK_WIDGET(image), (char *)imag_path) + +void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path); + +void _yon_ubl_header_setup_resource(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path); + +/**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. + * [main_window] is container widget, which holds main application functionality. + * [left_window] is container widget, which holds widgets, have to be shown at left part of ubl-settings-manager header. + * [right_window] is container widget, which holds widgets, have to be shown at right part of ubl-settings-manager header. + * [socket_main_id] is id of socket for [main_window]. + * [socket_left_id] is id of socket for [left_window]. + * [socket_right_id] is id of socket for [right_window]. + * [RU] + * Настраивает плаги для работы с сокетами в утилите ubl-settings-manager. + * [main_window] - контейнер основного интерфейса приложения. + * [left_window] - контейнер для виджетов которые должны отображаться в левой части шапки ubl-settings-manager. + * [right_window] - контейнер для виджетов которые должны отображаться в правой части шапки ubl-settings-manager. + * [socket_main_id] - id сокета для [main_window]. + * [socket_left_id] - id сокета для [left_window]. + * [socket_right_id] - id сокета для [right_window]. +*/ +void 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); + +/**yon_ubl_browser_window_open(char *link, char *browser_window_name) + * [EN] + * Launches integrated browser window, named [browser_window_name] at header with [link]. + * [RU] + * Открывает встроенный браузер с именем [browser_window_name] и показываемой страницей по ссылке [link] +*/ +void yon_ubl_browser_window_open(char *link, char *browser_window_name); +#endif \ No newline at end of file diff --git a/ublsettings-ui-about.glade b/ublsettings-ui-about.glade new file mode 100644 index 0000000..cf83633 --- /dev/null +++ b/ublsettings-ui-about.glade @@ -0,0 +1,64 @@ + + + + + + False + False + True + center + com.ublinux.ublsettings-ui + dialog + True + ublsettings-ui + 1.1 + Copyright © 2022 - 2023, UBSoft LLC + TEMPLATE Manager + https://wiki.ublinux.ru/ru/Программное_обеспечение/Программы_и_утилиты/Все/ublsettings-ui + Project Home Page + Это приложение распространяется без каких-либо гарантий. +Подробнее в <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License, версии 2 или позднее</a>. + UBGroup + UBGroup + com.ublinux.ublsettings-ui + True + gpl-2-0 + + + False + + + False + + + False + False + 0 + + + + + + + True + False + True + + + True + False + 5 + 5 + 5 + 5 + 2 + TEMPLATE Manager + + + + + + + + + diff --git a/ublsettings-ui-banner.png b/ublsettings-ui-banner.png new file mode 100644 index 0000000..8eb67cb Binary files /dev/null and b/ublsettings-ui-banner.png differ diff --git a/ublsettings-ui-documentation.glade b/ublsettings-ui-documentation.glade new file mode 100644 index 0000000..8629012 --- /dev/null +++ b/ublsettings-ui-documentation.glade @@ -0,0 +1,208 @@ + + + + + + False + False + 450 + dialog-question-symbolic + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + vertical + 10 + + + True + False + + + True + False + start + 20 + 20 + dialog-question-symbolic + 6 + + + False + True + 0 + + + + + True + False + vertical + + + True + False + start + 10 + 5 + Would you like to read documentation in the Web? + True + 0 + + + + + + + False + True + 0 + + + + + True + False + start + start + 10 + 10 + You will be redirected to documentation website where documentation is +translated and supported by community. + True + 0 + + + + False + True + 1 + + + + + Always redirect to online documentation + True + True + False + end + True + + + + False + True + end + 2 + + + + + + True + True + 1 + + + + + + True + True + 0 + + + + + True + False + 30 + True + + + Cancel + True + True + True + image8 + + + + True + True + 0 + + + + + Open documentation + True + True + True + image9 + + + + True + True + 1 + + + + + False + True + 1 + + + + + + + True + False + True + + + True + False + TEMPLATE Manager + + + + + + + + + + True + False + process-stop-symbolic + + + True + False + emblem-ok-symbolic + + diff --git a/ublsettings-ui-save-confirmation.glade b/ublsettings-ui-save-confirmation.glade new file mode 100644 index 0000000..168da42 --- /dev/null +++ b/ublsettings-ui-save-confirmation.glade @@ -0,0 +1,145 @@ + + + + + + True + False + process-stop-symbolic + + + True + False + emblem-ok-symbolic + + + + + + + + + + + False + False + 450 + dialog-question-symbolic + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + vertical + 10 + + + True + True + liststore1 + + + + + + Parameter + + + + 0 + + + + + + + Save + + + + 1 + + + + + + + True + True + 0 + + + + + True + False + end + 5 + True + + + Cancel + True + True + True + image8 + + + + True + True + 0 + + + + + Accept + True + True + True + image9 + + + + True + True + 1 + + + + + False + True + 1 + + + + + + + True + False + True + + + True + False + ubl-settings-TEMPLATES + + + + + + + + + diff --git a/ublsettings-ui.css b/ublsettings-ui.css new file mode 100644 index 0000000..88e8c57 --- /dev/null +++ b/ublsettings-ui.css @@ -0,0 +1,114 @@ + +.thin { + margin:0px; + padding:0px; +} +.noborder { + border:none; +} +.nobackground { +background:transparent; +} +.nobackground:active { +background:transparent; +} +.textHead{ + text-shadow: 2px 2px @theme_bg_color; + color: @theme_text_color; +} + +.inherited>* { + border:none; + background:inherit; +} +.workingbg { + background:@theme_base_color; +} +.menuitembottom{ + margin-top:0px; + margin-bottom:3px; + border-color:inherit; + border-left-width:inherit; + border-right-width:inherit; + } + .menuitemmiddle{ + margin-top:0px; + margin-bottom:0px; + border-color:inherit; + border-left-width:inherit; + border-right-width:inherit; + } + + .menuitemtop{ + margin-bottom:0px; + border-color:inherit; + border-top-width:inherit; + border-left-width:inherit; + border-right-width:inherit; + } + .menuitemtop>*{ + margin:2px 2px 0 2px; + padding: 3px 10px 3px 5px; + /* padding: 5px 0px 3px 5px; */ + border:transparent; + } + .menuitemmiddle>*{ + margin:0 2px 0 2px; + padding: 3px 10px 3px 5px; + /* padding: 3px 0px 3px 5px; */ + border:transparent; + } + .menuitembottom>*{ + margin:0 2px 2px 2px; + padding: 3px 10px 3px 5px; + /* padding: 3px 0px 5px 5px; */ + } + .menuitemtop:hover { + background:@theme_bg_color; + border-color:inherit; + border-top-width:inherit; + border-left-width:inherit; + border-right-width:inherit; + } + .menuitemmiddle:hover { + background:@theme_bg_color; + border-color:inherit; + border-left-width:inherit; + border-right-width:inherit; + } + .menuitembottom:hover { + background:@theme_bg_color; + border-color:inherit; + border-bottom-width:0px; + border-left-width:inherit; + border-right-width:inherit; + + } + .menuitemtop:hover>* { + margin:2px 2px 0 2px; + padding: 3px 10px 3px 5px; + /* padding: 5px 0 3px 5px; */ + background:@theme_selected_bg_color; + border-radius:2px; + } + .menuitemmiddle:hover>* { + margin:0 2px 0px 2px; + padding: 3px 10px 3px 5px; + /* padding: 3px 0px 3px 5px; */ + background:@theme_selected_bg_color; + border-radius:2px; + } + .menuitembottom:hover>* { + margin:0 2px 2px 2px; + padding: 3px 10px 3px 5px; + /* padding: 3px 0px 5px 5px; */ + background:@theme_selected_bg_color; + border-radius:2px; + } + .boxInfoMessError{ + background-color: #ea9999; +} + +.boxInfoMessOK{ + background-color: #f3f0ac; +} \ No newline at end of file diff --git a/ublsettings-ui.glade b/ublsettings-ui.glade new file mode 100644 index 0000000..4c0777b --- /dev/null +++ b/ublsettings-ui.glade @@ -0,0 +1,502 @@ + + + + + + + + + + True + False + center + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + 64 + com.ublinux.ublsettings-ui + + + False + True + 0 + + + + + True + False + + + True + False + + + True + False + center + vertical + + + 255 + True + False + end + TEMPLATE Manager + 0 + + + + + + + + True + True + 0 + + + + + 255 + True + False + start + TEMPLATE management app + 0 + + + + + + + + True + True + 1 + + + + + False + True + 0 + + + + + True + True + 0 + + + + + True + True + 1 + + + + + True + False + False + + + True + False + Load global configuration + + + + + + True + False + Load local configuration + + + + + + True + False + False + False + + + True + False + False + + + True + False + Save configuration + + + + + + True + False + Save to global configuration + + + + + + True + False + Save to local configuration + + + + + + 800 + 600 + False + 800 + 600 + com.ublinux.ublsettings-ui + + + True + False + vertical + + + True + False + vertical + + + True + False + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + 25 + + + False + True + 0 + + + + + True + False + start + 5 + 5 + 5 + 5 + 6 + 6 + True + + + + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + vertical + + + 81 + True + False + + + True + False + start + + + -1 + + + + + False + True + 0 + + + + + False + True + 1 + + + + + True + False + 5 + 5 + 5 + 5 + 5 + 5 + True + True + vertical + + + + + + False + True + 2 + + + + + True + True + 0 + + + + + + + True + False + True + + + True + False + 5 + 5 + 5 + 5 + 2 + TEMPLATE Manager + + + + + + + + True + False + 5 + 5 + 5 + 5 + 6 + 6 + 32 + com.ublinux.ublsettings-ui + + + + + True + False + + + True + True + False + True + menu3 + + + True + False + + + True + False + Save + + + False + True + 0 + + + + + True + False + pan-down-symbolic + + + False + True + 1 + + + + + + + False + True + 0 + + + + + True + True + True + False + True + True + menu2 + none + + + + + + + False + True + 1 + + + + + end + 1 + + + + + True + False + + + True + True + False + True + menu1 + + + True + False + + + True + False + Load + + + False + True + 0 + + + + + True + False + pan-down-symbolic + + + False + True + 1 + + + + + + + False + True + 0 + + + + + 2 + + + + + + + diff --git a/ublsettings-ui.pot b/ublsettings-ui.pot new file mode 100644 index 0000000..f12d952 --- /dev/null +++ b/ublsettings-ui.pot @@ -0,0 +1,122 @@ +# Language translations for ublsettings-ui package. +# Copyright (C) 2022, UBTech LLC +# This file is distributed under the same license as the ublsettings-ui package. +# UBLinux Team , 2022 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: ublsettings-ui 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-05-22 16:12+0600\n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: source/ublsettings-ui.h:31 +msgid "Operation succeeded" +msgstr "" + +#: source/ublsettings-ui.h:32 +msgid "" +"Warning! Application was launched without root - root-dependent actions are " +"locked" +msgstr "" + +#: source/ublsettings-ui.h:34 +msgid "About" +msgstr "" + +#: source/ublsettings-ui.h:35 +msgid "Documentation" +msgstr "" + +#: source/ublsettings-ui.h:37 +msgid "Save to local configuration" +msgstr "" + +#: source/ublsettings-ui.h:38 +msgid "Save to global configuration" +msgstr "" + +#: source/ublsettings-ui.h:39 +msgid "Save configuration" +msgstr "" + +#: source/ublsettings-ui.h:40 +msgid "Save" +msgstr "" + +#: source/ublsettings-ui.h:42 +msgid "Load local configuration" +msgstr "" + +#: source/ublsettings-ui.h:43 +msgid "Load global configuration" +msgstr "" + +#: source/ublsettings-ui.h:44 +msgid "Load" +msgstr "" + +#: source/ublsettings-ui.h:46 +msgid "Cancel" +msgstr "" + +#: source/ublsettings-ui.h:47 +msgid "Accept" +msgstr "" + +#: source/ublsettings-ui.h:49 +msgid "Would you like to read documentation in the Web?" +msgstr "" + +#: source/ublsettings-ui.h:50 +msgid "" +"You will be redirected to documentation website where documentation is\n" +"translated and supported by community." +msgstr "" + +#: source/ublsettings-ui.h:51 +msgid "Always redirect to online documentation" +msgstr "" + +#: source/ublsettings-ui.h:52 +msgid "Open documentation" +msgstr "" + +#: source/ublsettings-ui.h:53 +msgid "Project Home Page" +msgstr "" + +#: source/ublsettings-ui.h:54 +msgid "Nothing were chosen" +msgstr "" + +#: source/ublsettings-ui.h:57 +msgid "Global configuration loading succeeded." +msgstr "" + +#: source/ublsettings-ui.h:58 +msgid "Local configuration loading succeeded." +msgstr "" + +#: source/ublsettings-ui.h:59 +msgid "Config loading failed" +msgstr "" + +#: source/ublsettings-ui.h:61 +msgid "Local and global configuration saving succeeded." +msgstr "" + +#: source/ublsettings-ui.h:62 +msgid "Global configuration saving succeeded." +msgstr "" + +#: source/ublsettings-ui.h:63 +msgid "Local configuration saving succeeded." +msgstr "" diff --git a/ublsettings-ui_ru.po b/ublsettings-ui_ru.po new file mode 100644 index 0000000..a2719cf --- /dev/null +++ b/ublsettings-ui_ru.po @@ -0,0 +1,126 @@ +# Russian translations for ublsettings-ui package. +# Copyright (C) 2022, UBTech LLC +# This file is distributed under the same license as the ublsettings-ui package. +# UBLinux Team , 2022 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: ublsettings-ui 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-05-22 16:12+0600\n" +"PO-Revision-Date: 2023-01-01 00:00+0600\n" +"Last-Translator: UBLinux Team \n" +"Language-Team: Russian - UBLinux Team \n" +"Language: Russian\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: source/ublsettings-ui.h:31 +msgid "Operation succeeded" +msgstr "Операция завершена" + +#: source/ublsettings-ui.h:32 +msgid "" +"Warning! Application was launched without root - root-dependent actions are " +"locked" +msgstr "" +"Внимание! Приложение было запущено без прав суперпользователя - действия, " +"требующие их наличия заблокированы" + +#: source/ublsettings-ui.h:34 +msgid "About" +msgstr "О программе" + +#: source/ublsettings-ui.h:35 +msgid "Documentation" +msgstr "Справка" + +#: source/ublsettings-ui.h:37 +msgid "Save to local configuration" +msgstr "Сохранить в локальную конфигурацию" + +#: source/ublsettings-ui.h:38 +msgid "Save to global configuration" +msgstr "Сохранить в глобальную конфигурацию" + +#: source/ublsettings-ui.h:39 +msgid "Save configuration" +msgstr "Сохранить конфигурацию" + +#: source/ublsettings-ui.h:40 +msgid "Save" +msgstr "Сохранить" + +#: source/ublsettings-ui.h:42 +msgid "Load local configuration" +msgstr "Загрузить локальную конфигуруцию" + +#: source/ublsettings-ui.h:43 +msgid "Load global configuration" +msgstr "Загрузить глобальную конфигурацию" + +#: source/ublsettings-ui.h:44 +msgid "Load" +msgstr "Загрузить" + +#: source/ublsettings-ui.h:46 +msgid "Cancel" +msgstr "Отмена" + +#: source/ublsettings-ui.h:47 +msgid "Accept" +msgstr "Принять" + +#: source/ublsettings-ui.h:49 +msgid "Would you like to read documentation in the Web?" +msgstr "Вы хотите прочитать справку в Сети?" + +#: source/ublsettings-ui.h:50 +msgid "" +"You will be redirected to documentation website where documentation is\n" +"translated and supported by community." +msgstr "" +"Вы будете перенаправлены на сайт с документацией, где страницы помощи\n" +"переводятся и поддерживаются сообществом." + +#: source/ublsettings-ui.h:51 +msgid "Always redirect to online documentation" +msgstr "Всегда перенаправлять" + +#: source/ublsettings-ui.h:52 +msgid "Open documentation" +msgstr "Прочитать справку" + +#: source/ublsettings-ui.h:53 +msgid "Project Home Page" +msgstr "Домашняя страница проекта" + +#: source/ublsettings-ui.h:54 +msgid "Nothing were chosen" +msgstr "Ничего не было выбрано" + +#: source/ublsettings-ui.h:57 +msgid "Global configuration loading succeeded." +msgstr "Успешно загружена глобальная конфигурация" + +#: source/ublsettings-ui.h:58 +msgid "Local configuration loading succeeded." +msgstr "Успешно загружена локальная конфигурация" + +#: source/ublsettings-ui.h:59 +msgid "Config loading failed" +msgstr "" + +#: source/ublsettings-ui.h:61 +msgid "Local and global configuration saving succeeded." +msgstr "Успешно записаны локальная и глобальная конфигурация" + +#: source/ublsettings-ui.h:62 +msgid "Global configuration saving succeeded." +msgstr "Успешно записана глобальная конфигурация" + +#: source/ublsettings-ui.h:63 +msgid "Local configuration saving succeeded." +msgstr "Успешно записана локальная конфигурация" \ No newline at end of file