Beispiel #1
0
void CachedImage::_saveData()
{
    Q_ASSERT(_reply);
    if (!_reply)
        return;

    if (_reply->error() != QNetworkReply::NoError )
    {
        _reply->deleteLater();
        _reply = nullptr;

        emit downloadingChanged();

        return;
    }

    auto data = new QByteArray;
    *data = _reply->readAll();

    if (data->startsWith((char)0x89))      //-V2005
        setExtension("png");
    else if (data->startsWith((char)0xFF)) //-V2005
        setExtension("jpeg");
    else if (data->startsWith((char)0x47)) //-V2005
        setExtension("gif");

    auto future = QtConcurrent::run(this, &CachedImage::_saveFile, data);
    _saveWatcher.setFuture(future);

    _reply->deleteLater();
    _reply = nullptr;
}
Beispiel #2
0
/**
 * Opens a file and loads a sound effect.
 *
 * @param fileName         Sfx filename
 *
 * @returns                True is everything is OK, False otherwise
 */
bool FPSfx::loadFile(const char *fileName) {
	if (!_soundSupported)
		return true;

	SoundCodecs codec = FPCODEC_UNKNOWN;

	Common::File file;
	if (file.open(fileName))
		codec = FPCODEC_ADPCM;
	else if (file.open(setExtension(fileName, ".MP3")))
		codec = FPCODEC_MP3;
	else if (file.open(setExtension(fileName, ".OGG")))
		codec = FPCODEC_OGG;
	else if (file.open(setExtension(fileName, ".FLA")))
		codec = FPCODEC_FLAC;
	else {
		warning("FPSfx::LoadFile(): Cannot open sfx file!");
		return false;
	}

	Common::SeekableReadStream *buffer;
	switch (codec) {
	case FPCODEC_ADPCM: {
		if (file.readUint32BE() != MKTAG('A', 'D', 'P', 0x10)) {
			warning("FPSfx::LoadFile(): Invalid ADP header!");
			return false;
		}

		uint32 rate = file.readUint32LE();
		uint32 channels = file.readUint32LE();

		buffer = file.readStream(file.size() - file.pos());
		_rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels);
		}
		break;
	case FPCODEC_MP3:
#ifdef USE_MAD
		buffer = file.readStream(file.size());
		_rewindableStream = Audio::makeMP3Stream(buffer, DisposeAfterUse::YES);
#endif
		break;
	case FPCODEC_OGG:
#ifdef USE_VORBIS
		buffer = file.readStream(file.size());
		_rewindableStream = Audio::makeVorbisStream(buffer, DisposeAfterUse::YES);
#endif
		break;
	case FPCODEC_FLAC:
		buffer = file.readStream(file.size());
#ifdef USE_FLAC
		_rewindableStream = Audio::makeFLACStream(buffer, DisposeAfterUse::YES);
#endif
		break;
	default:
		return false;
	}

	_fileLoaded = true;
	return true;
}
void FunctionsTest::testSetExtension()
{
	QCOMPARE(setExtension("", "png"), QString(""));
	QCOMPARE(setExtension("http://test.com/file", "png"), QString("http://test.com/file"));
	QCOMPARE(setExtension("http://test.com/file.jpg", "png"), QString("http://test.com/file.png"));
	QCOMPARE(setExtension("http://test.com/file.jpg?toto=1", "png"), QString("http://test.com/file.png?toto=1"));
}
TFSBasis*
Attachment::serialize( SocketPackage& cPackage, bool bWriteToStorage )
{
    if ( bWriteToStorage )
    {
        cPackage.add( m_sExtension );
        cPackage.add( m_sFileName );
        cPackage.add( m_sFileType );

        cPackage.add( int(m_caContent.size()) );
        cPackage.add( &m_caContent[0], m_caContent.size() );
    }
    else
    {
        std::string sBuffer;
        size_t      nSize;

        setExtension( cPackage.getString(sBuffer).c_str() );
        setFileName ( cPackage.getString(sBuffer).c_str() );
        setFileType ( cPackage.getString(sBuffer).c_str() );

        m_caContent.resize( (nSize=cPackage.getInt()) );
        if ( nSize > 0 )
            ::memcpy( &m_caContent[0], cPackage.get(nSize), nSize*sizeof(char) );
    }

    return this;
}
Beispiel #5
0
void CachedImage::_setProperties()
{
    if (!_headReply)
        return;

    if (_headReply->error() != QNetworkReply::NoError)
    {
        _headReply->deleteLater();
        _headReply = nullptr;

        return;
    }

    auto mime = _headReply->header(QNetworkRequest::ContentTypeHeader).toString().split('/');
    if (mime.isEmpty())
        mime << "";

    if (!mime.first().isEmpty() && mime.first().toLower() != "image")
        qDebug() << "mime:" << mime.first() << "\nurl:" << _url;

    setExtension(mime.last());

    auto length = _headReply->header(QNetworkRequest::ContentLengthHeader).toInt();
    _kbytesTotal = length / 1024;

    emit totalChanged();

    _headReply->deleteLater();
    _headReply = nullptr;

    if (_man->autoload(_kbytesTotal))
        download();
}
Beispiel #6
0
void CachedImage::setExtension(QString format)
{
    format = format.toLower();

    if (format == "jpeg" || format == "jpg")
    {
        _format = JpegFormat;
        _extension = "jpg";
    }
    else if (format == "png")
    {
        _format = PngFormat;
        _extension = "png";
    }
    else if (format == "gif")
    {
        _format = GifFormat;
        _extension = "gif";
    }
    else if (format.isEmpty() && !_url.isEmpty())
    {
        auto ext = _url.split(".").last();
        if (!ext.isEmpty() && ext.size() != _url.size())
            setExtension(ext);
        return;
    }
    else
        qDebug() << "mime:" << format << "\nurl:" << _url;

    emit extensionChanged();
}
Beispiel #7
0
GmshIOOperation::GmshIOOperation()
{
  EG_TYPENAME;
  setFormat("Gmsh files(*.msh *.MSH)");
  setExtension(".msh");
  format = ascii1;
}
LRESULT AVIPreview::onChangeMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	if (ctrlCommands.GetSelectedCount() == 1)
	{
		int sel = ctrlCommands.GetSelectedIndex();
		const auto pa = FavoriteManager::getInstance()->getPreviewApp(sel);
		if (pa)
		{
			PreviewDlg dlg;
			dlg.name = Text::toT(pa->getName());
			dlg.application = Text::toT(pa->getApplication());
			dlg.argument = Text::toT(pa->getArguments());
			dlg.extensions = Text::toT(pa->getExtension());
			
			if (dlg.DoModal() == IDOK)
			{
				pa->setName(Text::fromT(dlg.name));
				pa->setApplication(Text::fromT(dlg.application));
				pa->setArguments(Text::fromT(dlg.argument));
				pa->setExtension(Text::fromT(dlg.extensions));
				
				ctrlCommands.SetItemText(sel, 0, dlg.name.c_str());
				ctrlCommands.SetItemText(sel, 1, dlg.application.c_str());
				ctrlCommands.SetItemText(sel, 2, dlg.argument.c_str());
				ctrlCommands.SetItemText(sel, 3, dlg.extensions.c_str());
			}
		}
	}
	
	return 0;
}
Beispiel #9
0
bool PictureShared::loadXpm(QIODevice* io)
{
    kDebug(30508) << "PictureShared::loadXpm";
    if (!io) {
        kError(30508) << "No QIODevice!" << endl;
        return false;
    }

    clear();

    // Old showcase XPM files have char(1) instead of some "
    // Therefore we need to treat XPM separately

    QByteArray array = io->readAll();

    // As XPM files are normally only ASCII files, we can replace it without problems

    int pos = 0;

    while ((pos = array.indexOf(char(1), pos)) != -1) {
        array[pos] = '"';
    }

    // Now that the XPM file is corrected, we need to load it.

    m_base = new PictureImage();

    QBuffer buffer(&array);
    bool check = m_base->load(&buffer, "xpm");
    setExtension("xpm");
    return check;
}
Beispiel #10
0
void Module::setExtension(const ObjectTypeTemplate &childTemplate, const ObjectType &parent)
{
    setExtension(childTemplate, [parent](const ObjectType& type)
    {
        return parent;
    });
}
DistanceFieldWriter::DistanceFieldWriter(QString format,QObject *parent) :
    AbstractImageWriter(parent)
{
    setExtension("png");
    setReloadSupport(false);
    m_format = format;
}
Beispiel #12
0
SolarSystem::SolarSkyBox::SolarSkyBox(Qt3DCore::QNode* parent):
    QSkyboxEntity(parent)
{
    //create skybox from file
    setBaseName(QStringLiteral("qrc:/Resources/Skybox/stars"));
    setExtension(QStringLiteral(".webp"));
}
Beispiel #13
0
/*!
  Elementary constructor.
*/
vpDiskGrabber::vpDiskGrabber()
  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
{
  setDirectory("/tmp");
  setBaseName("I");
  setExtension("pgm");

  init = false;
}
Beispiel #14
0
void ChordEdit::setHarmony(const Harmony* h)
      {
      _harmony = h->clone();
      setRoot(h->rootTpc());
      setBase(h->baseTpc());
      setExtension(h->id());

      for (int i = 0; i < h->numberOfDegrees(); ++i)
            addDegree(h->degree(i));
      }
