/*
 *  Copyright (C) 2004 Morten Fjord-Larsen
 *
 *  $Id: main.c,v 1.8 2004/06/12 14:45:50 fjord Exp $
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gnome.h>
#include <glade/glade.h>
#include <gconf/gconf-client.h>

#if 0
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-application.h>
#endif


#include "passwordchange.h"
#include "passwordentry.h"
#include "app.h"
#include "clipboard.h"
#include "preferences.h"

GConfClient *gconf_client = NULL;
GnomeClient *gnome_client = NULL;


#if 0
static void 
new_instance (BonoboAppClient *app_client, int argc, char *argv[])
{
    g_message("new-instance");
}
#endif

#if 0
static void 
unique_app (int *argcp, char *argv[])
{
    BonoboApplication *app;
    BonoboAppClient *client = NULL;
    gchar *serverinfo;
    Bonobo_RegistrationResult rv;

    bonobo_init(argcp, argv);

    app = bonobo_application_new("GNOME_Password_Manager");
    g_assert(app != NULL);

    serverinfo = bonobo_application_create_serverinfo(app, NULL);
    g_assert(serverinfo != NULL);

    rv = bonobo_application_register_unique(app, serverinfo, &client);
    g_free(serverinfo);

    bonobo_object_unref(app);

    if (rv == Bonobo_ACTIVATION_REG_ALREADY_ACTIVE) {
	g_message(_("One instance of Password Manager is already running."));
	//g_assert(client != NULL);
	//bonobo_app_client_new_instance(client, *argcp, argv, NULL);
	bonobo_object_unref(client);
	exit(1);
    } 
#if 0
    else {
	g_signal_connect(app, "new-instance", G_CALLBACK(new_instance), NULL);
    }
#endif
}
#endif


int main (int argc, char *argv[])
{
    GnomeProgram *app;

#ifdef ENABLE_NLS
    bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    textdomain (PACKAGE);
#endif

#if 0
    unique_app(&argc, argv);
#endif

    app = gnome_program_init(PACKAGE, VERSION, LIBGNOMEUI_MODULE,
	                     argc, argv, GNOME_PARAM_POPT_TABLE, NULL,
			     GNOME_PARAM_NONE);


    glade_gnome_init ();

    g_set_application_name (_("Password Manager"));

    gnome_client = gnome_master_client();
    gnome_client_set_restart_style(gnome_client, GNOME_RESTART_IF_RUNNING);
    gnome_client_set_restart_command(gnome_client, argc, argv);

    gconf_client = gconf_client_get_default ();
    gconf_client_add_dir (gconf_client,
	    GCONF_PATH,
	    GCONF_CLIENT_PRELOAD_ONELEVEL,
	    NULL);

    password_change_dialog_setup();
    password_entry_setup();
    app_init();

    gtk_main ();

    g_object_unref(gconf_client);
    clipboard_clear();

    return 0;
}
