コード例 #1
0
ファイル: gnmenu.c プロジェクト: RandomCore/nethack-de
GtkWidget*
ghack_init_menu_window (void)
{
    GtkWidget *menuWin = NULL;
    GtkWidget *parent = ghack_get_main_window ();

    menuWin = gnome_dialog_new("GnomeHack", GNOME_STOCK_BUTTON_OK, 
		    GNOME_STOCK_BUTTON_CANCEL, NULL);
    
    gnome_dialog_set_default( GNOME_DIALOG(menuWin), 0);
    gtk_signal_connect(GTK_OBJECT(menuWin), "destroy",
		    GTK_SIGNAL_FUNC(ghack_menu_destroy),
		    NULL);

    gtk_signal_connect (GTK_OBJECT (menuWin), "delete_event",
			GTK_SIGNAL_FUNC (ghack_menu_hide),
			NULL);
          
    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_clear",
		    GTK_SIGNAL_FUNC(ghack_menu_window_clear),
		    NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_display",
                       GTK_SIGNAL_FUNC(ghack_menu_window_display),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_start_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_start_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_add_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_add_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_end_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_end_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_select_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_select_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_putstr",
                       GTK_SIGNAL_FUNC(ghack_menu_window_put_string),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "key_press_event",
                       GTK_SIGNAL_FUNC(ghack_menu_window_key),
                       NULL);

    /* Center the dialog over parent */
    g_assert (parent != NULL);
    g_assert (menuWin != NULL);
    g_assert (GTK_IS_WINDOW (parent));
    g_assert (GNOME_IS_DIALOG (menuWin));
    gnome_dialog_set_parent (GNOME_DIALOG (menuWin), GTK_WINDOW (parent));
    
    return menuWin;
}
コード例 #2
0
ファイル: pgp5.c プロジェクト: jeansch/yank-component
static void
cb_decrypt(GtkWidget *w, gpointer p)
{
    GtkWidget    *pass_entry;
    GtkWidget    *warn_w;
    FILE         *pgpin;
    FILE         *pgpout;
    FILE         *pgperr;
    static gchar sys_buf[] = "pgpv -qzd +batchmode +force -o - %s";
    gchar        tmpbuf[1024];
    gchar        *tmpfname;
    gchar        *tmpcmd;
    note_data    *note;
    pid_t        pgp_pid;
    gint         fd;
    
    g_return_if_fail(p != NULL);
    g_return_if_fail(GNOME_IS_DIALOG(p));

    if (selected_node == NULL)
    {
        warn_w = gnome_warning_dialog_parented(
            _("Select a note first!"), yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }

    ask_commit_changes();

    note = (note_data *) gtk_ctree_node_get_row_data(
        GTK_CTREE(note_tree), GTK_CTREE_NODE(selected_node));
    
    if (!note->text || !strlen(note->text))
    {
        warn_w = gnome_warning_dialog_parented(_("Nothing to decrypt!"),
                                               yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }

    tmpfname = tmpnam(NULL);
    if (tmpfname == NULL)
    {
        warn_w = gnome_warning_dialog_parented(_("Can't create tmp filename!"),
                                               yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }
    fd = safe_open(tmpfname, O_CREAT | O_EXCL | O_WRONLY);
    if (fd == -1)
    {
        warn_w = gnome_warning_dialog_parented(_("Can't open tmp file!"),
                                               yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }
    write(fd, note->text, strlen(note->text));
    close(fd);

    tmpcmd = g_strdup_printf(sys_buf, tmpfname);
    
    pass_entry = gtk_object_get_user_data(GTK_OBJECT(p));
    setenv("PGPPASSFD", "0", 1);
    
    pgp_pid = run_pgp(tmpcmd, &pgpin, &pgpout, &pgperr);

    if (pgp_pid == -1)
    {
        warn_w = gnome_warning_dialog_parented(_("Error while running pgp!"),
                                               yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        
        unsetenv("PGPPASSFD");
        unlink(tmpfname);
        g_free(tmpcmd);
        return;
    }
    
    if (pgpin && pgpout)
    {
        fprintf(pgpin, "%s\n", gtk_entry_get_text(GTK_ENTRY(pass_entry)));
        fwrite(note->text, sizeof (gchar), strlen(note->text), pgpin);
        fclose(pgpin);

        gtk_text_freeze(GTK_TEXT(text_entry));
        gtk_editable_delete_text(GTK_EDITABLE(text_entry), 0,
                                 gtk_text_get_length(GTK_TEXT(text_entry)));
        do
        {
            fgets(tmpbuf, sizeof (tmpbuf), pgpout);
            if (!feof(pgpout))
            {
                gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL,
                                tmpbuf, strlen(tmpbuf));
            }
        } while (!feof(pgpout));
        gtk_text_thaw(GTK_TEXT(text_entry));
        
        fclose(pgpout);
        fclose(pgperr);
        
        if ((gtk_text_get_length(GTK_TEXT(text_entry)) == 0) && note->text)
        {
            warn_w = gnome_warning_dialog_parented(_("Pgp didn't return any\
 text. Maybe your're using the wrong password?"), yank_root_win(NULL));
            gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
            gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL,
                            note->text, strlen(note->text));
        }
コード例 #3
0
ファイル: pgp5.c プロジェクト: jeansch/yank-component
static void
cb_encrypt(GtkWidget *w, gpointer p)
{
    GtkWidget    *pass_entry;
    GtkWidget    *warn_w;
    FILE         *pgpin;
    FILE         *pgpout;
    FILE         *pgperr;
    static gchar sys_buf[] = "pgpe -catfq +batchmode";
    gchar        tmpbuf[1024];
    note_data    *note;
    
    g_return_if_fail(p != NULL);
    g_return_if_fail(GNOME_IS_DIALOG(p));

    if (selected_node == NULL)
    {
        warn_w = gnome_warning_dialog_parented(
            _("Select a note first!"), yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }

    ask_commit_changes();

    note = (note_data *) gtk_ctree_node_get_row_data(
        GTK_CTREE(note_tree), GTK_CTREE_NODE(selected_node));
    
    if (!note->text || !strlen(note->text))
    {
        warn_w = gnome_warning_dialog_parented(_("Nothing to encrypt!"),
                                               yank_root_win(NULL));
        gtk_window_set_modal(GTK_WINDOW(warn_w), TRUE);
        return;
    }
    
    pass_entry = gtk_object_get_user_data(GTK_OBJECT(p));
    setenv("PGPPASSFD", "0", 1);
    run_pgp(sys_buf, &pgpin, &pgpout, &pgperr); /*Execute PGP*/

    if(pgpin && pgpout)
    {
        fprintf(pgpin, "%s\n", gtk_entry_get_text(GTK_ENTRY(pass_entry)));
        /*Output buffer to PGP:*/
        fwrite(note->text, sizeof(gchar), strlen(note->text), pgpin);
        fclose(pgpin);

        gtk_text_freeze(GTK_TEXT(text_entry));
        gtk_editable_delete_text(GTK_EDITABLE(text_entry), 0,
                                 gtk_text_get_length(GTK_TEXT(text_entry)));
        /*Now, read the result back from PGP:*/
        do
        {
            fgets(tmpbuf, sizeof(tmpbuf), pgpout);
            if (!feof(pgpout))
            {
                gtk_text_insert(GTK_TEXT(text_entry), NULL, NULL, NULL,
                                tmpbuf, strlen(tmpbuf));
            }
        } while (!feof(pgpout));
        gtk_text_thaw(GTK_TEXT(text_entry));
        
        fclose(pgpout);
    }
    unsetenv("PGPPASSFD");
}