Example #1
0
bool KDirectory::createDir(const KData& dir)
{
	int pos = 0;
	while (true)
	{
		if ((pos = dir.find("/", pos)) == -1)
			pos = dir.length();
		KData dtDir = dir.substr(0, pos);
		pos++;
		if (!dtDir.isEmpty())
		{
			if (!isDirectoryExist(dtDir))
			{
				/*
				 if ( -1 == mkdir(dtDir.getData(),S_IRWXU|S_IRWXG|S_IRWXO) )
				 {
				 return false;
				 }
				 */
				if (MKDIR(dtDir.getData()) != 0)
				{
					return false;
				}

			}
		}
		if (pos >= (int) dir.length())
			break;
	}
	return true;
}
Example #2
0
/*
 bool KDirectory::isDirEmpty( const KData& fullDir )
 {
 KData dtDir = fullDir;
 dtDir.makePath( true );
 DIR* dir;
 if ( (dir=opendir(dtDir.getData())) == NULL )
 return false;
 struct dirent *pDirent;
 while( ( pDirent = readdir(dir) ) != NULL  )
 {
 struct stat statbuf;
 KData dtPath = dtDir;
 dtPath += pDirent->d_name;
 if ( stat(dtPath.getData(),&statbuf) == -1 )
 continue;
 if ( S_ISDIR(statbuf.st_mode) )
 {
 if ( pDirent->d_name && strcmp(pDirent->d_name,".") && strcmp(pDirent->d_name,"..") )
 {
 if ( !isDirEmpty(dtPath) )
 {
 closedir( dir );
 return false;
 }
 }
 }
 else
 {
 closedir( dir );
 return false;
 }
 }
 closedir( dir );
 return true;

 }
 */
bool KDirectory::open(const KData& directory, bool create)
{
	if (directory.isEmpty())
	{
		return false;
	}

	KData dir = directory;
	int pos;
	KData dtKData = "\\";
	while ((pos = dir.find(dtKData)) != -1)
	{
		dir.replace(pos, 1, "/");
	}
	_directory.erase();

	bool bDirExist = isDirectoryExist(dir);
	if (!bDirExist)
	{
		if (create)
		{
			if (!createDir(dir))
				return false;
		}
		else
		{
			return false;
		}
	}
	_directory = dir;
	_directory.makePath();
	return true;
}
Example #3
0
void DischargeItemTable::setData(const KData& d)
{
    if (d.isEmpty())
        return;

    //set row count
    this->setRowCount(d.count()+1);

    //setup data
    for(int k = 0; k < d.count(); k++) {
        const KDataItem &item = d.at(k);
        QTableWidgetItem * cell = new QTableWidgetItem(item.name());
        setItem(k, 0, cell);

        cell = new QTableWidgetItem(item.value().toString());
        setItem(k, 1, cell);
    }
}
Example #4
0
bool KDirectory::createFileDir(const KData& dir)
{
	int pos = 0;
	while (true)
	{
		if ((pos = dir.find("/", pos)) == -1)
			break;
		KData dtDir = dir.substr(0, pos);
		pos++;
		if (!dtDir.isEmpty())
		{
			if (!isDirectoryExist(dtDir))
			{
				if (MKDIR(dtDir.getData()) != 0)
				{
					return false;
				}
			}
		}
	}
	return true;
}