Statistics
| Branch: | Revision:

root / main.c

History | View | Annotate | Download (7.39 KB)

1
#include "main.h"
2
PangoFontDescription *font_desc,*font_desc1;
3
GtkRcStyle *rc_style;
4
GdkColor glue =   { 0, 0,      0,      0xffff };
5
GdkColor black =   { 0, 0,      0,      0};
6

    
7
int isOk = 0;        
8

    
9
GtkWidget *entry,*cb,*image,*label1;
10
GList *cbitems = NULL;
11

    
12
gint increase_font (GtkWidget *evnt)
13
{
14
  gtk_widget_modify_font ((label1), font_desc);
15
  gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &glue);
16
  return;
17
}
18

    
19
gint decrease_font (GtkWidget *evnt)
20
{
21
  gtk_widget_modify_font ((label1), font_desc1);
22
  gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, &black);
23
  return;
24
}
25

    
26
void open_config_file (GtkWidget *evt)  
27
{
28
  char temp[50];
29
  strcpy(temp,"gedit users/");
30
  strcat(temp,user_name);
31
  strcat(temp,"/aac.conf");
32
  system (temp);
33
}
34

    
35
gint callback( GtkWidget *widget,
36
               gpointer   data )
37
{
38

    
39
  strcpy(dir_name,USER_DIR);
40
  GtkWidget *message;
41

    
42
  /* Dialog box for the user name entry */
43

    
44
  if(strlen ((char *)user_name) <= 0)
45
  {
46
    message = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Please enter a name!!!");
47

    
48
    gtk_dialog_run(GTK_DIALOG(message));
49
    gtk_widget_hide(message);
50
  }
51
  else
52
    { /* Process the OK button selection */
53
      if(strncmp((char *) data,"OK",2) >= 0)
54
        {
55
           FILE *filePt;
56
           char fileName[100];
57
           char command[100] = "cp ";
58

    
59
           printf ("User name - %s \n",(char *)user_name);
60
           strcat(dir_name,user_name);  
61
          
62
           if(mkdir(dir_name, (mode_t) 0755) == 0)  
63
           {
64
              /* Directory newly created */
65
              strcat(command,"aac.conf.default ");
66
              strcat(command,dir_name);
67
              strcat(command,"/aac.conf");
68
              system(command);
69
           }
70
           strcpy(fileName, dir_name);
71
           strcat(fileName, "/aac.conf");
72
           filePt = fopen(fileName, "r");
73
           if(filePt == NULL)
74
           {
75
             /* Directory exists but configuration file deleted by mistake */
76

    
77
             message = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Configuration file removed from user directory. Copying the default configuration file.");
78

    
79
             gtk_dialog_run(GTK_DIALOG(message));
80
             gtk_widget_hide(message);
81

    
82
             printf("COMMAND B4 IS %s\n", command); 
83
             strcpy(command, "cp ");
84
             strcat(command,"/root/hope2/aac.conf.default ");
85
             strcat(command,dir_name);
86
             strcat(command,"/aac.conf");
87
             system(command);
88
           }  
89
           else
90
             fclose(filePt);
91

    
92
           /* Copying the files as per the requirement */
93

    
94
           strcpy(command, "cp ");
95
           strcat(command,dir_name);
96
           strcat(command,"/aac.conf .");
97
           system(command);
98
           
99
           isOk = 1;
100
           gtk_main_quit();
101
          }
102
    else if (strncmp((char *)data,"Clear",5) >= 0)
103
    {
104
         /* Clear button selected */
105

    
106
         gtk_entry_set_text(GTK_ENTRY((GTK_COMBO(cb)->entry)), "");
107
     }
108
     else
109
        g_print ("Invalid %s \n", (char *) data);
110
   }
111
 return(TRUE);
112
}
113

    
114
/* This callback quits the program */
115
gint delete_event( GtkWidget *widget,
116
                   GdkEvent  *event,
117
                   gpointer   data )
