Пример #1
0
/*!
  Inserts new record into the database, based on the current properties
  of the object.
*/
bool TSqlObject::create()
{
    // Sets the values of 'created_at', 'updated_at' or 'modified_at' properties
    for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) {
        const char *propName = metaObject()->property(i).name();
        QByteArray prop = QByteArray(propName).toLower();

        if (prop == CreatedAt || prop == UpdatedAt || prop == ModifiedAt) {
            setProperty(propName, QDateTime::currentDateTime());
        } else if (prop == LockRevision) {
            // Sets the default value of 'revision' property
            setProperty(propName, 1);  // 1 : default value
        } else {
            // do nothing
        }
    }

    syncToSqlRecord();

    QString autoValName;
    QSqlRecord record = *this;
    if (autoValueIndex() >= 0) {
        autoValName = field(autoValueIndex()).name();
        record.remove(autoValueIndex()); // not insert the value of auto-value field
    }

    QSqlDatabase &database = Tf::currentSqlDatabase(databaseId());
    QString ins = database.driver()->sqlStatement(QSqlDriver::InsertStatement, tableName(), record, false);
    if (Q_UNLIKELY(ins.isEmpty())) {
        sqlError = QSqlError(QLatin1String("No fields to insert"),
                             QString(), QSqlError::StatementError);
        tWarn("SQL statement error, no fields to insert");
        return false;
    }

    TSqlQuery query(database);
    bool ret = query.exec(ins);
    sqlError = query.lastError();
    if (Q_LIKELY(ret)) {
        // Gets the last inserted value of auto-value field
        if (autoValueIndex() >= 0) {
            QVariant lastid = query.lastInsertId();

            if (!lastid.isValid() && database.driverName().toUpper() == QLatin1String("QPSQL")) {
                // For PostgreSQL without OIDS
                ret = query.exec("SELECT LASTVAL()");
                sqlError = query.lastError();
                if (Q_LIKELY(ret)) {
                    lastid = query.getNextValue();
                }
            }

            if (lastid.isValid()) {
                QObject::setProperty(autoValName.toLatin1().constData(), lastid);
                QSqlRecord::setValue(autoValueIndex(), lastid);
            }
        }
    }
    return ret;
}
Пример #2
0
void QSslServer::incomingConnection(qintptr socket)
{
    QSslSocket *pSslSocket = new QSslSocket();

    if (Q_LIKELY(pSslSocket)) {
        pSslSocket->setSslConfiguration(m_sslConfiguration);

        if (Q_LIKELY(pSslSocket->setSocketDescriptor(socket)))
        {
            typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2)
            connect(pSslSocket, &QSslSocket::peerVerifyError, this, &QSslServer::peerVerifyError);

            connect(pSslSocket, &QSslSocket::encrypted, this, &QSslServer::newEncryptedConnection);

#else
            connect(pSslSocket,SIGNAL(peerVerifyError(QSslError)), this, SIGNAL(peerVerifyError(QSslError)));
            connect(pSslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SIGNAL(sslErrors(QList<QSslError>)));
            connect(pSslSocket, SIGNAL(encrypted()), this, SIGNAL(newEncryptedConnection()));
#endif
            addPendingConnection(pSslSocket);

            pSslSocket->startServerEncryption();
        }
        else
        {
            delete pSslSocket;
        }
    }
}
Пример #3
0
/*!
    \internal
 */
void QWebSocketServerPrivate::init()
{
    if (m_secureMode == NonSecureMode) {
        m_pTcpServer = new QTcpServer(q_ptr);
        if (Q_LIKELY(m_pTcpServer))
            QObjectPrivate::connect(m_pTcpServer, &QTcpServer::newConnection,
                                    this, &QWebSocketServerPrivate::onNewConnection);
        else
            qFatal("Could not allocate memory for tcp server.");
    } else {
#ifndef QT_NO_SSL
        QSslServer *pSslServer = new QSslServer(q_ptr);
        m_pTcpServer = pSslServer;
        if (Q_LIKELY(m_pTcpServer)) {
            QObjectPrivate::connect(pSslServer, &QSslServer::newEncryptedConnection,
                                    this, &QWebSocketServerPrivate::onNewConnection,
                                    Qt::QueuedConnection);
            QObject::connect(pSslServer, &QSslServer::peerVerifyError,
                             q_ptr, &QWebSocketServer::peerVerifyError);
            QObject::connect(pSslServer, &QSslServer::sslErrors,
                             q_ptr, &QWebSocketServer::sslErrors);
            QObject::connect(pSslServer, &QSslServer::preSharedKeyAuthenticationRequired,
                             q_ptr, &QWebSocketServer::preSharedKeyAuthenticationRequired);
        }
#else
        qFatal("SSL not supported on this platform.");
#endif
    }
    QObject::connect(m_pTcpServer, &QTcpServer::acceptError, q_ptr, &QWebSocketServer::acceptError);
}
Пример #4
0
/*!
    \internal
 */
