docs/en/Community-Developer-Guides/openKylin_SDK_Guide_V2.0.md

228 KiB
Raw Blame History

Enter a picture description

openSDK V2.0 ------ Development Guide

Enter a picture description

Enter a picture description

openSDK SIG

Table of contents

1 Overview
2 Deployment methods
3 System Capability SDK
   3.1 System Information
     3.1.1 System time reporting
     3.1.2 Get hardware information
     3.1.3 Get package list information
     3.1.4 Obtain resource information
     3.1.5 Obtain basic operating system information
     3.1.6 Get network information
     3.1.7 Get system runtime information
     3.1.8 Get current geographic information
   3.2 Power Management
     3.2.1 Lock Screen Settings
   3.3 File Management
   3.4 AI capabilities
     3.4.1 OCR character recognition function
   3.5 Printer Management
4 Application Support SDK
   4.1 QT self-developed control module
     4.1.1 Form module
     4.1.2 Dialog Module
     4.1.3 Input box module
     4.1.4 Button module
     4.1.5 Bar module
     4.1.6 Slider Module
     4.1.7 Message Prompt Module
     4.1.8 Breadcrumbs KBreadCrumb
     4.1.9 KCommentPanel
     4.1.10 KListView
     4.1.11 KTags
     4.1.12 KTranslucentFloor
   4.2 Wayland-helper
     4.2.1 WindowManager
     4.2.2 WindowInfo
     4.2.3 UkuiStyleHelper
   4.3 Apply general function modules
     4.3.1 Log module
     4.3.2 System related modules
     4.3.3 d-bus module------will be obsolete soon
     4.3.4 System information module
5 Basic Development SDK
   5.1 log
   5.2 Timers
   5.3 C language string extension
   5.4 Linked list module
   5.5 Configuration file operation
   5.6 Unit conversion

1 Overview

The openKylin self-developed developer kit (hereinafter referred to as openSDK) is based on the openKylin community operating system, providing a safe, reliable, fast, and stable developer interface for ecological construction and software development. Compared with other developer kits or frameworks in the community, openSDK focuses more on solving the problems of compatibility, adaptation, transplantation, optimization and other aspects of the open Kylin desktop operating system. openSDK currently focuses on three major modules, including application support SDK, system capability SDK, and basic development SDK, while fully considering the compatibility of openSDK.

This document aims to provide developers with an efficient way to refer to the declaration and usage of openSDK interfaces when developing applications on the openKylin system. Reduce the learning cost for developers when using openSDK.

The overall modules of the SDK are introduced as follows:

module describe
Application support SDK Focusing on the application display layer, it provides developers with Kirin self-developed controls, provides graphical development functions for graphical applications, and can use a unified UI framework to manage application windows and interact with the system, reducing application development and application migration. study cost;
System Capability SDK Focus on providing developers with more system capabilities, developers can quickly obtain basic system, hardware information, current runtime information, etc., improve development efficiency, and help development focus more on actual business content;
Basic Development SDK Focus on the application development process, providing developers with log management, package string processing and other capabilities to improve development efficiency;

2 Deployment method

When downloading and using the openKylin community self-developed developer kit, you need to add the openSDK source address in advance. The installation steps are as follows:

(1) Software source:

deb http://archive.build.openKylin.top/openkylin/ yangtze main cross pty

deb http://archive.build.openKylin.top/openkylin/ yangtze-security main cross pty

deb http://archive.build.openKylin.top/openkylin/ yangtze-updates main cross pty

(2) Update source after configuration:

$ sudo apt update

3 System Capability SDK

Each software package in the system capabilities SDK expresses one or a type of system capabilities, such as operating system information, hardware management, system built-in security policies, network management, etc.;

Install command:

$ sudo apt-get install libkysdk-system libkysdk-system-dev

3.1 System information

The design of this layer mainly provides applications with functional interfaces related to the operating system, and re-realizes OS-related functions (such as file systems, hardware information, communication, etc.) from the perspective of functions in three ways: self-development, combination, and packaging; Development complexity and debugging difficulty brought about by system differences and platform differences.

3.1.1 System time reporting

The com.kylin.kysdk.TimeServer Dbus service will send out a time signal when the system time is at an integral minute or when the system time is modified.

$ sudo apt-get install libdbus-1-dev libdbus-glib-1-dev libkysdk-systime libkysdk-systime-dev

(1) dbus service name: com.kylin.kysdk.TimeServer

(2) Path name: /com/kylin/kysdk/Timer

(3) Interfaces: com.kylin.kysdk.TimeInterface

(4) Signal:

System time modification signal: TimeChangeSignal

Timed timing signal: TimeSignal

System time modification time reporting

submoduleProgramming languageStatementDescription
System time reportingCVoid TimeChangeSignal(const char* t)When the system time is modified, the com.kylin.kysdk.TimeServerDbus service will send out a time signal
parameter descriptionreturn value description
t: current time such as: "2021/09 /26 21:13:28"none

system time full minutes

SubmoduleProgramming languageStatementDescription
System time reportingCvoid TimeSignal(const char* t)When the system time is in full minutes, the com.kylin.kysdk.TimeServerDbus service will send out a time signal
parameter descriptionreturn value description
t: current time such as: "2021/ 09/26 21:07:00"none

3.1.2 Get hardware information


$ sudo apt-get install libkysdk-hardware libkysdk-hardware-dev

3.1.2.1 Get CPU information

Encapsulate C interface to obtain CPU information

(1) CMakeLists.txt build project


aux_source_directory(. SOURCESCODE)

include_directories(.)

add_library(kyhw SHARED \${SOURCESCODE})

add_executable(kycpu-test test/kycpu-test.c)

target_link_libraries(kyhw kylog kyconf pthread systemd udev)

target_link_libraries(kycpu-test kyhw)

(2) To obtain hardware CPU information, a header file needs to be added:

#include "kysdk/kysdk-system/libkycpu.h"

Get CPU architecture

submoduleProgramming languageStatementDescription
Get CPU informationCextern const char* kdk_cpu_get_arch()Get CPU Architecture
Parameter DescriptionReturn value description
Noneconst char* schema Information, such as "x86_64"; the return is const char*, not free

Get CPU Manufacturer

submodule Programming language statement describe
Get CPU information C extern const char* kdk_cpu_get_vendor() Get the CPU manufacturer
Parameter Description Return value description
none const char* manufacturer string, such as "GenuineIntel"; return const char*, do not free

Get CPU model

submodule Programming language statement describe
Get CPU information C extern const char* kdk_cpu_get_model() Get the CPU model
Parameter Description Return value description
none const char* CPU model name, such as "Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz"; return const char*, do not free

Get the rated CPU frequency

submodule Programming language statement describe
Get CPU information C extern const char* kdk_cpu_get_freq_MHz() Obtain CPU rated main frequency
Parameter Description Return value description
none const char* rated main frequency hertz number, such as "1794.742", the unit is MHz; return const char*, do not free

Get the number of CPU cores

submodule Programming language statement describe
Get CPU information C extern unsigned int kdk_cpu_get_corenums() Get the number of CPU cores
Parameter Description Return value description
none unsigned int number of all available CPU cores

Get CPU support for virtualization

submodule Programming language statement describe
Get CPU information C const char* kdk_cpu_get_virt() Get CPU support for virtualization
Parameter Description Return value description
none const char* If the CPU supports virtualization, return virtualization technology, such as "vmx"; if not, return NULL; return const char*, do not free

3.1.2.2 Get network card information

Encapsulate the C interface to obtain the hardware information of the network card.

(1) CMakeLists.txt build project

aux_source_directory(. SOURCESCODE)

include_directories(.)

add_library(kyhw SHARED \${SOURCESCODE})

add_executable(kync-test test/kync-test.c)

target_link_libraries(kyhw kylog kyconf pthread systemd udev)

target_link_libraries(kync-test kyhw)

2) To obtain network card information, you need to add a header file:

  #include "kysdk/kysdk-system/libkync.h"

Get all network cards in the system

submodule Programming language statement describe
Get network card information C extern char** kdk_nc_get_cardlist() 获取系统中所有的网卡
Parameter Description Return value description
char** 网卡名称列表由NULL字符串表示结尾由alloc生成需要被kdk_nc_freeall回收若获取出错返回NULL

检测指定网卡是否处于 UP 状态

submodule Programming language statement describe
Get network card information C extern int kdk_nc_is_up(const char *nc) 检测指定网卡是否处于UP状态
Parameter Description Return value description
nc网卡名称如eno1 int Up返回1Down返回0

获取系统中当前处于 link up 状态的网卡列表

submodule Programming language statement describe
Get network card information C extern char** kdk_nc_get_upcards() 获取系统中当前处于 link up 状态的网卡列表
Parameter Description Return value description
char** 网卡名称列表由NULL字符串表示结尾由alloc生成需要被kdk_nc_freeall回收若获取出错返回NULL

获取指定网卡的物理 MAC 地址

submodule Programming language statement describe
Get network card information C extern char* kdk_nc_get_phymac(const char *nc) 获取指定网卡的物理MAC地址
Parameter Description Return value description
nc网卡名称如eno1 char* 物理MAC地址由alloc生成应当被free若指定网卡不存在则返回NULL

获取指定网卡的第一个 IPv4 地址

submodule Programming language statement describe
Get network card information C extern char* kdk_nc_get_private_ipv4(const char *nc) 获取指定网卡的第一个IPv4地址
Parameter Description Return value description
nc网卡名称如eno1 char* IPv4地址获取出错或无IP返回NULL

获取指定网卡的所有 IPv4 地址

submodule Programming language statement describe
Get network card information C extern char** kdk_nc_get_ipv4(const char* nc) 获取指定网卡的所有IPv4地址
Parameter Description Return value description
nc网卡名称如eno1 char** IPv4地址列表以NULL表示结尾由alloc生成需要被kdk_nc_freeall回收若获取出错返回NULL

获取指定网卡的第一个 IPv6 地址

submodule Programming language statement describe
Get network card information C extern char* kdk_nc_get_private_ipv6(const char *nc) 获取指定网卡的第一个IPv6地址
Parameter Description Return value description
nc网卡名称如eno1 char* IPv6地址获取出错或无IP返回NULL

获取指定网卡的所有 IPv6 地址

submodule Programming language statement describe
Get network card information C extern char** kdk_nc_get_ipv6(const char *nc) 获取指定网卡的所有IPv6地址
Parameter Description Return value description
nc网卡名称如eno1 char** IPv6地址列表以NULL表示结尾由alloc生成需要被kdk_nc_freeall回收若获取出错返回NULL

获取指定网卡的有线/无线类型

submodule Programming language statement describe
Get network card information C extern int kdk_nc_is_wireless(const char *nc); 获取指定网卡的有线/无线类型
Parameter Description Return value description
nc网卡名称如eno1 0 : 有线
1 : 无线

获取指定网卡的厂商名称和设备型号

submoduleProgramming languagestatementdescribe
Get network card informationCextern int kdk_nc_get_vendor_and_product(const char *nc, char *vendor, char *product);获取指定网卡的厂商名称和设备型号
Parameter DescriptionReturn value description
nc网卡名称如eno1vendor接受厂商名称的缓冲区product接受设备型号的缓冲区0 : 成功1 : 失败

回收字符串列表

submodule Programming language statement describe
Get network card information C extern inline void kdk_nc_freeall(char **ptr) 回收字符串列表
Parameter Description Return value description
ptr字符串列表

3.1.2.3 get disk information

封装 C 接口获取到网卡硬件信息。

1CMakeLists.txt 构建项目

 aux_source_directory(. SOURCESCODE)