118
{
119
  gtk_main_quit ();
120
  return(FALSE);
121
}
122

    
123

    
124
int main(int argc, char *argv[])
125
{
126
  
127
  GtkWidget *window;
128
  GtkWidget *button;
129
  GtkWidget *table;
130
  GtkWidget *label;
131
  GtkWidget *event_box;
132
  FILE *ft;
133
  char usr[15][15];
134
  int ind,ind1;
135
font_desc = pango_font_description_from_string ("Sans 19");
136
font_desc1 = pango_font_description_from_string ("Sans 18");
137

    
138
  /* To remove the unwanted files and copy the sound 
139
     configuration files */
140
/*  system ("rm -f out.wav &> /dev/null");
141
  system ("killall artsd &> /dev/null");
142
  system ("cp asound.state /var/lib/alsa/");
143
  system ("alsactl restore" );*/
144
  mkdir(USER_DIR, (mode_t) 0755);
145

    
146
  /* This is specific for LiveCD approach. USB stick have the configuration
147
     files and the log files are written to the stick. So to mount the USB,
148
     a perl program is written and executed */
149
//  system ("perl ./mountUSB.pl");
150
  gtk_rc_add_default_file ("hope_font");
151
  gtk_init (&argc, &argv);
152

    
153
  /* Create a new window */
154
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
155

    
156
  /* Set the window title */
157
  gtk_window_set_title (GTK_WINDOW (window), "User Name");
158
  gtk_widget_set_size_request (window, 600,300);
159
  gtk_container_set_border_width (GTK_CONTAINER (window), 20);
160

    
161
  g_signal_connect (G_OBJECT (window), "destroy",
162
                    G_CALLBACK (gtk_main_quit), NULL);
163

    
164
  g_signal_connect (G_OBJECT (window), "delete_event",
165
                    G_CALLBACK (gtk_main_quit), NULL);
166

    
167

    
168
  table = gtk_table_new (12, 3, FALSE);
169
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
170
  gtk_table_set_row_spacings (GTK_TABLE (table), 5);
171
  gtk_container_add (GTK_CONTAINER (window), table);
172

    
173
  label=gtk_label_new("Enter The User Name : ");
174
  gtk_table_attach_defaults (GTK_TABLE(table), label, 0, 2, 0, 2);
175
  gtk_widget_show (label);
176

    
177
  system("ls users/ > temp.txt");
178
  ft = fopen("temp.txt","r");
179
  ind=0;
180
  while(fscanf(ft,"%s\n",usr[ind]) != EOF)
181
  {
182
      cbitems=g_list_append (cbitems,usr[ind]);
183
      ind++;
184
  }
185

    
186
  /*Create entry box for user name*/
187

    
188
  cb =  gtk_combo_new ();
189
  gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems);
190
  gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (cb)->entry),"Vidyasagar");
191
  gtk_entry_set_max_length (GTK_ENTRY (GTK_COMBO(cb)->entry), 10);
192
//-- good function -- gtk_combo_set_value_in_list(GTK_COMBO(cb),TRUE,FALSE);
193
  gtk_table_attach_defaults (GTK_TABLE(table), cb, 2, 3, 0, 2);
194
  gtk_widget_show (cb);
195
  user_name = (gchar *) gtk_entry_get_text(GTK_ENTRY (GTK_COMBO(cb)->entry));
196
  if (ind >= 10)
197
  gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO(cb)->entry),FALSE);
198

    
199
  /* Create first button */
200
  button = gtk_button_new_with_label ("OK");
201
  /* When the button is clicked, we call the "callback" function
202
   * with a pointer to "OK" as its argument */
203
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
204
                      GTK_SIGNAL_FUNC (callback), (gpointer) "OK");
205

    
206
  /* Insert OK into the upper left quadrant of the table */
207
  gtk_table_attach_defaults (GTK_TABLE(table), button, 2, 3, 10, 12);
208
  
209
  image =gtk_image_new_from_file ("images.jpeg");
210
  gtk_table_attach_defaults (GTK_TABLE(table), image, 0, 2, 4, 10);
211
  fclose(ft);
212

    
213
/// config file addings
214
    
215
    event_box = gtk_event_box_new ();
216
    gtk_table_attach_defaults (GTK_TABLE(table), event_box, 2, 3, 5, 7);
217
    gtk_widget_show (event_box);
218

    
219
    label1 = gtk_label_new ("Change Config File");
220
    gtk_container_add (GTK_CONTAINER (event_box), label1);
221
    gtk_widget_show (label1);
222

    
223
    gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
224

    
225
    gtk_widget_realize (event_box);
226
    gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));
227
    g_signal_connect (G_OBJECT (event_box), "enter_notify_event",
228
                      G_CALLBACK (increase_font), NULL);
229
    g_signal_connect (G_OBJECT (event_box), "leave_notify_event",
230
                      G_CALLBACK (decrease_font), NULL);
231
    g_signal_connect (G_OBJECT (event_box), "button_press_event",
232
                      G_CALLBACK (open_config_file), NULL);
233

    
234
///config file code ends
235

    
236
  gtk_widget_show (button);
237
  gtk_widget_show (table);
238
  gtk_widget_show (window);
239
  gtk_widget_show (image);
240
  gtk_main ();
241
  printf("ISOK = %d\n", isOk);
242

    
243
  
244
  if(isOk == 1)
245
  {
246
     /* OK button is selected. So the next screen is called 
247
        by the Callmain method. This method is available in hope.c */
248
     gtk_widget_hide(GTK_WIDGET(window));
249
     Callmain(&argc, &argv);
250
  }
251

    
252
  return (0);
253
}
Redmine Appliance - Powered by TurnKey Linux