Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development - Better User management and Widgets library #112

Merged
merged 10 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KERNELOBJ = bin/kernel.o bin/terminal.o bin/helpers.o bin/pci.o bin/virtualdisk.
bin/diskdev.o bin/scheduler.o bin/work.o bin/rbuffer.o bin/errors.o bin/kclock.o bin/tar.o bin/color.o bin/loopback.o \
bin/serial.o bin/io.o bin/syscalls.o bin/list.o bin/hashmap.o bin/vbe.o bin/ksyms.o bin/windowserver.o bin/encoding.o\
bin/mouse.o bin/ipc.o bin/sysinf.o ${PROGRAMOBJ} ${GFXOBJ} bin/font8.o bin/net.o bin/fs.o bin/ext.o bin/fat16.o bin/partition.o\
bin/admin.o bin/usermanager.o bin/user.o bin/group.o bin/snake.o bin/msgbox.o
bin/admin.o bin/usermanager.o bin/user.o bin/group.o bin/snake.o bin/msgbox.o bin/kevents.o

BOOTOBJ = bin/bootloader.o

Expand Down
8 changes: 4 additions & 4 deletions admin/usermanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ static const struct userdb default_db = {
.name = "admin",
.hash = 525286959, /* admin */
.uid = 1,
.permissions = _
.permissions = ADMIN_FULL_ACCESS
},
{
.name = "system",
.hash = 1,
.uid = 2,
.permissions = _
.permissions = SYSTEM_FULL_ACCESS
},
{
.name = "guest",
.hash = 0,
.uid = 3,
.permissions = _
.permissions = CTRL_PROC_CREATE | ACCESS_NET | ACCESS_FS_READ
}
},
.groups = {
{
.name = "admin",
.gid = 1,
.permissions = _
.permissions = USER_CREATE | USER_PWD_MANAGE | USER_GROUP_MANAGE
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions apps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ programs: staticlibs bin/crt0.o ${USROBJS}
@make -C calculator/
@make -C graphs/
@make -C cube/
@make -C users/
@echo [USR] All user programs created and linked!

bin/%.o: utils/%.cpp
Expand Down Expand Up @@ -83,4 +84,5 @@ clean:
@make -C calculator/ clean
@make -C graphs/ clean
@make -C cube/ clean
@make -C users/ clean
rm -f .depend
48 changes: 48 additions & 0 deletions apps/users/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ROOT = ../../

CCFLAGS=-m32 -O2 -Wall -Wextra -Wpedantic -Wstrict-aliasing \
-Wno-pointer-arith -Wno-unused-parameter -nostdlib \
-nostdinc -ffreestanding -fno-pie -fno-stack-protector \
-fno-builtin-function -fno-builtin -I $(ROOT)include/ -I $(ROOT)apps/ -fno-exceptions -fno-rtti
MAKEFLAGS += --no-print-directory
UNAME := $(shell uname)
ifeq ($(UNAME),Linux)
CC=gcc
CPP=g++
AS=as
LD=ld

CCFLAGS += -elf_i386
ASFLAGS += --32
LDFLAGS += -m elf_i386
else
CC=i386-elf-gcc
CPP=i386-elf-g++
AS=i386-elf-as
LD=i386-elf-ld
endif

#### ONLY EDIT THIS ####
OUTPUT = users.o
LIBS = -lcore -lgraphic
EXTENDED =
########################

SRC_FILES = $(wildcard *.cpp)
OBJ_FILES = $(SRC_FILES:%.cpp=$(OUTPUTDIR)%.o)
OUTPUTDIR = ./bin/

all: $(OUTPUT) install

install: $(OUTPUT)
@cp $(OUTPUT) $(ROOT)rootfs/bin

$(OUTPUT): $(OBJ_FILES)
$(LD) -o $@ $(LDFLAGS) $^ -L$(ROOT)apps $(LIBS) $(EXTENDED) -T $(ROOT)apps/utils/linker.ld

$(OUTPUTDIR)%.o: %.cpp
@mkdir -p $(OUTPUTDIR)
$(CPP) $(CCFLAGS) -c $< -o $@

clean:
rm -rf $(OUTPUTDIR)* *.o *.d $(OUTPUT) .depend
139 changes: 139 additions & 0 deletions apps/users/users.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <utils/Graphics.hpp>
#include <utils/StdLib.hpp>
#include <utils/Widgets.hpp>
#include <utils/Thread.hpp>
#include <libc.h>
#include <colors.h>

class UserEditor : public Window {

public:
UserEditor(int width, int height) : Window(200, 200, "User Editor", 1) {
this->width = width;
this->height = height;

/* Create widgets */
widgets = new WidgetManager();
widgets->addWidget(new Button(10, 10, 100, 12, "Button", []() {
printf("Button pressed!\n");
}));
}

int eventHandler(struct gfx_event* event) {
switch (event->event)
{
case GFX_EVENT_RESOLUTION:
/* update screensize */
break;
case GFX_EVENT_EXIT:
delete widgets;
return -1;
case GFX_EVENT_KEYBOARD:
widgets->Keyboard(event->data);
/* keyboard event in e.data */
break;
case GFX_EVENT_MOUSE:
widgets->Mouse(event->data, event->data2);
break;
}
return 0;
}

void draw() {
/* Clear screen */
drawRect(0, 0, width, height, 30);
/* Draw widgets */
widgets->draw(this);
}

private:
int width;
int height;
WidgetManager* widgets;
};

void editorEntry(void* arg) {
UserEditor t(200, 200);

struct gfx_event e;
while (1){
gfx_get_event(&e, GFX_EVENT_BLOCKING); /* alt: GFX_EVENT_NONBLOCKING */
if(t.eventHandler(&e) == -1) break;
t.draw();
}
return;
}

class Users : public Window {
public:
Users(int width, int height) : Window(200, 200, "Users", 1) {
this->width = width;
this->height = height;

/* Create widgets */
widgets = new WidgetManager();
widgets->addWidget(new Button(10, 10, 100, 12, "Button", []() {
printf("Button pressed!\n");
}));
widgets->addWidget(new Button(10, 30, 100, 12, "Start Edit", []() {

Thread* editor = new Thread(editorEntry, 0);
editor->start(0);

}));

Input* input = new Input(10, 50, 100, 12, "Input");
widgets->addWidget(input);

widgets->addWidget(new Checkbox(10, 110, true));
widgets->addWidget(new Label(30, 110, 100, 12, "Checkbox"));
widgets->addWidget(new Checkbox(10, 130, false));
}

int eventHandler(struct gfx_event* event) {
switch (event->event)
{
case GFX_EVENT_RESOLUTION:
/* update screensize */
break;
case GFX_EVENT_EXIT:
delete widgets;
exit();
/* exit */
return -1;
case GFX_EVENT_KEYBOARD:
widgets->Keyboard(event->data);
/* keyboard event in e.data */
break;
case GFX_EVENT_MOUSE:
widgets->Mouse(event->data, event->data2);
break;
}
return 0;
}

void draw() {
/* Clear screen */
drawRect(0, 0, width, height, 30);
/* Draw widgets */
widgets->draw(this);
}

private:
int width;
int height;
WidgetManager* widgets;
};

int main()
{
Users t(200, 200);

struct gfx_event e;
while (1){
gfx_get_event(&e, GFX_EVENT_BLOCKING); /* alt: GFX_EVENT_NONBLOCKING */
if(t.eventHandler(&e) == -1) break;
t.draw();
}
return 0;
}
Loading