Statistics
| Branch: | Revision:

root / hope.c

History | View | Annotate | Download (47.1 KB)

1 0:3c15de202295 ee11d037
#include "hope.h"
2
#include "maintain.c"
3
#include "user_dict.c"
4
#include <gdk/gdkkeysyms.h>
5
#include <glib/gprintf.h>
6
7
PangoFontDescription *font_desc;
8
PangoFontDescription *font_dsc;
9
GtkRcStyle *rc_style;
10
11
static int flagserial,flagspace,flagback;
12
char sound[20];
13
char  logfile[MAX_STR_LEN];
14
/* Create a new hbox with an image and a label packed into it
15
 * and return the box. This is used at the top level */
16
17
18
19
20
static GtkWidget *xpm_label_box(gchar *label_text,  gchar *xpm_filename)
21
{
22
  GtkWidget *box;
23
  GtkWidget *label;
24
  GtkWidget *image;
25
  char final_label[10];
26
27
font_desc = pango_font_description_from_string ("Helvetica,Sans 15");
28
font_dsc = pango_font_description_from_string ("Helvetica,Sans 15");
29
  strcpy (final_label, " ");
30
  strcat (final_label, label_text);
31
  strcat (final_label, " ");
32
33
  /* Create box for image and label */
34
  box = gtk_vbox_new (FALSE, 0);
35
36
  gtk_container_set_border_width (GTK_CONTAINER (box), 0);
37
38
  /* Now on to the image stuff */
39
  image = gtk_image_new_from_file (xpm_filename);
40
41
  /* Create a label for the button */
42
  label = gtk_label_new (final_label);
43
//  gtk_widget_modify_font (label, font_dsc);
44
//  gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &blue);
45
46
  /* Pack the image and label into the box */
47
  gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
48
//  gtk_box_pack_start (GTK_BOX (box), image, TRUE, TRUE, 3);
49
  gtk_widget_show (label);
50
//gtk_widget_show (image);
51
52
    return box;
53
}
54
55
/* This function is used for removing temp files while running the application and exit the application. */
56
57
int cleanup_and_main_quit ()
58
{
59
  system ("sh clean.sh");
60
  gtk_main_quit ();
61
}
62
63
/* Callback method */
64
65
static void create_buttons()
66
{
67
  GtkWidget *box, *message;
68
69
  int i;
70
  int response = read_conf_file (CONFIG_FILE);
71
  change_mode = 0; // initial default mode
72
73
  /* This is to read the config file*/
74
  if (response == -1)
75
    fprintf (fp, "Error: Can not open config file %s\n", CONFIG_FILE);
76
  else if (response == -2)
77
    fprintf (fp, "Error: In config file => Wrong definition of label\n");
78
  else if (response == -3)
79
    fprintf (fp, "Error: In config file => Invalid mode given\n");
80
81
  if (response < 0)
82
  {
83
84
     message = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Brain overflow!");
85
     gtk_dialog_run(GTK_DIALOG(message));
86
     gtk_widget_hide(message);
87
     exit (1);
88
  }
89
90
  /* This is to populate all the 9 buttons with alphabets as labels*/
91
  for(i = 0; i < 10; i++)
92
    {
93
      button[i] = gtk_button_new();
94
      box = xpm_label_box (label[i], icon[i]);
95
//      g_print ("hop.c the label is %s\n",label[i]);
96
      gtk_container_add (GTK_CONTAINER (button[i]), box);
97
      gtk_table_attach_defaults (GTK_TABLE (table), button[i], i, i+1, 0, 2);
98
      gtk_widget_show (box);
99
      gtk_widget_show (button[i]);
100
    }
101
102
  g_signal_connect (GTK_OBJECT (window), "key_press_event",
103
                     GTK_SIGNAL_FUNC ( check), NULL);
104
}
105
106
/*
107
This method does the switching when the button is pressed. According to
108
various scan modes, it switches from one to other and highlights buttons/labels.
109
*/
110
111
static void callback()
112
{
113
  int index,i;
114
115
  if(scan_mode == 2)
116
    {
117
118
     switch(iter2%4)
119
        {
120
        case 0:
121
        sprintf(selected_char, "%s", gtk_label_get_text(GTK_LABEL(single_button_label[0])));
122
123
        if(strncmp(selected_char,"#",1) == 0)
124
         {
125
           char text_space[300];
126
           strcpy(text_to_add, (char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
127
           strcpy(text_space,text_to_add);
128
           for (i=0 ; i < strlen(text_space) ; i++)
129
           if(text_space[i]==' ')
130
           text_space[i] = '-';
131
           fprintf(fp, "W %s \n", text_space);
132
           is_word_selected = 1;
133
           enter_into_sentence_box();
134
/*-- will change to this            gdk_threads_enter();
135
           for(index = 0; index < 5; index++)
136
           gtk_entry_set_text(GTK_ENTRY(entry_label[index]), "");
137
           gdk_threads_leave(); if they ask */
138
         }
139
140
        if(strncmp(selected_char," ",1)==0)
141
        {
142
//         g_print ("The space thing is here %s\n",selected_char);
143
         spell_mode=0;
144
        }
145
         break;
146
        case 1:
147
          sprintf(selected_char, "%s", gtk_label_get_text(GTK_LABEL(single_button_label[1])));
148
149
          if(strncmp(selected_char,"#",1) == 0)
150
           {
151
              char text_space[300];
152
              strcpy(text_to_add, (char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
153
              strcpy(text_space,text_to_add);
154
              for (i=0 ; i < strlen(text_space) ; i++)
155
              if(text_space[i]==' ')
156
              text_space[i] = '-';
157
              fprintf(fp, "W %s \n", text_space);
158
              is_word_selected = 1;
159
              enter_into_sentence_box();
160
           }
161
162
          if(strncmp(selected_char,"UNDO",4) == 0)
163
          {
164
               flagspace=1;
165
               gtk_widget_modify_bg(single_button[1], GTK_STATE_NORMAL, &colorGray);
166
               strcpy(text_to_add,"");
167
               flagpridict=0;
168
               strcpy(strpridict,"");
169
               for(index = 0; index < 5; index++)
170
               gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
171
               gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
172
               //enter_into_sentence_box ();
173
               scan_mode=4;
174
//             gtk_entry_set_text(GTK_ENTRY(sentence_box)," ");
175
//             is_back_selected=1;
176
//              g_print ("yes\n");
177
//             return;
178
          }
179
          break;
180
        case 2:
181
          sprintf(selected_char, "%s", gtk_label_get_text(GTK_LABEL(single_button_label[2])));
182
          if(strncmp(selected_char,"#",1) == 0)
183
           {
184
              char text_space[300];
185
              strcpy(text_to_add, (char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
186
              strcpy(text_space,text_to_add);
187
              for (i=0 ; i < strlen(text_space) ; i++)
188
              if(text_space[i]==' ')
189
              text_space[i] = '-';
190
              fprintf(fp, "W %s \n", text_space);
191
              is_word_selected = 1;
192
              enter_into_sentence_box();
193
           }
194
/*
195
              change_mode = 1;
196
              if(spell_mode == 0)
197
              {
198
                // from word to spell mode
199
//--u                fprintf(fp, "W->S\n");
200
                      spell_mode = 1;
201
              }
202
              else
203
              {
204
                // from spell mode to word mode
205
//--u                fprintf(fp, "S->W\n");
206
                      spell_mode = 0;
207
              }
208

209
          }*/
210
          break;
211
        case 3:
212
          gdk_threads_enter();
213
          sprintf(selected_char, "%s", gtk_label_get_text(GTK_LABEL(single_button_label[3])));
214
          gdk_threads_leave();
215
          flagback=1;
216
          is_back_selected = 1;
217
          break;
218
        }
219
       // Selected char
220
//       fprintf(fp, "C = %s\n",selected_char);
221
    }
222
  else if (scan_mode == 3)
223
    {
224
      char text_space[200];
225
      switch(iter3%mod_value)
226
        {
227
        case 1:
228
          strcpy(text_to_add, (char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
229
230
          strcpy(text_space,text_to_add);
231
          for (i=0 ; i < strlen(text_space); i++)
232
          if(text_space[i]==' ')
233
          text_space[i] = '-';
234
          if(selected_char[0] == ' ')
235
          fprintf(fp, "D  %s \n", text_space);
236
          else
237
          fprintf(fp, "W %s \n", text_space);
238
239
          is_word_selected = 1;
240
          enter_into_sentence_box();
241
          break;
242
        case 2:
243
          strcpy(text_to_add, (char *)gtk_entry_get_text(GTK_ENTRY(entry_label[1])));
244
    // Selected word
245
          strcpy(text_space,text_to_add);
246
          for (i=0 ; i < strlen(text_space); i++)
247
          if(text_space[i]==' ')
248
          text_space[i] = '-';
249
          if(selected_char[0] == ' ')
250
          fprintf(fp, "D  %s \n", text_space);
251
          else
252
          fprintf(fp, "W %s \n", text_space);
253
254
          is_word_selected = 1;
255
          enter_into_sentence_box();
256
          break;
257
        case 3:
258
          strcpy(text_to_add,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[2])));
259
    // Selected word
260
          strcpy(text_space,text_to_add);
261
          for (i=0 ; i < strlen(text_space); i++)
262
          if(text_space[i]==' ')
263
          text_space[i] = '-';
264
          if(selected_char[0] == ' ')
265
          fprintf(fp, "D  %s \n", text_space);
266
          else
267
          fprintf(fp, "W %s \n", text_space);
268
269
          is_word_selected = 1;
270
          enter_into_sentence_box();
271
          break;
272
        case 4:
273
          strcpy(text_to_add,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[3])));
274
    // Selected word
275
          strcpy(text_space,text_to_add);
276
          for (i=0 ; i < strlen(text_space); i++)
277
          if(text_space[i]==' ')
278
          text_space[i] = '-';
279
          if(selected_char[0] == ' ')
280
          fprintf(fp, "D  %s \n", text_space);
281
          else
282
          fprintf(fp, "W %s \n", text_space);
283
284
          is_word_selected = 1;
285
          enter_into_sentence_box();
286
          break;
287
        case 5:
288
          strcpy(text_to_add,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[4])));
289
    // Selected word
290
          strcpy(text_space,text_to_add);
291
          for (i=0 ; i < strlen(text_space); i++)
292
          if(text_space[i]==' ')
293
          text_space[i] = '-';
294
          if(selected_char[0] == ' ')
295
          fprintf(fp, "D  %s \n", text_space);
296
          else
297
          fprintf(fp, "W %s \n", text_space);
298
299
          is_word_selected = 1;
300
          enter_into_sentence_box();
301
          break;
302
        case 6:
303
          is_more_selected = 1;
304
          break;
305
        case 0:
306
          stg3_back_selected = 1;
307
          break;
308
        default:
309
          break;
310
        }
311
    }
312
  else if (scan_mode == 4)
313
    {
314
//         g_print ("##################################################################yes this is the place\n");
315
//    sleep(5);
316
      if (is_selected)
317
        {
318
          is_word_selected = 0;
319
          gdk_threads_enter();
320
          gtk_widget_modify_bg(single_button[5], GTK_STATE_NORMAL, &colorGray);
321
          gdk_threads_leave();
322
          is_erase_selected = 1;
323
          enter_into_sentence_box();
324
        }
325
      else
326
        {
327
          int i = 0;
328
          char string[300];
329
          gdk_threads_enter();
330
          gtk_widget_modify_bg(single_button[4], GTK_STATE_NORMAL, &green);
331
          gdk_threads_leave();
332
          iter1=0;
333
         // Done selected - sentence in word mode/word in spell mode formed.
334
          strcpy(string,((char *)gtk_entry_get_text(GTK_ENTRY(sentence_box))));
335
          string[strlen(string)-1]='\0'; // because space is added to senetence box
336
337
/* Restricting the length of the string to SLEN, which will be added logfile*/
338
          if (strlen(string) >SLEN)
339
          string[SLEN-1]='\0';
340
341
          for(i=0;i<strlen(string)-1;i++)
342
          if(string[i]==' ')
343
          string[i]='-';
344
          fprintf(fp, "D  %s\n" , string);//((char *)gtk_entry_get_text(GTK_ENTRY(sentence_box))));
345
           system("play rings/click.wav");
346
                read_out((char *)gtk_entry_get_text(GTK_ENTRY(sentence_box)));
347
          system("play rings/click.wav");
348
349
          for (i=0; i <= current_index; i++)
350
              strcpy (text_array[i], "");
351
    current_index = 0;
352
    spell_index = 0;
353
          is_word_selected = 0;
354
          is_done_selected = 1;
355
//          gtk_widget_modify_bg(single_button[4], GTK_STATE_NORMAL, &colorGray);
356
//          g_print ("yes this is the placelllll \\n");
357
          prev_scan_mode = 1;
358
          while (check_for_user_input() == 0)
359
            ;
360
          gdk_threads_enter();
361
          gtk_entry_set_text(GTK_ENTRY(sentence_box),"");
362
          for(index = 0; index < 5; index++)
363
          gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
364
          gdk_threads_leave();
365
        }
366
    }
367
368
  if(is_word_selected)
369
    scan_mode = 4;
370
  else if(is_more_selected)
371
    scan_mode = 3;
372
  else if (stg3_back_selected)
373
    scan_mode = 2;
374
  else if (is_back_selected)
375
  {
376
        scan_mode = 1;
377
  }
378
  else if(spell_mode && scan_mode == 1 && !change_mode)
379
        scan_mode = 2;
380
  else if(spell_mode && scan_mode == 2  && !change_mode)
381
  {
382
        strcpy(text_to_add,selected_char);
383
        enter_into_sentence_box();
384
        scan_mode = 4;
385
  }
386
  else if (change_mode)
387
  {
388
389
    if(spell_mode)
390
    {
391
        for(index = 0; index < 5; index++)
392
                gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
393
394
    }
395
    else
396
    {
397
      for(index = 0; index < 5; index++)
398
        gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
399
//      gtk_entry_set_text(GTK_ENTRY(entry_label[5]), "MORE");
400
//      gtk_entry_set_text(GTK_ENTRY(entry_label[6]), "BACK");
401
      current_index++;
402
      spell_index = 0;
403
    }
404
    scan_mode = 1;
405
    change_mode = 0;
406
407
  }
408
  else if(!spell_mode)
409
    scan_mode = (scan_mode % 4) +1;
410
  else if(is_done_selected)
411
     scan_mode = 1;
412
}
413
414
/*
415
Using spell mode once the word construction is done this method is called.
416
If the formed word is found in the dictionary, the wav file is played.
417
Otherwise, the text to speech synthesis is done and the word is read out.
418
*/
419
420
void spell_out(char * string_to_read)
421
{
422
/*  int i = 0;
423
  char total_string [400];
424
  char prefix[20] = "wav/";
425
  int wordlen = strlen(string_to_read);
426
  int len;
427
  strcpy (total_string,"./playit.sh ");
428
  len=strlen(total_string);
429
  for(i=0;i<wordlen;i++)
430
    {
431
      if(string_to_read[i] == '#')
432
        {
433
// strcpy(prefix,"wav/");
434
          if(spell_mode)
435
            strcpy(prefix,"word");
436
          else
437
            strcpy(prefix,"spell");
438
        }
439
      else
440
        {
441
          prefix[4]= tolower(string_to_read[i]);
442
          prefix[5] ='\0';
443
        }
444
//      strcat(total_string, prefix);
445
//      strcat(total_string,".wav ");
446
//      strcpy (total_string,"./playit.sh ");
447
      total_string[len++]=string_to_read[i];
448
      total_string[len++]=',';
449

450
    }
451

452
      total_string[len++]='\0';
453
  if(string_to_read[2]== '#')
454
    {
455
     strcpy(total_string,"./playit.sh y,z,");
456
     strcat(total_string,prefix);
457
     }
458
    system(total_string);
459
  g_print ("The total string is %s\n",total_string);
460
//  strcat (total_string, " -o out.wav");
461
//  system(total_string);
462
//  system("play out.wav");*/
463
int i = 0;
464
  char total_string [100];
465
  char prefix[20] = "a";
466
  int wordlen = strlen(string_to_read);
467
468
  if(string_to_read[0] == 1 || string_to_read[0] == 2 || string_to_read[0] == 3)
469
    {
470
      system("./playit.sh template");
471
      return;
472
    }
473
474
475
  for(i=0;i<wordlen;i++)
476
    {
477
//      strcpy (total_string,"mplayer -quiet -af volume=20 wav/");
478
      strcpy (total_string,"./playit.sh ");
479
      if(string_to_read[i] == '#')
480
        {
481
/*          if(spell_mode)
482
            strcpy(prefix,"word");
483
          else
484
            strcpy(prefix,"spell"); */
485
            strcpy(prefix,"done");
486
        }
487
      else
488
        {
489
          prefix[0]= tolower(string_to_read[i]);
490
          prefix[1] ='\0';
491
        }
492
      strcat(total_string, prefix);
493
//      strcat(total_string,".mp3 ");
494
//      g_print ("%s\n",total_string);
495
     system(total_string);
496
497
//      sleep(1);
498
    }
499
//  strcat (total_string, " -o out.wav");
500
//  system(total_string);
501
//  system("play out.wav");
502
503
504
505
}
506
507
/*
508
This is method is called in the word mode. This is to read the final sentence
509
formed after pressing the DONE button.
510
*/
511
512
void read_sentence(char * sentence)
513
{
514
  char *token;
515
  char * temp = (char *) malloc ((strlen(sentence)+1)*sizeof(char));
516
  strcpy(temp,sentence);
517
  token = strtok(temp, " ");
518
  while (token != NULL)
519
    {
520
      read_out(token);
521
      token = strtok(NULL, " ");
522
    }
523
  free (temp);
524
}
525
526
/*
527
This is method is called in the word mode. This is to read the list of words
528
available in level 3.
529
*/
530
531
void read_out(char * string_to_read)
532
{
533
  char tmp_string [200];
534
  int i = 0, length = 0;
535
  char total_string [400];
536
  strcpy (tmp_string,string_to_read);
537
  for (i=0 ; i < strlen(tmp_string); i++)
538
               if(tmp_string[i]==' ')
539
               tmp_string[i] = '-';
540
541
  length = strlen(tmp_string);
542
  for(i = 0; i < length; i++)
543
    {
544
      if((tmp_string[i] != '-') && (tmp_string[i] != '#'))
545
              tmp_string[i] += 32;
546
      if(tmp_string[i] == '#')
547
        {
548
//--          if(!spell_mode)
549
//--            strcpy(tmp_string,"spell");
550
//--          else
551
            strcpy (tmp_string,"done");
552
      }
553
    }
554
  strcpy (total_string,"./playit.sh  ");
555
  strcat(total_string,tmp_string);
556
  system(total_string);
557
  g_print ("The total string is %s\n",total_string);
558
559
}
560
561
/*
562
This method is to add/delete the words/letters in the selected box. (the
563
box which shows the selected words/letters)
564
*/
565
void enter_into_sentence_box ()
566
{
567
  char concatenated_text[300] = "";
568
  int i;
569
570
// g_print ("ghjdgfdgsfjbg ---%d\n",flagspace );
571
   if (is_erase_selected)
572
    if (spell_mode && (spell_index))
573
       text_array[current_index][--spell_index] = 0;
574
    else
575
    {
576
       strcpy(text_array[current_index-1], "");
577
             strcpy(text_array[current_index], "");
578
       if (current_index != 0)
579
         current_index--;
580
//     printf ("I think it will come here :%d...........................\n",flagpridict);
581
   }
582
  else
583
    if (spell_mode)
584
     {
585
       text_array[current_index][spell_index++] = text_to_add[0];
586
       text_array[current_index][spell_index] = 0;
587
     }
588
/*   else if(flagspace == 1 )
589
      {
590
//       strcpy(text_array[current_index][spell_index++]," ");
591
//       text_array[current_index][spell_index++]=' ';
592
        text_array[current_index][spell_index++] = ' ';
593
        flagspace = 0;
594
      }*/
595
     else
596
       strcpy(text_array[current_index++],text_to_add);
597
598
  for(i=0; i <= current_index; i++)
599
    {
600
      strcat(concatenated_text,text_array[i]);
601
      strcat(concatenated_text," ");
602
    }
603
604
  gtk_entry_set_text(GTK_ENTRY(sentence_box),(gchar *)concatenated_text);
605
  fclose(fp);
606
607
/* Calling the function update_user_dictionary to maintain a user local dictionary. */
608
609
  update_user_dictionary(dir_name) ;
610
611
  fp=fopen(logfile,"a");
612
}
613
614
/*
615
This is the method that keeps on running in a thread which scans the
616
buttons/labels at each level according to the requirements.
617
*/
618
619
void *button_selection (void *args)
620
{
621
  yes_or_no_args *data = (yes_or_no_args *)args;
622
  gboolean say_something;
623
  guint word_count = 0;
624
  int label_iter = 1, index = 0;
625
626
  while (1)
627
    {
628
      if(scan_mode == 1)
629
        {
630
          gdk_threads_enter();
631
          if(flagback==1)
632
          {
633
           data->index-=3;
634
           iter1-=3;
635
//g_print ("data->index  and iter1+++++++++++++++++++++++++++ : %d and :%d\n",data->index,iter1);
636
           if(iter1 == -2)
637
           {iter1=8;
638
            data->index=7;
639
           }
640
           if(iter1 == -1)
641
           {
642
            iter1=9;
643
            data->index=8;
644
           }
645
           if(iter1 == 0)
646
           data->index=9;
647
           if(data->index == -3)
648
           data->index=8;
649
           flagback=0;
650
          }
651
652
//          gtk_widget_modify_bg(button[data->index],GTK_STATE_NORMAL,&colorRed);
653
          gtk_widget_modify_bg(single_button[2], GTK_STATE_NORMAL, &colorGray);
654
          gtk_widget_modify_bg(single_button[3], GTK_STATE_NORMAL, &colorGray);
655
          gtk_widget_modify_bg(single_button[4], GTK_STATE_NORMAL, &colorGray);
656
          gtk_widget_modify_bg(single_button[5], GTK_STATE_NORMAL, &colorGray);
657
          gdk_threads_leave();
658
659
          is_word_selected = 0;
660
          is_more_selected = 0;
661
          is_back_selected = 0;
662
663
664
          say_something = 1;// (yes_or_no != data->what);
665
666
          if(say_something)
667
            {
668
              /* set the variable */
669
              yes_or_no = data->what;
670
            }
671
672
          if (say_something)
673
            {
674
              /* set label text */
675
              if(data->what == NO_IT_IS_NOT)
676
                {
677
                  int index = iter1%10;
678
679
                   gchar string[7];
680
                  string[1] = '\0';
681
                     gdk_threads_enter ();
682
                  gtk_widget_modify_bg(button[data->index],GTK_STATE_NORMAL,&colorRed);
683
//g_print ("data->index---------------------------------- : %d\n",data->index);
684
                  data->what = YES_IT_IS;
685
                  if(index == 0)
686
                    {
687
                      index = 10;
688
                    }
689
                  string[0] = label[index-1][0];
690
                  if(string[0] == '1')
691
                  strcpy(string," TEMP");
692
                  gtk_label_set_text(GTK_LABEL(single_button_label[0]), string);
693
                  string[0] = label[index-1][1];
694
                  if(string[0] == '2')
695
                  strcpy(string,"UNDO");
696
                  gtk_label_set_text(GTK_LABEL(single_button_label[1]), string);
697
                  string[0] = label[index-1][2];
698
                  if(string[0] == '3')
699
                  strcpy(string,"     ");
700
                  gtk_label_set_text(GTK_LABEL(single_button_label[2]), string);
701
702
                  gdk_threads_leave ();
703
                  if(index==10)
704
                  system ("./playit.sh tem,plate");
705
                  else
706
                  spell_out(label[index-1]);
707
                  if(check_for_user_input())
708
                    callback();
709
                }
710
              else
711
                {
712
                  if(scan_mode == 1)
713
                    {
714
                      gdk_threads_enter ();
715
                      gtk_widget_modify_bg(button[data->index],GTK_STATE_NORMAL,&colorGray);
716
                      data->index = (iter1++)%10;
717
                      gdk_threads_leave ();
718
                    }
719
                  data->what = NO_IT_IS_NOT;
720
                   }
721
            }
722
          iter2=0;
723
        }
724
      else if (scan_mode == 2)
725
        { int i;
726
          stg3_back_selected = 0;
727
          gdk_threads_enter ();
728
//          gtk_widget_modify_base(entry_label[6], GTK_STATE_NORMAL, &colorGray);
729
          for(i=0;i<10;i++)
730
          gtk_widget_modify_bg(button[i],GTK_STATE_NORMAL,&colorGray);
731
          gtk_widget_modify_bg (backbutton, GTK_STATE_NORMAL, &colorGray);
732
          gdk_threads_leave ();
733
          switch(iter2%4)
734
            {
735
            case 0:
736
              gdk_threads_enter ();
737
              gtk_widget_modify_bg(single_button[0],GTK_STATE_NORMAL,&colorRed);
738
              gtk_widget_modify_bg(single_button[3],GTK_STATE_NORMAL,&colorGray);
739
              gdk_threads_leave ();
740
              read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[0])));
741
              if(check_for_user_input())
742
                callback();
743
              iter2++;
744
              break;
745
            case 1:
746
              gdk_threads_enter ();
747
              gtk_widget_modify_bg(single_button[1],GTK_STATE_NORMAL,&colorRed);
748
              gtk_widget_modify_bg(single_button[0],GTK_STATE_NORMAL,&colorGray);
749
              gdk_threads_leave ();
750
              read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[1])));
