Esempio n. 1
0
void FileUtils::deleteDir(const QString& fileDir)
{
	QDir dir(QDir::currentPath());
	if (!dir.exists(fileDir)) return;
	QDir fdir(fileDir);
	QFileInfoList fileList = fdir.entryInfoList();
	if (fileList.count() > 2)
	{
		for (int i = 0; i < fileList.count(); ++i)
		{
			const QFileInfo file = fileList.at(i);
			if (file.fileName() == "." || file.fileName() == "..")
			{
				continue;
			}
			if (file.isDir())
			{
				deleteDir(fileDir + "/" + file.fileName());
			}
			else
			{
				QString filePath = file.absoluteFilePath();
				QFile::remove(filePath);
			}
		}
	}		
	dir.rmdir(fileDir);
}
//---------------------------------------------------------------------------
void MainWindow::add_default_policy()
{
    QDir policies_dir(":/policies");

    policies_dir.setFilter(QDir::Files);
    QFileInfoList list = policies_dir.entryInfoList();
    for (int i = 0; i < list.count(); ++i)
    {
        QFile file(list[i].absoluteFilePath());

        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
            continue;
        QByteArray schematron = file.readAll();
        const std::string& file_str = list[i].absoluteFilePath().toStdString();
        C.policies.import_schema_from_memory(file_str, schematron.constData(), schematron.length());
    }

    QString path = get_local_folder();
    path += "/policies";
    policies_dir = QDir(path);

    policies_dir.setFilter(QDir::Files);
    list = policies_dir.entryInfoList();
    for (int i = 0; i < list.count(); ++i)
    {
        QFile file(list[i].absoluteFilePath());

        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
            continue;
        QByteArray data = file.readAll();
        C.policies.import_schema_from_memory(list[i].absoluteFilePath().toStdString(),
                                             data.constData(), data.length());
    }
}
bool PathManager::deleteThisDirectoryAndEverythingBelow(QString topDirPath)
{
    {
        QDir topDir(topDirPath);

        if (!topDir.exists()) {
            WLog(QString("The given topDir does not exists: %1").arg(topDirPath));
            return true;
        }

        //First delete any files in the current directory
        QFileInfoList files = topDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden | QDir::System/* | QDir::NoSymLinks*/);
        for(int i = 0; i < files.count(); i++)
        {
            QString currFileInPath = files.at(i).fileName();
            /*QString currFileAbsolutePath = files.at(i).absoluteFilePath();
        if(QFileInfo(currFileAbsolutePath).isSymLink()) {
            // it's a symlink simply remove it
            PATH_MANAGER_INTERNAL_LOG_TO_DATABASE(QString("The dir is a symlink file [%1]. Simply remove it.").arg(currDirAbsolutePath));
            QDir().remove(currDirAbsolutePath);
        }
        else */

            if( !topDir.remove(currFileInPath) ) {
                WLogS << " ! The specified file cannot be removed: " << currFileInPath;
                WLog(QString("The specified file cannot be removed: %1").arg(files.at(i).absoluteFilePath()));
                return false;
            }
        }

        //Now recursively delete any child directories
        QFileInfoList dirs = topDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs);
        for(int i = 0; i < dirs.count(); i++)
        {
            QString currDirAbsolutePath = dirs.at(i).absoluteFilePath();
            if(QFileInfo(currDirAbsolutePath).isSymLink()) {
                // it's a symlink to a dir, simply remove this symlink file
                WLog(QString("The dir is a symlink file [%1]. Simply remove it.").arg(currDirAbsolutePath));
                QDir().remove(currDirAbsolutePath);
            }
            else if( !PathManager::deleteThisDirectoryAndEverythingBelow( currDirAbsolutePath ) ) {
                return false;
            }
        }
    }

    //Finally, remove empty top directory