add_library(kydiskinfo SHARED ${SOURCESCODE})
set_target_properties(kydiskinfo PROPERTIES VERSION 1.2.0 SOVERSION 1)
add_executable(test-getdiskinfo test/getdiskinfo.c)
add_executable(test-getdisklist test/getdisklist.c)
find_library(UDEV_LIB udev)
target_link_libraries(kydiskinfo blkid kylog pthread systemd kyconf ${UDEV_LIB})
target_link_libraries(test-getdiskinfo kydiskinfo)
target_link_libraries(test-getdisklist kydiskinfo)

2Get network card information需要添加头文件

 #include "kysdk/kysdk-system/libkydiskinfo.h"

获取系统中所有磁盘的列表

submodule Programming language statement describe
get disk information C extern char** kdk_get_disklist() 获取系统中所有磁盘的列表
Parameter Description Return value description
char** 每个字符串表示一个磁盘的绝对路径, 结尾以NULL字符表示结束

释放由 kdk_get_disklist 返回的磁盘列表

submodule Programming language statement describe
get disk information C extern void kdk_free_disklist(char** disklist) 释放由kdk_get_disklist返回的磁盘列表
Parameter Description Return value description
disklist 由kdk_get_disk_list返回的字符串指针

获取系统中指定磁盘的磁盘信息

submodule Programming language statement describe
get disk information C extern kdk_diskinfo *kdk_get_diskinfo(const char *diskname) 获取指定磁盘的磁盘信息
Parameter Description Return value description
diskname指定磁盘名称应当是例如/dev/sda这种绝对路径或者是disklist中的某个元素 kdk_diskinfo* 该磁盘的详细信息,具体信息自取

释放由 kdk_get_diskinfo 返回的磁盘信息结构体

submodule Programming language statement describe
get disk information C extern void kdk_free_diskinfo(kdk_diskinfo *disk); 释放由kdk_get_diskinfo返回的磁盘信息结构体
Parameter Description Return value description
disk由kdk_get_diskinfo返回的结构体指针

3.1.2.4 获取 bios 信息

封装 C 接口获取到 bios 硬件信息。

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
include_directories(.)
add_library(kyhw SHARED ${SOURCESCODE})
add_executable(kybios-test test/kycpu-test.c)
target_link_libraries(kyhw kylog kyconf pthread systemd udev)
target_link_libraries(kybios-test kyhw)

2获取 bios 信息,需要添加头文件:

 #include "kysdk/kysdk-system/libkybiosinfo.h"

获取 bios 厂商信息

submodule Programming language statement describe
get disk information C extern const char *kdk_bios_get_vendor(); 获取bios厂商信息
Parameter Description Return value description
成功返回bios厂商失败返回null

获取 bios 版本信息

submodule Programming language statement describe
get disk information C extern const char *kdk_bios_get_version(); 获取bios版本信息
Parameter Description Return value description
成功返回bios版本失败返回null

释放内存

submodule Programming language statement describe
get disk information C extern void kdk_bios_free(char* info); 释放获取信息接口申请的内存
Parameter Description Return value description
获取信息接口返回的指针

3.1.2.5 获取主板信息

封装 C 接口获取到主板硬件信息。

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
include_directories(.)
add_library(kyhw SHARED ${SOURCESCODE})
add_executable(kyboard-test test/kycpu-test.c)
target_link_libraries(kyhw kylog kyconf pthread systemd udev)
target_link_libraries(kyboard-test kyhw)

2获取主板信息需要添加头文件

 #include "kysdk/kysdk-system/libkyboardinfo.h"

获取主板产品名称信息

submodule Programming language statement describe
get disk information C extern const char *kdk_board_get_name(); 获取主板产品名称
Parameter Description Return value description
成功返回主板产品名称失败返回null

获取主板生产日期

submodule Programming language statement describe
get disk information C extern const char *kdk_board_get_date(); 获取主板生产日期
Parameter Description Return value description
成功返回主板生产日期失败返回null

获取主板序列号

submodule Programming language statement describe
get disk information C extern const char *kdk_board_get_serial(); 获取主板序列号
Parameter Description Return value description
成功返回主板序列号失败返回null

获取主板厂商信息

submodule Programming language statement describe
get disk information C extern const char *kdk_board_get_vendor(); 获取主板厂商信息
Parameter Description Return value description
成功返回主板厂商信息失败返回null

释放内存

submodule Programming language statement describe
get disk information C extern void kdk_board_free(char* info); 释放获取信息接口申请的内存
Parameter Description Return value description
获取信息接口返回的指针

3.1.2.6 获取 usb 设备信息

封装 C 接口获取到 usb 设备硬件信息。

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
include_directories(.)
add_library(kyhw SHARED ${SOURCESCODE})
add_executable(kyusb-test test/kyusb-test.c)
target_link_libraries(kyhw kylog kyconf pthread systemd udev)
target_link_libraries(kyusb-test kyhw)

2获取 usb 设备信息,需要添加头文件:

 #include "kysdk/kysdk-system/libkyusbinfo.h"

获取所有 usb 设备信息

submodule Programming language statement describe
get disk information C extern pDriverInfoList kdk_usb_get_list(); 获取usb设备信息
Parameter Description Return value description
pDriverInfoList : usb设备信息的结构体指针具体信息自取

释放内存

submodule Programming language statement describe
get disk information C extern void kdk_usb_free(pDriverInfoList list); 释放获取信息时申请的内存
Parameter Description Return value description
list:kdk_usb_get_list()返回的指针

3.1.3 获取包列表信息

封装 C 接口获取系统中所有的包信息。

$ sudo apt-get install libkysdk-package libkysdk-package-dev

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
include_directories(.)
add_library(kypackage SHARED ${SOURCESCODE})
add_executable(kypackage-test test/kypackage-test.c)
target_link_libraries(kypackage-test kypackage)

2获取包列表信息需要添加头文件

 #include "kysdk/kysdk-system/libkypackages.h"

获取系统中所有包列表

submodule Programming language statement describe
获取包列表信息 C extern kdk_package_list* kdk_package_get_packagelist() 获取系统中所有包列表
Parameter Description Return value description
kdk_package_list* 包describe结构体列表返回的结构体需要由kdk_package_free_packagelist()回收

获取系统中指定包的版本号

submodule Programming language statement describe
获取包列表信息 C extern char* kdk_package_get_version(const char *name) 获取系统中指定包的版本号
Parameter Description Return value description
name软件包名 char* 版本号由alloc生成需要被free若给定的包不存在则返回NULL

检测指定包名的软件包是否正确安装

submoduleProgramming languagestatementdescribe
获取包列表信息Cextern int kdk_package_is_installed(const char *name, const char *version)检测指定包名的软件包是否正确安装
Parameter DescriptionReturn value description
name软件包名version版本号大部分情况下为NULL预留为snap做准备int 成功返回0失败返回错误码

3.1.4 Get resource information

封装 C 接口获取到内存、swap 分区、cpu 的使用率。

$ sudo apt-get install libkysdk-proc libkysdk-proc-dev 

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
include_directories(.)
add_library(kyrtinfo SHARED ${SOURCESCODE})
add_executable(kyrtinfo-test test/kyrtinfo-test.c)
target_link_libraries(kyrtinfo-test kyrtinfo)

2获取包列表信息需要添加头文件

 #include "kysdk/kysdk-system/libkyrtinfo.h"

获取系统中物理内存总大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_res_total_KiB() 获取系统中物理内存总大小
Parameter Description Return value description
unsigned long 物理内存大小KiB为单位

获取物理内存使用率

submodule Programming language statement describe
Get resource information C extern float kdk_rti_get_mem_res_usage_percent() 获取物理内存使用率
Parameter Description Return value description
float 物理内存使用率

获取物理内存使用大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_res_usage_KiB() 获取物理内存使用大小注意Buffer/Cache被计算为已使用内存
Parameter Description Return value description
unsigned long 物理内存使用大小KiB为单位

获取实际可用的物理内存大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_res_available_KiB() 获取实际可用的物理内存大小该数值约等于Free + Buffer + Cache
Parameter Description Return value description
unsigned long 可用物理内存大小KiB为单位

获取实际空闲的物理内存大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_res_free_KiB() 获取实际空闲的物理内存大小注意Buffer/Cache被计算为已使用内存
Parameter Description Return value description
unsigned long 空闲的物理内存大小KiB为单位

获取所有应用申请的虚拟内存总量

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_virt_alloc_KiB() 获取所有应用申请的虚拟内存总量
Parameter Description Return value description
unsigned long 虚拟内存总申请量KiB为单位

获取系统中 Swap 分区总大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_swap_total_KiB() 获取系统中Swap分区总大小
Parameter Description Return value description
unsigned long Swap分区大小KiB为单位

获取 Swap 分区使用率

submodule Programming language statement describe
Get resource information C extern float kdk_rti_get_mem_swap_usage_percent() 获取Swap分区使用率
Parameter Description Return value description
float Swap分区使用率

获取 Swap 分区使用量

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_swap_usage_KiB() 获取Swap分区使用量
Parameter Description Return value description
unsigned long Swap分区使用量KiB为单位

获取 Swap 分区空闲大小

submodule Programming language statement describe
Get resource information C extern unsigned long kdk_rti_get_mem_swap_free_KiB() 获取Swap分区空闲大小
Parameter Description Return value description
unsigned long Swap分区空闲大小KiB为单位

获取 CPU 瞬时使用率

submodule Programming language statement describe
Get resource information C extern float kdk_rti_get_cpu_current_usage() 获取CPU瞬时使用率
Parameter Description Return value description
float CPU瞬时使用率该值 < 1.00

获取操作系统开机时长

submodule Programming language statement describe
Get resource information C extern int kdk_rti_get_uptime(unsigned int *day, unsigned int *hour, unsigned int *min, unsigned int *sec) 获取操作系统开机时长
Parameter Description Return value description
day开机天数
hour小时数该数值一定 < 24
min分钟数该数值一定 < 60
sec秒数该数值一定 < 60
int 返回0表示成功返回非零表示失败

获取指定进程的 CPU 使用率

submodule Programming language statement describe
Get resource information C extern float kdk_get_process_cpu_usage_percent(int proc_num) 获取指定进程的CPU使用率
Parameter Description Return value description
proc_num进程号 float CPU使用率

获取指定进程的内存占用率

submodule Programming language statement describe
Get resource information C extern float kdk_get_process_mem_usage_percent(int proc_num) 获取指定进程的内存占用率
Parameter Description Return value description
proc_num进程号 float 内存占用率

获取指定进程的进程状态

submodule Programming language statement describe
Get resource information C extern char* kdk_get_process_status(int proc_num) 获取指定进程的进程状态
Parameter Description Return value description
proc_num进程号 char* 进程状态

获取指定进程的端口号占用

submodule Programming language statement describe
Get resource information C extern int kdk_get_process_port(int proc_num) 获取指定进程的端口号占用
Parameter Description Return value description
proc_num进程号 char* 使用的端口号

获取指定进程的启动时间

submodule Programming language statement describe
Get resource information C extern char* kdk_get_process_start_time(int proc_num) 获取指定进程的启动时间
Parameter Description Return value description
proc_num进程号 char* 启动时间

获取指定进程的运行时间

submodule Programming language statement describe
Get resource information C extern char* kdk_get_process_start_time(int proc_num) 获取指定进程的启动时间
Parameter Description Return value description
proc_num进程号 char* 启动时间

获取指定进程的 cpu 时间

submodule Programming language statement describe
Get resource information C extern char* kdk_get_process_cpu_time(int proc_num) 获取指定进程的cpu时间
Parameter Description Return value description
proc_num进程号 char* cpu时间

获取指定进程的 Command

submodule Programming language statement describe
Get resource information C extern char* kdk_get_process_command(int proc_num) 获取指定进程的Command
Parameter Description Return value description
proc_num进程号 char* Command

Get the owner of the specified process

submoduleProgramming languageStatementDescription
Get resource informationCextern char* kdk_get_process_user(int proc_num)Get the owner of the specified process
Parameters DescriptionReturn value description
proc_num: process numberchar* owner

