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

« back to all changes in this revision

Viewing changes to toolbox/toolbox-gtk.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:
26
26
#include <stdlib.h>
27
27
#include <string.h>
28
28
 
29
 
#include "toolboxInt.h"
 
29
#include "toolboxGtkInt.h"
30
30
#include "vm_assert.h"
31
31
#include "vm_app.h"
32
32
#include "eventManager.h"
42
42
#include "smallIcon.xpm"
43
43
#include "conf.h"
44
44
#include "toolboxgtk_version.h"
 
45
#include "util.h"
45
46
 
46
47
#include "embed_version.h"
47
48
VM_EMBED_VERSION(TOOLBOXGTK_VERSION_STRING);
62
63
/*
63
64
 * Globals
64
65
 */
65
 
static char hlpDir[PATH_MAX];
 
66
static char *hlpDir = NULL;
66
67
static Display *gXDisplay;
67
68
static Window gXRoot;
68
69
RpcIn *gRpcInCtlPanel;
70
71
static Bool optionAutoHide;
71
72
static guint gTimeoutId;
72
73
 
 
74
/* Help pages. These need to be in the same order as the tabs in the UI. */
 
75
static const char *gHelpPages[] = {
 
76
   "index.html",
 
77
   "tools_options.htm",
 
78
   "tools_devices.htm",
 
79
   "tools_scripts.htm",
 
80
   "tools_shrink.htm",
 
81
   "tools_about.htm",
 
82
};
 
83
 
73
84
/*
74
85
 * All signals that:
75
86
 * . Can terminate the process
105
116
GtkWidget* ToolsMain_Create(void);
106
117
 
107
118
 
108
 
Bool RpcInResetCB(char const **result, size_t *resultLen, const char *name,
109
 
                  const char *args, size_t argsSize, void *clientData);
 
119
Bool RpcInResetCB(RpcInData *data);
110
120
Bool RpcInSetOptionCB(char const **result, size_t *resultLen, const char *name,
111
121
                      const char *args, size_t argsSize, void *clientData);
112
122
Bool RpcInCapRegCB(char const **result, size_t *resultLen, const char *name,
145
155
      gRpcInCtlPanel = NULL;
146
156
   }
147
157
 
148
 
   /* Remove timeout so event queue isn't pumped after being destroyed. */ 
 
158
   /* Remove timeout so event queue isn't pumped after being destroyed. */
149
159
   gtk_timeout_remove(gTimeoutId);
150
160
   ASSERT(gEventQueue);
151
161
   EventManager_Destroy(gEventQueue);
157
167
 *
158
168
 * ToolsMainSignalHandler  --
159
169
 *
160
 
 *      Handler for Posix signals. We do this to ensure that we exit 
 
170
 *      Handler for Posix signals. We do this to ensure that we exit
161
171
 *      gracefully.
162
172
 *
163
173
 * Results:
