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 <liberregxml/erregapi.h>
00030
00031 #include "connectionMgrLog.h"
00032 #include "connectionMgr.h"
00033 #include "displayStatus.h"
00034 #include "erbusy.h"
00035 #include "background.h"
00036 #include "gtkSettingItem.h"
00037 #include "gtkInfoItem.h"
00038 #include "editScreen.h"
00039 #include "editScreenOverview.h"
00040 #include "widgetUtils.h"
00041 #include "editScreenStatic.h"
00042 #include "languages.h"
00043
00044 typedef enum
00045 {
00046 inputAddr_e = 0,
00047 inputNetmask_e,
00048 inputGateway_e,
00049 inputDns_e,
00050 undefStatus_e
00051 }staticStatus_t;
00052
00053 static GtkWidget *g_static = NULL;
00054
00055 static wdtLabelEntry *g_address = NULL;
00056 static wdtLabelEntry *g_netmask = NULL;
00057 static wdtLabelEntry *g_gateway = NULL;
00058 static wdtLabelEntry *g_dns = NULL;
00059
00060 static GtkWidget *g_info = NULL;
00061
00062
00063 static regIpSetting_t *g_old_settings = NULL;
00064
00065 static void on_next(GtkToggleButton *button, gpointer data);
00066
00067 static void edit_static_set_address(const char *address);
00068 static void edit_static_set_netmask(const char *netmask);
00069 static void edit_static_set_gateway(const char *gateway);
00070 static void edit_static_set_dns(const char *dns);
00071
00072 static const char *edit_static_get_address(void);
00073 static const char *edit_static_get_netmask(void);
00074 static const char *edit_static_get_gateway(void);
00075 static const char *edit_static_get_dns(void);
00076
00077 static void edit_static_backup_network_settings(void);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 GtkWidget *edit_static_create(void)
00094 {
00095 GtkWidget *item;
00096 GtkWidget *topVbox;
00097 GtkWidget *background;
00098 GtkWidget *alignment;
00099 GtkWidget *vbox;
00100 wdtLabelEntry *address;
00101 wdtLabelEntry *netmask;
00102 wdtLabelEntry *gateway;
00103 wdtLabelEntry *dns;
00104 GtkWidget *info;
00105 GtkWidget *widget;
00106
00107 CN_LOGPRINTF("entry");
00108
00109
00110 item = gtk_settingitem_new("");
00111
00112
00113 topVbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00114 gtk_settingitem_add_details(GTK_SETTINGITEM(item), topVbox);
00115
00116
00117 background = gtk_event_box_new();
00118 gtk_widget_set_name(background, "bk_grey_666_273");
00119 gtk_widget_set_size_request(background,
00120 BK_666_273_WIDTH, BK_666_273_HEIGHT);
00121 gtk_box_pack_start(GTK_BOX(topVbox), background, FALSE, FALSE, 0);
00122
00123
00124 alignment = gtk_alignment_new(0.0, 0.0, 0, 0);
00125 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00126 PADDING_TOP, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT);
00127 gtk_container_add(GTK_CONTAINER(background), alignment);
00128
00129
00130 vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00131 gtk_container_add(GTK_CONTAINER(alignment), vbox);
00132
00133
00134 address = wdt_label_entry_new(ipAddress_e);
00135 gtk_box_pack_start(GTK_BOX(vbox), address->parent, FALSE, FALSE, 0);
00136
00137
00138 netmask = wdt_label_entry_new(ipAddress_e);
00139 gtk_box_pack_start(GTK_BOX(vbox), netmask->parent, FALSE, FALSE, 0);
00140
00141
00142 gateway = wdt_label_entry_new(ipAddress_e);
00143 gtk_box_pack_start(GTK_BOX(vbox), gateway->parent, FALSE, FALSE, 0);
00144
00145
00146 dns = wdt_label_entry_new(ipAddress_e);
00147 gtk_box_pack_start(GTK_BOX(vbox), dns->parent, FALSE, FALSE, 0);
00148
00149
00150 info = gtk_infoitem_new(FALSE);
00151 gtk_box_pack_start(GTK_BOX(topVbox), info, FALSE, FALSE, 0);
00152
00153
00154 widget = dns->button;
00155 g_signal_connect_after(G_OBJECT(widget), "toggled",
00156 G_CALLBACK(on_next), NULL);
00157
00158
00159 gtk_widget_show(item);
00160 gtk_widget_show(topVbox);
00161 gtk_widget_show(background);
00162 gtk_widget_show(alignment);
00163 gtk_widget_show(vbox);
00164 gtk_widget_show(address->parent);
00165 gtk_widget_hide(address->button);
00166 gtk_widget_show(netmask->parent);
00167 gtk_widget_hide(netmask->button);
00168 gtk_widget_show(gateway->parent);
00169 gtk_widget_hide(gateway->button);
00170 gtk_widget_show(dns->parent);
00171 gtk_widget_show(info);
00172
00173
00174 g_static = item;
00175 g_address = address;
00176 g_netmask = netmask;
00177 g_gateway = gateway;
00178 g_dns = dns;
00179 g_info = info;
00180
00181 CN_LOGPRINTF("done");
00182
00183
00184 return item;
00185 }
00186
00187 void edit_static_set_text(void)
00188 {
00189 GtkWidget* widget = NULL;
00190
00191 CN_LOGPRINTF("entry");
00192
00193 if (g_static)
00194 {
00195 gtk_settingitem_set_header_text(GTK_SETTINGITEM(g_static),
00196 _("Network profile"));
00197 }
00198
00199 if (g_address)
00200 {
00201 widget = g_address->label;
00202 gtk_label_set_text(GTK_LABEL(widget),
00203 _("Enter the iLiad's IP address:"));
00204 }
00205
00206 if (g_netmask)
00207 {
00208 widget = g_netmask->label;
00209 gtk_label_set_text(GTK_LABEL(widget),
00210 _("Enter the iLiad's netmask:"));
00211 }
00212
00213 if (g_gateway)
00214 {
00215 widget = g_gateway->label;
00216 gtk_label_set_text(GTK_LABEL(widget),
00217 _("Enter the default gateway's IP address:"));
00218 }
00219
00220 if (g_dns)
00221 {
00222 widget = g_dns->label;
00223 gtk_label_set_text(GTK_LABEL(widget),
00224 _("Enter the DNS name server's IP address:"));
00225
00226 widget = g_dns->button;
00227 gtk_button_set_label(GTK_BUTTON(widget), _("Next"));
00228 }
00229
00230 if (g_info)
00231 {
00232 gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00233 _("If you do not know the settings for this network, "
00234 "please ask your network administrator."));
00235 }
00236 }
00237
00238 static staticStatus_t edit_static_detect_status(void)
00239 {
00240 staticStatus_t status = undefStatus_e;
00241
00242 if (!ergtk_entry_check_field(ERGTK_ENTRY(g_address->entry)))
00243 {
00244 status = inputAddr_e;
00245 }
00246 else if (!ergtk_entry_check_field(ERGTK_ENTRY(g_netmask->entry)))
00247 {
00248 status = inputNetmask_e;
00249 }
00250 else if (!ergtk_entry_check_field(ERGTK_ENTRY(g_gateway->entry)))
00251 {
00252 status = inputGateway_e;
00253 }
00254 else if (!ergtk_entry_check_field(ERGTK_ENTRY(g_dns->entry)))
00255 {
00256 status = inputDns_e;
00257 }
00258
00259 CN_LOGPRINTF("return %d", status);
00260 return status;
00261 }
00262
00263 static void edit_static_determine_status(void)
00264 {
00265 staticStatus_t status;
00266 GtkWidget *widget = NULL;
00267
00268 status = edit_static_detect_status();
00269 switch (status)
00270 {
00271 case inputAddr_e:
00272 widget = g_address->entry;
00273 break;
00274 case inputNetmask_e:
00275 widget = g_netmask->entry;
00276 break;
00277 case inputGateway_e:
00278 widget = g_gateway->entry;
00279 break;
00280 case inputDns_e:
00281 widget = g_dns->entry;
00282 break;
00283 default:
00284 widget = g_address->entry;
00285 break;
00286 }
00287
00288 if (widget)
00289 {
00290 gtk_widget_grab_focus(widget);
00291 }
00292 }
00293
00294
00295 void edit_static_set_network_settings(const regNetworkProfile_t *settings)
00296 {
00297 gchar *profilename = NULL;
00298 gchar *address = NULL;
00299 gchar *netmask = NULL;
00300 gchar *gateway = NULL;
00301 gchar *dns = NULL;
00302 regIpSetting_t* ipSettings;
00303
00304 CN_LOGPRINTF("entry [%p]", settings);
00305
00306 g_return_if_fail(settings != NULL);
00307
00308
00309 profilename = settings->name;
00310
00311 ipSettings = settings->ipSettings;
00312 if (ipSettings)
00313 {
00314 address = ipSettings->address;
00315 netmask = ipSettings->netmask;
00316 gateway = ipSettings->gateway;
00317 dns = ipSettings->dns;
00318 }
00319
00320 edit_static_set_title(profilename);
00321 edit_static_set_address(address);
00322 edit_static_set_netmask(netmask);
00323 edit_static_set_gateway(gateway);
00324 edit_static_set_dns(dns);
00325
00326 edit_static_determine_status();
00327
00328
00329 edit_static_backup_network_settings();
00330 }
00331
00332 void edit_static_set_title(const char *profilename)
00333 {
00334 char *title = NULL;
00335
00336 CN_LOGPRINTF("entry[%s]", profilename);
00337
00338 if (g_static)
00339 {
00340 if (profilename)
00341 {
00342 title = g_strdup_printf(_("Network profile: %s/static"),
00343 profilename);
00344 }
00345 else
00346 {
00347 title = g_strdup(_("Network profile: static"));
00348 }
00349
00350 gtk_settingitem_set_header_text(GTK_SETTINGITEM(g_static), title);
00351
00352 g_free(title);
00353 }
00354 }
00355
00356 static void edit_static_set_address(const char *address)
00357 {
00358 GtkWidget *widget;
00359
00360 CN_LOGPRINTF("entry %s", address);
00361
00362 if (g_address)
00363 {
00364 widget = g_address->entry;
00365 gtk_entry_set_text(GTK_ENTRY(widget), address ? address : "");
00366 }
00367 }
00368
00369 static void edit_static_set_netmask(const char *netmask)
00370 {
00371 GtkWidget *widget;
00372
00373 CN_LOGPRINTF("entry [%s]", netmask);
00374
00375 if (g_netmask)
00376 {
00377 widget = g_netmask->entry;
00378 gtk_entry_set_text(GTK_ENTRY(widget), netmask ? netmask : "");
00379 }
00380 }
00381
00382 static void edit_static_set_gateway(const char *gateway)
00383 {
00384 GtkWidget *widget;
00385
00386 CN_LOGPRINTF("entry [%s]", gateway);
00387
00388 if (g_gateway)
00389 {
00390 widget = g_gateway->entry;
00391 gtk_entry_set_text(GTK_ENTRY(widget), gateway ? gateway : "");
00392 }
00393 }
00394
00395 static void edit_static_set_dns(const char *dns)
00396 {
00397 GtkWidget *widget;
00398
00399 CN_LOGPRINTF("entry [%s]", dns);
00400
00401 if (g_dns)
00402 {
00403 widget = g_dns->entry;
00404 gtk_entry_set_text(GTK_ENTRY(widget), dns ? dns : "");
00405 }
00406 }
00407
00408 void edit_static_get_network_settings(regNetworkProfile_t *settings)
00409 {
00410 const gchar *address, *netmask, *gateway, *dns;
00411 regIpSetting_t *ipSettings;
00412
00413 CN_LOGPRINTF("entry");
00414
00415 g_return_if_fail(settings != NULL);
00416 g_return_if_fail(settings->addressMode == static_t);
00417
00418
00419 ipSettings = settings->ipSettings;
00420 if (ipSettings)
00421 {
00422 g_free(ipSettings->address);
00423 g_free(ipSettings->netmask);
00424 g_free(ipSettings->gateway);
00425 g_free(ipSettings->dns);
00426 g_free(ipSettings);
00427 ipSettings = NULL;
00428 settings->ipSettings = NULL;
00429 }
00430
00431
00432 address = edit_static_get_address();
00433 netmask = edit_static_get_netmask();
00434 gateway = edit_static_get_gateway();
00435 dns = edit_static_get_dns();
00436
00437
00438 if (settings->addressMode == static_t)
00439 {
00440 ipSettings = g_new0(regIpSetting_t, 1);
00441 if (ipSettings)
00442 {
00443 ipSettings->address = g_strdup(address);
00444 ipSettings->netmask = g_strdup(netmask);
00445 ipSettings->gateway = g_strdup(gateway);
00446 ipSettings->dns = g_strdup(dns );
00447 }
00448 settings->ipSettings = ipSettings;
00449 }
00450 }
00451
00452 static const char *edit_static_get_address(void)
00453 {
00454 GtkWidget *widget;
00455 const char *address = NULL;
00456
00457 if (g_address)
00458 {
00459 widget = g_address->entry;
00460 address = gtk_entry_get_text(GTK_ENTRY(widget));
00461 }
00462
00463 CN_LOGPRINTF("return address=%s", address);
00464
00465 return address;
00466 }
00467
00468 static const char *edit_static_get_netmask(void)
00469 {
00470 GtkWidget *widget;
00471 const char *netmask = NULL;
00472
00473 if (g_netmask)
00474 {
00475 widget = g_netmask->entry;
00476 netmask = gtk_entry_get_text(GTK_ENTRY(widget));
00477 }
00478
00479 CN_LOGPRINTF("return netmask=%s", netmask);
00480 return netmask;
00481 }
00482
00483 static const char *edit_static_get_gateway(void)
00484 {
00485 GtkWidget *widget;
00486 const char *gateway = NULL;
00487
00488 if (g_gateway)
00489 {
00490 widget = g_gateway->entry;
00491 gateway = gtk_entry_get_text(GTK_ENTRY(widget));
00492 }
00493
00494 CN_LOGPRINTF("return gateway=%s", gateway);
00495 return gateway;
00496 }
00497
00498 static const char *edit_static_get_dns(void)
00499 {
00500 GtkWidget *widget;
00501 const char *dns = NULL;
00502
00503 if (g_dns)
00504 {
00505 widget = g_dns->entry;
00506 dns = gtk_entry_get_text(GTK_ENTRY(widget));
00507 }
00508
00509 CN_LOGPRINTF("return dns=%s", dns);
00510 return dns;
00511 }
00512
00513 gboolean edit_static_check_network_settings(void)
00514 {
00515 staticStatus_t status;
00516 gboolean valid = TRUE;
00517
00518 CN_LOGPRINTF("entry");
00519
00520 status = edit_static_detect_status();
00521 if (status != undefStatus_e)
00522 {
00523 valid = FALSE;
00524 }
00525
00526 CN_LOGPRINTF("return valid=%d", valid);
00527 return valid;
00528 }
00529
00530
00531
00532 static void edit_static_backup_network_settings(void)
00533 {
00534 const char *address, *netmask, *gateway, *dns;
00535
00536 CN_LOGPRINTF("entry");
00537
00538 address = edit_static_get_address();
00539 netmask = edit_static_get_netmask();
00540 gateway = edit_static_get_gateway();
00541 dns = edit_static_get_dns();
00542
00543 if (g_old_settings)
00544 {
00545 g_free(g_old_settings->address);
00546 g_free(g_old_settings->netmask);
00547 g_free(g_old_settings->gateway);
00548 g_free(g_old_settings->dns);
00549 g_free(g_old_settings);
00550 }
00551
00552 g_old_settings = g_new0(regIpSetting_t, 1);
00553 g_assert(g_old_settings != NULL);
00554 g_old_settings->address = g_strdup(address);
00555 g_old_settings->netmask = g_strdup(netmask);
00556 g_old_settings->gateway = g_strdup(gateway);
00557 g_old_settings->dns = g_strdup(dns);
00558 }
00559
00560 void edit_static_restore_network_settings(void)
00561 {
00562 char *address = NULL;
00563 char *netmask = NULL;
00564 char *gateway = NULL;
00565 char *dns = NULL;
00566
00567 CN_LOGPRINTF("entry");
00568
00569 if (g_old_settings)
00570 {
00571 address = g_old_settings->address;
00572 netmask = g_old_settings->netmask;
00573 gateway = g_old_settings->gateway;
00574 dns = g_old_settings->dns;
00575 }
00576
00577 edit_static_set_address(address);
00578 edit_static_set_netmask(netmask);
00579 edit_static_set_gateway(gateway);
00580 edit_static_set_dns(dns);
00581 }
00582
00583 void edit_static_screen_leave(void)
00584 {
00585 gboolean valid = TRUE;
00586
00587 CN_LOGPRINTF("entry");
00588
00589 valid = edit_static_check_network_settings();
00590
00591
00592 if (!valid)
00593 {
00594 edit_overview_set_address(dhcp_t);
00595 }
00596 }
00597
00598
00599 static gboolean on_delayed_next(gpointer data)
00600 {
00601 gboolean valid;
00602 GtkToggleButton *button;
00603
00604 erbusy_blink();
00605
00606 valid = edit_static_check_network_settings();
00607 if (valid)
00608 {
00609
00610 edit_static_backup_network_settings();
00611
00612 edit_goto_page(editScreenOverview_e);
00613 edit_overview_update_info_text(inputProxy_e);
00614 }
00615 else
00616 {
00617 edit_static_determine_status();
00618 }
00619
00620 button = GTK_TOGGLE_BUTTON(data);
00621 gtk_toggle_button_set_active(button, FALSE);
00622
00623 return FALSE;
00624 }
00625
00626 static void on_next(GtkToggleButton *button, gpointer data)
00627 {
00628 gboolean active;
00629
00630 CN_LOGPRINTF("entry");
00631
00632 active = gtk_toggle_button_get_active(button);
00633 if (active)
00634 {
00635 g_timeout_add(500, on_delayed_next, button);
00636 }
00637 }
00638
00639
00640 gboolean on_edit_static_keypress(GdkEventKey *event)
00641 {
00642 GtkToggleButton *button;
00643 gboolean ret = FALSE;
00644
00645 CN_LOGPRINTF("entry");
00646
00647 switch (event->keyval)
00648 {
00649 case GDK_Return:
00650
00651
00652 if (g_dns)
00653 {
00654 button = GTK_TOGGLE_BUTTON(g_dns->button);
00655 gtk_toggle_button_set_active(button, TRUE);
00656 }
00657 ret = TRUE;
00658 break;
00659
00660 case GDK_F5:
00661
00662
00663 cmgr_up_page();
00664 ret = TRUE;
00665 break;
00666
00667 case GDK_Down:
00668 case GDK_Up:
00669
00670 erbusy_off();
00671 ret = TRUE;
00672
00673 default:
00674 erbusy_off();
00675 break;
00676 }
00677
00678 return ret;
00679 }
00680