//    if( !topDir.rmdir(topDir.path()) ) {
    if( !QDir().rmdir(topDirPath) ) {
        WLog(QString("The specified directory cannot be removed: %1. Maybe it's still not empty.").arg(topDirPath));
        return false;
    }

    return true;
}
Esempio n. 4
0
void XMLMoveThread::DelSDPicFile()
{
    //qDebug()<<tr("删除图片开始");
    QDir dir;
    if(!dir.exists("/SDHC"))
    {
        LogMsg("lane", tr("未检测到SD卡,不执行SD卡文件清理操作"));
        //qDebug()<<tr("未检测到SD卡,不执行SD卡文件清理操作");
        return;
    }
    QString dirName = "/SDHC/PicFile";
    if(!dir.exists(dirName))
    {
        LogMsg("lane", tr("SD中不存在图片备份,不执行SD卡文件清理操作"));
        //qDebug()<<tr("SD中不存在图片备份,不执行SD卡文件清理操作");
        return;
    }
    QDate curDate = QDateTime::currentDateTime().addDays(-getLaneInfo()->getPicSaveDay()).date();
    QString tmpFileName = curDate.toString("MMdd");
    dir.setPath(dirName);
    QFileInfoList dirList = dir.entryInfoList(QDir::Dirs,QDir::Time);
    QFileInfo dirInfo;
    int count = dirList.count();
    for(int i = count - 1;i > 0;i--)
    {
        //qDebug()<<tr("SD卡图片文件夹数量:%1").arg(count);
        //保留一个文件夹
        //        if(count <= 3)
        //        {
        //            qDebug()<<tr("保留一个文件夹");
        //            return;
        //        }
        dirInfo = dirList.at(i);
        if(!dirInfo.fileName().startsWith(".") && dirInfo.created().date() <= curDate)
            //if(dirInfo.fileName() == tmpFileName)
        {
            tmpFileName = dirInfo.fileName();
            //qDebug()<<tr("确定要删除文件目录:%1").arg(tmpFileName);
            dir.setPath(dirName + "/" + tmpFileName);
            QFileInfoList fileList = dir.entryInfoList(QDir::Files,QDir::Time);
            for(int i = 0;i < fileList.count();i++)
            {
                if(!dir.exists("/SDHC"))
                {
                    LogMsg("lane", tr("文件清理过程中检测不到SD卡"));
                    //qDebug()<<tr("文件清理过程中检测不到SD卡");
                    return;
                }
                QFile::remove(fileList.at(i).filePath());
            }
            dir.rmdir(dirInfo.filePath());
            //count --;
        }
    }
}
Esempio n. 5
0
QStringList WinApi::DrivesListPretty() {
  QFileInfoList list = QDir::drives();
  QStringList result;
#if (QT_VERSION >= 0x40700)
  result.reserve(list.count());
#endif
  for (int i = 0; i < list.count(); i++) {
    result.append(WinApi::VolumeNamePretty(list.at(i).filePath().left(2)));
  }
  return result;
}
Esempio n. 6
0
void WPSRun::GribLink(QString sDir,QString output_root)
{
    int i1 =0;
    int i2 =0;
    int i3 =0;
    QDir dir(sDir);
    dir.setSorting(QDir::Type|QDir::Reversed);
    QFileInfoList list = dir.entryInfoList();
    QDateTime* dt = new QDateTime();
    QDateTime StartDT = p_namelist_tool->GetDateTimeStart();
    QDateTime EndDT = p_namelist_tool->GetDateTimeEnd();
    QStringList dateList;

    int n;
    if(list.count()>100) //Если файлов очччень много, то берем последние 100
    {
        n = 100;
    } else
    {
        n = list.count();
    }
    for (int iList=0;iList<n;iList++)
    {

        QFileInfo info = list[iList];
        if(info.isFile())
        {
            QString sFilePath = info.filePath();
            p_namelist_tool->GetDateTimeFromGrib2(sFilePath,dt);
            if(*dt<StartDT || *dt>EndDT||dateList.contains(dt->toString("hhmmddMMyyyy")))
                continue;
            dateList<<dt->toString("hhmmddMMyyyy");

            QFile::link(sFilePath, output_root+"GRIBFILE."+Alphabet[i3]+Alphabet[i2]+Alphabet[i1]);
            i1++;
            if(i1>25)
            {
                i1 =0;
                i2++;
                if(i2>25)
                {
                    i2 =0;
                    i3++;
                    if(i3>25)
                    {
                        break;
                    }
                }
            }
        }
    }
}
Esempio n. 7
0
void SlideEffect::findImagesInFolder( const QString& folder )
{
    if ( folder.isNull() )
        return;

    QDir dir( folder );

    if ( !dir.exists() || !dir.isReadable() ) {
        qWarning() << "Folder does not exist or is not readable: "
        << folder << endl;
        return;
    }

    // TODO: make an automated filter, maybe with QImageIO.
    QStringList filters;
    filters << "*.png" << "*.jpg" << "*.jpeg" << "*.tif" << "*.tiff" <<
    "*.gif" << "*.bmp" << "*.xpm" << "*.ppm" <<  "*.pnm"  << "*.xcf" <<
    "*.pcx";
    QStringList filtersUp;
    for ( int i = 0; i < filters.size(); ++i )
        filtersUp << filters.at( i ).toUpper();
    dir.setNameFilters( filters << filtersUp );
    dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks | QDir::AllDirs );

    const QFileInfoList list = dir.entryInfoList();
    for ( int i = 0; i < list.count(); ++i ) {
        QFileInfo fi = list.at( i );
        if ( fi.isFile() )
            m_files.append( fi.filePath() );
        else if ( fi.isDir() && m_searchRecursive &&
                  fi.fileName() != "." &&  fi.fileName() != ".." )
            findImagesInFolder( fi.absoluteFilePath() );
    }
}
/*!
    Creates and returns a screensaver on the given token.
    \param token Identifies the screensaver to be created.
    \return The created state.
 */
