Exemplo n.º 1
0
void StorageGroup::StaticInit(void)
{
    QMutexLocker locker(&m_staticInitLock);

    if (m_staticInitDone)
        return;

    m_staticInitDone = true;

    m_builtinGroups["ChannelIcons"] = GetConfDir() + "/ChannelIcons";
    m_builtinGroups["Themes"] = GetConfDir() + "/themes";
    m_builtinGroups["Temp"] = GetConfDir() + "/tmp";

    QMap<QString, QString>::iterator it = m_builtinGroups.begin();
    for (; it != m_builtinGroups.end(); ++it)
    {
        QDir qdir(it.value());
        if (!qdir.exists())
            qdir.mkpath(it.value());

        if (!qdir.exists())
            LOG(VB_GENERAL, LOG_ERR,
                QString("SG() Error: Could not create builtin"
                        "Storage Group directory '%1' for '%2'").arg(it.value())
                    .arg(it.key()));
    }
}
Exemplo n.º 2
0
void
manager::init(const std::string &dir) {
    QDir qdir(dir.c_str());
    QFileInfoList file_infos = qdir.entryInfoList(QStringList("*.def"));
    QFileInfoList::const_iterator fi = file_infos.begin();
    for (; fi != file_infos.end(); fi++) {
        QFileInfo file_info = *fi;
        ACE_DEBUG((LM_DEBUG, "lang::manager::init def file %s\n",
                  file_info.filePath().toLatin1().constData()));
        std::string path_noext(qdir.filePath(file_info.completeBaseName()).toLatin1().constData());
        config_file df(config_file::ini_file);
        df.load(path_noext + ".def");

        std::list<info>::iterator i = _infos.insert(_infos.end(), info());
        i->_lang    = df.get_value("info/language");
        i->_author  = df.get_value("info/author");
        i->_email   = df.get_value("info/email");
        i->_version = df.get<std::string>("info/version", "0.81");
        i->_file    = path_noext + ".lang";

        ACE_DEBUG((LM_DEBUG, "lang::manager::init lang definition: ",
                  "%s by %s in file %s\n",
                  i->lang().c_str(), i->author().c_str(), i->file().c_str()));
    }

    if (_infos.size() == 0)
        throw exceptionf(0, "Language files not found. Reinstall RV House");
}
Exemplo n.º 3
0
bool Bundle::extractArchive(const KArchiveDirectory *dir, const QString &path)
{
    const QStringList l = dir->entries();

    QStringList::const_iterator it;
    for (it = l.constBegin(); it != l.constEnd(); ++it) {
        const KArchiveEntry* entry = dir->entry((*it));
        QString fullPath = QString("%1/%2").arg(path).arg(*it);
        if (entry->isDirectory()) {
            QString outDir = QString("%1%2").arg(m_tempDir->name()).arg(path);
            QDir qdir(outDir);
            qdir.mkdir(*it);
            extractArchive(static_cast<const KArchiveDirectory*>(entry), fullPath);
        } else if (entry->isFile()) {
            QString outName = QString("%1%2").arg(m_tempDir->name()).arg(fullPath.remove(0, 1));
            //qDebug()<<"-------- "<<outName;
            QFile f(outName);
            if (!f.open(QIODevice::WriteOnly)) {
                qWarning("Couldn't create %s", qPrintable(outName));
                continue;
            }
            const KArchiveFile *archiveFile = static_cast<const KArchiveFile*>(entry);
            f.write(archiveFile->data());
            f.close();
        } else {
            qWarning("Unidentified entry at %s", qPrintable(fullPath));
        }
    }
    return true;
}
int main(int argc, char** argv)
{
  // Set the DCMTK log level to debug
  dcmtk::log4cplus::Logger rootLogger = dcmtk::log4cplus::Logger::getRoot();
  rootLogger.setLogLevel(dcmtk::log4cplus::DEBUG_LOG_LEVEL);

  QApplication app(argc, argv);

  app.setOrganizationName("commontk");
  app.setOrganizationDomain("commontk.org");
  app.setApplicationName("ctkDICOMQueryRetrieve");

  QSettings settings;
  QString databaseDirectory;

  // set up the database
  if (argc > 1)
  {
    QString directory(argv[1]);
    settings.setValue("DatabaseDirectory", directory);
    settings.sync();
  }

  if ( settings.value("DatabaseDirectory", "") == "" )
  {
    databaseDirectory = QString("./ctkDICOM-Database");
    std::cerr << "No DatabaseDirectory on command line or in settings.  Using \"" << databaseDirectory.toLatin1().data() << "\".\n";
  } else
  {
    databaseDirectory = settings.value("DatabaseDirectory", "").toString();
  }

  QDir qdir(databaseDirectory);
  if ( !qdir.exists(databaseDirectory) )
  {
    if ( !qdir.mkpath(databaseDirectory) )
    {
      std::cerr << "Could not create database directory \"" << databaseDirectory.toLatin1().data() << "\".\n";
      return EXIT_FAILURE;
    }
  }


  QString databaseFileName = databaseDirectory + QString("/ctkDICOM.sql");

  QSharedPointer<ctkDICOMDatabase> dicomDatabase = QSharedPointer<ctkDICOMDatabase> (new ctkDICOMDatabase);
  dicomDatabase->openDatabase(databaseFileName);

  ctkDICOMQueryRetrieveWidget queryRetrieve;

  queryRetrieve.setRetrieveDatabase(dicomDatabase);

  queryRetrieve.show();
  queryRetrieve.raise();
  return app.exec();
}
Exemplo n.º 5
0
QString getTestFileFolder()
{
    QString ret;
    ret = TESTDATA_DIR;
    ret += "/testdata";
    QDir qdir(ret);
    if(!qdir.exists())
        ret = "";
    return ret;
}
Exemplo n.º 6
0
QString Config::getConfigDir()
{
    QString dir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
    dir += QDir::separator();
    dir += CONFIG_FILE_DIR;

    QDir qdir(dir);
    if (!qdir.exists())
        qdir.mkpath(dir);

    return dir;
}
Exemplo n.º 7
0
std::string QtUtils::GetOpenFileName(
    const std::string &filter,
    const std::string &caption,
    const std::string &dir)
{
    QString qcaption(caption.c_str());
    QString qdir(dir.c_str());
    QString qfilter(filter.c_str());
    QWidget *parent = 0;

    QString filename = QFileDialog::getOpenFileName(parent, qcaption, qdir, qfilter);

    return filename.toStdString();
}
Exemplo n.º 8
0
int qdir2( char *path )
{
	DIR *dir;
	qdir(path);
	dir=opendir(path);
	if ( dir==NULL )
	{
		plog(gettext("Failed to open a directory '%s`: %s\n"),path,strerror(errno));
		return 1;
	}	else
	{
		if ( closedir(dir) ) return 1;
		return 0;
	}
}
Exemplo n.º 9
0
void DicomWidget::setupDatabaseDirectory()
{
    QString databaseDirectory = this->getDICOMDatabaseDirectory();

	QDir qdir(databaseDirectory);
	if ( !qdir.exists(databaseDirectory) )
	{
		if ( !qdir.mkpath(databaseDirectory) )
		{
			CX_LOG_CHANNEL_ERROR("dicom") << "Could not create database directory \"" << databaseDirectory;
		}
	}

    CX_LOG_CHANNEL_INFO("dicom") << "DatabaseDirectory set to: " << databaseDirectory;
	mBrowser->setDatabaseDirectory(databaseDirectory);
}
Exemplo n.º 10
0
		void InputDataItemIO::writeConfigSection(SDFInputDataItem* sd_item, std::ofstream& out, std::ostringstream& item_positions, const String& directory)
		{
			String activity_string;
			String tmp;
			std::multiset<int> activities = sd_item->activityValues();
			
			std::multiset<int>::iterator a_it = activities.begin();
			for (; a_it != activities.end(); ++a_it)
			{
				activity_string += " "+ String(*a_it);
			}
			out << "[InputReader]" << "\n";
			if(sd_item->isDone()) out<<"done = "<<1<<std::endl;
			
			QDir qdir(directory.c_str());
			String rel_filename = (qdir.relativeFilePath(sd_item->filename())).toStdString();
			out << "sd_file = "<< rel_filename << "\n";
			out << "read_sd_descriptors = "<< sd_item->useSDProperties() << "\n";
			out << "activity_IDs = "<< activity_string << "\n";
			out << "center_data = "<< sd_item->centerData() << "\n";
			out << "center_response = "<< sd_item->centerY() << "\n";
			if(sd_item->getNonNumericClassNames()) out << "nonnumeric_class_names = 1\n";
			
			QPointF pos = sd_item->pos();
			// save position of this item to given stream
			item_positions<<pos.x()<<"  "<<pos.y()<<std::endl;
			
			list<CSVInputDataItem*>* csv_items = sd_item->getConnectedCSVItems();
			for(list<CSVInputDataItem*>::iterator it=csv_items->begin(); it!=csv_items->end(); it++)
			{
				String rel_filename = (qdir.relativeFilePath((*it)->filename())).toStdString();
				out << "csv_file = " << rel_filename <<"\n";
				out << "csv_separator = "<<"\""<<(*it)->getSeperator()<<"\"\n";
				out << "csv_desc_labels = "<<(*it)->getDescriptorLabels()<<"\n";
				out << "csv_compound_labels = "<< (*it)->getCompoundLabels()<<"\n";
				out << "csv_no_response = "<< (*it)->getNoResponseVariables()<<"\n";
				
				QPointF pos = (*it)->pos();
				// save position of appended CSV-item to given stream
				item_positions<<pos.x()<<"  "<<pos.y()<<std::endl;
				
				written_csv_.insert(*it);
			}
			out << "output = " << sd_item->savedAs().toStdString()  << "\n";
			out<<"\n";
		}
