Пример #1
0
UserAgentsManagerDialog::UserAgentsManagerDialog(QList<UserAgentInformation> userAgents, QWidget *parent) : Dialog(parent),
	m_ui(new Ui::UserAgentsManagerDialog)
{
	m_ui->setupUi(this);
	m_ui->moveDownButton->setIcon(ThemesManager::getIcon(QLatin1String("arrow-down")));
	m_ui->moveUpButton->setIcon(ThemesManager::getIcon(QLatin1String("arrow-up")));

	QStandardItemModel *model(new QStandardItemModel(this));
	model->setHorizontalHeaderLabels(QStringList({tr("Title"), tr("Value")}));

	for (int i = 0; i < userAgents.count(); ++i)
	{
		QList<QStandardItem*> items({new QStandardItem(userAgents.at(i).getTitle()), new QStandardItem(userAgents.at(i).value)});
		items[0]->setData(userAgents.at(i).identifier, Qt::UserRole);
		items[0]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable);
		items[1]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable);

		model->appendRow(items);
	}

	m_ui->userAgentsView->setModel(model);

	connect(m_ui->userAgentsView, SIGNAL(canMoveDownChanged(bool)), m_ui->moveDownButton, SLOT(setEnabled(bool)));
	connect(m_ui->userAgentsView, SIGNAL(canMoveUpChanged(bool)), m_ui->moveUpButton, SLOT(setEnabled(bool)));
	connect(m_ui->userAgentsView, SIGNAL(needsActionsUpdate()), this, SLOT(updateUserAgentActions()));
	connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addUserAgent()));
	connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(removeUserAgent()));
	connect(m_ui->moveDownButton, SIGNAL(clicked()), m_ui->userAgentsView, SLOT(moveDownRow()));
	connect(m_ui->moveUpButton, SIGNAL(clicked()), m_ui->userAgentsView, SLOT(moveUpRow()));
}
Пример #2
0
UserAgentsManagerDialog::UserAgentsManagerDialog(QList<UserAgentInformation> userAgents, QWidget *parent) : QDialog(parent),
	m_ui(new Ui::UserAgentsManagerDialog)
{
	m_ui->setupUi(this);
	m_ui->moveDownButton->setIcon(Utils::getIcon(QLatin1String("arrow-down")));
	m_ui->moveUpButton->setIcon(Utils::getIcon(QLatin1String("arrow-up")));

	QStringList labels;
	labels << tr("Title") << tr("Value");

	QStandardItemModel *model = new QStandardItemModel(this);
	model->setHorizontalHeaderLabels(labels);

	for (int i = 0; i < userAgents.count(); ++i)
	{
		const QString title = userAgents.at(i).title;
		QList<QStandardItem*> items;
		items.append(new QStandardItem(title.isEmpty() ? tr("(Untitled)") : title));
		items[0]->setData(userAgents.at(i).identifier, Qt::UserRole);
		items[0]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
		items.append(new QStandardItem(userAgents.at(i).value));
		items[1]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);

		model->appendRow(items);
	}

	m_ui->userAgentsView->setModel(model);
	m_ui->userAgentsView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);

	connect(m_ui->userAgentsView, SIGNAL(canMoveDownChanged(bool)), m_ui->moveDownButton, SLOT(setEnabled(bool)));
	connect(m_ui->userAgentsView, SIGNAL(canMoveUpChanged(bool)), m_ui->moveUpButton, SLOT(setEnabled(bool)));
	connect(m_ui->userAgentsView, SIGNAL(needsActionsUpdate()), this, SLOT(updateUserAgentActions()));
	connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addUserAgent()));
	connect(m_ui->editButton, SIGNAL(clicked()), this, SLOT(editUserAgent()));
	connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(removeUserAgent()));
	connect(m_ui->moveDownButton, SIGNAL(clicked()), m_ui->userAgentsView, SLOT(moveDownRow()));
	connect(m_ui->moveUpButton, SIGNAL(clicked()), m_ui->userAgentsView, SLOT(moveUpRow()));
}
void ARTSPConnection::onSendRequest(const sp<AMessage> &msg) {
    sp<AMessage> reply;
    CHECK(msg->findMessage("reply", &reply));

    if (mState != CONNECTED) {
        reply->setInt32("result", -ENOTCONN);
        reply->post();
        return;
    }

    AString request;
    CHECK(msg->findString("request", &request));

    // Just in case we need to re-issue the request with proper authentication
    // later, stash it away.
    reply->setString("original-request", request.c_str(), request.size());

    addAuthentication(&request);
    addUserAgent(&request);

    // Find the boundary between headers and the body.
    ssize_t i = request.find("\r\n\r\n");
    CHECK_GE(i, 0);

    int32_t cseq = mNextCSeq++;

    AString cseqHeader = "CSeq: ";
    cseqHeader.append(cseq);
    cseqHeader.append("\r\n");

    request.insert(cseqHeader, i + 2);

    ALOGV("request: '%s'", request.c_str());

    size_t numBytesSent = 0;
    while (numBytesSent < request.size()) {
        ssize_t n =
            send(mSocket, request.c_str() + numBytesSent,
                 request.size() - numBytesSent, 0);

        if (n < 0 && errno == EINTR) {
            continue;
        }

        if (n <= 0) {
            performDisconnect();

            if (n == 0) {
                // Server closed the connection.
                ALOGE("Server unexpectedly closed the connection.");

                reply->setInt32("result", ERROR_IO);
                reply->post();
            } else {
                ALOGE("Error sending rtsp request. (%s)", strerror(errno));
                reply->setInt32("result", -errno);
                reply->post();
            }

            return;
        }

        numBytesSent += (size_t)n;
    }

    mPendingRequests.add(cseq, reply);
}
Пример #4
0
void ARTSPConnection::onSendRequest(const sp<AMessage> &msg) {
#ifndef ANDROID_DEFAULT_CODE
    int32_t backup;
    if (msg->findInt32("backup-keep-tcp", &backup)) {
        mForceQuitTCP = backup;
    }
#endif
    sp<AMessage> reply;
    CHECK(msg->findMessage("reply", &reply));

    if (mState != CONNECTED) {
        reply->setInt32("result", -ENOTCONN);
        reply->post();
        return;
    }

    AString request;
    CHECK(msg->findString("request", &request));

    // Just in case we need to re-issue the request with proper authentication
    // later, stash it away.
    reply->setString("original-request", request.c_str(), request.size());
#ifndef ANDROID_DEFAULT_CODE
    // mtk80902: ALPS01139972 - SETUP resp with a wrong Session "xxx\0\0\0.."
    // so the followed \r\n is ignored by find's strstr operation
    if (request.find("\r\n\r\n") < 0) {
        ALOGW("what the hell with this req?");  // seems print str is useless..
        reply->setInt32("result", -EBADMSG);
        reply->post();
        return;
    }
#endif
    addAuthentication(&request);
    addUserAgent(&request);

    // Find the boundary between headers and the body.
    ssize_t i = request.find("\r\n\r\n");
    CHECK_GE(i, 0);

    int32_t cseq = mNextCSeq++;

    AString cseqHeader = "CSeq: ";
    cseqHeader.append(cseq);
    cseqHeader.append("\r\n");

    request.insert(cseqHeader, i + 2);

#ifndef ANDROID_DEFAULT_CODE
    ALOGI("request: '%s'", request.c_str());
#else
    ALOGV("request: '%s'", request.c_str());
#endif

    size_t numBytesSent = 0;
    while (numBytesSent < request.size()) {
        ssize_t n =
#ifndef ANDROID_DEFAULT_CODE
            send(mSocket, request.c_str() + numBytesSent,
                 request.size() - numBytesSent, MTK_SEND_FLAG);
#else
            send(mSocket, request.c_str() + numBytesSent,
                 request.size() - numBytesSent, 0);
#endif

        if (n < 0 && errno == EINTR) {
            continue;
        }

        if (n <= 0) {
            performDisconnect();

            if (n == 0) {
                // Server closed the connection.
                ALOGE("Server unexpectedly closed the connection.");

                reply->setInt32("result", ERROR_IO);
                reply->post();
            } else {
                ALOGE("Error sending rtsp request. (%s)", strerror(errno));
                reply->setInt32("result", -errno);
                reply->post();
            }

            return;
        }

        numBytesSent += (size_t)n;
    }

    mPendingRequests.add(cseq, reply);
#ifndef ANDROID_DEFAULT_CODE 
    sp<AMessage> timeout = new AMessage(kWhatTimeout, id());
    timeout->setInt32("cseq", cseq);
    int64_t t;
    if (reply->findInt64("timeout", &t)) {
        timeout->post(t);
    } else {
        timeout->post(kRequestTimeout);
    }
#endif // #ifndef ANDROID_DEFAULT_CODE
}