Example #1
0
int makedir (const QString& newdir)
{
	QChar p;
	QString buffer;
	int len = newdir.length();
	
	if (len <= 0)
		return 0;
	buffer = newdir;

	if (buffer.endsWith("/") || buffer.endsWith("\\"))
		buffer.left(len - 1);

	if (mymkdir(buffer) == 0)
		return 1;

	uint cIndex = 1;
	p = buffer[1];
	while (1)
	{
		QString tmpBuf;
		while(!p.isNull() && p != '\\' && p != '/')
			p = buffer[cIndex++];
		tmpBuf = buffer.left(cIndex - 1);
		if ((mymkdir(tmpBuf) == -1) && (errno == ENOENT))
			return 0;
		if (p.isNull())
			break;
		p = buffer[++cIndex];
	}
	return 1;
}
Example #2
0
QStringList GaduEmoticonParser::parseAliases()
{
	QStringList result;

	QChar c = peek();
	if (c.isNull())
		return result;

	bool multiple = false;
	if (c == '(')
	{
		multiple = true;
		eat();
	}

	while (true)
	{
		QString alias = parseQuoted();
		if (!alias.isEmpty())
			result.append(alias);

		if (!multiple)
			return result;

		c = get();
		if (c.isNull() || c == ')')
			return result;

		if (c != ',') // some kind of error
			return result;
	}

	Q_ASSERT(false);
}
Example #3
0
void ShoutCastMetaParser::setMetaFormat(const QString &metaformat)
{
/*
  We support these metatags :
  %a - artist
  %t - track
  %b - album
  %r - random bytes
 */
    m_meta_format = metaformat;

    m_meta_artist_pos = 0;
    m_meta_title_pos = 0;
    m_meta_album_pos = 0;

    int assign_index = 1;
    int pos = 0;

    pos = m_meta_format.indexOf("%", pos);
    while (pos >= 0)
    {
        pos++;

        QChar ch;

        if (pos < m_meta_format.length())
            ch = m_meta_format.at(pos);

        if (!ch.isNull() && ch == '%')
        {
            pos++;
        }
        else if (!ch.isNull() && (ch == 'r' || ch == 'a' || ch == 'b' || ch == 't'))
        {
            if (ch == 'a')
                m_meta_artist_pos = assign_index;

            if (ch == 'b')
                m_meta_album_pos = assign_index;

            if (ch == 't')
                m_meta_title_pos = assign_index;

            assign_index++;
        }
        else
            LOG(VB_GENERAL, LOG_ERR,
                QString("ShoutCastMetaParser: malformed metaformat '%1'")
                    .arg(m_meta_format));

        pos = m_meta_format.indexOf("%", pos);
    }

    m_meta_format.replace("%a", "(.*)");
    m_meta_format.replace("%t", "(.*)");
    m_meta_format.replace("%b", "(.*)");
    m_meta_format.replace("%r", "(.*)");
    m_meta_format.replace("%%", "%");
}
Example #4
0
QChar QPhoneNumberString::translatedToVanity(const QChar c) {
    if ( c.isNull() ) return QChar();
    if ( c.isNumber() ) return c;
    if ( c.isSpace() ) return QChar('1');
    QChar vanityChar = m_VanityChars[ c.toLower() ];
    if ( vanityChar.isNull() )
        kDebug() << " did not found char "
                 << c << hex << c.unicode()
                 << "\" to translate.";
    return( vanityChar );
}
void Scanner::consumeUntil(const char* stopAt, const char* stopAfter)
{
    QChar ch = m_src.peek();
    while (!ch.isNull() && !ch.isSpace() && !std::strchr(stopAt, ch.toLatin1())) {
        m_src.move();
        ch = m_src.peek();
        if (stopAfter && !ch.isNull() && std::strchr(stopAfter, ch.toLatin1())) {
            m_src.move();
            break;
        }
    }
}
Example #6
0
    QString get(int type)
    {
        QChar current;
        QString result;

        passWhiteSpace();
        while (true) {
            current = next();
            if (current.isNull()) {
                break;
            }
            if (current.isSpace()) {
                break;
            }
            bool number = isNumber(current);
            if (type == GetDigit && !number) {
                break;
            }
            if (type == GetString && number) {
                break;
            }
            if(current == QLatin1Char( CONVERSION_CHAR )) {
                break;
            }
            ++m_index;
            result += current;
        }
        return result;
    }