751
              if(check_for_user_input())
752
                callback();
753
              iter2++;
754
              break;
755
            case 2:
756
              gdk_threads_enter ();
757
              gtk_widget_modify_bg(single_button[2],GTK_STATE_NORMAL,&colorRed);
758
              gtk_widget_modify_bg(single_button[1],GTK_STATE_NORMAL,&colorGray);
759
              gdk_threads_leave ();
760
              read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[2])));
761
              if(check_for_user_input())
762
                callback();
763
              iter2++;
764
              break;
765
            case 3:
766
              gdk_threads_enter ();
767
              gtk_widget_modify_bg(single_button[3],GTK_STATE_NORMAL,&colorRed);
768
              gtk_widget_modify_bg(single_button[2],GTK_STATE_NORMAL,&colorGray);
769
              gdk_threads_leave ();
770
              read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[3])));
771
              if(check_for_user_input())
772
                callback();
773
              if(!is_back_selected)
774
              {
775
                  prev_scan_mode = 2;
776
                  scan_mode = 4;
777
              }
778
              iter2++;
779
              break;
780
            }
781
          iter3=1;
782
          label_iter = 1;
783
          mod_value = 7;
784
        }
785
      else if (scan_mode == 3)
786
        {
787
          gchar returnString[MAX_STR_LEN];
788
789
          gdk_threads_enter();
790
          for(index = 0; index < 6; index++)
791
            gtk_widget_modify_bg(single_button[index],GTK_STATE_NORMAL,&colorGray);
792
          gdk_threads_leave();
793
794
          if(iter3 == 1)
795
            {
796
              word_count = init_query(selected_char);
797
              if (flagpridict ==1)
798
              strcpy (selected_char,strpridict);
799
              gdk_threads_enter();
800
              gtk_entry_set_text(GTK_ENTRY(entry_label[0]),selected_char);
801
              gdk_threads_leave();
802
              if(word_count > 0)
803
                  for(index =1; index < 5; index ++)
804
                    {
805
                      run_query(returnString,label_iter++);
806
                      gdk_threads_enter();
807
                      gtk_entry_set_text(GTK_ENTRY(entry_label[index]),returnString);
808
                      gdk_threads_leave();
809
                    }
810
              else
811
                 {
812
                  gdk_threads_enter();
813
                  for(index = 1; index < 5; index++)
814
                  gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
815
                  gdk_threads_leave();
816
                 }
817
            }
818
          if(label_iter > word_count)
819
            {
820
              is_more_selected = 0;
821
              mod_value = word_count+2;
822
//              printf ("------------------------------------%d",mod_value);
823
            }
824
          else if(is_more_selected)
825
            {
826
                  int diff = word_count - label_iter;
827
                  if(diff > 5)
828
                     for(index =1; index < 5; index ++)
829
                      {
830
                      run_query(returnString,label_iter++);
831
                      gdk_threads_enter();
832
                      gtk_entry_set_text(GTK_ENTRY(entry_label[index]),returnString);
833
                      gdk_threads_leave();
834
                    }
835
                   else
836
                   {
837
                      for(index = 1; index <diff; index++)
838
                      {
839
                         run_query(returnString,label_iter++);
840
                         gdk_threads_enter();
841
                         gtk_entry_set_text(GTK_ENTRY(entry_label[index]),returnString);
842
                         gdk_threads_leave();
843
                      }
844
                      for(; index < 5 ; index++)
845
                      {
846
                         gdk_threads_enter();
847
                         gtk_entry_set_text(GTK_ENTRY(entry_label[index])," ");
848
                         gdk_threads_leave();
849
                      }
850
                      mod_value = diff + 1;
851
//          printf ("%d------------%d----------\n",mod_value,diff);
852
853
                   }
854
              is_more_selected = 0;
855
              iter3 = 1;
856
              gdk_threads_enter();
857
//              gtk_widget_modify_bg(entry_label[5], GTK_STATE_NORMAL, &colorGray);
858
              gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
859
              gdk_threads_leave();
860
            }
861
          char spacestr[100];
862
           int ind;
863
//          printf ("%d------------%d----------%d\n",iter3,mod_value,no_of_results);
864
                  if (selected_char[0] == ' ')
865
                     {
866
                       if((iter3%mod_value) == 1)
867
                         iter3=2;
868
                      gdk_threads_enter();
869
                      for(index = 1; index < 5; index++)
870
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
871
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
872
                      gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
873
                      gdk_threads_leave();
874
                     }
875
          switch(iter3%mod_value)
876
            {
877
            case 1:
878
              gdk_threads_enter();
879
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&colorRed);
880
881
              for(index = 0; index < 5; index++)
882
                  if(index != 0)
883
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
884
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
885
                      gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
886
887
              gdk_threads_leave();
888
              strcpy(spacestr,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
889
               for (ind=0 ; ind < strlen(spacestr); ind++)
890
               if(spacestr[ind]==' ')
891
               spacestr[ind] = '-';
892
//               g_print ("the string  is : %s \n",spacestr);
893
               read_out(spacestr);
894
              //read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[0])));
895
              if(check_for_user_input())
896
                {
897
                  iter1=0;
898
                  flagpridict=1;
899
                  strcpy(strpridict,spacestr);
900
                  scan_mode=0;
901
                  printf("before callback\n");
902
                  callback();
903
                  printf("after callback\n");
904
                }
905
              iter3++;
906
              break;
907
            case 2:
908
              gdk_threads_enter();
909
              gtk_widget_modify_base(entry_label[1], GTK_STATE_NORMAL,&colorRed);
910
              for(index = 0; index < 5; index++)
911
                  if(index != 1)
912
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
913
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
914
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
915
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
916
917
              gdk_threads_leave();
918
              strcpy(spacestr,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[1])));