Beispiel #15
0
/**
 * Sets the name of the file name.
 * If the name has an extension, the extension will be set
 * If the name has a full path (starts with drive or separator), the path will be set
 * If the name has a relative path, the path will be appended to the current path
 *
 * @param name		the name
 */
void Filename::setName(const char *name)
{
	if (name == NULL || *name == '\0')
		m_name = "";
	else
	{
#ifdef WIN32
		if (isalpha(*name) && *(name + 1) == ':')
		{
			setDrive(name);
			name += 2;
		}
#endif
		std::string localname = name;
		convertToSystemPath(localname);
		const char *dot = strrchr(localname.c_str(), '.');
		const char *firstSeparator = strchr(localname.c_str(), PATH_SEPARATOR);
		const char *lastSeparator = strrchr(localname.c_str(), PATH_SEPARATOR);
		if (firstSeparator != NULL)
		{
			// name has a path
			if (firstSeparator == localname)
			{
				// set path
				m_path = std::string(firstSeparator, lastSeparator - firstSeparator + 1);
			}
			else
			{
				// append path
				m_path += std::string(localname.c_str(), lastSeparator - 
					localname.c_str() + 1);
			}
		}
		if (dot != NULL && (lastSeparator == NULL || dot > lastSeparator))
		{
			// name has an extension
			setExtension(dot);
			if (lastSeparator == NULL)
				m_name = std::string(localname.c_str(), dot - localname.c_str());
			else
				m_name = std::string(lastSeparator + 1, dot - (lastSeparator + 1));
		}
		else
		{
			// name doesn't have an extension
			if (lastSeparator == NULL)
				m_name = localname;
			else
				m_name = std::string(lastSeparator + 1);
		}
	}

	makeFullPath();
}	// Filename::setName
Beispiel #16
0
Path& Path::makeFile()
{
	if (!_dirs.empty() && _name.empty())
	{
		_name = _dirs.back();
		_dirs.pop_back();
#if defined(POCO_OS_FAMILY_VMS)
		setExtension("DIR");
#endif
	}
	return *this;
}
Beispiel #17
0
vpDiskGrabber::vpDiskGrabber(const char *dir, const char *basename,
                             long number,
                             int step, unsigned int noz,
                             const char *ext)
  : image_number(number), image_step(step), number_of_zero(noz), useGenericName(false)
{
  setDirectory(dir);
  setBaseName(basename);
  setExtension(ext);

  init = false;
}
Beispiel #18
0
void Module::setExtension(const ObjectTypeTemplate &childTemplate, const ObjectType &parent, const std::map<int, int> &parameterMapping)
{
    setExtension(childTemplate, [parent, parameterMapping](const ObjectType& type)
    {
        ObjectType father = parent;
        for(const auto& binding : parameterMapping)
        {
            father.setParameter(binding.second, type.parameterValue(binding.first));
        }
        return father;
    });
}
Beispiel #19
0
bool CachedImage::_exists()
{
    const auto path = QString("%1/%2.%3").arg(_man->path()).arg(_hash);

    if (QFile::exists(path.arg("jpg")))
    {
        setExtension("jpeg");
        return true;
    }
    if (QFile::exists(path.arg("png")))
    {
        setExtension("png");
        return true;
    }
    if (QFile::exists(path.arg("gif")))
    {
        setExtension("gif");
        return true;
    }

    return false;
}
Beispiel #20
0
void Watcher::reset(const PlatformProcess& child) {
  if (child == *instance().worker_) {
    instance().worker_ = 0;
    resetWorkerCounters(0);
    return;
  }

  // If it was not the worker pid then find the extension name to reset.
  for (const auto& extension : extensions()) {
    if (*extension.second == child) {
      setExtension(extension.first, std::make_shared<PlatformProcess>());
      resetExtensionCounters(extension.first, 0);
    }
  }
}
void formatStockage::ecrire() {

    setHeader("[FORMAT_STOCKAGE]");
    setExtension(".avc");
    this->blocConfiguration::ecrire();

    std::ostringstream monEcriture;
    monEcriture << "Format_binaire>1_texte>2:\n";
    monEcriture << this->format << std::endl;
    monEcriture << "Format_stockage_fichier_prelevement_DG_0>texte_1>binaire:\n";
    monEcriture << this->formatFichierPrelevement << std::endl;

    Ecriture::Ecrire(monEcriture.str());

    Ecriture::Ecrire("\n");
}
Beispiel #22
0
vpDiskGrabber::vpDiskGrabber(const char *generic_name)
  : image_number(0), image_step(1), number_of_zero(0), useGenericName(false)
{
  setDirectory("/tmp");
  setBaseName("I");
  setExtension("pgm");

  init = false;
  if (strlen( generic_name ) >= FILENAME_MAX) {
    throw(vpException(vpException::memoryAllocationError,
                      "Not enough memory to intialize the generic name"));
  }

  strcpy(this->genericName, generic_name);
  useGenericName = true;
}
Beispiel #23
0
void TabEditor::openFileDialog(){

    QString file = QFileDialog::getOpenFileName(this,
                                              "Select source file",
                                              ".",
                                              "Text files (*.csv)"
                                              ";;csv files (*.txt)"
                                              ";;csv files (*.sav)"
                                              ";;csv files (*.xpt)"
                                              ";;csv files (*.dpt)"
                                              ";;All files (*.*)");

   file.replace("/","//");
   setFileName(QFileInfo(file).baseName());
   setExtension(QFileInfo(file).suffix());
   setPath(file);

}
Beispiel #24
0
OutgoingRTPPkt::OutgoingRTPPkt(const uint32* const csrcs, uint16 numcsrc,
const unsigned char* const hdrext, uint32 hdrextlen,
const unsigned char* const data, size_t datalen,
uint8 paddinglen, CryptoContext* pcc) :
RTPPacket((getSizeOfFixedHeader() + sizeof(uint32) * numcsrc + hdrextlen),datalen,paddinglen, pcc)
{
    uint32 pointer = (uint32)getSizeOfFixedHeader();
    // add CSCR identifiers (putting them in network order).
    setCSRCArray(csrcs,numcsrc);
    pointer += numcsrc * sizeof(uint32);

    // add header extension.
    setbuffer(hdrext,hdrextlen,pointer);
    setExtension(hdrextlen > 0);
    pointer += hdrextlen;

    // add data.
    setbuffer(data,datalen,pointer);
}
void blocCartographieTemporelle::ecrire(){

    setHeader("[CARTOGRAPHIES_TEMPORELLES]");
    setExtension(".ana");
    blocConfiguration::ecrire();

    std::ostringstream monEcriture;
    monEcriture << "Nombre_de_cartos_temporelles_: \n";
    monEcriture << this->getNbElement() << std::endl;

    Ecriture::Ecrire(monEcriture.str());

    cartographieTemporelle* temp;
    for(int i=0; i<this->getNbElement(); i++){
        temp = this->GetCarto(i);
        temp->ecrire(i+1);
    }

    Ecriture::Ecrire("\n");
}
void blocSurfacePrelevement::ecrire(){

    setHeader("[SURFACES_DE_PRELEVEMENT]");
    setExtension(".ana");
    this->blocConfiguration::ecrire();

    std::ostringstream monEcriture;
    monEcriture << "Nombre_de_surfaces_de_prelevement_au_total\n";
    monEcriture << this->getNbElement() << std::endl;
    monEcriture << "Nombre_de_surfaces_de_prelevement_DG\n";
    monEcriture << this->nbSurfacesDG << std::endl;

    Ecriture::Ecrire(monEcriture.str());

    for(int i=0; i<this->getNbElement(); i++){
        surfacePrelevement* temp = this->GetSurface(i);
        temp->ecrire(i+1);
    }

    Ecriture::Ecrire("\n");
}
Beispiel #27
0
CString Utils::getFileName(const std::vector<CString>& filter, int& typeIndex, CString fileName)
{
	const int index = (typeIndex - 1) * 2 + 1;

	const CString strExtension(GetExtension(fileName));
	const int extensionIndex = findExtension(filter, strExtension);

	if (index < filter.size())
	{
		if (extensionIndex == -1)
		{
			setExtension(fileName, GetExtension(filter[index]));
		}
		else if (!IsExtension(filter[index], strExtension))
		{
			typeIndex = extensionIndex / 2 + 1;
		}
	}

	return fileName;
}
void paroi::ecrire(){

    setHeader("[TYPE_PAROIS_0>Mur_1>PEC_2>FLOQUET_3>PML_4>PMC]");
    setExtension(".dsc");
    this->blocConfiguration::ecrire();

    
    std::ostringstream monEcriture;
    monEcriture << "Paroi_z_inferieure:\n";
    monEcriture << this->paroiInferieure << std::endl;
    monEcriture << "Paroi_z_superieur:\n";
    monEcriture << this->paroiSuperieure << std::endl;
    monEcriture << "Parois_x=0_x=xmax:\n";
    monEcriture << this->paroiX << std::endl;
    monEcriture << "Paroi_y=0_y=ymax:\n";
    monEcriture << this->paroiY << std::endl;

    Ecriture::Ecrire(monEcriture.str());

    Ecriture::Ecrire("\n");
}
void blocMetallisation::ecrire(){

    setHeader("[METALLISATIONS]");
    setExtension(".dsc");
    this->blocConfiguration::ecrire();



    std::ostringstream monEcriture;
    monEcriture << "Nombre_de_plans_de_metallisations\n";
    monEcriture << this->getNbElement() << std::endl;

    std::string ecriture(monEcriture.str());
    Ecriture::Ecrire(ecriture);

    for(int i=0; i<this->getNbElement() ; i++){
        metallisation* temp = this->GetMetallisation(i);
        temp->ecrire(i+1);
    }

    Ecriture::Ecrire("\n");
}
Beispiel #30
0
void Client::retrieveExtension()
{
    QSqlQuery retrieveExtension;
    retrieveExtension.prepare("SELECT acd_agent_exten_map_id, extension "
                              "FROM acd_agent_exten_map "
                              "WHERE ip_address = :ip_address");

    retrieveExtension.bindValue(":ip_address", socket->peerAddress().toString());

    if (retrieveExtension.exec()) {
        if (retrieveExtension.next()) {
            agentExtenMapId = retrieveExtension.value(0).toUInt();

            setExtension(retrieveExtension.value(1).toString());

            if (!extension.isEmpty())
                socketOut.writeTextElement("extension", extension);
        }
    } else {
        logFailedQuery(&retrieveExtension, "retrieving extension");
    }
}