~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to toolbox/toolboxScripts.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
# include <syslimits.h>
32
32
#endif
33
33
 
34
 
#include "toolboxInt.h"
 
34
#include "toolboxGtkInt.h"
35
35
#include "guestApp.h"
36
36
#include "conf.h"
37
37
#include "str.h"
106
106
 
107
107
   /* Only root can edit scripts. */
108
108
   if (geteuid() != 0) {
109
 
      label = 
 
109
      label =
110
110
         gtk_label_new("This option is enabled only if you run VMware Tools as root.");
111
111
      gtk_widget_show(label);
112
112
      gtk_box_pack_start(GTK_BOX(scriptstab), label, FALSE, FALSE, 0);
115
115
      gtk_widget_show(hbox);
116
116
      gtk_box_pack_start(GTK_BOX(scriptstab), hbox, FALSE, FALSE, 0);
117
117
 
 
118
#ifdef GTK2
 
119
      label = gtk_label_new_with_mnemonic("Script Even_t");
 
120
#else
118
121
      label = gtk_label_new("Script Event");
 
122
#endif
119
123
      gtk_widget_show(label);
120
124
      gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
121
125
 
124
128
      gtk_box_pack_start(GTK_BOX(hbox), scriptsCombo, TRUE, TRUE, 0);
125
129
      items = g_list_append(items, SCRIPT_SUSPEND);
126
130
      items = g_list_append(items, SCRIPT_RESUME);
127
 
      items = g_list_append(items, SCRIPT_OFF); 
 
131
      items = g_list_append(items, SCRIPT_OFF);
128
132
      items = g_list_append(items, SCRIPT_ON);
129
133
      gtk_combo_set_popdown_strings(GTK_COMBO(scriptsCombo), items);
130
134
      gtk_combo_set_use_arrows(GTK_COMBO(scriptsCombo), TRUE);
132
136
      gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(scriptsCombo)->entry), FALSE);
133
137
      gtk_signal_connect(GTK_OBJECT(GTK_COMBO(scriptsCombo)->entry), "changed",
134
138
                         GTK_SIGNAL_FUNC(Scripts_OnComboChanged), NULL);
 
139
#ifdef GTK2
 
140
      gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_COMBO(scriptsCombo)->entry);
135
141
 
 
142
      scriptsUseScript = gtk_check_button_new_with_mnemonic("_Use Script");
 
143
#else
136
144
      scriptsUseScript = gtk_check_button_new_with_label("Use Script");
 
145
#endif
137
146
      gtk_widget_show(scriptsUseScript);
138
147
      gtk_box_pack_start(GTK_BOX(scriptstab), scriptsUseScript, FALSE, FALSE, 0);
139
148
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(scriptsUseScript), TRUE);
157
166
          GuestApp_FindProgram("gnome-terminal")) {
158
167
         termApp = "gnome-terminal";
159
168
         termAppOption = "-x";
160
 
      } else if (getenv("KDE_FULL_SESSION") != NULL && 
 
169
      } else if (getenv("KDE_FULL_SESSION") != NULL &&
161
170
                 !strcmp(getenv("KDE_FULL_SESSION"), "true") &&
162
171
                 GuestApp_FindProgram("konsole")) {
163
172
         termApp = "konsole";
172
181
         termAppOption = "-x";
173
182
      }
174
183
 
175
 
      scriptsDefaultScript = 
 
184
#ifdef GTK2
 
185
      scriptsDefaultScript =
 
186
         gtk_radio_button_new_with_mnemonic(NULL,("_Default Script"));
 
187
#else
 
188
      scriptsDefaultScript =
176
189
         gtk_radio_button_new_with_label(NULL,("Default Script"));
 
190
#endif
177
191
      gtk_widget_show(scriptsDefaultScript);
178
192
      gtk_box_pack_start(GTK_BOX(scriptstab), scriptsDefaultScript, FALSE, FALSE, 0);
179
 
      radiobtn_group  = 
 
193
      radiobtn_group  =
180
194
         gtk_radio_button_group(GTK_RADIO_BUTTON(scriptsDefaultScript));
181
195
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(scriptsDefaultScript), TRUE);
182
196
      gtk_signal_connect(GTK_OBJECT(scriptsDefaultScript), "toggled",
183
197
                         GTK_SIGNAL_FUNC(Scripts_OnDefaultScriptToggled), NULL);
184
 
      
 
198
 
 
199
#ifdef GTK2
 
200
      scriptsCustomScript = gtk_radio_button_new_with_mnemonic(NULL,("Cu_stom Script"));
 
