Init commit

pull/1/head
parent 21f46a2794
commit 3406e758dc

147
.gitignore vendored

@ -0,0 +1,147 @@
# ---> C
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
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
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# ---> CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
# ---> ArchLinuxPackages
*.tar
*.tar.*
*.jar
*.exe
*.msi
*.zip
*.tgz
*.log
*.log.*
*.sig
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

@ -0,0 +1,117 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice

@ -1,2 +1,41 @@
# libublsettings-gtk3
# Выполнить
# Build
In order to build ubl-settings-logging you will need:
- CMake
- C compiler
- [ublsettings](https://gitea.ublinux.ru/Applications/libublsettings)
- 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-gtk3 provides librariy:
```C
#include <ublsettings-gtk3.h>
```
## ublsettings-gtk3
Ublsettings-gtk3 provides various utility functions used in ubl-settings- applications. They are divided into sections as:
**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

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.9)
project(ublsettings-gtk3 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
ublsettings-gtk3.c
ublsettings-gtk3.h)
set(LIBRARIES
${GTK_LIBRARIES}
${WEBKIT_LIBRARIES}
${VTE291_LIBRARIES}
ublsettings
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.

@ -0,0 +1,770 @@
#include "ublsettings-gtk3.h"
#ifdef __GTK_H__
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&&parameters){
for (int i=0;i<size;i++){
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo),parameters[i]);
}
return 1;
} else
return 0;
}
int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find){
if (combo_box&&text_to_find){
int active=gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
char *str="-1";
for (int i=0;strcmp(str,"")!=0;i++){
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box),i);
str=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box));
if (!str) return -1;
if (strstr(str,text_to_find)) return i;
}
} return -1;
}
void yon_gtk_column_minimal_fixed_size_set(GtkTreeViewColumn *column){
int width= gtk_tree_view_column_get_width(column);
gtk_tree_view_column_set_min_width(column,width);
}
int yon_dictionary_gtk_pack_start_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){
va_list args;
va_start(args,padding);
GtkWidget *widget = va_arg(args,GtkWidget*);
while (widget){
gtk_box_pack_start(GTK_BOX(destination), widget, expand, fill, padding);
}
va_end(args);
return 1;
}
int yon_dictionary_gtk_pack_end_multiple_widgets(GtkBox *destination, gboolean expand, gboolean fill, int padding, ...){
va_list args;
va_start(args,padding);
GtkWidget *widget = va_arg(args,GtkWidget*);
while (widget){
gtk_box_pack_end(GTK_BOX(destination), widget, expand, fill, padding);
}
va_end(args);
return 1;
}
void yon_gtk_widget_set_sensitive_from_toggle_button(GtkToggleButton *toggle, GtkWidget *target){
gtk_widget_set_sensitive(target,gtk_toggle_button_get_active(toggle));
}
void yon_gtk_widget_set_sensitive_from_toggle_button_inversed(GtkToggleButton *toggle, GtkWidget *target){
gtk_widget_set_sensitive(target,!gtk_toggle_button_get_active(toggle));
}
void yon_gtk_widget_set_sensitive_from_combo_box(GtkComboBox *toggle, GtkWidget *target){
gtk_widget_set_sensitive(target,gtk_combo_box_get_active(toggle)>0 ? 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);
}
#endif

@ -0,0 +1,391 @@
#ifndef UBL_UTILS_GTK3
#define UBL_UTILS_GTK3
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gtk/gtkx.h>
#include <vte/vte.h>
#include <webkit2/webkit2.h>
#include <ublsettings.h>
#ifdef __GTK_H__
/**
* 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
#endif
Loading…
Cancel
Save