mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-24 21:20:12 +00:00
Move ui related function to ui.c
This commit is contained in:
parent
6fbcc78a12
commit
4e3bef5d2e
@ -7,7 +7,7 @@ include_directories(${GTK_INCLUDE_DIRS})
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
add_executable(wihotspot ui/main.c ui/h_prop.c ui/h_prop.h)
|
||||
add_executable(wihotspot ui/main.c ui/h_prop.c ui/h_prop.h ui/ui.c ui/ui.h)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES} "pthread")
|
||||
|
||||
|
@ -16,7 +16,11 @@
|
||||
|
||||
char cmd[BUFSIZE];
|
||||
|
||||
int parse_output(char *cmd) {
|
||||
const char* SSID;
|
||||
const char* PASS;
|
||||
|
||||
|
||||
static int parse_output(char *cmd) {
|
||||
|
||||
char buf[BUFSIZE];
|
||||
FILE *fp;
|
||||
@ -51,4 +55,6 @@ char *build_command(char *iface_src, char *iface_dest, char *ssid, char *pass) {
|
||||
|
||||
int startShell(char *cmd) {
|
||||
parse_output(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef WIHOTSPOT_H_PROP_H
|
||||
#define WIHOTSPOT_H_PROP_H
|
||||
|
||||
int parse_output(char *);
|
||||
static int parse_output(char *);
|
||||
char * build_command(char*, char*,char*, char*);
|
||||
int startShell(char*);
|
||||
|
||||
|
@ -1,84 +1,13 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "h_prop.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
typedef struct {
|
||||
GtkEntry *ssid;
|
||||
GtkEntry *pass;
|
||||
} WIData;
|
||||
|
||||
|
||||
void *threadFunc(void *args) {
|
||||
startShell(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *stopHp() {
|
||||
startShell("sudo create_ap --stop ap0");
|
||||
}
|
||||
|
||||
static void on_create_hp_clicked(GtkWidget *widget,
|
||||
gpointer data) {
|
||||
|
||||
WIData *d = (WIData *) data;
|
||||
g_thread_new("shell", threadFunc, build_command("wlp3s0", "wlp3s0", (char *) gtk_entry_get_text(d->ssid),
|
||||
(char *) gtk_entry_get_text(d->pass)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
g_thread_new("shell2", stopHp, NULL);
|
||||
|
||||
}
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
GtkBuilder *builder;
|
||||
GObject *window;
|
||||
GtkButton *button_create_hp;
|
||||
GtkButton *button_stop_hp;
|
||||
GtkEntry *entry_ssd;
|
||||
GtkEntry *entry_pass;
|
||||
GError *error = NULL;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
builder = gtk_builder_new();
|
||||
if (gtk_builder_add_from_file(builder, "glade/wifih.ui", &error) == 0) {
|
||||
g_printerr("Error loading file: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Connect signal handlers to the constructed widgets. */
|
||||
window = gtk_builder_get_object(builder, "window");
|
||||
g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
|
||||
entry_ssd = (GtkEntry *) gtk_builder_get_object(builder, "entry_ssid");
|
||||
entry_pass = (GtkEntry *) gtk_builder_get_object(builder, "entry_pass");
|
||||
|
||||
|
||||
WIData wiData = {
|
||||
.pass= entry_pass,
|
||||
.ssid= entry_ssd
|
||||
};
|
||||
|
||||
button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp");
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), &wiData);
|
||||
|
||||
button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp");
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
|
||||
gtk_main();
|
||||
|
||||
initUi(argc,argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
87
src/ui/ui.c
Normal file
87
src/ui/ui.c
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Created by lakinduakash on 13/04/19.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "h_prop.h"
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
GtkEntry *ssid;
|
||||
GtkEntry *pass;
|
||||
} WIData;
|
||||
|
||||
|
||||
void *threadFunc(void *args) {
|
||||
startShell(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *stopHp() {
|
||||
startShell("sudo create_ap --stop ap0");
|
||||
}
|
||||
|
||||
static void on_create_hp_clicked(GtkWidget *widget,
|
||||
gpointer data) {
|
||||
|
||||
WIData *d = (WIData *) data;
|
||||
g_thread_new("shell", threadFunc, build_command("wlp3s0", "wlp3s0", (char *) gtk_entry_get_text(d->ssid),
|
||||
(char *) gtk_entry_get_text(d->pass)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) {
|
||||
g_thread_new("shell2", stopHp, NULL);
|
||||
|
||||
}
|
||||
|
||||
int initUi(int argc, char *argv[]){
|
||||
GtkBuilder *builder;
|
||||
GObject *window;
|
||||
GtkButton *button_create_hp;
|
||||
GtkButton *button_stop_hp;
|
||||
GtkEntry *entry_ssd;
|
||||
GtkEntry *entry_pass;
|
||||
GError *error = NULL;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
builder = gtk_builder_new();
|
||||
if (gtk_builder_add_from_file(builder, "glade/wifih.ui", &error) == 0) {
|
||||
g_printerr("Error loading file: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Connect signal handlers to the constructed widgets. */
|
||||
window = gtk_builder_get_object(builder, "window");
|
||||
g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
|
||||
entry_ssd = (GtkEntry *) gtk_builder_get_object(builder, "entry_ssid");
|
||||
entry_pass = (GtkEntry *) gtk_builder_get_object(builder, "entry_pass");
|
||||
|
||||
|
||||
WIData wiData = {
|
||||
.pass= entry_pass,
|
||||
.ssid= entry_ssd
|
||||
};
|
||||
|
||||
button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp");
|
||||
g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), &wiData);
|
||||
|
||||
button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp");
|
||||
g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL);
|
||||
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
10
src/ui/ui.h
Normal file
10
src/ui/ui.h
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by lakinduakash on 13/04/19.
|
||||
//
|
||||
|
||||
#ifndef WIHOTSPOT_UI_H
|
||||
#define WIHOTSPOT_UI_H
|
||||
|
||||
int initUi(int argc, char *argv[]);
|
||||
|
||||
#endif //WIHOTSPOT_UI_H
|
Loading…
Reference in New Issue
Block a user