Example #7
0
void MainWidget::paintEvent(QPaintEvent *event) {
    int xt = event->region().boundingRect().topLeft().x()/xsize;
    int yt = event->region().boundingRect().topLeft().y()/ysize;
    int xb = event->region().boundingRect().bottomRight().x()/xsize;
    int yb = event->region().boundingRect().bottomRight().y()/ysize;
    QPainter painter(this);

    if (showGrid) {
        painter.setPen(palette().dark().color());
        for (int i = xt; i <= xb; ++i)
            painter.drawLine(xsize * i, 0, xsize * i, ysize * yasc);
        for (int j = yt; j <= yb; ++j)
            painter.drawLine(0, ysize * j, xsize * xasc, ysize * j);
    }

    for (int i = xt; i <= xb; ++i) {
        for (int j = yt; j <= yb; ++j) {
            QRect rect = pixelRect(i, j);
            if (!event->region().intersect(rect).isEmpty()) {
                painter.fillRect(rect, QColor::fromRgb(background.pixel(i, j)));
                painter.setPen(QColor::fromRgb(foreground.pixel(i,j)));
                QChar c = text.at(j).at(i);
                if (c.isNull())
                    c = ' ';
                painter.drawText(rect.translated(1,0), Qt::AlignCenter, c);
            }
        }
    }
    QRect lastRect = pixelRect(lastx, lasty).adjusted(0,0,-1,-1);
    if (!event->region().intersect(lastRect).isEmpty() && hasFocus()) {
        painter.setPen(selColor);
        painter.drawRect(lastRect);
    }
    current_brush->second->onWidgetPaint(event, painter);
}
Example #8
0
QImage MainWidget::getRenderedImage(bool g) const {
    QSize size(xsize*xasc, ysize*yasc);
    if (g)
        size += QSize(1, 1);
    QImage image(size, QImage::Format_ARGB32);
    QPainter painter(&image);

    if (g) {
        painter.setPen(palette().dark().color());
        for (int i = 0; i <= xasc; ++i)
            painter.drawLine(xsize * i, 0, xsize * i, ysize * yasc);
        for (int j = 0; j <= yasc; ++j)
            painter.drawLine(0, ysize * j, xsize * xasc, ysize * j);
    }

    for (int i = 0; i < xasc; ++i) {
        for (int j = 0; j < yasc; ++j) {
            QRect rect = g ? QRect(xsize * i + 1, ysize * j + 1, xsize - 1, ysize - 1) : QRect(xsize * i, ysize * j, xsize, ysize);;
            painter.fillRect(rect, QColor::fromRgb(background.pixel(i, j)));
            painter.setPen(QColor::fromRgb(foreground.pixel(i,j)));
            QChar c = text.at(j).at(i);
            if (c.isNull())
                c = ' ';
            painter.drawText(rect.translated(1,0), Qt::AlignCenter, c);
        }
    }
    painter.end();
    return image;
}
QString Q_GUI_EXPORT qt_accHotKey(const QString &text)
{
#ifndef QT_NO_SHORTCUT
    if (text.isEmpty())
        return text;

    int fa = 0;
    QChar ac;
    while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) {
        ++fa;
        if (fa < text.length()) {
            // ignore "&&"
            if (text.at(fa) == QLatin1Char('&')) {
                ++fa;
                continue;
            } else {
                ac = text.at(fa);
                break;
            }
        }
    }
    if (ac.isNull())
        return QString();
    return (QString)QKeySequence(Qt::ALT) + ac.toUpper();
