示例#1
0
static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c)
{
	QString szTheme;

	KVSM_PARAMETERS_BEGIN(c)
	KVSM_PARAMETER("theme", KVS_PT_STRING, 0, szTheme)
	KVSM_PARAMETERS_END(c)

	KviThemeInfo out;
	KviThemeInfo::Location eLocation = KviThemeInfo::Auto;

	if(c->switches()->find('b', "builtin"))
		eLocation = KviThemeInfo::Builtin;
	else if(c->switches()->find('e', "external"))
		eLocation = KviThemeInfo::External;
	else if(c->switches()->find('u', "user"))
		eLocation = KviThemeInfo::User;

	if(!KviTheme::apply(szTheme, eLocation, out))
	{
		QString szErr = out.lastError();
		c->error(__tr2qs_ctx("Failed to apply theme: %Q", "theme"), &szErr);
		return false;
	}

	return true;
}
/*
	@doc: theme.apply
	@type:
		command
	@title:
		theme.apply
	@short:
		Apply a theme.
	@syntax:
		theme.apply <package_name:string>
	@description:
		Attempts to apply the theme specified by <package_name>.
*/
static bool theme_kvs_cmd_apply(KviKvsModuleCommandCall * c)
{
	QString szThemePackFile;

	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("package_name",KVS_PT_STRING,0,szThemePackFile)
	KVSM_PARAMETERS_END(c)
	KviThemeInfo * themeInfo = new KviThemeInfo();
	if(themeInfo->load(szThemePackFile))
	{
		themeInfo->setSubdirectory(szThemePackFile);
		if(KviMessageBox::yesNo(__tr2qs_ctx("Apply theme - KVIrc","theme"),
		__tr2qs_ctx("Do you wish to apply theme \"%Q\" (version %Q)?","theme"),
		&(themeInfo->name()),&(themeInfo->version())))
		{
			KviThemeInfo out;
			if(!KviTheme::load(szThemePackFile,out))
			{
				QString szErr = out.lastError();
				QString szMsg = QString(__tr2qs_ctx("Failed to apply the specified theme: %1","theme")).arg(szErr);
				QMessageBox::critical(0,__tr2qs_ctx("Apply theme - KVIrc","theme"),szMsg,
				QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
			}
			return true;
		}
	}
	c->warning(__tr2qs_ctx("The theme package '%Q' does not exist","theme"),&szThemePackFile);
	return true;
}
static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c)
{
	QString szFileName;

	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("file_name_path",KVS_PT_STRING,KVS_PF_OPTIONAL,szFileName)
	KVSM_PARAMETERS_END(c)


	KviFileUtils::adjustFilePath(szFileName);

	QString szTmp;
	c->enterBlockingSection();

	bool bResult = KviFileDialog::askForSaveFileName(szTmp,__tr2qs_ctx("Choose a file to save the screenshot to","theme"),szFileName,"*.png");

	if(!c->leaveBlockingSection())return false; // need to stop immediately
	if(!bResult)return true;

	szFileName = szTmp;

	if(szFileName.isEmpty())return true; // done
	KviFileUtils::adjustFilePath(szFileName);
	if(QFileInfo(szFileName).suffix()!="png")
		szFileName+=".png";

	QString szError;
	if(!ThemeFunctions::makeKVIrcScreenshot(szFileName))
	{
		c->error(__tr2qs_ctx("Error making screenshot","theme")); // FIXME: a nicer error ?
		return false;
	}

	return true;
}
/*
	@doc: theme.info
	@type:
		function
	@title:
		theme.info
	@short:
		Return info about an user defined theme.
	@syntax:
		<themes_list:string> $theme.info(<theme_name:string>)
	@description:
		Returns as hash the info about an user definded theme.
		Hash keys are: name, version, author, description.
*/
static bool theme_kvs_fnc_info(KviKvsModuleFunctionCall * c)
{
	QString szThemePackFile;

	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("package_name",KVS_PT_STRING,0,szThemePackFile)
	KVSM_PARAMETERS_END(c)
	KviThemeInfo * themeInfo = new KviThemeInfo();
	if(themeInfo->load(szThemePackFile))
	{
		KviKvsHash *pHash=new KviKvsHash();
		KviKvsVariant *name=new KviKvsVariant(themeInfo->name());
		pHash->set("name",name);
		KviKvsVariant *version=new KviKvsVariant(themeInfo->version());
		pHash->set("version",version);
		KviKvsVariant *author=new KviKvsVariant(themeInfo->author());
		pHash->set("author",author);
		KviKvsVariant *description=new KviKvsVariant(themeInfo->description());
		pHash->set("description",description);
		c->returnValue()->setHash(pHash);
		return true;
	}
	c->warning(__tr2qs_ctx("The theme package '%Q' does not exist","theme"),&szThemePackFile);
	return true;
}
示例#5
0
static bool theme_kvs_cmd_pack(KviKvsModuleCommandCall * c)
{
	QString szPath, szName, szVersion, szDescription, szAuthor, szImage;

	KviKvsArrayCast aCast;

	KVSM_PARAMETERS_BEGIN(c)
	KVSM_PARAMETER("package_path", KVS_PT_NONEMPTYSTRING, 0, szPath)
	KVSM_PARAMETER("package_name", KVS_PT_NONEMPTYSTRING, 0, szName)
	KVSM_PARAMETER("package_version", KVS_PT_NONEMPTYSTRING, 0, szVersion)
	KVSM_PARAMETER("package_description", KVS_PT_STRING, 0, szDescription)
	KVSM_PARAMETER("package_author", KVS_PT_NONEMPTYSTRING, 0, szAuthor)
	KVSM_PARAMETER("package_image", KVS_PT_STRING, 0, szImage)
	KVSM_PARAMETER("theme", KVS_PT_ARRAYCAST, 0, aCast)
	KVSM_PARAMETERS_END(c)

	KviKvsArray * pArray = aCast.array();
	if((!pArray) || (pArray->size() < 1))
	{
		c->error(__tr2qs_ctx("No themes specified", "theme"));
		return false;
	}

	kvs_uint_t s = pArray->size();
	QStringList lThemeList;

	for(kvs_uint_t i = 0; i < s; i++)
	{
		KviKvsVariant * v = pArray->at(i);
		if(!v)
			continue; // ?
		QString szVal;
		v->asString(szVal);
		if(szVal.isEmpty())
			continue;
		lThemeList.append(szVal);
	}

	KviPointerList<KviThemeInfo> lThemeInfoList;
	lThemeInfoList.setAutoDelete(true);

	Q_FOREACH(QString szTheme, lThemeList)
	{
		KviThemeInfo * pInfo = new KviThemeInfo();
		if(!pInfo->load(szTheme, KviThemeInfo::External))
		{
			QString szErr = pInfo->lastError();
			c->error(__tr2qs_ctx("Failed to load theme from directory %Q: %Q", "theme"), &szTheme, &szErr);
			delete pInfo;
			return false;
		}

		lThemeInfoList.append(pInfo);
	}
/*
	@doc: spellchecker.check
	@type:
		function
	@title:
		$spellchecker.check
	@short:
		Check a single work for spelling mistakes.
	@syntax:
		<bool> $spellchecker.check(<word:string>)
	@description:
		This function returns true if the word is spelled correctly.
*/
static bool spellchecker_kvs_check(KviKvsModuleFunctionCall* c)
{
	QString szWord;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("word", KVS_PT_STRING, 0, szWord)
	KVSM_PARAMETERS_END(c)
	QByteArray utf8 = szWord.toUtf8();
	bool bResult = g_pEnchantDicts->isEmpty();
	KviPointerListIterator<EnchantDict> it(*g_pEnchantDicts);
	for (bool b = it.moveFirst(); b; b = it.moveNext())
		bResult |= enchant_dict_check(*it, utf8.data(), utf8.size()) == 0;

	c->returnValue()->setBoolean(bResult);
	return true;
}
示例#7
0
static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c)
{
	QString szFileName;

	KVSM_PARAMETERS_BEGIN(c)
	KVSM_PARAMETER("file_name_path", KVS_PT_STRING, KVS_PF_OPTIONAL, szFileName)
	KVSM_PARAMETERS_END(c)

	KviFileUtils::adjustFilePath(szFileName);

	QString szTmp;
	c->enterBlockingSection();

	bool bResult = KviFileDialog::askForSaveFileName(
	    szTmp,
	    __tr2qs_ctx("Enter a Filename - KVIrc", "theme"), //dialog header title
	    szFileName,
	    "*.png",
	    false,
	    false,
	    true,
	    g_pMainWindow);

	if(!c->leaveBlockingSection())
		return false; // need to stop immediately

	if(!bResult)
		return true;

	szFileName = szTmp;

	if(szFileName.isEmpty())
		return true; // done

	KviFileUtils::adjustFilePath(szFileName);
	if(QFileInfo(szFileName).suffix() != "png")
		szFileName += ".png";

	QString szError;
	if(!ThemeFunctions::makeKVIrcScreenshot(szFileName))
	{
		c->error(__tr2qs_ctx("Error capturing and saving screenshot!", "theme"));
		return false;
	}

	return true;
}
示例#8
0
static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c)
{
	QString szThemePackFile;

	KVSM_PARAMETERS_BEGIN(c)
	KVSM_PARAMETER("package_path", KVS_PT_STRING, 0, szThemePackFile)
	KVSM_PARAMETERS_END(c)

	QString szError;
	if(!ThemeFunctions::installThemePackage(szThemePackFile, szError))
	{
		c->error(__tr2qs_ctx("Error installing theme package: %Q", "theme"), &szError);
		return false;
	}

	return true;
}
示例#9
0
static bool language_kvs_cmd_detect(KviKvsModuleFunctionCall * c)
{
	QString text, error;
	KviKvsArray *matches;
	KviKvsHash *match, *ret;
	LanguageAndEncodingResult r;
	int matchcount=DLE_NUM_BEST_MATCHES;

	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("text",KVS_PT_STRING,KVS_PF_OPTIONAL,text)
	KVSM_PARAMETERS_END(c)

	//on error we return an empty array
	matches = new KviKvsArray();

	if(text.isEmpty()){
		error = "err_notext";
		matchcount = 0;
	} else {
		detect_language_and_encoding(text.toUtf8().data(),&r,0);

		for(int i=0;i<matchcount;i++)
		{
			match = new KviKvsHash();
			match->set("language",new KviKvsVariant(QString(r.match[i].szLanguage)));
			match->set("encoding",new KviKvsVariant(r.match[i].szEncoding));
			match->set("score",new KviKvsVariant((kvs_real_t)r.match[i].dScore));
			matches->set(i, new KviKvsVariant(match));
		}
	}

	ret = new KviKvsHash();
	ret->set("matches",new KviKvsVariant(matches));
	ret->set("matchcount",new KviKvsVariant((kvs_int_t)matchcount));
	ret->set("error",new KviKvsVariant(error));
	ret->set("accuracy",new KviKvsVariant((kvs_real_t)r.dAccuracy));

	c->returnValue()->setHash(ret);

	return true;
}
示例#10
0
static bool perl_kvs_cmd_destroy(KviKvsModuleCommandCall * c)
{
	QString szContext;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("context",KVS_PT_NONEMPTYSTRING,0,szContext)
	KVSM_PARAMETERS_END(c)

	KVS_CHECK_MODULE_STATE(m,c)

#ifdef COMPILE_PERL_SUPPORT
	KviPerlCoreCtrlCommand_destroy ex;
	ex.uSize = sizeof(KviPerlCoreCtrlCommand_destroy);
	ex.szContext = szContext;

	if(!g_pPerlCoreModule->ctrl(KVI_PERLCORECTRLCOMMAND_DESTROY,&ex))
	{
		if(!c->switches()->find('q',"quiet"))
			c->warning(__tr2qs_ctx("The perlcore module failed to execute the code: something is wrong with the perl support","perl"));
	}
#endif //COMPILE_PERL_SUPPORT

	return true;
}
示例#11
0
static bool theme_kvs_fnc_info(KviKvsModuleFunctionCall * c)
{
	QString szTheme;

	KVSM_PARAMETERS_BEGIN(c)
	KVSM_PARAMETER("theme", KVS_PT_STRING, 0, szTheme)
	KVSM_PARAMETERS_END(c)

	KviKvsHash * pHash = new KviKvsHash();
	c->returnValue()->setHash(pHash);

	KviThemeInfo theme;
	if(!theme.load(szTheme, KviThemeInfo::Auto))
	{
		c->warning(__tr2qs_ctx("The theme package '%Q' doesn't exist", "theme"), &szTheme);
		return true;
	}

	pHash->set("name", new KviKvsVariant(theme.name()));
	pHash->set("version", new KviKvsVariant(theme.version()));
	pHash->set("author", new KviKvsVariant(theme.author()));
	pHash->set("description", new KviKvsVariant(theme.description()));
	return true;
}
示例#12
0
static bool perl_kvs_cmd_begin(KviKvsModuleCommandCall * c)
{
	// This command is somewhat special in the fact that has a dedicated
	// parsing routine in the KVS core parser.
	// The parser sets the perl code as the first parameter of our call,
	// the remaining params are the context name and the arguments

	QString szCode,szContext;
	KviKvsVariantList vList;
	KVSM_PARAMETERS_BEGIN(c)
		KVSM_PARAMETER("code",KVS_PT_STRING,0,szCode)
		KVSM_PARAMETER("context",KVS_PT_STRING,KVS_PF_OPTIONAL,szContext)
		KVSM_PARAMETER("args",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList)
	KVSM_PARAMETERS_END(c)

	KVS_CHECK_MODULE_STATE(m,c)

#ifdef COMPILE_PERL_SUPPORT
	KviPerlCoreCtrlCommand_execute ex;
	ex.uSize = sizeof(KviPerlCoreCtrlCommand_execute);
	ex.pKvsContext = c->context();
	ex.szContext = szContext;
	ex.szCode = szCode;
	for(KviKvsVariant * v = vList.first();v;v = vList.next())
	{
		QString tmp;
		v->asString(tmp);
		ex.lArgs.append(tmp);
	}
	ex.bQuiet = c->switches()->find('q',"quiet");

	if(!g_pPerlCoreModule->ctrl(KVI_PERLCORECTRLCOMMAND_EXECUTE,&ex))
	{
		if(!c->switches()->find('q',"quiet"))
			c->warning(__tr2qs_ctx("The perlcore module failed to execute the code: something is wrong with the perl support","perl"));
		return true;
	}

	if(!ex.lWarnings.isEmpty())
	{
		for(QStringList::Iterator it = ex.lWarnings.begin();it != ex.lWarnings.end();++it)
			c->warning(*it);
	}

	if(!ex.bExitOk)
	{
		if(!c->switches()->find('q',"quiet"))
		{

			if(c->switches()->find('f',"fail-on-error"))
			{
				c->warning(__tr2qs_ctx("Perl execution error:","perl"));
				c->warning(ex.szError);
				return false;
			} else {
				c->warning(__tr2qs_ctx("Perl execution error:","perl"));
				c->error(ex.szError);
			}
		}
	}

	if(!c->switches()->find('n',"no-return"))
		c->context()->returnValue()->setString(ex.szRetVal);

#endif //COMPILE_PERL_SUPPORT

	return true;
}