summaryrefslogtreecommitdiffstatshomepage
path: root/tests/t0104-tree.sh
blob: 2ce1251cbf56d06cc0f940cb36bd18b4537c78ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

. ./setup.sh

prepare_tests "Check content on tree page"

run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
run_test 'find file-1' 'grep -e "file-1" trash/tmp'
run_test 'find file-50' 'grep -e "file-50" trash/tmp'

run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'

run_test 'find line 1' '
	grep -e "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
'

run_test 'no line 2' '
	! grep -e "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
'

run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'

run_test 'verify a+b link' '
	grep -e "/foo+bar/tree/a+b" trash/tmp
'

run_test 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >trash/tmp'

run_test 'verify a+b?h=1+2 link' '
	grep -e "/foo+bar/tree/a+b?h=1%2b2" trash/tmp
'

tests_done
si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "src/archive_parser.h"
#include "src/list_item.h"

#include <QFileDialog>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actionOpen_triggered(bool checked) {
    QFileDialog fileDialog;
    fileDialog.setFileMode(QFileDialog::AnyFile);
    fileDialog.setNameFilter(tr("Mastodon data export directory (outbox.json)"));
    if (fileDialog.exec()) {
        QStringList files = fileDialog.selectedFiles();
        outbox_filename = files[0];
        ui->statusInfoText->setText(outbox_filename);
    }

    if (data_archive) {
        delete data_archive;
        data_archive = nullptr;
    }

    // TODO: Do this in another thread
    QApplication::setOverrideCursor(Qt::WaitCursor);
    data_archive = new Archive(outbox_filename, ArchiveType::MASTODON);
    auto parse_error = data_archive->init();

    switch (parse_error) {
        case Archive::FailedOpeningFile:
            QMessageBox::warning(this, tr("Archive Parser"), tr("Failed opening file.")); break;
        case Archive::JsonParseError:
            QMessageBox::warning(this, tr("Archive Parser"), tr("Failed parsing outbox JSON.")); break;
        case Archive::JsonEmpty:
        case Archive::JsonNull:
        case Archive::JsonNotObject:
        case Archive::JsonNotActivityStream:
            QMessageBox::warning(this, tr("Archive Parser"), tr("The outbox JSON is empty or invalid in another way. Not an outbox.json?")); break;
        case Archive::NoError:
            break;
    }

    ui->listWidget->clear();

    if (parse_error == Archive::NoError) {
        data_archive->update_status_list(view_filters, ui->listWidget);
    }

    QApplication::restoreOverrideCursor();
}

void MainWindow::on_actionQuit_triggered(bool checked) {
    QCoreApplication::quit();
}

void MainWindow::on_actionAbout_triggered(bool checked) {
    QMessageBox::information(this, "title", "text");
}

void MainWindow::on_listWidget_itemActivated(QListWidgetItem *item) {
    ListItem* casted = dynamic_cast<ListItem*>(item);
    if (casted != nullptr) { // this is always a nullptr, but it should work?? https://cplusplus.com/forum/beginner/78766/
        QString status_info = data_archive->get_html_status_info(casted->get_status_index());
        ui->statusInfoText->setHtml(status_info);
    }
}

void MainWindow::relist_statuses() {
    if (data_archive) {
        ui->listWidget->clear();
        data_archive->update_status_list(view_filters, ui->listWidget);
        view_filters_changed = false;
    }
}

void MainWindow::reset_view_filters() {
    if (ui->actionAll_toots->isChecked())
        view_filters = {true, true, true, true, view_filters.onlyWithAttachment};
    else
        view_filters = {false, false, false, false, view_filters.onlyWithAttachment};
}

void MainWindow::on_actionAll_toots_triggered(bool checked) {
    ui->actionAll_toots->setChecked(true);
    ui->actionPublic_toots->setChecked(false);
    ui->actionUnlisted_toots->setChecked(false);
    ui->actionPrivate_toots->setChecked(false);
    ui->actionDirect_messages->setChecked(false);
    ui->actionOnly_with_attachment->setChecked(false);

    reset_view_filters();
    relist_statuses();
}

void MainWindow::on_actionPublic_toots_triggered(bool checked) {
    if (ui->actionAll_toots->isChecked()) {
        ui->actionAll_toots->setChecked(false);
        reset_view_filters();
    }
    view_filters.includePublic = checked;
    view_filters_changed = true;
}

void MainWindow::on_actionUnlisted_toots_triggered(bool checked) {
    if (ui->actionAll_toots->isChecked()) {
        ui->actionAll_toots->setChecked(false);
        reset_view_filters();
    }
    view_filters.includeUnlisted = checked;
    view_filters_changed = true;
}

void MainWindow::on_actionPrivate_toots_triggered(bool checked) {
    if (ui->actionAll_toots->isChecked()) {
        ui->actionAll_toots->setChecked(false);
        reset_view_filters();
    }
    view_filters.includePrivate = checked;
    view_filters_changed = true;
}

void MainWindow::on_actionDirect_messages_triggered(bool checked) {
    if (ui->actionAll_toots->isChecked()) {
        ui->actionAll_toots->setChecked(false);
        reset_view_filters();
    }
    view_filters.includeDirect = checked;
    view_filters_changed = true;
}

void MainWindow::on_actionOnly_with_attachment_triggered(bool checked) {
    view_filters.onlyWithAttachment = checked;
    view_filters_changed = true;
}

void MainWindow::on_menuView_aboutToHide() {
    if (view_filters_changed)
        relist_statuses();
}