Beispiel #1
0
TrManager::TrManager()
    : Singleton(this)
    , translator(LoadTranslator())
    , kindNames()
    , subNames()
    , shredTypeNames()
{
    for (int i = 0; i < SUB_COUNT; ++i) {
        subNames[i] =
            QCoreApplication::translate("Block", rawSubs[i].toLatin1());
    }
    for (int i = 0; i < KIND_COUNT; ++i) {
        kindNames[i] =
            QCoreApplication::translate("Block", rawKinds[i].toLatin1());
    }

    const QString rawShredTypes[] = { SHRED_TABLE(X_STRING) };
    const char shredChars[] = { SHRED_TABLE(X_CHAR) };

    int index = 0;
    for (const QString& raw : rawShredTypes) {
        shredTypeNames.insert(shredChars[index++],
            QCoreApplication::translate("Shred", raw.toLatin1()));
    }
}
/*!
    \reimp
 */
QObject *SnsrBigClockScreensaverPlugin::createInstance(
    const QServiceInterfaceDescriptor &descriptor,
    QServiceContext *context,
    QAbstractSecuritySession *session)
{
    Q_UNUSED(context);
    Q_UNUSED(session);

    if (descriptor.interfaceName() == QLatin1String(gBigClockInterfaceName)) {
        LoadTranslator();
        return new SnsrBigClockScreensaver();
    }
    return 0;
}
Beispiel #3
0
QTranslator* LeechCraft::Util::InstallTranslator (const QString& baseName,
		const QString& prefix,
		const QString& appName)
{
	const auto& localeName = GetLocaleName ();
	if (auto transl = LoadTranslator (baseName, localeName, prefix, appName))
	{
		qApp->installTranslator (transl);
		return transl;
	}

	qWarning () << Q_FUNC_INFO
			<< "could not load translation file for locale"
			<< localeName
			<< baseName
			<< prefix
			<< appName;
	return nullptr;
}
Beispiel #4
0
int	main(int argc, char	**argv)
{
	bool bAllQueriesDump = true;
	if (argc < 2) 
		PrintUsage();
	else
		if (argc ==	2)
		{
			if (	 !strcmp (argv[0], "-h")
				|| !strcmp (argv[0], "-help")
				|| !strcmp (argv[0], "/h")
				|| !strcmp (argv[0], "/help")
				)
				PrintUsage();
		}
		else
		{
			if (!strcmp(argv [2], "--no-query-dump"))
			{
				bAllQueriesDump	= false;
				fprintf(stderr, "no dump of all queries \n");
			}
			else
				PrintUsage();
		};


	string LockFileName;
	if (!GetLockName(LockFileName))
	{
		return 1;
	};

	string Action =	argv[1];
	if (		(Action	!= "start")
		&&	(Action	!= "start_cli")
		&&	(Action	!= "stop")
		)
		PrintUsage();

	if (Action == "stop")
	{					
		if (access(LockFileName.c_str(), 04) !=	0)
		{
			printf("Seman Daemon was	not	started!\n");
			return 1;
		};
		FILE* fp = fopen (LockFileName.c_str(),	"r");
		if (!fp)
		{
			printf("Cannot open	file %s!\n", LockFileName.c_str());
			return 1;
		};
		pid_t pid;
		fscanf(fp, "%i", &pid);
		fclose (fp);

		if (kill (pid, SIGTERM)	== 0)
		{
			printf ("Seman Daemon was stopped\n");
			remove (LockFileName.c_str());
		}
		else
			printf ("Cannot	send a SIGTERM to the process\n");
		return 1;
	};



	seman_daemon_log	("Entering Seman Daemon");
	if (Action == "start_cli")
	{
		fprintf	(stderr, "removing %s\n",LockFileName.c_str());
		remove(LockFileName.c_str());
	};
	if (access(LockFileName.c_str(), 04) ==	0)
	{
		printf("Daemon already	started!\n");
		return 1;
	};

	if (Action == "start")
	{		
		//	working	as a daemon
		int	fd;	int	i;
		struct rlimit flim;
		if (getppid()!=1)
		{
			signal(SIGTTOU,SIG_IGN);
			signal(SIGTTIN,SIG_IGN);
			signal(SIGTSTP,SIG_IGN);
			if(fork()!=0)
			{
				exit(0);
			};
			setsid();
		}

		getrlimit(RLIMIT_NOFILE, &flim);

		for(fd=0;fd<flim.rlim_max;fd++)
			close(fd);
		chdir("/");

		openlog("Seman Server",	LOG_PID| LOG_CONS, LOG_DAEMON );

	}

	try{
		if (Action == "start_cli")
		{
			fprintf	(stderr, "Open	a lock file	%s\n", LockFileName.c_str());
		}

		syslog(LOG_ALERT, "Open	a lock file	%s\n", LockFileName.c_str());
		FILE* fp = fopen (LockFileName.c_str(),	"w");
		if (!fp)
		{
			syslog(LOG_ALERT, "Cannot open file	%s!\n",	LockFileName.c_str());
			return 1;
		};
		fprintf(fp,	"%i", getpid());
		fclose (fp);


		if (Action == "start_cli")
		{
			fprintf	(stderr, "SocketInitialize...\n");
		}
		seman_daemon_log ("SocketInitialize...");
    	SocketInitialize(false);


		if (Action == "start_cli")
		{
			fprintf	(stderr, "LoadTranslator...\n");
		}
		if (!LoadTranslator ())
		{
			seman_daemon_log ("Cannot load Seman");			
			if (Action == "start_cli")
			{
				fprintf	(stderr, "Cannot load Seman\n");
			}
			SocketDeinitialize();
			return 1;

		};
	


		if (signal (SIGTERM, termination_handler) == SIG_IGN)
			signal (SIGTERM, SIG_IGN);

		if (Action == "start_cli")
			fprintf	(stderr, "\nWaiting	for	accept ... \n");

		while (1)
		{
			sleep(40);
		}
	}
	catch(...)
	{
		if (Action == "start_cli")
		{
			fprintf	(stderr, "An exception	occurred!\n");
		}
		syslog(LOG_ALERT, "An exception	occurred! ");
		UnloadData();
		SocketDeinitialize();
		return -1;
	};

	SocketDeinitialize();	

	return 1;
}