void QWebSocketServerPrivate::onCloseConnection()
{
    if (Q_LIKELY(currentSender)) {
        QTcpSocket *pTcpSocket = qobject_cast<QTcpSocket*>(currentSender->sender);
        if (Q_LIKELY(pTcpSocket))
            pTcpSocket->close();
    }
}
/*!
 * \internal
 */
void QWebSocketPrivate::ignoreSslErrors()
{
    m_configuration.m_ignoreSslErrors = true;
    if (Q_LIKELY(m_pSocket)) {
        QSslSocket *pSslSocket = qobject_cast<QSslSocket *>(m_pSocket.data());
        if (Q_LIKELY(pSslSocket))
            pSslSocket->ignoreSslErrors();
    }
}
void QEventDispatcherBlackberry::wakeUp()
{
    Q_D(QEventDispatcherBlackberry);
    if (d->wakeUps.testAndSetAcquire(0, 1)) {
        bps_event_t *event;
        if (Q_LIKELY(bps_event_create(&event, bpsUnblockDomain, 0, 0, 0) == BPS_SUCCESS)) {
            if (Q_LIKELY(bps_channel_push_event(d->bps_channel, event) == BPS_SUCCESS))
                return;
            else
                bps_event_destroy(event);
        }
        qWarning("QEventDispatcherBlackberry: wakeUp failed");
    }
}
Пример #7
0
void Arguments::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize)
{
    if (Q_UNLIKELY(d->overrodeLength)) {
        unsigned length = min(get(exec, exec->propertyNames().length).toUInt32(exec), maxSize);
        for (unsigned i = 0; i < length; i++)
            buffer[i] = get(exec, i);
        return;
    }

    if (Q_LIKELY(!d->deletedArguments)) {
        unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
        unsigned i = 0;
        for (; i < parametersLength; ++i)
            buffer[i] = d->registers[d->firstParameterIndex + i].jsValue();
        for (; i < d->numArguments; ++i)
            buffer[i] = d->extraArguments[i - d->numParameters].jsValue();
        return;
    }

    unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
    unsigned i = 0;
    for (; i < parametersLength; ++i) {
        if (!d->deletedArguments[i])
            buffer[i] = d->registers[d->firstParameterIndex + i].jsValue();
        else
            buffer[i] = get(exec, i);
    }
    for (; i < d->numArguments; ++i) {
        if (!d->deletedArguments[i])
            buffer[i] = d->extraArguments[i - d->numParameters].jsValue();
        else
            buffer[i] = get(exec, i);
    }
}
Пример #8
0
void TabManager::select_all()
{
    codeEditor *current=qobject_cast<codeEditor *>(currentWidget());

    if(Q_LIKELY(current!=NULL))
        current->selectAll();
}
Пример #9
0
void TabManager::paste()
{
    codeEditor *current=qobject_cast<codeEditor *>(currentWidget());

    if(Q_LIKELY(current!=NULL))
        current->paste();
}
Пример #10
0
void FileAndDirectoryUtils::dumpStringToFile(QFile *f, QString &str) {
    if (Q_LIKELY(f == NULL || str.length() <= minLengthToWrite)) {
        return;
    }
    f->write(str.toLocal8Bit());
    str.clear();
}
Пример #11
0
// AspectThread
bool QPostman::shouldNotifyFrontend(const QSceneChangePtr &e)
{
    Q_D(QPostman);
    const QPropertyUpdatedChangePtr propertyChange = qSharedPointerDynamicCast<QPropertyUpdatedChange>(e);
    if (Q_LIKELY(d->m_scene != nullptr) && !propertyChange.isNull()) {
        const QScene::NodePropertyTrackData propertyTrackData
                = d->m_scene->lookupNodePropertyTrackData(e->subjectId());

        const QNode::PropertyTrackingMode trackMode = propertyTrackData.trackedPropertiesOverrides.value(QLatin1String(propertyChange->propertyName()),
                                                                                                      propertyTrackData.defaultTrackMode);

        switch (trackMode) {
        case QNode::TrackAllValues:
            return true;

        case QNode::DontTrackValues:
            return false;

        case QNode::TrackFinalValues: {
            const bool isIntermediate
                = QPropertyUpdatedChangeBasePrivate::get(propertyChange.data())->m_isIntermediate;
            return !isIntermediate;
        }

        default:
            Q_UNREACHABLE();
            return false;
        }
    }
    return true;
}
Пример #12
0
/*!
    \overload

    Starts (or restarts) the timer with a \a msec milliseconds timeout and the
    given \a timerType. See Qt::TimerType for information on the different
    timer types.

    \a obj will receive timer events.

    \sa stop(), isActive(), QObject::timerEvent(), Qt::TimerType
 */