Exemplo n.º 11
0
QStringList QtUtils::GetOpenRexFilenames(const std::string &dir)
{
    QString qfilter(
        "Images (*.tga; *.bmp; *.jpg; *.jpeg; *.png);;"
        "Sounds (*.ogg; *.wav);;"
        "Ogre 3D Models (*.mesh);;"
        "Ogre Particle Scripts (*.particle);;"
        "Ogre Skeleton (*.skeleton);;"
        "Ogre Material (*.material);;"
        "Flash Animation (*.swf);;"
        "All Files (*.*)");
    QString qcaption("Open");
    QString qdir(dir.c_str());
    QWidget *parent = 0;

    return QFileDialog::getOpenFileNames(parent, qcaption, qdir, qfilter);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
QStringList RicFileHierarchyDialog::buildDirectoryListRecursive(const QString& currentDir, int level)
{
    QStringList allDirs;

    if (cancelPressed()) return allDirs;

    QString currPathFilter = pathFilter();
    bool subStringFilter = false;

    // Optimizing for speed by a refined match at first directory level
    if (level == 1)
    {
        QString pathFilter = this->pathFilter();
        if (!pathFilter.startsWith("*"))
        {
            int wildcardIndex = pathFilter.indexOf(QRegExp(QString("[*%1]").arg(SEPARATOR)));
            if (wildcardIndex >= 0)
            {
                currPathFilter = pathFilter.left(wildcardIndex + 1);
                subStringFilter = true;
            }
        }
    }

    QString currRelPath = RiaFilePathTools::relativePath(rootDir(), currentDir);
    if (pathFilterMatch(currPathFilter, currRelPath))
    {
        allDirs.push_back(currentDir);
    }
    else if(level == 1 && subStringFilter)
    {
        return QStringList();
    }

    QDir qdir(currentDir);
    QStringList subDirs = qdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
    for (QString subDir : subDirs)
    {
        QString subDirFullPath = qdir.absoluteFilePath(subDir);
        updateStatus(SEARCHING_FOR_DIRS, subDirFullPath);
        QApplication::processEvents();
        allDirs += buildDirectoryListRecursive(subDirFullPath, level + 1);
    }
    return cancelPressed() ? QStringList() : allDirs;
}
Exemplo n.º 13
0
//---------------------------------------------------------------------------
bool TSatScript::checkdirectory(QString path)
{
    QDir qdir(path);

    //qDebug("checkdirectory: %s, %s:%d", path.toStdString().c_str(),  __FILE__, __LINE__);

    if(!qdir.exists()) {
        if(!qdir.mkpath(path)) {
            qDebug("Error: Failed to create directory %s, %s:%d",
                   path.toStdString().c_str(),
                   __FILE__, __LINE__);

            return false;
        }
    }

    return true;
}
Exemplo n.º 14
0
StringList QtUtils::GetOpenFileNames(
    const std::string &filter,
    const std::string &caption,
    const std::string &dir)
{
    QString qcaption(caption.c_str());
    QString qdir(dir.c_str());
    QString qfilter(filter.c_str());
    QWidget *parent = 0;
    StringList filelist;

    QStringList filenames = QFileDialog::getOpenFileNames(parent, qcaption, qdir, qfilter);

    // Convert QStringList to std::list<std::string> list.
    for(QStringList::iterator q_it = filenames.begin(); q_it != filenames.end(); ++q_it)
        filelist.push_back(q_it->toStdString());

    return filelist;
}
Exemplo n.º 15
0
QStringList FilesModel::files(){
    QDir qdir(QDir::homePath() + "/.local/share/com.ubuntu.developer.bobo1993324.qvbam/roms");
    if (!qdir.exists()) {
        qdir.mkpath(qdir.absolutePath());
        return QStringList();
    } else {
        QStringList qsl = qdir.entryList();
        int i = 0;
        while (i < qsl.length()) {
            if (qsl[i] == "." || qsl[i] == "..") {
                qsl.removeAt(i);
            } else {
                i++;
            }
        }
        qDebug() << "return " << qsl;
        return qsl;
    }

}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
QStringList RicFileHierarchyDialog::findFilesInDirs(const QStringList& dirs)
{
    QStringList allFiles;
    QStringList filters = createNameFilterList(fileNameFilter(), fileExtensions());

    for (const auto& dir : dirs)
    {
        QDir qdir(dir);
        QStringList files = qdir.entryList(filters, QDir::Files);

        updateStatus(SEARCHING_FOR_FILES, qdir.absolutePath());
        QApplication::processEvents();

        for (QString file : files)
        {
            QString absFilePath = qdir.absoluteFilePath(file);
            allFiles.append(absFilePath);
        }
    }
    return allFiles;
}
Exemplo n.º 17
0
		void InputDataItemIO::writeConfigSection(CSVInputDataItem* csv_item, std::ofstream& out, const String& directory)
		{
			// if csv_item has been written to a config section because it is connected to a SDFInputDataItem, do nothing!
			if(written_csv_.find(csv_item)!=written_csv_.end()) return;
			
			QDir qdir(directory.c_str());
			String rel_filename = (qdir.relativeFilePath(csv_item->filename())).toStdString();
			out << "[InputReader]" << "\n";
			if(csv_item->isDone()) out<<"done = "<<1<<std::endl;
			out << "csv_file = " << rel_filename<<"\n";
			out << "csv_separator = "<<"\""<<csv_item->getSeperator()<<"\"\n";
			out << "csv_desc_labels = "<<csv_item->getDescriptorLabels()<<"\n";
			out << "csv_compound_labels = "<<csv_item->getCompoundLabels()<<"\n";
			out << "csv_no_response = "<<csv_item->getNoResponseVariables()<<"\n";
			if(csv_item->getNonNumericClassNames()) out << "nonnumeric_class_names = 1\n";
			out << "center_data = "<< csv_item->centerData() << "\n";
			out << "center_response = "<< csv_item->centerY() << "\n";
			out << "output = " << csv_item->savedAs().toStdString() << "\n";
			out << "\n";
			
			written_csv_.insert(csv_item);
		}
Exemplo n.º 18
0
void FormStyle::LoadColorList()
{
	QString oldColorScheme = colorScheme;

	ui.colorsB->clear();

	QDir qdir(qApp->applicationDirPath()+"/colors");
	QStringList fileList = qdir.entryList( QStringList( "*" + colorExt ), QDir::Files, QDir::Name );
	QStringList addToList;

	for ( int i = 0 ; i < fileList.count() ; i++ )
	{
		colorSet = new QSettings( "colors/"+fileList[i],QSettings::IniFormat );

		if ( colorSet->value("QMPColorFileInfo/QMPColor").toBool() )
			addToList += fileList[i].left( fileList[i].length() - colorExt.length() );

		delete colorSet;
	}

	ui.colorsB->addItems( addToList );

	int idxDefCol(-1), idxCol(-1);
	for ( int currIdx = 0 ; currIdx < ui.colorsB->count() ; currIdx++ )
	{
		if ( ui.colorsB->itemText( currIdx ) == defColorScheme )
			idxDefCol = currIdx;
		if ( ui.colorsB->itemText( currIdx ) == oldColorScheme )
			idxCol = currIdx;
	}
	if ( idxCol != -1 )
		ui.colorsB->setCurrentIndex( idxCol );
	else if ( idxDefCol != -1 )
		ui.colorsB->setCurrentIndex( idxDefCol );
	else
		ui.colorsB->setCurrentIndex( 0 );
}
Exemplo n.º 19
0
StringList QtUtils::GetOpenRexFileNames(const std::string &dir)
{
    QString qfilter(
        "Images (*.tga; *.bmp; *.jpg; *.jpeg; *.png);;"
        "Sounds (*.ogg; *.wav);;"
        "Ogre 3D Models (*.mesh);;"
        "Ogre Particle Scripts (*.particle);;"
        "Ogre Skeleton (*.skeleton);;"
        "Ogre Material (*.material);;"
        "Flash Animation (*.swf);;"
        "All Files (*.*)");
    QString qcaption("Open");
    QString qdir(dir.c_str());
    QWidget *parent = 0;
    StringList filelist;

    QStringList filenames = QFileDialog::getOpenFileNames(parent, qcaption, qdir, qfilter);

    // Convert QStringList to std::list<std::string> list.
    for(QStringList::iterator q_it = filenames.begin(); q_it != filenames.end(); ++q_it)
        filelist.push_back(q_it->toStdString());

    return filelist;
}
Exemplo n.º 20
0
/**
 *  \brief Returns the relative pathname of a file by comparing the filename
 *         against all Storage Group directories (and MythVideo's startupdir)
 *
 *  \param filename The full pathname of the file to use
 *  \return         The relative path if it can be determined, otherwise the
 *                  full input filename is returned back to the caller.
 */
QString StorageGroup::GetRelativePathname(const QString &filename)
{
    QString result = filename;
    MSqlQuery query(MSqlQuery::InitCon());

    LOG(VB_FILE, LOG_DEBUG,
        QString("StorageGroup::GetRelativePathname(%1)").arg(filename));

    StaticInit();

    if (filename.startsWith("myth://"))
    {
        QUrl qurl(filename);

        if (qurl.hasFragment())
            result = qurl.path() + "#" + qurl.fragment();
        else
            result = qurl.path();

        if (result.startsWith("/"))
            result.replace(0, 1, "");

        return result;
    }

    query.prepare("SELECT DISTINCT dirname FROM storagegroup "
                      "ORDER BY dirname DESC;");
    if (query.exec())
    {
        QString dirname;
        while (query.next())
        {
            /* The storagegroup.dirname column uses utf8_bin collation, so Qt
             * uses QString::fromAscii() for toString(). Explicitly convert the
             * value using QString::fromUtf8() to prevent corruption. */
            dirname = QString::fromUtf8(query.value(0)
                                        .toByteArray().constData());
            if (filename.startsWith(dirname))
            {
                result = filename;
                result.replace(0, dirname.length(), "");
                if (result.startsWith("/"))
                    result.replace(0, 1, "");

                LOG(VB_FILE, LOG_DEBUG, 
                    QString("StorageGroup::GetRelativePathname(%1) = '%2'")
                        .arg(filename).arg(result));
                return result;
            }
        }
    }

    query.prepare("SELECT DISTINCT data FROM settings WHERE "
                  "value = 'VideoStartupDir';");
    if (query.exec())
    {
        while (query.next())
        {
            QString videostartupdir = query.value(0).toString();
            QStringList videodirs = videostartupdir.split(':',
                                            QString::SkipEmptyParts);
            QString directory;
            for (QStringList::Iterator it = videodirs.begin();
                                       it != videodirs.end(); ++it)
            {
                directory = *it;
                if (filename.startsWith(directory))
                {
                    result = filename;
                    result.replace(0, directory.length(), "");
                    if (result.startsWith("/"))
                        result.replace(0, 1, "");

                    LOG(VB_FILE, LOG_DEBUG,
                        QString("StorageGroup::GetRelativePathname(%1) = '%2'")
                            .arg(filename).arg(result));
                    return result;
                }
            }
        }
    }

    QMap<QString, QString>::iterator it = m_builtinGroups.begin();
    for (; it != m_builtinGroups.end(); ++it)
    {
        QDir qdir(it.value());
        if (!qdir.exists())
            qdir.mkpath(it.value());

        QString directory = it.value();
        if (filename.startsWith(directory))
        {
            result = filename;
            result.replace(0, directory.length(), "");
            if (result.startsWith("/"))
                result.replace(0, 1, "");

            LOG(VB_FILE, LOG_DEBUG,
                QString("StorageGroup::GetRelativePathname(%1) = '%2'")
                    .arg(filename).arg(result));
            return result;
        }
    }

    return result;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicFileHierarchyDialog::buildDirectoryListRecursiveSimple(const QString& rootDir, 
                                                               const QString& remainingPathFilter, 
                                                               QStringList* accumulatedDirs)
{
    if (cancelPressed()) return;

    QString currentRemainingpathFilter = remainingPathFilter;
    {
        // Remove prefixing or trailing path separators from filter

        int pathSepIdx = currentRemainingpathFilter.indexOf(SEPARATOR);
        while ( pathSepIdx == 0 )
        {
            currentRemainingpathFilter.remove(pathSepIdx, 1);
            pathSepIdx = currentRemainingpathFilter.indexOf(SEPARATOR);
        }

        if ( currentRemainingpathFilter.endsWith(SEPARATOR) )
        {
            currentRemainingpathFilter.chop(1);
        }
    }

    QString effectiveRootDir = rootDir;
    {
        // Remove trailing path separator from root
        if ( effectiveRootDir.endsWith(SEPARATOR) )
        {
            effectiveRootDir.chop(1);
        }
    }

    // Search pathfilter for the first wildcard. 
    // Use the path up to that directory directly, short-cutting the search
    {
        std::set<int> sortedWildCardPositions;
        sortedWildCardPositions.insert(currentRemainingpathFilter.indexOf("*"));
        sortedWildCardPositions.insert(currentRemainingpathFilter.indexOf("?"));
        sortedWildCardPositions.insert(currentRemainingpathFilter.indexOf("["));

        int minWildCardPos = -1;
        for ( int wildCardPos : sortedWildCardPositions )
        {
            if ( wildCardPos == -1 ) continue;

            minWildCardPos = wildCardPos;
            break;
        }

        if ( minWildCardPos == -1 )
        {
            effectiveRootDir += SEPARATOR + currentRemainingpathFilter;
            currentRemainingpathFilter = "";
        }
        else
        {
            int pathSepPos = currentRemainingpathFilter.indexOf(SEPARATOR);
            while ( pathSepPos != -1 && pathSepPos < minWildCardPos )
            {
                effectiveRootDir += SEPARATOR + currentRemainingpathFilter.left(pathSepPos);
                currentRemainingpathFilter.remove(0, pathSepPos + 1); // include the separator
                minWildCardPos -= (pathSepPos + 1);
                pathSepPos = currentRemainingpathFilter.indexOf(SEPARATOR);
            }
        }
    }

    // Find the filter to use for this directory level 
    // Assumes no prefixed path separator

    QStringList subDirsFullPath;
    {
        int pathSepIdx = currentRemainingpathFilter.indexOf(SEPARATOR);
        QString currentDirNameFilter = currentRemainingpathFilter.left(pathSepIdx);
        
        if ( pathSepIdx == -1 ) 
        {
            currentRemainingpathFilter = "";
        }
        else
        {
            currentRemainingpathFilter.remove(0, pathSepIdx);
        }

        if ( currentDirNameFilter.isEmpty() ) currentDirNameFilter = "*";



        QDir qdir(effectiveRootDir, currentDirNameFilter, QDir::NoSort, QDir::Dirs | QDir::NoDotAndDotDot);

        // Add effectiveRoot if current dir name filter =""or"*" or "?" and currentRemainingpathFilter = ""
        // and remainingPathFilter not empty
        if ( (currentDirNameFilter == "*" || currentDirNameFilter == "?") 
            && currentRemainingpathFilter.isEmpty()
            && !remainingPathFilter.isEmpty())
        {
            (*accumulatedDirs) += qdir.absolutePath();
        }

        QStringList subDirs = qdir.entryList();

        for ( const QString& subDir : subDirs )
        {
            QString fullPath = qdir.absoluteFilePath(subDir);
            subDirsFullPath += fullPath;
            (*accumulatedDirs) += fullPath;
        }
    }

    for (const QString& subDir : subDirsFullPath)
    {
        updateStatus(SEARCHING_FOR_DIRS, subDir);
        QApplication::processEvents();
        buildDirectoryListRecursiveSimple(subDir, currentRemainingpathFilter, accumulatedDirs);
    }
}
Exemplo n.º 22
0
bool FileServerHandler::HandleAnnounce(MythSocket *socket,
                  QStringList &commands, QStringList &slist)
{
    if (commands[1] == "FileServer")
    {
        if (slist.size() >= 3)
        {
            SocketHandler *handler =
                new SocketHandler(socket, m_parent, commands[2]);

            handler->BlockShutdown(true);
            handler->AllowStandardEvents(true);
            handler->AllowSystemEvents(true);

            QWriteLocker wlock(&m_fsLock);
            m_fsMap.insert(commands[2], handler);
            m_parent->AddSocketHandler(handler);

            slist.clear();
            slist << "OK";
            handler->SendStringList(slist);
            return true;
        }
        return false;
    }

    if (commands[1] != "FileTransfer")
        return false;

    if (slist.size() < 3)
        return false;

    if ((commands.size() < 3) || (commands.size() > 6))
        return false;

    FileTransfer *ft    = NULL;
    QString hostname    = "";
    QString filename    = "";
    bool writemode      = false;
    bool usereadahead   = true;
    int timeout_ms      = 2000;
    switch (commands.size())
    {
      case 6:
        timeout_ms      = commands[5].toInt();
      case 5:
        usereadahead    = commands[4].toInt();
      case 4:
        writemode       = commands[3].toInt();
      default:
        hostname        = commands[2];
    }

    QStringList::const_iterator it = slist.begin();
    QUrl qurl           = *(++it);
    QString wantgroup   = *(++it);

    QStringList checkfiles;
    while (++it != slist.end())
        checkfiles += *(it);

    slist.clear();

    LOG(VB_GENERAL, LOG_DEBUG, "FileServerHandler::HandleAnnounce");
    LOG(VB_GENERAL, LOG_INFO, QString("adding: %1 as remote file transfer")
                            .arg(hostname));

    if (writemode)
    {
        if (wantgroup.isEmpty())
            wantgroup = "Default";

        StorageGroup sgroup(wantgroup, gCoreContext->GetHostName(), false);
        QString dir = sgroup.FindNextDirMostFree();
        if (dir.isEmpty())
        {
            LOG(VB_GENERAL, LOG_ERR, "Unable to determine directory "
                    "to write to in FileTransfer write command");

            slist << "ERROR" << "filetransfer_directory_not_found";
            socket->writeStringList(slist);
            return true;
        }

        QString basename = qurl.path();
        if (basename.isEmpty())
        {
            LOG(VB_GENERAL, LOG_ERR, QString("FileTransfer write "
                    "filename is empty in url '%1'.")
                    .arg(qurl.toString()));

            slist << "ERROR" << "filetransfer_filename_empty";
            socket->writeStringList(slist);
            return true;
        }

        if ((basename.contains("/../")) ||
            (basename.startsWith("../")))
        {
            LOG(VB_GENERAL, LOG_ERR, QString("FileTransfer write "
                    "filename '%1' does not pass sanity checks.")
                    .arg(basename));

            slist << "ERROR" << "filetransfer_filename_dangerous";
            socket->writeStringList(slist);
            return true;
        }

        filename = dir + "/" + basename;
    }
    else
        filename = LocalFilePath(qurl, wantgroup);

    QFileInfo finfo(filename);
    if (finfo.isDir())
    {
        LOG(VB_GENERAL, LOG_ERR, QString("FileTransfer filename "
                "'%1' is actually a directory, cannot transfer.")
                .arg(filename));

        slist << "ERROR" << "filetransfer_filename_is_a_directory";
        socket->writeStringList(slist);
        return true;
    }

    if (writemode)
    {
        QString dirPath = finfo.absolutePath();
        QDir qdir(dirPath);
        if (!qdir.exists())
        {
            if (!qdir.mkpath(dirPath))
            {
                LOG(VB_GENERAL, LOG_ERR, QString("FileTransfer "
                        "filename '%1' is in a subdirectory which does "
                        "not exist, but can not be created.")
                        .arg(filename));

                slist << "ERROR" << "filetransfer_unable_to_create_subdirectory";
                socket->writeStringList(slist);
                return true;
            }
        }

        ft = new FileTransfer(filename, socket, m_parent, writemode);
    }
    else
        ft = new FileTransfer(filename, socket, m_parent, usereadahead, timeout_ms);

    ft->BlockShutdown(true);

    {
        QWriteLocker wlock(&m_ftLock);
        m_ftMap.insert(socket->socket(), ft);
    }

    slist << "OK"
          << QString::number(socket->socket())
          << QString::number(ft->GetFileSize());

    if (checkfiles.size())
    {
        QFileInfo fi(filename);
        QDir dir = fi.absoluteDir();
        for (it = checkfiles.begin(); it != checkfiles.end(); ++it)
        {
            if (dir.exists(*it) &&
                QFileInfo(dir, *it).size() >= kReadTestSize)
                    slist << *it;
        }
    }

    socket->writeStringList(slist);
    m_parent->AddSocketHandler(ft);
    return true;
}
Exemplo n.º 23
0
		void InputDataItemIO::readConfigSection(String& configfile_section, std::map<String, DataItem*>& filenames_map, std::list<std::pair<double,double> >* item_positions, const String& directory)
		{
			std::istringstream input;
			input.str(configfile_section);
			
			String line;
			getline(input,line);
			if(line.hasPrefix("[InputPartitioner]"))
			{
				ConfigIO::putbackLine(&input,line);
				readPartitionerSection(configfile_section,filenames_map,item_positions);
				return;
			}
			ConfigIO::putbackLine(&input,line);
			
			InputConfiguration conf;
			try
			{
				conf = ConfigIO::readInputConfiguration(&input);
			}
			catch(BALL::Exception::GeneralException e)
			{
				QMessageBox::critical(view_,"Error reading SD-input",e.getMessage());
			}
			
			SDFInputDataItem* sd_item=0;
			if(conf.sd_file!="")
			{
				try
				{
					QDir qdir(directory.c_str());
					QString abs_filename = qdir.absoluteFilePath(conf.sd_file.c_str());
								
					sd_item = new SDFInputDataItem(abs_filename, conf.activities,conf.center_data, conf.center_y, view_);
					view_->data_scene->addItem(sd_item);
					sd_item->addToPipeline();
					sd_item->setSavedAs(conf.output.c_str());
					sd_item->useSDProperties(conf.read_sd_descriptors);
					sd_item->setNonNumericClassNames(conf.nonnumeric_class_names);
					if(item_positions!=0 && item_positions->size()>0)
					{
						std::pair<double,double> pos = item_positions->front();
						item_positions->pop_front();
						sd_item->setPos(pos.first,pos.second);
						sd_item->setCenterDataFlag(conf.center_data);
						sd_item->setCenterResponseFlag(conf.center_y);
					}
				}
				catch(BALL::Exception::GeneralException e)
				{
					QMessageBox::critical(view_,"Error reading SD-input",e.getMessage());
				}
				filenames_map.insert(std::make_pair(conf.output,sd_item));
			}

			try
			{
				unsigned int no=conf.csv_file.size();
				QDir qdir(directory.c_str());
				for(unsigned int i=0; i<no;i++)
				{
					CSVInputDataItem* csv_item;
					if(sd_item!=0)
					{
						csv_item = new CSVInputDataItem(sd_item->data(),view_);	
						csv_item->setAppend(true);
						if(i==no-1)
						{
							csv_item->setCenterDataFlag(conf.center_data);
							csv_item->setCenterResponseFlag(conf.center_y);
						}
						else
						{
							csv_item->setCenterDataFlag(0);
							csv_item->setCenterResponseFlag(0);
						}
						csv_item->setView(view_);
						QString abs_filename = qdir.absoluteFilePath(conf.csv_file[i].c_str());
						csv_item->setFilename(abs_filename.toStdString());
						QStringList list = abs_filename.split("/");
						csv_item->setName(list[list.size()-1]);
					}
					else
					{
						QString abs_filename = qdir.absoluteFilePath(conf.csv_file[i].c_str());	
						csv_item = new CSVInputDataItem(abs_filename,view_);	
						csv_item->setAppend(false);
						csv_item->setCenterDataFlag(conf.center_data);
						csv_item->setCenterResponseFlag(conf.center_y);
						if(i==0) filenames_map.insert(std::make_pair(conf.output,csv_item));
					}
					csv_item->setNonNumericClassNames(conf.nonnumeric_class_names);
					csv_item->setXLabelFlag(conf.csv_desc_labels[i]);
					csv_item->setYLabelFlag(conf.csv_compound_labels[i]);
					csv_item->setNumOfActivities(conf.csv_no_response[i]);
					csv_item->setSeperator(conf.csv_separator[i]);
					csv_item->setSavedAs(conf.output.c_str());
					
 					view_->data_scene->addItem(csv_item);
					csv_item->addToPipeline();
					if(item_positions!=0 && item_positions->size()>0)
					{
						std::pair<double,double> pos = item_positions->front();
						item_positions->pop_front();
						csv_item->setPos(pos.first,pos.second);
					}
 					if(sd_item) 
					{
						Edge* edge = new Edge(sd_item, csv_item);
						view_->data_scene->addItem(edge);
						sd_item->appendCSVDescriptors(csv_item);
					}
				}
			}
			catch(BALL::Exception::GeneralException e)
			{
				QMessageBox::critical(view_,"Error reading CSV-input",e.getMessage());
			}
		}
Exemplo n.º 24
0
/**
 * @brief Apply output parsers, return the next expected model output file name(s).
 * @param step          Step number to search the files for.
 * @param test_only     If true, only tests if the expected output file exists.
 * @return              Vector containing the output file name(s).
 */
std::vector<std::string> BinaryHandler::_get_data_filenames( int step,
                                                             bool test_only )
{
    std::vector<std::string> output_files;
    QString run_id = QString::number( _toothLife->getID() );
    QString run_path = systemTempPath + "/" + run_id + "/";
    QDir qdir(run_path);

    std::string ext = "";
    if (_output_style == "PLY" || _output_style == "") {
        ext = ".ply";
    }
    else if (_output_style == "Matrix") {
        ext = ".txt";
    }
    else if (_output_style == "Humppa") {
        ext = ".off";
    }
    else {
        return output_files;
    }

    //
    // TODO: Imnplement control of output file names.
    //

    // Note: allowing for some room in the input file name:
    int iter = step*stepSize;
    QString target = QString::number(iter) + "*" + run_id + "*"
                     + QString(ext.c_str());
    QStringList filter;
    filter << target;
    QFileInfoList files = qdir.entryInfoList( filter, QDir::Files );

    if (files.size() == 0) {
        return output_files;
    }

    if (test_only) {
        for (auto file : files) {
            output_files.push_back( file.fileName().toStdString() );
        }
        return output_files;
    }

/*
    std::cout << std::endl;
    std::cout << "** Running parsers in " << run_path.toStdString() << std::endl;
    std::cout << "** Parser target " << target.toStdString() << std::endl;
    std::cout << "** Number of files to be parsed: " << files.size() << std::endl;
*/

    // Apply parsers
    for (int i=0; i<files.size(); i++) {
        QString file = files.at(i).fileName();

        for (auto& parser : _output_parsers) {
            QString path_style = "..\bin\\";
            #if defined(__linux__) || defined(__APPLE__)
            path_style = "../bin/";
            #endif
            QString parser_out = "parser_tmp_" + run_id + ".txt";
            QString cmd = path_style + parser + " " + file + " "
                          + parser_out;

            QProcess process;
            process.start(cmd);
            if(!process.waitForFinished( PARSER_TIMEOUT )) {
                // TODO: Add checks for other errors, e.g., does the parser exist.
               qDebug() << "Error: Parser" << parser << "failed to finish in"
                        << PARSER_TIMEOUT << "msecs on file" << file <<". SKipping.";
               continue;
            }

            // Replace the input file with the parser output if applicable.
            if (QFile::exists(parser_out)) {
                QFile::remove(file);
                QFile::copy(parser_out, file);
                QFile::remove(parser_out);
            }
        }
    }

    // Assuming a fixed output file name for now.
    std::string outfile = std::to_string(iter) + "_" + run_id.toStdString() + ext;
    output_files.push_back( outfile );

    return output_files;
}
Exemplo n.º 25
0
void processDirectory(const QString &dir_old,
                      const QString &dir_new,
                      const QString &dir_result,
                      const QStringList &ignoreMasks)
{
  QDir qdir(dir_new, "", QDir::Name | QDir::IgnoreCase,
            QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);

  QFileInfoList files = qdir.entryInfoList();
  for (int i = 0; i < files.count(); ++i)
  {
    //qDebug() << files.at(i).absoluteFilePath();
    QFileInfo fi = files.at(i);

    // check for ignores
    bool ignore_this_file = false;
    for (int k = 0; k < ignoreMasks.size(); ++k)
    {
      QRegExp rx(ignoreMasks.at(k));
      rx.setPatternSyntax(QRegExp::Wildcard);
      if (rx.exactMatch(fi.fileName()))
      {
        ignore_this_file = true;
        break;
      }
    }
    if (ignore_this_file)
      continue;

    if (fi.isFile())
    {
      QDir qdir_old(dir_old);
      if(!qdir_old.exists(fi.fileName()))
      {
        CopyFile(dir_result, fi.absoluteFilePath());
      }
      else  // compare crc, if changed then copy
      {

        quint16 crc_new = getCrc(fi.absoluteFilePath());
        quint16 crc_old = getCrc(qdir_old.absoluteFilePath(fi.fileName()));
        log(QString("Comparing crc %1 = %2\n").arg(crc_old).arg(crc_new));
        if (crc_new == 0 || crc_old == 0)
          return;

        if (crc_new != crc_old)
        {
          CopyFile(dir_result, fi.absoluteFilePath());
        }
      }
    }
    else if (fi.isDir())
    {
      processDirectory(dir_old + "/" + fi.fileName(),
                       dir_new + "/" + fi.fileName(),
                       dir_result + "/" + fi.fileName(),
                       ignoreMasks);
      //*/
    }
  }
}