File: alkwebviewwidgettest.cpp

package info (click to toggle)
alkimia 8.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,796 kB
  • sloc: cpp: 10,563; sh: 563; python: 212; php: 105; perl: 69; xml: 12; makefile: 10
file content (104 lines) | stat: -rw-r--r-- 2,820 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
    SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de

    This file is part of libalkimia.

    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "alkwebview.h"
#include "alktestdefs.h"

#include <QApplication>
#include <QDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>

class AlkWebViewTestDialog : public QDialog
{
    Q_OBJECT
public:
    AlkWebView *view;
    QLineEdit *urlEdit;
    QLabel *startedLabel;
    QLabel *finishedLabel;
    QLabel *redirectedLabel;

    AlkWebViewTestDialog()
    {
#ifdef BUILD_WITH_WEBENGINE
        AlkWebView::setWebInspectorEnabled(true);
#endif
        view = new AlkWebView;
#ifdef BUILD_WITH_WEBKIT
        view->setWebInspectorEnabled(true);
#endif

        QGridLayout *layout = new QGridLayout;
        urlEdit = new QLineEdit;
        QPushButton *pushButton = new QPushButton("Load url");
        startedLabel = new QLabel;
        finishedLabel = new QLabel;
        redirectedLabel = new QLabel;
        connect(view, SIGNAL(loadRedirectedTo(QUrl)), this, SLOT(slotRedirectedTo(QUrl)));
        connect(view, SIGNAL(loadStarted()), this, SLOT(slotStarted()));
        connect(view, SIGNAL(loadFinished(bool)), this, SLOT(slotFinished(bool)));
        connect(pushButton, SIGNAL(pressed()), this, SLOT(slotPressed()));
        layout->addWidget(urlEdit, 0, 0, 1, 4);
        layout->addWidget(pushButton, 0, 5);
        layout->addWidget(view, 1, 0, 4, 4);
        layout->addWidget(new QLabel("Signals"), 1, 5, 1, 2);
        layout->addWidget(new QLabel("started:"), 2, 5);
        layout->addWidget(startedLabel, 2, 6);
        layout->addWidget(new QLabel("finished:"), 3, 5);
        layout->addWidget(finishedLabel, 3, 6);
        layout->addWidget(new QLabel("redirected:"), 4, 5);
        layout->addWidget(redirectedLabel, 4, 6);
        setLayout(layout);
        QString url = QLatin1String(TEST_DOWNLOAD_URL_CURRENCY) + "&redirect=1";
        urlEdit->setText(url);
        view->load(url);
    }

public Q_SLOTS:
    void slotPressed()
    {
        QUrl url(urlEdit->text());
        startedLabel->setText("");
        finishedLabel->setText("");
        redirectedLabel->setText("");
        if (url.isValid())
            view->load(url);
    }

    void slotStarted()
    {
        startedLabel->setText("ok");
    }

    void slotRedirectedTo(const QUrl &url)
    {
        if (url.isValid()) {
            redirectedLabel->setText("ok");
            urlEdit->setText(url.toString());
        }
    }

    void slotFinished(bool ok)
    {
        finishedLabel->setText(ok ? "ok" : "failed");
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    AlkWebViewTestDialog dialog;
    dialog.show();
    app.exec();
}

#include "alkwebviewwidgettest.moc"