void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj)
{
    QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
    if (Q_UNLIKELY(msec < 0)) {
        qWarning("QBasicTimer::start: Timers cannot have negative timeouts");
        return;
    }
    if (Q_UNLIKELY(!eventDispatcher)) {
        qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
        return;
    }
    if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
        qWarning("QBasicTimer::start: Timers cannot be started from another thread");
        return;
    }
    if (id) {
        if (Q_LIKELY(eventDispatcher->unregisterTimer(id)))
            QAbstractEventDispatcherPrivate::releaseTimerId(id);
        else
            qWarning("QBasicTimer::start: Stopping previous timer failed. Possibly trying to stop from a different thread");
    }
    id = 0;
    if (obj)
        id = eventDispatcher->registerTimer(msec, timerType, obj);
}
/*!
    \internal
 */
qint64 QWebSocketPrivate::writeFrame(const QByteArray &frame)
{
    qint64 written = 0;
    if (Q_LIKELY(m_pSocket))
        written = m_pSocket->write(frame);
    return written;
}
/*!
    \internal
 */
QHostAddress QWebSocketPrivate::peerAddress() const
{
    QHostAddress address;
    if (Q_LIKELY(m_pSocket))
        address = m_pSocket->peerAddress();
    return address;
}
/*!
    \internal
 */
QString QWebSocketPrivate::peerName() const
{
    QString name;
    if (Q_LIKELY(m_pSocket))
        name = m_pSocket->peerName();
    return name;
}
/*!
    \internal
 */
QAbstractSocket::SocketError QWebSocketPrivate::error() const
{
    QAbstractSocket::SocketError err = QAbstractSocket::UnknownSocketError;
    if (Q_LIKELY(m_pSocket))
        err = m_pSocket->error();
    return err;
}
Пример #17
0
static inline int futexFlags()
{
    int value = futexFlagSupport.load();
    if (Q_LIKELY(value != -1))
        return value;
    return checkFutexPrivateSupport();
}
Пример #18
0
/*!
    \internal
 */
QWebSocket *QWebSocketServerPrivate::nextPendingConnection()
{
    QWebSocket *pWebSocket = Q_NULLPTR;
    if (Q_LIKELY(!m_pendingConnections.isEmpty()))
        pWebSocket = m_pendingConnections.dequeue();
    return pWebSocket;
}
/*!
    \internal
 */
bool QWebSocketPrivate::flush()
{
    bool result = true;
    if (Q_LIKELY(m_pSocket))
        result = m_pSocket->flush();
    return result;
}
Пример #20
0
static int unixCheckClockType()
{
#if (_POSIX_MONOTONIC_CLOCK-0 == 0) && defined(_SC_MONOTONIC_CLOCK)
    // we need a value we can store in a clockid_t that isn't a valid clock
    // check if the valid ones are both non-negative or both non-positive
#  if CLOCK_MONOTONIC >= 0 && CLOCK_REALTIME >= 0
#    define IS_VALID_CLOCK(clock)    (clock >= 0)
#    define INVALID_CLOCK            -1
#  elif CLOCK_MONOTONIC <= 0 && CLOCK_REALTIME <= 0
#    define IS_VALID_CLOCK(clock)    (clock <= 0)
#    define INVALID_CLOCK            1
#  else
#    error "Sorry, your system has weird values for CLOCK_MONOTONIC and CLOCK_REALTIME"
#  endif

    static QBasicAtomicInt clockToUse = Q_BASIC_ATOMIC_INITIALIZER(INVALID_CLOCK);
    int clock = clockToUse.loadAcquire();
    if (Q_LIKELY(IS_VALID_CLOCK(clock)))
        return clock;

    // detect if the system supports monotonic timers
    clock = sysconf(_SC_MONOTONIC_CLOCK) > 0 ? CLOCK_MONOTONIC : CLOCK_REALTIME;
    clockToUse.storeRelease(clock);
    return clock;

#  undef INVALID_CLOCK
#  undef IS_VALID_CLOCK
#elif (_POSIX_MONOTONIC_CLOCK-0) > 0
    return CLOCK_MONOTONIC;
#else
    return CLOCK_REALTIME;
#endif
}
/*!
    \internal
 */
