示例#1
0
/**
 * main:
 * @argc: default arguments
 * @argv: default arguments
 *
 * Parses the options, daemonizes, starts HKP, DBus and Avahi
 *
 * Returns: 0 on success
 */
int main(int argc, char* argv[])
{
    GOptionContext *octx = NULL;
    GError *error = NULL;

    seahorse_secure_memory_init ();
    
    octx = g_option_context_new ("");
    g_option_context_add_main_entries (octx, options, GETTEXT_PACKAGE);
    g_option_context_add_group (octx, egg_sm_client_get_option_group ());

    if (!gtk_init_with_args (&argc, &argv, _("Encryption Daemon (Seahorse)"), 
                             (GOptionEntry *)options, GETTEXT_PACKAGE, &error)) {
	    g_printerr ("seahorse-daemon: %s\n", error->message);
	    g_error_free (error);
	    exit (1);
    }
     	 
	g_signal_connect (egg_sm_client_get (), "quit", G_CALLBACK (smclient_quit), NULL);

    /*
     * All functions after this point have to print messages
     * nicely and not just called exit()
     */
    daemonize ();

    /* Handle some signals */
    seahorse_unix_signal_register (SIGINT, unix_signal);
    seahorse_unix_signal_register (SIGTERM, unix_signal);

    /* We log to the syslog */
    prepare_logging ();

    /* Insert Icons into Stock */
    seahorse_gtkstock_init ();
   
    /* Make the default SeahorseContext */
    seahorse_context_new (SEAHORSE_CONTEXT_APP | SEAHORSE_CONTEXT_DAEMON);

    /* Load the various components */
    seahorse_pgp_module_init ();

    seahorse_context_refresh_auto (NULL);

    /* Initialize the various daemon components */
    seahorse_dbus_server_init ();

    /* Sometimes we've already gotten a quit signal */
    if(!daemon_quit) {
        daemon_running = TRUE;
        gtk_main ();
        g_message ("left gtk_main\n");
    }

    seahorse_dbus_server_cleanup ();

    g_option_context_free (octx);
    seahorse_context_destroy (SCTX_APP ());

    return 0;
}
int
main (int argc, char **argv)
{
    GOptionContext *octx = NULL;
    SeahorseToolMode mode;
    gchar **uris = NULL;
    int ret = 0;

    seahorse_secure_memory_init ();

#ifdef ENABLE_NLS
    bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
#endif

    /*
     * In order to keep the progress window responsive we use a model
     * where two processes communicate with each other. One does the
     * operations, the other shows the progress window, handles cancel.
     */
    seahorse_tool_progress_init (argc, argv);

    octx = g_option_context_new ("");
    g_option_context_add_main_entries (octx, options, GETTEXT_PACKAGE);

    gtk_init_with_args (&argc, &argv, _("File Encryption Tool"), (GOptionEntry *) options, GETTEXT_PACKAGE, NULL);

    /* Load up all our arguments */
    uris = read_uri_arguments ();

    if(!uris || !uris[0]) {
        fprintf (stderr, "seahorse-tool: must specify files\n");
        return 2;
    }

    /* The basic settings for the operation */
    memset (&mode, 0, sizeof (mode));

    if (mode_encrypt_sign || mode_encrypt) {
        mode.recipients = prompt_recipients (&mode.signer);
        if (mode.recipients) {
            mode.title = _("Encrypting");
            mode.errmsg = _("Couldn't encrypt file: %s");
            mode.startcb = encrypt_sign_start;
            mode.package = TRUE;
        }

    } else if (mode_sign) {
        mode.signer = prompt_signer ();
        if (mode.signer) {
            mode.title = _("Signing");
            mode.errmsg = _("Couldn't sign file: %s");
            mode.startcb = sign_start;
        }

    } else if (mode_import) {
        mode.title = _("Importing");
        mode.errmsg = _("Couldn't import keys from file: %s");
        mode.startcb = import_start;
        mode.donecb = import_done;
        mode.imports = 0;

    } else if (mode_decrypt) {
        mode.title = _("Decrypting");
        mode.errmsg = _("Couldn't decrypt file: %s");
        mode.startcb = decrypt_start;
        mode.donecb = decrypt_done;

    } else if (mode_verify) {
        mode.title = _("Verifying");
        mode.errmsg = _("Couldn't verify file: %s");
        mode.startcb = verify_start;
        mode.donecb = verify_done;

    } else {
        fprintf (stderr, "seahorse-tool: must specify an operation");
        return 2;
    }

    /* Must at least have a start cb to do something */
    if (mode.startcb) {

        ret = seahorse_tool_files_process (&mode, (const gchar**)uris);

        /* Any results necessary */
        if (ret == 0) {
            if (mode_import)
                import_show (&mode);
        }
    }

    /* TODO: This is temporary code. The actual display of these things should
       be via the daemon. */
    g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc)check_dialogs, NULL, NULL);
    gtk_main ();

    if (mode.recipients)
        seahorse_util_free_keys (mode.recipients);
    if (mode.signer)
        gpgme_key_unref (mode.signer);

    g_strfreev (uris);

    return ret;
}