Beispiel #1
1
QByteArray fromUnicode(const QString &data)
{
#ifdef Q_OS_WIN
    return data.toUtf8();
#else
    QTextCodec *locale = QTextCodec::codecForLocale();
    QByteArray result;
    char buffer[30000];
    uint buffer_len = 0;
    uint len = 0;
    int offset = 0;
    const int part_len = 5000;

    QString part;

    while (offset < data.length()) {
        part = data.mid(offset, part_len);
        QByteArray test = locale->fromUnicode(part);
        if (locale->toUnicode(test) == part) {
            result += test;
            offset += part_len;
            continue;
        }
        len = part.length();
        buffer_len = 0;
        for (uint i = 0; i < len; i++) {
            QByteArray test = locale->fromUnicode(part.mid(i, 1));
            if (locale->toUnicode(test) == part.mid(i, 1)) {
                if (buffer_len + test.length() + 1 > sizeof(buffer)) {
                    break;
                }
                strcpy(buffer + buffer_len, test.data());
                buffer_len += test.length();
            } else {
                QString res;
                res.sprintf("&#%d;", part.at(i).unicode());
                test = locale->fromUnicode(res);
                if (buffer_len + test.length() + 1 > sizeof(buffer)) {
                    break;
                }
                strcpy(buffer + buffer_len, test.data());
                buffer_len += test.length();
            }
        }
        result += QByteArray(buffer, buffer_len + 1);
        offset += part_len;
    }
    return result;
#endif
}
Beispiel #2
0
bool Pack::ExecuteCmd(QString exe, QStringList argument, QProcess &pprocess, QString workPath)
{
	QString enterPath = QStringLiteral("cd ") + "\"" + workPath + "\"" + QStringLiteral("\n");
	QString arg;
	arg.append(exe);
	for (QStringList::Iterator ite = argument.begin(); ite != argument.end(); ite++)
	{
		arg.append(" ");
		arg.append(*ite);		
	}
	arg.append("\n");
	pprocess.start("cmd");
	pprocess.waitForStarted();
	QTextCodec *gbk = QTextCodec::codecForName("GBK");
	QByteArray byteEnterPath = gbk->fromUnicode(enterPath.constData(), enterPath.length());
	QByteArray byteCommand = gbk->fromUnicode(arg.constData(), arg.length());
	char *charEnterPath = byteEnterPath.data();
	char *charCommand = byteCommand.data();
	pprocess.write(byteEnterPath);
	pprocess.write(charCommand);
	pprocess.closeWriteChannel();
	if (!pprocess.waitForFinished(1000 * 60 * 20)){
		return false;
	}
	return true;
	//mpprocess->setWorkingDirectory(workPath);
	//mpprocess->start(exe,argument);
}
QString FontDocument::hexCode(const QString &key, const QString &encoding, bool bom) const
{
  QString result;
  QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1());

  QChar ch = key.at(0);
  QByteArray codeArray = codec->fromUnicode(&ch, 1);

  quint64 code = 0;

  for (int i = 0; i < codeArray.count() && i < 8; i++) {
    code = code << 8;
    code |= (quint8)codeArray.at(i);
  }

  if (encoding.contains("UTF-16")) {
    // reorder bytes
    quint64 a =
      ((code & 0x000000000000ff00ULL) >> 8) |
      ((code & 0x00000000000000ffULL) << 8);
    code &= 0xffffffffffff0000ULL;
    code |= a;

    if (bom) {
      // 0xfeff00c1
      result = QString("%1").arg(code, 8, 16, QChar('0'));
    } else {
      // 0x00c1
      code &= 0x000000000000ffffULL;
      result = QString("%1").arg(code, 4, 16, QChar('0'));
    }
  } else if (encoding.contains("UTF-32")) {
Beispiel #4
0
void CDeviceGarmin::uploadTracks(const QList<CTrack*>& trks)
{
    qDebug() << "CDeviceGarmin::uploadTracks()";

    Garmin::IDevice * dev = getDevice();
    if(dev == 0) return;

    std::list<Garmin::Track_t> gartrks;
    QTextCodec *codec = QTextCodec::codecForName(CResources::self().charset().toLatin1());

    QList<CTrack*>::const_iterator trk = trks.begin();
    while(trk != trks.end())
    {
        Garmin::Track_t gartrk;

        gartrk.ident = codec->fromUnicode((*trk)->getName()).data();
        gartrk.color = (*trk)->getColorIdx();

        const QList<CTrack::pt_t>& trkpts           = (*trk)->getTrackPoints();
        QList<CTrack::pt_t>::const_iterator trkpt   =  trkpts.begin();
        while(trkpt != trkpts.end())
        {
            Garmin::TrkPt_t gartrkpt;

            QDateTime t = QDateTime::fromTime_t(trkpt->timestamp);
            t = t.addYears(-20).addDays(1);

            gartrkpt.time   = t.toTime_t();
            gartrkpt.lon    = trkpt->lon;
            gartrkpt.lat    = trkpt->lat;
            gartrkpt.alt    = trkpt->ele;

            gartrk.track.push_back(gartrkpt);
            ++trkpt;
        }

        gartrks.push_back(gartrk);
        ++trk;
    }

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    try
    {
        dev->uploadTracks(gartrks);
        if (CResources::self().playSound())
        {
            QSound::play(":/sounds/xfer-done.wav");
        }

        QApplication::restoreOverrideCursor();
    }
    catch(int)
    {
        QMessageBox::warning(0,tr("Device Link Error"),dev->getLastError().c_str(),QMessageBox::Ok,QMessageBox::NoButton);
        QApplication::restoreOverrideCursor();
        return;
    }

    theMainWindow->getCanvas()->setFadingMessage(tr("Upload tracks finished!"));
}
Beispiel #5
0
void CaxaRun::open()
{
	QString fileName = QFileDialog::getExistingDirectory(this, "", "");
	if (!fileName.isEmpty())
	{
		CxXmlHelper helper("");
		string name = fileName.toStdString();
		QTextCodec *c = QTextCodec::codecForName("gb18030");
		if (c) 
		{
			name = c->fromUnicode(fileName).data();
		}

		if (helper.read(name))
		{
			m_knowledges = helper.knowlegdes();
			ui.cb_knowledge->clear();

			std::map<std::string, CxKnowlegdeDesc>::iterator it = m_knowledges.begin();
			while (it != m_knowledges.end())
			{  
				ui.cb_knowledge->addItem(QString::fromStdString(it->second.m_strName.c_str()));
				it++;
			}
		}
	}
}
Beispiel #6
0
void XmlSync::processEntryType05(QDomElement &parentNode, QByteArray *data)
{
    QDomElement entryNode = parentNode.firstChildElement();
    QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");

    while(!entryNode.isNull())
    {
        if(entryNode.tagName() == QString("text"))
        {
            QDomElement originalNode;
            QString originalText;

            GET_NODE(entryNode, "original", originalNode);
            GET_NODE_TEXT(originalNode, originalText);

            data->append(codec->fromUnicode(originalText));
        }
        else if (entryNode.tagName() == QString("ctrl"))
        {
            QString ctrlString;

            ATTRIBUTE_TO_STRING_NOT_EMPTY(entryNode, "value", ctrlString);
            data->append(ctrlString);
        }
        else
        {
            fatalExit("Unknown tag (not 'text' or 'ctrl')");
        }

        entryNode = entryNode.nextSiblingElement();
    }
}
Beispiel #7
0
//------------------------------------------------------------------------------------
void readRecentFiles(QSettings& settings)
{
    int recentFileCount = settings.value("recentfiles/count").toInt();
    Ogitors::UTFStringVector recentList;
    recentList.clear();
    for(int i = 0;i < recentFileCount;i++)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-16");
        QString value = settings.value(QString("recentfiles/entry%1").arg(i)).toString();

        if(!QFile::exists(value))
            continue;

        QByteArray encodedString = codec->fromUnicode(value);

        Ogre::ushort *data = (Ogre::ushort*)encodedString.data();
        data++;

        Ogre::UTFString retStr(data,(encodedString.size() / 2) - 1);

        recentList.push_back(retStr);
    }

    Ogitors::OgitorsRoot::getSingletonPtr()->InitRecentFiles(recentList);
}
Beispiel #8
0
bool NCSqlQuery::exec( const QString & qs )
{
	bool ok = false;
	QTextCodec* codec = QTextCodec::codecForName(NCSQL_DEFAULTCODEC);
	
	if ( qs.isEmpty() )
		ok = QSqlQuery::exec();
	else
		ok = QSqlQuery::exec( (const char*)(codec->fromUnicode( qs )) );

	if ( !ok )
		logSqlError( qs, getErrorMsg() );
		
	if ( isActive() )
		saveColumns();
	else
		ok = false;
		
	//recinfo = sqlquery->driver()->recordInfo( *sqlquery );

	#ifdef NCSQL_ALWAYSLOG
		logSqlError( qs, "OK." );
	#endif

		
	#ifdef NCSQL_DEBUG_ON
		qDebug( "**************************************" );
		qDebug( "Execute NCSqlQuery::exec(...)" );
		qDebug( "**************************************" );
		qDebug( "%s", qPrintable(qs) );
		qDebug( "**************************************" );
	#endif
		
	return ok;
}
Beispiel #9
0
QString gbk_2_utf8(const QString &in)
{
    QTextCodec *gbk = QTextCodec::codecForName("gbk");
    //QTextCodec *utf8 = QTextCodec::codecForName("uft8");

    return gbk->toUnicode(gbk->fromUnicode(in));
}
Beispiel #10
0
void ZebraPaintEngine::drawText ( const QPointF &p, const QString & text, const QFont &font )
{
  QTransform transform = painter()->worldTransform();

  int xInDots = (int)(transform.dx());
  int yInDots = (int)(transform.dy());

  int carHeight = (font.pointSize() * resolution()) / 72;
  const int minSize = 10;
  if(carHeight < minSize) {
    carHeight = minSize;
  }
  int carWidth = qRound((carHeight * 15.0) / 28.0); // fixed width/height ratio for the scalable A0 font

  QString rotation = transformRotationCmd();
  if(rotation == rotation90Cmd()) {
    xInDots -= carHeight;
  }
  else if(rotation == rotation180Cmd()) {
    yInDots -= carHeight;
    xInDots -= (carWidth * text.length());
  }
  else if(rotation == rotation270Cmd()) {
    yInDots -= (carWidth * text.length());
  }

  QString output = QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "FW%3").arg(xInDots).arg(yInDots).arg(rotation);
  output += QString(m_CmdPrefix + "A0,%1,0" + m_CmdPrefix + "FD" + text + m_CmdPrefix + "FS\n").arg(carHeight);

  QTextCodec *codec = QTextCodec::codecForName("IBM 850");
  m_printBuffer.append(codec->fromUnicode(output));
}
Beispiel #11
0
DocumentPDF::DocumentPDF(const QString& _name)
{
#ifdef WIN32
    int size = _name.size();
    wchar_t* buffer = new wchar_t[size];
    _name.toWCharArray(buffer);
    m_xpdfDoc = new PDFDoc(buffer, size);
    delete [] buffer;
#elif defined __unix__

    QTextCodec* codec = QTextCodec::codecForName("UTF-8");

    QByteArray array = codec->fromUnicode(_name);

    const_c_str_t name = array.data();
    GString* filename = new GString( name );
    m_xpdfDoc = new PDFDoc(filename);    
#endif
    m_valid = m_xpdfDoc->isOk();
    if (m_valid)
    {
        m_numberOfPages = m_xpdfDoc->getNumPages();
        mp_thumbonails = new QList<QImage*>();
        m_pageNumber = 1;
        m_pageZoom = 1;
        mp_currentPage = NULL;
    }
}
void doctorChangeDialog::workChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray work = codec->fromUnicode( ui.workHours->text() );
    strncpy_s( doc->priem, work.constData(), 50 );
}
void doctorChangeDialog::dolgnostChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray dolgnost = codec->fromUnicode( ui.speciality->text() );
    strncpy_s( doc->dolgnost, dolgnost.constData(), 50 );
}
void doctorChangeDialog::fioChanged()
{
    //QTextCodec* codec = QTextCodec::codecForName("Windows-1251");
    QTextCodec *codec = QTextCodec::codecForName("CP866");
    QByteArray fio = codec->fromUnicode( ui.fio->text() );
    strncpy_s( doc->fio, fio.constData(), 50 );
}
Beispiel #15
0
static QString evilBytes(const QString& str,
    bool isUtf8, int format, const QByteArray &codecName)
{
    //qDebug() << "EVIL: " << str << isUtf8 << format << codecName;
    if (isUtf8)
        return protect(str);
    if (format == 20)
        return protect(str);
    if (codecName == "UTF-8")
        return protect(str);
    QTextCodec *codec = QTextCodec::codecForName(codecName);
    if (!codec)
        return protect(str);
    QString t = QString::fromLatin1(codec->fromUnicode(protect(str)).data());
    int len = (int) t.length();
    QString result;
    // FIXME: Factor is sensible only for latin scripts, probably.
    result.reserve(t.length() * 2);
    for (int k = 0; k < len; k++) {
        if (t[k].unicode() >= 0x7f)
            result += numericEntity(t[k].unicode());
        else
            result += t[k];
    }
    return result;
}
Beispiel #16
0
QVector<QString> IndexedEdictFile::findMatches( const QString &query ) const
{
  QVector<QString> results;
  if( ! m_valid )
  {
    return results;
  }

  QTextCodec *codec = QTextCodec::codecForName( "eucJP" );
  if( ! codec )
  {
    return results;
  }

  QByteArray searchString = codec->fromUnicode( query );
  int indexSize = m_indexFile.size() / sizeof( uint32_t );
  int dictSize  = m_dictFile.size() / sizeof( unsigned char );

  int matchLocation = findFirstMatch( searchString );
  QByteArray currentWord = lookupDictLine( ++matchLocation );
  if( matchLocation == 0 )
  {
    return results;
  }

  QVector<uint32_t> possibleHits;

  do
  {
    currentWord = lookupDictLine( ++matchLocation );
    int i = 0;
    while( lookupDictChar( m_indexPtr[ matchLocation - 1 ] + i - 2 ) != 0x0A )
    {
      --i;
    }
    possibleHits.push_back( m_indexPtr[ matchLocation - 1 ] + i - 1 );
  } while( matchLocation < indexSize && 0 == equalOrSubstring( searchString, currentWord ) );

  if( possibleHits.size() <= 0 )
  {
    return results;
  }

  qSort( possibleHits );
  uint32_t last = 0;

  foreach( uint32_t it, possibleHits )
  {
    if(last != it)
    {
      last = it;
      results.push_back( codec->toUnicode( lookupFullLine( it ) ) );
    }
  }

  return results;
}
QByteArray
AmarokLyricsScript::fromUtf8( const QString &str, const QString &encoding )
{
    QTextCodec* codec = QTextCodec::codecForName( encoding.toUtf8() );
    if( !codec )
        return QByteArray();

    return codec->fromUnicode( str );
}
Beispiel #18
0
void PluginList::writePlugins(const QString &fileName, bool writeUnchecked) const
{
  SafeWriteFile file(fileName);

  QTextCodec *textCodec = writeUnchecked ? m_Utf8Codec : m_LocalCodec;

  file->resize(0);

  file->write(textCodec->fromUnicode("# This file was automatically generated by Mod Organizer.\r\n"));

  QStringList saveList;

  bool invalidFileNames = false;
  int writtenCount = 0;
  for (size_t i = 0; i < m_ESPs.size(); ++i) {
    int priority = m_ESPsByPriority[i];
    if (m_ESPs[priority].m_Enabled || writeUnchecked) {
      //file.write(m_ESPs[priority].m_Name.toUtf8());
      if (!textCodec->canEncode(m_ESPs[priority].m_Name)) {
        invalidFileNames = true;
        qCritical("invalid plugin name %s", m_ESPs[priority].m_Name.toUtf8().constData());
      } else {
        saveList << m_ESPs[priority].m_Name;
        file->write(textCodec->fromUnicode(m_ESPs[priority].m_Name));
      }
      file->write("\r\n");
      ++writtenCount;
    }
  }

  if (invalidFileNames) {
    reportError(tr("Some of your plugins have invalid names! These plugins can not be loaded by the game. "
                   "Please see mo_interface.log for a list of affected plugins and rename them."));
  }

  if (writtenCount == 0) {
    qWarning("plugin list would be empty, this is almost certainly wrong. Not saving.");
  } else {
    if (file.commitIfDifferent(m_LastSaveHash[fileName])) {
      qDebug("%s saved", QDir::toNativeSeparators(fileName).toUtf8().constData());
    }
  }
}
/*将字符串转化为二进制流,亦或(^)操作只能在二进制流文件上进行*/
QByteArray qstringToByte(const QString &strInfo)
{
  QByteArray result;
  if(strInfo.length() > 0){
    QTextCodec *codec = QTextCodec::codecForName("GBK");
    result = codec->fromUnicode(strInfo);
  }

  return result;
}
Beispiel #20
0
QByteArray Zeroconf::TruncateName(const QString& name) {
  QTextCodec* codec = QTextCodec::codecForName("UTF-8");
  QByteArray truncated_utf8;
  foreach (QChar c, name) {
    QByteArray rendered = codec->fromUnicode(&c, 1, NULL);
    if (truncated_utf8.size() + rendered.size() >= 63) {
      break;
    }
    truncated_utf8 += rendered;
  }
void Highlighter::slot_addWord(QString word)
{
	QMessageBox::information(NULL,"","guguguggu");
    std::cout << qPrintable(word) << std::endl;
    QByteArray encodedString;
    QString spell_encoding=QString(pChecker->get_dic_encoding());
    QTextCodec *codec = QTextCodec::codecForName(spell_encoding.toLatin1());
    encodedString = codec->fromUnicode(word);
    pChecker->add(encodedString.data());
    rehighlight();
}
Beispiel #22
0
void Utility::postHttp(const QString postUrl,const QString postData)
{
    QTextCodec *codec = QTextCodec::codecForName("gb2312");
    QByteArray array=codec->fromUnicode(postData);
    QNetworkRequest request;
    request.setUrl(QUrl(postUrl));
    request.setRawHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");/*设置http请求头,不然塞班真机会出现问题*/
    request.setRawHeader ("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 LBBROWSER");
    request.setRawHeader ("Cookie", settings.getValue ("userCookie","").toByteArray ());
    manager->post(request,array);
}
Beispiel #23
0
static string toGbkString(QString gbk)
{
	string inv = gbk.toStdString();
	QTextCodec *c = QTextCodec::codecForName("gb18030");
	if (c) 
	{
		inv = c->fromUnicode(gbk).data();
	}

	return inv;
}
Beispiel #24
0
void MRAData::addUnicodeString(const QString &str) {

    QTextCodec *codec = QTextCodec::codecForName("UTF-16LE");

    QByteArray ba = codec->fromUnicode(str);

    ba = ba.remove(0, 2); // remove BOM (Byte Order Mark)

    addUint32(ba.size());
    addData(ba.constData(), ba.size());

}
Beispiel #25
0
QByteArray Channel1MessageData::fromUnicode(const QString &message, Channel1Codec charset)
{
	QTextCodec *codec = 0;
	if (charset == CodecUtf16Be)
		codec = utf16Codec();
	else
		codec = asciiCodec();
	QByteArray data = codec->fromUnicode(message);
	if (charset == CodecUtf16Be)
		data = data.mid(2); // Remove BOM which are shown by some clients as an unknown symbol
	return data;
}
Beispiel #26
0
void ZGui::saveAs ( const QString fileName, bool save )
{ 
	if ( (access(fileName.utf8(),0) == 0) && !save )
	{
		QString sBody = lng->getString("REWRITE").arg ( getFileName(fileName) );
		
		ZMessageDlg * pConfirmation = new ZMessageDlg ( lng->getString("SAVING"), sBody, ( ZMessageDlg::MessageDlgType )1, 0, this, "2", true, 0 );
		if ( pConfirmation->exec() )
		{
			ZMessageDlg * pMessage = new ZMessageDlg ( lng->getString("SAVING"), lng->getString("CHANGED"), ( ZMessageDlg::MessageDlgType )1, 0, this, "saveas", true, 0 );
			pMessage->show();
			delete pMessage;
		}
		
		delete pConfirmation;
	}
	
	if ( !(access(getFilePath(fileName).utf8(),02) == 0) ) // Check save to ReadOnly FS
	{   
		ZMessageDlg * pWarning = new ZMessageDlg ( lng->getString("ERROR"), "Do not save to ReadOnly FS!", ( ZMessageDlg::MessageDlgType )2, 0, this, "saveas", true, 0 );
		pWarning->exec();
		delete pWarning;
		return;
	}
	
	if ( access(fileName.utf8(),0) == 0 ) //remove file for rewrite
		remove(fileName.utf8());
	
	QFile file ( fileName );
	
	if ( !file.open ( IO_WriteOnly | IO_Truncate ) )
	{   
		ZMessageDlg * pWarning = new ZMessageDlg ( lng->getString("ERROR"), lng->getString("FILE_SAVING_FAILED"), ( ZMessageDlg::MessageDlgType )2, 0, this, "saveas", true, 0 );
		pWarning->exec();
		delete pWarning;
		return;
	}
	
	QTextCodec* codec = codecByLocalId(textCode);	
	file.reset();
	QCString str = codec->fromUnicode( edit->text() );
	file.writeBlock( str, str.length() );
	char endFile[]={0};
	file.writeBlock( endFile, sizeof(endFile) );
	
	file.flush();
	file.close();
	
	ZMessageDlg * pMessage = new ZMessageDlg ( lng->getString("SAVING"), lng->getString("FILE_SAVING_SUCCESS"), ( ZMessageDlg::MessageDlgType ) 2, 0, this, "saveas", true, 0 );
	pMessage->exec();
	delete pMessage;
}
Beispiel #27
0
void GisClient::sendCommand(const QString &command)
{
    QByteArray block;

    QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
    block.append(codec->fromUnicode(command));

    tcpSocket->write(block);
    tcpSocket->write("\n");
    QEventLoop loop;
    QTimer::singleShot(300, &loop, SLOT(quit()));
    loop.exec();
}
void FileTransferWidget::SendCmd(const QString& aCmd)
{
    QString codepage = "CP1251";
    QTextCodec* codec = QTextCodec::codecForName(codepage.toLocal8Bit());
    if (codec != NULL)
    {
        m_socket->write(codec->fromUnicode(aCmd));
    }
    else
    {
        m_socket->write(aCmd.toLatin1());
    }
}
Beispiel #29
0
void TextToSpeechPrivate::say(const QString &text) {
	QTextCodec *codec = QTextCodec::codecForName("Apple Roman");
	Q_ASSERT(codec != NULL);

	qmLock.lock();
	qlMessages.append(codec->fromUnicode(text));
	qmLock.unlock();

	if (!bRunning) {
		ProcessSpeech();
		bRunning = true;
	}
}
Beispiel #30
0
void
CXParamData::setValues(const QString& aGroup, const PairsList& aValues)
{
  std::string group = aGroup.toStdString();

  QTextCodec* codec = QTextCodec::codecForName("UTF-8");

  for (int i = 0; i < aValues.count(); i++)
    {
      gIniFile.SetValue(group, aValues.at(i).first.toStdString(),
          codec->fromUnicode(aValues.at(i).second).data());
    }
}