quint16 QWebSocketPrivate::peerPort() const
{
    quint16 port = 0;
    if (Q_LIKELY(m_pSocket))
        port = m_pSocket->peerPort();
    return port;
}
Пример #22
0
bool TRoom::removeSpecialExit( QString cmd )
{
    QString _strippedCmd;
    QString _prefix= "";
    bool isFound = false;

    if( cmd.startsWith('0') || cmd.startsWith('1') )
    {
        _strippedCmd = cmd.mid(1);
        _prefix = cmd.mid(0,1);
    }
    else
    {
        _strippedCmd = cmd;
    }

    if( _strippedCmd.isEmpty() )
        return isFound; // Refuse to delete an unnamed special exit!!!

    QMutableMapIterator<int, QString> it( other );
    while(it.hasNext() )
    {
        it.next();
        if( ! it.value().size() )
            continue;

        if( Q_LIKELY( it.value().startsWith('0') || it.value().startsWith('1') ) )
        {
            if( it.value().mid(1) != _strippedCmd )
                continue;
            else
            { // Found the matching command
                it.remove();
                isFound = true;
                break;
            }
        }
        else
        {
            if( it.value() != _strippedCmd )
                continue;
            else
            { // Found the matching command, this is an old one with no lock state prefix
                it.remove();
                isFound = true;
                break;
            }

        }
    }
    // Have definately removed the existing case of this command

    TArea * pA = mpRoomDB->getArea( areaId );
    if( pA )
    {
        pA->ausgaengeBestimmen();
        // The fast_ausgaengeBestimmen() method is only suitable for ADDING rooms/exits
    }
    return isFound;
}
Пример #23
0
/*!
    \internal
 */
