Exemple #1
0
void HistoryForm::onTick01()
{
    if (this->CurrentEdit == nullptr)
        throw new Huggle::NullPointerException("local WikiEdit CurrentEdit", BOOST_CURRENT_FUNCTION);

    if (this->RetrievingEdit && this->RetrievedEdit != nullptr)
    {
        if (this->RetrievedEdit->IsPostProcessed())
        {
            MainWindow::HuggleMain->ProcessEdit(this->RetrievedEdit, false, true);
            this->RetrievingEdit = false;
            this->RetrievedEdit = nullptr;
            this->t1->stop();
            this->MakeSelectedRowBold();
            MainWindow::HuggleMain->wEditBar->RefreshPage();
        }
        return;
    }

    if (this->query == nullptr || !this->query->IsProcessed())
        return;

    if (this->query->IsFailed())
    {
        this->ui->pushButton->setEnabled(true);
        Huggle::Syslog::HuggleLogs->ErrorLog(_l("history-failure"));
        this->query = nullptr;
        this->t1->stop();
        return;
    }
    bool IsLatest = false;
    QList<ApiQueryResultNode*> revision_data = this->query->GetApiQueryResult()->GetNodes("rev");
    int x = 0;
    while (x < revision_data.count())
    {
        ApiQueryResultNode *rv = revision_data.at(x);
        WikiPageHistoryItem *item = new WikiPageHistoryItem(this->query->GetSite());
        if (rv->Attributes.contains("revid"))
        {
            item->RevID = rv->GetAttribute("revid");
        }
        else
        {
            x++;
            continue;
        }
        bool founder = false;
        item->Name = this->CurrentEdit->Page->PageName;
        item->Site = this->CurrentEdit->GetSite();
        if (rv->Attributes.contains("user"))
            item->User = rv->GetAttribute("user");
        if (rv->Attributes.contains("size"))
            item->Size = rv->GetAttribute("size");
        if (rv->Attributes.contains("timestamp"))
            item->Date = rv->GetAttribute("timestamp");
        if (rv->Attributes.contains("comment") && !rv->GetAttribute("comment").isEmpty())
            item->Summary = rv->GetAttribute("comment");
        this->ui->tableWidget->insertRow(x);
        QIcon icon(":/huggle/pictures/Resources/blob-none.png");
        if (this->CurrentEdit->Page->FounderKnown() && WikiUser::CompareUsernames(item->User, this->CurrentEdit->Page->GetFounder()))
            founder = true;
        if (WikiUtil::IsRevert(item->Summary))
        {
            item->Type = EditType_Revert;
            icon = QIcon(":/huggle/pictures/Resources/blob-revert.png");
        }
        else if (WikiUser::IsIPv6(item->User) || WikiUser::IsIPv4(item->User))
        {
            item->Type = EditType_Anon;
            icon = QIcon(":/huggle/pictures/Resources/blob-anon.png");
        }
        else if (this->CurrentEdit->GetSite()->GetProjectConfig()->WhiteList.contains(item->User))
        {
            item->Type = EditType_W;
            icon = QIcon(":/huggle/pictures/Resources/blob-ignored.png");
        }
        WikiUser *wu = WikiUser::RetrieveUser(item->User, item->Site);
        if (wu != nullptr)
        {
            if (wu->IsReported)
            {
                item->Type = EditType_Reported;
                icon = QIcon(":/huggle/pictures/Resources/blob-reported.png");
            }
            else if (wu->GetWarningLevel() > 0)
            {
                switch (wu->GetWarningLevel())
                {
                case 1:
                    item->Type = EditType_1;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-1.png");
                    break;
                case 2:
                    item->Type = EditType_2;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-2.png");
                    break;
                case 3:
                    item->Type = EditType_3;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-3.png");
                    break;
                case 4:
                    item->Type = EditType_4;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-4.png");
                    break;
                }
            }
        }
        bool selected = this->CurrentEdit->RevID == item->RevID.toInt();
        if (selected && x == 0)
            IsLatest = true;
        item->IsCurrent = true;
        if (selected)
            this->SelectedRow = x;
        QFont font;
        font.setItalic(founder);
        font.setBold(selected);
        QTableWidgetItem *i = new QTableWidgetItem(icon, "");
        this->ui->tableWidget->setItem(x, 0, i);
        i = new QTableWidgetItem(item->User);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 1, i);
        i = new QTableWidgetItem(item->Size);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 2, i);
        i = new QTableWidgetItem(item->Summary);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 3, i);
        i = new QTableWidgetItem(item->Date);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 4, i);
        i = new QTableWidgetItem(item->RevID);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 5, i);
        this->Items.append(item);
        x++;
    }
    this->ui->tableWidget->resizeRowsToContents();
    this->query = nullptr;
    this->t1->stop();
    if (!this->CurrentEdit->NewPage && !Configuration::HuggleConfiguration->ForceNoEditJump && !IsLatest)
    {
        if (Configuration::HuggleConfiguration->UserConfig->LastEdit)
        {
            this->Display(0, Resources::Html_StopFire, true);
            return;
        }
        else
        {
            QPoint pntr(0, this->pos().y());
            if (this->pos().x() > 400)
                pntr.setX(this->pos().x() - 200);
            else
                pntr.setX(this->pos().x() + 100);

            if (hcfg->UserConfig->ShowWarningIfNotOnLastRevision)
                QToolTip::showText(pntr, "<b><big>" + _l("historyform-not-latest-tip") + "</big></b>", this);
        }
    }
    if (hcfg->UserConfig->AutomaticallyGroup)
    {
        // Check if edits made around of this one weren't made by same user
        // in case they were we need to display a range of them
        QString user = this->CurrentEdit->User->Username;
        int RangeStart = this->SelectedRow;
        int RangeEnd = this->SelectedRow;
        int row = this->SelectedRow;
        while (row > 0)
        {
            if (user != this->ui->tableWidget->item(row - 1, 1)->text())
                break;
            row--;
        }
        RangeStart = row;
        row = this->SelectedRow;
        while (row < (this->ui->tableWidget->rowCount() - 1))
        {
            if (user != this->ui->tableWidget->item(row + 1, 1)->text())
                break;
            row++;
        }
        RangeEnd = row;
        if (RangeStart != RangeEnd)
        {
            QItemSelectionModel *selectionModel = this->ui->tableWidget->selectionModel();
            row = RangeStart;
            this->IgnoreSelectionChanges = true;
            this->ui->tableWidget->clearSelection();
            QItemSelection itemSelection = selectionModel->selection();
            while (row <= RangeEnd)
            {
                this->ui->tableWidget->selectRow(row++);
                itemSelection.merge(selectionModel->selection(), QItemSelectionModel::Select);
            }
            selectionModel->clearSelection();
            this->IgnoreSelectionChanges = false;
            selectionModel->select(itemSelection, QItemSelectionModel::Select);
        }
    }
    this->IgnoreSelectionChanges = false;
    MainWindow::HuggleMain->wEditBar->RefreshPage();
}
void HistoryForm::onTick01()
{
    if (this->CurrentEdit == nullptr)
        throw new Huggle::NullPointerException("local WikiEdit CurrentEdit", BOOST_CURRENT_FUNCTION);

    if (this->RetrievingEdit && this->RetrievedEdit != nullptr)
    {
        if (this->RetrievedEdit->IsPostProcessed())
        {
            MainWindow::HuggleMain->ProcessEdit(this->RetrievedEdit, false, true);
            this->RetrievingEdit = false;
            this->RetrievedEdit = nullptr;
            this->t1->stop();
            this->MakeSelectedRowBold();
            MainWindow::HuggleMain->wEditBar->RefreshPage();
        }
        return;
    }

    if (this->query == nullptr || !this->query->IsProcessed())
        return;

    if (this->query->IsFailed())
    {
        this->ui->pushButton->setEnabled(true);
        Huggle::Syslog::HuggleLogs->ErrorLog(_l("history-failure"));
        this->query = nullptr;
        this->t1->stop();
        return;
    }
    bool IsLatest = false;
    QList<ApiQueryResultNode*>revision_data = this->query->GetApiQueryResult()->GetNodes("rev");
    int x=0;
    QColor xb;
    bool xt = false;
    while (x < revision_data.count())
    {
        if (xt)
        {
            xb = QColor(206, 202, 250);
        } else
        {
            xb = QColor(224, 222, 250);
        }
        xt = !xt;
        ApiQueryResultNode *rv = revision_data.at(x);
        WikiPageHistoryItem *item = new WikiPageHistoryItem();
        if (rv->Attributes.contains("revid"))
        {
            item->RevID = rv->GetAttribute("revid");
        } else
        {
            x++;
            continue;
        }
        item->Name = this->CurrentEdit->Page->PageName;
        item->Site = this->CurrentEdit->GetSite();
        if (rv->Attributes.contains("user"))
            item->User = rv->GetAttribute("user");
        if (rv->Attributes.contains("size"))
            item->Size = rv->GetAttribute("size");
        if (rv->Attributes.contains("timestamp"))
            item->Date = rv->GetAttribute("timestamp");
        if (rv->Attributes.contains("comment") && !rv->GetAttribute("comment").isEmpty())
            item->Summary = rv->GetAttribute("comment");
        this->ui->tableWidget->insertRow(x);
        QIcon icon(":/huggle/pictures/Resources/blob-none.png");
        if (WikiUtil::IsRevert(item->Summary))
        {
            item->Type = EditType_Revert;
            icon = QIcon(":/huggle/pictures/Resources/blob-revert.png");
        }
        else if (WikiUser::IsIPv6(item->User) || WikiUser::IsIPv4(item->User))
        {
            item->Type = EditType_Anon;
            icon = QIcon(":/huggle/pictures/Resources/blob-anon.png");
        }
        else if (this->CurrentEdit->GetSite()->GetProjectConfig()->WhiteList.contains(item->User))
        {
            item->Type = EditType_W;
            icon = QIcon(":/huggle/pictures/Resources/blob-ignored.png");
        }
        WikiUser *wu = WikiUser::RetrieveUser(item->User, item->Site);
        if (wu != nullptr)
        {
            if (wu->IsReported)
            {
                item->Type = EditType_Reported;
                icon = QIcon(":/huggle/pictures/Resources/blob-reported.png");
            } else if (wu->GetWarningLevel() > 0)
            {
                switch(wu->GetWarningLevel())
                {
                    case 1:
                        item->Type = EditType_1;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-1.png");
                        break;
                    case 2:
                        item->Type = EditType_2;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-2.png");
                        break;
                    case 3:
                        item->Type = EditType_3;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-3.png");
                        break;
                    case 4:
                        item->Type = EditType_4;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-4.png");
                        break;
                }
            }
        }
        if (this->CurrentEdit->RevID == item->RevID.toInt())
        {
            if (x == 0)
                IsLatest = true;
            item->IsCurrent = true;
            this->SelectedRow = x;
            QFont font;
            font.setBold(true);
            QTableWidgetItem *i = new QTableWidgetItem(icon, "");
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 0, i);
            i = new QTableWidgetItem(item->User);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 1, i);
            i = new QTableWidgetItem(item->Size);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 2, i);
            i = new QTableWidgetItem(item->Summary);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 3, i);
            i = new QTableWidgetItem(item->RevID);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 4, i);
            i = new QTableWidgetItem(item->Date);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 5, i);
        } else
        {
            QTableWidgetItem *i = new QTableWidgetItem(icon, "");
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 0, i);
            i = new QTableWidgetItem(item->User);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 1, i);
            i = new QTableWidgetItem(item->Size);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 2, i);
            i = new QTableWidgetItem(item->Summary);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 3, i);
            i = new QTableWidgetItem(item->RevID);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 4, i);
            i = new QTableWidgetItem(item->Date);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 5, i);
        }
        this->Items.append(item);
        x++;
    }
    this->ui->tableWidget->resizeRowsToContents();
    this->query = nullptr;
    this->t1->stop();
    if (!this->CurrentEdit->NewPage && !Configuration::HuggleConfiguration->ForcedNoEditJump && !IsLatest)
    {
        if (Configuration::HuggleConfiguration->UserConfig->LastEdit)
        {
            this->Display(0, Resources::Html_StopFire, true);
        } else
        {
            QPoint pntr(0, this->pos().y());
            if (this->pos().x() > 400)
                pntr.setX(this->pos().x() - 200);
            else
                pntr.setX(this->pos().x() + 100);

            // display a tip
            QToolTip::showText(pntr, "<b><big>" + _l("historyform-not-latest-tip") + "</big></b>", this);
        }
    }
    MainWindow::HuggleMain->wEditBar->RefreshPage();
}