@@ -1702,14 +1702,50 @@ static rg_gui_event_t wifi_status_cb(rg_gui_option_t *option, rg_gui_event_t eve
17021702static rg_gui_event_t wifi_manage_slot_cb (rg_gui_option_t * option , rg_gui_event_t event )
17031703{
17041704 int slot = option -> arg ;
1705+ rg_wifi_config_t config = {0 };
1706+
1707+ if (event == RG_DIALOG_INIT || event == RG_DIALOG_UPDATE || event == RG_DIALOG_ENTER )
1708+ {
1709+ rg_network_wifi_read_config (slot , & config );
1710+ strcpy (option -> value , config .ssid [0 ] ? config .ssid : _ ("(add network)" ));
1711+ }
17051712
17061713 if (event == RG_DIALOG_ENTER )
17071714 {
1708- rg_wifi_config_t config ;
1709- if (!rg_network_wifi_read_config (slot , & config ))
1715+ if (!config .ssid [0 ])
17101716 {
1711- rg_gui_alert (_ ("Error" ), _ ("No network configuration found in this slot" ));
1712- return RG_DIALOG_VOID ;
1717+ // Get SSID from user
1718+ char * ssid = rg_gui_input_str (_ ("Wi-Fi SSID" ), _ ("Enter new network name:" ), "" );
1719+ if (!ssid || strlen (ssid ) == 0 )
1720+ {
1721+ free (ssid );
1722+ return RG_DIALOG_VOID ;
1723+ }
1724+
1725+ // Get password from user
1726+ char * password = rg_gui_input_str (_ ("Wi-Fi Password" ), _ ("Enter password (leave empty for open network):" ), "" );
1727+ if (!password )
1728+ password = strdup ("" );
1729+
1730+ // Save the configuration
1731+ rg_wifi_config_t new_config = {0 };
1732+ strncpy (new_config .ssid , ssid , sizeof (new_config .ssid ) - 1 );
1733+ strncpy (new_config .password , password , sizeof (new_config .password ) - 1 );
1734+ new_config .channel = 0 ; // Auto
1735+ new_config .ap_mode = false;
1736+
1737+ free (ssid );
1738+ free (password );
1739+
1740+ if (!rg_network_wifi_write_config (slot , & new_config ))
1741+ {
1742+ rg_gui_alert (_ ("Error" ), _ ("Failed to save network configuration" ));
1743+ return RG_DIALOG_VOID ;
1744+ }
1745+
1746+ rg_settings_commit ();
1747+ config = new_config ;
1748+ // fall through, allowing the user to connect to the new network
17131749 }
17141750
17151751 char title [50 ];
@@ -1773,6 +1809,7 @@ static rg_gui_event_t wifi_manage_slot_cb(rg_gui_option_t *option, rg_gui_event_
17731809 break ;
17741810 }
17751811
1812+ strcpy (option -> value , config .ssid [0 ] ? config .ssid : _ ("(empty)" ));
17761813 return RG_DIALOG_REDRAW ;
17771814 }
17781815
@@ -1783,106 +1820,15 @@ static rg_gui_event_t wifi_manage_networks_cb(rg_gui_option_t *option, rg_gui_ev
17831820{
17841821 if (event == RG_DIALOG_ENTER )
17851822 {
1786- char slot_labels [5 ][60 ];
1787- rg_gui_option_t slot_options [6 ];
1788-
1789- for (size_t i = 0 ; i < 5 ; i ++ )
1790- {
1791- rg_wifi_config_t config ;
1792- if (rg_network_wifi_read_config (i , & config ))
1793- snprintf (slot_labels [i ], sizeof (slot_labels [i ]), "Slot %d: %.25s" , (int )i , config .ssid );
1794- else
1795- snprintf (slot_labels [i ], sizeof (slot_labels [i ]), "Slot %d: (empty)" , (int )i );
1796-
1797- slot_options [i ] = (rg_gui_option_t ){i , slot_labels [i ], NULL ,
1798- rg_network_wifi_read_config (i , & config ) ? RG_DIALOG_FLAG_NORMAL : RG_DIALOG_FLAG_DISABLED ,
1799- & wifi_manage_slot_cb };
1800- }
1801- slot_options [5 ] = (rg_gui_option_t )RG_DIALOG_END ;
1802-
1803- rg_gui_dialog (_ ("Manage Networks" ), slot_options , 0 );
1804- return RG_DIALOG_REDRAW ;
1805- }
1806- return RG_DIALOG_VOID ;
1807- }
1808-
1809- static rg_gui_event_t wifi_add_network_cb (rg_gui_option_t * option , rg_gui_event_t event )
1810- {
1811- if (event == RG_DIALOG_ENTER )
1812- {
1813- // Get SSID from user
1814- char * ssid = rg_gui_input_str (_ ("Wi-Fi SSID" ), _ ("Enter network name:" ), "" );
1815- if (!ssid || strlen (ssid ) == 0 )
1816- {
1817- free (ssid );
1818- rg_gui_alert (_ ("Error" ), _ ("SSID cannot be empty" ));
1819- return RG_DIALOG_REDRAW ;
1820- }
1821-
1822- // Get password from user
1823- char * password = rg_gui_input_str (_ ("Wi-Fi Password" ), _ ("Enter password (leave empty for open network):" ), "" );
1824- if (!password )
1825- password = strdup ("" );
1826-
1827- // Select slot to save to
1828- char slot_labels [5 ][50 ];
1829- for (size_t i = 0 ; i < 5 ; i ++ )
1830- {
1831- rg_wifi_config_t config ;
1832- if (rg_network_wifi_read_config (i , & config ))
1833- snprintf (slot_labels [i ], sizeof (slot_labels [i ]), "Slot %d: %s" , (int )i , config .ssid );
1834- else
1835- snprintf (slot_labels [i ], sizeof (slot_labels [i ]), "Slot %d: (empty)" , (int )i );
1836- }
1837-
1838- const rg_gui_option_t slot_options [] = {
1839- {0 , slot_labels [0 ], NULL , RG_DIALOG_FLAG_NORMAL , NULL },
1840- {1 , slot_labels [1 ], NULL , RG_DIALOG_FLAG_NORMAL , NULL },
1841- {2 , slot_labels [2 ], NULL , RG_DIALOG_FLAG_NORMAL , NULL },
1842- {3 , slot_labels [3 ], NULL , RG_DIALOG_FLAG_NORMAL , NULL },
1843- {4 , slot_labels [4 ], NULL , RG_DIALOG_FLAG_NORMAL , NULL },
1823+ rg_gui_option_t slot_options [] = {
1824+ {0 , _ ("Slot 0" ), "_" , RG_DIALOG_FLAG_NORMAL , & wifi_manage_slot_cb },
1825+ {1 , _ ("Slot 1" ), "_" , RG_DIALOG_FLAG_NORMAL , & wifi_manage_slot_cb },
1826+ {2 , _ ("Slot 2" ), "_" , RG_DIALOG_FLAG_NORMAL , & wifi_manage_slot_cb },
1827+ {3 , _ ("Slot 3" ), "_" , RG_DIALOG_FLAG_NORMAL , & wifi_manage_slot_cb },
1828+ {4 , _ ("Slot 4" ), "_" , RG_DIALOG_FLAG_NORMAL , & wifi_manage_slot_cb },
18441829 RG_DIALOG_END ,
18451830 };
1846-
1847- int selected_slot = rg_gui_dialog (_ ("Select Slot" ), slot_options , 0 );
1848- if (selected_slot == RG_DIALOG_CANCELLED )
1849- {
1850- free (ssid );
1851- free (password );
1852- return RG_DIALOG_REDRAW ;
1853- }
1854-
1855- // Save the configuration
1856- rg_wifi_config_t new_config = {0 };
1857- strncpy (new_config .ssid , ssid , sizeof (new_config .ssid ) - 1 );
1858- strncpy (new_config .password , password , sizeof (new_config .password ) - 1 );
1859- new_config .channel = 0 ; // Auto
1860- new_config .ap_mode = false;
1861-
1862- if (rg_network_wifi_write_config (selected_slot , & new_config ))
1863- {
1864- // Commit settings
1865- rg_settings_commit ();
1866-
1867- // Ask if user wants to connect now
1868- char confirm_msg [150 ];
1869- snprintf (confirm_msg , sizeof (confirm_msg ),
1870- "Network saved to slot %d.\n\nConnect now?" , selected_slot );
1871-
1872- if (rg_gui_confirm (_ ("Network Saved" ), confirm_msg , true))
1873- {
1874- rg_settings_set_boolean (NS_WIFI , SETTING_WIFI_ENABLE , true);
1875- rg_settings_set_number (NS_WIFI , SETTING_WIFI_SLOT , selected_slot );
1876- wifi_toggle_interactive (true, selected_slot );
1877- }
1878- }
1879- else
1880- {
1881- rg_gui_alert (_ ("Error" ), _ ("Failed to save network configuration" ));
1882- }
1883-
1884- free (ssid );
1885- free (password );
1831+ rg_gui_dialog (_ ("Manage Networks" ), slot_options , 0 );
18861832 return RG_DIALOG_REDRAW ;
18871833 }
18881834 return RG_DIALOG_VOID ;
@@ -1932,7 +1878,6 @@ static rg_gui_event_t wifi_cb(rg_gui_option_t *option, rg_gui_event_t event)
19321878 {
19331879 const rg_gui_option_t options [] = {
19341880 {0x00 , _ ("Wi-Fi enable" ), "-" , RG_DIALOG_FLAG_NORMAL , & wifi_enable_cb },
1935- {0x00 , _ ("Add new network" ), NULL , RG_DIALOG_FLAG_NORMAL , & wifi_add_network_cb },
19361881 {0x00 , _ ("Manage networks" ), NULL , RG_DIALOG_FLAG_NORMAL , & wifi_manage_networks_cb },
19371882 RG_DIALOG_SEPARATOR ,
19381883 {0x00 , _ ("Wi-Fi access point" ), NULL , RG_DIALOG_FLAG_NORMAL , & wifi_access_point_cb },
0 commit comments