示例#1
0
static void
awn_html_dialog_new(WebApplet *webapplet)
{
  /* create viewer */
  webapplet->mainwindow = awn_dialog_new_for_widget (GTK_WIDGET(webapplet->applet));
  webapplet->box = gtk_vbox_new (FALSE, 1);

  webapplet->viewer = html_web_view_new ();

  /* Load the .ini file for websites */
  GError *err = NULL;
  webapplet->sites_file = g_key_file_new();

  g_key_file_load_from_file(webapplet->sites_file,
                            APPLETSDIR"/webapplet/webapplet-websites.ini",
                            0, &err);

  if (err)
  {
    printf("Error loading websites: %s\n", err->message);
    g_error_free(err);
    g_key_file_free(webapplet->sites_file);
    webapplet->sites_file = NULL;
  }

  /* If first time using this, hide WebView, show location entry/website buttons */
  if (config_get_first_start(webapplet))
  {
    gtk_widget_set_no_show_all(webapplet->viewer, TRUE);

    gtk_box_pack_start(GTK_BOX(webapplet->box), first_start(webapplet),
                       FALSE, FALSE, 0);

    awn_applet_simple_set_tooltip_text(AWN_APPLET_SIMPLE(webapplet->applet),
                                       _("Web Applet"));
  }

  else
  {
    go_to_url(webapplet, (gchar*)config_get_uri(webapplet));

    if (webapplet->sites_file)
    {
      const gchar *name = config_get_site(webapplet);

      if (name && strcmp(name, "") != 0)
      {
        gint size = awn_applet_get_size(webapplet->applet);

        WebSite *site = get_site(webapplet, (gchar*)name);
        gchar *path = g_strdup_printf(APPLETSDIR"/webapplet/icons/%s", site->icon);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(path, size, size, NULL);
        awn_applet_simple_set_icon_pixbuf(AWN_APPLET_SIMPLE(site->webapplet->applet), pixbuf);

        if (site->width && site->height)
        {
          gtk_widget_set_size_request(GTK_WIDGET(site->webapplet->box),
                                      site->width, site->height);
        }
      }
    }
  }

  gtk_box_pack_start(GTK_BOX(webapplet->box), webapplet->viewer, TRUE, TRUE, 0);
  gtk_container_add(GTK_CONTAINER(webapplet->mainwindow), webapplet->box);
}
示例#2
0
int main(int argc, char **argv) {
    time_t start;

    if (argv[0][0] != '(') {
        char *old_argv0, *new_argv0 = "(bbs100 guard)";

        old_argv0 = argv[0];
        argv[0] = new_argv0;
        execv(old_argv0, argv);			/* restart with new name */

        fprintf(stderr, "bbs100: startup failed\n");
        exit(-1);
    }
    printf("bbs100 guard %s by Walter de Jong <*****@*****.**> (C) 1997-2015\n", VERSION);
    printf("bbs100 comes with ABSOLUTELY NO WARRANTY. This is free software.\n"
           "For details, see the GNU General Public License.\n\n");

    if (argc <= 1) {
        printf("usage: guard <main program>\n");
        return 1;
    }
    if (getcwd(currdir, MAX_PATHLEN) == NULL) {
        perror("guard: can't get current directory");
        exit(-1);
    }
    if (chdir("/") == -1) {
        perror("guard: failed to change directory to / ");
        exit(-1);
    }
    start = time(NULL);

    /*
    	Odd ... when guard closes stdin, the main program's listen()
    	will go into TIME_WAIT and eventually close automatically

    	close(fileno(stdin));
    */

    /*
    	bah ... we have to go to the background immediately, otherwise
    	waitpid() won't find this child, as it will the child of another
    	process ...
    */
    goto_background();

    /*
    	start the program
    */
    first_start(&argv[1]);

    /*
    	Odd (2) ...
    	When guard closes stdout/stderr, accept() will fail when SO_REUSEADDR
    	is used on the listen()ing socket

    	close(fileno(stdout));
    	close(fileno(stderr));
    */

    /*
    	monitor and restart the program if necessary
    */
    restart_program(&argv[1], start);
    return 0;
}