919
               for (ind=0 ; ind < strlen(spacestr); ind++)
920
               if(spacestr[ind]==' ')
921
               spacestr[ind] = '-';
922
//               g_print ("the string  is : %s \n",spacestr);
923
               read_out(spacestr);
924
//              read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[1])));
925
              if(check_for_user_input())
926
                callback();
927
              iter3++;
928
              break;
929
            case 3:
930
              gdk_threads_enter();
931
              gtk_widget_modify_base(entry_label[2], GTK_STATE_NORMAL,&colorRed);
932
              for(index = 0; index < 5; index++)
933
                  if(index != 2)
934
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
935
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
936
                      gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
937
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
938
939
              gdk_threads_leave();
940
              strcpy(spacestr,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[2])));
941
               for (ind=0 ; ind < strlen(spacestr); ind++)
942
               if(spacestr[ind]==' ')
943
               spacestr[ind] = '-';
944
//               g_print ("the string  is : %s \n",spacestr);
945
               read_out(spacestr);
946
//              read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[2])));
947
              if(check_for_user_input())
948
                callback();
949
              iter3++;
950
              break;
951
            case 4:
952
              gdk_threads_enter();
953
              gtk_widget_modify_base(entry_label[3], GTK_STATE_NORMAL,&colorRed);
954
              for(index = 0; index < 5; index++)