Get the CPU usage of the specified process

submoduleProgramming languageStatementDescription
Get resource informationCextern float kdk_procname_get_process_cpu_usage_percent(char *proc_name)Get the CPU usage of the specified process
Parameter descriptionReturn value description< /td>
proc_name process namefloat CPU usage

Get information about the specified process

submoduleProgramming languageStatementDescription
Get resource informationCextern char** kdk_procname_get_process_infomation(char *proc_name)Get the information of the specified process
Parameter descriptionReturn value description< /td>
proc_name process namechar** process information list, ending with NULL, generated by alloc, needs to be reclaimed by kdk_proc_freeall; if there is an error in obtaining, return NULL;

Get all information about the process

submoduleProgramming languageStatementDescription
Get resource informationCchar** kdk_get_process_all_information()Get all process information
Parameter DescriptionReturn value description
Nonechar** process All information lists, end with NULL, are generated by alloc and need to be recycled by kdk_proc_freeall; if there is an error in obtaining, return NULL;

list of recycled strings

submoduleProgramming languageStatementDescription
Get resource informationCextern inline void kdk_proc_freeall(char **ptr)recycle string list
parameters DescriptionReturn value description
ptr: string listnone

3.1.5 Obtain the basic information of the operating system

Encapsulate C interface to obtain system name, version number, activation information, etc.

$ sudo apt-get install libkysdk-sysinfo libkysdk-sysinfo-dev 

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)

include_directories(.)

find_library(GLIBC_LIB glib-2.0)

find_library(DBUS_LIB dbus-1)

find_library(DBUS_GLIB_LIB dbus-glib-1)

add_library(kysysinfo SHARED ${SOURCESCODE})

add_executable(kysysinfo-test test/kysysinfo_test.c)

target_link_libraries(kysysinfo kylin-activation kylog systemd kyconf

${GLIBC_LIB} ${DBUS_LIB} ${DBUS_GLIB_LIB})

target_link_libraries(kysysinfo-test kysysinfo)

2To obtain operating system information, you need to add header files:

 #include "kysdk/kysdk-system/libkysysinfo.h"

Get operating system architecture information

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_architecture() Get system architecture information
Parameter Description Return value description
char* system architecture, for example: x86_64

Get OS name

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_systemName() Get OS name
Parameter Description Return value description
char* system name, for example: Kylin

Get the operating system version number

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_version(bool verbose) Get the system version number
Parameter Description Return value description
verbose: 0 for abbreviated version number, 1 for detailed version number char* System version number, for example: system brief version: xxxx desktop operating system; system detailed version: Desktop-V10-Professional-Release-Build1-210203

Get the kernel version number

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_kernelVersion() Get the kernel version number
Parameter Description Return value description
char*

Get the username of the currently logged in user

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_eUser() Get the username of the currently logged in userEffect User
Parameter Description Return value description
char* returns a string on success, and NULL on failure. The returned string needs to be freed

Get operating system item number name

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_projectName() Get operating system item number name
Parameter Description Return value description
char* returns a string on success, and NULL on failure. The returned string needs to be freed

Get OS project subnumber name

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_projectSubName() Get OS project subnumber name
Parameter Description Return value description
char* returns a string on success, and NULL on failure. The returned string needs to be freed

Obtain the operating system product identification code

submodule Programming language statement describe
Get basic system information C extern unsigned int kdk_system_get_productFeatures() Obtain the operating system product identification code
Parameter Description Return value description
unsigned int return flag code
0000: abnormal information
0001: only PC features
0010: only tablet features
0011: support tablet and PC features

Obtain the virtual machine type of the operating system host

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_hostVirtType() Obtain the virtual machine type of the operating system host
Parameter Description Return value description
char* returns NULL if the acquisition fails, and returns a string if the acquisition succeeds. The content of the string is as follows:
[none, qemu, kvm, zvm, vmware,hyper-v, orcale virtualbox, xen, bochs, uml,parallels,bhyve,qnx,arcn,openvz,lxc,lxc-libvirt,systemd-nspawn,docker,podman,rkt,wsl]

Obtain the cloud platform type of the operating system host

submodule Programming language statement describe
Get basic system information C extern char* kdk_system_get_hostCloudPlatform() Obtain the cloud platform type of the operating system host
Parameter Description Return value description
char* returns NULL if the acquisition fails, and returns a string if the acquisition succeeds. The content of the string is as follows:
[none, huawei]

Determine whether the current operating system is a dedicated machine system

submodule Programming language statement describe
Get basic system information C extern bool kdk_system_is_zyj(void) Determine whether the current mirroring system is a dedicated machine system
Parameter Description Return value description
bool
true means yes
false means no

Get system resolution information

submodule Programming language statement describe
Get basic system information C extern char** kdk_system_get_resolving_power() Get system resolution information
Parameter Description Return value description
char** Resolution information list, ending with NULL, generated by alloc, needs to be reclaimed by kdk_resolving_freeall; if there is an error in obtaining, return NULL

list of recycled strings

submodule Programming language statement describe
Get basic system information C extern inline void kdk_resolving_freeal(char **ptr) list of recycled strings
Parameter Description Return value description
ptr字符串列表 none

3.1.6 获取网络信息

获取网络连接状态

submodule Programming language statement describe
Get basic system information dbus interface bus: system bus
name : org.freedesktop.NetworkManager
path: org.freedesktop.NetworkManager
method: state()->int arg0; Get network connection status。
Parameter Description Return value description
none int network connection status

Get network port status

cpanS="1 ="1" width="91">
submoduleProgramming languageStatementDescription
Get basic system informationCextern int kdk_net_get_port_stat(int port);Get port status
Parameter description< /td>Return value description
port port number int port status FREE: 0TCP_ESTABLISHED:1 TCP_SYN_SENT:2 TCP_SYN_RECV:3 TCP_FIN_WAIT1:4 TCP_FIN_WAIT2:5 TCP_TIME_WAIT:6 TCP_CLOSE:7 TCP_CLOSE_WAIT:8 TCP_LAST_ACL:9 TCP_LISTEN:10 TCP_CLOSING:11

Get the status of multiple network ports

submoduleProgramming languageStatementDescription
Get system basic informationCint kdk_net_get_multiple_port_stat(int start, int end, int *result)Get [start, end] port status
parameter descriptionreturn value description
start start port number end end port number result int with enough space array. Accept port statusSuccess returns 0 Failure returns port status

get default gateway

submoduleProgramming languageStatementDescription
Get basic system informationCextern prouteMapList kdk_net_get_route();Get Default Gateway
Parameter DescriptionReturn value description
NoneprouteMapList network management information, The specific information is fetched by yourself, and NULL is returned if it fails

Get firewall status

submoduleProgramming languageStatementDescription
Get system basic informationCextern pChain kdk_net_get_iptable_rules()Get Firewall Information
Parameter Description Return value description
NonepChain firewall information, specific Information self-fetching, failure returns NULL

3.1.7 Obtain system runtime information

Encapsulate C++ class to obtain network speed, cpu temperature, hard disk temperature, etc.

$ sudo apt-get install libkyrealtimeinfo libkyrealtimeinfo-dev

(1) CMakeLists.txt build project

include_directories("smartctl/")
aux_source_directory(./smartctl CODE)
add_library(kyrealtime SHARED libkyrealtimeinfo.cpp libkyrealtimeinfo.h ${CODE})
set_target_properties(kyrealtime PROPERTIES VERSION 1.2.0 SOVERSION 1)

add_executable(realtimetest test/getrealtimeinfo.cpp)
target_link_libraries(realtimetest kyrealtime)

(2) To obtain the runtime information of the operating system, a header file needs to be added:

#include "kysdk/kysdk-system/libkyrealtimeinfo.h"

Get Instantaneous Internet Speed

submoduleProgramming languageStatementDescription
Get basic system informationC++RealTimeInfo::float kdk_real_get_net_speed();Get Instantaneous Internet Speed
Parameter Description Return value description
nonefloat Instantaneous network speed

Get cpu temperature

submoduleProgramming languageStatementDescription
Get basic system informationC++RealTimeInfo::float kdk_real_get_cpu_temperatu();Get instantaneous cpu temperature
Parameter description Return value description
nonefloatcpu Instantaneous temperature

Get HDD temperature

submoduleProgramming languageStatementDescription
Get basic system informationC++RealTimeInfo::float kdk_real_get_disk_temperatu(const char * name);Get the instantaneous hard disk temperature
Parameter descriptionReturn value description
name: the absolute path of the hard diskfloat specifies the instantaneous temperature of the hard disk

Get disk speed

submoduleProgramming languageStatementDescription
Get system basic informationC++RealTimeInfo::int kdk_real_get_disk_rate(const char *name);Get disk speed
Parameter descriptionReturn value description
name: the absolute path of the hard diskint specifies the disk speed

3.1.8 Get current geographic information

Encapsulates the C interface to obtain the geographic information of the current ip address.

$ sudo apt-get install libkylocation libkylocation-dev

(1) CMakeLists.txt build project

include_directories("/usr/include/python3.8")
add_library(kylocation SHARED libkylocation.c)
set_target_properties(kylocation PROPERTIES VERSION 1.2.0 SOVERSION 1)
target_link_libraries(kylocation -lpython3.8)
add_executable(locationtest test/getlocation.c)
target_link_libraries(locationtest kylocation)

(2) To obtain the geographical information of the IP address, a header file needs to be added:

#include "kysdk/kysdk-system/libkylocation.h"

Get local location

submodule Programming language statement describe
Get basic system information C extern char *kdk_loaction_get(); Get the location of this machine
Parameter Description Return value description
Describe the json string of the geographic location

3.2 Power Management

The design of this layer is mainly for the application power management interface.

3.2.1 Lock Screen Settings

Encapsulate the C++ interface to provide the ability to set the lock screen.

Set to prohibit lock screen

submodule Programming language statement describe
power management module C++ uint32_t kdk_set_inhibit_lockscreen(const char *appName , const char *reason) Set to prohibit lock screen
Parameter Description Return value description
appNameApplication name
reason: Reason for prohibiting lock screen
0: Failed
>0: Successful (greater than 0)

Unban lock screen

submodule Programming language statement describe
power management module C++ int kdk_un_inhibit_lockscreen(uint32_t flag) Unban lock screen
Parameter Description Return value description
flagThe return value of prohibiting the lock screen interface 0: success
-1: failure

3.3 File Management

The module design is mainly for developers to monitor file changes in the file system and provide interface definitions; reduce

Differences between system versions due to changes in some file systems;

Installation method:

 $ sudo apt install libkysdk-filesystem libkysdk-filesystem-dev