#else
    Q_UNUSED(text);
    return QString();
#endif
}
Example #10
0
void Tabruler::setTabFillChar(QChar t)
{
	if (t.isNull())
	{
		tabFillCombo->setEditable(false);
		tabFillCombo->setCurrentIndex(0);
	}
	else if (t == '.')
	{
		tabFillCombo->setEditable(false);
		tabFillCombo->setCurrentIndex(1);
	}
	else if (t == '-')
	{
		tabFillCombo->setEditable(false);
		tabFillCombo->setCurrentIndex(2);
	}
	else if (t == '_')
	{
		tabFillCombo->setEditable(false);
		tabFillCombo->setCurrentIndex(3);
	}
	else
	{
		tabFillCombo->setCurrentIndex(4);
		tabFillCombo->setEditable(true);
		setCurrentComboItem(tabFillCombo, CommonStrings::trCustomTabFill+QString(t));
	}
	emit tabrulerChanged();
	emit tabsChanged();
}
Example #11
0
FormatToken Scanner::readMultiLineComment(int literalId)
{
	saveState(State_MultiLineComment, QChar(static_cast<ushort>(literalId)));
	for(;;) {
		QChar ch = m_src.peek();
		if(ch.isNull())
			break;
		if(ch == QLatin1Char(']'))
		{
			bool bMatching = true;
			for(int i=0; i < literalId; ++i)
			{
				if(m_src.peek(i+1) != QLatin1Char('='))
				{
					bMatching = false;
					break;
				}
			}
			if(bMatching && m_src.peek(literalId+1) == QLatin1Char(']'))
			{
				clearState();
				m_src.move(literalId+2);
				break;
			}
		}
		m_src.move();
	}
	return FormatToken(Format_MLComment, m_src.anchor(), m_src.length());
}
Example #12
0
//-----------------------------------------------------------------------------
QString FontHelper::escapeControlChars(const QString &value)
{
    QString result;

    for (int i = 0; i < value.length(); i++)
    {
        QChar c = value.at(i);

        if (c.isNull() || !c.isPrint())
        {
            quint16 code = c.unicode();
            result.append(QString("\\x%1").arg(code, 4, 16, QChar('0')));
        }
        else if (c == QChar('@'))
        {
            result.append(QString("\\x0040"));
        }
        else if (c == QChar(QChar::Nbsp))
        {
            result.append(QString("\\x00a0"));
        }
        else
        {
            result.append(c);
        }
    }

    return result;
}
Example #13
0
// Handling of the HTML accesskey attribute.
bool KKbdAccessExtensions::handleAccessKey( const QKeyEvent* ev )
{
// Qt interprets the keyevent also with the modifiers, and ev->text() matches that,
// but this code must act as if the modifiers weren't pressed
    if (!d->accessKeyLabels) return false;
    QChar c;
    if( ev->key() >= Key_A && ev->key() <= Key_Z )
        c = 'A' + ev->key() - Key_A;
    else if( ev->key() >= Key_0 && ev->key() <= Key_9 )
        c = '0' + ev->key() - Key_0;
    else {
        // TODO fake XKeyEvent and XLookupString ?
        // This below seems to work e.g. for eacute though.
        if( ev->text().length() == 1 )
            c = ev->text()[ 0 ];
    }
    if( c.isNull())
        return false;

    QLabel* lab = d->accessKeyLabels->first();
    while (lab) {
        if (lab->text() == c) {
            lab->buddy()->setFocus();
            delete d->accessKeyLabels;
            d->accessKeyLabels = 0;
            return true;
        }
        lab = d->accessKeyLabels->next();
    }
    return false;
}
Example #14
0
void HTML::decodeStr(QString* str)
{
    int index = 0;
    QChar decodedChar;
    QStringList res;
    QRegExp entityParser("(&([a-zA-Z]+);)",Qt::CaseInsensitive);
    QRegExp directCharParser("(&#([0-9]+);)",Qt::CaseInsensitive);


    qDebug() << "Checking" << *str;
    while (index > -1) {
        index = directCharParser.indexIn(*str,index+1);
        res = directCharParser.capturedTexts();
        if (index != -1) {
            decodedChar = QChar(directCharParser.cap(2).toInt());
            str->replace(res.at(1), decodedChar);
            qDebug() << *str;
        }
    }

    index = 0;
    while((index = entityParser.indexIn(*str,index)) != -1)
    {
        index++;
        decodedChar = resolveEntity(entityParser.cap(2));
        qDebug() << "Decoding in " << entityParser.cap(1) << ":" << entityParser.cap(2) << " to " << decodedChar << "(" << decodedChar.isNull()<<")";
        if (!decodedChar.isNull()) {
            qDebug() << "Replacing in " << entityParser.cap(1) << ":" << entityParser.cap(2) << " to " << decodedChar;
            str->replace(entityParser.cap(1),QString(decodedChar));
        }
    }

}
Example #15
0
void CodeEditor::keyPressEvent(QKeyEvent *event)
{
    switch (event->key()) {
    	case Qt::Key_Return:
		case Qt::Key_Enter:
		{
			QTextCursor tc = textCursor();
			QString t = tc.block().text();
			QString spaces;
			QChar *data = t.data();
			while (!data->isNull() && data->isSpace()) {
				spaces.append(*data);
				++data;
			}
			QPlainTextEdit::keyPressEvent(event);
			insertPlainText(spaces);
		}
        break;
		case Qt::Key_F1:
			insertPlainText("\t");
			break;

		default:
			QPlainTextEdit::keyPressEvent(event);
    }
}
Example #16
0
QString Lexer::readArgument()
{
    int count = 0;

    QString arg;

    readWhiteSpaces();
    while( currentChar() ){

	readWhiteSpaces();
	QChar ch = currentChar();

	if( ch.isNull() || (!count && (ch == ',' || ch == ')')) )
	    break;

	Token tk(m_source);
	nextToken( tk );

	if( tk == '(' ){
	    ++count;
	} else if( tk == ')' ){
	    --count;
	}

	if( tk != -1 )
            arg += tk.text() + " ";
    }

    return arg.stripWhiteSpace();
}
Example #17
0
void IpcMsg::sendMessage(QString msg)
{
    auto shm = new QSharedMemory("TimeTrackShm");
    shm->attach();
    shm->lock();

    // send the message
    char *to = (char*)shm->data();
    QChar *data = msg.data();
    while(!data->isNull()){
        memset(to, data->toLatin1(), 1);
        ++data;
        ++to;
    }
    memset(to, 0, 1);

    shm->unlock();
    delete shm;

    // unlock the listener
    auto sem = new QSystemSemaphore(
                "TimeTrackSem", 0, QSystemSemaphore::Open);
    sem->release();
    delete sem;
}
Example #18
0
void GaduEmoticonParser::parse()
{
	QChar c = peek();
	if (c.isNull())
		return;

	if (c == '*') // ignore first *, I don't know why
		eat();

	QStringList aliases = parseAliases();
	eat(); // ,
	QString animatedPath = parseQuoted();
	eat(); // ,
	QString staticPath = parseQuoted();

	if (aliases.isEmpty() || animatedPath.isEmpty())
		return;

	animatedPath = ThemePath + fixFileName(ThemePath, animatedPath);
	if (staticPath.isEmpty())
		staticPath = animatedPath;
	else
		staticPath = ThemePath + fixFileName(ThemePath, staticPath);

	Result = Emoticon(aliases.at(0), staticPath, animatedPath);
	foreach (const QString &alias, aliases)
		Aliases.append(Emoticon(alias, staticPath, animatedPath));
}
Example #19
0
QString QFileSelectorPrivate::selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors, const QChar &indicator)
{
    /* selectionHelper does a depth-first search of possible selected files. Because there is strict
       selector ordering in the API, we can stop checking as soon as we find the file in a directory
       which does not contain any other valid selector directories.
    */
    Q_ASSERT(path.isEmpty() || path.endsWith(QLatin1Char('/')));

    for (const QString &s : selectors) {
        QString prospectiveBase = path;
        if (!indicator.isNull())
            prospectiveBase += indicator;
        prospectiveBase += s + QLatin1Char('/');
        QStringList remainingSelectors = selectors;
        remainingSelectors.removeAll(s);
        if (!QDir(prospectiveBase).exists())
            continue;
        QString prospectiveFile = selectionHelper(prospectiveBase, fileName, remainingSelectors, indicator);
        if (!prospectiveFile.isEmpty())
            return prospectiveFile;
    }

    // If we reach here there were no successful files found at a lower level in this branch, so we
    // should check this level as a potential result.
    if (!QFile::exists(path + fileName))
        return QString();
    return path + fileName;
}
Example #20
0
int InputMask::findInMask( int pos, bool forward, bool findSeparator, QChar searchChar ) const
{
    if ( pos >= m_maxLength || pos < 0 )
        return -1;

    int end = forward ? m_maxLength : -1;
    int step = forward ? 1 : -1;
    int i = pos;

    while ( i != end )
    {
        if ( findSeparator )
        {
            if ( m_maskData[ i ].separator && m_maskData[ i ].maskChar == searchChar )
                return i;
        }
        else
        {
            if ( !m_maskData[ i ].separator )
            {
                if ( searchChar.isNull() )
                    return i;
                else if ( isValidInput( searchChar, m_maskData[ i ].maskChar ) )
                    return i;
            }
        }
        i += step;
    }
    return -1;
}
void MainWindow::MakeFreqMap(){
	m_pFreqMap = new QHash<QChar,int>(); 
	QString plainText = m_pTextEdit->toPlainText() ; 
	if(!plainText.isEmpty())
	{
		QChar * data = plainText.data();
		while(!data->isNull())
		{
			//iterate through string, adding and incrementing frequencies.
			QHash<QChar, int>::iterator iter = m_pFreqMap->find(*data); 
			if(iter.key() == m_pFreqMap->end().key()){
				//key not found, insert new key and set its value to 1
				m_pFreqMap->insert(*data,1);
			}
			else{
				//the value was found, increment its frequency
				//this is an inefficient way to do this, consider redoing it.
				int newFreq = m_pFreqMap->take(*data) + 1; 
				m_pFreqMap->insert(*data,newFreq);		
			}
			//lastly, move one position through the string. 
			data++;
		}
	}
//Make Nodes from the freq map
	MakeNodes(m_pFreqMap);
	RunBST(); 
}
QStringList CommandExecutionEngine::tokenize(const QString& string, const QString& quoteSymbols, const QString& escapeSymbols)
{
	QStringList result;
	QString str;

	QChar quote;

	for (int i = 0; i < string.size(); ++i)
	{
		if ( quote.isNull() )
		{
			if ( quoteSymbols.contains(string[i]) )
			{
				if ( !str.isNull() ) result.append(tokenizeNonQuoted(str.simplified()));
				quote = string[i];
				str = quote;
			}
			else str.append(string[i]);
		}
		else
		{
			if ( string[i] == quote && !isEscaped(string, i, escapeSymbols) )
			{
				result.append(str + quote);
				quote = QChar();
				str = QString();
			}
		}
	}

	if ( !str.isNull() ) result.append(tokenizeNonQuoted(str.simplified()));
	return result;
}
Example #23
0
void ExtractToken( QString & buffer, const QString & string, int & pos, bool & isNumber )
{
	buffer.clear();
	if ( string.isNull() || pos >= string.length() )
		return;

	isNumber = false;
	QChar curr = string[ pos ];
	if ( curr == '-' || curr == '+' || curr.isDigit() )
	{
		if ( curr == '-' || curr == '+' )
			INCBUF();

		if ( !curr.isNull() && curr.isDigit() )
		{
			isNumber = true;
			while ( curr.isDigit() )
				INCBUF();

			if ( curr == '.' )
			{
				INCBUF();
				while ( curr.isDigit() )
					INCBUF();
			}

			if ( !curr.isNull() && curr.toLower() == 'e' )
			{
				INCBUF();
				if ( curr == '-' || curr == '+' )
					INCBUF();

				if ( curr.isNull() || !curr.isDigit() )
					isNumber = false;
				else
					while ( curr.isDigit() )
						INCBUF();
			}
		}
	}

	if ( !isNumber )
	{
		while ( curr != '-' && curr != '+' && !curr.isDigit() && pos < string.length() )
			INCBUF();
	}
}
Example #24
0
void PrefixSettings::getWineCdromLetter(){
    if (!txtMountPoint->text().isEmpty()){
        QChar letter = CoreLib->getCdromWineDrive(db_prefix.getPath(prefix_name), txtMountPoint->text());
        if (!letter.isNull()){
            comboWinDrive->setCurrentIndex(comboWinDrive->findText(QString("%1:").arg(letter.toUpper())));
        }
    }
}
Example #25
0
/*! Lex any string types at the current position of the stream.
 * \return The lexed token. */
