use xemil instead of libconfig
This commit is contained in:
parent
3cf59d76a6
commit
46c31fcdfd
12 changed files with 111 additions and 70 deletions
|
|
@ -2,7 +2,11 @@ include(MDEBase)
|
||||||
include(MDEPkgConfig)
|
include(MDEPkgConfig)
|
||||||
mde_setup_project(mpanel ${CMAKE_INSTALL_BINDIR})
|
mde_setup_project(mpanel ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
mde_pkg_config_add(mpanel libconfig)
|
target_link_libraries(
|
||||||
|
mpanel
|
||||||
|
PRIVATE
|
||||||
|
xemil
|
||||||
|
)
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,73 @@
|
||||||
#include "mpanel.h"
|
#include "mpanel.h"
|
||||||
|
|
||||||
static void read_config(config_t* cfg, const char* path) {
|
static void read_config(xemil_t** cfg, const char* path) {
|
||||||
if(!config_read_file(cfg, path)) {
|
xemil_t* tmp;
|
||||||
fprintf(stderr, "MPanel config error: file %s at line %d: %s\n", path, config_error_line(cfg), config_error_text(cfg));
|
|
||||||
|
if((tmp = xl_open_file(path)) == NULL || !xl_parse(tmp)) {
|
||||||
|
fprintf(stderr, "MPanel config error: file %s\n", path);
|
||||||
|
if(tmp != NULL) xl_close(tmp);
|
||||||
|
} else {
|
||||||
|
if((*cfg) != NULL) xl_close(*cfg);
|
||||||
|
|
||||||
|
*cfg = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_modules(void) {
|
void load_modules(void) {
|
||||||
config_t cfg;
|
xemil_t* cfg = NULL;
|
||||||
config_setting_t* s;
|
char* conf = MDEDirectoryConfigPath();
|
||||||
char* conf = MDEDirectoryConfigPath();
|
char* dir = MwDirectoryJoin(conf, "mpanel");
|
||||||
char* dir = MwDirectoryJoin(conf, "mpanel");
|
char* path = MwDirectoryJoin(dir, "mpanelrc");
|
||||||
char* path = MwDirectoryJoin(dir, "mpanelrc");
|
|
||||||
|
|
||||||
free(dir);
|
free(dir);
|
||||||
free(conf);
|
free(conf);
|
||||||
|
|
||||||
config_init(&cfg);
|
|
||||||
config_clear(&cfg);
|
|
||||||
read_config(&cfg, SYSCONFDIR "/mpanel/mpanelrc");
|
read_config(&cfg, SYSCONFDIR "/mpanel/mpanelrc");
|
||||||
read_config(&cfg, path);
|
read_config(&cfg, path);
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
if((s = config_lookup(&cfg, "Modules")) != NULL && (config_setting_type(s) == CONFIG_TYPE_LIST || config_setting_type(s) == CONFIG_TYPE_ARRAY)) {
|
if(cfg != NULL && cfg->root != NULL) {
|
||||||
int i = 0;
|
xl_node_t* n = cfg->root->first_child;
|
||||||
config_setting_t* c;
|
if(strcmp(cfg->root->name, "Modules") != 0) {
|
||||||
while((c = config_setting_get_elem(s, i)) != NULL) {
|
fprintf(stderr, "MPanel config error: Root element has to be Modules\n");
|
||||||
config_setting_t* type;
|
return;
|
||||||
if(config_setting_type(c) == CONFIG_TYPE_GROUP && (type = config_setting_lookup(c, "Type")) != NULL && config_setting_type(type) == CONFIG_TYPE_STRING) {
|
}
|
||||||
char* p;
|
|
||||||
void* lib;
|
|
||||||
|
|
||||||
dir = MDEStringConcatenate(LIBDIR "/mpanel/lib", config_setting_get_string(type));
|
while(n != NULL) {
|
||||||
p = MDEStringConcatenate(dir, "Module.so");
|
if(n->type == XL_NODE_NODE && strcmp(n->name, "Module") == 0) {
|
||||||
free(dir);
|
char* type = NULL;
|
||||||
|
xl_attribute_t* attr = n->first_attribute;
|
||||||
|
|
||||||
if((lib = dlopen(p, RTLD_LOCAL | RTLD_LAZY)) != NULL) {
|
while(attr != NULL) {
|
||||||
void (*call)(MwWidget box, config_setting_t* setting) = dlsym(lib, "module");
|
if(strcmp(attr->key, "Type") == 0) {
|
||||||
|
type = attr->value;
|
||||||
|
}
|
||||||
|
|
||||||
call(box, c);
|
attr = attr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(p);
|
if(type != NULL) {
|
||||||
}
|
char* p = MDEStringConcatenate("lib", type);
|
||||||
i++;
|
char* p2 = MDEStringConcatenate(p, "Module.so");
|
||||||
}
|
char* s = MwDirectoryJoin(LIBDIR "/mpanel", p2);
|
||||||
}
|
void* lib = dlopen(s, RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
|
||||||
config_destroy(&cfg);
|
if(lib != NULL) {
|
||||||
|
void (*module)(MwWidget box, xl_node_t* node) = dlsym(lib, "module");
|
||||||
|
|
||||||
|
if(module != NULL) module(box, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(s);
|
||||||
|
free(p2);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n = n->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
xl_close(cfg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
/* External */
|
/* External */
|
||||||
#include <libconfig.h>
|
#include <xemil.h>
|
||||||
|
|
||||||
/* Standard */
|
/* Standard */
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,10 @@
|
||||||
Modules: (
|
<?xml version="1.0"?>
|
||||||
{
|
<Modules>
|
||||||
Type = "StartButton";
|
<Module Type="StartButton">
|
||||||
},
|
</Module>
|
||||||
{
|
<Module Type="Separator" />
|
||||||
Type = "Separator";
|
<Module Type="TaskBar">
|
||||||
},
|
</Module>
|
||||||
{
|
<Module Type="Separator" />
|
||||||
Type = "TaskBar";
|
<Module Type="Time" />
|
||||||
},
|
</Modules>
|
||||||
{
|
|
||||||
Type = "Separator";
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Type = "Time";
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,8 @@ include(MDEBase)
|
||||||
include(MDEPkgConfig)
|
include(MDEPkgConfig)
|
||||||
mde_setup_library(SeparatorModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
mde_setup_library(SeparatorModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
||||||
|
|
||||||
mde_pkg_config_add(SeparatorModule libconfig)
|
target_link_libraries(
|
||||||
|
SeparatorModule
|
||||||
|
PRIVATE
|
||||||
|
xemil
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <libconfig.h>
|
#include <xemil.h>
|
||||||
|
|
||||||
void module(MwWidget box, config_setting_t* setting) {
|
void module(MwWidget box, xl_node_t* node) {
|
||||||
MwVaCreateWidget(MwSeparatorClass, "separator", box, 0, 0, 0, 0,
|
MwVaCreateWidget(MwSeparatorClass, "separator", box, 0, 0, 0, 0,
|
||||||
MwNfixedSize, 10,
|
MwNfixedSize, 10,
|
||||||
MwNorientation, MwVERTICAL,
|
MwNorientation, MwVERTICAL,
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,12 @@ include(MDEBase)
|
||||||
include(MDEPkgConfig)
|
include(MDEPkgConfig)
|
||||||
mde_setup_library(StartButtonModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
mde_setup_library(StartButtonModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
||||||
|
|
||||||
mde_pkg_config_add(StartButtonModule libconfig)
|
target_link_libraries(
|
||||||
|
StartButtonModule
|
||||||
|
PRIVATE
|
||||||
|
xemil
|
||||||
|
)
|
||||||
|
|
||||||
mde_pkg_config_add(StartButtonModule inih)
|
mde_pkg_config_add(StartButtonModule inih)
|
||||||
|
|
||||||
mde_math_add(StartButtonModule)
|
mde_math_add(StartButtonModule)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#define _MILSKO
|
#define _MILSKO
|
||||||
#include <MDE/Foundation.h>
|
#include <MDE/Foundation.h>
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <libconfig.h>
|
#include <xemil.h>
|
||||||
#include <ini.h>
|
#include <ini.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -132,9 +132,9 @@ static void call(const char* name, int dir, int symlink, void* user) {
|
||||||
if(opaque->name != NULL) {
|
if(opaque->name != NULL) {
|
||||||
int i;
|
int i;
|
||||||
MwMenu mc = NULL, m;
|
MwMenu mc = NULL, m;
|
||||||
for(i = 0; i < arrlen(opaque->menu->sub); i++) {
|
for(i = 0; i < arrlen(opaque->menu->sub[0]->sub); i++) {
|
||||||
if(strcmp(opaque->menu->sub[i]->name, category_mapping[c]) == 0) {
|
if(strcmp(opaque->menu->sub[0]->sub[i]->name, category_mapping[c]) == 0) {
|
||||||
mc = opaque->menu->sub[i];
|
mc = opaque->menu->sub[0]->sub[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +145,7 @@ static void call(const char* name, int dir, int symlink, void* user) {
|
||||||
mc->sub = NULL;
|
mc->sub = NULL;
|
||||||
mc->wsub = NULL;
|
mc->wsub = NULL;
|
||||||
|
|
||||||
arrput(opaque->menu->sub, mc);
|
arrput(opaque->menu->sub[0]->sub, mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < arrlen(mc->sub); i++) {
|
for(i = 0; i < arrlen(mc->sub); i++) {
|
||||||
|
|
@ -275,7 +275,7 @@ int sort_alphabet(const void* a, const void* b) {
|
||||||
return strcmp((*((MwMenu*)a))->name, (*((MwMenu*)b))->name);
|
return strcmp((*((MwMenu*)a))->name, (*((MwMenu*)b))->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void module(MwWidget box, config_setting_t* setting) {
|
void module(MwWidget box, xl_node_t* node) {
|
||||||
MwLLPixmap closed = NULL;
|
MwLLPixmap closed = NULL;
|
||||||
MwLLPixmap opened = NULL;
|
MwLLPixmap opened = NULL;
|
||||||
MwWidget btn;
|
MwWidget btn;
|
||||||
|
|
@ -348,15 +348,25 @@ void module(MwWidget box, config_setting_t* setting) {
|
||||||
opaque->menu->wsub = NULL;
|
opaque->menu->wsub = NULL;
|
||||||
opaque->menu->sub = NULL;
|
opaque->menu->sub = NULL;
|
||||||
|
|
||||||
|
m = malloc(sizeof(*m));
|
||||||
|
m->name = MwStringDuplicate("Applications");
|
||||||
|
m->keep = 0;
|
||||||
|
m->wsub = NULL;
|
||||||
|
m->sub = NULL;
|
||||||
|
|
||||||
|
arrput(opaque->menu->sub, m);
|
||||||
|
|
||||||
MDEDirectoryScan(DATAROOTDIR "/applications", call, opaque);
|
MDEDirectoryScan(DATAROOTDIR "/applications", call, opaque);
|
||||||
MDEDirectoryScan("/usr/share/applications", call, opaque);
|
MDEDirectoryScan("/usr/share/applications", call, opaque);
|
||||||
#if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
MDEDirectoryScan("/usr/pkg/share/applications", call, opaque);
|
MDEDirectoryScan("/usr/pkg/share/applications", call, opaque);
|
||||||
#endif
|
#endif
|
||||||
qsort(opaque->menu->sub, arrlen(opaque->menu->sub), sizeof(MwMenu), sort_alphabet);
|
|
||||||
|
|
||||||
for(i = 0; i < arrlen(opaque->menu->sub); i++) {
|
if(arrlen(opaque->menu->sub[0]->sub) > 0) {
|
||||||
qsort(opaque->menu->sub[i]->sub, arrlen(opaque->menu->sub[i]->sub), sizeof(MwMenu), sort_alphabet);
|
qsort(opaque->menu->sub[0]->sub, arrlen(opaque->menu->sub[0]->sub), sizeof(MwMenu), sort_alphabet);
|
||||||
|
for(i = 0; i < arrlen(opaque->menu->sub[0]->sub); i++) {
|
||||||
|
qsort(opaque->menu->sub[0]->sub[i]->sub, arrlen(opaque->menu->sub[0]->sub[i]->sub), sizeof(MwMenu), sort_alphabet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
btn->opaque = opaque;
|
btn->opaque = opaque;
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,8 @@ include(MDEBase)
|
||||||
include(MDEPkgConfig)
|
include(MDEPkgConfig)
|
||||||
mde_setup_library(TaskBarModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
mde_setup_library(TaskBarModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
||||||
|
|
||||||
mde_pkg_config_add(TaskBarModule libconfig)
|
target_link_libraries(
|
||||||
|
TaskBarModule
|
||||||
|
PRIVATE
|
||||||
|
xemil
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <libconfig.h>
|
#include <xemil.h>
|
||||||
|
|
||||||
void module(MwWidget box, config_setting_t* setting) {
|
void module(MwWidget box, xl_node_t* node) {
|
||||||
MwWidget b = MwCreateWidget(MwFrameClass, "taskbar", box, 0, 0, 0, 0);
|
MwWidget b = MwCreateWidget(MwFrameClass, "taskbar", box, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,8 @@ include(MDEBase)
|
||||||
include(MDEPkgConfig)
|
include(MDEPkgConfig)
|
||||||
mde_setup_library(TimeModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
mde_setup_library(TimeModule ${CMAKE_INSTALL_LIBDIR}/mpanel)
|
||||||
|
|
||||||
mde_pkg_config_add(TimeModule libconfig)
|
target_link_libraries(
|
||||||
|
TimeModule
|
||||||
|
PRIVATE
|
||||||
|
xemil
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <libconfig.h>
|
#include <xemil.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -54,7 +54,7 @@ static void tick(MwWidget handle, void* user, void* client) {
|
||||||
free(children);
|
free(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
void module(MwWidget box, config_setting_t* setting) {
|
void module(MwWidget box, xl_node_t* node) {
|
||||||
MwWidget b = MwVaCreateWidget(MwBoxClass, "time", box, 0, 0, 0, 0,
|
MwWidget b = MwVaCreateWidget(MwBoxClass, "time", box, 0, 0, 0, 0,
|
||||||
MwNfixedSize, 64,
|
MwNfixedSize, 64,
|
||||||
MwNbackground, "#bebdb2",
|
MwNbackground, "#bebdb2",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue