Falkon Develop
Cross-platform Qt-based web browser
siteinfowidget.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qztools.h"
19#include "siteinfowidget.h"
20#include "ui_siteinfowidget.h"
21#include "browserwindow.h"
22#include "mainapplication.h"
23#include "webpage.h"
24#include "tabbedwebview.h"
25#include "sqldatabase.h"
27
28#include <QToolTip>
29
31 : LocationBarPopup(parent)
32 , ui(new Ui::SiteInfoWidget)
33 , m_window(window)
34{
35 this->setAttribute(Qt::WA_DeleteOnClose);
36 ui->setupUi(this);
37
38 setPopupAlignment(Qt::AlignLeft);
39
40 WebView* view = m_window->weView();
41
42 ui->titleLabel->setText(tr("<b>Site %1<b/>").arg(view->url().host()));
43
44 if (view->url().scheme() == QL1S("https")) {
45 ui->secureLabel->setText(tr("Your connection to this site is <b>secured</b>."));
46 ui->secureIcon->setPixmap(QPixmap(QSL(":/icons/locationbar/safe.png")));
47 }
48 else {
49 ui->secureLabel->setText(tr("Your connection to this site is <b>unsecured</b>."));
50 ui->secureIcon->setPixmap(QPixmap(QSL(":/icons/locationbar/unsafe.png")));
51 }
52
53 QString scheme = view->url().scheme();
54 QString host = view->url().host();
55
56 QSqlQuery query(SqlDatabase::instance()->database());
57 query.prepare(QSL("SELECT sum(count) FROM history WHERE url LIKE ?"));
58 query.addBindValue(QSL("%1://%2%").arg(scheme, host));
59 query.exec();
60
61 if (query.next()) {
62 int count = query.value(0).toInt();
63 if (count > 3) {
64 ui->historyLabel->setText(tr("This is your <b>%1</b> visit of this site.").arg(QString::number(count) + QLatin1Char('.')));
65 ui->historyIcon->setPixmap(QPixmap(QSL(":/icons/locationbar/visit3.png")));
66 }
67 else if (count == 0) {
68 ui->historyLabel->setText(tr("You have <b>never</b> visited this site before."));
69 ui->historyIcon->setPixmap(QPixmap(QSL(":/icons/locationbar/visit1.png")));
70 }
71 else {
72 ui->historyIcon->setPixmap(QPixmap(QSL(":/icons/locationbar/visit2.png")));
73 QString text;
74 if (count == 1) {
75 text = tr("first");
76 }
77 else if (count == 2) {
78 text = tr("second");
79 }
80 else if (count == 3) {
81 text = tr("third");
82 }
83 ui->historyLabel->setText(tr("This is your <b>%1</b> visit of this site.").arg(text));
84 }
85 }
86
87 updateProtocolHandler();
88
89 connect(ui->pushButton, &QAbstractButton::clicked, m_window->action(QSL("Tools/SiteInfo")), &QAction::trigger);
90 connect(ui->protocolHandlerButton, &QPushButton::clicked, this, &SiteInfoWidget::protocolHandlerButtonClicked);
91}
92
94{
95 delete ui;
96}
97
98void SiteInfoWidget::updateProtocolHandler()
99{
100 WebPage *page = m_window->weView()->page();
101
102 const QString scheme = page->registerProtocolHandlerRequestScheme();
103 const QUrl registeredUrl = mApp->protocolHandlerManager()->protocolHandlers().value(scheme);
104
105 if (!scheme.isEmpty() && registeredUrl != page->registerProtocolHandlerRequestUrl()) {
106 ui->protocolHandlerLabel->setText(tr("Register as <b>%1</b> links handler").arg(page->registerProtocolHandlerRequestScheme()));
107 ui->protocolHandlerButton->setText(tr("Register"));
108 } else {
109 ui->protocolHandlerLabel->hide();
110 ui->protocolHandlerButton->hide();
111 ui->protocolHandlerLine->hide();
112 }
113}
114
115void SiteInfoWidget::protocolHandlerButtonClicked()
116{
117 WebPage *page = m_window->weView()->page();
118
119 mApp->protocolHandlerManager()->addProtocolHandler(page->registerProtocolHandlerRequestScheme(), page->registerProtocolHandlerRequestUrl());
120 close();
121}
QAction * action(const QString &name) const
TabbedWebView * weView() const
void setPopupAlignment(Qt::Alignment alignment)
SiteInfoWidget(BrowserWindow *window, QWidget *parent=nullptr)
static SqlDatabase * instance()
QString registerProtocolHandlerRequestScheme() const
Definition: webpage.cpp:542
QUrl registerProtocolHandlerRequestUrl() const
Definition: webpage.cpp:534
WebPage * page() const
Definition: webview.cpp:132
#define mApp
#define QL1S(x)
Definition: qzcommon.h:44
#define QSL(x)
Definition: qzcommon.h:40