955
                  if(index != 3)
956
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
957
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
958
                      gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
959
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
960
961
              gdk_threads_leave();
962
              strcpy(spacestr,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[3])));
963
               for (ind=0 ; ind < strlen(spacestr); ind++)
964
               if(spacestr[ind]==' ')
965
               spacestr[ind] = '-';
966
//               g_print ("the string  is : %s \n",spacestr);
967
               read_out(spacestr);
968
//              read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[3])));
969
              if(check_for_user_input())
970
                                        callback();
971
              iter3++;
972
              break;
973
            case 5:
974
              gdk_threads_enter();
975
              gtk_widget_modify_base(entry_label[4], GTK_STATE_NORMAL,&colorRed);
976
              for(index = 0; index < 5; index++)
977
                  if(index != 4)
978
                      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
979
                      gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
980
                      gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
981
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
982
983
              gdk_threads_leave();
984
              strcpy(spacestr,(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[4])));
985
               for (ind=0 ; ind < strlen(spacestr); ind++)
986
               if(spacestr[ind]==' ')
987
               spacestr[ind] = '-';
988
//               g_print ("the string  is : %s \n",spacestr);
989
               read_out(spacestr);
990
//              read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[4])));
991
              if(check_for_user_input())
992
                callback();
993
              iter3++;