Screensaver* ScreensaverFactoryPrivate::createScreensaver(const ScreensaverToken &token)
{
    QStringList pluginPaths;

    // check plugin dirs from root of different drives
    QFileInfoList drives = QDir::drives();
    for(int i=0; i < drives.count(); i++) {
        QFileInfo drive = drives.at(i);
        QString driveLetter = drive.absolutePath();
        QString path = driveLetter + mPluginDirectory;
        if (QDir(path).exists()) {
            pluginPaths << path;
        }
    }

    // check plugin dir relative to current dir
    if (QDir(mPluginDirectory).exists() && 
        !pluginPaths.contains(QDir(mPluginDirectory).absolutePath())) {
        pluginPaths << mPluginDirectory;
    }

    IScreensaverProvider *provider(0);
    QPluginLoader *loader = new QPluginLoader();
    QObject *plugin(0);

    for(int i=0; i < pluginPaths.count(); i++) {
        QString path = pluginPaths.at(i);
        QString fileName = QDir(path).absoluteFilePath(token.mLibrary);

        loader->setFileName(fileName);
        plugin = loader->instance();
        provider = qobject_cast<IScreensaverProvider*>(plugin);
        if (provider) {
            break;
        }
    }

    Screensaver *screensaver(0);

    if (provider) {
        screensaver = provider->createScreensaver(token);
        if (!screensaver) {
            qWarning() << "Screensaver creation failed.";
            qWarning() << token.mLibrary << "cannot provide" << token.mUri;
            loader->unload();
            delete loader;
        } else {
            // unload plugin once screensaver gets deleted
            ScreensaverPluginUnloader *unloader = new ScreensaverPluginUnloader(loader);
            unloader->connect(screensaver, SIGNAL(destroyed()), SLOT(deleteLater()));
        }
    } else {
        qDebug() << "Screensaver creation failed.";
        qWarning() << token.mLibrary << "- provider not found";
        loader->unload();
        delete loader;
    }

    return screensaver;
}
Esempio n. 9
0
LADSPAPresetManager::LADSPAPresetManager()
{
    m_iPresetCount = 0;

    LADSPALoader * loader = new LADSPALoader();

    QDir dir(WWidget::getPath(QString("../../ladspa_presets"))); // TODO
    QFileInfoList files = dir.entryInfoList();
    m_Presets.resize(files.count());
    for (QFileInfoList::iterator fileIter = files.begin(); fileIter != files.end(); fileIter++)
    {
        qDebug() << "LADSPA: file " << (*fileIter).filePath();
        if ((*fileIter).isDir())
        {
            continue;
        }

        QFile file((* fileIter).filePath());

        QDomDocument document("Preset");
        file.open(QIODevice::ReadOnly);
        document.setContent(&file);
        file.close();

        LADSPAPreset * preset = new LADSPAPreset(document.documentElement(), loader);
        m_Presets [m_iPresetCount] = preset;
        m_iPresetCount++;
    }
}
Esempio n. 10
0
void LocalSong::addDir()
{
    locDir= QFileDialog::getExistingDirectory(this,tr("扫描本地目录"),musicPaths.isEmpty() ? QDir::homePath() : musicPaths.first(),QFileDialog::ShowDirsOnly
                                              | QFileDialog::DontResolveSymlinks);
    QDir dir(locDir);
    if(false==dir.exists())
    {
        return;
    }
    dir.setFilter(QDir::Files | QDir::NoSymLinks);
    QFileInfoList list = dir.entryInfoList();

    int file_count = list.count();
    if(file_count <= 0)
    {
        return;
    }
    for(int i=0; i<file_count;++i)
    {
        QFileInfo file_info = list.at(i);
        QString suffix = file_info.suffix();
        if(QString::compare(suffix, QString("mp3"), Qt::CaseInsensitive) == 0)
        {
            QString absolute_file_path = file_info.absoluteFilePath();
            addSongList(absolute_file_path);
            setInfo(absolute_file_path);
        }
    }
    qDebug()<<"已添加整个目录"<<locDir;
    unsigned long dirLength=songlist.length();
    qDebug()<<"歌曲总数为"<<dirLength;
    emit dirCount(dirLength);
}
Esempio n. 11
0
void Controller::createCurrentAlbum(QString _dir, QString _currentImage)
{
   _dir.remove(0,8);
   QDir dir;
   QStringList currentList;
   QStringList filters;
   dir.setPath(_dir);
   dir.setSorting(QDir::Name);
   filters << "*.png" << "*.jpg" << "*.bmp";
   QFileInfoList list = dir.entryInfoList(filters,QDir::Files|QDir::NoDotAndDotDot);
   for(int i = 0; i < list.count(); ++i)
   {
        QFileInfo fileInfo = list.at(i);
        currentList << "file:///" + fileInfo.absoluteFilePath();
   }
   if(m_listAlbums.find("current") != m_listAlbums.end())
   {
        m_listAlbums.remove("current");
   }

   m_listAlbums.insert("current",new Album(currentList,_currentImage));
   m_listAlbums.find("current").value()->setName("current");
   m_pCurrentCtrl->setAlbum(m_listAlbums.find("current").value());
   m_pCurrentCtrl->start(QThread::IdlePriority);
   m_pCurrentAlbum = m_listAlbums.find("current").value();
}
void UniboardSankoreTransition::documentTransition()
{
    if (QFileInfo(mUniboardSourceDirectory).exists() || QFileInfo(mOldSankoreDirectory).exists()){
        QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document";

        QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory);
        fileInfoList << UBFileSystemUtils::allElementsInDirectory(mOldSankoreDirectory + "/document");

        QString backupDirectoryPath = UBFileSystemUtils::normalizeFilePath(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));

        if (fileInfoList.count() != 0){
            mTransitionDlg = new UBUpdateDlg(NULL, fileInfoList.count(), backupDirectoryPath);
            connect(mTransitionDlg, SIGNAL(updateFiles()), this, SLOT(startDocumentTransition()));
            connect(this, SIGNAL(transitionFinished(bool)), mTransitionDlg, SLOT(onFilesUpdated(bool)));
            mTransitionDlg->show();
        }