201
#else
185
202
      scriptsCustomScript = gtk_radio_button_new_with_label(NULL,("Custom Script"));
 
203
#endif
186
204
      gtk_widget_show(scriptsCustomScript);
187
205
      gtk_box_pack_start(GTK_BOX(scriptstab), scriptsCustomScript, FALSE, FALSE, 0);
188
206
      gtk_radio_button_set_group(GTK_RADIO_BUTTON(scriptsCustomScript),
189
207
                                 radiobtn_group);
190
 
      
 
208
 
191
209
      hbox = gtk_hbox_new(FALSE, 10);
192
210
      gtk_widget_show(hbox);
193
211
      gtk_box_pack_start(GTK_BOX(scriptstab), hbox, FALSE, FALSE, 0);
194
212
      gtk_widget_set_usize(hbox, -1, 25);
195
 
      
 
213
 
196
214
      scriptsPath = gtk_entry_new();
197
215
      gtk_widget_show(scriptsPath);
198
216
      gtk_box_pack_start(GTK_BOX(hbox), scriptsPath, TRUE, TRUE, 0);
199
217
      gtk_widget_set_sensitive(scriptsPath, FALSE);
200
218
      gtk_signal_connect(GTK_OBJECT(scriptsPath), "changed",
201
219
                         GTK_SIGNAL_FUNC(Scripts_PathOnChanged), NULL);
202
 
      
 
220
 
 
221
#ifdef GTK2
 
222
      scriptsBrowse = gtk_button_new_with_mnemonic("_Browse...");
 
223
#else
203
224
      scriptsBrowse = gtk_button_new_with_label("Browse...");
 
225
#endif
204
226
      gtk_widget_show(scriptsBrowse);
205
227
      if (termApp) {
206
228
         gtk_box_pack_start(GTK_BOX(hbox), scriptsBrowse, FALSE, FALSE, 0);
209
231
      }
210
232
      gtk_widget_set_usize(scriptsBrowse, 70, 6);
211
233
      gtk_widget_set_sensitive(scriptsBrowse, FALSE);