994
              break;
995
            case 6:
996
              gdk_threads_enter();
997
//              gtk_widget_modify_base(entry_label[5], GTK_STATE_NORMAL,&colorRed);
998
              gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL,&colorRed);
999
              for(index = 0; index < 5; index++)
1000
              gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
1001
              gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
1002
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
1003
1004
              gdk_threads_leave();
1005
//            read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[5])));
1006
              read_out ("MORE");
1007
              if(check_for_user_input())
1008
                    callback();
1009
              iter3++;
1010
              break;
1011
            case 0:
1012
              gdk_threads_enter();
1013
//              gtk_widget_modify_base(entry_label[6], GTK_STATE_NORMAL,&colorRed);
1014
              gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL,&colorRed);
1015
              for(index = 0; index < 5; index++)
1016
              gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
1017
              gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
1018
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
1019
1020
              gdk_threads_leave();
1021
//              read_out((char *)gtk_entry_get_text(GTK_ENTRY(entry_label[6])));
1022
              read_out("BACK");//(char *)gtk_entry_get_text(GTK_ENTRY(entry_label[6])));
1023
              if(check_for_user_input())
1024
                {
1025
                 if (flagpridict == 1 )
1026
                   {
1027
                    int len=strlen(strpridict);
1028
                    strpridict[len-1]='\0';
1029
                    gdk_threads_enter();
1030
                    gtk_entry_set_text(GTK_ENTRY(entry_label[0]), strpridict);
1031
                    gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL, &yellow);
1032
                    gdk_threads_leave();
1033
                   }