Esempio n. 13
0
void NDirWatcherThread::parseDir(const QString & path, bool recursive, const QString & rootPath)
{
    QDir d(path);
    if (!d.exists() || d.dirName() == "." || d.dirName() == "..")
        return;

    QString absolutePath = d.absolutePath();
    if (m_notSharedDirs.contains(absolutePath))
    {	// Excluded dir, we don't add it in database
        NDir dir = m_notSharedDirs[absolutePath];
        if (dir.recursive()) // Recursive exclusion
            return;
        // but we can add children in database
    } else {
        // Include dir
        QDir dir(rootPath);
        dir.cdUp();
        m_dirs.addDir(absolutePath, dir.absolutePath());
    }

    if (!recursive)
        return;

    d.setFilter(QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks);
    QFileInfoList list = d.entryInfoList();
    for(int i = 0; i < list.count(); i++)
    {
        const QFileInfo & fi = list[i];
        if (isStopping())
            break;
        //qDebug(qPrintable(fi.absoluteFilePath()));
        parseDir(fi.absoluteFilePath(), recursive, rootPath); // absoluteFilePath because dir is considered has a file
    }
}
Esempio n. 14
0
void LoadVideoThread::loadFromImages()
{
    qDebug() << "Start loading frames...";

    QDir dirImages(filePath);
    QFileInfoList listImages = dirImages.entryInfoList(QStringList() << "*.tif" << "*.tiff" << "*.jpg" << "*.png");

    if (0 == listImages.count())
    {
        emit completeLoading(false);
    }
    else
    {
        QFileInfoList::const_iterator it = listImages.begin();
        while(it != listImages.end())
        {
            cv::Mat frame = cv::imread(it->filePath().toStdString());
            cv::Mat rgbFrame;
            cv::cvtColor(frame, rgbFrame, CV_BGR2RGB);

            gtv->appendFrame(rgbFrame);
            it++;
        }
        emit completeLoading(true);
    }
    exit(0);
}
Esempio n. 15
0
// setting log directory member variable,
// creating the directory if it doesn't exist
bool Logger::initLog()
{
    bool isLogFolderReady = false;
    bool isLogFileReady = false;
    m_logDir.setPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
    if (m_logDir.cdUp())
    {
        if (!m_logDir.exists("Logs"))
            m_logDir.mkdir("Logs");
        if (m_logDir.cd("Logs"))
        {
            isLogFolderReady = true;
            if (m_logDir.count() > 10)
            {
                QFileInfo oldestLog;
                QFileInfoList logFiles = m_logDir.entryInfoList();
                for (int i = 0; i < logFiles.count(); i++)
                {
                    if (i == 0)
                        oldestLog = logFiles.at(0);
                    else if (logFiles.at(i).lastModified() < oldestLog.lastModified())
                        oldestLog = logFiles.at(i);
                }
                m_logDir.remove(oldestLog.fileName());
            }
            m_logFile = new QFile(m_logDir.path() + "/Log-" + QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss") + ".txt");
            if (m_logFile->open(QFile::WriteOnly | QIODevice::Text))
                isLogFileReady = true;
        }
    }
    return (isLogFolderReady && isLogFileReady);
}
Esempio n. 16
0
void MainWindow::populatePortPathCombo(){
	QDir devDir("/dev");

	QMap<QString, QString> serialDevices;
	QFileInfoList files = devDir.entryInfoList(QDir::System|QDir::Writable);

	for(int i=0; i<files.count(); i++){
		QFileInfo info = files[i];

		if(info.fileName().startsWith("tty")){
			serialDevices.insert(info.fileName(), info.absoluteFilePath());
		}
	}

	int index = -1;
	if(ui->portCombo->count()){
		index = ui->portCombo->currentIndex();
		ui->portCombo->clear();
	}

	ui->portCombo->insertItems(0, serialDevices.values());

	if(index != -1){
		ui->portCombo->setCurrentIndex(index);
	}
}
Esempio n. 17
0
bool RecurseDirectory(HZIP hz, QString sDir, QString prevDir = "") 
{
       QDir dir(sDir);
       QFileInfoList list = dir.entryInfoList();
       for (int iList=0;iList<list.count();iList++)
       {
           QFileInfo info = list[iList];

           QString sFilePath = info.filePath();
           if (info.isDir())
           {
               // recursive
               if (info.fileName()!=".." && info.fileName()!=".")
               {
                    ZRESULT zr;
                   return RecurseDirectory(hz, sFilePath);
               }
           }
           else
           {
               // Do something with the file here
               
               if(ZipAdd(hz, (/*sDir.right(sDir.size() - sDir.lastIndexOf("/") -1) + "/" + */info.fileName()).toLatin1().data(), info.absoluteFilePath().toLatin1().data()) != ZR_OK)
                   return false;
           }
       }

       return true;
};
Esempio n. 18
0
/**
 * Creates a log file with the prefix <tt>logFilePrefix</tt>, the current timestamp and the filename extension '.log',
 * for example: prefix_2013-10-10_11.55.17.log
 *
 * If the directory <tt>directory</tt> does not exist it will be created.
 * If there are more than <tt>maxNrOfLogFiles</tt> log files in the directory <tt>directory</tt>,
 * the oldest log files are deleted.
 *
 * \param logFilePrefix - a common prefix for all log files
 * \param directory - the directory where to save the log files
 * \param maxNrOfLogFiles - the maximum number of log files to keep
 */
FileAppender::FileAppender(const QString& logFilePrefix, const QString& directory, quint32 maxNrOfLogFiles)
{
  if(maxNrOfLogFiles < 1)
  {
    std::cerr << "<FileAppender::FileAppender> 'maxNrOfLogFiles' has to be greater than '1'" << std::endl;
    return;
  }

  QDir dir(directory);

  if(!dir.exists() && !dir.mkpath(directory))
  {
    std::cerr << "<FileAppender::FileAppender> Cannot create the log file directory " << qPrintable(directory) << std::endl;
    return;
  }

  // get current log file count
  dir.setSorting(QDir::Name | QDir::Reversed);
  dir.setFilter(QDir::Files);
  dir.setNameFilters(QStringList() << logFilePrefix + "*.log");
  QFileInfoList logFiles = dir.entryInfoList();

  // keep only the latest 'maxNrOfLogFiles - 1' files and delete all others
  for(qint32 i = maxNrOfLogFiles - 1; i < logFiles.count(); ++i)
  {
    bool ret = QFile::remove(logFiles.at(i).absoluteFilePath());
    Q_ASSERT(ret);
  }

  setFileName(directory + QDir::separator() + logFilePrefix + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss") + ".log");
}
Esempio n. 19
0
//! [5]
QXmlNodeModelIndex FileTree::nextSibling(const QXmlNodeModelIndex &nodeIndex,
        const QFileInfo &fileInfo,
        qint8 offset) const
{
    Q_ASSERT(offset == -1 || offset == 1);

    // Get the context node's parent.
    const QXmlNodeModelIndex parent(nextFromSimpleAxis(Parent, nodeIndex));

    if (parent.isNull())
        return QXmlNodeModelIndex();

    // Get the parent's child list.
    const QFileInfo parentFI(toFileInfo(parent));
    Q_ASSERT(Type(parent.additionalData()) == Directory);
    const QFileInfoList siblings(QDir(parentFI.absoluteFilePath()).entryInfoList(QStringList(),
                                 m_filterAllowAll,
                                 m_sortFlags));
    Q_ASSERT_X(!siblings.isEmpty(), Q_FUNC_INFO, "Can't happen! We started at a child.");

    // Find the index of the child where we started.
    const int indexOfMe = siblings.indexOf(fileInfo);

    // Apply the offset.
    const int siblingIndex = indexOfMe + offset;
    if (siblingIndex < 0 || siblingIndex > siblings.count() - 1)
        return QXmlNodeModelIndex();
    else
        return toNodeIndex(siblings.at(siblingIndex));
}
Esempio n. 20
0
void NDirWatcherThread::updateItemHash(NDirWatcherThreadItem & item)
{
    item.m_previousHash = item.m_hash;
    item.m_hash.clear();

    m_dir.setPath(item.m_path);
    if (!m_dir.exists())
        return;
    QFileInfoList list = m_dir.entryInfoList();
    for(int i = 0; i < list.count(); i++)
    {
        const QFileInfo & fi = list[i];
        NFileSuffix suffix = m_fileSuffixes.category(fi); // Optimized
        if (!suffix.isValid())
            continue;
        if (!suffix.shared())
            continue;

        m_hasher->reset();
        m_hasher->addData(fi.lastModified().toString().toUtf8()); // content change
        //if size changed, lastModified has changed to
        m_hasher->addData(fi.fileName().toUtf8()); // name change
        m_hasher->addData(item.m_hash); // previous hash (we get a hash for the directory, not for the file)
        item.m_hash = m_hasher->result();
    }
}
Esempio n. 21
0
/**
 * There might be a "better" way of doing this, but I don't know it,
 * but I do know that this does work. :)  Feel free to improve the loading system,
 * there isn't much code anyway.
 */
void AudioCDEncoder::findAllPlugins(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders)
{
    QString foundEncoders;

		KStandardDirs standardDirs;
    QStringList dirs = standardDirs.findDirs("module", QLatin1String( "" ));
    for (QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) {
        QDir dir(*it);
        if (!dir.exists()) {
            kDebug(7117) << "Directory given by KStandardDirs: " << dir.path() << " doesn't exists!";
            continue;
        }

        dir.setFilter(QDir::Files | QDir::Hidden);
        const QFileInfoList files = dir.entryInfoList();
        for (int i = 0; i < files.count(); ++i) {
            QFileInfo fi(files.at(i));
            if (0 < fi.fileName().count(QRegExp( QLatin1String( "^libaudiocd_encoder_.*.so$" )))) {
                QString fileName = (fi.fileName().mid(0, fi.fileName().indexOf(QLatin1Char( '.' ))));
                if (foundEncoders.contains(fileName)) {
                    kDebug(7117) << "Warning, encoder has been found twice!";
                    continue;
                }
                foundEncoders.append(fileName);
                KLibrary::void_function_ptr function = loadPlugin(fileName);
                if (function) {
                    void (*functionPointer) (KIO::SlaveBase *, QList<AudioCDEncoder*>&) =
                            (void (*)(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders)) function;
                    functionPointer(slave, encoders);
                }
            }
        }
    }
}
Esempio n. 22
0
void LPhotoData::init() {
  if (imageTimer->isActive()) {
    imageTimer->stop();
  }

  images.clear();

  QDir imgdir(m_dirpath);
  imgdir.setFilter(QDir::Files | QDir::NoSymLinks);

  QFileInfoList infolist = imgdir.entryInfoList();

  for (int i = 0; i < infolist.count(); i++) {
    QImage test_img(infolist.at(i).filePath());
    if (!test_img.isNull()) {
      images << infolist.at(i).filePath();
    }
  }
  slideCount = images.count();

  if (slideCount > 0) {
    if (!imageTimer->isActive()) {
      imageTimer->start(3000);
    }
  }
}
void RecurseDirectory(const QString dir, bool recursion)
{
    QDir dirEnt(dir);
    QFileInfoList list = dirEnt.entryInfoList();
    for(int i = 0; i < list.count(); i++)
    {
        QFileInfo info = list[i];

        QString filePath = info.filePath();
        QString fileExt = info.suffix().toLower();
        QString name = dir + QDir::separator();
        if(recursion && info.isDir())
        {
            // recursive
            if(info.fileName() != ".." && info.fileName() != ".")
            {
                RecurseDirectory(filePath, recursion);
            }
        }
        else
            if(imageExtensions.contains(fileExt))
            {
                if(!QFile::exists(name + info.completeBaseName() + QString(".atlas")))
                {
                    packerData *data = new packerData;
                    data->path = info.absoluteFilePath();
                    data->file = filePath.replace(topImageDir, "");
                    //                qDebug() << "Packing " << data->path << "...";
                    mainPacker->addItem(data->path, data);
                }
            }
    }
}
Esempio n. 24
0
//显示文件信息列表
void FileViewer::showFileInfoList(QFileInfoList list)
{
    ListWidgetFile->clear();
    for(unsigned int i=0;i<list.count();i++)
    {
    	QFileInfo tmpFileInfo=list.at(i);
		if((tmpFileInfo.isDir()))
		{
			QIcon icon("./images/dir.png");

			QString fileName=tmpFileInfo.fileName();
			
			QListWidgetItem *tmp=new QListWidgetItem (icon,fileName);
			
			ListWidgetFile->addItem(tmp);

		}
		else if(tmpFileInfo.isFile())
		{
			QIcon icon("./images/file.png");
			QString fileName=tmpFileInfo.fileName();
			QListWidgetItem *tmp=new QListWidgetItem (icon,fileName);
			ListWidgetFile->addItem(tmp);

		}
    }
}
Esempio n. 25
0
/*
 *  Add directories and files from specified directory
 */
void Worker::addDirectoryFiles(QString dirPath)
{
    m_directoryList.append(dirPath);

    QDir dir(dirPath);
    dir.setFilter(QDir::Hidden | QDir::AllEntries | QDir::NoDotAndDotDot); // All files need to be deleted before directories can be deleted

    QFileInfoList fileInfoList = dir.entryInfoList();

    for (int i=0; i < fileInfoList.count(); i++)
    {
        QFileInfo fileInfo = fileInfoList.at(i);
        QString absoluteFilePath = fileInfo.absoluteFilePath();

        // Take out redundant entries (why do they need to there in the first place?)
        if (absoluteFilePath == dirPath ||
            absoluteFilePath == dirPath.left(dirPath.lastIndexOf("/")) ||
            absoluteFilePath == "/.." || absoluteFilePath == "/")
            continue;

        if (m_directoryList.contains(absoluteFilePath) || m_fileList.contains(absoluteFilePath))
            continue;

        if (fileInfo.isDir())
        {
            addDirectoryFiles(absoluteFilePath);
        }
        else
            m_fileList.append(absoluteFilePath);
    }
}
Esempio n. 26
0
void XMLMoveThread::run()
{

    //先判断是否有目录,如果没有则创建
    QDir dir;
    QString dirName = tr("/SDHC/file/%1")
            .arg(QDateTime::currentDateTime().date().toString("yyyyMMdd"));
    //先判断是否有SD卡,每次向SD卡移动数据时都需要判断
    if(!dir.exists("/SDHC"))
    {
        LogMsg("lane", tr("未检测到SD卡,退出备份"));
        ///=qDebug()<<tr("未检测到SD卡,退出xml备份");
        return;
    }
    if(!dir.exists(dirName))
    {
        if(!dir.mkpath(dirName))
        {
            LogMsg("lane", tr("备份线程[%1]文件夹创建失败").arg(dirName));
            return;
        }
    }
    //获取tmpBakUp目录下所有文件信息
    dir.setPath("./tmpBakUp");
    QFileInfoList fileList = dir.entryInfoList(QDir::Files, QDir::Time);
    //转移文件,保留最新创建的一个
    QFileInfo fileInfo;
    for(int i = fileList.count() - 1; i > 0 ; i--)
    {
        //qDebug() << fileList.count() << i;
        fileInfo = fileList.at(i);
        if(fileInfo.exists())
        {
            if(!dir.exists("/SDHC"))
            {
                LogMsg("lane", tr("未检测到SD卡,退出备份"));
                //qDebug()<<tr("未检测到SD卡,退出xml备份");
                return;
            }
            if(!QFile::copy(fileInfo.filePath(), dirName + "/" + fileInfo.fileName()))
            {
                LogMsg("lane", tr("%1文件复制失败,退出此次备份").arg(fileInfo.filePath()));
                break;
            }
            if(!QFile::remove(fileInfo.filePath()))
            {
                LogMsg("lane", tr("%1文件删除失败,退出此次备份").arg(fileInfo.filePath()));
                break;
            }
            //qDebug() << fileList.count() << i <<fileInfo.fileName() << "bakup success";
            msleep(500);
        }
    }

    //转移图片文件 liujian
    movePicFile();
    //sd卡内数据删除
    DelSDPicFile();
    DelSDXmlFile();
}
Esempio n. 27
0
/*
 * Clean folder
 */
bool lamexp_clean_folder(const QString &folderPath)
{
	QDir tempFolder(folderPath);
	if(tempFolder.exists())
	{
		QFileInfoList entryList = tempFolder.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);

		for(int i = 0; i < entryList.count(); i++)
		{
			if(entryList.at(i).isDir())
			{
				lamexp_clean_folder(entryList.at(i).canonicalFilePath());
			}
			else
			{
				for(int j = 0; j < 3; j++)
				{
					if(lamexp_remove_file(entryList.at(i).canonicalFilePath()))
					{
						break;
					}
				}
			}
		}
		return tempFolder.rmdir(".");
	}
	return true;
}
Esempio n. 28
0
QString Planet::getPlanetTexture()
{
    QString res = "";
    dir.setPath(this->fullTexturePath());
    QStringList filter;
    filter << "*.png" << "*.jpg";
    dir.setFilter(QDir::Files);
    dir.setNameFilters(filter);
    QFileInfoList lst = dir.entryInfoList();
    if (lst.count() > 0) {
        int h = lst.count();
        QFileInfo fi = lst.at(rand() % h);
        return fi.fileName();
    }
    return res;
}
Esempio n. 29
0
MyFileSystemNodeItem::MyFileSystemNodeItem (const QFileInfo & info, QObject * parent)
    : QObject (parent)
    , m_size  (info.size ())
    , m_info  (info)
{
    MyFileSystemNodeItem::s_instances.insert (m_info.filePath (), this);
    if (m_info.isDir ()) {
        const QFileInfoList list (QDir (m_info.filePath ()).entryInfoList (filter, sort));
#ifdef USE_ITERATOR
        QListIterator<QFileInfo> it (list);
        while (it.hasNext ()) {
            m_size += (new MyFileSystemNodeItem (it.next (), this))->getSize ();
        }
#else
#   ifdef USE_FOREACH
        foreach (QFileInfo entry, list) {
            m_size += (new MyFileSystemNodeItem (entry, this))->getSize ();
        }

#   else
        const int nb = list.count ();
        for (int idx = 0; idx < nb; idx++) {
            m_size += (new MyFileSystemNodeItem (list.at (idx), this))->getSize ();
        }
#   endif
#endif
    }
}
Esempio n. 30
-1
LangManager::LangManager(QObject *parent) :
    QObject(parent)
{
    //: Fill this with your language (ex: English, Deutch, Français, etc)
    tr("__LANG__");
    //: Fill this with the country your language is for (United-States, France, etc.)
    tr("__COUNTRY__");

    QStringList searchDirs;
#ifdef Q_OS_MAC
    searchDirs << qApp->applicationDirPath() + "/../Resources/lang"
               << qApp->applicationDirPath() + "/../../../../resources";
#else
    searchDirs << qApp->applicationDirPath() + "/lang"
               << qApp->applicationDirPath() + "/../resources";
#endif

    QDir searchDir;
    searchDir.setFilter(QDir::Files);
    searchDir.setNameFilters(QStringList() << "*.qm");

    QFileInfoList files;
    for(QString dir : searchDirs) {
        searchDir.setPath(dir);
        files = searchDir.entryInfoList();
        if(files.count()) {
            LOG_INFO(QString("%1 translations found in the directory %2")
                     .arg(files.count())
                     .arg(searchDir.absolutePath()));
            break;
        }
    }

    // Insert default translation. By doing this here, we ensure the LanguageEvent will
    // correctly be posted when switching from any language to default.
    _langMap.insert(TYM_DEFAULT_LANGUAGE, "English (United States)");
    _translatorMap.insert(TYM_DEFAULT_LANGUAGE, new QTranslator(this));

    for(QFileInfo f : files) {
        QString key = f.baseName();

        QTranslator* transl = new QTranslator(this);
        transl->load(f.fileName(), f.absolutePath());
        _translatorMap.insert(key, transl);

        QString langName = transl->translate("LangManager", "__LANG__")
                + " (" + transl->translate("LangManager", "__COUNTRY__") + ")";
        if(langName == " ()") {
            langName = key;
        }
        _langMap.insert(key, langName);
    }
}