statement describe
QStringList addWatchTargetRecursive(QString url, FileWatcherType type = PERIODIC, int attr = OPEN` CLOSE
QStringList addWatchTargetListRecursive(QStringList urlList, FileWatcherType type = PERIODIC, int attr = OPEN` CLOSE
QStringList removeWatchTargetRecursive(QString url, int maxdepth = 5, int recurType = ALLFILE); Remove the specified file from the listen list
void clearWatchList(); clear watch list
void pauseWatcher(); Pause file monitoring
void restartWatcher(); resume file monitoring

3.4 AI Capabilities

The design of this layer mainly provides the AI recognition function interface for the application, and adds OCR to the OS. Text recognition function; shielding needs

The development complexity and debugging difficulty brought by the introduction of AI functions.

3.4.1 OCR text recognition function

Encapsulate C++ interface to provide OCR text recognition function.

get text box

submodule Programming language statement describe
OCR text recognition function C++ Std::vector<std::vector<std::vector>> kdk::kdkOCR::getRect(const std::string &imagePath) get text box
Parameter Description Return value description
String 图片文件路径 Vector<vector<vector<vector
The coordinate matrix of the text box points, and the number of text boxes

get text content

submodule Programming language statement describe
OCR text recognition function C++ Std::vector<std::vector>>getCls(const std::string &imagePath,int nums) get text content
Parameter Description Return value description
String Image file path
VectorText string in the image
Int nums Number of literal stacks to process simultaneously

3.5 Printer Management

This layer mainly provides a printer management interface for the application, which can realize the delivery of printing tasks, printing methods, and printing tasks.

cancellation of service.

Get a list of system printers

submodule Programming language statement describe
printer management C extern char** kdk_printer_get_list(); Get a list of printers
Parameter Description Return value description
char ** System Printer List

Get a list of available printers on the system

submodule Programming language statement describe
printer management C extern char** kdk_printer_get _availablelist(); Get a list of available printers
Parameter Description Return value description
char ** System Printer List

Set print parameters

submodule Programming language statement describe
printer management C extern void kdk_printer_set_options(int number_up,const char *media,const char *number_up_layout,const char *sides); Set print parameters
Parameter Description Return value description
number_upPrint several pages on one paper
media: paper type
number_up_layout: cups attribute, such as lrtb
sides: single-sided one-sided, double-sided (long side flip): two_sided_long_dege
double-sided (short flip side)
two_sided_short_dege

print documents

submodule Programming language statement describe
printer management C extern int kdk_printer_print_local_file(const char *printername, char *filepath); print documents
Parameter Description Return value description
printername: printer name
filepathPrint the absolute path of the file
int id of the print job

cancel print job

submodule Programming language statement describe
printer management C extern int kdk_printer_cancel_all_jobs(const char *printername); cancel print job
Parameter Description Return value description
printernameprinter name int
Success: 0
Failed:-1

Get printer status

submodule Programming language statement describe
printer management C extern int kdk_printer_get_status(const char *printername); Get printer status
Parameter Description Return value description
printernameprinter name printer status code

Parse the downloaded filename from the url

submodule Programming language statement describe
printer management C extern void kdk_printer_get_filename(const char *url, char *filename); Parse downloaded filename from url
Parameter Description Return value description
urldownload link
filenameparsed filename

Get current print job status

submodule Programming language statement describe
printer management C extern int kdk_printer_get_job_status(const char *printername, int jobid); Get current print job status
Parameter Description Return value description
printernameprinter name print task status code

Download network files to local

submodule Programming language statement describe
printer management C extern int kdk_printer_print_download_remote_file(const char *url, const char *filepath); Download network files to local
Parameter Description Return value description
urlnetwork file download status code
filepathThe file path to save, user-defined

4 Application support SDK

In the openSDK application support layer, all packages provide graphical development functions for graphical applications, such as graphical controls, theme styles, etc.; this layer is usually bound to a specific development framework, such as QT, GTK; When installing the application support layer SDK, two virtual packages need to be installed: libkysdk-application, libkysdk-applications-dev, and other packages generate multiple real packages according to functional classification, such as: QT control class: libkysdk-qtwidgets, wayland display protocol compatible interface libkysdk -waylandhelper, apply common module libkysdk-kabase etc.

Install command:

$ sudo apt install libkysdk-applications libkysdk-applications-dev

4.1 QT self-developed control module

The QT self-developed control module kysdk-qtwidgets is a submodule of kysdk-application, and the installation method is as follows:

sudo apt install libkysdk-qtwidgets libkysdk-qtwidgets-dev

According to different project types, you can refer to the following demos:

(1) .pro file build project

Added to the qt project .pro file:

CONFIG += link_pkgconfig
PKGCONFIG += kysdk-qtwidgets

(2) CMakeLists.txt build project

cmake_minimum_required(VERSION 3.5)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(KYSDKQTWIDGETS_PKG kysdk-qtwidgets)
target_include_directories(demo PRIVATE ${KYSDKQTWIDGETS_PKG_INCLUDE_DIRS})
target_link_directories(demo PRIVATE ${KYSDKQTWIDGETS_PKG_LIBRARY_DIRS})
target_link_libraries(demo Qt5::Widgets ${KYSDKQTWIDGETS_PKG_LIBRARIES})

In a specific project, you need to introduce the corresponding header file and namespace in the code, such as:

#include "kwidget.h"
using namespace kdk;

Some controls use translation files, you can load translation files in the main() function, currently supported

Chinese, Tibetan, and English, the translation files have been compiled into the dynamic library, and the loading method is as follows:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTranslator trans;
    QString locale = QLocale::system().name();
    if(locale == "zh_CN")
    {
        if(trans.load(":/translations/gui_zh_CN.qm"))
        {
            a.installTranslator(&trans);
        }
    }
    if(locale == "bo_CN")
    {
        if(trans.load(":/translations/gui_bo_CN.qm"))
        {
            a.installTranslator(&trans);
        }
    }
    Widget w;
    w.show();
    return a.exec();
}

4.1.1 Form Module

4.1.1.1 Basic form

Function description: KWidget, inherited from QWidget, supports responsive theme background switching, responsive icon main

Title switching, the title color responds to the window activation status, and the window button style conforms to the design style of ukui3.1.

Divided into four components iconBar, windowButtonBar, sideBar, baseBar.

iconBar, windowButtonBar default height is 40px, sideBar default width is 200px.

输入图片说明 输入图片说明

枚举类型 LayoutType { VerticalType, HorizontalType, MixedType }

VerticalTypeupper and lower structure

HorizontalTypeleft and right structure

MixedTypetransitional structure

statement describe
QWidget* sideBar(); Get the left column widget, and add custom content through setlayout.
QWidget* baseBar(); Get the widget in the main content area, and add custom content through setlayout.
void setIcon(const QIcon& icon); Add form icon via icon
void setIcon(const QString& iconName); Set the window icon, iconName needs to directly specify the icon name in the system directory, such as "kylin-music".
void setWidgetName(const QString& widgetName); Set the form name.
KWindowButtonBar* windowButtonBar(); Gets the window triplet control to control whether to display the maximize, minimize, and drop-down menu buttons.
KIconBar* iconBar(); Get window title, icon combination controls to control related styles.
void setLayoutType(LayoutType type); Sets the layout structure type.

4.1.1.2 KBubbleWidget

Function description: KBubbleWidget, inherited from QWidget, is a window with a bubble tail

body, you can specify the size, display direction and display position of the bubble tail, and you can also set the circle of the form

Corners, frosted glass and transparency. Enabled since version 2.0.0.0.

enumeration typeenum TailDirection{ TopDirection, LeftDirection, BottomDirection, RightDirection, None };
enum TailLocation{ LeftLocation, MiddleLocation, RightLocation };

TailDirection: The display direction of the tail of the bubble

TailLocation: Specify the display position of the tail of the bubble

statement describe
void setTailSize(const QSize& size); Sets the bubble tail size
QSize tailSize(); Get the bubble tail size
void setTailPosition(TailDirection dirType, TailLocation locType=MiddleLocation); Set the display position of the bubble tail
TailDirection tailDirection(); Get the display direction of the bubble tail (left, up, right, down)
TailLocation tailLocation(); Get the display position of the bubble tail (left, center, right)
void setBorderRadius(int bottomLeft,int topLeft,int topRight,int bottomRight); Set the form corner radius
void setBorderRadius(int radius); Set the form corner radius
void setEnableBlur(bool flag); Set whether to enable the frosted glass effect
bool enableBlur(); Get whether the frosted glass effect is enabled
void setOpacity(qreal opacity); set transparency
qreal opacity(); get transparency

4.1.2 Dialog Module

4.1.2.1 Basic Dialog

Function description: KDialog, inherited from QDialog, supports switching of responsive theme and background, corresponding icon main

Title switching, the window button style conforms to the design style of ukui3.1, and the title color responds to the activation state of the window.

statement describe
void setWindowIcon(const QIcon &icon); Settings dialog icon
void setWindowIcon(const QString& iconName); Set the window icon directly according to the icon name, for example:dialog->setWindowIcon("kylin-music");
void setWindowTitle(const QString &); Set the dialog title name
QPushButton* maximumButton(); Get the maximize button
QPushButton* minimumButton(); Get the minimize button
QPushButton* closeButton(); get the close button
KMenuButton* menuButton(); Get the drop-down menu button, which is hidden by default and not displayed。
QWidget* mainWidget(); Get the main content area and add content through setLayout(). For example:dialog->mainWidget()->setLayout(hLayout);

4.1.2.2 About Dialog

Function description: KAboutDialog, the main contents include: application icon, application name, version

ID, team mailbox and specific application description, note that the default application description is not displayed. can pass

Control whether it needs to be displayed through setBodyTextVisible(bool).

输入图片说明

输入图片说明

statement describe
void setAppIcon(const QIcon& icon); set application icon
void setAppName(const QString& appName); set application name
QString appName(); get application name
void setAppVersion(const QString& appVersion); Set the application version number
QString appVersion(); Get application version number
void setBodyText(const QString& bodyText); Set application-specific description content
QString bodyText(); Get application-specific description content
void setAppSupport(const QString& appSupport); Set service and support mailboxes, with default defaults
QString appSupport(); Get Service and Support Email
void setBodyTextVisiable(bool flag); Set whether to display the description content
void setAppPrivacyLabelVisible(bool flag); Set whether the privacy button is visible (enabled since version 1.2.0.10)
bool AppPrivacyLabelIsVisible(); Returns whether the privacy button is visible (enabled since version 1.2.0.10)

4.1.2.3 Input Dialog

Function description: input dialog KInputDialog, inherited from QDialog, refer to QInputDialog

Source code, adjusted the layout and style of sub-controls, the function is the same as QInputDialog.

(1)QString KInputDialog::getText(QWidget *parent, const QString &label,

QLineEdit::EchoMode mode, const QString &text, bool *ok,

Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)

Text input dialog, same as QInputDialog

输入图片说明

(2)QString KInputDialog::getMultiLineText(QWidget *parent,const QString&label,

const QString &text, bool *ok, Qt::WindowFlags flags,

Qt::InputMethodHints inputMethodHints)

Multi-line text input box, same as QInputDialog

输入图片说明

(3)

int KInputDialog::getInt(QWidget *parent,const QString &label, int value,
int min, int max, int step, bool *ok, Qt::WindowFlags flags)

Integer number input dialog, same as QInputDialog

输入图片说明

(3)

double KInputDialog::getDouble(QWidget *parent,const QString &label,
double value, double minValue, double maxValue, 
int decimals, bool *ok, Qt::WindowFlags flags)

Floating-point number input dialog, same as QInputDialog

输入图片说明

enumerated type

