Exemplo n.º 1
0
bool KviApplication::findImageThemeOnlyCompat(QString &szRetPath,const QString &filename)
{
	// if we have a theme, look it up as first
	if(!KVI_OPTION_STRING(KviOption_stringIconThemeSubdir).isEmpty())
	{
		QString szTmp = KVI_OPTION_STRING(KviOption_stringIconThemeSubdir);
		szTmp.append(KVI_PATH_SEPARATOR_CHAR);
		szTmp.append(filename);

		getLocalKvircDirectory(szRetPath,KviApplication::Themes,szTmp);
		if(KviFileUtils::fileExists(szRetPath))return true;

		getGlobalKvircDirectory(szRetPath,KviApplication::Themes,szTmp);
		if(KviFileUtils::fileExists(szRetPath))return true;
	}

	getLocalKvircDirectory(szRetPath,KviApplication::Pics,filename);
	if(KviFileUtils::fileExists(szRetPath))return true;


	if(findImageInImageSearchPath(szRetPath,filename))return true;

	szRetPath = filename;

	return false;
}
Exemplo n.º 2
0
bool KviApplication::findImage(QString & szRetPath, const QString & filename)
{
	// Find a user file...
	if(KviFileUtils::isAbsolutePath(filename))
	{
		szRetPath = filename;
		return KviFileUtils::fileExists(filename);
	}

	// if we have a theme, look it up as first
	if(!KVI_OPTION_STRING(KviOption_stringIconThemeSubdir).isEmpty())
	{
		QString szTmp = KVI_OPTION_STRING(KviOption_stringIconThemeSubdir);
		szTmp.append(KVI_PATH_SEPARATOR_CHAR);
		szTmp.append(filename);
		getLocalKvircDirectory(szRetPath, KviApplication::Themes, szTmp);
		if(KviFileUtils::fileExists(szRetPath))
			return true;

		getGlobalKvircDirectory(szRetPath, KviApplication::Themes, szTmp);
		if(KviFileUtils::fileExists(szRetPath))
			return true;
	}

	int i;

	for(i = 0; i < 2; i++)
	{
		getLocalKvircDirectory(szRetPath, pics_localsubdirs[i], filename);
		if(KviFileUtils::fileExists(szRetPath))
			return true;
	}

	for(i = 0; i < 2; i++)
	{
		getGlobalKvircDirectory(szRetPath, pics_globalsubdirs[i], filename);
		if(KviFileUtils::fileExists(szRetPath))
			return true;
	}

	if(findImageInImageSearchPath(szRetPath, filename))
		return true;

	// Last resort
	szRetPath = QDir::homePath();
	KviQString::ensureLastCharIs(szRetPath, KVI_PATH_SEPARATOR_CHAR);
	szRetPath.append(filename);
	if(KviFileUtils::fileExists(szRetPath))
		return true;

	szRetPath = filename;

	return false;
}
Exemplo n.º 3
0
bool KviApplication::findSmallIcon(QString &szRetPath,const QString &filename)
{
	// this is a bit optimized for the small builtin icons
	// looks up less places.

	//if(kvi_isAbsolutePath(filename))
	//{
		// BUG!.. we should never
		//szRetPath=filename;
		//return KviFileUtils::fileExists(filename);
	//}

	// if we have a theme, look it up as first
	if(!KVI_OPTION_STRING(KviOption_stringIconThemeSubdir).isEmpty())
	{
		QString szTmp = KVI_OPTION_STRING(KviOption_stringIconThemeSubdir);
		szTmp.append(KVI_PATH_SEPARATOR_CHAR);
		szTmp.append(KVI_SMALLICONS_SUBDIRECTORY);
		szTmp.append(KVI_PATH_SEPARATOR_CHAR);
		szTmp.append(filename);

		getLocalKvircDirectory(szRetPath,KviApplication::Themes,szTmp);
		if(KviFileUtils::fileExists(szRetPath))return true;

		getGlobalKvircDirectory(szRetPath,KviApplication::Themes,szTmp);
		if(KviFileUtils::fileExists(szRetPath))return true;
	}

	// unlikely
	getLocalKvircDirectory(szRetPath,KviApplication::SmallIcons,filename);
	if(KviFileUtils::fileExists(szRetPath))return true;

	getLocalKvircDirectory(szRetPath,KviApplication::Pics,filename);
	if(KviFileUtils::fileExists(szRetPath))return true;

	// likely
	getGlobalKvircDirectory(szRetPath,KviApplication::SmallIcons,filename);
	if(KviFileUtils::fileExists(szRetPath))return true;

	if(findImageInImageSearchPath(szRetPath,filename))return true;

	// Last resort... bleah :/
	szRetPath = QDir::homePath();
	KviQString::ensureLastCharIs(szRetPath,KVI_PATH_SEPARATOR_CHAR);
	szRetPath.append(filename);
	if(KviFileUtils::fileExists(szRetPath))return true;

	szRetPath = filename;

	return false;
}
Exemplo n.º 4
0
bool KviApplication::findAudioFile(QString &szRetPath,const QString &szFileName)
{
	if(KviFileUtils::isAbsolutePath(szFileName))
	{
		szRetPath = szFileName;
		return KviFileUtils::fileExists(szFileName);
	}

	getLocalKvircDirectory(szRetPath,KviApplication::Audio,szFileName);
	if(KviFileUtils::fileExists(szRetPath))
		return true;

	getGlobalKvircDirectory(szRetPath,KviApplication::Audio,szFileName);
	if(KviFileUtils::fileExists(szRetPath))
		return true;

	// Last resort
	szRetPath = QDir::homePath();
	KviQString::ensureLastCharIs(szRetPath,KVI_PATH_SEPARATOR_CHAR);
	szRetPath.append(szFileName);
	if(KviFileUtils::fileExists(szRetPath))
		return true;

	szRetPath = szFileName;

	return false;
}
Exemplo n.º 5
0
bool KviApplication::getReadOnlyConfigPath(QString &buffer,const char *config_name,KvircSubdir sbd,bool bNoFail)
{
	// Take a look in the local directory....
	getLocalKvircDirectory(buffer,sbd,config_name);
	//qDebug("%s %s %i |%s| %i",__FILE__,__FUNCTION__,__LINE__,buffer.ptr(),KviFileUtils::fileExists(buffer.ptr()));
	if(!KviFileUtils::fileExists(buffer))
	{
		// No saved config yet... check for defaults
		QString tmp;
		getGlobalKvircDirectory(tmp,sbd,config_name);
		if(!KviFileUtils::fileExists(tmp))
		{
			// No defaults...no such config file at all.
			if(bNoFail)getLocalKvircDirectory(buffer,sbd,config_name);
			return false;
		} else buffer = tmp; // get the defaults this time
	} // else file exists...
	return true;
}
Exemplo n.º 6
0
bool KviApplication::checkLocalKvircDirectory()
{
	//First check if the dir exists
	if(!KviFileUtils::directoryExists(m_szLocalKvircDir))
		return false;
	if(!QFileInfo(m_szLocalKvircDir).isWritable())
		return false;

	QString szBuff;
	getLocalKvircDirectory(szBuff, Config);
	if(!KviFileUtils::directoryExists(szBuff))
		return false;

	return true;
}
Exemplo n.º 7
0
void KviApplication::getTmpFileName(QString &szBuffer,const QString &szEndingFileName)
{
	QString tmp;
	getLocalKvircDirectory(tmp,Tmp);
	KviQString::ensureLastCharIs(tmp,KVI_PATH_SEPARATOR_CHAR);

	struct timeval tmv;
	kvi_gettimeofday(&tmv,0);

	QString szFileName = szEndingFileName.isNull() ? QString("file.tmp") : szEndingFileName;
	do {
		szBuffer = tmp;
		KviQString::appendFormatted(szBuffer,"kvirc_%d_%Q",tmv.tv_usec,&szFileName);
		tmv.tv_usec++;
	} while(KviFileUtils::fileExists(szBuffer));
}
Exemplo n.º 8
0
void KviApplication::getChannelDumpLogFileName(QString & szStr)
{
	unsigned int uLogN = 0;
	QString szPrefix = "kick_";
	do{
		QString szName = QString("%1%2.log").arg(szPrefix).arg(uLogN);
		getLocalKvircDirectory(szStr,Log,szName);
		uLogN++;
		if(uLogN > 9999)
		{
			// Time to clear logs! :)
			szPrefix += "x";
			uLogN = 0;
		}
	} while(KviFileUtils::fileExists(szStr));
	KviFileUtils::adjustFilePath(szStr);
}
Exemplo n.º 9
0
bool KviApplication::mapImageFile(QString &szRetPath,const QString &filename)
{
	szRetPath = filename;
	// can't map non absolute paths
	if(!KviFileUtils::isAbsolutePath(filename))return false;
	// can't map non existing paths
	if(!KviFileUtils::fileExists(filename))return false;

	QFileInfo fi = QFileInfo(filename);

	unsigned int size = fi.size();

	QString szBestMatch;

	while(szRetPath.indexOf(KVI_PATH_SEPARATOR) != -1)
	{
		KviQString::cutToFirst(szRetPath,KVI_PATH_SEPARATOR);

		if(szRetPath.isEmpty())break;

		QString szBuffer;

		int i;

		for(i=0;i<2;i++)
		{
			getLocalKvircDirectory(szBuffer,pics_localsubdirs[i],szRetPath);
			if(KviFileUtils::fileExists(szBuffer))
			{
				QFileInfo fi2(szBuffer);
				if(size == fi2.size())
				{
					// probably the same file
					szBestMatch = szRetPath;
				}
			}
		}

		for(i=0;i<2;i++)
		{
			getGlobalKvircDirectory(szBuffer,pics_globalsubdirs[i],szRetPath);
			//qDebug("CHECK %s",szBuffer.ptr());
			if(KviFileUtils::fileExists(szBuffer))
			{
				QFileInfo fi2(szBuffer);
				if(size == fi2.size())
				{
					// probably the same file
					szBestMatch = szRetPath;
				}
			}
		}

		// Last resort
		szBuffer = QDir::homePath();
		KviQString::ensureLastCharIs(szBuffer,KVI_PATH_SEPARATOR_CHAR);
		szBuffer.append(szRetPath);
		if(KviFileUtils::fileExists(szBuffer))
		{
			QFileInfo fi2(szBuffer);
			if(size == fi2.size())
			{
				// prolly the same file
				szBestMatch = szRetPath;
			}
		}
	}

	if(!szBestMatch.isEmpty())
	{
		szRetPath = szBestMatch;
		return true;
	}


	// no way to map it :/
	szRetPath = filename;
	return false;
}