diff --git a/src/Makefile b/src/Makefile index 114276e..0a16e1c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,7 +16,7 @@ GLIB_COMPILE_RESOURCES = $(shell $(PKGCONFIG) --variable=glib_compile_resources BUILT_SRC = resources.c -_OBJ = main.o ui.o h_prop.o util.o read_config.o about_ui.o $(BUILT_SRC:.c=.o) +_OBJ = main.o ui.o h_prop.o util.o read_config.o about_ui.o qr_ui.o $(BUILT_SRC:.c=.o) OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) # Determine this makefile's path. diff --git a/src/ui/glade/qr.glade b/src/ui/glade/qr.glade new file mode 100644 index 0000000..a9b4ff0 --- /dev/null +++ b/src/ui/glade/qr.glade @@ -0,0 +1,50 @@ + + + + + + False + QR code + center-on-parent + dialog + + + + + + False + vertical + 2 + + + False + end + + + + + + + + + False + False + 0 + + + + + True + False + gtk-missing-image + + + True + True + 1 + + + + + + diff --git a/src/ui/glade/wifih.gresource.xml b/src/ui/glade/wifih.gresource.xml index 98722f9..f0b1dd1 100644 --- a/src/ui/glade/wifih.gresource.xml +++ b/src/ui/glade/wifih.gresource.xml @@ -8,6 +8,10 @@ about.glade + + qr.glade + + style.css diff --git a/src/ui/glade/wifih.ui b/src/ui/glade/wifih.ui index 2dab4a8..4af0e3e 100644 --- a/src/ui/glade/wifih.ui +++ b/src/ui/glade/wifih.ui @@ -1,5 +1,5 @@ - + @@ -235,7 +235,7 @@ - No Haveged + No Haveged True True False @@ -245,7 +245,7 @@ 0 9 - + Use psk @@ -488,6 +488,15 @@ + + + + + + + + + False @@ -606,6 +615,24 @@ + + + + + + + + + + + + + + + + + + False @@ -663,6 +690,19 @@ False True 48 + 0 + + + + + Open QR + True + True + True + + + False + True 1 diff --git a/src/ui/h_prop.c b/src/ui/h_prop.c index 93c7379..53ac906 100644 --- a/src/ui/h_prop.c +++ b/src/ui/h_prop.c @@ -62,6 +62,8 @@ static char accepted_macs[BUFSIZE]; static const char* g_ssid=NULL; static const char* g_pass=NULL; +static char* qr_image_path; + //config_t cfg; static int parse_output(const char *cmd) { @@ -424,6 +426,36 @@ char** get_wifi_interface_list(int *length){ } +char* generate_qr_image(char* ssid,char* type,char *password){ + char cmd[BUFSIZE]; + + qr_image_path = "/tmp/wihotspot_qr.png"; + + snprintf(cmd, BUFSIZE, "%s -V -s 10 -d 256 -o %s 'WIFI:S:%s;T:%s;P:%s;;' ","qrencode",qr_image_path, ssid,type,password); + + FILE *fp; + + char temp_buff[1048]; + + if ((fp = popen(cmd, "r")) == NULL) { + printf("Error opening pipe!\n"); + + } + + + while (fgets(temp_buff, sizeof(temp_buff), fp) != NULL) { + + printf("%s", temp_buff); + } + + if (pclose(fp)) { + printf("Error executing qrencode\n"); + + } + + return qr_image_path; +} + Node get_connected_devices(char *PID) { char cmd[BUFSIZE]; diff --git a/src/ui/h_prop.h b/src/ui/h_prop.h index f407086..16a19e3 100644 --- a/src/ui/h_prop.h +++ b/src/ui/h_prop.h @@ -71,6 +71,8 @@ void write_accepted_macs(char* filename, char* accepted_macs); char * read_mac_filter_file(char * filename); +char* generate_qr_image(char* ssid,char* type,char *password); + Node get_connected_devices(char *PID); PtrToNode add_device_node(Node l, int number, char *line, int marker[3]); diff --git a/src/ui/qr_ui.c b/src/ui/qr_ui.c new file mode 100644 index 0000000..bacad6c --- /dev/null +++ b/src/ui/qr_ui.c @@ -0,0 +1,59 @@ +// +// Created by lakinduakash on 13/04/19. +// +/* +Copyright (c) 2021, lakinduaksh + All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + */ + + + +#include +#include "qr_ui.h" + +static GtkBuilder *builder; +static GError *error = NULL; + +void open_qr(GtkWidget *widget, gpointer root,char* image_path) { + + builder = gtk_builder_new(); + //Load ui description from built resource - need to generate compiled source with glib-compile-resource + gtk_builder_add_from_resource(builder,"/org/gtk/wihotspot/qr.glade",&error); + + root = gtk_builder_get_object(builder, "dialog_qr"); + + GtkImage* qr_image = (GtkImage *) gtk_builder_get_object(builder, "image_qr"); + + gtk_image_set_from_file(qr_image,image_path); + + GtkDialog* dialog= GTK_DIALOG(root); + + gtk_dialog_run(GTK_DIALOG(dialog)); + + gtk_widget_destroy(GTK_WIDGET( dialog)); + + g_signal_connect (dialog, "destroy", G_CALLBACK(gtk_main_quit), NULL); + +} \ No newline at end of file diff --git a/src/ui/qr_ui.h b/src/ui/qr_ui.h new file mode 100644 index 0000000..cfc8eda --- /dev/null +++ b/src/ui/qr_ui.h @@ -0,0 +1,11 @@ + +#ifndef WIHOTSPOT_UI_QR +#define WIHOTSPOT_UI_QR + + +#include + + +void open_qr(GtkWidget *widget, gpointer window,char* image_path); + +#endif \ No newline at end of file diff --git a/src/ui/ui.c b/src/ui/ui.c index ef3589b..3deb0a1 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "read_config.h" #include "util.h" #include "about_ui.h" +#include "qr_ui.h" #define BUFSIZE 512 #define AP_ENABLED "AP-ENABLED" @@ -57,6 +58,7 @@ GObject *window; GtkButton *button_create_hp; GtkButton *button_stop_hp; GtkButton *button_about; +GtkButton *button_qr; GtkButton *button_refresh; GtkGrid *grid_devices; @@ -158,10 +160,16 @@ static void on_stop_hp_clicked(GtkWidget *widget, gpointer data) { } static void on_about_open_click(GtkWidget *widget, gpointer data){ - show_info(widget,data); } +static void on_qr_open_click(GtkWidget *widget, gpointer data){ + + char* image_path = generate_qr_image(configValues.ssid,"WPA",configValues.pass); + + open_qr(widget,data,image_path); +} + static void loadStyles(){ provider = gtk_css_provider_new(); @@ -369,6 +377,7 @@ int initUi(int argc, char *argv[]){ button_create_hp = (GtkButton *) gtk_builder_get_object(builder, "button_create_hp"); button_stop_hp = (GtkButton *) gtk_builder_get_object(builder, "button_stop_hp"); button_about = (GtkButton *) gtk_builder_get_object(builder, "button_about"); + button_qr = (GtkButton *) gtk_builder_get_object(builder, "button_qr"); button_refresh = (GtkButton *)gtk_builder_get_object(builder, "button_refresh"); grid_devices = (GtkGrid *)gtk_builder_get_object(builder, "grid_devices"); @@ -416,6 +425,7 @@ int initUi(int argc, char *argv[]){ g_signal_connect (button_create_hp, "clicked", G_CALLBACK(on_create_hp_clicked), NULL); g_signal_connect (button_stop_hp, "clicked", G_CALLBACK(on_stop_hp_clicked), NULL); g_signal_connect (button_about, "clicked", G_CALLBACK(on_about_open_click), NULL); + g_signal_connect (button_qr, "clicked", G_CALLBACK(on_qr_open_click), NULL); g_signal_connect (button_refresh, "clicked", G_CALLBACK(on_refresh_clicked), NULL); g_signal_connect (cb_open, "toggled", G_CALLBACK(on_cb_open_toggle), NULL); g_signal_connect (cb_mac, "toggled", G_CALLBACK(on_cb_mac_toggle), NULL); //new