00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00037 #include "config.h"
00038
00039 #include <glib.h>
00040 #include <gtk/gtk.h>
00041
00042 #include <libergtk/ergtk.h>
00043
00044 #include "connectionMgrLog.h"
00045 #include "background.h"
00046 #include "gtkProfileEntry.h"
00047 #include "widgetUtils.h"
00048 #include "languages.h"
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 wdtLabelEntry *wdt_label_entry_new (entryFilter_e filter)
00061 {
00062 GtkWidget *vbox = NULL;
00063 GtkWidget *label = NULL;
00064 GtkWidget *hbox = NULL;
00065 GtkWidget *entry = NULL;
00066 GtkWidget *button = NULL;
00067 wdtLabelEntry *item = NULL;
00068 int spacing = 0;
00069
00070 CN_LOGPRINTF("entry filter[%d]", filter);
00071
00072
00073 vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00074
00075
00076 label = gtk_label_new("");
00077 gtk_widget_set_name(label, "info_label");
00078 gtk_widget_set_size_request(label, LABEL_WIDTH, LABEL_HEIGHT);
00079 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00080 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00081
00082
00083 spacing = SITEM_BK_WIDTH - PADDING_LEFT - PADDING_RIGHT
00084 - ENTRY_WIDTH - SBUTTON_WIDTH;
00085 hbox = gtk_hbox_new(FALSE, spacing);
00086 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00087
00088
00089 entry = ergtk_entry_new();
00090 if (filter == ipAddress_e)
00091 {
00092 ergtk_entry_set_ipv4_filter(ERGTK_ENTRY(entry));
00093 }
00094 else if (filter == integer_e)
00095 {
00096 ergtk_entry_set_integer_filter(ERGTK_ENTRY(entry));
00097 }
00098
00099 gtk_widget_set_size_request(entry, ENTRY_WIDTH, ENTRY_HEIGHT);
00100 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
00101
00102
00103 button = ergtk_toggle_button_new_with_label("");
00104 gtk_widget_set_size_request(button, SBUTTON_WIDTH, SBUTTON_HEIGHT);
00105 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
00106
00107
00108 gtk_widget_show(label);
00109 gtk_widget_show_all(hbox);
00110
00111
00112 item = g_new0(wdtLabelEntry, 1);
00113 g_assert(item != NULL);
00114 item->parent = vbox;
00115 item->label = label;
00116 item->entry = entry;
00117 item->button = button;
00118
00119
00120 return item;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 wdtLabelButton *wdt_label_button_new (int nbutton, gboolean smallButton,
00133 int minsel, int maxsel)
00134 {
00135 GtkWidget *vbox = NULL;
00136 GtkWidget *label = NULL;
00137 GtkWidget *hbox = NULL;
00138 GtkWidget *button = NULL;
00139 GtkToggleButton **buttonList = NULL;
00140 GtkWidget *selection = NULL;
00141 wdtLabelButton *item = NULL;
00142 int i;
00143 int spacing = 0, maxSpacing;
00144 int buttonWidth, buttonHeight;
00145
00146 CN_LOGPRINTF("entry nbutton[%d] smallButton[%d] minsel[%d] maxsel[%d]",
00147 nbutton, smallButton, minsel, maxsel);
00148
00149
00150 vbox = gtk_vbox_new(FALSE, VBOX_SPACING);
00151
00152
00153 label = gtk_label_new("");
00154 gtk_widget_set_name(label, "info_label");
00155 gtk_widget_set_size_request(label, LABEL_WIDTH, LABEL_HEIGHT);
00156 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00157 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00158
00159
00160 if (smallButton)
00161 {
00162 buttonWidth = SBUTTON_WIDTH;
00163 buttonHeight = SBUTTON_HEIGHT;
00164 }
00165 else
00166 {
00167 buttonWidth = BUTTON_WIDTH;
00168 buttonHeight = BUTTON_HEIGHT;
00169 }
00170
00171
00172 if (nbutton > 1)
00173 {
00174 spacing = (SITEM_BK_WIDTH - PADDING_LEFT - PADDING_RIGHT
00175 - buttonWidth * nbutton)
00176 / (nbutton -1);
00177 }
00178 maxSpacing = (SITEM_BK_WIDTH - PADDING_LEFT - PADDING_RIGHT
00179 - BUTTON_WIDTH * 3) / 2;
00180 if (spacing > maxSpacing)
00181 {
00182 spacing = maxSpacing;
00183 }
00184
00185
00186 hbox = gtk_hbox_new(FALSE, spacing);
00187 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00188
00189
00190 buttonList = g_new0(GtkToggleButton*, nbutton+1);
00191 g_assert(buttonList != NULL);
00192
00193
00194 for (i = 0; i < nbutton; i++)
00195 {
00196 button = ergtk_toggle_button_new_with_label("");
00197 gtk_widget_set_size_request(button, buttonWidth, buttonHeight);
00198 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
00199 buttonList[i] = GTK_TOGGLE_BUTTON(button);
00200 }
00201 buttonList[i] = NULL;
00202
00203
00204 selection = ergtk_selection_group_new(buttonList);
00205 ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection),
00206 minsel, maxsel);
00207
00208
00209 gtk_widget_show(label);
00210 gtk_widget_show_all(hbox);
00211
00212
00213 item = g_new0(wdtLabelButton, 1);
00214 g_assert(item != NULL);
00215
00216 item->parent = vbox;
00217 item->label = label;
00218 item->selection = selection;
00219 item->buttonList = buttonList;
00220 item->nbutton = nbutton;
00221
00222
00223 return item;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 bkWdtLabelEntry *bk_wdt_label_entry_new(entryFilter_e filter)
00235 {
00236 GtkWidget *background = NULL;
00237 GtkWidget *alignment = NULL;
00238 wdtLabelEntry *details = NULL;
00239 bkWdtLabelEntry *item = NULL;
00240
00241 CN_LOGPRINTF("entry filter[%d]", filter);
00242
00243
00244 background = gtk_event_box_new();
00245 gtk_widget_set_name(background, "bk_grey_666_75");
00246 gtk_widget_set_size_request(background,
00247 SITEM_BK_WIDTH, SITEM_BK_HEIGHT);
00248
00249
00250 alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00251 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00252 PADDING_TOP, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT);
00253 gtk_container_add(GTK_CONTAINER(background), alignment);
00254
00255
00256 details = wdt_label_entry_new(filter);
00257 g_assert(details != NULL);
00258 gtk_container_add(GTK_CONTAINER(alignment), details->parent);
00259
00260
00261 gtk_widget_show(alignment);
00262 gtk_widget_show(details->parent);
00263
00264
00265 item = g_new0(bkWdtLabelEntry, 1);
00266 g_assert(item != NULL);
00267 item->background = background;
00268 item->details = details;
00269
00270
00271 return item;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 bkWdtLabelButton *bk_wdt_label_button_new(int nbutton, gboolean smallButton,
00283 int minsel, int maxsel)
00284 {
00285 GtkWidget *background = NULL;
00286 GtkWidget *alignment = NULL;
00287 wdtLabelButton *details = NULL;
00288 bkWdtLabelButton *item = NULL;
00289
00290 CN_LOGPRINTF("entry nbutton[%d] smallButton[%d] minsel[%d] maxsel[%d]",
00291 nbutton, smallButton, minsel, maxsel);
00292
00293
00294 background = gtk_event_box_new();
00295 gtk_widget_set_name(background, "bk_grey_666_75");
00296 gtk_widget_set_size_request(background,
00297 SITEM_BK_WIDTH, SITEM_BK_HEIGHT);
00298
00299
00300 alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00301 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00302 PADDING_TOP, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT);
00303 gtk_container_add(GTK_CONTAINER(background), alignment);
00304
00305
00306 details = wdt_label_button_new(nbutton, smallButton, minsel, maxsel);
00307 g_assert(details != NULL);
00308 gtk_container_add(GTK_CONTAINER(alignment), details->parent);
00309
00310
00311 gtk_widget_show(alignment);
00312 gtk_widget_show(details->parent);
00313
00314
00315 item = g_new0(bkWdtLabelButton, 1);
00316 g_assert(item != NULL);
00317 item->background = background;
00318 item->details = details;
00319
00320
00321 return item;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 bkProfileEntry *bk_profile_entry_new(void)
00333 {
00334 GtkWidget *background = NULL;
00335 GtkWidget *alignment = NULL;
00336 GtkWidget *details = NULL;
00337 bkProfileEntry *item = NULL;
00338
00339 CN_LOGPRINTF("entry");
00340
00341
00342 background = gtk_event_box_new();
00343 gtk_widget_set_name(background, "bk_grey_666_75");
00344 gtk_widget_set_size_request(background,
00345 SITEM_BK_WIDTH, SITEM_BK_HEIGHT);
00346
00347
00348 alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
00349 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00350 PADDING_TOP, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT);
00351 gtk_container_add(GTK_CONTAINER(background), alignment);
00352
00353
00354 details = gtk_profile_entry_new();
00355 g_assert(details != NULL);
00356 gtk_container_add(GTK_CONTAINER(alignment), details);
00357
00358
00359 gtk_widget_show(alignment);
00360 gtk_widget_show(details);
00361
00362
00363 item = g_new0(bkProfileEntry, 1);
00364 g_assert(item != NULL);
00365 item->background = background;
00366 item->details = details;
00367
00368
00369 return item;
00370 }
00371
00372 void bk_profile_entry_display(const bkProfileEntry *item,
00373 const regNetworkProfile_t *settings)
00374 {
00375 GtkWidget *widget;
00376 networkProfile_t nwSettings;
00377
00378 g_return_if_fail(item != NULL);
00379 g_return_if_fail(settings != NULL);
00380
00381
00382 nwSettings.scanSettings = NULL;
00383
00384 nwSettings.regSettingsList = g_new0(regNetworkProfile_t*, 1);
00385 g_return_if_fail(nwSettings.regSettingsList != NULL);
00386
00387 nwSettings.regSettingsList[0] = (regNetworkProfile_t*)settings;
00388 nwSettings.regIndexList = NULL;
00389 nwSettings.nRegProfiles = 1;
00390 nwSettings.nActiveIndex = 0;
00391
00392 widget = item->details;
00393 gtk_profile_entry_display_settings(GTK_PROFILE_ENTRY(widget),
00394 &nwSettings, "");
00395
00396 g_free(nwSettings.regSettingsList);
00397 nwSettings.regSettingsList = NULL;
00398 }
00399
00400 void bk_profile_entry_update_status(const bkProfileEntry* item,
00401 pingStatus_t status)
00402 {
00403 gchar *text;
00404 gboolean flashing = FALSE;
00405 GtkWidget *widget;
00406
00407 g_return_if_fail(item != NULL);
00408
00409 switch (status)
00410 {
00411 case pingSucceeded_e:
00412 text = _("Connected");
00413 break;
00414 case pingFailed_e:
00415 case pingFailedPCShare_e:
00416 case pingFailedNetwork_e:
00417 text = _("Unsuccessful");
00418 break;
00419 case pingSkipped_e:
00420 text = ("Skipped");
00421 break;
00422 case pingNeedKey_e:
00423 text = _("Security key required");
00424 break;
00425 case pingAborted_e:
00426 text = _("Aborted");
00427 break;
00428 case pingAborting_e:
00429 text = _("Aborting...");
00430 flashing = TRUE;
00431 break;
00432 case pingConnecting_e:
00433 text = _("Connecting...");
00434 flashing = TRUE;
00435 break;
00436 default:
00437 text = "";
00438 break;
00439 }
00440
00441
00442 widget = item->details;
00443 gtk_profile_entry_set_status(GTK_PROFILE_ENTRY(widget), text);
00444 gtk_profile_entry_set_status_flashing(GTK_PROFILE_ENTRY(widget),
00445 flashing);
00446 }
00447