Refcator and fix warnings in connecetd devices

This commit is contained in:
Lakindu Akash 2021-09-12 15:29:29 +05:30
parent 4cc946b5fe
commit af913a0968
No known key found for this signature in database
GPG Key ID: 6FB0085A614E0AC2
2 changed files with 70 additions and 47 deletions

View File

@ -60,11 +60,11 @@ GtkButton *button_about;
GtkButton *button_refresh;
GtkGrid *grid_devices;
GtkWidget *h;
GtkWidget *i;
GtkWidget *m;
GtkWidget *n;
PtrToNode l;
GtkWidget *label_cd_hostname;
GtkWidget *label_cd_ip;
GtkWidget *label_cd_mac;
GtkWidget *label_cd_number;
PtrToNode device_list;
GtkEntry *entry_ssd;
GtkEntry *entry_pass;
@ -161,48 +161,6 @@ static void on_about_open_click(GtkWidget *widget, gpointer data){
show_info(widget,data);
}
static void set_connected_devices_label()
{
Position tmp;
l = get_connected_devices(running_info[0]); // running_info[0] PID
// Remove all the children widgets
GList *children, *iter;
children = gtk_container_get_children(GTK_CONTAINER(grid_devices));
for (iter = children; iter != NULL; iter = g_list_next(iter))
{
gtk_widget_destroy(GTK_WIDGET(iter->data));
}
g_list_free(children);
while (l->Next != NULL)
{
tmp = l; // Save the last one
l = l->Next;
char number[1];
sprintf(number, "%d", l->Number);
n = gtk_label_new(number);
h = gtk_label_new(l->HOSTNAME);
i = gtk_label_new(l->IP);
m = gtk_label_new(l->MAC);
gtk_grid_attach(grid_devices, n, 0, l->Number, 1, 1);
gtk_grid_attach(grid_devices, h, 1, l->Number, 1, 1);
gtk_grid_attach(grid_devices, i, 2, l->Number, 1, 1);
gtk_grid_attach(grid_devices, m, 3, l->Number, 1, 1);
gtk_widget_show_all((GtkWidget *)grid_devices);
free(tmp); // Free the last pointer
}
}
static void on_refresh_clicked(GtkWidget *widget, gpointer data)
{
if (running_info[0] != NULL)
{
set_connected_devices_label();
}
}
static void loadStyles(){
provider = gtk_css_provider_new();
@ -919,4 +877,65 @@ gchar* get_accepted_macs(){
return accepted_macs;
}
/**
* Clear device list
*/
static void clear_connecetd_devices_list(){
// Remove all the children widgets
GList *children, *iter;
children = gtk_container_get_children(GTK_CONTAINER(grid_devices));
for (iter = children; iter != NULL; iter = g_list_next(iter))
{
gtk_widget_destroy(GTK_WIDGET(iter->data));
}
g_list_free(children);
}
/**
* Set connected device list
*
*/
static void set_connected_devices_label()
{
Position tmp;
device_list = get_connected_devices(running_info[0]); // running_info[0] PID
clear_connecetd_devices_list();
while (device_list->Next != NULL)
{
tmp = device_list; // Save the last one
device_list = device_list->Next;
char number[2];
sprintf(number, "%d", device_list->Number);
label_cd_number = gtk_label_new(number);
label_cd_hostname = gtk_label_new(device_list->HOSTNAME);
label_cd_ip = gtk_label_new(device_list->IP);
label_cd_mac = gtk_label_new(device_list->MAC);
gtk_grid_attach(grid_devices, label_cd_number, 0, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_hostname, 1, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_ip, 2, device_list->Number, 1, 1);
gtk_grid_attach(grid_devices, label_cd_mac, 3, device_list->Number, 1, 1);
gtk_widget_show_all((GtkWidget *)grid_devices);
free(tmp); // Free the last pointer
}
}
/**
* When conncetd devices refresh button clicked
*/
static void on_refresh_clicked(GtkWidget *widget, gpointer data)
{
if (running_info[0] != NULL)
{
set_connected_devices_label();
}
else {
clear_connecetd_devices_list();
}
}

View File

@ -72,4 +72,8 @@ gchar* get_accepted_macs();
static void set_connected_devices_label(); // new
static void on_refresh_clicked(GtkWidget *widget, gpointer data);
static void clear_connecetd_devices_list();
#endif //WIHOTSPOT_UI_H