enum InputDialogOption { NoButtons, UseListViewForComboBoxItems, UsePlainTextEditForTextInput }
flags InputDialogOptions
enum InputMode { TextInput, IntInput, DoubleInput }
常量 describe
QInputDialog::NoButtons 不显示确定和取消按钮
QInputDialog::UseListViewForComboBoxItems 使用QListView而不是不可编辑的QComboxItems来显示使用SetComboxItems设置的项目。
QInputDialog::UsePlainTextEditForTextInput 使用QPlainTextEdit进行多行文本输入。在这个值中在5.2中被引入。
常量 describe
QInputDialog::TextInput 用于输入文本字符串。
QInputDialog::IntInput 用于输入整数。
QInputDialog::DoubleInput 用于以双精度输入的浮点数。
statement describe
void setInputMode(InputMode mode); 设置输入模式
InputMode inputMode() const; 获取输入模式
void setLabelText(const QString &text); 设置标签文本
QString labelText() const; 获取标签文本
void setOption(InputDialogOption option, bool on = true); 设置选项
bool testOption(InputDialogOption option) const; 测试选项
void setOptions(InputDialogOptions options); 设置选项
InputDialogOptions options() const; 获取输入框选项
void setTextValue(const QString &text); 设置文本值
QString textValue() const; 获取文本值
void setTextEchoMode(QLineEdit::EchoMode mode); 设置文本模式
QLineEdit::EchoMode textEchoMode() const; 获取文本模式
void setComboBoxEditable(bool editable); 设置组合框可编辑
bool isComboBoxEditable() const; 返回组合框是否可以编辑
void setComboBoxItems(const QStringList &items); 设置组合框项目
QStringList comboBoxItems() const; 返回组合框列表
void setIntValue(int value); 设置int类型的值
int intValue() const; 获取int类型的值
void setIntMinimum(int min); 设置int类型的最低值
int intMinimum() const; 获取int最低值
void setIntMaximum(int max); 设置int类型最大值
int intMaximum() const; 获取int最大值
void setIntRange(int min, int max); 设置int范围
void setIntStep(int step); 设置int步数
int intStep() const; 获取int步数
void setDoubleValue(double value); 设置double值
double doubleValue() const; 获取double值
void setDoubleMinimum(double min); 设置double最小值
double doubleMinimum() const; 获取double最小值
void setDoubleMaximum(double max); 设置double最大值
double doubleMaximum() const; 获取double最大值
void setDoubleRange(double min, double max); 设置double范围
void setDoubleDecimals(int decimals); 设置两个小数
int doubleDecimals() const; 返回小数位数
void setOkButtonText(const QString &text); 设置确认按钮文本
QString okButtonText() const; 获取确认按钮文本
void setCancelButtonText(const QString &text); 设置取消按钮文本
QString cancelButtonText() const; 获取取消按钮文本
void open(QObject *receiver, const char *member); 此函数将其信号之一连接到接收器和成员指定的插槽。特定信号取决于在成员中指定的参数。
void setVisible(bool visible) override; 设置是否可见
QSize minimumSizeHint() const override; 最小尺寸提示
QSize sizeHint() const override; 尺寸提示
static QString getText(QWidget *parent,const QString &label,QLineEdit::EchoMode echo = QLineEdit::Normal,const QString &text = String(), bool *ok = nullptr,Qt::WindowFlags flags = Qt::WindowFlags(),Qt::InputMethodHints inputMethodHints = Qt::ImhNone); 获取文本
static QString getMultiLineText(QWidget *parent,const QString &label,const QString &text = QString(), bool *ok = nullptr,Qt::WindowFlags flags = Qt::WindowFlags(),Qt::InputMethodHints inputMethodHints = Qt::ImhNone); 获取多行文本
static QString getItem(QWidget *parent,const QString &label,const QStringList &items, int current = 0, bool editable = true,bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(),Qt::InputMethodHints inputMethodHints = Qt::ImhNone); 获取项目
static int getInt(QWidget *parent,const QString &label, int value = 0,int minValue = -2147483647, int maxValue = 2147483647,int step = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) 获取int型文本
static double getDouble(QWidget *parent,const QString &label,double value = 0, double minValue = -2147483647,double maxValue = 2147483647, int decimals = 1, bool *ok = nullptr,Qt::WindowFlags flags = Qt::WindowFlags()); 获取double类型文本
void setDoubleStep(double step); 设置double步数
double doubleStep() const; 获取double步数
void setPlaceholderText(const QString &); 设置PlaceholderText的文本内容自1.2.0.12启用)
QString placeholderText() const; 获取PlaceholderText的文本内容自1.2.0.12启用)

4.1.2.4 Progress dialog

Function description: KProgressDialog, inherited from QDialog, refer to QProgressDialog source code, The style of the child control ProgressBar has been adjusted. You can set whether specific download information needs to be displayed, set the suffix of the progress value, etc.

KProgressDialog *progress2 = new KProgressDialog(tr("Download"),tr("Cancel"),0,100,this);
progress2->setSubContent("Downloading...");
progress2->setSuffix("MB");
progress2->setWindowTitle("Progress Dialog");
progress2->setWindowIcon("kylin-music");
progress2->setValue(50);
progress2->setShowDetail(false);

输入图片说明

输入图片说明

statement describe
void setLabel(QLabel *label); 将标签设置给label。进度对话框会调整大小以适应。标签成为进度对话框的所有权必要时将被删除所以不要在堆栈中传递对象的地址。
void setCancelButton(QPushButton *button); 将取消按钮设置给按钮cancelButton。进度对话框拥有这个按钮的所有权这个按钮在必要时将被删除所以不要传递堆栈中的对象的地址用new()来创建按钮。如果传递nullptr将不会显示取消按钮。
void setBar(QProgressBar *bar); 将进度条部件设置给bar。进度对话框会调整大小以适应。进度条对话框拥有进度条的所有权该进度条将在必要时被删除所以不要使用分配在堆栈中的进度条。
void setSuffix(const QString& suffix); 设置detail的后缀
void setShowDetail(bool flag); 设置是否显示详细信息
int minimum() const; 返回最小值
int maximum() const; 返回最大值
int value() const 返回当前值
QString labelText() const; 返回提示内容
void setAutoReset(bool reset); 设置进度对话框是否在value()等于maximum()时立即调用reset()默认为true。
bool autoReset() const; 返回是否自动重置
void setAutoClose(bool close); 设置是否自动关闭对话框
bool autoClose() const; 返回是否自动关闭对话框
QProgressBar* progressBar(); 获取进度条
void cancel() 取消进度条。
void reset() 重置进度条。
void setMaximum(int maximum) 设置进度条所代表的最高值默认值是100。
void setMinimum(int minimum) 设置进度条所代表的最小值默认值是0。
void setRange(int minimum, int maximum) 设置进度条范围如果最大值小于最小值则最小值成为唯一的合法值。如果当前值超出了新的范围则用reset()重置进度框。
void setValue(int progress) 设置当前进度值。
void setLabelText(const QString &text) 设置提示标签文本。
void setCancelButtonText(const QString &text) 设置取消按钮文本。
void setSubContent(const QString &text) 设置次级内容。

4.1.2.5 Program uninstall dialog

Function description: KUninstallDialog, the code is integrated from the Kylin installer, and supports displaying application diagrams

logo, application name, package name, version number and other information, excluding the specific uninstallation behavior. Just pass the

Enter the package name and the last two parameters of the version.

KUninstallDialog *uninstallDialog = new KUninstallDialog("browser360-cn-stable","104",this);

输入图片说明

statement describe
QLabel* debAppNameLabel(); 获取应用名称的label
QLabel* debNameLabel(); 获取包名的label
QLabel* debIconLabel(); 获取应用图标的label
QLabel* debVersionLabel(); 获取包版本的label
QPushButton* uninstallButtton(); 获取卸载按钮pushbutton

4.1.3 Input box module

4.1.3.1 Password input box

Function description: KPasswordEdit, supports switching between plain text/dark text of the input content, supports settings

Password verification result (blue border for normal input, green border for correct password, and green border for wrong password

red border), supports loading status, and supports setting whether to enable clearButton.

Enter picture description

enumerated type

enum  LoginState{Ordinary,LoginSuccess,LoginFailed}
statement describe
void setState(LoginState state); 设置登录状态
LoginState state(); 返回登录状态
void setLoading(bool flag); 设置是否启用加载状态。
bool isLoading(); 判断是否处于加载状态
QString placeholderText(); 返回placeholderText的文本内容
void setPlaceholderText(QString&text); 设置PlaceholderText的文本内容
void setClearButtonEnabled(bool enable); 设置是否启用ClearButton
bool isClearButtonEnabled() const; 返回是否启用了ClearButton
void setEchoModeBtnVisible(bool enable); 设置EchoModeBtn是否可见
bool echoModeBtnVisible(); 返回EchoModeBtn是否可见
void setClearBtnVisible(bool enable); 设置ClearBtn是否可见
bool clearBtnVisible(); 返回ClearBtn是否可见
void setEnabled(bool); 设置KLineEdit是否可用

4.1.3.2 Search input box

Function description: You can set the text content and alignment of placeHolder, and the alignment of input text

mode, whether to enable the clear button, etc.

输入图片说明

statement describe
void setEnabled(bool); 设置是否可用
bool isEnabled(); 返回是否可用
void setClearButtonEnabled(bool enable); 设置是否显示清除按钮
bool isClearButtonEnabled() const; 返回是否显示清除按钮
QStringplaceholderText() const; 返回placeholder
void setPlaceholderText(const QString &); 设置placeholder的文本
Qt::Alignment placeholderAlignment() const; 返回placeholder的对齐方式
void setPlaceholderAlignment(Qt::Alignment flag); 设置placeholder的对齐方式
Qt::Alignment alignment() const; 返回输入文本的对齐方式
void setAlignment(Qt::Alignment flag) 设置输入文本的对齐方式。
void clear() 清空搜索框内容。
void setTranslucent(bool flag); 设置是否启用半透明效果自1.2.0.10启用)
bool isTranslucent(); 获取是否启用半透明效果自1.2.0.10启用)

4.1.4 Button module

4.1.4.1 Bordered buttons

Function description: KBoderButton, inherited from QPushButton, is encapsulated in style. able to pass

setPalette() to further adjust the style.

Such as:

QPalette palette = m_pBtn1->palette();                 
palette.setColor(QPalette::ButtonText,QColor(255,0,0)); 
m_pBtn1->setPalette(palette);                          

All interfaces in QPushButton are applicable and support four construction methods.

statement describe
KBorderButton(QWidget* parent = nullptr); 仅一个button
KBorderButton(const QString &text, QWidget *parent = nullptr); 构造一个带文本button
KBorderButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr); 构造一个带文本和图标的button
KBorderButton(const QIcon &icon, QWidget *parent = nullptr); 构造一个带图标的button
void setIcon(const QIcon &icon); 设置按钮图标

4.1.4.2 Borderless buttons

Function description: KboderlessButton, inherited from QPushButton, is encapsulated in style. same

You can further adjust the style through setPalette().

Enter picture description

All interfaces in QPushButton are applicable and support four construction methods.

statement describe
KBorderlessButton(QWidget* parent = nullptr); 仅一个button
KBorderlessButton(const QString &text, QWidget *parent = nullptr); 构造一个带文本button
KBorderlessButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr); 构造一个带文本和图标的button
KBorderlessButton(const QIcon &icon, QWidget *parent = nullptr); 构造一个带图标的button
void setIcon(const QIcon &icon) 设置无边框按钮图标。

4.1.4.3 Drop-down menu button

Function description: KMenuButton, inherited from QPushButon, the default ICon is "open-menu-symbolic", the first-level menu contains 5 options, namely: "Settings", "Theme", "Help", "About", " Exit", the theme includes 3 secondary options, namely: "Follow Theme", "Light Theme", and "Dark Theme".

Enter picture description

Each interface of QPushButton applies.

statement describe
QMenu* menu(); 获取主菜单
QMenu* themeMenu(); 获取主题菜单
QAction* settingAction(); 获取设置action
QAction* themeAction(); 获取主题Action
QAction* assistAction(); 获取帮助Action
QAction* aboutAction() 获取关于Action
QAction* quitAction(); 获取离开Action
QAction* autoAction(); 获取跟随主题Action
QAction* lightAction(); 获取浅色主题Action
QAction* darkAction(); 获取深色主题Action

4.1.4.4 switch button

Function description: KSwitchButton, inherited from QPushButton, redraws the button to indicate the on/off state.

输入图片说明

输入图片说明

statement describe
void setCheckable(bool); 设置是否可选中
bool isCheckable() const; 返回是否可选中
bool isChecked() const; 返回是否选中
void setChecked(bool); 设置是否选中
void setTranslucent(bool flag); 设置是否启用半透明效果自1.2.0.10启用)
bool isTranslucent() 获取是否启用半透明效果自1.2.0.10启用)

4.1.4.5 Tool Buttons

Function description: KToolButton, inherited from QToolButton, supports three styles, supports loading status, and supports whether to display the drop-down button.

Enter image description