1034
                 else
1035
                   {
1036
                     gdk_threads_enter();
1037
                     for(index = 0; index < 5; index++)
1038
                     gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
1039
                     gdk_threads_leave();
1040
                   }
1041
                 callback();
1042
                }
1043
              iter3++;
1044
              break;
1045
            }
1046
1047
//          gdk__threads_leave();
1048
1049
        }
1050
      else if (scan_mode == 4)
1051
        {
1052
          gdk_threads_enter ();
1053
//         sleep(2);
1054
//g_print("test maadi");
1055
          for(index = 0; index < 5; index++)
1056
              gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
1057
              gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
1058
              gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
1059
              gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
1060
1061
          gdk_threads_leave ();
1062
1063
          gdk_threads_enter ();
1064
          for(index =0; index < 4; index++)
1065
            gtk_widget_modify_bg(single_button[index],GTK_STATE_NORMAL,&colorGray);
1066
          gdk_threads_leave ();
1067
1068
          //for DONE button
1069
1070
          is_selected = 0;
1071
          gdk_threads_enter ();
1072
          gtk_widget_modify_bg(single_button[4],GTK_STATE_NORMAL,&colorRed);
1073
          gtk_widget_modify_bg(single_button[5],GTK_STATE_NORMAL,&colorGray);
1074
          gdk_threads_leave ();
1075
          read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[4])));
1076
          sleep(1);
1077
1078
          if(check_for_user_input())
1079
            callback();
1080
1081
          if(is_done_selected)
1082
            {
1083
              scan_mode = 1;
1084
              is_done_selected = 0;
1085
     g_print ("check here\n");
1086
            }
1087
          else
1088
            {
1089
              //for ERASE button
1090
              is_selected = 1;
1091
              gdk_threads_enter ();
1092
              gtk_widget_modify_bg(single_button[5],GTK_STATE_NORMAL,&colorRed);
1093
              gtk_widget_modify_bg(single_button[4],GTK_STATE_NORMAL,&colorGray);
1094
              gdk_threads_leave ();
1095
              read_out((char *)gtk_label_get_text(GTK_LABEL(single_button_label[5])));
1096
              if(check_for_user_input())
1097
               {
1098
                  if (flagpridict == 1)
1099
                   {
1100
//                  gtk_entry_set_text(GTK_ENTRY(entry_label[0]),strpridict);
1101
//                    scan_mode=3;
1102
                    strcpy(selected_char ,"");
1103
                   }
1104
                  callback();
1105
               }
1106
            }
1107
          if(!is_erase_selected)
1108
            {
1109
              g_print("test maadi --1\n");
1110
//              flagpridict=0;
1111
//---              strcpy(strpridict,"");
1112
              if((prev_scan_mode == 2) && (!is_done_selected))
1113
                {
1114
              g_print("test maadi --2\n");
1115
                  gdk_threads_enter();
1116
                  gtk_widget_modify_bg(single_button[5],GTK_STATE_NORMAL,&colorGray);
1117
                  gdk_threads_leave();
1118
                  prev_scan_mode = 1;
1119
                  scan_mode = 2;
1120
                }
1121
              else
1122
                {
1123
              g_print("test maadi --3\n");
1124
                  gdk_threads_enter();
1125
                  for(index = 0; index < 5; index++)
1126
                  gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
1127
                  gdk_threads_leave();
1128
                  scan_mode = 1;
1129
                  flagpridict=0;
1130
                  strcpy(strpridict,"");
1131
                }
1132
            }
1133
          else
1134
            {
1135
              g_print("test maadi --4\n");
1136
              if(!spell_mode)
1137
                if(prev_scan_mode == 2)
1138
                {
1139
                    g_print("test maadi --5 PS : %d  SM %d\n",scan_mode , prev_scan_mode);
1140
                    scan_mode = prev_scan_mode;
1141
                    gdk_threads_enter();
1142
                    gtk_widget_modify_bg(single_button[5],GTK_STATE_NORMAL,&colorGray);
1143
                    gdk_threads_leave();
1144
                }
1145
                else
1146
                {
1147
                    scan_mode = 3;
1148
                    if (selected_char[0] == '#')
1149
                    scan_mode = 1;
1150
                    g_print("test maadi --6 %s\n",selected_char);
1151
                }
1152
              else
1153
                {
1154
                   scan_mode = 2;
1155
                   g_print("test maadi --7\n");
1156
                }
1157
              is_erase_selected = 0;
1158
            }
1159
        }
1160
    }
1161
  return NULL;