198
208
{
199
209
   char helpPage[1000];
200
210
 
 
211
   if (hlpDir == NULL) {
 
212
      ToolsMain_MsgBox("Error", "Unable to determine where help pages are stored.");
 
213
      return;
 
214
   }
 
215
 
201
216
   if (help == NULL) {
202
217
      ToolsMain_MsgBox("Error", "No help was found for the page.");
203
218
      return;
204
219
   }
205
220
 
206
 
   Str_Snprintf(helpPage, sizeof helpPage, "file:%s%s", hlpDir, help);
 
221
   Str_Snprintf(helpPage, sizeof helpPage, "file:%s/%s", hlpDir, help);
207
222
   if (!GuestApp_OpenUrl(helpPage, FALSE)) {
208
223
      ToolsMain_MsgBox("Help Unavailable",
209
224
                       "Sorry, but help requires a web browser.  You may need "
234
249
ToolsMain_OnHelp(gpointer btn,  // IN: Unused
235
250
                 gpointer data) // IN: notebook containing all tabs
236
251
{
237
 
   char *text;
238
 
   GtkWidget *curPage;
 
252
   gint page;
239
253
   GtkNotebook *nb;
240
254
 
241
255
   nb = GTK_NOTEBOOK(data);
243
257
      return;
244
258
   }
245
259
 
246
 
   curPage = gtk_notebook_get_nth_page(nb, gtk_notebook_get_current_page(nb));
247
 
   gtk_label_get(GTK_LABEL(gtk_notebook_get_tab_label(nb,curPage)), &text);
248
 
   if (strcmp(text, TAB_LABEL_OPTIONS) == 0) {
249
 
      ToolsMain_OpenHelp("tools_options.htm");
250
 
   } else if (strcmp(text, TAB_LABEL_DEVICES) == 0) {
251
 
      ToolsMain_OpenHelp("tools_devices.htm");
252
 
   } else if (strcmp(text, TAB_LABEL_SCRIPTS) == 0) {
253
 
      ToolsMain_OpenHelp("tools_scripts.htm");
254
 
   } else if (strcmp(text, TAB_LABEL_SHRINK) == 0) {
255
 
      ToolsMain_OpenHelp("tools_shrink.htm");
256
 
   } else if (strcmp(text, TAB_LABEL_ABOUT) == 0) {
257
 
   ToolsMain_OpenHelp("tools_about.htm");
258
 
   } else {
259
 
      ToolsMain_OpenHelp("index.htm");
 
260
   page = gtk_notebook_get_current_page(nb) + 1;
 
261
   ASSERT(page > 0);
 
262
 
 
263
   if (page >= ARRAYSIZE(gHelpPages)) {
 
264
      char *text;
 
265
      GtkWidget *curPage;
 
266
      curPage = gtk_notebook_get_nth_page(nb, page - 1);
 
267
      gtk_label_get(GTK_LABEL(gtk_notebook_get_tab_label(nb,curPage)), &text);
 
268
      Warning("No help page for tab %s, defaulting to index.\n", text);
 
269
      page = 0;
260
270
   }
 
271
 
 
272
   ToolsMain_OpenHelp(gHelpPages[page]);
261
273
}
262
274
 
263
275
 
301
313
   gtk_widget_show(label);
302
314
   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
303
315
 
 
316
#ifdef GTK2
 
317
   okbtn = gtk_button_new_with_mnemonic("_OK");
 
318
#else
304
319
   okbtn = gtk_button_new_with_label("OK");
 
320
#endif
305
321
   gtk_widget_show(okbtn);
306
322
   gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area), okbtn, FALSE, FALSE, 0);
307
323
   gtk_widget_set_usize(okbtn, 70, 25);
308
324
   gtk_signal_connect_object(GTK_OBJECT(okbtn), "clicked",
309
325
                             GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog));
 
326
   GTK_WIDGET_SET_FLAGS(okbtn, GTK_CAN_DEFAULT);
 
327
   gtk_widget_grab_default(okbtn);
310
328
   gtk_widget_show_all(dialog);
311
329
}
312
330
 
352
370
   gtk_widget_show(label);
353
371
   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
354
372
 
 
373
#ifdef GTK2
 
374
   btn = gtk_button_new_with_mnemonic("_Yes");
 
375
#else
355
376
   btn = gtk_button_new_with_label("Yes");
 
377
#endif
356
378
   gtk_widget_show(btn);
357
379
   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), btn, FALSE, FALSE, 0);
358
380
   gtk_widget_set_usize(btn, 70, 25);
359
381
   gtk_signal_connect(GTK_OBJECT(btn), "clicked",
360
382
                      GTK_SIGNAL_FUNC(ToolsMain_YesNoBoxOnClicked), &ret);
361
383
 
 
384
#ifdef GTK2
 
385
   btn = gtk_button_new_with_mnemonic("_No");
 
386
#else
362
387
   btn = gtk_button_new_with_label("No");
 
388
#endif
363
389
   gtk_widget_show(btn);
364
390
   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), btn, FALSE, FALSE, 0);
365
391
   gtk_widget_set_usize(btn, 70, 25);
