Ejemplo n.º 1
0
extern QVariantMap toMap(QWebElement el, QStringList css_attrs) {
    QVariantMap map;
    map["isNull"] = false;
    map["classes"] = QVariant(el.classes());
    map["tagName"] = QVariant(el.tagName());
    QRect rect = el.geometry();

    QVariantMap geo;

    geo["width"] = rect.width();
    geo["height"] = rect.height();
    geo["x"] = rect.x();
    geo["y"] = rect.y();
    map["geometry"] = QVariant(geo);

    QVariantMap attrs;
    QStringList attributes = el.attributeNames();
    foreach(QString name,attributes) {
        attrs[name] = el.attribute(name);
    }
Ejemplo n.º 2
0
void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl)
{
    Q_UNUSED(baseUrl);
    qDebug() << "--- start of query result --- cut here ------";
    qDebug() << QString::fromUtf8(htmlReply.constData());
    qDebug() << "--- end of query result ----- cut here ------";

    emit layoutAboutToBeChanged();
    beginResetModel();
    QWebPage page;
    page.mainFrame()->setContent(htmlReply, "text/html", baseUrl);
    QWebElement doc = page.mainFrame()->documentElement();

    // Check if the page is reporting an error before parsing it
    QWebElement errorElement = doc.findFirst("span.errore");
    if (!errorElement.isNull()) {
        m_departureSchedules.clear();
        m_arrivalSchedules.clear();
        QString errorText = errorElement.toPlainText().trimmed();
        if (errorText == "localita' non trovata") {
            setError(tr("Unknown station"));
        } else {
            setError(tr("Unknown error"));
        }
        qDebug() << "error:" << error();
        return;
    }
    // Find the first div
    QWebElement current = doc.findFirst("div");

    qDebug() << "skipping to the departures";
    // Skip to the first div of class corpocentrale, which contains the first
    // departure-related contents
    while (!current.classes().contains("corpocentrale")) {
        current = current.nextSibling();
        qDebug() << "skipping to the next element";
        if (current.isNull())
            break;
    }
    // Mark every div as a departure class element; the next corpocentrale
    // marks the start of the arrivals section
    qDebug() << "marking departures";
    do {
        if (current.classes().contains("bloccorisultato")) {
            StationScheduleItem schedule = parseResult(current);
            if (schedule.isValid()) {
                m_departureSchedules << schedule;
            }
        }
        current = current.nextSibling();
        qDebug() << "marking as departures";
        if (current.isNull())
            break;
    } while (!current.classes().contains("corpocentrale"));

    // Mark everything as an arrival, until reaching the footer
    while (!current.classes().contains("footer")) {
        if (current.classes().contains("bloccorisultato")) {
            StationScheduleItem schedule = parseResult(current);
            if (schedule.isValid()) {
                m_arrivalSchedules << schedule;
            }
        }
        current = current.nextSibling();
        qDebug() << "marking as arrival";
        if (current.isNull())
            break;
    }
    endResetModel();
    emit layoutChanged();
}
Ejemplo n.º 3
0
void MWBotWin::atkRat() {
	QWebElement elm;
	setBusy(true);
// go to page
	loadPath(QStringList() << "square" << "metro");
// select dark/normal rats
	elm = frm->findFirstElement("div.metro-branch div.metro-rats-light__dark-block");
	if (!elm.isNull()) {
		log(trUtf8("Dark/Normal select"),"bug.png");
		if (opt.ratk.dark) {
			elm = frm->findFirstElement("a.f[href='/metro/select/1/']");
		} else {
			elm = frm->findFirstElement("a.f[href='/metro/select/0/']");
		}
		elm = elm.findFirst("div.c");
		if (elm.isNull()) {
			log(trUtf8("DEBUG: Rat selection error"));
			return;
		}
		clickElement(elm);
	}
// check timer & atk rat
	int time = getRatTimer();
	if (opt.ratk.ratlev > opt.ratk.maxlev) {
		elm = frm->findFirstElement("div#action-rat-fight div small small.dashedlink");
		if (elm.isNull()) {
			time = 60;
		} else {
			time = elm.attribute("timer").toInt() + 60;
		}
		opt.ratk.time = QDateTime::currentDateTime().addSecs(time);
		opt.ratk.ratlev = 1;
		log(trUtf8("Хватит крыс. Ждём обвала. До обвала <b>%0</b> мин.").arg(time/60 + 1),"rat.png");
	} else if (time < 1) {
		log(trUtf8("Уровень крысы: <b>%0</b>").arg(opt.ratk.ratlev),"rat.png");
		restoreHP();
		clickElement("div#action-rat-fight div.button-big div.c");
		clickElement("div#welcome-rat button.button div.c");
		if (opt.ratk.ratlev % 5 == 0) {
			groupFight();
		} else {
			fightResult();
		}
		getRatTimer();
	} else {
		time += 30 + random() % 30;
		opt.ratk.time = QDateTime::currentDateTime().addSecs(time);
		log(trUtf8("До следующей крысы <b>%0</b> мин.").arg(time/60 + 1),"rat.png");
	}
// take tails prize
	elm = frm->findFirstElement("div.metro-branch table.collectbar td.actions button.button");
	if (!elm.isNull()) {
		if (!elm.classes().contains("disabled")) {
			elm = elm.findFirst("div.c");
			clickElement(elm);
			log(trUtf8("Получен приз за крысинные хвосты"),"rattail.png");
		}
	}

	setBusy(false);
}
Ejemplo n.º 4
0
void MWBotWin::doTaxi() {
	if (curTime.date().dayOfWeek() != 1) return;
	if (opt.taxi.time > curTime) return;
	QWebElement elm;
	QWebElement sub;
	int time;
	int count;
	int loop;
	setBusy(true);
	loadPage("arbat");
// check taxi chest and take it
	elm = frm->findFirstElement("div.auto-bombila table.collectbar td.actions button.button");
	if (elm.isNull()) {
		count = 0;
	} else {
		count = elm.classes().contains("disabled") ? 0 : 1;
	}
	if (count) {
		sub = elm.findFirst("div.c");
		clickElement(sub);
		log(trUtf8("Забран сундук бомбилы"),"chest.png");
	}
// check taxi timer, send a car & charge it if it needs
	elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown");
	if (elm.styleProperty("display",QWebElement::ComputedStyle) == "none") {
		time = 0;
	} else {
		time = elm.attribute("timer").toInt();
	}
	if (time != 0) {
		time += (30 + (random() % 30));
		opt.taxi.time = curTime.addSecs(time);
		log(trUtf8("До следующей бомбилки %0 сек").arg(time),"taxi.png");
	} else {
		do {
			loop = 0;
			elm= frm->findFirstElement("div.auto-bombila table.action button.ride-button span.f div.c");
			clickElement(elm);
			elm = frm->findFirstElement("div.alert.alert-error h2#alert-title");
			if (elm.isNull()) {
				elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown");
				time = elm.attribute("timer").toInt();
				time += 30 + random() % 30;
				opt.taxi.time = curTime.addSecs(time);
				log(trUtf8("Авто отправлено бомбить. До следующего раза %0 сек").arg(time),"taxi.png");
			} else {
				elm = frm->findFirstElement("div.alert.alert-error div.actions div.button div.c");
				sub = elm.findFirst("span");
				count = sub.toPlainText().remove("\"").toInt();
				getFastRes();
				if (sub.classes().contains("ruda")) {
					count = (info.ore >= count) ? 1 : 0;
				} else if (sub.classes().contains("oil")) {
					count = (info.oil >= count) ? 1 : 0;
				} else {
					count = 0;
				}
				if (count) {
					clickElement(elm);
					log(trUtf8("Машина заправлена"),"taxi.png");
					loop = 1;
				} else {
					time = 15 * 60;
					opt.taxi.time = curTime.addSecs(time);
					log(trUtf8("Не хватает ресурсов для заправки. Ждём 15 мин"),"taxi.png");
				}
			}
		} while (loop);
	}
	setBusy(false);
}
Ejemplo n.º 5
0
bool MyWebView::eventFilter(QObject *watched, QEvent *event)
{
	if (!m_boolEnableEvtProcess) { return false; }

	if (event->type() == QEvent::MouseMove)
	{
		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
		QWebView *view          = dynamic_cast<QWebView*>(watched);
		QPoint pos              = view->mapFromGlobal(mouseEvent->globalPos());
		QWebFrame *frame        = view->page()->frameAt(mouseEvent->pos());
		if (frame!=NULL)
		{
			QWebHitTestResult hitTestResult = frame->hitTestContent(pos);
			// if the hovered elem is not the same as the previously hovered
			if (hitTestResult.element() != m_old_hover_element)
			{
				QWebElement elemCurrent = hitTestResult.element();
				// if dragging, overwrite with closer WContainer
				if (m_boolIsDraggingWidget)
				{
					elemCurrent = FindCloserContainer(elemCurrent);
				}
				if (!elemCurrent.isNull())
				{
					// Change color
					ChangeHoveredElemColor(elemCurrent);
					// Message to print
					m_strCurrentElemId = elemCurrent.attribute("id");
					// Emit message
					QStringList strlistClasses = elemCurrent.classes();
					strlistClasses.removeAll(g_strHighlightClassName);
					Q_EMIT mouseMovedOverElem(m_strCurrentElemId, strlistClasses.join(' '));
				}
			}
		}
	}
	else if (event->type() == QEvent::MouseButtonPress)
	{
		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
		if (mouseEvent->button() == Qt::LeftButton)
		{
			QWebView *view = dynamic_cast<QWebView*>(watched);
			QPoint pos = view->mapFromGlobal(mouseEvent->globalPos());
			QWebFrame *frame = view->page()->frameAt(mouseEvent->pos());
			if (frame != NULL)
			{
				QWebHitTestResult hitTestResult = frame->hitTestContent(pos);
                QWebElement welemTemp = hitTestResult.element();
                QWebElement elemCurrent = FindCloserWidget(welemTemp);
				// if the clicked elem is not the same as the previously clicked
				if (elemCurrent != m_old_click_element)
				{
					// Change color
					ChangeClickedElemColor(elemCurrent);
					// Message to print
					m_strCurrentElemId = elemCurrent.attribute("id");
					// Emit message
					Q_EMIT mouseLeftClickedOverElem(m_strCurrentElemId);
				}
			}
		}
	}
	return false;
}