~ubuntu-branches/ubuntu/karmic/xscreensaver/karmic

« back to all changes in this revision

Viewing changes to driver/demo-Gtk.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2006-07-29 23:00:43 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20060729230043-3ergkicskbntet5n
Tags: 4.24-5
remove /usr/doc/xscreensaver link to finish /usr/doc ->
/usr/share/doc transition (closes: #380394)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* demo-Gtk.c --- implements the interactive demo-mode and options dialogs.
2
 
 * xscreensaver, Copyright (c) 1993-2005 Jamie Zawinski <jwz@jwz.org>
 
2
 * xscreensaver, Copyright (c) 1993-2006 Jamie Zawinski <jwz@jwz.org>
3
3
 *
4
4
 * Permission to use, copy, modify, distribute, and sell this software and its
5
5
 * documentation for any purpose is hereby granted without fee, provided that
144
144
 
145
145
/* from exec.c */
146
146
extern void exec_command (const char *shell, const char *command, int nice);
 
147
extern int on_path_p (const char *program);
147
148
 
148
149
static void hack_subproc_environment (Window preview_window_id, Bool debug_p);
149
150
 
190
191
  int *list_elt_to_hack_number; /* table for sorting the hack list */
191
192
  int *hack_number_to_list_elt; /* the inverse table */
192
193
  Bool *hacks_available_p;      /* whether hacks are on $PATH */
 
194
  int total_available;          /* how many are on $PATH */
193
195
  int list_count;               /* how many items are in the list: this may be
194
196
                                   less than p->screenhacks_count, if some are
195
197
                                   suppressed. */
645
647
                strcpy (buf, "Unknown error!");
646
648
              warning_dialog (s->toplevel_widget, buf, False, 100);
647
649
            }
648
 
          if (err) free (err);
649
650
        }
650
651
      else
651
652
        {
845
846
           p->load_url_command,
846
847
           p->help_url, p->help_url, p->help_url, p->help_url);
847
848
  strcat (help_command, " ) &");
848
 
  system (help_command);
 
849
  if (system (help_command) < 0)
 
850
    fprintf (stderr, "%s: fork error\n", blurb());
849
851
  free (help_command);
850
852
}
851
853
 
889
891
  flush_dialog_changes_and_save (s);
890
892
  xscreensaver_command (GDK_DISPLAY(), XA_EXIT, 0, False, NULL);
891
893
  sleep (1);
892
 
  system ("xscreensaver -nosplash &");
 
894
  if (system ("xscreensaver -nosplash &") < 0)
 
895
    fprintf (stderr, "%s: fork error\n", blurb());
893
896
 
894
897
  await_xscreensaver (s);
895
898
}
1027
1030
  int list_elt = selected_list_element (s);
1028
1031
  int hack_number;
1029
1032
  char *name, *name2, *cmd, *str;
 
1033
  char *oname = 0;
1030
1034
  if (list_elt < 0) return;
1031
1035
  hack_number = s->list_elt_to_hack_number[list_elt];
1032
1036
 
1035
1039
 
1036
1040
  name = strdup (p->screenhacks[hack_number]->command);
1037
1041
  name2 = name;
 
1042
  oname = name;
1038
1043
  while (isspace (*name2)) name2++;
1039
1044
  str = name2;
1040
1045
  while (*str && !isspace (*str)) str++;
1051
1056
               cmd,
1052
1057
               name2, name2, name2, name2);
1053
1058
      strcat (cmd2, " ) &");
1054
 
      system (cmd2);
 
1059
      if (system (cmd2) < 0)
 
1060
        fprintf (stderr, "%s: fork error\n", blurb());
1055
1061
      free (cmd2);
1056
1062
    }
1057
1063
  else
1061
1067
                      False, 100);
1062
1068
    }
1063
1069
 
1064
 
  free (name);
 
1070
  free (oname);
1065
1071
}
1066
1072
 
1067
1073
 
1080
1086
#ifdef HAVE_GTK2
1081
1087
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
1082
1088
  STFU g_assert (model);
1083
 
  gtk_tree_model_iter_nth_child (model, &iter, NULL, list_elt);
1084
 
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
1085
 
  gtk_tree_selection_select_iter (selection, &iter);
 