528
554
   gtk_box_pack_start(GTK_BOX(vbox), notebookMain, TRUE, TRUE, 0);
529
555
   gtk_container_set_border_width(GTK_CONTAINER(notebookMain), 0);
530
556
 
 
557
#ifdef GTK2
 
558
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Options_Create(ToolsMain),
 
559
                            gtk_label_new_with_mnemonic(TAB_LABEL_OPTIONS));
 
560
#else
531
561
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Options_Create(ToolsMain),
532
562
                            gtk_label_new(TAB_LABEL_OPTIONS));
 
563
#endif
533
564
 
534
 
   /* 
535
 
    * Beginning with ACE1, a VM could be configured to prevent editing of 
536
 
    * device state from the guest. So we enable the devices page only if the 
 
565
   /*
 
566
    * Beginning with ACE1, a VM could be configured to prevent editing of
 
567
    * device state from the guest. So we enable the devices page only if the
537
568
    * command fails (meaning we're pre-ACE1), or if the command succeeds and
538
569
    * we're allowed to edit the devices.
539
570
    */
540
571
   if (!RpcOut_sendOne(&result, &resultLen, "vmx.capability.edit_devices") ||
541
572
       strcmp(result, "0") != 0) {
542
 
      gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), 
 
573
#ifdef GTK2
 
574
      gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain),
 
575
                               Devices_Create(ToolsMain),
 
576
                               gtk_label_new_with_mnemonic(TAB_LABEL_DEVICES));
 
577
#else
 
578
      gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain),
543
579
                               Devices_Create(ToolsMain),
544
580
                               gtk_label_new(TAB_LABEL_DEVICES));
 
581
#endif
545
582
   } else {
546
583
      Debug("User not allowed to edit devices");
547
584
   }
548
585
   free(result);
549
586
 
 
587
#ifdef GTK2
 
588
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Scripts_Create(ToolsMain),
 
589
                         gtk_label_new_with_mnemonic(TAB_LABEL_SCRIPTS));
 
590
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Shrink_Create(ToolsMain),
 
591
                            gtk_label_new_with_mnemonic(TAB_LABEL_SHRINK));
 
592
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), About_Create(ToolsMain),
 
593
                            gtk_label_new_with_mnemonic(TAB_LABEL_ABOUT));
 
594
#else
550
595
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Scripts_Create(ToolsMain),
551
596
                         gtk_label_new(TAB_LABEL_SCRIPTS));
552
597
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), Shrink_Create(ToolsMain),
553
598
                            gtk_label_new(TAB_LABEL_SHRINK));
554
599
   gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), About_Create(ToolsMain),
555
600
                            gtk_label_new(TAB_LABEL_ABOUT));
 
601
#endif
556
602
 
557
603
   hbox = gtk_hbutton_box_new();
558
604
   gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 10);
560
606
   gtk_widget_show(hbox);
561
607
   gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
562
608
 
563
 
   /* 
 
609
   /*
564
610
    * The HIG says that the Help button should be in the lower left, and all
565
611
    * other buttons in the lower right.
566
612
    *
567
613
    * See http://developer.gnome.org/projects/gup/hig/2.0/windows-alert.html#alert-button-order
568
614
    */
 
615
#ifdef GTK2
 
616
   btn = gtk_button_new_with_mnemonic("_Help");
 
617
#else
569
618
   btn = gtk_button_new_with_label("Help");
 
619
#endif
570
620
   gtk_widget_show(btn);
571
621
   gtk_box_pack_start(GTK_BOX(hbox), btn, FALSE, FALSE, 0);
572
622
   gtk_signal_connect(GTK_OBJECT(btn), "clicked", GTK_SIGNAL_FUNC(ToolsMain_OnHelp),
573
623
                      notebookMain);
574
624
 
 
625
#ifdef GTK2
 
626
   btn = gtk_button_new_with_mnemonic("_Close");
 
627
#else
575
628
   btn = gtk_button_new_with_label("Close");
 