212
 
      gtk_signal_connect(GTK_OBJECT(scriptsBrowse), "clicked", 
 
234
      gtk_signal_connect(GTK_OBJECT(scriptsBrowse), "clicked",
213
235
                         GTK_SIGNAL_FUNC(Scripts_OnBrowse), NULL);
214
236
 
215
237
      /* Only create edit button if there is an available X terminal app. */
216
238
      if (termApp) {
 
239
#ifdef GTK2
 
240
         scriptsEdit = gtk_button_new_with_mnemonic("_Edit...");
 
241
#else
217
242
         scriptsEdit = gtk_button_new_with_label("Edit...");
 
243
#endif
218
244
         gtk_widget_show(scriptsEdit);
219
245
         gtk_box_pack_end(GTK_BOX(hbox), scriptsEdit, FALSE, FALSE, 0);
220
246
         gtk_widget_set_usize(scriptsEdit, 70, 25);
221
 
         gtk_signal_connect(GTK_OBJECT(scriptsEdit), "clicked", 
 
247
         gtk_signal_connect(GTK_OBJECT(scriptsEdit), "clicked",
222
248
                            GTK_SIGNAL_FUNC(Scripts_OnEdit), NULL);
223
249
      }
224
250
 
225
251
      hbox = gtk_hbox_new(FALSE, 10);
226
252
      gtk_widget_show(hbox);
227
253
      gtk_box_pack_end(GTK_BOX(scriptstab), hbox, FALSE, FALSE, 0);
228
 
      
 
254
 
 
255
#ifdef GTK2
 
256
      scriptsRun = gtk_button_new_with_mnemonic("_Run Now");
 
257
#else
229
258
      scriptsRun = gtk_button_new_with_label("Run Now");
 
259
#endif
230
260
      gtk_widget_show(scriptsRun);
231
261
      gtk_box_pack_end(GTK_BOX(hbox), scriptsRun, FALSE, FALSE, 0);
232
262
      gtk_widget_set_usize(scriptsRun, 70, 25);
233
 
      gtk_signal_connect(GTK_OBJECT(scriptsRun), "clicked", 
 
263
      gtk_signal_connect(GTK_OBJECT(scriptsRun), "clicked",
234
264
                         GTK_SIGNAL_FUNC(Scripts_OnRun), NULL);
235
265
 
 
266
#ifdef GTK2
 
267
      scriptsApply = gtk_button_new_with_mnemonic("_Apply");
 
268
#else
236
269
      scriptsApply = gtk_button_new_with_label("Apply");
 
270
#endif
237
271
      gtk_widget_show(scriptsApply);
238
272
      gtk_box_pack_end(GTK_BOX(hbox), scriptsApply, FALSE, FALSE, 0);
239
273
      gtk_widget_set_usize(scriptsApply, 70, 6);
240
274
      gtk_widget_set_sensitive(scriptsApply, FALSE);
241
 
      gtk_signal_connect(GTK_OBJECT(scriptsApply), "clicked", 
 
275
      gtk_signal_connect(GTK_OBJECT(scriptsApply), "clicked",
242
276
                         GTK_SIGNAL_FUNC(Scripts_OnApply), NULL);
243
 
      
 
277
 
244
278
      gtk_signal_emit_by_name(GTK_OBJECT(GTK_COMBO(scriptsCombo)->entry), "changed");
245
279
 
246
280
   }
253
287
 *
254
288
 * Scripts_UpdateEnabled --
255
289
 *
256
 
 *      Update the enabled/disabled state of the widgets on the Scripts tab. 
257
 
 * 
 
290
 *      Update the enabled/disabled state of the widgets on the Scripts tab.
 
291
 *
258
292
 * Results:
259
293
 *      None.
260
294
 *
268
302
Scripts_UpdateEnabled(void)
269
303
{
270
304
   Bool enabledUse, enabledCustom;
271
 
   
 
305
 
272
306
   enabledUse = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(scriptsUseScript));
273
 
   enabledCustom = 
 
307
   enabledCustom =
274
308
      gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(scriptsCustomScript));
275
309
   gtk_widget_set_sensitive(scriptsDefaultScript, enabledUse);
276
310
   gtk_widget_set_sensitive(scriptsCustomScript, enabledUse);
282
316
   gtk_widget_set_sensitive(scriptsBrowse, enabledUse && enabledCustom);
283
317
}
284
318
 
285
 
   
 
319
 
286
320
/*
287
321
 *-----------------------------------------------------------------------------
288
322
 *
290
324
 *
291
325
 *      Callback for the gtk signal "changed" on the Scripts tab's combo box.
292
326
 *      Lookup the script paths based on the entry selected and update the UI
293
 
 *      to match the contents of confDict. It temporarily blocks the  "toggled" 
294
 
 *      signals because the callbacks for those signal should only be called 
 
327
 *      to match the contents of confDict. It temporarily blocks the  "toggled"
 
328
 *      signals because the callbacks for those signal should only be called
295
329
 *      if a user makes a change, not when the state is changed internally
296
330
 *
297
331
 * Results:
306
340
void
307
341
Scripts_OnComboChanged(gpointer entry, // IN: the entry selected
308
342
                       gpointer data)  // IN: unused
309
 
{   
 
343
{
310
344
   const char *path, *defaultPath;
311
345
   const char *currentState;
312
346
   currentState = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(scriptsCombo)->entry));
317
351
      path = GuestApp_GetDictEntry(confDict, CONFNAME_RESUMESCRIPT);
318
352
      defaultPath = GuestApp_GetDictEntryDefault(confDict, CONFNAME_RESUMESCRIPT);
319
353
   } else if (strcmp(currentState, SCRIPT_OFF) == 0) {
320
 
      path = GuestApp_GetDictEntry(confDict, CONFNAME_POWEROFFSCRIPT);      
 
354
      path = GuestApp_GetDictEntry(confDict, CONFNAME_POWEROFFSCRIPT);
321
355
      defaultPath = GuestApp_GetDictEntryDefault(confDict, CONFNAME_POWEROFFSCRIPT);
322
356
   } else if (strcmp(currentState, SCRIPT_ON) == 0) {
323
 
      path = GuestApp_GetDictEntry(confDict, CONFNAME_POWERONSCRIPT);      
 
357
      path = GuestApp_GetDictEntry(confDict, CONFNAME_POWERONSCRIPT);
324
358
      defaultPath = GuestApp_GetDictEntryDefault(confDict, CONFNAME_POWERONSCRIPT);
325
359
   } else {
326
360
      path = "";
331
365
                                    GTK_SIGNAL_FUNC(Scripts_OnUseScriptToggled),
332
366
                                    NULL);
333
367
   gtk_signal_handler_block_by_func(GTK_OBJECT(scriptsDefaultScript),
334
 
                                    GTK_SIGNAL_FUNC(Scripts_OnDefaultScriptToggled), 
 
368
                                    GTK_SIGNAL_FUNC(Scripts_OnDefaultScriptToggled),
335
369
                                    NULL);
336
370
   if (strcmp(path, "") == 0) {
337
371
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(scriptsUseScript), FALSE);
355
389
                                      GTK_SIGNAL_FUNC(Scripts_OnDefaultScriptToggled),
356
390
                                      NULL);
357
391
   gtk_widget_set_sensitive(scriptsApply, FALSE);
358
 
 
 
392
 
359
393
   gtk_signal_handler_unblock_by_func(GTK_OBJECT(scriptsUseScript),
360
394
                                      GTK_SIGNAL_FUNC(Scripts_OnUseScriptToggled),
361
395
                                      NULL);
464
498
      if (enabledDef) {
465
499
         path = GuestApp_GetDictEntryDefault(confDict, confName);
466
500
      } else {
467
 
         path = gtk_editable_get_chars(GTK_EDITABLE(scriptsPath), 0, -1); 
 
501
         path = gtk_editable_get_chars(GTK_EDITABLE(scriptsPath), 0, -1);
468
502
      }
469
503
   }
470
504
 
588
622
   char path[PATH_MAX];
589
623
   const char *defaultPath;
590
624
   struct stat statBuf;
591
 
   
 
625
 
592
626
   scriptsFileDlg = gtk_file_selection_new("Select a file");
593
627
   gtk_widget_show(scriptsFileDlg);
594
628
 
595
629
   defaultPath = gtk_entry_get_text(GTK_ENTRY(scriptsPath));
596
630
   Str_Strcpy(path, defaultPath, sizeof path);
597
631
 
598
 
   /* 
599
 
    * If the filename represents a directory but does not end with a path 
 
632
   /*
 
633
    * If the filename represents a directory but does not end with a path
600
634
    * separator, append a path separator to it so that the file chooser will
601
635
    * start off in that directory instead of its parent.
602
636
    */
605
639
       S_ISDIR(statBuf.st_mode)) {
606
640
      Str_Strcat(path, "/", sizeof path);
607
641
   }