1162
}
1163
1164
/*
1165
This is to create buttons for level 2 and DONE and ERASE.
1166
*/
1167
1168
static void create_single_button()
1169
{
1170
  GtkWidget *box;
1171
  int index;
1172
1173
  for(index = 0; index < 6; index++)
1174
    {
1175
      single_button[index] = gtk_button_new();
1176
      box = gtk_vbox_new(FALSE,0);
1177
1178
      if(index == 3)
1179
        {
1180
         single_button_label[index] = gtk_label_new("BACK");
1181
//         gtk_widget_modify_font (single_button_label[index], font_desc);
1182
//         gtk_widget_modify_fg (single_button_label[index], GTK_STATE_NORMAL, &blue);
1183
        }
1184
      else if(index == 4)
1185
        {
1186
         single_button_label[index] = gtk_label_new("DONE");
1187
//         gtk_widget_modify_font (single_button_label[index], font_desc);
1188
//         gtk_widget_modify_fg (single_button_label[index], GTK_STATE_NORMAL, &blue);
1189
        }
1190
      else if(index == 5)
1191
        {
1192
         single_button_label[index] = gtk_label_new("ERASE");
1193
//         gtk_widget_modify_font (single_button_label[index], font_desc);
1194
//         gtk_widget_modify_fg (single_button_label[index], GTK_STATE_NORMAL, &blue);
1195
        }
1196
      else
1197
        single_button_label[index] = gtk_label_new(" ");
1198
1199
      gtk_box_pack_start (GTK_BOX (box), single_button_label[index], FALSE, FALSE, 3);
1200
      gtk_widget_show(single_button_label[index]);
1201
      gtk_widget_show(box);
1202
      gtk_container_add (GTK_CONTAINER (single_button[index]), box);
1203
      if(index == 4 || index == 5)
1204
        gtk_table_attach_defaults (GTK_TABLE (table),single_button[index], 9, 10, index, index+1);
1205
       else
1206
        gtk_table_attach_defaults (GTK_TABLE (table), single_button[index], 0, 1, index+3, index+4);
1207
1208
      gtk_widget_show(single_button[index]);
1209
    }
1210
}
1211
1212
/*
1213
This is to create the labels in level 3.
1214
*/
1215
void create_labels()
1216
{
1217
  int index;
1218
1219
  for(index = 0; index < 5; index ++)
1220
    {
1221
      entry_label[index] = gtk_entry_new_with_max_length(MAX_STR_LEN);
1222
//      gtk_widget_modify_text (entry_label[index], GTK_STATE_NORMAL, &blue);
1223
//      gtk_widget_modify_font ((entry_label[index]), font_desc);
1224
      gtk_entry_set_editable(GTK_ENTRY(entry_label[index]), FALSE);
1225
      gtk_widget_modify_base(entry_label[index], GTK_STATE_NORMAL, &colorGray);
1226
      gtk_table_attach_defaults (GTK_TABLE (table), entry_label[index], 2, 8, index+2,index+3);
1227
1228
/*    if(index == 5)
1229
      {
1230
        if(!spell_mode)
1231
                gtk_entry_set_text(GTK_ENTRY(entry_label[index]), "MORE");
1232
        else
1233
                gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
1234
      }
1235
      else if(index == 6)
1236
      {
1237
        if(!spell_mode)
1238
                gtk_entry_set_text(GTK_ENTRY(entry_label[index]), "BACK");
1239
        else
1240
                gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
1241
      }
1242
      else
1243
        gtk_entry_set_text(GTK_ENTRY(entry_label[index]), " ");
1244
  */
1245
      gtk_widget_show (entry_label[index]);
1246
    }
1247
  gtk_widget_modify_base(entry_label[0], GTK_STATE_NORMAL,&yellow);
1248
  morebutton = gtk_button_new_with_label("MORE");
1249
//  gtk_widget_modify_font (GTK_BIN (morebutton)->child, font_desc);
1250
//  gtk_widget_modify_fg (GTK_BIN (morebutton)->child, GTK_STATE_NORMAL, &blue);
1251
  gtk_table_attach_defaults (GTK_TABLE (table), morebutton, 2, 5, 7,8);
1252
  gtk_widget_modify_bg(morebutton, GTK_STATE_NORMAL, &colorGray);
1253
  gtk_widget_show (morebutton);
1254
1255
  backbutton = gtk_button_new_with_label("BACK");
1256
//  gtk_widget_modify_font (GTK_BIN (backbutton)->child, font_desc);
1257
//  gtk_widget_modify_fg (GTK_BIN (backbutton)->child, GTK_STATE_NORMAL, &blue);
1258
  gtk_table_attach_defaults (GTK_TABLE (table), backbutton, 5, 8, 7,8);
1259
  gtk_widget_modify_bg(backbutton, GTK_STATE_NORMAL, &colorGray);
1260
  gtk_widget_show (backbutton);
1261
1262
  sentence_box = gtk_entry_new_with_max_length(200);
1263
//  gtk_widget_modify_font ((sentence_box), font_desc);
1264
//  gtk_widget_modify_text (sentence_box, GTK_STATE_NORMAL, &blue);
1265
  gtk_entry_set_editable(GTK_ENTRY(sentence_box), FALSE);
1266
  gtk_entry_set_text(GTK_ENTRY(sentence_box)," ");
1267
//  gtk_widget_modify_base(sentence_box, GTK_STATE_NORMAL, &colorGray);
1268
  gtk_table_attach_defaults (GTK_TABLE (table), sentence_box, 0, 10, 8, 9);
1269
  gtk_widget_grab_focus (sentence_box);
1270
  gtk_widget_show (sentence_box);
1271
}
1272
1273
/*
1274
The pos signifies the position of the word in the list of words
1275
in res.txt. resultAt.txt gives the word at pos.
1276
*/
1277
1278
void run_query(char *string, int pos)
1279
{
1280
  FILE *fid = NULL;
1281
  char cmd[300];
1282
  char str[3];
1283
  int ind;
1284
  if( pos > no_of_results )
1285
    {
1286
      strcpy(string,"");
1287
      return;
1288
    }
1289
  strcpy (cmd, "cat res.txt | head -");
1290
  sprintf (str, "%d" , pos);
1291
  strcat (cmd, str);
1292
  strcat (cmd, " | tail -1 > resultAt.txt");
1293
  system (cmd);
1294
1295
  fid = fopen("resultAt.txt","r");
1296
  fscanf(fid,"%s",string);
1297
//  printf("---> %s pos %d no_of_res %d\n",string,pos,no_of_results);
1298
  fclose(fid);
1299
  for(ind=0;ind<strlen(string);ind++)
1300
  if(string[ind]=='-')
1301
  string[ind] = ' ';
1302
   return;
1303
}
1304
1305
/*
1306
This is to clean the query and reset the variables.
1307
*/
1308
1309
void clean_query(void)
1310
{
1311
  no_of_results = 0;
1312
  memset(query_string,0,MAX_LEN);
1313
  return;
1314
}
1315
1316
/*This is to check the dictionary and find out the list of words. The number of
1317
words resulted from the query is given in resNo.txt and the words are given
1318
in res.txt.
1319
*/
1320
1321
int init_query(char *qString)
1322
{
1323
  char cmd[100];
1324
  char spcmd[2200];
1325
  char cmd_new[200];
1326
  FILE *fid = NULL;
1327
1328
  fclose(fp);
1329
  if (qString[0]== ' ')
1330
  {
1331
   strcpy(qString," ");
1332
   strcpy(strpridict,"");
1333
   strcpy (spcmd, "grep -h '^D");
1334
  }
1335
  else
1336
  strcpy (spcmd, "grep -h '^W ");
1337
1338
  if (flagpridict == 1)
1339
  {
1340
     strcat(strpridict,qString);
1341
//     printf ("------------------> %s\n",strpridict);
1342
     strcpy(qString,strpridict);
1343
//     printf ("------------------> %s\n",qString);
1344
  }
1345
1346
  strcat(spcmd, qString);
1347
  strcat (spcmd, "' ");
1348
  strcat (spcmd, dir_name);
1349
  strcat (spcmd, "/logs/* | sort | uniq -c | sort -n -r  | awk '{print $3}' > res1.txt");
1350
/*for showing words used to all users */
1351
//--- : for showing words to all users:  strcat (spcmd, "-r users/* | sort | uniq -c | sort -n -r  | awk '{print $3}' > res1.txt");
1352
//  printf ("---> %s\n",spcmd);
1353
  system (spcmd);
1354
  system ("cp res1.txt res.txt");
1355
1356
1357
  strcpy (query_string, qString);
1358
  strcpy (cmd, "grep  ""^");
1359
  strcat (cmd, qString);
1360
  strcat (cmd, """ ");
1361
  switch(query_string[0])
1362
    {
1363
    case 'A':
1364
    case 'B':
1365
    case 'C':
1366
//      strcat (cmd, "dict/abc.txt");
1367
      strcat (cmd, "dict/A2Zwordslist.txt");
1368
      break;
1369
    case 'D':
1370
    case 'E':
1371
    case 'F':
1372
//      strcat (cmd, "dict/def.txt");
1373
      strcat (cmd, "dict/A2Zwordslist.txt");
1374
      break;
1375
    case 'G':
1376
    case 'H':
1377
    case 'I':
1378
//      strcat (cmd, "dict/ghi.txt");
1379
      strcat (cmd, "dict/A2Zwordslist.txt");
1380
      break;
1381
    case 'J':
1382
    case 'K':
1383
    case 'L':
1384
//      strcat (cmd, "dict/jkl.txt");
1385
      strcat (cmd, "dict/A2Zwordslist.txt");
1386
      break;
1387
    case 'M':
1388
    case 'N':
1389
    case 'O':
1390
//      strcat (cmd, "dict/mno.txt");
1391
      strcat (cmd, "dict/A2Zwordslist.txt");
1392
      break;
1393
    case 'P':
1394
    case 'Q':
1395
    case 'R':
1396
//      strcat (cmd, "dict/pqr.txt");
1397
      strcat (cmd, "dict/A2Zwordslist.txt");
1398
      break;
1399
    case 'S':
1400
    case 'T':
1401
    case 'U':
1402
//      strcat (cmd, "dict/stu.txt");
1403
      strcat (cmd, "dict/A2Zwordslist.txt");
1404
      break;
1405
    case 'V':
1406
    case 'W':
1407
    case 'X':
1408
    case 'Y':
1409
    case 'Z':
1410
//      strcat (cmd, "dict/vwxyz.txt");
1411
      strcat (cmd, "dict/A2Zwordslist.txt");
1412
      break;
1413
    case '1':
1414
    case '2':
1415
    case '3':
1416
      strcat(cmd, "dict/temp.txt");
1417
      break;
1418
    default:
1419
      strcat(cmd, "dict/temp.txt");
1420
      break;
1421
    }
1422
1423
  strcat (cmd, "> let.txt");
1424
  system (cmd);
1425
  system ("cat res1.txt let.txt > res2.txt");
1426
  system ("cat res2.txt res1.txt | sort | uniq -u >> res.txt");
1427
//  printf("---> %s\n",cmd);
1428
//  strcat (cmd_new, " | wc -l > resNo.txt");
1429
  strcpy (cmd_new, "grep -c ^");
1430
  strncat(cmd_new,qString,1);
1431
  strcat (cmd_new," res.txt > resNo.txt");
1432
  system (cmd_new);
1433
//  printf("---> %s\n",cmd_new);
1434
1435
  fid = fopen("resNo.txt","r");
1436
  fscanf(fid,"%d",&no_of_results);
1437
//  printf("---> %d\n",no_of_results);
1438
  fclose(fid);
1439
  fp = fopen (logfile, "a");
1440
1441
  return no_of_results;
1442
}
1443
1444
/*
1445
This is the method called by the main program. This initializes the
1446
GUI and spawns a thread which runs the scanning process forever.
1447
The thread is used as gtk_main should be called to make the GUI visible
1448
and no code after that can be executed. Before gtk_main is invoked, if
1449
the scanning process is done then it never reaches gtk_main and the
1450
GUI will not be displayed.
1451
*/
1452
1453
int Callmain( int   *argc, char ***argv )
1454
{
1455
1456
  yes_or_no_args yes_args;
1457
  pthread_t yes_tid;
1458
  GtkWidget * event_box;
1459
1460
  time_t    time_now;
1461
  struct tm *time_ptr;
1462
  char  string[MAX_STR_LEN];
1463
  char  str_dict[MAX_STR_LEN];
1464
1465
1466
  time(&time_now);     /* get time in seconds */
1467
1468
 /* custom build the format of the date/ time */
1469
  time_ptr = localtime(&time_now);
1470
  strftime(string, MAX_STR_LEN, "%d-%b-%G", time_ptr);
1471
1472
  strcpy(logfile,USER_DIR);
1473
  strcat(logfile,user_name);
1474
  strcat(logfile,LOG_FILE_PREFIX);
1475
  mkdir(logfile, (mode_t)0755);
1476
1477
/* Here we are calling the function maintain_userlogs in maintain.c to restrict the memory for a each user. */
1478
1479
  maintain_userlogs (logfile);
1480
1481
/* Here we are creating local dictionary for the usser. */
1482
1483
  strcpy(str_dict , "touch ");
1484
  strcat(str_dict , logfile);
1485
  strcat(str_dict  , "dict.txt");
1486
  system(str_dict);
1487
1488
  strcat(logfile,string);
1489
//  printf("LOG FILE NAME IS %s\n", LOGFIle);
1490
1491
  fp = fopen (logfile, "a");
1492
1493
  gdk_color_parse("red",&colorRed);
1494
  gtk_init (argc, argv);
1495
1496
  if (!g_thread_supported ())
1497
    {
1498
      g_thread_init (NULL);
1499
      gdk_threads_init();
1500
    }
1501
1502
  gdk_threads_enter ();
1503
1504
1505
  /* Create a new window */
1506
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1507
  gtk_widget_set_size_request (window, 800, 400);
1508
  gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, TRUE);
1509
1510
  gtk_window_set_title (GTK_WINDOW (window), "HOPE");
1511
1512
  /* It's a good idea to do this for all windows. */
1513
  g_signal_connect (G_OBJECT (window), "destroy",
1514
                    G_CALLBACK (cleanup_and_main_quit), NULL);
1515
1516
  g_signal_connect (G_OBJECT (window), "delete_event",
1517
                    G_CALLBACK (cleanup_and_main_quit), NULL);
1518
1519
  //adding event_box for handling events
1520
  event_box = gtk_event_box_new ();
1521
  gtk_container_add (GTK_CONTAINER (window), event_box);
1522
1523
  /* Sets the border width of the window. */
1524
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
1525
1526
  /* Create a 10x10 table */
1527
  table = gtk_table_new (9, 10, TRUE);
1528
1529
  /*Set table row spacing and column spacing*/
1530
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);
1531
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
1532
1533
  /* Put the table in the main window */
1534
  gtk_container_add (GTK_CONTAINER (event_box), table);
1535
1536
  /* Create buttons */
1537
  create_buttons();
1538
1539
  gtk_widget_modify_bg(button[0],GTK_STATE_NORMAL,&colorRed);
1540
1541
  create_single_button();
1542
1543
  create_labels();
1544
1545
  gtk_widget_realize (event_box);
1546
  gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));
1547
1548
  gtk_widget_show (table);
1549
  gtk_widget_show (event_box);
1550
  gtk_widget_show (window);
1551
1552
  /*
1553
  Here the variables to be sent to the thread are created. The thread is
1554
  created and button_selection method is executed in the thread.
1555
  */
1556
  scan_mode = 1;
1557
  yes_args.what = NO_IT_IS_NOT;
1558
  yes_args.index = 0;
1559
  pthread_create (&yes_tid, NULL, button_selection, &yes_args);
1560
1561
  /* Rest in gtk_main and wait for the fun to begin! */
1562
  gtk_main ();
1563
  gdk_threads_leave ();
1564
1565
  return 0;
1566
}
1567
Redmine Appliance - Powered by TurnKey Linux