/* 
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *         (C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#include <err.h>
#include <unistd.h>

#include <kaboutdata.h>
#include <ksystemtray.h>
#include <kcmdlineargs.h>
#include <kuniqueapplication.h>

#include <dbsdglobal.h>
#include <user.h>
#include <users.h>
#include <translation.h>

#include <mountertray.h>
#include <graphics.h>


int  main(int argc,  char *argv[]) {
	/* Disable permission check when not running
	 * on native DesktopBSD.
	 */
	if(DBSDGlobal::isNativeDesktopBSD()) {
		uid_t uid = getuid();
		if(uid > 0)
		{
			struct passwd *p = getpwuid(uid);
			if(p == NULL)
				errx(1, "User doesn't exist (?)");
		
			User *u = Users::getUser(p->pw_name);
			if(u == NULL)
				errx(2, "Obtaining user object failed");
		
			if(!u->isMemberOf("mount"))
				errx(3, "User is not a member of group 'mount'.");
		}
	}

   KAboutData  about("dbsd-traymounter", "Mount Control", "", NULL, KAboutData::License_BSD);
   KCmdLineArgs::init(argc, argv, &about);
   KUniqueApplication::addCmdLineOptions();
   if(!KUniqueApplication::start())
   	errx(0, "already running.");
   
   KUniqueApplication  app;
   
   pixInit();
   Translation::installTranslator();
   
   MounterTray  traymounter;
   app.setMainWidget(&traymounter);
   
   traymounter.show();
   return  app.exec();
};