TokenPtr Lexer::lexStrings()
{
    consume();

    QChar next = peek();

    QString str = "";

    int decimals = 0;
    while (!next.isNull() && next != '"')
    {
        str += next;
        if (next == '.') ++decimals;
        consume();
        next = peek();
    }

    consume('"');

    if ((str.count() == 3) && ((str == "---") || (str == str.toUpper())))
    {
        return TokenPtr(new TagToken(str, true, d->currentSpan()));
    }

    if ((decimals == '2') || (decimals == 3))
    {
        Date date = Date::parse(str);

        if (date.isValid())
        {
            return TokenPtr(new DateToken(date, true, d->currentSpan()));
        }
    }

    if (decimals == 0)
    {
        bool ok = false;
        long long v = str.toLongLong(&ok);
        if (ok)
        {
            return TokenPtr(new IntegerToken(v, true, d->currentSpan()));
        }
    }

    if (decimals == 1)
    {
        int prec = str.split('.')[1].count();
        bool ok = false;
        double v = str.toDouble(&ok);

        if (ok)
        {
            return TokenPtr(new DecimalToken(v, prec, true, d->currentSpan()));
        }
    }

    return TokenPtr(new StringToken(str, d->currentSpan()));
}
/**
  reads single-line ruby comment, started with "#"
  */