1089
  if (gtk_tree_model_iter_nth_child (model, &iter, NULL, list_elt))
 
1090
    {
 
1091
      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
 
1092
      gtk_tree_selection_select_iter (selection, &iter);
 
1093
    }
1086
1094
#else  /* !HAVE_GTK2 */
1087
1095
  gtk_list_select_item (GTK_LIST (list), list_elt);
1088
1096
#endif /* !HAVE_GTK2 */
2349
2357
}
2350
2358
 
2351
2359
 
2352
 
static Bool
2353
 
on_path_p (const char *program)
2354
 
{
2355
 
  int result = False;
2356
 
  struct stat st;
2357
 
  char *cmd = strdup (program);
2358
 
  char *token = strchr (cmd, ' ');
2359
 
  char *path = 0;
2360
 
  int L;
2361
 
 
2362
 
  if (token) *token = 0;
2363
 
  token = 0;
2364
 
 
2365
 
  if (strchr (cmd, '/'))
2366
 
    {
2367
 
      result = (0 == stat (cmd, &st));
2368
 
      goto DONE;
2369
 
    }
2370
 
 
2371
 
  path = getenv("PATH");
2372
 
  if (!path || !*path)
2373
 
    goto DONE;
2374
 
 
2375
 
  L = strlen (cmd);
2376
 
  path = strdup (path);
2377
 
  token = strtok (path, ":");
2378
 
 
2379
 
  while (token)
2380
 
    {
2381
 
      char *p2 = (char *) malloc (strlen (token) + L + 3);
2382
 
      strcpy (p2, token);
2383
 
      strcat (p2, "/");
2384
 
      strcat (p2, cmd);
2385
 
      result = (0 == stat (p2, &st));
2386
 
      if (result)
2387
 
        goto DONE;
2388
 
      token = strtok (0, ":");
2389
 
    }
2390
 
 
2391
 
 DONE:
2392
 
  free (cmd);
2393
 
  if (path) free (path);
2394
 
  return result;
2395
 
}
2396
 
 
2397
 
 
2398
2360
static void
2399
2361
populate_hack_list (state *s)
2400
2362
{
3315
3277
    calloc (sizeof(int), p->screenhacks_count + 1);
3316
3278
  s->hacks_available_p = (Bool *)
3317
3279
    calloc (sizeof(Bool), p->screenhacks_count + 1);
 
3280
  s->total_available = 0;
3318
3281
 
3319
3282
  /* Check which hacks actually exist on $PATH
3320
3283
   */
3321
3284
  for (i = 0; i < p->screenhacks_count; i++)
3322
3285
    {
3323
3286
      screenhack *hack = p->screenhacks[i];
3324
 
      s->hacks_available_p[i] = on_path_p (hack->command);
 
3287
      int on = on_path_p (hack->command) ? 1 : 0;
 
3288
      s->hacks_available_p[i] = on;
 
3289
      s->total_available += on;
3325
3290
    }
3326
3291
 
3327
3292
  /* Initialize list->hack table to unsorted mapping, omitting nonexistent
3473
3438
    Bool available_p = (hack_number >= 0
3474
3439
                        ? s->hacks_available_p [hack_number]
3475
3440
                        : True);
 
3441
    Bool nothing_p = (s->total_available < 5);
 
3442
 
3476
3443
#ifdef HAVE_GTK2
3477
3444
    GtkWidget *notebook = name_to_widget (s, "preview_notebook");
3478
3445
    gtk_notebook_set_page (GTK_NOTEBOOK (notebook),
3479
3446
                           (s->running_preview_error_p
3480
 
                            ? (available_p ? 1 : 2)
 
3447
                            ? (available_p ? 1 :
 
3448
                               nothing_p ? 3 : 2)
3481
3449
                            : 0));
3482
3450
#else /* !HAVE_GTK2 */
3483
3451
    if (s->running_preview_error_p)
3718
3686
        close (out);  /* don't need this one */
3719
3687
 
3720
3688
        *buf = 0;
3721
 
        fgets (buf, sizeof(buf)-1, f);
 
3689
        if (!fgets (buf, sizeof(buf)-1, f))
 
3690
          *buf = 0;
3722
3691
        fclose (f);
3723
3692
 
3724
3693
        /* Wait for the child to die. */