00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026 #include "config.h"
00027 #include <string.h>
00028 #include <gtk/gtk.h>
00029 #include <libergtk/ergtk.h>
00030
00031 #include "connectionMgrLog.h"
00032 #include "displayStatus.h"
00033 #include "erbusy.h"
00034 #include "background.h"
00035 #include "gtkSettingItem.h"
00036 #include "gtkInfoItem.h"
00037 #include "gtkProfileGroup.h"
00038 #include "connectScreenData.h"
00039 #include "editScreen.h"
00040 #include "widgetUtils.h"
00041 #include "editScreenProfiles.h"
00042 #include "editScreenWireless.h"
00043 #include "editScreenSearch.h"
00044 #include "connectScan.h"
00045 #include "connectionMgr.h"
00046 #include "languages.h"
00047
00048 static GtkWidget *g_search = NULL;
00049 static bkWdtLabelButton *g_options = NULL;
00050 static GtkWidget *g_known_profiles = NULL;
00051 static GtkWidget *g_info = NULL;
00052
00053
00054 static networkProfile_t *g_network_profiles = NULL;
00055 static int g_n_network_profiles = 0;
00056
00057 static GtkWidget *create_known_profiles (void);
00058
00059 static void on_options_update(GtkWidget *selection,
00060 gpointer button,
00061 gpointer data);
00062 static void on_profile_entry_selected (GtkProfileGroup *profileGroup,
00063 guint profileIndex);
00064
00065 static int edit_search_get_n_network_profiles(void);
00066 static const networkProfile_t *edit_search_get_network_profile(int profileIndex);
00067 static void edit_search_destroy_network_profiles(void);
00068
00069 static void edit_search_init_network_profiles(connection_t networkType,
00070 network_spec_t *pScanNetworks,
00071 int nScanNetworks);
00072 static void edit_search_scan_networks_done(void);
00073
00074 static void edit_search_restore_scan_ctxt(void);
00075
00076
00077
00078
00079
00080
00081
00082
00083 GtkWidget *edit_search_create(void)
00084 {
00085 GtkWidget *item;
00086 GtkWidget *vbox;
00087 bkWdtLabelButton *options;
00088 GtkWidget *profilelist;
00089 GtkWidget *info;
00090 GtkWidget *widget;
00091
00092 CN_LOGPRINTF("entry");
00093
00094
00095 item = gtk_settingitem_new("");
00096
00097
00098 vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00099 gtk_settingitem_add_details(GTK_SETTINGITEM(item), vbox);
00100
00101
00102 options = bk_wdt_label_button_new(2, FALSE, 0, 1);
00103 gtk_box_pack_start(GTK_BOX(vbox), options->background, FALSE, FALSE, 0);
00104
00105
00106 profilelist = create_known_profiles();
00107 gtk_box_pack_start(GTK_BOX(vbox), profilelist, FALSE, FALSE, 0);
00108
00109
00110 info = gtk_infoitem_new(FALSE);
00111 gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
00112
00113
00114 widget = options->details->selection;
00115 g_signal_connect (G_OBJECT (widget), "selection-update",
00116 G_CALLBACK (on_options_update), NULL);
00117
00118
00119 gtk_widget_show(item);
00120 gtk_widget_show(vbox);
00121 gtk_widget_show(options->background);
00122 gtk_widget_show(profilelist);
00123 gtk_widget_show(info);
00124
00125
00126 g_search = item;
00127 g_options = options;
00128 g_info = info;
00129
00130 CN_LOGPRINTF("done");
00131
00132
00133 return item;
00134 }
00135
00136
00137
00138
00139 static GtkWidget *create_known_profiles (void)
00140 {
00141 GtkWidget* item;
00142
00143 CN_LOGPRINTF("entry");
00144
00145
00146 item = gtk_profile_group_new(MAX_PROFILES_PER_PAGE, connectMode_e);
00147 gtk_profile_group_show_dialup(GTK_PROFILE_GROUP(item), FALSE);
00148 gtk_profile_group_callback_on_buttons_clicked(GTK_PROFILE_GROUP(item),
00149 on_profile_entry_selected, NULL);
00150 g_known_profiles = item;
00151
00152 return item;
00153 }
00154
00155 void edit_search_set_text(void)
00156 {
00157 GtkProfileGroup *profileGroup;
00158 GtkWidget *widget = NULL;
00159
00160 CN_LOGPRINTF("entry");
00161
00162 if (g_search)
00163 {
00164 gtk_settingitem_set_header_text(GTK_SETTINGITEM(g_search),
00165 _("Create new wireless network"));
00166 }
00167
00168 if (g_options)
00169 {
00170 widget = g_options->details->label;
00171 gtk_label_set_text(GTK_LABEL(widget),
00172 _("Select a way to create the network."));
00173
00174 widget = GTK_WIDGET(g_options->details->buttonList[0]);
00175 gtk_button_set_label(GTK_BUTTON(widget), _("Search"));
00176
00177 widget = GTK_WIDGET(g_options->details->buttonList[1]);
00178 gtk_button_set_label(GTK_BUTTON(widget), _("Manually"));
00179 }
00180
00181 if (g_known_profiles)
00182 {
00183 profileGroup = GTK_PROFILE_GROUP(g_known_profiles);
00184 gtk_profile_group_set_header_text(profileGroup,
00185 _("Network profiles"));
00186 }
00187
00188 if (g_info)
00189 {
00190 gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00191 _("When you click on 'Search' the device will scan for networks.\n"
00192 "Clicking 'Manually' requires all the settings."));
00193 }
00194 }
00195
00196 static void edit_search_update_profilelist_info(scanStatus_t status)
00197 {
00198 GtkProfileGroup *item;
00199 char *info;
00200
00201 CN_LOGPRINTF("entry");
00202
00203 if (g_known_profiles)
00204 {
00205 item = GTK_PROFILE_GROUP(g_known_profiles);
00206 switch (status)
00207 {
00208 case scanRunning_e:
00209 info = _("Please wait while the iLiad scans "
00210 "for wireless networks ....");
00211 break;
00212 case scanAborting_e:
00213 info = _("Aborting scan ...");
00214 break;
00215 case rescanNeed_e:
00216 info = _("No wireless networks detected.");
00217 break;
00218 case scanOk_e:
00219 info = _("Please select the network you wish to create.");
00220 break;
00221 default:
00222 info = "";
00223 break;
00224 }
00225
00226 gtk_profile_group_set_info_text(item, info);
00227 }
00228 }
00229
00230 static void edit_search_display_profilelist(void)
00231 {
00232 int i, nProfiles, nDisplayed, max;
00233 GtkProfileGroup *profileGroup;
00234 const networkProfile_t *settings;
00235
00236 g_return_if_fail(g_known_profiles != NULL);
00237
00238 nProfiles = edit_search_get_n_network_profiles();
00239 max = MAX_PROFILES_PER_PAGE;
00240 nDisplayed = ((nProfiles < max) ? nProfiles: max);
00241
00242 profileGroup = GTK_PROFILE_GROUP(g_known_profiles);
00243
00244
00245 if (nDisplayed > 0)
00246 {
00247 for (i = 0; i < nDisplayed; i++)
00248 {
00249 settings = edit_search_get_network_profile(i);
00250 gtk_profile_group_display_settings(profileGroup, i,
00251 settings, TRUE);
00252 }
00253 }
00254 gtk_profile_group_show_profile_entries(profileGroup, nDisplayed);
00255 }
00256
00257 void edit_search_restore_screen(void)
00258 {
00259 GtkToggleButton *button;
00260
00261
00262 button = g_options->details->buttonList[0];
00263 gtk_toggle_button_set_active(button, FALSE);
00264
00265 button = g_options->details->buttonList[0];
00266 gtk_toggle_button_set_active(button, FALSE);
00267
00268
00269 edit_search_destroy_network_profiles();
00270 edit_search_display_profilelist();
00271 edit_search_update_profilelist_info(undefScanStatus_e);
00272 }
00273
00274 static gboolean on_delayed_search(gpointer data)
00275 {
00276 scanContext_t *ctxt;
00277
00278 erbusy_blink();
00279
00280 edit_search_restore_scan_ctxt();
00281 ctxt = cmgr_get_scan_ctxt();
00282 connect_scan(ctxt, FALSE);
00283
00284 return FALSE;
00285 }
00286
00287 static gboolean on_delayed_manually(gpointer data)
00288 {
00289 char *profilename;
00290 GtkToggleButton *button;
00291
00292 erbusy_blink();
00293
00294 edit_wireless_set_ssid("");
00295 edit_wireless_set_encrtype(encr_undefined_t);
00296
00297 profilename = edit_profiles_default_profilename();
00298 edit_wireless_set_profilename(profilename);
00299 g_free(profilename);
00300
00301
00302 edit_wireless_backup_network_settings();
00303
00304 delay_edit_wireless_determine_status();
00305
00306 edit_goto_page(editScreenWireless_e);
00307
00308
00309 button = g_options->details->buttonList[1];
00310 gtk_toggle_button_set_active(button, FALSE);
00311
00312 return FALSE;
00313 }
00314
00315 static void on_options_update(GtkWidget *selection,
00316 gpointer button,
00317 gpointer data)
00318 {
00319 erGtkSelectionGroup *item;
00320 int nsel;
00321
00322 CN_LOGPRINTF("entry");
00323
00324 item = ERGTK_SELECTION_GROUP(selection);
00325 ergtk_selection_group_get_selected_buttons(item, &nsel, 1);
00326 switch (nsel)
00327 {
00328 case 0:
00329
00330 edit_search_destroy_network_profiles();
00331 edit_search_display_profilelist();
00332 edit_search_update_profilelist_info(scanRunning_e);
00333 g_timeout_add(500, on_delayed_search, NULL);
00334 break;
00335 case 1:
00336
00337 g_timeout_add(500, on_delayed_manually, NULL);
00338 break;
00339 default:
00340 break;
00341 }
00342 }
00343
00344 static gboolean on_delayed_profile_entry_selected(gpointer data)
00345 {
00346 int profileIndex = (int)data;
00347
00348 const networkProfile_t *pNetwork = NULL;
00349 network_spec_t *pScan = NULL;
00350
00351 const gchar *ssid = "";
00352 wireless_encr_type_t encrtype = encr_undefined_t;
00353
00354 GtkProfileGroup *profileGroup;
00355
00356 CN_LOGPRINTF("entry");
00357
00358 erbusy_blink();
00359
00360 if ((profileIndex >= 0) && (profileIndex < g_n_network_profiles))
00361 {
00362 pNetwork = edit_search_get_network_profile(profileIndex);
00363 pScan = pNetwork->scanSettings;
00364
00365
00366 ssid = pScan->ssid;
00367 edit_wireless_set_ssid(ssid);
00368
00369 encrtype = pScan->encryption;
00370 edit_wireless_set_encrtype(encrtype);
00371
00372
00373 edit_wireless_set_profilename(ssid);
00374
00375
00376 edit_wireless_backup_network_settings();
00377
00378 delay_edit_wireless_determine_status();
00379
00380 edit_goto_page(editScreenWireless_e);
00381
00382 profileGroup = GTK_PROFILE_GROUP(g_known_profiles);
00383 gtk_profile_group_unselect_profile(profileGroup, profileIndex);
00384 }
00385
00386 return FALSE;
00387 }
00388
00389 static void on_profile_entry_selected (GtkProfileGroup* profileGroup,
00390 guint profileIndex)
00391 {
00392 CN_LOGPRINTF ("entry");
00393
00394
00395 g_timeout_add(500,
00396 on_delayed_profile_entry_selected,
00397 (gpointer)profileIndex);
00398 }
00399
00400 static void edit_search_restore_scan_ctxt(void)
00401 {
00402 scanContext_t *ctxt;
00403 char *ssidList;
00404
00405 CN_LOGPRINTF("entry");
00406
00407 ctxt = cmgr_get_scan_ctxt();
00408 if (ctxt)
00409 {
00410 connect_scan_ctxt_set_mode(ctxt, editScan_e);
00411 connect_scan_ctxt_set_network_type(ctxt, wireless_t);
00412 connect_scan_ctxt_set_done_callbacks(ctxt,
00413 edit_search_init_network_profiles,
00414 edit_search_scan_networks_done);
00415
00416 ssidList = connect_data_get_hidden_ssid_list();
00417 connect_scan_ctxt_set_ssidlist(ctxt, ssidList);
00418 g_free(ssidList);
00419 }
00420 }
00421
00422 static void edit_search_init_network_profiles(connection_t networkType,
00423 network_spec_t *pScanNetworks,
00424 int nScanNetworks)
00425 {
00426 int i;
00427 networkProfile_t *pNetwork;
00428
00429 CN_LOGPRINTF("entry");
00430
00431
00432 edit_search_destroy_network_profiles();
00433
00434
00435 if (pScanNetworks && (nScanNetworks != 0))
00436 {
00437 g_n_network_profiles = nScanNetworks;
00438 g_network_profiles = g_new0(networkProfile_t, nScanNetworks);
00439 g_return_if_fail(g_network_profiles != NULL);
00440
00441 for (i = 0; i < nScanNetworks; i++)
00442 {
00443 pNetwork = &g_network_profiles[i];
00444 pNetwork->scanSettings = dup_network_spec(&pScanNetworks[i]);
00445 pNetwork->regSettingsList = NULL;
00446 pNetwork->regIndexList = NULL;
00447 pNetwork->nRegProfiles = 0;
00448 pNetwork->nActiveIndex = -1;
00449 }
00450 }
00451 }
00452
00453 static void edit_search_destroy_network_profiles(void)
00454 {
00455 CN_LOGPRINTF("entry");
00456
00457 common_data_destroy_network_profiles(g_network_profiles,
00458 g_n_network_profiles);
00459 g_network_profiles = NULL;
00460 g_n_network_profiles = 0;
00461 }
00462
00463 static int edit_search_get_n_network_profiles(void)
00464 {
00465 CN_LOGPRINTF("entry [%d]", g_n_network_profiles);
00466
00467 return g_n_network_profiles;
00468 }
00469
00470 static const networkProfile_t *edit_search_get_network_profile(int profileIndex)
00471 {
00472 CN_LOGPRINTF("entry profileIndex[%d]", profileIndex);
00473
00474 networkProfile_t *ret = NULL;
00475
00476 g_return_val_if_fail(g_network_profiles != NULL, NULL);
00477 g_return_val_if_fail(profileIndex < g_n_network_profiles, NULL);
00478
00479 ret = &g_network_profiles[profileIndex];
00480
00481 CN_LOGPRINTF("ret=%p", ret);
00482
00483 return ret;
00484 }
00485
00486 static void edit_search_scan_networks_done(void)
00487 {
00488 int nProfiles;
00489 GtkToggleButton *button;
00490
00491 CN_LOGPRINTF("entry");
00492
00493 edit_search_display_profilelist();
00494
00495 nProfiles = edit_search_get_n_network_profiles();
00496 if (nProfiles > 0)
00497 {
00498
00499 edit_search_update_profilelist_info(scanOk_e);
00500 }
00501 else
00502 {
00503 edit_search_update_profilelist_info(rescanNeed_e);
00504 }
00505
00506
00507 if (g_options)
00508 {
00509 button = g_options->details->buttonList[0];
00510 gtk_toggle_button_set_active(button, FALSE);
00511 }
00512
00513 display_update_request_screen_refresh(STATUS_ITEM_CHANGE,
00514 WAVEFORM_TYPING);
00515 }
00516
00517 gboolean on_edit_search_keypress(GdkEventKey *event)
00518 {
00519 GtkToggleButton *button;
00520 gboolean ret = FALSE;
00521
00522 CN_LOGPRINTF("entry");
00523
00524 switch (event->keyval)
00525 {
00526 case GDK_Return:
00527
00528
00529 if (g_options)
00530 {
00531 button = g_options->details->buttonList[1];
00532 gtk_toggle_button_set_active(button, TRUE);
00533 }
00534 ret = TRUE;
00535 break;
00536
00537 case GDK_F5:
00538
00539
00540 cmgr_up_page();
00541 ret = TRUE;
00542 break;
00543
00544 case GDK_Down:
00545 case GDK_Up:
00546 case GDK_Page_Down:
00547 case GDK_Page_Up:
00548 default:
00549 erbusy_off();
00550 break;
00551 }
00552
00553 return ret;
00554 }
00555