Skip to content

Commit

Permalink
rework the UI and fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
NachtsternBuild authored Aug 9, 2024
1 parent eb9efea commit 5d99f29
Showing 1 changed file with 120 additions and 63 deletions.
183 changes: 120 additions & 63 deletions Anwendung/preflash/backup_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,75 +22,132 @@
#include "program_functions.h"
#include "function_header.h"

// the root backup skript in c need a little test
// extern void backup_root();
#define MAX_BUFFER_SIZE 256
// include all functions
extern void backup_root();
extern void backup_noroot();

// button 1 - backup with root
static void get_backup_root(GtkWidget *widget, gpointer data)
// Callback functions for each button
// function without any function
static void start_zero_function_20(GtkWidget *widget, gpointer data)
{
// backup_root();
// this is if the c-code not work
char function_command[255];
open_terminal_by_desktop("bash /usr/bin/projekt-122/backup_root.sh");
printf("Keine Funktion!\n");
}

// button 3 - backup without root
static void get_backup_noroot(GtkWidget *widget, gpointer data)
// function backup via root
static void start_backup_root(GtkWidget *widget, gpointer data)
{

// char function_command[255];
/* thanks to @mrrfv for the backup-skripts */
// open_terminal_by_desktop("bash backup.sh");
backup_noroot();
GtkWidget *dialog;
const char *message;
message = "Der Prozess kann eine Weile dauern. \nIgnorien sie alle beenden erzwingen Meldungen.\n";
show_message(message);

backup_root();

message = "Prozess beendet.\n";
show_message(message);
}

void backup_function(int argc, char *argv[])
// no function
static void start_zero_function_21(GtkWidget *widget, gpointer data)
{
// int gtk
gtk_init(&argc, &argv);

// make main window
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Projekt 122 - Backup");
gtk_container_set_border_width(GTK_CONTAINER(window), 500);
gtk_widget_set_size_request(window, 800, 750);
gtk_widget_show(window);

// make button for every function
GtkWidget *button_get_backup_root = gtk_button_new_with_label("Root Backups");
GtkWidget *button_get_backup_noroot = gtk_button_new_with_label("Backup ohne Root");

// Link the click callback function with the buttons
g_signal_connect(button_get_backup_root, "clicked", G_CALLBACK(get_backup_root), NULL);
g_signal_connect(button_get_backup_noroot, "clicked", G_CALLBACK(get_backup_noroot), NULL);

// Create a layout container (HBox) for the buttons
GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);

// Create a layout container (VBox) for the left and right buttons
GtkWidget *left_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 7);
GtkWidget *right_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 7);

// Add the first two buttons to the left VBox
gtk_box_pack_start(GTK_BOX(left_vbox), button_get_backup_root, TRUE, TRUE, 0);

// Add the other two buttons to the right VBox
gtk_box_pack_start(GTK_BOX(right_vbox), button_get_backup_noroot, TRUE, TRUE, 0);

// Add the left and right VBoxes to the main HBox
gtk_box_pack_start(GTK_BOX(hbox), left_vbox, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), right_vbox, TRUE, TRUE, 0);

// Add the main HBox to the main window
gtk_container_add(GTK_CONTAINER(window), hbox);

// show all button
gtk_widget_show(button_get_backup_root);
gtk_widget_show(button_get_backup_noroot);
gtk_widget_show(left_vbox);
gtk_widget_show(right_vbox);
gtk_widget_show(hbox);

// gtk main loop
gtk_main();
printf("Keine Funktion!\n");
}

// function without any function
static void start_zero_function_22(GtkWidget *widget, gpointer data)
{
printf("Keine Funktion!\n");
}

// function backup with no root
static void start_backup_noroot(GtkWidget *widget, gpointer data)
{
backup_noroot();
}

// function without any function
static void start_zero_function_23(GtkWidget *widget, gpointer data)
{
printf("Keine Funktion!\n");
}

/* main function of preflash_GUI*/
void backup_function(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *grid;
GtkWidget *button;
char button_labels[6][20] = {" ", "Backup mit Root", " ",
" ", "Backup ohne Root", " "};

gtk_init(&argc, &argv);

// create new windows
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Projekt 122 - Backup");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);

// create a grid
grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(window), grid);

// add buttons and connect them with callback
for (int i = 0; i < 6; i++) {
button = gtk_button_new_with_label(button_labels[i]);
gtk_grid_attach(GTK_GRID(grid), button, i % 3, i / 3, 1, 1);
switch (i) {
case 0:
g_signal_connect(button, "clicked", G_CALLBACK(start_zero_function_20), NULL);
break;
case 1:
g_signal_connect(button, "clicked", G_CALLBACK(start_backup_root), NULL);
break;
case 2:
g_signal_connect(button, "clicked", G_CALLBACK(start_zero_function_21), NULL);
break;
case 3:
g_signal_connect(button, "clicked", G_CALLBACK(start_zero_function_22), NULL);
break;
case 4:
g_signal_connect(button, "clicked", G_CALLBACK(start_backup_root), NULL);
break;
case 5:
g_signal_connect(button, "clicked", G_CALLBACK(start_zero_function_23), NULL);
break;
}
}

/* change the style of the buttons to quick settings buttons from android 12 - css is used for this*/
GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(provider,
"button {\n"
" background-color: #8B0000;\n" /* darkred */
" border: none;\n"
" border-radius: 12px;\n" /* round corners */
" padding: 12px 24px;\n" /* inside distance */
" color: #ffffff;\n" /* White text */
" font-size: 16px;\n" /* Font size */
" font-weight: 500;\n" /* Medium font */
" text-align: center;\n" /* Centre text */
" box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n" /* Light shade */
" transition: background-color 0.3s ease, box-shadow 0.3s ease;\n" /* Animation */
"}\n"
"button:hover {\n"
" background-color: #A52A2A;\n" /* Brighter red on hover */
" box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);\n" /* Amplify shadows */
"}\n",
-1,
NULL);
GtkStyleContext *context = gtk_widget_get_style_context(window);
gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);

// show window
gtk_widget_show_all(window);

// run main-gtk-loop
gtk_main();
}

0 comments on commit 5d99f29

Please sign in to comment.