aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-04-23 11:22:02 +0300
committeraqua <aqua@iserlohn-fortress.net>2024-04-23 11:38:55 +0300
commit3f72c39fb0e95d45d15bde64661040e920574a85 (patch)
tree49bde891396d92ecd61c3d833e071c897f1eabe2 /lib
parentFix compile error with meson unstable-kconfig module (diff)
downloadsmolbote-3f72c39fb0e95d45d15bde64661040e920574a85.tar.xz
Ported to qt6
Diffstat (limited to 'lib')
-rw-r--r--lib/bookmarks/formats/ffjson.cpp7
-rw-r--r--lib/bookmarks/formats/xbel.cpp17
-rw-r--r--lib/downloads/downloadswidget.cpp2
-rw-r--r--lib/downloads/downloadswidget.h4
-rw-r--r--lib/downloads/widgets/downloaditemwidget.cpp27
-rw-r--r--lib/downloads/widgets/downloaditemwidget.h10
6 files changed, 36 insertions, 31 deletions
diff --git a/lib/bookmarks/formats/ffjson.cpp b/lib/bookmarks/formats/ffjson.cpp
index f9e0866..f95d0d8 100644
--- a/lib/bookmarks/formats/ffjson.cpp
+++ b/lib/bookmarks/formats/ffjson.cpp
@@ -8,11 +8,12 @@
#include "ffjson.h"
#include "bookmarkitem.h"
+#include <QDateTime>
+#include <QDebug>
+#include <QIODevice>
+#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
-#include <QJsonArray>
-#include <QDebug>
-#include <QDateTime>
inline auto asDate(const QJsonValue &v)
{
diff --git a/lib/bookmarks/formats/xbel.cpp b/lib/bookmarks/formats/xbel.cpp
index 7ff79a9..a0a553f 100644
--- a/lib/bookmarks/formats/xbel.cpp
+++ b/lib/bookmarks/formats/xbel.cpp
@@ -15,28 +15,28 @@
inline void readChildElements(QXmlStreamReader &reader, BookmarkItem *parent)
{
while(reader.readNextStartElement()) {
- if(reader.name() == "title") {
+ if(reader.name() == QLatin1String("title")) {
parent->setData(BookmarkItem::Title, reader.readElementText());
- } else if(reader.name() == "dateAdded") {
+ } else if(reader.name() == QLatin1String("dateAdded")) {
parent->setData(BookmarkItem::DateAdded, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date));
- } else if(reader.name() == "lastModified") {
+ } else if(reader.name() == QLatin1String("lastModified")) {
parent->setData(BookmarkItem::LastModified, QDateTime::fromString(reader.readElementText(), Qt::RFC2822Date));
- } else if(reader.name() == "tags") {
+ } else if(reader.name() == QLatin1String("tags")) {
parent->setData(BookmarkItem::Tags, reader.readElementText().split(";"));
- } else if(reader.name() == "description") {
+ } else if(reader.name() == QLatin1String("description")) {
parent->setData(BookmarkItem::Description, reader.readElementText());
- } else if(reader.name() == "folder") {
+ } else if(reader.name() == QLatin1String("folder")) {
auto *item = new BookmarkItem({}, BookmarkItem::Folder, parent);
item->setExpanded(!(reader.attributes().value("folded") == QLatin1String("yes")));
parent->appendChild(item);
readChildElements(reader, item);
- } else if(reader.name() == "bookmark") {
+ } else if(reader.name() == QLatin1String("bookmark")) {
auto *item = new BookmarkItem({}, BookmarkItem::Bookmark, parent);
item->setData(BookmarkItem::Href, reader.attributes().value("href").toString());
parent->appendChild(item);
@@ -53,7 +53,8 @@ void Xbel::read(QIODevice *device, BookmarkItem *item)
QXmlStreamReader qXmlStreamReader(device);
if(qXmlStreamReader.readNextStartElement()) {
- if(!(qXmlStreamReader.name() == "xbel" && qXmlStreamReader.attributes().value("version") == "1.0")) {
+ if(!(qXmlStreamReader.name() == QLatin1String("xbel")
+ && qXmlStreamReader.attributes().value("version") == QLatin1String("1.0"))) {
return;
}
diff --git a/lib/downloads/downloadswidget.cpp b/lib/downloads/downloadswidget.cpp
index 02ed08a..2f192e9 100644
--- a/lib/downloads/downloadswidget.cpp
+++ b/lib/downloads/downloadswidget.cpp
@@ -28,7 +28,7 @@ DownloadsWidget::~DownloadsWidget()
delete ui;
}
-void DownloadsWidget::addDownload(QWebEngineDownloadItem *item)
+void DownloadsWidget::addDownload(QWebEngineDownloadRequest *item)
{
const QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), m_downloadPath + "/" + item->downloadFileName());
diff --git a/lib/downloads/downloadswidget.h b/lib/downloads/downloadswidget.h
index eb4ce57..d0aa2b4 100644
--- a/lib/downloads/downloadswidget.h
+++ b/lib/downloads/downloadswidget.h
@@ -10,7 +10,7 @@
#define SMOLBOTE_DOWNLOADDIALOG_H
#include <QDialog>
-#include <QWebEngineDownloadItem>
+#include <QWebEngineDownloadRequest>
namespace Ui
{
@@ -26,7 +26,7 @@ public:
~DownloadsWidget() override;
public slots:
- void addDownload(QWebEngineDownloadItem *item);
+ void addDownload(QWebEngineDownloadRequest *item);
private:
Ui::DownloadDialog *ui;
diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp
index e0c8a60..169ba6f 100644
--- a/lib/downloads/widgets/downloaditemwidget.cpp
+++ b/lib/downloads/widgets/downloaditemwidget.cpp
@@ -30,7 +30,7 @@ inline QString sizeString(qint64 size)
return QString("%1 GB").arg(size / (1024 * 1024 * 1024));
}
-DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *parent)
+DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadRequest *m_item, QWidget *parent)
: QWidget(parent)
, ui(new Ui::DownloadItemForm)
{
@@ -51,11 +51,11 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *
ui->path_label->setText(QString("%1<br>%2").arg(item->downloadDirectory(), item->downloadFileName()));
this->updateState(item->state());
- connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState);
- connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress);
- connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished);
+ connect(item, &QWebEngineDownloadRequest::stateChanged, this, &DownloadItemWidget::updateState);
+ connect(item, &QWebEngineDownloadRequest::receivedBytesChanged, this, &DownloadItemWidget::updateProgress);
+ connect(item, &QWebEngineDownloadRequest::isFinishedChanged, this, &DownloadItemWidget::updateFinished);
- connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadItem::cancel);
+ connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadRequest::cancel);
connect(ui->pause_toolButton, &QToolButton::clicked, item, [m_item](bool clicked) {
clicked ? m_item->pause() : m_item->resume();
});
@@ -69,34 +69,34 @@ DownloadItemWidget::~DownloadItemWidget()
delete ui;
}
-void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state)
+void DownloadItemWidget::updateState(QWebEngineDownloadRequest::DownloadState state)
{
switch(state) {
- case QWebEngineDownloadItem::DownloadRequested:
+ case QWebEngineDownloadRequest::DownloadRequested:
ui->status_label->setText(tr("Requested"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadInProgress:
+ case QWebEngineDownloadRequest::DownloadInProgress:
ui->status_label->setText(tr("In progress"));
ui->pause_toolButton->setEnabled(true);
ui->abort_toolButton->setEnabled(true);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadCompleted:
+ case QWebEngineDownloadRequest::DownloadCompleted:
ui->status_label->setText(tr("Completed"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
ui->open_toolButton->setEnabled(true);
break;
- case QWebEngineDownloadItem::DownloadCancelled:
+ case QWebEngineDownloadRequest::DownloadCancelled:
ui->status_label->setText(tr("Cancelled"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
ui->open_toolButton->setEnabled(false);
break;
- case QWebEngineDownloadItem::DownloadInterrupted:
+ case QWebEngineDownloadRequest::DownloadInterrupted:
ui->status_label->setText(tr("Interrupted"));
ui->pause_toolButton->setEnabled(false);
ui->abort_toolButton->setEnabled(false);
@@ -107,8 +107,11 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state
}
}
-void DownloadItemWidget::updateProgress(qint64 value, qint64 total)
+void DownloadItemWidget::updateProgress()
{
+ const auto value = item->receivedBytes();
+ const auto total = item->totalBytes();
+
ui->progressBar->setValue(static_cast<int>((static_cast<long double>(value) / static_cast<long double>(total)) * 100));
ui->progressBar->setFormat(QString("%1 / %2").arg(sizeString(value), sizeString(total)));
}
diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h
index a1de175..5d540a3 100644
--- a/lib/downloads/widgets/downloaditemwidget.h
+++ b/lib/downloads/widgets/downloaditemwidget.h
@@ -9,7 +9,7 @@
#ifndef SMOLBOTE_DOWNLOADITEMFORM_H
#define SMOLBOTE_DOWNLOADITEMFORM_H
-#include <QWebEngineDownloadItem>
+#include <QWebEngineDownloadRequest>
#include <QWidget>
namespace Ui
@@ -22,17 +22,17 @@ class DownloadItemWidget : public QWidget
Q_OBJECT
public:
- explicit DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *parent = 0);
+ explicit DownloadItemWidget(QWebEngineDownloadRequest *m_item, QWidget *parent = 0);
~DownloadItemWidget() override;
private slots:
- void updateState(QWebEngineDownloadItem::DownloadState state);
- void updateProgress(qint64 value, qint64 total);
+ void updateState(QWebEngineDownloadRequest::DownloadState state);
+ void updateProgress();
void updateFinished();
private:
Ui::DownloadItemForm *ui;
- QWebEngineDownloadItem *item = nullptr;
+ QWebEngineDownloadRequest *item = nullptr;
};
#endif // SMOLBOTE_DOWNLOADITEMFORM_H