enumerated type

enum  KToolButtonType{Flat,SemiFlat,Background}
statement describe
KToolButtonType type(); 返回类型
void setType(KToolButtonType type); 设置类型
void setIcon(const QIcon& icon); 设置Icon
void setLoading(bool flag); 设置正在加载状态,仅不带箭头的toolbuttuon支持该状态
bool isLoading(); 返回是否正在加载
QIcon icon(); 获取Icon
void setArrow(bool flag); 设置是否显示向下箭头,默认不显示
bool hasArrow() const; 返回是否显示箭头
void setPixmapSize(const QSize&size); 设置pixmap大小
QSize pixmapSize() const; 获取pixmap大小

4.1.4.6 KPushButton

Function description: KPushButton, inherited from QPushButton, provides a translucent effect on the basis of QPushButton. You can set the button rounded corners, background color, whether the icon follows the system highlight, and you can also set the button type, which is divided into normal type and round shape (the size needs to be set to achieve a perfect circle). Enabled since version 1.2.0.10.

Enter picture description

enumerated type

enum  ButtonType { NormalType, CircleType };
statement describe
void setBorderRadius(int radius); 通过圆角半径设置按钮圆角(每个圆角相同)
void setBorderRadius(int bottomLeft,int topLeft,int topRight,int bottomRight); 通过四个点来设置圆角
int borderRadius(); 获取按钮圆角
void setBackgroundColor(QColor color); 设置按钮背景色
QColor backgroundColor(); 获取按钮背景色
void setButtonType(ButtonType type); 设置KPushButton的类型
ButtonType buttonType(); 获取KPushButton的类型
void setTranslucent(bool flag); 设置KPushButton是否为半透明
bool isTranslucent(); 判断KPushButton是否为半透明
void setIconHighlight(bool flag); 设置图标是否跟随系统高亮色,默认不跟随
bool isIconHighlight(); 判断图标是否跟随系统高亮色
void setIconColor(QColor color); 设置按钮添加图标的颜色自1.2.0.13启用)
QColor IconColor(); 获取按钮添加图标的颜色自1.2.0.13启用)
void setBackgroundColorHighlight(bool flag); 设置按钮背景色是否跟随系统高亮色默认不跟随自1.2.0.13启用)
bool isBackgroundColorHighlight(); 判断按钮背景色是否跟随系统高亮色自1.2.0.13启用)

4.1.4.7 KPressButton

Function description: KPressButton, inherited from QPushButton, provides translucent effect on the basis of QPushButton, can set rounded corners, whether it is selectable, whether it is selected, and can also set the type of button and whether to enable the loading state. Enabled since version 1.2.0.10.

Enter picture description

enumerated type

enum  ButtonType { NormalType, CircleType };
statement describe
void setBorderRadius(int radius); 通过圆角半径设置按钮圆角(每个圆角相同)
void setBorderRadius(int bottomLeft,int topLeft,int topRight,int bottomRight); 通过四个点来设置圆角
void setCheckable(bool); 设置是否可选中
bool isCheckable() const; 返回是否可选中
void setChecked(bool); 设置是否选中
bool isChecked() const; 返回是否选中
void setButtonType(ButtonType type); 设置button类型
ButtonType buttonType(); 获取KPushButton的类型
void setTranslucent(bool flag); 设置KPushButton是否为半透明
bool isTranslucent(); 判断KPushButton是否为半透明
void setLoaingStatus(bool flag); 设置是否启用loading状态
bool isLoading(); 返回是否启用loading状态

4.1.5 Bar module

4.1.5.1 KIconBar

Function description: A component of KWidget and KDialog, used to display icons and window names.

输入图片说明

statement describe
void setIcon(const QString& iconName); 设置图标名称
void setIcon(const QIcon& icon); 设置图标
void setWidgetName(const QString& widgetName) 设置标题
QLabel* nameLabel(); 获取标题label
QLabel* iconLabel(); 获取图标label

4.1.5.2 KWindowButtonBar

Function description: A component of KWidget and KDialog, used for drop-down menu, minimize, maximize, and close buttons.

enumerated type

enum  MaximumButtonState{Maximum,Restore}

输入图片说明

statement describe
QPushButton* minimumButton(); Get the minimize button
QPushButton* maximumButton(); Get the maximize button
QPushButton* closeButton(); get the close button
KMenuButton* menuButton(); 获取菜单按钮
MaximumButtonState maximumButtonState(); Get the maximize button的状态(最大化/恢复)
void setMaximumButtonState(MaximumButtonState state); 设置最大化按钮图标状态(最大化/恢复)

4.1.5.3 Progress bar

Function description: KProgressBar, inherited from QProgressBar, supports three states: normal, completed and failed, supports whether to display the progress value, supports horizontal and vertical.

Enter picture description

enumerated type

enum  ProgressBarState{NormalProgress,FailedProgress,SuccessProgress}
statement describe
ProgressBarState state(); 获取状态
void setState(ProgressBarState state); 设置状态
QString text() const override; 获取文本
void setOrientation(Qt::Orientation); 设置方向

4.1.5.4 KProgressCircle

The circular progress bar supports three states: normal, completed and failed, and supports whether to display the progress value.

输入图片说明

statement describe
int minimum() const 获取环形进度条的最小值。
int maximum() const 获取环形进度条的最大值。
int value() const 获取环形进度条的值。
QString text() const 获取环形进度条的文本。
void setTextVisible(bool visible) 设置环形进度条的文本是否可见。
bool isTextVisible() const 返回环形进度条的文本是否可见。
ProgressBarState state() 获取环形进度条的状态。
void setState(ProgressBarState state) 设置环形进度条的状态。

4.1.5.5 KTabBar

Function description: Inherited from QTabBar

Enter picture description

enumerated type

enum  KTabBarStyle{SegmentDark,SegmentLight,Sliding}
statement describe
void setTabBarStyle(KTabBarStyle barStyle); 设置TabBar样式
KTabBarStyle barStyle(); 返回TabBar样式
void setBorderRadius(int radius); 设置圆角半径只对SegmentDarkSegmentLight样式生效
int borderRadius(); 获取圆角半径
void setBackgroundColor(const QColor &color) 设置KTabBar背景色。

4.1.5.6 Navigation Bar

Functional description: KNavigationBar supports displaying three styles of items, the item with icon indicates the first-level navigation item, the item without icon indicates the second-level navigation item, and the item in gray font indicating the group.

statement describe
void addItem(QStandardItem*item); 增加常规Item
void addSubItem(QStandardItem*subItem); 增加次级Item
void addGroupItems(QList<QStandardItem*>items,const QString& tag); 成组增加Item,在导航栏中会显示tag
void addTag(const QString& tag); 添加tag
QStandardItemModel* model(); 获取model
QListView* listview(); 获取listview

4.1.5.7 KPixmapContainer

Function description: It is used to indicate the message prompt information on the upper right of the avatar. You can set the value, font size, background color, and picture size of the prompt information.

输入图片说明

statement describe
int value() const; 获取值
void setValue(int value); 设置值
void setValueVisiable(bool flag); 设置值是否可见
bool isValueVisiable() const; 获取值是否可见
void setPixmap(const QPixmap& pixmap); 设置pixmap
QPixmap pixmap()const; 获取pixmap
void clearValue(); 清除值
QColor color(); 返回背景色
void setColor(const QColor& color); 设置背景色
int fontSize(); 返回字体大小
void setFontSize(int size); 设置字体大小

4.1.6 Slider module

4.1.6.1 Slider

Function description:

Non-step relationship: the number of steps is 1, you can click and drag anywhere;

Step relationship: the number of steps is a fixed value, which can be clicked and dragged according to the step value;

Node relationship: the number of steps is the node interval, which can be clicked and dragged according to the node interval

Enter picture description

enumerated type

enum  KSliderType{SmoothSlider,StepSlider,NodeSlider,SingleSelectSlider}
statement describe
void setTickInterval(int interval); 设置节点间隔
void setSliderType(KSliderType type); 设置滑动条类型
KSliderType sliderType(); 获取滑动条类型
int tickInterval() const;
void setValue(int); 设置值
void setNodeVisible(bool flag); 设置是否显示节点
bool nodeVisible(); 获取是否显示节点
void setToolTip(const QString&); 设置tooltip自1.2.0.7启用)
QString toolTip() const;
void setTranslucent(bool flag); 设置是否启用半透明效果自1.2.0.10启用)
bool isTranslucent(); 获取是否启用半透明效果自1.2.0.10启用)

4.1.7 Message prompt module

4.1.7.1 KBadge

Function description: message reminder bubble. You can set the prompt information value, font size, background color.

输入图片说明

statement describe
int value(); 返回值
void setValue(int value); 设置值最大显示数值为999大于999显示"..."
void setValueVisiable(bool flag); 设置值是否可见
bool isValueVisiable() const; 获取值是否可见
QColor color(); 获取背景色
void setColor(const QColor& color); 设置背景色
int fontSize(); 获取字体大小
void setFontSize(int size); 设置字体大小

4.1.7.2 KBallonTip

Function description: message prompt box, supports four background colors and corresponding prompt icons.

Enter picture description

enumerated type

enum  TipType{Nothing,Normal,Info,Warning,Error}
statement describe
void showInfo(); 气泡在显示之后一定时间后自动消失
void setTipType(const TipType& type); 设置类型
TipType tipType(); 返回类型
void setText(const QString& text); 设置文本内容
QString text(); 返回文本内容
void setContentsMargins(int left, int top, int right, int bottom) 通过上下左右数值设置内容边距。
void setContentsMargins(const QMargins &margins); 通过QMargins对象设置内容边距。
void setTipTime(int my_time); 设置持续时间

4.1.7.3 KSecurityLevelBar

Function description: password strength prompt bar, used to indicate the password strength level. It is divided into three levels: low, medium and high, and the specific division strategy of the level is specified by the application program.

输入图片说明

输入图片说明

输入图片说明

枚举类型

enum  SecurityLevel{Low,Medium,High}
statement describe
void setSecurityLevel(SecurityLevel level); 设置安全等级
SecurityLevel securityLevel(); 获取安全等级

4.1.8 Breadcrumbs KBreadCrumb

Borderless tab bar, you can add text and icons, support click and hover highlight.

Function diagram:

输入图片说明

枚举类型

enum  KBreadCrumbType { FlatBreadCrumb, CubeBreadCrumb }
statement describe
void setIcon(const QIcon &icon); 设置图标
QIcon icon() const; 返回图标
bool isFlat() const; 返回KBreadCrumb是否为flat类型。
void setFlat(bool flat); 设置KBreadCrumb是否为flat类型。

4.1.9 KCommentPanel

enum  StarLevel {LevelZero =0, LevelOne, LevelTwo, LevelThree, LevelFour,LevelFive}

枚举类型

statement describe
void setIcon(const QIcon&); 设置图标
void setTime(const QString&); 设置评论时间
void setName(const QString&); 设置评论名称
void setText(const QString&); 设置评论内容
void setGrade(StarLevel level); 设置评论等级

4.1.10 KListView

提供一个图片两行文字的显示效果,若只有一行文字,则对于 icon 居中显示 。

输入图片说明

4.1.11 KTag

标签,分为默认和可关闭的两种。

输入图片说明

输入图片说明

枚举类型

enum  TagStyle { HighlightTag, BoderTag, BaseBoderTag, GrayTag}
statement describe
void setClosable(bool flag) 设置标签是否可以关闭。
bool closable() 返回标签是否可以关闭。
void setText(const QString &text) 设置标签的文本。
void setTagStyle(TagStyle style) 设置标签的样式。
TagStyle tagStyle() 获取标签的样式。
QString text() 获取标签的文本。

4.1.12 KTranslucentFloor

KTranslucentFloor继承自 QFrame提供一个毛玻璃底板可以设置圆角以及是否添加阴影效果。自 1.2.0.12 版本启用。