629
#endif
576
630
   gtk_widget_show(btn);
577
631
   gtk_box_pack_start(GTK_BOX(hbox), btn, FALSE, FALSE, 0);
578
632
   gtk_signal_connect_object(GTK_OBJECT(btn), "clicked",
602
656
 */
603
657
 
604
658
Bool
605
 
RpcInResetCB(char const **result,     // OUT
606
 
             size_t *resultLen,       // OUT
607
 
             const char *name,        // IN
608
 
             const char *args,        // IN
609
 
             size_t argsSize,         // Unused
610
 
             void *clientData)        // Unused
 
659
RpcInResetCB(RpcInData *data) // IN/OUT
611
660
{
612
661
   Debug("----------toolbox: Received 'reset' from vmware\n");
613
662
 
614
 
   return RpcIn_SetRetVals(result, resultLen, "ATR " TOOLS_CTLPANEL_NAME,
615
 
                           TRUE);
 
663
   return RPCIN_SETRETVALS(data, "ATR " TOOLS_CTLPANEL_NAME, TRUE);
616
664
}
617
665
 
618
666
 
820
868
/*
821
869
 *-----------------------------------------------------------------------------
822
870
 *
 
871
 * InitHelpDir --
 
872
 *
 
873
 *      Queries the Tools config dictionary for the location of the Toolbox
 
874
 *      Help docs.  If not found, will try to fall back to semi-safe defaults.
 
875
 *
 
876
 * Results:
 
877
 *      None.
 
878
 *
 
879
 * Side effects:
 
880
 *      If a suitable directory was found, hlpDir will point to a buffer
 
881
 *      containing it.  Otherwise it will remain NULL.
 
882
 *
 
883
 *-----------------------------------------------------------------------------
 
884
 */
 
885
 
 
886
void
 
887
InitHelpDir(GuestApp_Dict *pConfDict)   // IN
 
888
{
 
889
   const char *tmpDir = NULL;
 
890
 
 
891
   ASSERT(hlpDir == NULL);
 
892
 
 
893
   tmpDir = GuestApp_GetDictEntry(pConfDict, CONFNAME_HELPDIR);
 
894
   if (!tmpDir || !File_Exists(tmpDir)) {
 
895
      unsigned int i;
 
896
 
 
897
      static const char *candidates[] = {
 
898
         "/usr/lib/vmware-tools/hlp",        // Linux, Solaris
 
899
         "/usr/local/lib/vmware-tools/hlp",  // FreeBSD
 
900
      };
 
901
 
 
902
      for (i = 0; i < ARRAYSIZE(candidates); i++) {
 
903
         if (File_Exists(candidates[i])) {
 
904
            tmpDir = candidates[i];
 
905
            break;
 
906
         }
 
907
      }
 
908
   }
 
909
 
 
910
   if (tmpDir) {
 
911
      hlpDir = Util_SafeStrdup(tmpDir);
 
912
   }
 
913
}
 
914
 
 
915
 
 
916
/*
 
917
 *-----------------------------------------------------------------------------
 
918
 *
823
919
 * ShowUsage --
824
920
 *
825
921
 *      Print out usage information to stdout.
843
939
           "\n"
844
940
           "   %s --minimize|--iconify\n"
845
941
           "      Start the toolbox window minimized.\n"
 
942
           "\n"
 
943
           "   %s --version\n"
 
944
           "      Show the VMware(R) Tools version.\n"
846
945
           "\n",
847
 
           prog, prog);
 
946
           prog, prog, prog);
848
947
}
849
948
 
850
949
 
856
955
 *      This is main
857
956
 *
858
957
 * Results:
859
 
 *      0 on success, -1 otherwise
 
958
 *      0 on success.
860
959
 *
861
960
 * Side effects:
862
961
 *      The linux toolbox ui will run and do a variety of tricks for your
867
966
int
868
967
main(int argc, char *argv[])
869
968
{
870
 
   char *tmp;
871
 
   Bool optIconify, optHelp;
 
969
   Bool optIconify, optHelp, optVersion;
872
970
   struct sigaction olds[ARRAYSIZE(gSignals)];
873
971
   GuestApp_Dict *pConfDict;
874
972
 
875
 
   /* 
876
 
    * Setup the path to the help directory. We assume that this binary lives in
877
 
    * "LIBDIR/<some_bin_path>" and that the help directory is "LIBDIR/hlp".
878
 
    *
879
 
    * If for some reason this isn't true (if argv[0] lacks enough parent
880
 
    * directories) we'll still initialize the help directory path to something,
881
 
    * but subsequent help requests will probably fail.
882
 
    */
883
 
   Str_Strcpy(hlpDir, argv[0], sizeof hlpDir);
884
 
   tmp = Str_Strrchr(hlpDir, '/');
885
 
   if (tmp) {
886
 
      *tmp-- = '\0';
887
 
      tmp = Str_Strrchr(hlpDir, '/');
888
 
      if (tmp) {
889
 
         *tmp = '\0';
890
 
      }
891
 
   }
892
 
   Str_Strcat(hlpDir, "/hlp/", sizeof hlpDir);
893
 
 
894
973
   if (!VmCheck_IsVirtualWorld()) {
895
974
#ifndef ALLOW_TOOLS_IN_FOREIGN_VM
896
 
      Panic("The VMware Toolbox must be run inside a virtual machine.\n");
 
975
      Warning("The VMware Toolbox must be run inside a virtual machine.\n");
 
976
      return 1;
897
977
#else
898
978
      runningInForeignVM = TRUE;
899
979
#endif
907
987
   pConfDict = Conf_Load();
908
988
   Debug_Set(GuestApp_GetDictEntryBool(pConfDict, CONFNAME_LOG), DEBUG_PREFIX);
909
989
   Debug_EnableToFile(GuestApp_GetDictEntry(pConfDict, CONFNAME_LOGFILE), FALSE);
 
990
   InitHelpDir(pConfDict);
910
991
   GuestApp_FreeDict(pConfDict);
911
992
 
912
993
   optionAutoHide = FALSE;
929
1010
   /* Default values */
930
1011
   optIconify = FALSE;
931
1012
   optHelp = FALSE;
 
1013
   optVersion = FALSE;
932
1014
 
933
1015
   if (argc == 2) {
934
1016
      if (strcmp(argv[1], "--iconify") == 0) {
935
1017
         optIconify = TRUE;
936
1018
      } else if (strcmp(argv[1], "--minimize") == 0) {
937
 
            optIconify = TRUE;
 
1019
         optIconify = TRUE;
 
1020
      } else if (strcmp(argv[1], "--version") == 0) {
 
1021
         optVersion = TRUE;
938
1022
      } else {
939
1023
         optHelp = TRUE;
940
1024
      }
946
1030
      ShowUsage(argv[0]);
947
1031
      exit(0);
948
1032
   }
 
1033
   if (optVersion) {
 
1034
      printf("VMware(R) Tools version %s\n", TOOLS_VERSION);
 
1035
      exit(0);
 
1036
   }
949
1037
 
950
1038
   /*
951
1039
    * See bug 73119. Some distros (SUSE 9.2 64-bit) set LC_CTYPE to the UTF-8 version of
1005
1093
    */
1006
1094
   gTimeoutId = gtk_timeout_add(0, &EventQueuePump, NULL);
1007
1095
 
1008
 
   /* 
1009
 
    * We'll block here until the window is destroyed or a 
1010
 
    * signal is received. 
 
1096
   /*
 
1097
    * We'll block here until the window is destroyed or a
 
1098
    * signal is received.
1011
1099
    */
1012
1100
   gtk_main();
1013
1101
 
1015
1103
 
1016
1104
   gdk_pixmap_unref(pixmap);
1017
1105
   gdk_bitmap_unref(bitmask);
 
1106
   free(hlpDir);
1018
1107
 
1019
1108
   return 0;
1020
1109
}