Token Scanner::readComment()
{
    QChar ch = m_src.peek();
    while (!isLineFeed(ch) && !ch.isNull()) {
        m_src.move();
        ch = m_src.peek();
    }
    return Token(Token::Comment, m_src.anchor(), m_src.length());
}
Example #27
0
bool Map::isPassable(int x, int y)
{
	QChar c = getChar(x, y);
	if(!c.isNull())
	{
		return isPassable(c);
	}
	return false;
}
Example #28
0
    QString prettyChar(QChar c)
    {
        if ( !c.isNull() )
        {
            return "end of file";
        }

        return QString( c );
    }
bool CommandExecutionEngine::doQuotesMatch(const QString& string, const QString& quoteSymbols, const QString& escapeSymbols)
{
	QChar quote;

	for (int i = 0; i < string.size(); ++i)
	{
		if ( quote.isNull() )
		{
			if ( quoteSymbols.contains(string[i]) ) quote = string[i];
		}
		else
		{
			if ( string[i] == quote && !isEscaped(string, i, escapeSymbols) ) quote = QChar();
		}
	}

	return quote.isNull();
}
int findWordBegin(const TextEditor::AssistInterface *interface)
{
    int pos = interface->position();
    QChar c;
    do {
        c = interface->characterAt(--pos);
    } while (!c.isNull() && (c.isLetterOrNumber() ||  c == QLatin1Char('_')));
    return pos + 1;
}