Merge pull request #200 from lakinduakash/dev

QR code
This commit is contained in:
Lakindu Akash 2021-10-16 22:18:17 +05:30 committed by GitHub
commit 5fff792b7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 213 additions and 5 deletions

View File

@ -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.

50
src/ui/glade/qr.glade Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkDialog" id="dialog_qr">
<property name="can_focus">False</property>
<property name="title" translatable="yes">QR code</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<child type="titlebar">
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_qr">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -8,6 +8,10 @@
<file preprocess="xml-stripblanks">about.glade</file>
</gresource>
<gresource prefix="/org/gtk/wihotspot">
<file preprocess="xml-stripblanks">qr.glade</file>
</gresource>
<gresource prefix="/css">
<file>style.css</file>
</gresource>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="window">
@ -235,7 +235,7 @@
</child>
<child>
<object class="GtkCheckButton" id="cb_no_haveged">
<property name="label" translatable="false">No Haveged</property>
<property name="label">No Haveged</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@ -488,6 +488,15 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -606,6 +615,24 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -663,6 +690,19 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">48</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_qr">
<property name="label" translatable="yes">Open QR</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>

View File

@ -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];

View File

@ -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]);

59
src/ui/qr_ui.c Normal file
View File

@ -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 <gtk/gtk.h>
#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);
}

11
src/ui/qr_ui.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef WIHOTSPOT_UI_QR
#define WIHOTSPOT_UI_QR
#include <gtk/gtk.h>
void open_qr(GtkWidget *widget, gpointer window,char* image_path);
#endif

View File

@ -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