00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00030 #include <gtk/gtk.h>
00031 #include <gdk/gdkkeysyms.h>
00032
00033 #include <liberdm/display.h>
00034 #include <libergtk/ergtk.h>
00035
00036 #include "connectionMgrLog.h"
00037 #include "displayStatus.h"
00038 #include "gtkSettingItem.h"
00039 #include "gtkProfileEntry.h"
00040 #include "gtkProfileGroup.h"
00041 #include "background.h"
00042 #include "erbusy.h"
00043
00044
00045 static void gtk_profile_group_class_init(GtkProfileGroupClass * klass);
00046 static void gtk_profile_group_init(GtkProfileGroup * profileGroup);
00047 static void gtk_profile_group_create(GtkProfileGroup * profileGroup,
00048 int nProfiles, profileGroupMode_t mode);
00049
00050
00051 static GtkWidget *create_list(GtkProfileGroup* profileGroup);
00052
00053
00054 static gboolean on_profile_group_name_button_press(GtkWidget* button,
00055 GdkEventButton* event,
00056 gpointer data);
00057 static gboolean on_profile_group_edit_button_press(GtkWidget* button,
00058 GdkEventButton* event,
00059 gpointer data);
00060
00061 static void on_profile_group_selection_update(erGtkSelectionGroup *selection,
00062 gpointer button,
00063 gpointer data);
00064
00065
00066 GtkWidget *gtk_profile_group_new(int nProfiles, profileGroupMode_t mode)
00067 {
00068 GtkProfileGroup *profileGroup = NULL;
00069
00070 profileGroup = (GtkProfileGroup*)g_object_new(GTK_PROFILE_GROUP_TYPE,
00071 NULL);
00072 gtk_profile_group_create(profileGroup, nProfiles, mode);
00073
00074 return GTK_WIDGET(profileGroup);
00075 }
00076
00077 void gtk_profile_group_set_mode(GtkProfileGroup* profileGroup,
00078 profileGroupMode_t mode)
00079 {
00080 CN_LOGPRINTF("entry");
00081
00082 profileGroupMode_t oldMode;
00083
00084 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00085 g_return_if_fail((mode >= 0) && (mode < modeUndef_e));
00086
00087 if (mode == deleteMode_e)
00088 {
00089 oldMode = gtk_profile_group_get_mode(profileGroup);
00090 if (oldMode == editMode_e)
00091 {
00092 profileGroup->mode = mode;
00093 }
00094 }
00095 else
00096 {
00097 profileGroup->mode = mode;
00098 }
00099 }
00100
00101 profileGroupMode_t gtk_profile_group_get_mode(GtkProfileGroup* profileGroup)
00102 {
00103 CN_LOGPRINTF("entry");
00104
00105 profileGroupMode_t mode = modeUndef_e;
00106
00107 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(profileGroup), mode);
00108
00109 mode = profileGroup->mode;
00110
00111 return mode;
00112 }
00113
00114
00115 GType gtk_profile_group_get_type(void)
00116 {
00117 static GType profile_group_type = 0;
00118
00119 if (!profile_group_type)
00120 {
00121 static const GTypeInfo profile_group_info = {
00122 sizeof(GtkProfileGroupClass),
00123 NULL,
00124 NULL,
00125 (GClassInitFunc) gtk_profile_group_class_init,
00126 NULL,
00127 NULL,
00128 sizeof(GtkProfileGroup),
00129 0,
00130 (GInstanceInitFunc) gtk_profile_group_init,
00131 0
00132 };
00133
00134 profile_group_type = g_type_register_static(GTK_TYPE_EVENT_BOX,
00135 "ProfileGroup",
00136 &profile_group_info,
00137 0);
00138 }
00139
00140 return profile_group_type;
00141 }
00142
00143
00144 static void gtk_profile_group_class_init(GtkProfileGroupClass * klass)
00145 {
00146
00147 }
00148
00149 static void gtk_profile_group_init(GtkProfileGroup * profileGroup)
00150 {
00151 CN_LOGPRINTF("entry");
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 static void gtk_profile_group_create(GtkProfileGroup *profileGroup,
00169 int nProfiles,
00170 profileGroupMode_t mode)
00171 {
00172 CN_LOGPRINTF("entry");
00173
00174 GtkWidget* item;
00175 GtkWidget* background;
00176 GtkWidget* alignment;
00177 GtkWidget* vbox;
00178 GtkWidget* dialup;
00179 GtkWidget* dialupLabel;
00180 GtkWidget* dialupSigHbox;
00181 GtkWidget* dialupSigImage;
00182 GtkWidget* label;
00183 GtkWidget* list;
00184
00185 CN_LOGPRINTF("nProfiles[%d] mode[%d]", nProfiles, mode);
00186
00187 g_return_if_fail((mode == editMode_e) || (mode == connectMode_e));
00188
00189
00190 profileGroup->nProfiles = nProfiles;
00191 profileGroup->mode = mode;
00192
00193
00194 item = gtk_settingitem_new("");
00195 gtk_container_add(GTK_CONTAINER(profileGroup), item);
00196 gtk_widget_show(item);
00197
00198
00199 background = gtk_event_box_new();
00200 gtk_widget_set_name(background, "profile_group_background");
00201 gtk_widget_set_size_request(background,
00202 PROFILE_GROUP_WIDTH,
00203 PROFILE_GROUP_HEIGHT);
00204 gtk_settingitem_add_details(GTK_SETTINGITEM(item), background);
00205 gtk_widget_show(background);
00206
00207
00208 alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00209 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
00210 PROFILE_GROUP_PADDING_TOP,
00211 PROFILE_GROUP_PADDING_BOTTOM,
00212 PROFILE_GROUP_PADDING_LEFT,
00213 PROFILE_GROUP_PADDING_RIGHT);
00214 gtk_container_add(GTK_CONTAINER(background), alignment);
00215 gtk_widget_show(alignment);
00216
00217
00218 vbox = gtk_vbox_new(FALSE, PROFILE_GROUP_SPACING);
00219 gtk_container_add(GTK_CONTAINER(alignment), vbox);
00220 gtk_widget_show(vbox);
00221
00222
00223 dialup = gtk_vbox_new(FALSE, PROFILE_GROUP_DIALUP_SPACING);
00224 gtk_box_pack_start(GTK_BOX(vbox), dialup, FALSE, FALSE, 0);
00225
00226
00227 dialupLabel = gtk_label_new("");
00228 gtk_widget_set_name (dialupLabel, "profile_group_info_text");
00229 gtk_widget_set_size_request(dialupLabel,
00230 (-1), PROFILE_GROUP_DIALUP_LABEL_HEIGHT);
00231 gtk_label_set_justify (GTK_LABEL(dialupLabel), GTK_JUSTIFY_LEFT);
00232 gtk_misc_set_alignment(GTK_MISC(dialupLabel), 0.0, 0.0);
00233 gtk_box_pack_start (GTK_BOX (dialup), dialupLabel, FALSE, FALSE, 0);
00234 gtk_widget_show(dialupLabel);
00235
00236
00237 dialupSigHbox = gtk_hbox_new(FALSE, 0);
00238 gtk_widget_set_size_request(GTK_WIDGET(dialupSigHbox),
00239 PROFILE_GROUP_DIALUP_SIGIMG_WIDTH,
00240 PROFILE_GROUP_DIALUP_SIGIMG_HEIGHT);
00241 gtk_box_pack_start(GTK_BOX(dialup), dialupSigHbox, FALSE, FALSE, 0);
00242 gtk_widget_show(dialupSigHbox);
00243
00244
00245 int i;
00246 char bgStyle[] = "profile_entry_signal0_background";
00247 for (i = 0; i < 5; i++)
00248 {
00249 dialupSigImage = gtk_event_box_new();
00250 gtk_widget_set_size_request(GTK_WIDGET(dialupSigImage),
00251 PROFILE_GROUP_DIALUP_SIGIMG_WIDTH,
00252 PROFILE_GROUP_DIALUP_SIGIMG_HEIGHT);
00253 snprintf(bgStyle, sizeof(bgStyle),
00254 "profile_entry_signal%d_background", i);
00255 gtk_widget_set_name(GTK_WIDGET(dialupSigImage), bgStyle);
00256 gtk_box_pack_start(GTK_BOX(dialupSigHbox), dialupSigImage,
00257 FALSE, FALSE, 0);
00258 profileGroup->dialupSigImage[i] = dialupSigImage;
00259 }
00260
00261
00262 label = gtk_label_new("");
00263 gtk_widget_set_name (label, "profile_group_info_text");
00264 gtk_widget_set_size_request(GTK_WIDGET(label),
00265 PROFILE_GROUP_INFO_WIDTH,
00266 (-1) );
00267 gtk_label_set_justify (GTK_LABEL(label), GTK_JUSTIFY_LEFT);
00268 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
00269 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
00270 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
00271 gtk_widget_show(label);
00272
00273
00274 list = create_list(profileGroup);
00275 gtk_box_pack_start(GTK_BOX(vbox), list, FALSE, FALSE, 0);
00276 gtk_widget_show(list);
00277
00278
00279 profileGroup->item = item;
00280 profileGroup->background = background;
00281 profileGroup->infoLabel = label;
00282
00283 profileGroup->dialup = dialup;
00284 profileGroup->dialupLabel = dialupLabel;
00285 profileGroup->dialupSigHbox = dialupSigHbox;
00286
00287
00288
00289 CN_LOGPRINTF("done");
00290 }
00291
00292
00293
00294
00295
00296 static GtkWidget *create_list (GtkProfileGroup* profileGroup)
00297 {
00298 GtkWidget *vbox;
00299 GtkWidget *profile;
00300 GtkWidget *selection;
00301 GtkWidget *nameButton, *editButton;
00302 GtkToggleButton **button_tbl;
00303 GtkProfileEntry **profileEntries;
00304 int i;
00305
00306
00307 CN_LOGPRINTF("profileGroup->nProfiles=%d", profileGroup->nProfiles);
00308 profileEntries = g_new0(GtkProfileEntry*, profileGroup->nProfiles);
00309 g_assert(profileEntries != NULL);
00310 button_tbl = g_new0(GtkToggleButton*, (profileGroup->nProfiles+1));
00311 g_assert(button_tbl != NULL);
00312
00313
00314 vbox = gtk_vbox_new(FALSE, PROFILE_GROUP_ENTRY_SPACING);
00315
00316
00317 for (i = 0; i < profileGroup->nProfiles; i++)
00318 {
00319 profile = gtk_profile_entry_new ();
00320 gtk_box_pack_start (GTK_BOX (vbox), profile, FALSE, FALSE, 0);
00321 profileEntries[i] = GTK_PROFILE_ENTRY(profile);
00322
00323 editButton = gtk_profile_entry_get_editbutton(profileEntries[i]);
00324 nameButton = gtk_profile_entry_get_namebutton(profileEntries[i]);
00325 g_signal_connect(G_OBJECT(nameButton), "button-press-event",
00326 G_CALLBACK(on_profile_group_name_button_press), profileGroup);
00327 g_signal_connect(G_OBJECT(editButton), "button-press-event",
00328 G_CALLBACK(on_profile_group_edit_button_press), profileGroup);
00329
00330
00331 if (profileGroup->mode == editMode_e)
00332 {
00333 gtk_profile_entry_show_edit_button(profileEntries[i], TRUE);
00334 button_tbl[i] = GTK_TOGGLE_BUTTON (editButton);
00335 }
00336 else
00337 {
00338 gtk_profile_entry_show_edit_button(profileEntries[i], FALSE);
00339 button_tbl[i] = GTK_TOGGLE_BUTTON (nameButton);
00340 }
00341 }
00342
00343
00344 button_tbl[profileGroup->nProfiles] = NULL;
00345 selection = ergtk_selection_group_new (button_tbl);
00346 ergtk_selection_group_set_details(ERGTK_SELECTION_GROUP(selection),
00347 0, 1);
00348
00349 g_signal_connect (G_OBJECT (selection), "selection-update",
00350 G_CALLBACK (on_profile_group_selection_update), profileGroup);
00351
00352
00353 g_free(button_tbl);
00354 button_tbl = NULL;
00355
00356
00357 profileGroup->profileEntries = profileEntries;
00358 profileGroup->selection = selection;
00359 profileGroup->nDisplayed = 0;
00360
00361 return vbox;
00362 }
00363
00364
00365 void gtk_profile_group_set_info_text(GtkProfileGroup * profileGroup,
00366 gchar * infoText)
00367 {
00368 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00369
00370 if (infoText)
00371 {
00372 CN_LOGPRINTF("infoLabel [%s]", infoText);
00373
00374 gtk_label_set_text(GTK_LABEL(profileGroup->infoLabel), infoText);
00375 gtk_widget_show(profileGroup->infoLabel);
00376 }
00377 }
00378
00379
00380 void gtk_profile_group_set_header_text(GtkProfileGroup * profileGroup,
00381 gchar * headerText)
00382 {
00383 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00384
00385 if (headerText)
00386 {
00387 CN_LOGPRINTF("headerLabel [%s]", headerText);
00388
00389 gtk_settingitem_set_header_text(GTK_SETTINGITEM(profileGroup->item),
00390 headerText);
00391 }
00392 }
00393
00394 void gtk_profile_group_set_dialup_text(GtkProfileGroup *profileGroup,
00395 gchar* text)
00396 {
00397 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00398
00399 if (text)
00400 {
00401 CN_LOGPRINTF("text [%s]", text);
00402 gtk_label_set_text(GTK_LABEL(profileGroup->dialupLabel), text);
00403 }
00404 }
00405
00406 void gtk_profile_group_set_editbuttons_text(GtkProfileGroup *profileGroup,
00407 gchar* editText)
00408 {
00409 int i;
00410 GtkProfileEntry* profileEntry;
00411
00412 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00413
00414 if (editText)
00415 {
00416 CN_LOGPRINTF("editButton [%s]", editText);
00417
00418 for ( i= 0; i < profileGroup->nProfiles; i++)
00419 {
00420 profileEntry = profileGroup->profileEntries[i];
00421 gtk_profile_entry_set_editbutton_text(profileEntry, editText);
00422 }
00423 }
00424 }
00425
00426
00427 gint gtk_profile_group_get_selected_profile_index(GtkProfileGroup *profileGroup)
00428 {
00429 guint profileIndex;
00430 erGtkSelectionGroup *selection;
00431
00432 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(profileGroup), -1);
00433 g_return_val_if_fail(ERGTK_IS_SELECTION_GROUP(profileGroup->selection), -1);
00434
00435 selection = ERGTK_SELECTION_GROUP(profileGroup->selection);
00436 ergtk_selection_group_get_selected_buttons(selection, &profileIndex, 1);
00437 if ((profileIndex >= 0) && (profileIndex < profileGroup->nDisplayed))
00438 {
00439 CN_LOGPRINTF("profileIndex=%d", profileIndex);
00440 return profileIndex;
00441 }
00442 else
00443 {
00444 return (-1);
00445 }
00446 }
00447
00448
00449 static GtkProfileEntry* gtk_profile_group_get_profile_entry(GtkProfileGroup *profileGroup,
00450 gint profileIndex)
00451 {
00452 CN_LOGPRINTF("entry [%p] [%d]", profileGroup, profileIndex);
00453
00454 GtkProfileEntry *profileEntry = NULL;
00455
00456 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(profileGroup), NULL);
00457
00458 CN_LOGPRINTF("entry profile[%d]", profileGroup->nProfiles);
00459
00460 if ((profileIndex >= 0) && (profileIndex < profileGroup->nProfiles))
00461 {
00462 CN_LOGPRINTF("entry profileEntries[%p]",
00463 profileGroup->profileEntries);
00464 profileEntry = profileGroup->profileEntries[profileIndex];
00465 }
00466
00467 CN_LOGPRINTF("ret[%p]", profileEntry);
00468 return profileEntry;
00469 }
00470
00471
00472 void gtk_profile_group_set_status_text(GtkProfileGroup* profileGroup,
00473 int profileIndex,
00474 gchar* text,
00475 gboolean flashing)
00476 {
00477 GtkProfileEntry *profileEntry;
00478
00479 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00480 g_return_if_fail((profileIndex >= 0) && (profileIndex < profileGroup->nProfiles));
00481 g_return_if_fail(text != NULL );
00482
00483 profileEntry = gtk_profile_group_get_profile_entry(profileGroup,
00484 profileIndex);
00485 g_return_if_fail(profileEntry != NULL);
00486
00487 gtk_profile_entry_set_status (profileEntry, text);
00488 gtk_profile_entry_set_status_flashing (profileEntry, flashing);
00489 }
00490
00491
00492 void gtk_profile_group_display_settings(GtkProfileGroup* profileGroup,
00493 int profileIndex,
00494 const networkProfile_t* settings,
00495 gboolean resetStatus)
00496 {
00497 CN_LOGPRINTF("entry");
00498
00499 GtkProfileEntry *profileEntry;
00500
00501 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00502 g_return_if_fail((profileIndex >= 0) && (profileIndex < profileGroup->nProfiles));
00503 g_return_if_fail(settings != NULL );
00504
00505 profileEntry = gtk_profile_group_get_profile_entry(profileGroup,
00506 profileIndex);
00507 g_return_if_fail(profileEntry != NULL);
00508
00509 if (resetStatus)
00510 {
00511 gtk_profile_entry_display_settings (profileEntry, settings, "");
00512 }
00513 else
00514 {
00515 gtk_profile_entry_display_settings (profileEntry, settings, NULL);
00516 }
00517 gtk_profile_entry_set_buttons_active(profileEntry, FALSE, FALSE);
00518 }
00519
00520 void gtk_profile_group_show_dialup(GtkProfileGroup *profileGroup,
00521 gboolean show)
00522 {
00523 CN_LOGPRINTF("entry profileGroup[%p] show[%d]", profileGroup, show);
00524
00525 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00526
00527 if (show)
00528 {
00529 gtk_widget_show(profileGroup->dialup);
00530 }
00531 else
00532 {
00533 gtk_widget_hide(profileGroup->dialup);
00534 }
00535 }
00536
00537 void gtk_profile_group_set_dialup_signal_image(GtkProfileGroup *profileGroup,
00538 guint quality)
00539 {
00540 CN_LOGPRINTF("entry profileGroup[%p] quality[%d]",
00541 profileGroup, quality);
00542
00543 int i;
00544
00545 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00546 g_return_if_fail((quality >= 0) && (quality <= 100));
00547
00548
00549 for (i = 0; i < 5; i++)
00550 {
00551 gtk_widget_hide(profileGroup->dialupSigImage[i]);
00552 }
00553
00554
00555 if (quality <= 0)
00556 {
00557 gtk_widget_show(profileGroup->dialupSigImage[0]);
00558 }
00559 else if (quality <= 25)
00560 {
00561 gtk_widget_show(profileGroup->dialupSigImage[1]);
00562 }
00563 else if (quality <= 50)
00564 {
00565 gtk_widget_show(profileGroup->dialupSigImage[2]);
00566 }
00567 else if (quality <= 75)
00568 {
00569 gtk_widget_show(profileGroup->dialupSigImage[3]);
00570 }
00571 else
00572 {
00573 gtk_widget_show(profileGroup->dialupSigImage[4]);
00574 }
00575 }
00576
00577
00578 void gtk_profile_group_show_profile_entries(GtkProfileGroup *profileGroup,
00579 guint nDisplayed)
00580 {
00581 int i;
00582 CN_LOGPRINTF("entry nDisplayed[%d]", nDisplayed);
00583 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00584
00585 i = 0;
00586 while (i < nDisplayed && i < profileGroup->nProfiles)
00587 {
00588 gtk_widget_show(GTK_WIDGET(profileGroup->profileEntries[i]));
00589 i++;
00590 }
00591 while (i < profileGroup->nProfiles)
00592 {
00593 gtk_widget_hide(GTK_WIDGET(profileGroup->profileEntries[i]));
00594 i++;
00595 }
00596
00597
00598 profileGroup->nDisplayed = nDisplayed;
00599
00600
00601 }
00602
00603 void gtk_profile_group_callback_on_buttons_clicked( GtkProfileGroup *profileGroup,
00604 on_profile_group_selection_update_t* on_name,
00605 on_profile_group_selection_update_t* on_edit)
00606 {
00607 CN_LOGPRINTF("entry");
00608 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00609
00610 profileGroup->callback_on_name = on_name;
00611 profileGroup->callback_on_edit = on_edit;
00612 }
00613
00614 void gtk_profile_group_callback_on_buttons_press( GtkProfileGroup *profileGroup,
00615 on_profile_group_button_press_t* on_name_press,
00616 on_profile_group_button_press_t* on_edit_press)
00617 {
00618 CN_LOGPRINTF("entry");
00619 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00620
00621 profileGroup->callback_on_name_press = on_name_press;
00622 profileGroup->callback_on_edit_press = on_edit_press;
00623 }
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00657
00659 static int get_button_index(GtkProfileGroup* profileGroup,
00660 GtkWidget* button,
00661 gboolean edit)
00662 {
00663 GtkProfileEntry* profileEntry;
00664 GtkWidget* nameEditBtn;
00665 gint i, profileIndex = -1;
00666
00667 for (i = 0; i < profileGroup->nProfiles; i++)
00668 {
00669 profileEntry = profileGroup->profileEntries[i];
00670 if (edit)
00671 {
00672 nameEditBtn = gtk_profile_entry_get_editbutton(profileEntry);
00673 }
00674 else
00675 {
00676 nameEditBtn = gtk_profile_entry_get_namebutton(profileEntry);
00677 }
00678
00679 if (nameEditBtn == button)
00680 {
00681 profileIndex = i;
00682 CN_LOGPRINTF("button press event: profileIndex=%d",
00683 profileIndex);
00684 break;
00685 }
00686 }
00687
00688 return profileIndex;
00689 }
00690
00691 static gboolean on_profile_group_name_button_press(GtkWidget* button,
00692 GdkEventButton* event,
00693 gpointer data)
00694 {
00695 CN_LOGPRINTF("entry");
00696
00697 GtkProfileGroup* profileGroup;
00698 gint profileIndex = -1;
00699 gboolean active;
00700 gboolean ret = FALSE;
00701
00702 g_return_val_if_fail(GTK_IS_TOGGLE_BUTTON(button), FALSE);
00703 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(data), FALSE);
00704
00705 profileGroup = GTK_PROFILE_GROUP(data);
00706 profileIndex = get_button_index(profileGroup, button, FALSE);
00707 g_return_val_if_fail(profileIndex != -1, FALSE);
00708
00709 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
00710 switch (profileGroup->mode)
00711 {
00712 case editMode_e:
00713
00714 ret = TRUE;
00715 break;
00716 case connectMode_e:
00717 if (profileGroup->callback_on_name_press)
00718 {
00719 ret = profileGroup->callback_on_name_press(profileGroup,
00720 profileIndex,
00721 active);
00722 }
00723 break;
00724 case deleteMode_e:
00725 if (profileGroup->callback_on_name_press)
00726 {
00727 ret = profileGroup->callback_on_name_press(profileGroup,
00728 profileIndex,
00729 active);
00730 }
00731 break;
00732 default:
00733 break;
00734 }
00735
00736 return ret;
00737 }
00738
00739 static gboolean on_profile_group_edit_button_press(GtkWidget* button,
00740 GdkEventButton* event,
00741 gpointer data)
00742 {
00743 CN_LOGPRINTF("entry");
00744
00745 GtkProfileGroup* profileGroup;
00746 gint profileIndex = -1;
00747 gboolean active;
00748 gboolean ret = FALSE;
00749
00750 g_return_val_if_fail(GTK_IS_TOGGLE_BUTTON(button), FALSE);
00751 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(data), FALSE);
00752
00753 profileGroup = GTK_PROFILE_GROUP(data);
00754 profileIndex = get_button_index(profileGroup, button, TRUE);
00755 g_return_val_if_fail(profileIndex != -1, FALSE);
00756
00757 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
00758 switch (profileGroup->mode)
00759 {
00760 case editMode_e:
00761 ret = FALSE;
00762 break;
00763 case connectMode_e:
00764 ret = TRUE;
00765 break;
00766 case deleteMode_e:
00767 ret = TRUE;
00768 break;
00769 default:
00770 break;
00771 }
00772
00773 return ret;
00774 }
00775
00776 static void on_profile_group_selection_update(erGtkSelectionGroup *selection,
00777 gpointer button,
00778 gpointer data)
00779 {
00780 CN_LOGPRINTF("entry");
00781
00782 GtkProfileGroup* profileGroup;
00783 guint profileIndex;
00784 GtkToggleButton* btn;
00785 gboolean active;
00786
00787 g_return_if_fail(ERGTK_IS_SELECTION_GROUP(selection));
00788 g_return_if_fail(GTK_IS_TOGGLE_BUTTON(button));
00789 g_return_if_fail(IS_GTK_PROFILE_GROUP(data));
00790
00791 profileGroup = GTK_PROFILE_GROUP(data);
00792 if (profileGroup->mode == deleteMode_e)
00793 {
00794 CN_WARNPRINTF("in delete mode, ignore selection-update signal");
00795 }
00796
00797 btn = GTK_TOGGLE_BUTTON(button);
00798 active = gtk_toggle_button_get_active(btn);
00799 if (active)
00800 {
00801 ergtk_selection_group_get_selected_buttons(selection,
00802 &profileIndex, 1);
00803 g_return_if_fail((profileIndex >= 0) && (profileIndex < profileGroup->nDisplayed));
00804
00805 if (profileGroup->mode == editMode_e)
00806 {
00807 if (profileGroup->callback_on_edit)
00808 {
00809 profileGroup->callback_on_edit(profileGroup, profileIndex);
00810 }
00811 }
00812 else
00813 {
00814 if (profileGroup->callback_on_name)
00815 {
00816 profileGroup->callback_on_name(profileGroup, profileIndex);
00817 }
00818 }
00819 }
00820 }
00821
00822
00823 guint on_profile_group_keypress(GtkProfileGroup* profileGroup,
00824 GdkEventKey * event)
00825 {
00826 CN_LOGPRINTF ("entry");
00827
00828 gboolean selected;
00829 gboolean displayUpdated = FALSE;
00830 guint returnValue = 0;
00831
00832 switch (event->keyval)
00833 {
00834 case GDK_Down:
00835
00836 selected = gtk_profile_group_select_next_profile (profileGroup);
00837 if (!selected)
00838 {
00839 gtk_profile_group_select_first_profile (profileGroup);
00840 }
00841 displayUpdated = TRUE;
00842
00843 returnValue = 1;
00844 break;
00845
00846 case GDK_Up:
00847
00848 selected = gtk_profile_group_select_previous_profile(profileGroup);
00849 if (!selected)
00850 {
00851 gtk_profile_group_select_last_profile (profileGroup);
00852 }
00853 displayUpdated = TRUE;
00854
00855 returnValue = 1;
00856 break;
00857
00858 case GDK_Return:
00859 default:
00860 CN_ERRORPRINTF ("-- case default");
00861 erbusy_off ();
00862 }
00863
00864
00865 if (displayUpdated)
00866 {
00867 display_update_request_screen_refresh (STATUS_ITEM_CHANGE,
00868 WAVEFORM_TYPING);
00869 }
00870
00871 return returnValue;
00872 }
00873
00875
00876
00877
00879 void gtk_profile_group_select_first_profile (GtkProfileGroup* profileGroup)
00880 {
00881 CN_LOGPRINTF ("entry");
00882
00883 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00884 if (profileGroup->nDisplayed > 0)
00885 {
00886 gtk_profile_group_select_profile (profileGroup, 0);
00887 }
00888 }
00889
00890 void gtk_profile_group_select_last_profile (GtkProfileGroup* profileGroup)
00891 {
00892 CN_LOGPRINTF ("entry");
00893
00894 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00895 if (profileGroup->nDisplayed > 0)
00896 {
00897 gtk_profile_group_select_profile (profileGroup,
00898 profileGroup->nDisplayed-1);
00899 }
00900 }
00901
00902 gboolean gtk_profile_group_select_next_profile (GtkProfileGroup* profileGroup)
00903 {
00904 CN_LOGPRINTF ("entry");
00905
00906 erGtkSelectionGroup *selection;
00907 guint profileIndex;
00908 gboolean selected = FALSE;
00909
00910 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(profileGroup), FALSE);
00911
00912 selection = ERGTK_SELECTION_GROUP(profileGroup->selection);
00913 ergtk_selection_group_get_selected_buttons(selection,
00914 &profileIndex, 1);
00915 if ((profileIndex >= 0) && (profileIndex < profileGroup->nDisplayed))
00916 {
00917
00918 if ((profileIndex + 1) < profileGroup->nDisplayed)
00919 {
00920 gtk_profile_group_select_profile(profileGroup,
00921 profileIndex + 1);
00922 selected = TRUE;
00923 }
00924 }
00925 return selected;
00926 }
00927
00928 gboolean gtk_profile_group_select_previous_profile (GtkProfileGroup* profileGroup)
00929 {
00930 CN_LOGPRINTF ("entry");
00931
00932 erGtkSelectionGroup *selection;
00933 guint profileIndex;
00934 gboolean selected = FALSE;
00935
00936 g_return_val_if_fail(IS_GTK_PROFILE_GROUP(profileGroup), FALSE);
00937
00938 selection = ERGTK_SELECTION_GROUP(profileGroup->selection);
00939 ergtk_selection_group_get_selected_buttons(selection, &profileIndex, 1);
00940 if ((profileIndex >= 0) && (profileIndex < profileGroup->nDisplayed))
00941 {
00942
00943 if ((profileIndex - 1) > 0)
00944 {
00945 gtk_profile_group_select_profile(profileGroup, profileIndex-1);
00946 selected = TRUE;
00947 }
00948 }
00949 return selected;
00950 }
00951
00952 void gtk_profile_group_select_profile (GtkProfileGroup* profileGroup,
00953 guint profileIndex)
00954 {
00955 CN_LOGPRINTF ("entry: profileIndex [%d]", profileIndex);
00956
00957 erGtkSelectionGroup *selection;
00958 guint selectedIndex;
00959 GtkProfileEntry *profileEntry;
00960
00961 g_return_if_fail(IS_GTK_PROFILE_GROUP(profileGroup));
00962
00963
00964 if ((profileIndex >= 0) && (profileIndex < profileGroup->nProfiles))
00965 {
00966 profileEntry = profileGroup->profileEntries[profileIndex];
00967 g_return_if_fail(profileEntry != NULL);
00968
00969 if (profileGroup->mode == deleteMode_e)
00970 {
00971 gtk_profile_entry_set_buttons_active(profileEntry, TRUE, FALSE);
00972 }
00973 else
00974 {
00975
00976 selection = ERGTK_SELECTION_GROUP(profileGroup->selection);
00977 ergtk_selection_group_get_selected_buttons(selection,
00978 &selectedIndex, 1);
00979 if (profileIndex != selectedIndex)
00980 {
00981 if (profileGroup->mode == editMode_e)
00982 {
00983 gtk_profile_entry_set_buttons_active(profileEntry,
00984 FALSE, TRUE);
00985 }
00986 else
00987 {
00988 gtk_profile_entry_set_buttons_active(profileEntry,
00989 TRUE, FALSE);
00990 }
00991 }
00992 }
00993 }
00994 }
00995
00996 void gtk_profile_group_unselect_profile (GtkProfileGroup* profileGroup,
00997 guint profileIndex)
00998 {
00999 CN_LOGPRINTF ("entry");
01000
01001 GtkProfileEntry* profileEntry;
01002
01003 if ((profileIndex >= 0) && (profileIndex < profileGroup->nProfiles))
01004 {
01005 profileEntry = profileGroup->profileEntries[profileIndex];
01006 if (profileEntry)
01007 {
01008 gtk_profile_entry_set_buttons_active(profileEntry,
01009 FALSE, FALSE);
01010 }
01011 }
01012 }
01013