comparison g23m/condat/ms/src/bmi/MmiBand.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*******************************************************************************
2
3 CONDAT (UK)
4
5 ********************************************************************************
6
7 This software product is the property of Condat (UK) Ltd and may not be
8 disclosed to any third party without the express permission of the owner.
9
10 ********************************************************************************
11
12 $Project name: Basic MMI
13 $Project code: BMI
14 $Module: Frequency band selection
15 $File: MmiBand.c
16 $Revision: 1.0
17
18 $Author: Condat(UK)
19 $Date: 03/04/02
20
21 ********************************************************************************
22
23 Description:
24
25 This provides the functionality for menu options to select and display the current
26 band used.
27
28 ********************************************************************************
29 $History: MmiBand.c
30
31 03/04/02 Original Condat(UK) BMI version.
32
33 $End
34
35 *******************************************************************************/
36
37
38
39
40 /*******************************************************************************
41
42 Include files
43
44 *******************************************************************************/
45 #define ENTITY_MFW
46
47 /* includes */
48 #include <string.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51
52 #if defined (NEW_FRAME)
53
54 #include "typedefs.h"
55 #include "vsi.h"
56 #include "pei.h"
57 #include "custom.h"
58 #include "gsm.h"
59
60 #else
61
62 #include "STDDEFS.H"
63 #include "custom.h"
64 #include "gsm.h"
65 #include "vsi.h"
66
67 #endif
68 #include "mfw_sys.h"
69
70 #include "cus_aci.h"
71
72 #include "mfw_mfw.h"
73 #include "mfw_win.h"
74 #include "mfw_kbd.h"
75 /* SPR#1428 - SH - New Editor changes */
76 #ifndef NEW_EDITOR
77 #include "mfw_edt.h"
78 #endif
79 #include "mfw_lng.h"
80 #include "mfw_tim.h"
81 #include "mfw_icn.h"
82 #include "mfw_mnu.h"
83 #include "mfw_phb.h"
84 #include "mfw_cm.h"
85 #include "mfw_sim.h"
86 #include "mfw_nm.h"
87 #include "mfw_sat.h"
88 #include "mfw_ss.h" /*for convert*/
89 #include "mfw_phb.h"
90 #include "ksd.h"
91 #include "psa.h"
92 #include "mfw_sms.h"
93 #include "mfw_cphs.h"
94 #include "mfw_sat.h"
95 #include "Mfw_band.h"
96 #include "mfw_ffs.h"
97
98 #include "dspl.h"
99
100 #include "MmiMmi.h"
101 #include "MmiDialogs.h"
102 #include "MmiLists.h"
103 #include "MmiBand.h"
104 #include "MmiCPHS.h"
105 #include "mmiColours.h"
106
107 /***********************************Macros**********************************************/
108
109 #define MAX_NUMBER_OF_FREQS 5
110 #define NO_OF_BAND_MODES 2
111 #define BAND_INIT 1
112 #define BAND_DESTROY 2
113
114
115
116 /*********************Structure Definitions********************************************************/
117 typedef struct
118 {
119 T_MMI_CONTROL mmi_control;
120 T_MFW_HND freq_win; /* MFW win handler */
121 T_MFW_HND parent;
122 UBYTE available_freqs;
123 UBYTE selected_freqs; /* SPR#998 - SH - Used to store list of selected frequencies */
124 T_MFW_BAND_MODE mode; /* SPR#998 - SH */
125 UBYTE type[MAX_NUMBER_OF_FREQS];
126 ListMenuData * menu_list_data;
127 UBYTE no_of_entries;
128 } T_FREQ_INFO;
129
130
131 static const MfwMnuAttr Freq_menuAttrib =
132 {
133 &melody_menuArea,
134 MNU_LEFT | MNU_LIST | MNU_CUR_LINE, /* centered page menu */
135 -1, /* use default font */
136 NULL, /* with these items */
137 0, /* number of items */
138 COLOUR_LIST_SMS,
139 TxtNull,
140 MNUATTRSPARE};
141
142 /* List of all possible frequencies */
143
144 static const int band_list[MAX_NUMBER_OF_FREQS] = {
145 MFW_BAND_GSM_900,
146 MFW_BAND_DCS_1800,
147 MFW_BAND_PCS_1900,
148 MFW_BAND_E_GSM,
149 MFW_BAND_GSM_850
150 };
151
152 /* SPR#998 - SH - Static handle to allow callback functions to access data */
153 static T_FREQ_INFO *current_data = NULL;
154
155 /*********************************Function Prototypes*****************************/
156
157 char* Freq2Str(int freq);
158
159 int Freq2StrID(int freq);
160 static T_MFW_HND mmi_band_build_freq_list( MfwHnd parent_window, UBYTE available_freqs);
161 static int mmi_band_display_status(T_MFW_HND parent);
162 static int mmi_band_display_status_cb(T_MFW_HND parent, USHORT identifier, USHORT reason);
163 void mmi_band_freq_exec_cb (T_MFW_HND win, USHORT event, SHORT value, void * parameter);
164 void mmi_band_freq_list_cb(T_MFW_HND * Parent, ListMenuData * ListData);
165 static void mmi_band_freq_list_destroy(MfwHnd own_window);
166 static int mmi_band_freq_win_cb (MfwEvt e, MfwWin *w);
167 /* SPR#998 - SH - Functions used by new checkbox menus */
168 int mmi_band_menu_func(MfwMnu* menu, MfwMnuItem* item);
169 USHORT mmi_band_menu_flag( struct MfwMnuTag *menu, struct MfwMnuAttrTag *attr, struct MfwMnuItemTag *item );
170
171
172 /************************************Public Functions************************/
173
174
175 /*************************************************************************
176
177 $Function: mmi_band_radio_mode_change_auto
178
179 $Description: Changes multiband mode to automatic. Selected from menu.
180
181 $Returns: status int
182
183 $Arguments: menu and menu item (not used)
184
185
186 *******************************************************************************/
187
188 int mmi_band_radio_mode_change_auto(MfwMnu* m, MfwMnuItem* i)
189 {
190 T_MFW_HND parent = mfwParent( mfw_header());
191 // T_MFW_BAND_MODE mode; // RAVI
192
193 TRACE_FUNCTION("mmi_band_radio_mode_change_auto");
194
195 if (band_radio_mode_switch(MFW_BAND_MODE_Auto, 0) >= MFW_BAND_OK)
196 {
197 ShowMessage(parent, TxtDone, TxtNull);
198 }
199 else
200 ShowMessage(parent, TxtFailed, TxtNull);
201
202 return MFW_EVENT_CONSUMED;
203 }
204
205
206 /*******************************************************************************
207
208 $Function: mmi_band_radio_mode_change_manual
209
210 $Description: Gets a list of available manual bands. Selected from menu.
211
212 $Returns: status int
213
214 $Arguments: menu and menu item (not used)
215
216
217 *******************************************************************************/
218
219 int mmi_band_radio_mode_change_manual(MfwMnu* m, MfwMnuItem* i)
220 {
221 T_MFW_HND parent = mfwParent( mfw_header());
222 T_MFW_BAND_MODE maxMode;
223 UBYTE available_freqs;
224 T_MFW_HND win;
225
226 if (band_get_radio_modes(&maxMode, &available_freqs) >= MFW_BAND_OK)
227 {
228 if (maxMode >= MFW_BAND_MODE_Manual) /* Make sure manual is an accepted mode */
229 {
230 win = mmi_band_build_freq_list(parent, available_freqs);
231 if (win NEQ NULL)
232 {
233 SEND_EVENT (win, BAND_INIT, 0, 0);
234 }
235 else
236 ShowMessage(parent, TxtManual, TxtNotSupported);
237 }
238 }
239
240 return MFW_EVENT_CONSUMED;
241 }
242
243
244 /*******************************************************************************
245
246 $Function: mmi_band_radio_mode_info
247
248 $Description: Get current band setting
249
250 $Returns: status int
251
252 $Arguments: menu and menu item (not used)
253
254
255 *******************************************************************************/
256
257 int mmi_band_radio_mode_info(MfwMnu* m, MfwMnuItem* i)
258 { T_MFW_HND parent = mfwParent( mfw_header());
259
260 mmi_band_display_status(parent);
261
262 return MFW_EVENT_CONSUMED;
263 }
264
265
266 /*******************************Private Functions**********************************/
267
268
269
270 /*******************************************************************************
271
272 $Function: Freq2Str
273
274 $Description: Converts the band enum into an appropraite string
275
276 $Returns: string
277
278 $Arguments: Band (integer)
279
280
281 *******************************************************************************/
282
283 char* Freq2Str(int freq)
284 {
285 switch (freq)
286 {
287 case MFW_BAND_DCS_1800: return MmiRsrcGetText(TxtDCS_1800); //break; // RAVI
288 case MFW_BAND_PCS_1900: return MmiRsrcGetText(TxtPCS_1900); //break; // RAVI
289 case MFW_BAND_E_GSM: return MmiRsrcGetText(TxtE_GSM); //break; // RAVI
290 case MFW_BAND_GSM_850: return MmiRsrcGetText(TxtGSM_850); // break; // RAVI
291 case MFW_BAND_GSM_900: return MmiRsrcGetText(TxtGSM_900); // break; // RAVI
292 default: return MmiRsrcGetText(TxtError); // break; // RAVI
293 }
294 }
295
296
297 /*******************************************************************************
298
299 $Function: Freq2Str
300
301 $Description: Converts the band enum into an appropraite string ID
302
303 $Returns: string ID
304
305 $Arguments: Band (integer)
306
307
308 *******************************************************************************/
309
310 int Freq2StrID(int freq)
311 {
312 switch (freq)
313 {
314 case MFW_BAND_DCS_1800: return TxtDCS_1800; //break; // RAVI
315 case MFW_BAND_PCS_1900: return TxtPCS_1900; //break; // RAVI
316 case MFW_BAND_E_GSM: return TxtE_GSM; //break; // RAVI
317 case MFW_BAND_GSM_850: return TxtGSM_850; // break; // RAVI
318 case MFW_BAND_GSM_900: return TxtGSM_900; //break; // RAVI
319 default: return TxtError; //break; // RAVI
320 }
321 }
322
323
324 /*******************************************************************************
325
326 $Function: mmi_band_display_status
327 $Description: Displays the current band status
328 $Returns: none
329 $Arguments: parent - parent window
330
331 *******************************************************************************/
332
333 static int mmi_band_display_status(T_MFW_HND parent)
334 {
335 /* SPR#998 - SH - Now store mode in data->mode */
336 T_MFW_WIN *win_data = ((T_MFW_HDR *) parent)->data;
337 T_FREQ_INFO *data = (T_FREQ_INFO *)win_data->user;
338
339 if (band_get_current_radio_mode(&data->mode, &data->selected_freqs) >= MFW_BAND_OK)
340 {
341 if (data->mode == MFW_BAND_MODE_Auto)
342 {
343 ShowMessage(parent, TxtAutomatic, TxtNull);
344 }
345 else
346 {
347 ShowMessage(parent, TxtManual, TxtNull);
348 }
349 }
350 else
351 {
352 ShowMessage(parent, TxtReadError, TxtNull);
353 }
354
355 return 1; // RAVI - Changed return to return 1.
356 }
357
358
359 /*******************************************************************************
360
361 $Function: mmi_band_display_status_cb
362 $Description: Callback for status list window - currently does nothing
363 $Returns: none
364 $Arguments: parent - parent window
365 identifier - length of status string
366 reason - not used
367
368 *******************************************************************************/
369
370 static int mmi_band_display_status_cb(T_MFW_HND parent, USHORT identifier, USHORT reason)
371 {
372 return 1; // RAVI - Changed return to return 1.
373 }
374
375
376 /*******************************************************************************
377
378 $Function: mmi_band_build_freq_list
379 $Description: Creates window for frequency list
380 $Returns: window created
381 $Arguments: parent window
382
383 *******************************************************************************/
384
385 static T_MFW_HND mmi_band_build_freq_list( MfwHnd parent_window, UBYTE available_freqs)
386 {
387 T_FREQ_INFO *data = (T_FREQ_INFO *)ALLOC_MEMORY (sizeof (T_FREQ_INFO));
388 T_MFW_WIN *win;
389 // int index; // RAVI
390
391 TRACE_FUNCTION("mmi_band_build_freq_list()");
392 /*
393 * Create window handler
394 */
395
396 data->freq_win = win_create (parent_window, 0, E_WIN_VISIBLE, (T_MFW_CB)mmi_band_freq_win_cb);
397 if (data->freq_win EQ NULL)
398 {
399 return NULL;
400 }
401
402 current_data = data; /* SPR#998 - SH - Store handle for data; used by callbacks */
403
404 /*
405 * connect the dialog data to the MFW-window
406 */
407
408 data->mmi_control.dialog = (T_DIALOG_FUNC)mmi_band_freq_exec_cb;
409 data->mmi_control.data = data;
410 win = ((T_MFW_HDR *)data->freq_win)->data;
411 win->user = (void *)data;
412 data->parent = parent_window;
413 data->available_freqs = available_freqs;
414
415 winShow(data->freq_win);
416 /*
417 * return window handle
418 */
419
420 return data->freq_win;
421 }
422
423
424 /*******************************************************************************
425
426 $Function: mmi_band_freq_exec_cb
427
428 $Description: Exec callback function of the information Numbers window
429
430 $Returns: none
431
432 $Arguments: win - window handler
433 event - mfw event
434 parameter - optional data.
435
436 *******************************************************************************/
437
438 void mmi_band_freq_exec_cb (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
439 {
440 T_MFW_WIN *win_data = ((T_MFW_HDR *) win)->data;
441 T_FREQ_INFO *data = (T_FREQ_INFO *)win_data->user;
442 UBYTE numberOfEntries;
443 int index;
444 T_MFW_BAND_MODE maxMode;
445 // char *menuItem; // RAVI
446 /* SPR#998 - SH - Remove code that implements custom checkbox implementaton,
447 * as checkboxes now handled by mfw */
448
449 TRACE_FUNCTION ("mmi_band_freq_exec_cb()");
450
451 switch (event)
452 {
453 case BAND_INIT:
454
455 TRACE_EVENT("mmi_band_freq_exec_cb() Event:BAND_INIT");
456
457 /* initialization of administrative data */
458
459 data->menu_list_data = (ListMenuData *)ALLOC_MEMORY(sizeof(ListMenuData));
460
461 if(!data->menu_list_data)
462 {
463 TRACE_EVENT("Failed memory alloc 1 ");
464 return;
465 }
466
467 band_get_radio_modes(&maxMode, &data->available_freqs);
468
469 /* Run through the list of possible frequencies first to obtain
470 the number of frequencies permitted (how many will be in the menu) */
471 /* SPR#998 - SH - Removed custom checkbox implementation */
472
473 numberOfEntries = 0;
474
475 for (index=0; index<MAX_NUMBER_OF_FREQS; index++)
476 {
477 if (data->available_freqs & band_list[index])
478 {
479 data->type[numberOfEntries] = band_list[index];
480 numberOfEntries++;
481 }
482 }
483
484 /* If there are no entries, show "Empty List" message and exit */
485
486 if (numberOfEntries==0)
487 {
488 ShowMessage(data->parent, TxtEmptyList, TxtNull);
489 mmi_band_freq_list_destroy(win);
490 return;
491 }
492
493 /* Get the status of all the frequencies */
494 /* SPR#998 - SH - Use data->mode */
495
496 if (band_get_current_radio_mode(&data->mode, &data->selected_freqs) >= MFW_BAND_OK)
497 {
498 /* If we're not in manual choose manual */
499
500 if (data->mode!=MFW_BAND_MODE_Manual)
501 {
502 data->selected_freqs = data->available_freqs; /* SH - default when choosing manual is all */
503 band_radio_mode_switch(MFW_BAND_MODE_Manual, data->selected_freqs);
504 }
505
506 /* Allocate the memory for the list structure */
507
508 data->no_of_entries = numberOfEntries;
509
510 data->menu_list_data->List = (T_MFW_MNU_ITEM *)ALLOC_MEMORY( numberOfEntries * sizeof(T_MFW_MNU_ITEM) );
511
512 if(!data->menu_list_data->List)
513 {
514 TRACE_EVENT("Failed memory alloc 2");
515 return;
516 }
517
518 /* Allocate memory for the menu texts, and populate the list structure */
519
520 numberOfEntries = 0;
521
522 for (index=0; index<MAX_NUMBER_OF_FREQS; index++)
523 {
524 if (data->available_freqs & band_list[index])
525 {
526 /* SPR#998 - SH - Removed code, checkboxes now handled by MFW */
527 mnuInitDataItem(&data->menu_list_data->List[numberOfEntries]);
528 /* Here we specify the function that checks and unchecks the checkboxes */
529 data->menu_list_data->List[numberOfEntries].func = mmi_band_menu_func;
530 data->menu_list_data->List[numberOfEntries].str = (char *)Freq2StrID(band_list[index]);
531 /* Here we specify the function that returns the checkbox status of any menu item */
532 data->menu_list_data->List[numberOfEntries].flagFunc = mmi_band_menu_flag;
533 numberOfEntries++;
534 }
535 }
536
537 data->menu_list_data->ListLength =numberOfEntries;
538 data->menu_list_data->ListPosition = 1;
539 data->menu_list_data->CursorPosition = 1;
540 data->menu_list_data->SnapshotSize = numberOfEntries;
541 data->menu_list_data->Font = 0;
542 data->menu_list_data->LeftSoftKey = TxtSoftSelect;
543 data->menu_list_data->RightSoftKey = TxtSoftBack;
544 data->menu_list_data->KeyEvents = KEY_ALL;
545 data->menu_list_data->Reason = 0;
546 data->menu_list_data->Strings = FALSE; /* SPR#998 - SH - We no longer alter the menu strings */
547 data->menu_list_data->Attr = (MfwMnuAttr*)&Freq_menuAttrib;
548 data->menu_list_data->autoDestroy = FALSE;
549
550 /* Create the dynamic menu window */
551 listDisplayListMenu(win, data->menu_list_data,(ListCbFunc)mmi_band_freq_list_cb,0);
552 }
553 else /* We haven't been able to read the status */
554 {
555 ShowMessage(win, TxtReadError, TxtNull);
556 }
557
558 break;
559
560 case BAND_DESTROY:
561 TRACE_EVENT("mmi_band_freq_exec_cb() Event:BAND_DESTROY");
562 /*
563 * Free Memory
564 */
565
566 /* SPR#998 - SH - No longer free allocated strings here */
567
568 numberOfEntries = data->no_of_entries;
569
570 if (data->menu_list_data != NULL)
571 {
572 FREE_MEMORY ((void *)data->menu_list_data->List, numberOfEntries * sizeof (T_MFW_MNU_ITEM));
573 FREE_MEMORY ((void *)data->menu_list_data, sizeof (ListMenuData));
574 }
575
576 FREE_MEMORY ((void *)data, sizeof (T_FREQ_INFO));
577 break;
578
579 default:
580 break;
581 }
582 }
583
584
585 /*******************************************************************************
586
587 $Function: mmi_band_freq_list_cb
588
589 $Description: Callback function for the info num list.
590
591 $Returns: none
592
593 $Arguments: Parent - parent window.
594 ListData - Menu item list
595 *******************************************************************************/
596
597 void mmi_band_freq_list_cb(T_MFW_HND * Parent, ListMenuData * ListData)
598 {
599 /* SPR#998 - SH - Selecting a checkbox is handled now by the checkbox functions,
600 * so much less is required here */
601
602 T_MFW_WIN *win_data = ((T_MFW_HDR *)Parent)->data;
603 T_FREQ_INFO *data = (T_FREQ_INFO *)win_data->user;
604
605 TRACE_FUNCTION("mmi_band_freq_list_cb");
606
607 if ((ListData->Reason EQ LISTS_REASON_BACK) || (ListData->Reason EQ LISTS_REASON_CLEAR))
608 {
609 listsDestroy(ListData->win);
610 mmi_band_freq_list_destroy(data->freq_win);
611 }
612 else if(ListData->Reason EQ LISTS_REASON_SELECT)
613 {
614 winShow(Parent);
615 }
616 }
617
618
619 /*******************************************************************************
620
621 $Function: mmi_band_freq_list_destroy
622
623 $Description: Destroy the info num window.
624
625 $Returns: none
626
627 $Arguments: own_window- current window
628 *******************************************************************************/
629
630 static void mmi_band_freq_list_destroy(MfwHnd own_window)
631 {
632 T_MFW_WIN *win_data;
633 T_FREQ_INFO *data;
634
635 TRACE_FUNCTION ("mmi_band_freq_list_destroy()");
636
637 if (own_window)
638 {
639 win_data = ((T_MFW_HDR *)own_window)->data;
640 data = (T_FREQ_INFO *)win_data->user;
641
642 if (data)
643 {
644 /*
645 * Free Memory
646 */
647 SEND_EVENT (own_window, BAND_DESTROY, 0, 0);
648 /*
649 * Delete WIN handler
650 */
651 win_delete (own_window);
652
653 current_data = NULL; /* SPR#998 - SH - Set the data handle to NULL */
654 }
655 else
656 {
657 TRACE_EVENT ("mmi_band_freq_list_destroy() called twice");
658 }
659 }
660 }
661
662
663 /*******************************************************************************
664
665 $Function: mmi_band_freq_win_cb
666
667 $Description: Window callback function for the info numbers window.
668
669 $Returns: none
670
671 $Arguments: w - mfw window handler
672 e - mfw event
673
674 *******************************************************************************/
675
676 static int mmi_band_freq_win_cb (MfwEvt e, MfwWin *w) /* yyy window event handler */
677 {
678 TRACE_FUNCTION ("mmi_band_freq_win_cb()");
679 switch (e)
680 {
681 case MfwWinVisible: /* window is visible */
682 break;
683 case MfwWinFocussed: /* input focus / selected */
684 case MfwWinDelete: /* window will be deleted */
685
686 default:
687 return MFW_EVENT_REJECTED;
688 }
689 return MFW_EVENT_CONSUMED;
690 }
691
692
693
694 /*******************************************************************************
695
696 $Function: mmi_band_menu_func
697
698 $Description: SPR#998 - SH - Added
699 Select or deselect a checkbox item. The appropriate band function is
700 called, to ensure that the selection is valid.
701
702 $Returns: None.
703
704 $Arguments: m, ma, mi - not used
705
706 *******************************************************************************/
707
708 int mmi_band_menu_func(MfwMnu* menu, MfwMnuItem* item)
709 {
710 T_FREQ_INFO *data = current_data;
711
712 TRACE_FUNCTION("mmi_band_menu_func");
713
714 data->selected_freqs ^= data->type[menu->lCursor[menu->level]]; /* Toggle this band */
715
716 if (band_radio_mode_switch(MFW_BAND_MODE_Manual, data->selected_freqs) >= MFW_BAND_OK)
717 {
718 mnuUpdate(menu);
719 }
720 else
721 {
722 data->selected_freqs ^= data->type[menu->lCursor[menu->level]]; /* Undo change */
723 ShowMessage(data->freq_win, TxtFailed, TxtNull);
724 }
725
726 return 1;
727 }
728
729
730 /*******************************************************************************
731
732 $Function: mmi_band_menu_flag
733
734 $Description: Attribut function for menu entries.
735
736 $Returns: Checked or unchecked
737
738 $Arguments: m, ma, mi - not used
739
740 *******************************************************************************/
741
742 USHORT mmi_band_menu_flag( struct MfwMnuTag *menu, struct MfwMnuAttrTag *attr, struct MfwMnuItemTag *item )
743 {
744 T_FREQ_INFO *data = current_data; /* SPR#998 - SH - Get data from static handle */
745 int currentOption;
746
747 TRACE_FUNCTION("mmi_band_menu_flag()");
748 TRACE_EVENT_P1("Freq info data: %x", data);
749
750 /* Identify current menu option */
751
752 currentOption = mnuIdentify(attr, item);
753
754 /* If we find it, work out if it's checked or not */
755
756 if (currentOption>-1)
757 {
758 if (data->selected_freqs & data->type[currentOption])
759 return MNU_ITEM_CHECKED;
760 else
761 return MNU_ITEM_UNCHECKED;
762 }
763 return 0;
764 }
765