输入图片说明

statement describe
void setBorderRadious(int radious); 设置圆角半径
int borderRadius(); 返回圆角半径
void setShadow(bool flag); 设置是否显示阴影
bool shadow(); 返回是否显示阴影
void setEnableBlur(bool flag); 设置是否启用毛玻璃效果自2.0.0.0启用)
bool enableBlur(); 获取是否已启用毛玻璃效果自2.0.0.0启用)
void setOpacity(qreal opacity); 设置透明度自2.0.0.0启用)
qreal opacity(); 获取透明度自2.0.0.0启用)

4.2 Wayland-helper

该模块主要负责提供在 X 平台和 Wayland 平台下均能生效的兼容接口,使应用无需考虑显示平台的差异。该模块安装方式如下:

sudo apt install libkysdk-waylandhelper libkysdk-waylandhelper-dev

根据不同项目类型,可参考以下 demo 构建项目:

1 .pro 文件构建项目:

qt 项目.pro 文件中增加:

CONFIG += link_pkgconfig         
PKGCONFIG += kysdk-waylandhelper 

2 CMakeLists.txt 构建项目

cmake_minimum_required(VERSION 3.5)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(KYSDKWAYLANDHELPER_PKG kysdk-waylandhelper)
target_include_directories(demo PRIVATE ${KYSDKWAYLANDHELPER_PKG_INCLUDE_DIRS})
target_link_directories(demo PRIVATE ${KYSDKWAYLANDHELPER_PKG_LIBRARY_DIRS})
target_link_libraries(demo Qt5::Widgets ${KYSDKWAYLANDHELPER_PKG_LIBRARIES})

4.2.1 WindowManager

statement describe
static WindowManager* self(); 获取单例对象
static WindowInfo getwindowInfo(const WindowId& windowId); 获取窗口信息
static WindowId currentActiveWindow(); 获取当前活动窗口
static void keepWindowAbove(const WindowId& windowId); 置顶窗口
static QString getWindowTitle(const WindowId& windowId); 获取窗口标题
static QIcon getWindowIcon(const WindowId& windowId); 获取窗口图标
static QString getWindowGroup(const WindowId& windowId); 获取窗口所在组的组名
static void closeWindow(const WindowId& windowId); 关闭窗口
static void activateWindow(const WindowId& windowId); 激活窗口
static void maximizeWindow(const WindowId& windowId); 最大化窗口
static void minimizeWindow(const WindowId& windowId); 最小化窗口
static quint32 getPid(const WindowId& windowId); 获取窗口进程pid
static void showDesktop(); 显示当前桌面
static void hideDesktop(); 取消显示当前桌面
static QString currentDesktop(); 获取当前桌面的名称
static QList windows(); 获取当前窗口列表
static NET::WindowType getWindowType(const WindowId& windowId); 获取窗口类型仅适用于X环境下wayland下统一返回normal
static void setGeometry(QWindow *window,const QRect &rect);
static void setSkipTaskBar(QWindow *window,bool skip); 设置是否跳过任务栏自2.0.0.0启用)
static void setSkipSwitcher(QWindow *window,bool skip); 设置是否跳过窗口选择自2.0.0.0启用)
static bool skipTaskBar(const WindowId& windowId); 判断窗体是否跳过任务栏自2.0.0.0启用)
static bool skipSwitcher(const WindowId& windowId); 判断窗体是否跳过窗口选择自2.0.0.0启用)
static bool isShowingDesktop(); 判断桌面是否处于显示状态自2.0.0.0启用)
static void setOnAllDesktops(const WindowId &windowId); 设置窗口在所有桌面中显示自2.0.0.0启用)
static bool isOnAllDesktops(const WindowId &windowId); 判断窗口是否在所有桌面中显示自2.0.0.0启用)

4.2.2 WindowInfo

statement describe
inline bool isMaximized() const; 返回窗口是否是最大化状态
inline bool isMinimized() const; 返回窗口是否是最小化状态
inline bool isMaximizable() const; 返回窗口是否可以最大化
inline bool isMinimizable() const; 返回窗口是否可以最小化
inline bool isKeepAbove() const; 返回窗口是否是置顶状态
inline bool hasSkipTaskbar() const; 返回窗口是否跳过任务栏
inline bool isFullscreen() const; 返回窗口是否是全屏状态
inline bool isOnAllDesktops() const noexcept; 返回窗口是否在所有桌面中显示
inline bool isValid() const; 判断窗口id是否有效
inline bool isActive() const noexcept; 返回窗口是否是激活状态

4.2.3 UkuiStyleHelper

statement describe
static UkuiStyleHelper *self(); 获取单例对象
void removeHeader(QWidget* widget); 移除窗管标题栏

4.3 应用通用功能模块

4.3.1 日志模块

submodule Programming language statement describe
日志模块 C++ static void logOutput(QtMsgType type , const QMessageLogContext &context , const QString &msg); 用于Qt注册日志函数不应单独调用.
Parameter Description Return value description
type:日志类型 context:调用打印日志接口文件信息 msg:日志信息

4.3.2 系统相关模块

submodule Programming language statement describe
窗管模块 C++ static bool setWindowMotifHint(int winId); 添加窗管协议 .
Parameter Description Return value description
winId : 窗口 id 成功 : true
失败 : false
submodule Programming language statement describe
窗管模块 C++ static bool setScalingProperties(void); 设置窗口缩放属性
Parameter Description Return value description
成功 : true
失败 : false
submodule Programming language statement describe
session模块 C++ quint32 setInhibitLockScreen(AppName appName , QString reason); 禁止系统锁屏 .
Parameter Description Return value description
appName : 应用名 成功 : 非 0 的正整数
reason : 禁止锁屏的原因 失败 : 0
submodule Programming language statement describe
session模块 C++ bool unInhibitLockScreen(quint32 flag) 取消禁止系统锁屏 .
Parameter Description Return value description
flag : 禁止锁屏标识 成功 : true
失败 : false

4.3.3 d-bus 模块------即将废弃

submodule Programming language statement describe
d-bus模块 C++ static QList callMethod(QString serviceName, QString objectPath, QString interfaceName, QString methodName, QList args = QList()); 函数调用
Parameter Description Return value description
serviceName : 服务名 函数返回值
objectPath : 对象路径
interfaceName : 接口名
methodName : 函数名
args : 参数列表

4.3.4 系统信息模块

submodule Programming language statement describe
系统信息模块 C++ QString getLsbReleaseInformation(QString key); 根据 lsb-release 文件的 key 值 获取信息
Parameter Description Return value description
key : 键值 获取到的信息 , 为空时可能确实为空也可能失败
submodule Programming language statement describe
系统信息模块 C++ QString getOsReleaseInformation(QString key); 根据 os-release 文件的 key 值 获取信息
Parameter Description Return value description
key : 键值 获取到的信息 , 为空时可能确实为空也可能失败
submodule Programming language statement describe
系统信息模块 C++ QString getProjectCodeName(void) 获取 PROJECT_CODENAME 字段的值
Parameter Description Return value description
空 : 失败
非空 : 获取到的值
submodule Programming language statement describe
系统信息模块 C++ QString getCpuModelName(void) 获取 CPU 型号
Parameter Description Return value description
空 : 失败
非空 : 获取到的值
submodule Programming language statement describe
系统信息模块 C++ QString getHdPlatform(void); 获取硬件平台信息
Parameter Description Return value description
空 : 失败
非空 : 获取到的值

5 基础开发 SDK

该层设计主要为应用开发提供与操作系统无关的、高通用性、基础性的功能集合。减少不同应用在实现相同功能式的差异性和复杂性。该层设计主要为应用开发提供与操作系统无关的、高通用性、基础性的功能集合。减少不同应用在实现相同功能式的差异性和复杂性。

安装命令:

$ sudo apt install libkysdk-base libkysdk-base-dev 

5.1 日志

C 语言日志模块提供了八个等级的日志记录接口,非 root 程序记录在~/.log

目录中root 程序记录在/var/log 下

$ sudo apt-get install libkysdk-log llibkysdk-log-dev 

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
add_library(kylog SHARED ${SOURCESCODE})
add_executable(kylog-testlog test/test-log.c)
add_executable(kylog-testsetdir test/test-setdir.c)
add_executable(kylog-testpressure test/test-pressure.c)
add_executable(kylog-testautowrap test/test-autowrap.c)
find_library(SYSTEMD_LIB systemd)
target_link_libraries(kylog kyconf pthread ${SYSTEMD_LIB})
target_link_libraries(kylog-testlog kylog)
target_link_libraries(kylog-testsetdir kylog)
target_link_libraries(kylog-testautowrap kylog)
target_link_libraries(kylog-testpressure kylog)

2调用日志模块需要添加头文件

#include "kysdk/kysdk-base/libkylog.h"

输出日志

类型 statement
输出debug级别日志 #define klog_debug(fmt , ...)
输出info级别日志 #define klog_info(fmt , ...)
输出notice级别日志 #define klog_notice(fmt , ...)
输出warning级别日志 #define klog_warning(fmt , ...)
输出error级别日志 #define klog_err(fmt , ...)
输出crit级别日志 #define klog_crit(fmt , ...)
输出alert级别日志 #define klog_alert(fmt , ...)
输出emerg级别日志 #define klog_emerg(fmt , ...)

初始化日志记录

submodule Programming language statement describe
日志 C extern int kdk_logger_init(const char *ini)
Parameter Description Return value description
ini日志配置文件路径若传入NULL则会使用默认的日志配置文件 int0表示成功非0表示失败

缓存区日志写入

submodule Programming language statement describe
日志 C extern void kdk_logger_flush() DESTRUCTOR;
Parameter Description Return value description

设置日志存储目录

submodule Programming language statement describe
日志 C extern int kdk_logger_setdir(const char* dpath) 设置日志的存储目录若不设置非root程序会被记录在~/.log下root程序会被记录在/var/log下
Parameter Description Return value description
dpath日志存储路径 int

设置日志输出自动换行

submodule Programming language statement describe
日志 C extern void kdk_logger_set_autowrap(int autowarp) 设置日志输出自动换行
Parameter Description Return value description
autowarp1表示启用启动换行0表示禁止自动换行

5.2 定时器

C 语言定时器模块,给 C/C++程序提供定时器功能接口。

$ sudo apt-get install libkysdk-timer libkysdk-timer-dev 

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
add_library(kytimer SHARED ${SOURCESCODE})
add_executable(test-kytimer test/test-kytimer.c)
target_link_libraries(kytimer pthread)
target_link_libraries(test-kytimer kytimer)

2调用定时器模块需要添加头文件

#include "kysdk/kysdk-base/libkytimer.h"

初始化定时器

submodule Programming language statement describe
定时器 C int kdk_timer_init() 初始化定时器核心组件
Parameter Description Return value description
int0表示成功非0表示失败

启动定时器

submodule Programming language statement describe
定时器 C size_t kdk_timer_start(unsigned int intervalms, time_handler callback, KTimerAttribute attr, KTimerType type, void* userdata, int freeOnDelete)
Parameter Description Return value description
intervalms定时器时间以毫秒为单位 size_t定时器的ID
callback定时器到期后触发的回调函数指针
attr定时器属性KTIMER_SINGLESHOT表示一次性定时器KTIMER_PERIODIC表示周期性定时器KTIMER_NEVER表示不会被触发的定时器
type定时器类型KTIMER_ABSOLUTE表示绝对时间定时器修改系统时间不会影响定时器的时间KTIMER_RELATIVE表示相对时间定时器修改系统时间会影响定时器时间
userdata指向用户数据的指针
freeOnDelete [未启用]

停止给定的定时器

submodule Programming language statement describe
定时器 C void kdk_timer_stop(size_t timerfd) 停止给定的定时器
Parameter Description Return value description
timerfd由kdk_timer_start返回的定时器ID