608
 
   
609
 
   gtk_file_selection_set_filename(GTK_FILE_SELECTION(scriptsFileDlg), 
 
642
 
 
643
   gtk_file_selection_set_filename(GTK_FILE_SELECTION(scriptsFileDlg),
610
644
                                   path);
611
645
   gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(scriptsFileDlg));
612
646
   gtk_widget_set_sensitive(GTK_FILE_SELECTION(scriptsFileDlg)->ok_button, FALSE);
 
647
#ifdef GTK2
 
648
   gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(scriptsFileDlg), FALSE);
 
649
#else
613
650
   gtk_clist_set_selection_mode(GTK_CLIST(GTK_FILE_SELECTION(scriptsFileDlg)->
614
651
                                          file_list),
615
652
                                GTK_SELECTION_BROWSE);
 
653
#endif
616
654
   gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(scriptsFileDlg)->ok_button),
617
655
                       "clicked", (GtkSignalFunc)Scripts_BrowseOnOk, &path);
618
656
   gtk_signal_connect(GTK_OBJECT(scriptsFileDlg), "destroy",
621
659
                                        cancel_button),
622
660
                             "clicked", (GtkSignalFunc)gtk_widget_destroy,
623
661
                             GTK_OBJECT(scriptsFileDlg));
624
 
   gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(scriptsFileDlg)->selection_entry), 
 
662
   gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(scriptsFileDlg)->selection_entry),
625
663
                      "changed",
626
 
                      (GtkSignalFunc)Scripts_BrowseOnChanged, 
 
664
                      (GtkSignalFunc)Scripts_BrowseOnChanged,
627
665
                      GTK_FILE_SELECTION(scriptsFileDlg)->ok_button);
628
666
 
629
667
 
631
669
   while (gtk_events_pending() || scriptsFileDlg != NULL) {
632
670
      gtk_main_iteration();
633
671
   }
634
 
   
 
672
 
635
673
   if (*path != 0) {
636
 
      gtk_entry_set_text(GTK_ENTRY(scriptsPath), path); 
 
674
      gtk_entry_set_text(GTK_ENTRY(scriptsPath), path);
637
675
      gtk_widget_set_sensitive(scriptsApply, TRUE);
638
676
   }
639
677
}
672
710
 * Scripts_BrowseOnOk --
673
711
 *
674
712
 *      Callback for the gtk signal "clicked" on the Scripts file browser OK
675
 
 *      button.  Set "okPressed" to 1 so the Scripts_OnBrowse code knows to 
 
713
 *      button.  Set "okPressed" to 1 so the Scripts_OnBrowse code knows to
676
714
 *      quit looping and that OK was the reason we closed.
677
715
 *
678
716
 * Results: