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 #include "connectionMgrLog.h"
00031 #include "displayStatus.h"
00032 #include "background.h"
00033 #include "connectionMgr.h"
00034 #include "gtkSettingItem.h"
00035 #include "gtkInfoItem.h"
00036 #include "widgetUtils.h"
00037 #include "editScreen.h"
00038 #include "editScreenDialup.h"
00039 #include "editScreenOverview.h"
00040 #include "connectScreenData.h"
00041 #include "connectPing.h"
00042 #include "erbusy.h"
00043 #include "languages.h"
00044 
00045 typedef enum
00046 {
00047     inputPhone_e = 0,
00048     inputUser_e,
00049     inputPassword_e,
00050     dialupInputProfileName_e,
00051     dialupConnecting_e,
00052     dialupSucceeded_e,
00053     dialupFailed_e,
00054     dialupAborting_e,
00055     dialupAborted_e,
00056     undefStatus_e
00057 }dialupStatus_t;
00058 
00059 GtkWidget *g_dialup = NULL;
00060 
00061 wdtLabelEntry *g_phone = NULL;
00062 wdtLabelEntry *g_user = NULL;
00063 wdtLabelEntry *g_password = NULL;
00064 
00065 bkWdtLabelEntry  *g_profilename = NULL;
00066 bkWdtLabelButton *g_buttons = NULL;
00067 
00068 GtkWidget *g_info = NULL;
00069 
00070 
00071 static regDialupSetting_t *g_old_settings = NULL;
00072 static char *g_old_profilename = NULL;
00073 
00074 static GtkWidget *create_settings(void);
00075 
00076 static void edit_dialup_update_info_text(dialupStatus_t status);
00077 
00078 static void edit_dialup_set_phone(const char *phone); 
00079 static void edit_dialup_set_user(const char *user);
00080 static void edit_dialup_set_password(const char *password);
00081  
00082 static const char *edit_dialup_get_password(void);
00083 static const char *edit_dialup_get_user(void);
00084 static const char *edit_dialup_get_phone(void);
00085 
00086 static void edit_dialup_backup_network_settings(void);
00087 
00088 static void on_changed(GtkEntry *widget, gpointer data);
00089 static void on_next(GtkToggleButton *button, gpointer data);
00090 static void on_buttons_update(GtkWidget *selection, 
00091                               gpointer button, 
00092                               gpointer data);
00093 
00094 static gboolean delayed_deactive_button(gpointer data);
00095 
00096 static void on_test(void);
00097 static void on_save(void);
00098 static void on_saveconnect(void);
00099 
00100 static void edit_dialup_restore_ping_ctxt(void);
00101 
00102 static void on_connected(int profileIndex);
00103 static void on_failed(void);
00104 static void ui_update_status(int profileIndex, pingStatus_t status);
00105 static void ui_display_settings(int profileIndex, gboolean resetStatus);
00106 static void ui_select_profile(int profileIndex);
00107 static void ui_unselect_all_profile(void);
00108 
00109 static void edit_dialup_freeze_ui(gboolean freeze);
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 GtkWidget *edit_dialup_create(void)
00121 {
00122     GtkWidget *item = NULL;
00123     GtkWidget *vbox = NULL;
00124     GtkWidget *settings = NULL;
00125     bkWdtLabelEntry *profilename = NULL;
00126     bkWdtLabelButton *buttons = NULL;
00127     GtkWidget *info = NULL;
00128     GtkWidget *widget = NULL;
00129 
00130     CN_LOGPRINTF("entry");
00131 
00132     
00133     item = gtk_settingitem_new("");
00134  
00135     
00136     vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00137     gtk_settingitem_add_details(GTK_SETTINGITEM(item), vbox);
00138 
00139     
00140     settings = create_settings();
00141     gtk_box_pack_start(GTK_BOX(vbox), settings, FALSE, FALSE, 0);
00142 
00143     
00144     profilename = bk_wdt_label_entry_new(string_e);
00145     gtk_box_pack_start(GTK_BOX(vbox), profilename->background, 
00146                        FALSE, FALSE, 0);
00147    
00148     
00149     buttons = bk_wdt_label_button_new(3, FALSE, 0, 1);
00150     gtk_box_pack_start(GTK_BOX(vbox), buttons->background, FALSE, FALSE, 0);
00151 
00152     
00153     info = gtk_infoitem_new(FALSE);
00154     gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0);
00155 
00156     
00157     widget = profilename->details->entry;
00158     g_signal_connect_after(G_OBJECT(widget), "changed-stable", 
00159                G_CALLBACK(on_changed), (gpointer)dialupInputProfileName_e);
00160     widget = profilename->details->button;
00161     g_signal_connect_after(G_OBJECT(widget), "toggled", 
00162                            G_CALLBACK(on_next), NULL);
00163    
00164     widget = buttons->details->selection;
00165     g_signal_connect(G_OBJECT(widget), "selection-update",
00166                      G_CALLBACK(on_buttons_update), NULL);
00167 
00168     
00169     gtk_widget_show(vbox);
00170     gtk_widget_show(settings);
00171     gtk_widget_show(profilename->background);
00172     gtk_widget_show(buttons->background);
00173     gtk_widget_show(info);
00174     gtk_widget_show(item);
00175 
00176     
00177     g_dialup = item;
00178     g_profilename = profilename;
00179     g_buttons = buttons;
00180     g_info = info;
00181 
00182     CN_LOGPRINTF("done");
00183 
00184     
00185     return item;
00186 }
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 static GtkWidget *create_settings(void)
00197 {
00198     GtkWidget *background = NULL;
00199     GtkWidget *alignment = NULL;
00200     GtkWidget *vbox = NULL;
00201     wdtLabelEntry *phone = NULL;
00202     wdtLabelEntry *user = NULL;
00203     wdtLabelEntry *password = NULL;
00204     GtkWidget *widget = NULL;
00205 
00206     CN_LOGPRINTF("entry");
00207 
00208     
00209     background = gtk_event_box_new();
00210     gtk_widget_set_name(background, "bk_grey_666_245");
00211     gtk_widget_set_size_request(background, 
00212             BK_666_245_WIDTH, BK_666_245_HEIGHT);
00213 
00214     
00215     alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00216     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00217             PADDING_TOP, PADDING_BOTTOM, PADDING_LEFT,PADDING_RIGHT);
00218     gtk_container_add(GTK_CONTAINER(background), alignment);
00219 
00220     
00221     vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00222     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00223     
00224     
00225     phone = wdt_label_entry_new(string_e);
00226     gtk_box_pack_start(GTK_BOX(vbox), phone->parent, FALSE, FALSE, 0); 
00227     
00228     
00229     user = wdt_label_entry_new(string_e);
00230     gtk_box_pack_start(GTK_BOX(vbox), user->parent, FALSE, FALSE, 0);
00231     
00232     
00233     password = wdt_label_entry_new(string_e);
00234     gtk_box_pack_start(GTK_BOX(vbox), password->parent, FALSE, FALSE, 0);
00235 
00236     
00237     widget = phone->entry;
00238     g_signal_connect_after(G_OBJECT(widget), "changed-stable", 
00239                            G_CALLBACK(on_changed), (gpointer)inputPhone_e);
00240     widget = user->entry;
00241     g_signal_connect_after(G_OBJECT(widget), "changed-stable", 
00242                            G_CALLBACK(on_changed), (gpointer)inputUser_e);
00243     widget = password->entry;
00244     g_signal_connect_after(G_OBJECT(widget), "changed-stable", 
00245                        G_CALLBACK(on_changed), (gpointer)inputPassword_e);
00246         
00247     
00248     gtk_widget_show(alignment);
00249     gtk_widget_show(vbox);
00250     gtk_widget_show(phone->parent);
00251     gtk_widget_hide(phone->button);
00252     gtk_widget_show(user->parent);
00253     gtk_widget_hide(user->button);
00254     gtk_widget_show(password->parent);
00255     gtk_widget_hide(password->button);
00256 
00257     
00258     g_phone = phone;
00259     g_user = user;
00260     g_password = password;
00261 
00262     
00263     return background;
00264 }
00265 
00266 void edit_dialup_enable_save_button(gboolean enable)
00267 {
00268     GtkWidget *widget;
00269 
00270     CN_LOGPRINTF("entry %d", enable);
00271     
00272     if (g_buttons)
00273     {
00274         widget = GTK_WIDGET(g_buttons->details->buttonList[1]);
00275         gtk_widget_set_sensitive(widget, enable);
00276     }
00277 }
00278 
00279 void edit_dialup_set_text(void)
00280 {
00281     GtkWidget *widget = NULL;
00282 
00283     CN_LOGPRINTF("entry");
00284 
00285     if (g_dialup)
00286     {
00287         gtk_settingitem_set_header_text(GTK_SETTINGITEM(g_dialup),
00288                                         _("Network profile"));
00289     }
00290 
00291     if (g_phone)
00292     {
00293         widget = g_phone->label;
00294         gtk_label_set_text(GTK_LABEL(widget), 
00295                 _("Type the phone number which you get from your ISP:"));
00296     }
00297    
00298     if (g_user)
00299     {
00300         widget = g_user->label;
00301         gtk_label_set_text(GTK_LABEL(widget), _("Type your username:"));
00302     }
00303     
00304     if (g_password)
00305     {
00306         widget = g_password->label;
00307         gtk_label_set_text(GTK_LABEL(widget), _("Type your password:"));
00308     }
00309     
00310     if (g_profilename)
00311     {
00312         widget = g_profilename->details->label;
00313         gtk_label_set_text(GTK_LABEL(widget), 
00314                            _("You can personalize the profile name."));
00315         widget = g_profilename->details->button;
00316         gtk_button_set_label(GTK_BUTTON(widget), _("Next"));
00317     }
00318 
00319     if (g_buttons)
00320     {
00321         widget = g_buttons->details->label;
00322         gtk_label_set_text(GTK_LABEL(widget),
00323             _("Select an action for this profile."));
00324 
00325        widget = GTK_WIDGET(g_buttons->details->buttonList[0]);
00326        gtk_button_set_label(GTK_BUTTON(widget), _("Test"));
00327        widget = GTK_WIDGET(g_buttons->details->buttonList[1]);
00328        gtk_button_set_label(GTK_BUTTON(widget), _("Save"));
00329        widget = GTK_WIDGET(g_buttons->details->buttonList[2]);
00330        gtk_button_set_label(GTK_BUTTON(widget), _("Save & Connect"));
00331     }
00332 }
00333 
00334 static void edit_dialup_update_info_text(dialupStatus_t status)
00335 {
00336     CN_LOGPRINTF("entry");
00337 
00338     g_return_if_fail(g_info != NULL);
00339 
00340     switch (status)
00341     {
00342         case inputPhone_e:
00343         case inputUser_e:
00344         case inputPassword_e:
00345             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconInfo_e); 
00346             gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00347                     _("If you do not know the settings for this network, "
00348                       "please ask your Internet Service Provider "
00349                       "for detailed information."));
00350             break;
00351         case dialupInputProfileName_e:
00352         case undefStatus_e:
00353             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconInfo_e); 
00354             gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00355                 _("If you personalize the profile name, "
00356                   "it will be easy to recognize "
00357                   "in the iLiad's network profile list.\n"
00358                   "Click 'Next' for more advanced settings."));
00359             break;
00360         case dialupConnecting_e:
00361             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconInfo_e); 
00362             gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00363                 _("The iLiad is trying to connect to the server."));
00364             break;
00365         case dialupSucceeded_e:
00366             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconOk_e); 
00367             gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00368                     _("Connection to the server established."));
00369              break;
00370         case dialupFailed_e:
00371             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconFailed_e); 
00372             gtk_infoitem_set_text(GTK_INFOITEM(g_info),
00373                     _("Connection to server "
00374                       "can not been established correctly."));
00375            break;
00376         case dialupAborting_e:
00377             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconInfo_e); 
00378             gtk_infoitem_set_text(GTK_INFOITEM(g_info), 
00379                 _("The iLiad is aborting the connection."));
00380             break;
00381         case dialupAborted_e:
00382             gtk_infoitem_set_icon(GTK_INFOITEM(g_info), iconInfo_e);
00383             gtk_infoitem_set_text(GTK_INFOITEM(g_info), 
00384                 _("The connection has been aborted."));
00385             break;
00386  
00387         default:
00388             break;
00389     }
00390 }
00391 
00392 
00393 static dialupStatus_t edit_dialup_detect_status(void)
00394 {
00395     erGtkEntry *phone, *user, *password, *profilename;
00396     dialupStatus_t status = undefStatus_e;
00397 
00398     CN_LOGPRINTF("entry");
00399 
00400     phone = ERGTK_ENTRY(g_phone->entry);
00401     user = ERGTK_ENTRY(g_user->entry);
00402     password = ERGTK_ENTRY(g_password->entry);
00403     profilename = ERGTK_ENTRY(g_profilename->details->entry);
00404 
00405     if (!ergtk_entry_check_field(phone))
00406     {
00407         status = inputPhone_e;
00408     }
00409     else if (!ergtk_entry_check_field(user))
00410     {
00411         status = inputUser_e;
00412     }
00413     else if (!ergtk_entry_check_field(password))
00414     {
00415         status = inputPassword_e;
00416     }
00417     else if (!ergtk_entry_check_field(profilename))
00418     {
00419         status = inputProfileName_e;
00420     }
00421 
00422     CN_LOGPRINTF("return %d", status);
00423     return status;
00424 }
00425 
00426 static void edit_dialup_determine_status(void)
00427 {
00428     dialupStatus_t status;
00429     GtkWidget *widget = NULL;
00430 
00431     status = edit_dialup_detect_status();
00432     switch (status)
00433     {
00434         case inputPhone_e:
00435             widget = g_phone->entry;
00436             break;
00437         case inputUser_e:
00438             widget = g_user->entry;
00439             break;
00440         case inputPassword_e:
00441             widget = g_password->entry;
00442             break;
00443         case inputProfileName_e:
00444         case undefStatus_e:
00445             widget = g_profilename->details->entry;
00446             break;
00447         default:
00448             break;
00449     }
00450     
00451     if (widget)
00452     {
00453         gtk_widget_grab_focus(widget);
00454     }
00455 
00456     edit_dialup_update_info_text(status);
00457 }
00458 
00459 void edit_dialup_set_network_settings(const regNetworkProfile_t *settings)
00460 {
00461     regDialupSetting_t *dialupSettings = NULL;
00462     char *phone = "";
00463     char *user = "";
00464     char *password = "";
00465     char *profilename = "";
00466 
00467     CN_LOGPRINTF("entry [%p]", settings);
00468 
00469     g_return_if_fail(settings != NULL);
00470     g_return_if_fail(settings->connection == dialup_t);
00471 
00472     
00473     profilename = settings->name;
00474     dialupSettings = settings->dialupSettings;
00475     if (dialupSettings)
00476     {
00477         phone = dialupSettings->phone;
00478         user = dialupSettings->user;
00479         password = dialupSettings->password;
00480     }
00481 
00482     
00483     edit_dialup_set_phone(phone);
00484     edit_dialup_set_user(user);
00485     edit_dialup_set_password(password);
00486     edit_dialup_set_profilename(profilename);
00487 
00488     edit_dialup_determine_status();
00489 
00490     
00491     edit_dialup_backup_network_settings();
00492 }
00493 
00494 static void edit_dialup_backup_network_settings(void) 
00495 {
00496     const char *phone, *user, *password, *profilename;
00497 
00498     CN_LOGPRINTF("entry");
00499 
00500     phone = edit_dialup_get_phone();
00501     user = edit_dialup_get_user();
00502     password = edit_dialup_get_password();
00503     profilename = edit_dialup_get_profilename();
00504 
00505     if (g_old_settings)
00506     {
00507         g_free(g_old_settings->phone);
00508         g_free(g_old_settings->user);
00509         g_free(g_old_settings->password);
00510         g_free(g_old_settings);
00511     }
00512 
00513     g_old_settings = g_new0(regDialupSetting_t, 1);
00514     g_assert(g_old_settings != NULL);
00515     g_old_settings->phone = g_strdup(phone);
00516     g_old_settings->user = g_strdup(user);
00517     g_old_settings->password = g_strdup(password);
00518     
00519     g_free(g_old_profilename);
00520     g_old_profilename = g_strdup(profilename);
00521 }
00522 
00523 static void edit_dialup_set_phone(const char *phone) 
00524 {
00525     GtkWidget *widget;
00526 
00527     CN_LOGPRINTF("entry [%s]", phone);
00528 
00529     if (g_phone)
00530     {
00531         widget = g_phone->entry;
00532         gtk_entry_set_text(GTK_ENTRY(widget), phone ? phone : ""); 
00533     }
00534 }
00535 
00536 static void edit_dialup_set_user(const char* user)
00537 {
00538     GtkWidget *widget;
00539 
00540     CN_LOGPRINTF("entry [%s]", user);
00541 
00542     if (g_user)
00543     {
00544         widget = g_user->entry;
00545         gtk_entry_set_text(GTK_ENTRY(widget), user ? user : "");
00546     }
00547 } 
00548 
00549 static void edit_dialup_set_password(const char *password)
00550 {
00551     GtkWidget *widget;
00552 
00553     CN_LOGPRINTF("entry [%s]", password);
00554 
00555     if (g_password)
00556     {
00557         widget = g_password->entry;
00558         gtk_entry_set_text(GTK_ENTRY(widget), password ? password : "");
00559     }
00560 }
00561 
00562 void edit_dialup_set_profilename(const char *profilename)
00563 {
00564     GtkWidget *widget;
00565 
00566     CN_LOGPRINTF("entry [%s]", profilename);
00567 
00568     if (g_profilename)
00569     {
00570         widget = g_profilename->details->entry;
00571         gtk_entry_set_text(GTK_ENTRY(widget), 
00572                            profilename ? profilename: "");
00573     }
00574 }
00575 
00576 void edit_dialup_get_network_settings(regNetworkProfile_t *settings)
00577 {
00578     regDialupSetting_t *dialupSettings;
00579     const gchar *phone, *user, *password, *profilename;
00580 
00581     CN_LOGPRINTF("entry [%p]", settings);
00582 
00583     g_return_if_fail(settings != NULL);
00584     g_return_if_fail(settings->connection == dialup_t);
00585 
00586     
00587     dialupSettings = settings->dialupSettings;
00588     if (dialupSettings)
00589     {
00590         g_free(dialupSettings->phone);
00591         g_free(dialupSettings->user);
00592         g_free(dialupSettings->password);
00593         g_free(dialupSettings);
00594         dialupSettings = NULL;
00595         settings->dialupSettings = NULL;
00596     }
00597    
00598     
00599     if (settings->connection == dialup_t)
00600     {
00601         profilename = edit_dialup_get_profilename();
00602         g_free(settings->name);
00603         settings->name = g_strdup(profilename);
00604 
00605         dialupSettings = g_new0(regDialupSetting_t, 1);
00606         if (dialupSettings)
00607         {
00608             phone = edit_dialup_get_phone();
00609             user = edit_dialup_get_user();
00610             password = edit_dialup_get_password();
00611 
00612             dialupSettings->phone = g_strdup(phone);
00613             dialupSettings->user = g_strdup(user);
00614             dialupSettings->password = g_strdup(password);
00615            
00616             settings->dialupSettings = dialupSettings;
00617         }
00618     }
00619 }
00620 
00621 static const char *edit_dialup_get_phone(void)
00622 {
00623     GtkWidget *widget;
00624     const char *phone = NULL;
00625 
00626     if (g_phone)
00627     {
00628         widget = g_phone->entry;
00629         phone = gtk_entry_get_text(GTK_ENTRY(widget));
00630     }
00631 
00632     CN_LOGPRINTF("return phone=%s", phone);
00633     return phone;
00634 }
00635 
00636 static const char *edit_dialup_get_user(void)
00637 {
00638     GtkWidget *widget;
00639     const char *user = NULL;
00640 
00641     if (g_user)
00642     {
00643         widget = g_user->entry;
00644         user = gtk_entry_get_text(GTK_ENTRY(widget));
00645     }
00646 
00647     CN_LOGPRINTF("return user=%s", user);
00648     return user;
00649 }
00650 
00651 static const char *edit_dialup_get_password(void)
00652 {
00653     GtkWidget *widget;
00654     const char *password = NULL;
00655 
00656     if (g_password)
00657     {
00658         widget = g_password->entry;
00659         password = gtk_entry_get_text(GTK_ENTRY(widget));
00660     }
00661 
00662     CN_LOGPRINTF("return password[%s]", password);
00663     return password;
00664 }
00665 
00666 const char *edit_dialup_get_profilename(void)
00667 {
00668     GtkWidget *widget;
00669     const char *profilename = NULL;
00670 
00671     if (g_profilename)
00672     {
00673         widget = g_profilename->details->entry;
00674         profilename = gtk_entry_get_text(GTK_ENTRY(widget));
00675     }
00676 
00677     CN_LOGPRINTF("return profilename=%s", profilename);
00678     return profilename;
00679 }
00680 
00681 gboolean edit_dialup_check_network_settings(void)
00682 {
00683     dialupStatus_t status;
00684     gboolean valid = TRUE;
00685 
00686     CN_LOGPRINTF("entry");
00687 
00688     status = edit_dialup_detect_status();
00689     if ((status != inputUser_e)
00690         && (status != inputPassword_e)
00691         && (status != undefStatus_e))
00692     {
00693         valid = FALSE;
00694     }
00695 
00696     CN_LOGPRINTF("return valid=%d", valid);
00697     return valid;
00698 }
00699 
00700 void edit_dialup_restore_network_settings(void)
00701 {
00702     char *phone = NULL;
00703     char *user = NULL;
00704     char *password = NULL;
00705     char *profilename = NULL; 
00706     
00707     CN_LOGPRINTF("entry");
00708      
00709     if (g_old_settings)
00710     {
00711        phone = g_old_settings->phone;
00712        user = g_old_settings->user;
00713        password = g_old_settings->password;
00714     }
00715     if (g_old_profilename)
00716     {
00717         profilename = g_old_profilename;
00718     }
00719     
00720     edit_dialup_set_phone(phone);
00721     edit_dialup_set_user(user);
00722     edit_dialup_set_password(password);
00723     edit_dialup_set_profilename(profilename);
00724 
00725 }
00726 
00727 
00728 static void on_changed(GtkEntry *widget, gpointer data)
00729 {
00730     CN_LOGPRINTF("entry");
00731 
00732     dialupStatus_t status = (dialupStatus_t)data;
00733     edit_dialup_update_info_text(status);
00734     if (status == inputProfileName_e)
00735     {
00736         edit_overview_update_profile();
00737     }
00738 }
00739 
00740 static gboolean on_delayed_next(gpointer data)
00741 {
00742     CN_LOGPRINTF("entry");
00743     
00744     erbusy_blink();
00745 
00746     edit_dialup_backup_network_settings();
00747 
00748     edit_goto_page(editScreenOverview_e);
00749     edit_overview_update_info_text(inputProxy_e);
00750     edit_overview_update_profile();
00751 
00752     return FALSE;
00753 }
00754 
00755 static void on_next(GtkToggleButton *button, gpointer data)
00756 {
00757     gboolean active;
00758     gboolean valid;
00759 
00760     CN_LOGPRINTF("entry");
00761 
00762     active = gtk_toggle_button_get_active(button);
00763     if (active)
00764     {
00765         valid = edit_dialup_check_network_settings();
00766         if (valid)
00767         {
00768             g_timeout_add(500, on_delayed_next, NULL);
00769         }
00770         else
00771         {
00772             edit_dialup_determine_status();
00773         }
00774 
00775         
00776         g_timeout_add(500, delayed_deactive_button, button);
00777     }
00778 }
00779 
00780 static gboolean delayed_deactive_button(gpointer data)
00781 {
00782     GtkToggleButton *button = GTK_TOGGLE_BUTTON(data);
00783     
00784     if (button)
00785     {
00786         gtk_toggle_button_set_active(button, FALSE);
00787     }
00788 
00789     return FALSE;
00790 }
00791 
00792 static void on_buttons_update(GtkWidget *selection, 
00793                               gpointer button, 
00794                               gpointer data)
00795 {
00796     gboolean   active;
00797     gboolean   valid;
00798     int        nsel;
00799     GtkWidget  *widget;
00800     erGtkSelectionGroup *sel;
00801     gboolean toDeactive = TRUE;
00802 
00803     CN_LOGPRINTF("entry");
00804 
00805     active = gtk_toggle_button_get_active(button);
00806     valid = edit_dialup_check_network_settings();
00807     if (!valid)
00808     {
00809         edit_dialup_determine_status();
00810     }
00811 
00812     if (active && valid)
00813     {
00814         widget = g_buttons->details->selection;
00815         sel = ERGTK_SELECTION_GROUP(widget);
00816         ergtk_selection_group_get_selected_buttons(sel, &nsel, 1);
00817 
00818         switch (nsel)
00819         {
00820             case 0:
00821                 
00822                 on_test();
00823                 toDeactive = FALSE;
00824                 break;
00825             case 1:
00826                 
00827                 on_save();
00828                 toDeactive = FALSE;
00829                 break;
00830             case 2:
00831                 
00832                 on_saveconnect();
00833                 toDeactive = FALSE;
00834                 break;
00835             default:
00836                 break;
00837         }
00838     }
00839 
00840     if (active && toDeactive)
00841     {
00842         g_timeout_add(500, delayed_deactive_button, button);
00843     }
00844 }
00845 
00846 static gboolean on_delayed_test(gpointer data)
00847 {
00848     GtkToggleButton *button;
00849 
00850     CN_LOGPRINTF("entry");
00851 
00852     erbusy_blink();
00853 
00854     edit_dialup_backup_network_settings();
00855 
00856     edit_overview_update_profile();
00857     edit_goto_page(editScreenOverview_e);
00858     
00859     edit_overview_click_test();
00860    
00861     if (g_buttons)
00862     {
00863         button = g_buttons->details->buttonList[0];
00864         gtk_toggle_button_set_active(button, FALSE);
00865     }
00866 
00867     return FALSE;
00868 }
00869 
00870 static void on_test(void)
00871 {
00872     CN_LOGPRINTF("entry");
00873 
00874     g_timeout_add(500, on_delayed_test, NULL);
00875 }
00876 
00877 static gboolean on_delayed_save(gpointer data)
00878 {
00879     GtkToggleButton *button;
00880 
00881     CN_LOGPRINTF("entry");
00882 
00883     erbusy_blink();
00884 
00885     edit_save_profile();
00886     edit_goto_page(editScreenProfiles_e);
00887 
00888     if (g_buttons)
00889     {
00890         button = g_buttons->details->buttonList[1];
00891         gtk_toggle_button_set_active(button, FALSE);
00892     }
00893 
00894     return FALSE;
00895 }
00896 
00897 static void on_save(void)
00898 {
00899     CN_LOGPRINTF("entry");
00900 
00901     g_timeout_add(500, on_delayed_save, NULL);
00902 }
00903 
00904 static void on_saveconnect(void)
00905 {
00906     pingContext_t *ctxt;
00907 
00908     CN_LOGPRINTF("entry");
00909 
00910     edit_dialup_freeze_ui(TRUE);
00911 
00912     edit_dialup_restore_ping_ctxt();
00913 
00914     ctxt = cmgr_get_ping_ctxt();
00915     if (ctxt)
00916     {
00917         connect_ping_select_initial_profile(ctxt);
00918         connect_ping(ctxt, TRUE);
00919     }
00920 }
00921 
00922 static void edit_dialup_restore_ping_ctxt(void)
00923 {
00924     pingContext_t *ctxt;
00925     cmgrConnectType_t connectType;
00926 
00927     CN_LOGPRINTF("entry");
00928     
00929     ctxt = cmgr_get_ping_ctxt();
00930     if (ctxt)
00931     {
00932         
00933         connect_ping_ctxt_set_mode(ctxt, editPing_e);
00934         connectType = connect_data_get_connect_type();
00935         connect_ping_ctxt_set_connect_type(ctxt, connectType);
00936         
00937         
00938         connect_ping_ctxt_set_done_callbacks(ctxt, on_connected, on_failed);
00939        
00940         
00941         connect_ping_ctxt_set_get_initial_profile(ctxt, 
00942                         edit_get_initial_profile);
00943         connect_ping_ctxt_set_access_network_profiles_callbacks(ctxt,
00944                                         edit_get_n_network_profiles,
00945                                         edit_get_network_profile,
00946                                         edit_select_next_regprofile);
00947 
00948         
00949         connect_ping_ctxt_set_ui_callbacks(ctxt, 
00950                                     ui_update_status, 
00951                                     ui_display_settings,
00952                                     ui_select_profile,
00953                                     ui_unselect_all_profile);
00954     }
00955 }
00956 
00957 static void on_connected(int profileIndex)
00958 {
00959     GtkToggleButton *button;
00960 
00961     CN_LOGPRINTF("entry");
00962   
00963     edit_dialup_freeze_ui(FALSE);
00964 
00965     if (g_buttons)
00966     {
00967         button = g_buttons->details->buttonList[2];
00968         g_timeout_add(500, delayed_deactive_button, button);
00969     }
00970 
00971     edit_save_profile();
00972 
00973     edit_on_connected();    
00974 }
00975 
00976 static void on_failed(void)
00977 {
00978     GtkToggleButton *button;
00979 
00980     CN_LOGPRINTF("entry");
00981 
00982     edit_dialup_freeze_ui(FALSE);
00983 
00984     if (g_buttons)
00985     {
00986         button = g_buttons->details->buttonList[2];
00987         g_timeout_add(500, delayed_deactive_button, button);
00988     }
00989 }
00990 
00991 static void ui_update_status(int profileIndex, pingStatus_t status)
00992 {
00993     dialupStatus_t state;
00994 
00995     CN_LOGPRINTF("entry");
00996 
00997     switch (status)
00998     {
00999         case pingSucceeded_e:
01000             state = dialupSucceeded_e;
01001             break;
01002         case pingFailed_e:
01003         case pingFailedPCShare_e:
01004         case pingFailedNetwork_e:
01005             state = dialupFailed_e;
01006             break;
01007         case pingConnecting_e:
01008             state = dialupConnecting_e;
01009             break;
01010         case pingAborting_e:
01011             state = dialupAborting_e;
01012             break;
01013         case pingAborted_e:
01014             state = dialupAborted_e;
01015             on_failed();
01016             break;
01017         default:
01018             state = undefStatus_e;
01019             break;
01020     }
01021 
01022     edit_dialup_update_info_text(state);
01023 
01024     display_update_request_screen_refresh(STATUS_ITEM_CHANGE, 
01025                                           WAVEFORM_TYPING);
01026 }
01027 
01028 static void ui_display_settings(int profileIndex, gboolean resetStatus)
01029 {
01030     CN_LOGPRINTF("entry");
01031     
01032 }
01033 
01034 static void ui_select_profile(int profileIndex)
01035 {
01036     CN_LOGPRINTF("entry");
01037     
01038 }
01039 
01040 static void ui_unselect_all_profile(void)
01041 {
01042     CN_LOGPRINTF("entry");
01043     
01044 }
01045 
01046 gboolean on_edit_dialup_keypress(GdkEventKey *event)
01047 {
01048     pingContext_t *ctxt;
01049     GtkToggleButton *button;
01050     gboolean ret = FALSE;
01051 
01052     CN_LOGPRINTF("entry");
01053     
01054     ctxt = cmgr_get_ping_ctxt();
01055     switch (event->keyval)
01056     {
01057         case GDK_Return:
01058             
01059             if (!connect_ping_in_pinging(ctxt))
01060             {
01061                 
01062                 if (g_buttons)
01063                 {
01064                     button = GTK_TOGGLE_BUTTON(g_buttons->details->buttonList[2]);
01065                     gtk_toggle_button_set_active(button, TRUE);
01066                 }
01067                 ret = TRUE;
01068             }
01069             break;
01070 
01071         case GDK_F5:
01072             
01073             
01074             connect_ping_abort(ctxt);
01075             cmgr_up_page();
01076             ret = TRUE;
01077             break;
01078         case GDK_Down:
01079         case GDK_Up:
01080             
01081             erbusy_off();
01082             ret = TRUE;
01083             break;
01084         default:
01085             erbusy_off();
01086             break;
01087     }
01088 
01089     return ret;
01090 }
01091 
01093 
01095 
01096 static void edit_dialup_freeze_ui(gboolean freeze)
01097 {
01098     editMode_t mode;
01099     gboolean sensitive;
01100     GtkWidget *widget;
01101 
01102     CN_LOGPRINTF("entry[%d]", freeze);
01103 
01104     sensitive = !freeze;
01105 
01106     
01107     widget = g_phone->entry;
01108     gtk_widget_set_sensitive(widget, sensitive);
01109     
01110     widget = g_user->entry;
01111     gtk_widget_set_sensitive(widget, sensitive);
01112     
01113     widget = g_password->entry;
01114     gtk_widget_set_sensitive(widget, sensitive);
01115 
01116     
01117     widget = g_profilename->details->entry;
01118     gtk_widget_set_sensitive(widget, sensitive);
01119 
01120     widget = g_profilename->details->button;
01121     gtk_widget_set_sensitive(widget, sensitive);
01122     
01123     
01124     widget = GTK_WIDGET(g_buttons->details->buttonList[0]);
01125     gtk_widget_set_sensitive(widget, sensitive);
01126     
01127     widget = GTK_WIDGET(g_buttons->details->buttonList[1]);
01128     gtk_widget_set_sensitive(widget, sensitive);
01129 
01130     widget = GTK_WIDGET(g_buttons->details->buttonList[2]);
01131     gtk_widget_set_sensitive(widget, sensitive);
01132  
01133     if (sensitive)
01134     {
01135         
01136         
01137         mode = edit_get_mode();
01138         if ((mode == editModeConnectFillIn_e)
01139             || (mode == editModeConnectCreate_e)
01140             || (mode == editModeConnectNormal_e))
01141         {
01142             edit_dialup_enable_save_button(FALSE);
01143         }
01144     }
01145 }
01146