예제 #1
0
bool HistoryChatView::onContextMenu(ChatView *view, QMenu *menu, const QWebHitTestResult &result)
{
  ChatId id(view->id());
  if (id.type() != ChatId::ChannelId && id.type() != ChatId::UserId)
    return false;

  const QWebElement block = result.enclosingBlockElement();
  if (!block.hasClass("blocks") || block.hasClass("removed"))
    return false;

  const QWebElement container = block.parent();
  const qint64 mdate          = container.attribute(LS("data-mdate")).toLongLong();

  if (!mdate)
    return false;

  id.init(container.attribute(LS("id")).toLatin1());
  id.setDate(mdate);
  if (id.type() != ChatId::MessageId)
    return false;

  const int permissions = this->permissions(HistoryDB::get(id));
  if (permissions == NoPermissions)
    return false;

  if (permissions & Remove) {
    QVariantList data;
    data << view->id() << (id.hasOid() ? ChatId::toBase32(id.oid().byteArray()) : id.toString());

    menu->insertAction(menu->actions().first(), removeAction(data));
  }
  return true;
}
예제 #2
0
void PmrWindowWidget::filter(const QString &pFilter)
{
    // Filter our list of exposures and remove any duplicates (they will be
    // 'reintroduced' in the next step)

    QStringList filteredExposureNames = mExposureNames.filter(QRegularExpression(pFilter, QRegularExpression::CaseInsensitiveOption));

    mNumberOfFilteredExposures = filteredExposureNames.count();

    filteredExposureNames.removeDuplicates();

    // Update our message and show/hide the relevant exposures

    page()->mainFrame()->documentElement().findFirst("p[id=message]").setInnerXml(message());

    QWebElement trElement = page()->mainFrame()->documentElement().findFirst(QString("tbody[id=exposures]")).firstChild();
    QWebElement ulElement;

    for (int i = 0, iMax = mExposureNames.count(); i < iMax; ++i) {
        if (mExposureDisplayed[i] != filteredExposureNames.contains(mExposureNames[i])) {
            QString displayValue = mExposureDisplayed[i]?"none":"table-row";

            trElement.setStyleProperty("display", displayValue);

            ulElement = trElement.firstChild().firstChild().nextSibling();

            if (ulElement.hasClass("visible"))
                ulElement.setStyleProperty("display", displayValue);

            mExposureDisplayed[i] = !mExposureDisplayed[i];
        }

        trElement = trElement.nextSibling();
    }
}
void PhysiomeModelRepositoryWindowWidget::filter(const QString &pFilter)
{
    // Make sure that we have something to filter (i.e. no error message)

    if (!mErrorMessage.isEmpty())
        return;

    // Filter our list of exposures, remove any duplicates (they will be
    // reintroduced in the next step) and update our message (by retranslating
    // ourselves)

    QStringList filteredExposureNames = mExposureNames.filter(QRegularExpression(pFilter, QRegularExpression::CaseInsensitiveOption));

    mNumberOfFilteredExposures = filteredExposureNames.count();

    filteredExposureNames.removeDuplicates();

    retranslateUi();

    // Show/hide the relevant exposures
    // Note: to call QWebElement::setStyleProperty() many times is time
    //       consuming, hence we rely on mExposureDisplayed to determine when we
    //       should change the display property of our elements...

    QWebElement trElement = page()->mainFrame()->documentElement().findFirst(QString("tbody[id=exposures]")).firstChild();
    QWebElement ulElement;

    for (int i = 0, iMax = mExposureNames.count(); i < iMax; ++i) {
        if (mExposureDisplayed[i] != filteredExposureNames.contains(mExposureNames[i])) {
            QString displayValue = mExposureDisplayed[i]?"none":"table-row";

            trElement.setStyleProperty("display", displayValue);

            ulElement = trElement.firstChild().firstChild().nextSibling();

            if (ulElement.hasClass("visible"))
                ulElement.setStyleProperty("display", displayValue);

            mExposureDisplayed[i] = !mExposureDisplayed[i];
        }

        trElement = trElement.nextSibling();
    }
}
예제 #4
0
static QList<GagObject> parseGAG(const QWebElementCollection &entryItems)
{
    QList<GagObject> gagList;

    foreach (const QWebElement &element, entryItems) {
        GagObject gag;
        gag.setId(element.attribute("data-entry-id"));
        gag.setUrl(element.attribute("data-entry-url"));
        gag.setVotesCount(element.attribute("data-entry-votes").toInt());
        gag.setCommentsCount(element.attribute("data-entry-comments").toInt());
        gag.setTitle(element.findFirst("a").toPlainText().trimmed());

        gag.setIsLiked(!element.findFirst("ul.badge-item-vote-container.up").isNull());
        gag.setIsDisliked(!element.findFirst("ul.badge-item-vote-container.down").isNull());

        const QWebElement postContainer = element.findFirst("div.post-container");

        if (!postContainer.findFirst("div.nsfw-post").isNull()) {
            gag.setIsNSFW(true);
        } else if (!postContainer.findFirst("div.badge-animated-container-animated").isNull()) {
            gag.setIsGIF(true);
            gag.setImageUrl(postContainer.findFirst("img.badge-item-img").attribute("src"));
            gag.setGifImageUrl(postContainer.findFirst("div.badge-animated-container-animated").attribute("data-image"));
        } else if (postContainer.hasClass("with-button")) {
            //not full pic, we'll need to go deeper for the full lenght image
            const QUrl regularImgUrl = postContainer.findFirst("img.badge-item-img").attribute("src");
            const QUrl imgUrl = QString("%1/photo/%2_700b.jpg").arg(regularImgUrl.toString(QUrl::RemovePath)).arg(gag.id());

            Q_ASSERT(imgUrl.isValid());

            gag.setFullImageUrl(imgUrl);
            gag.setImageUrl(regularImgUrl);
            gag.setIsPartialImage(true);
        } else {
            gag.setImageUrl(postContainer.findFirst("img.badge-item-img").attribute("src"));
        }

        gagList.append(gag);
    }