销毁定时器

submodule Programming language statement describe
定时器 C void kdk_timer_destroy() 销毁定时器
Parameter Description Return value description

重置定时器

submodule Programming language statement describe
定时器 C void kdk_timer_reset(size_t timerfd , unsigned int intervalms) 重置定时器
Parameter Description Return value description
timerfd由kdk_timer_start返回的定时器ID
intervalms需要调整的时间间隔以ms为单位

5.3 C 语言字符串扩展

该模块封装了对字符串操作的 C 接口,包括字符串裁剪、分割、大小写转换、查找特定字符等操作。

$ sudo apt-get install libkysdk-utils libkysdk-utils-dev 

1调用 C 语言字符串扩展模块,需要添加头文件:

#include "kysdk/kysdk-base/cstring-extension.h"

分割字符串

submodule Programming language statement describe
C语言字符串扩展 C static inline char** strsplit(char *str, char delim) 对原字符串以给定的分隔符进行分割,注意该函数会修改原字符串
Parameter Description Return value description
str:需要分割的字符串 char** 分割后的字符串列表以NULL结尾。存储分割后所有字符串的字符串列表本身是由alloc申请的内存因此当使用完成后应当被free而分割出来的各个字符串不是申请的内存而是分别指向了原字符串中的特定位置因此他们不需要被分别free
delim:分隔符

小写字符串

submodule Programming language statement describe
C语言字符串扩展 C static inline void str2lower(char *str) 将字符串中的所有大写字母转化为小写字
Parameter Description Return value description
str:需要操作的字符串指针

大写字符串

submodule Programming language statement describe
C语言字符串扩展 C static inline void str2upper(char *str) 将字符串中的所有小写字母转化为大写字母
Parameter Description Return value description
str:需要操作的字符串指针

统计出现次数

submodule Programming language statement describe
C语言字符串扩展 C static inline size_t strcounts(const char *str, char ch) 统计给定字符在字符串中出现的次数
Parameter Description Return value description
str:原字符串 size_t:字符出现的次数
ch:需要统计的字符

后缀判断

submodule Programming language statement describe
C语言字符串扩展 C static inline int strendwith(const char *str, const char *postfix) 判断str是否以postfix结尾需要区分大小写
Parameter Description Return value description
str:原字符串 int 若str以postfix结尾则返回0否则返回1
postfix:需要匹配的字符串后缀

查找子字符串的首次出现位置

submodule Programming language statement describe
C语言字符串扩展 C static inline int strfirstof(const char* str, char ch) 在给定的字符串中查找给定字符第一次出现的位置计数从0开始
Parameter Description Return value description
str:原字符串 int 第一次出现的位置,若未找到给定的字符,则返回-1
ch:需要查找的字符

查找子字符串的末次出现位置

submodule Programming language statement describe
C语言字符串扩展 C static inline int strlastof(const char* str, char ch) 在给定的字符串中查找给定字符最后一次出现的位置计数从0开始
Parameter Description Return value description
str:原字符串 int 最后一次出现的位置,若未找到给定的字符,则返回-1
ch:需要查找的字符

删除空格和制表符

submodule Programming language statement describe
C语言字符串扩展 C static inline void strstripblank(char *str) 删除给定字符串前后的空格和水平制表符tab注意该操作会修改原字符串
Parameter Description Return value description
str:需要修改的字符串指针

跳过开始的所有空格、制表符、换行符

submodule Programming language statement describe
C语言字符串扩展 C static inline const char *strskipspace(const char *p) 跳过字符串前的所有空格、制表符、换行符;该操作不会修改原字符串
Parameter Description Return value description
p:指向原字符串的指针 const char* 指向跳过space后的字符串指针

前缀判断(区分大小写)

submodule Programming language statement describe
C语言字符串扩展 C static inline int strstartswith(const char *str, const char *prefix) 判断str是否以prefix开头该函数区分大小写
Parameter Description Return value description
str原字符串 int 若str以prefix开头则返回0否则返回1
prefix需要匹配的字符串前缀

前缀判断(不区分大小写)

submodule Programming language statement describe
C语言字符串扩展 C static inline int strstartswith_nocase(const char *str, const char *prefix) 判断str是否以prefix开头不区分大小写
Parameter Description Return value description
str:原字符串 int 若str以prefix开头则返回0否则返回1
prefix:需要匹配的字符串前缀

删减字符串前后的指定字符

submodule Programming language statement describe
C语言字符串扩展 C static inline void strstrip(char *str, char ch) 对给定的字符串进行strip操作删减字符串前后的指定字符注意该操作会修改原字符串
Parameter Description Return value description
str:需要进行strip的字符串指针
ch:需要删除的字符

跳过开始的所有空格、水平制表符

submodule Programming language statement describe
C语言字符串扩展 C static inline const char *strskipblank(const char *p) 跳过字符串前的所有空格和水平制表符tab该操作不会修改原字符串
Parameter Description Return value description
p指向原字符串的指针 const char* 指向跳过space后的字符串指针

删除前后的空格、制表符、换行符

submodule Programming language statement describe
C语言字符串扩展 C static inline void strstripspace(char *str) 删除给定字符串前后的空格、制表符、换行符,注意该操作会修改原字符串
Parameter Description Return value description
str需要进行strip操作的字符串指针

5.4 链表模块

该模块实现了 C 语言链表操作相关接口。

$ sudo apt-get install libkysdk-utils libkysdk-utils-dev

1CMakeLists.txt 构建项目

aux_source_directory(linklist/skip_linklist SOURCESCODE)
add_library(kydatastruct SHARED ${SOURCESCODE})
add_subdirectory(linklist)
include_directories(linklist)
include_directories(linklist/skip_linklist)
add_executable(test-delete linklist/skip_linklist/test/delete_test.c)
add_executable(test-insert linklist/skip_linklist/test/insert_test.c)
add_executable(test-search linklist/skip_linklist/test/search_test.c)
target_link_libraries(test-delete kydatastruct)
target_link_libraries(test-insert kydatastruct)
target_link_libraries(test-search kydatastruct)

2调用定时器模块需要添加头文件

#include "kysdk/kysdk-base/skip_linklist.h"

创建跳表

submodule Programming language statement describe
链表 C extern kysdk_skiplist* kysdk_create_skiplist() 创建跳表
Parameter Description Return value description
kysdk_skiplist* 跳表

销毁跳表

submodule Programming language statement describe
链表 C extern void kysdk_destroy_skiplist(kysdk_skiplist *list) 销毁跳表并回收所有分配的内存注意data.ptr指向的内存若存在不会被释放
Parameter Description Return value description
list跳表

删除 key 值对应的节点

submodule Programming language statement describe
链表 C extern int kysdk_skiplist_delete(kysdk_skiplist *list, int key) 删除key值对应的节点
Parameter Description Return value description
list需要操作的链表 int, 成功删除返回0失败返回-1
key

插入节点

submodule Programming language statement describe
链表 C extern int kysdk_skiplist_insert(kysdk_skiplist *list, int key, kysdk_listdata data) 插入节点
Parameter Description Return value description
list需要操作的链表 int成功插入返回0失败返回-1
key
data数据

根据给定的 key 搜索 data 内容

submodule Programming language statement describe
链表 C extern kysdk_listdata kysdk_skiplist_search(kysdk_skiplist *list, int key) 根据给定的key搜索data内容
Parameter Description Return value description
list需要操作的链表 kysdk_listdata当搜索的key不存在时data.num值为-1
key

设置跳表最高层数

submodule Programming language statement describe
链表 C extern int kysdk_skiplist_setmaxlevels(kysdk_skiplist *list, unsigned int maxlevels) 设置跳表最高层数,该选项必须在跳表为空时使用
Parameter Description Return value description
list需要修改的跳表 int成功返回0失败返回-1
maxlevels层数

5.5 配置文件操作

KYSDK 配置文件处理库支持标准格式、XML(未实现)、JSON(未实现)的

配置文件处理,包括配置文件的读与写操作。

sudo apt-get install libkysdk-config libkysdk-config-dev

1CMakeLists.txt 构建项目

aux_source_directory(. SOURCESCODE)
add_library(kyconf SHARED ${SOURCESCODE})
add_executable(kyconf-test-struct test/test_structlist.c)
target_link_libraries(kyconf-test-struct kyconf kylog pthread)

2调用配置文件模块需要添加头文件

#include "kysdk/kysdk-base/libkyconf.h"

初始化配置文件

submodule Programming language statement describe
配置文件操作 C extern int kdk_conf_init(const char* confpath) 初始化配置文件
Parameter Description Return value description
confpath配置文件的路径 int 成功返回句柄号(非负值),失败返回错误码(负值)

销毁指定的配置文件句柄

submodule Programming language statement describe
配置文件操作 C extern void kdk_conf_destroy(int id) 销毁指定的配置文件句柄
Parameter Description Return value description
id由kdk_conf_init返回的配置文件句柄

重新载入配置文件

submodule Programming language statement describe
配置文件操作 C extern int kdk_conf_reload(int id) 重新载入配置文件
Parameter Description Return value description
id由kdk_conf_init返回的配置文件句柄 int 成功返回0失败返回错误码

获取指定配置项的值

submodule Programming language statement describe
配置文件操作 C extern const char* kdk_conf_get_value(int id, const char* group, const char* key) 获取指定配置项的值
Parameter Description Return value description
id由kdk_conf_init返回的配置文件句柄 const char* 配置项所拥有的值若key不存在则返回一个空字符串
groupkey所在的组名称
key配置项名称

枚举 key 值

submodule Programming language statement describe
配置文件操作 C extern char** const kdk_conf_list_key(int id, const char* group) 列举id对应配置文件的指定Group下的key值结尾以NULL指针表示
Parameter Description Return value description
id由kdk_conf_init返回的句柄值 const char** const 以NULL结尾的字符串列表每个字符串都是一个key名称字符串列表本身是由alloc分配的内存需要被free释放字符串不需要释放
group需要列举的Group名称

枚举配置文件的 Group

submodule Programming language statement describe
配置文件操作 C extern char** const kdk_conf_list_group(int id) 列举id对应配置文件的所有Group结尾以NULL指针表示
Parameter Description Return value description
id由kdk_conf_init返回的句柄值 const char** const 以NULL结尾的字符串列表每个字符串都是一个组名称字符串列表本身是由alloc分配的内存需要被free释放字符串不需要释放

5.6 单位进制转换

$ sudo apt-get install libkysdk-utils libkysdk-utils-dev 

1调用 C 语言字符串扩展模块,需要添加头文件:

#include "kysdk/kysdk-base/cstring-extension.h"

字符格式单位进制转换

submodule Programming language statement describe
配置文件操作 C extern int kdkVolumeBaseCharacterConvert(const char* origin_data, KDKVolumeBaseType result_base, char* result_data); 字符格式单位进制转换
Parameter Description Return value description
入参: int类型值接口执行是否成功
origin_data:原始字符类型的数据以具体进制单位结束如果没有缺省为B 0-无异常
result_base:期望的结果进制单位 1-非法进制
出参: 2-非法参数
result_data:转化进制后的字符数据,带进制单位 3-非法数据格式
4-系统运行异常引发的未知错误

数字格式单位进制转换

submodule Programming language statement describe
配置文件操作 C extern int kdkVolumeBaseNumericalConvert(double origin_numerical, KDKVolumeBaseType origin_base, KDKVolumeBaseType result_base, double* result_numerical); 数字格式单位进制转换
Parameter Description Return value description
入参: int类型值接口执行是否成功
origin_numerical原始数字类型数据 0-无异常
origin_base原始的进制单位 1-非法进制
出参: 2-非法参数
result_base期望的进制单位 3-非法数据格式
result_numerical期望进制下的数字类型数据 4-系统运行异常引发的未知错误