QTextStream &QWebSocketHandshakeResponse::writeToStream(QTextStream &textStream) const
{
    if (Q_LIKELY(!m_response.isEmpty()))
        textStream << m_response.toLatin1().constData();
    else
        textStream.setStatus(QTextStream::WriteFailed);
    return textStream;
}
Пример #24
0
void ExportPrimersDialog::sl_connectionCompleted() {
    QObject *connectionDialog = sender();
    if (Q_LIKELY(NULL != connectionDialog)) {
        connectionDialog->deleteLater();
    }
    initDatabases();
    sl_updateState();
}
Пример #25
0
QString SubsurfaceSysInfo::osVersion()
{
#if defined(Q_OS_IOS)
	int major = (int(MacintoshVersion) >> 4) & 0xf;
	int minor = int(MacintoshVersion) & 0xf;
	if (Q_LIKELY(major < 10 && minor < 10)) {
		char buf[4] = { char(major + '0'), '.', char(minor + '0'), '\0' };
		return QString::fromLatin1(buf, 3);
	}
	return QString::number(major) + QLatin1Char('.') + QString::number(minor);
#elif defined(Q_OS_OSX)
	int minor = int(MacintoshVersion) - 2;  // we're not running on Mac OS 9
	Q_ASSERT(minor < 100);
	char buf[] = "10.0\0";
	if (Q_LIKELY(minor < 10)) {
		buf[3] += minor;
	} else {
		buf[3] += minor / 10;
		buf[4] = '0' + minor % 10;
	}
	return QString::fromLatin1(buf);
#elif defined(Q_OS_WIN)
	const char *version = winVer_helper();
	if (version)
		return QString::fromLatin1(version).toLower();
	// fall through

	// Android and Blackberry should not fall through to the Unix code
#elif defined(Q_OS_ANDROID)
	// TBD
#elif defined(Q_OS_BLACKBERRY)
	deviceinfo_details_t *deviceInfo;
	if (deviceinfo_get_details(&deviceInfo) == BPS_SUCCESS) {
		QString bbVersion = QString::fromLatin1(deviceinfo_details_get_device_os_version(deviceInfo));
		deviceinfo_free_details(&deviceInfo);
		return bbVersion;
	}
#elif defined(Q_OS_UNIX)
	QUnixOSVersion unixOsVersion = detectUnixVersion();
	if (!unixOsVersion.versionIdentifier.isEmpty())
		return unixOsVersion.versionIdentifier;
#endif

	// fallback
	return unknownText();
}
Пример #26
0
void CPU::interrupt(byte opcode)
{
    if (Q_LIKELY(m_state.int_enabled))
    {
        m_state.interrupt = true;
        m_state.interrupt_opcode = opcode;
    }
}
Пример #27
0
void Arguments::fillArgList(ExecState* exec, MarkedArgumentBuffer& args)
{
    if (Q_UNLIKELY(d->overrodeLength)) {
        unsigned length = get(exec, exec->propertyNames().length).toUInt32(exec);
        for (unsigned i = 0; i < length; i++)
            args.append(get(exec, i));
        return;
    }

    if (Q_LIKELY(!d->deletedArguments)) {
        if (Q_LIKELY(!d->numParameters)) {
            args.initialize(d->extraArguments, d->numArguments);
            return;
        }

        if (d->numParameters == d->numArguments) {
            args.initialize(&d->registers[d->firstParameterIndex], d->numArguments);
            return;
        }

        unsigned parametersLength = min(d->numParameters, d->numArguments);
        unsigned i = 0;
        for (; i < parametersLength; ++i)
            args.append(d->registers[d->firstParameterIndex + i].jsValue());
        for (; i < d->numArguments; ++i)
            args.append(d->extraArguments[i - d->numParameters].jsValue());
        return;
    }

    unsigned parametersLength = min(d->numParameters, d->numArguments);
    unsigned i = 0;
    for (; i < parametersLength; ++i) {
        if (!d->deletedArguments[i])
            args.append(d->registers[d->firstParameterIndex + i].jsValue());
        else
            args.append(get(exec, i));
    }
    for (; i < d->numArguments; ++i) {
        if (!d->deletedArguments[i])
            args.append(d->extraArguments[i - d->numParameters].jsValue());
        else
            args.append(get(exec, i));
    }
}
Пример #28
0
void EventDispatcherEPollPrivate::unregisterSocketNotifier(QSocketNotifier* notifier)
{
	Q_ASSERT(notifier != 0);
	Q_ASSUME(notifier != 0);

	SocketNotifierHash::Iterator it = this->m_notifiers.find(notifier);
	if (Q_LIKELY(it != this->m_notifiers.end())) {
		HandleData* info = it.value();
		int fd           = static_cast<int>(notifier->socket());

		this->m_notifiers.erase(it); // Hash is not rehashed

		HandleHash::Iterator hi = this->m_handles.find(fd);
		Q_ASSERT(hi != this->m_handles.end());

		struct epoll_event e;
		e.data.fd = fd;

		if (info->sni.r == notifier) {
			info->sni.events &= ~EPOLLIN;
			info->sni.r       = 0;
		}
		else if (info->sni.w == notifier) {
			info->sni.events &= ~EPOLLOUT;
			info->sni.w       = 0;
		}
		else if (info->sni.x == notifier) {
			info->sni.events &= ~EPOLLPRI;
			info->sni.x       = 0;
		}
		else {
			qFatal("%s: internal error: cannot find socket notifier", Q_FUNC_INFO);
		}

		e.events = info->sni.events;

		int res;

		if (info->sni.r || info->sni.w || info->sni.x) {
			res = epoll_ctl(this->m_epoll_fd, EPOLL_CTL_MOD, fd, &e);
		}
		else {
			res = epoll_ctl(this->m_epoll_fd, EPOLL_CTL_DEL, fd, &e);
			if (Q_UNLIKELY(res != 0 && EBADF == errno)) {
				res = 0;
			}

			this->m_handles.erase(hi);
			delete info;
		}

		if (Q_UNLIKELY(res != 0)) {
			qErrnoWarning("%s: epoll_ctl() failed", Q_FUNC_INFO);
		}
	}
}
/*!
    \internal
 */
qint64 QWebSocketPrivate::writeFrames(const QList<QByteArray> &frames)
{
    qint64 written = 0;
    if (Q_LIKELY(m_pSocket)) {
        QList<QByteArray>::const_iterator it;
        for (it = frames.cbegin(); it < frames.cend(); ++it)
            written += writeFrame(*it);
    }
    return written;
}
Пример #30
0
QT_BEGIN_NAMESPACE

static float qt_sg_envFloat(const char *name, float defaultValue)
{
    if (Q_LIKELY(!qEnvironmentVariableIsSet(name)))
        return defaultValue;
    bool ok = false;
    const float value = qgetenv(name).toFloat(&ok);
    return ok ? value : defaultValue;
}