From 442ba9f09a8ee18609361f3971b5da7f40eb5c35 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 10 Oct 2017 19:25:44 +0200 Subject: Split off DownloadsWidget into library Fixed bug with BookmarksWidget crashing the program on exit --- src/browser.cpp | 16 +--- src/browser.h | 7 +- src/forms/downloadsform.ui | 81 ------------------ src/forms/downloadswidget.cpp | 79 ------------------ src/forms/downloadswidget.h | 49 ----------- src/lib/bookmarks/bookmarkswidget.cpp | 9 +- src/lib/bookmarks/bookmarkswidget.h | 5 +- src/lib/downloads/downloads.qbs | 27 ++++++ src/lib/downloads/downloadsform.ui | 81 ++++++++++++++++++ src/lib/downloads/downloadswidget.cpp | 86 +++++++++++++++++++ src/lib/downloads/downloadswidget.h | 50 +++++++++++ src/lib/downloads/widgets/downloaditemform.ui | 53 ++++++++++++ src/lib/downloads/widgets/downloaditemwidget.cpp | 102 +++++++++++++++++++++++ src/lib/downloads/widgets/downloaditemwidget.h | 52 ++++++++++++ src/mainwindow.cpp | 11 ++- src/mainwindow.h | 2 +- src/widgets/dockingwidget.cpp | 82 ------------------ src/widgets/dockingwidget.h | 55 ------------ src/widgets/downloaditemform.ui | 53 ------------ src/widgets/downloaditemwidget.cpp | 102 ----------------------- src/widgets/downloaditemwidget.h | 52 ------------ src/widgets/mainwindowmenubar.cpp | 11 ++- 22 files changed, 485 insertions(+), 580 deletions(-) delete mode 100644 src/forms/downloadsform.ui delete mode 100644 src/forms/downloadswidget.cpp delete mode 100644 src/forms/downloadswidget.h create mode 100644 src/lib/downloads/downloads.qbs create mode 100644 src/lib/downloads/downloadsform.ui create mode 100644 src/lib/downloads/downloadswidget.cpp create mode 100644 src/lib/downloads/downloadswidget.h create mode 100644 src/lib/downloads/widgets/downloaditemform.ui create mode 100644 src/lib/downloads/widgets/downloaditemwidget.cpp create mode 100644 src/lib/downloads/widgets/downloaditemwidget.h delete mode 100644 src/widgets/dockingwidget.cpp delete mode 100644 src/widgets/dockingwidget.h delete mode 100644 src/widgets/downloaditemform.ui delete mode 100644 src/widgets/downloaditemwidget.cpp delete mode 100644 src/widgets/downloaditemwidget.h (limited to 'src') diff --git a/src/browser.cpp b/src/browser.cpp index c0289a6..14fee3e 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -42,14 +42,6 @@ Browser::~Browser() { qDeleteAll(m_windows); m_windows.clear(); - - if(m_bookmarksManager) { - delete m_bookmarksManager; - } - - if(m_downloadManager) { - delete m_downloadManager; - } } QString Browser::applicationLongVersion() const @@ -126,17 +118,17 @@ Settings *Browser::settings() BookmarksWidget *Browser::bookmarks() { if(!m_bookmarksManager) { - m_bookmarksManager = new BookmarksWidget(settings()->value("bookmarks.path").toString()); + m_bookmarksManager = QSharedPointer(new BookmarksWidget(settings()->value("bookmarks.path").toString()), &QObject::deleteLater); } - return m_bookmarksManager; + return m_bookmarksManager.data(); } DownloadsWidget *Browser::downloads() { if(!m_downloadManager) { - m_downloadManager = new DownloadsWidget(); + m_downloadManager = QSharedPointer(new DownloadsWidget(settings()->value("downloads.path").toString()), &QObject::deleteLater); } - return m_downloadManager; + return m_downloadManager.data(); } BlockerManager *Browser::blocklists() diff --git a/src/browser.h b/src/browser.h index 9fd0bdf..dedb933 100644 --- a/src/browser.h +++ b/src/browser.h @@ -23,7 +23,7 @@ #include "singleapplication.h" #include -#include "forms/downloadswidget.h" +#include #include "settings.h" #include "webengine/webengineprofile.h" @@ -31,6 +31,7 @@ #include "webengine/urlinterceptor.h" #include +#include #ifdef browser #undef browser @@ -80,8 +81,8 @@ private: QHash m_profiles; UrlRequestInterceptor *m_urlRequestInterceptor = nullptr; - BookmarksWidget *m_bookmarksManager = nullptr; - DownloadsWidget *m_downloadManager = nullptr; + QSharedPointer m_bookmarksManager; + QSharedPointer m_downloadManager; BlockerManager *m_blocklistManager = nullptr; QObject *m_plugin = nullptr; diff --git a/src/forms/downloadsform.ui b/src/forms/downloadsform.ui deleted file mode 100644 index 5ab770f..0000000 --- a/src/forms/downloadsform.ui +++ /dev/null @@ -1,81 +0,0 @@ - - - DownloadDialog - - - - 0 - 0 - 420 - 600 - - - - - 420 - 600 - - - - Downloads - - - - - - - - - Details - - - - - - Type - - - - - - - - - - - - - - Path - - - - - - - Size - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/forms/downloadswidget.cpp b/src/forms/downloadswidget.cpp deleted file mode 100644 index 008e371..0000000 --- a/src/forms/downloadswidget.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#include "downloadswidget.h" -#include "ui_downloadsform.h" - -#include -#include -#include -#include -#include -#include "widgets/downloaditemwidget.h" -#include "browser.h" - -DownloadsWidget::DownloadsWidget(QWidget *parent) : - DockingWidget(tr("Downloads"), parent), - ui(new Ui::DownloadDialog) -{ - ui->setupUi(this); - ui->filePath->setWordWrap(true); - - connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); -} - -DownloadsWidget::~DownloadsWidget() -{ - delete ui; -} - -void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) -{ - QString filepath = QFileDialog::getSaveFileName(this, - tr("Save"), - browser->settings()->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); - - if(filepath.isEmpty()) { - // user cancelled the save dialog - item->cancel(); - return; - } - - item->setPath(filepath); - - QListWidgetItem *listItem = new QListWidgetItem(); - int rowIndex = ui->listWidget->count(); - ui->listWidget->insertItem(rowIndex, listItem); - - DownloadItemWidget *form = new DownloadItemWidget(item, this); - listItem->setSizeHint(form->size()); - ui->listWidget->setItemWidget(listItem, form); - - item->accept(); - this->show(); -} - -void DownloadsWidget::showItemDetails(int index) -{ - DownloadItemWidget *form = qobject_cast(ui->listWidget->itemWidget(ui->listWidget->item(index))); - ui->mimeType_label->setText(form->item()->mimeType()); - ui->filePath_label->setText(form->item()->path()); - ui->fileSize_label->setText(QString("%1 bytes").arg(form->item()->totalBytes())); -} diff --git a/src/forms/downloadswidget.h b/src/forms/downloadswidget.h deleted file mode 100644 index fed3833..0000000 --- a/src/forms/downloadswidget.h +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#ifndef DOWNLOADDIALOG_H -#define DOWNLOADDIALOG_H - -#include "widgets/dockingwidget.h" - -namespace Ui { -class DownloadDialog; -} - -class QWebEngineDownloadItem; -class DownloadsWidget : public DockingWidget -{ - Q_OBJECT - -public: - explicit DownloadsWidget(QWidget *parent = 0); - ~DownloadsWidget(); - -public slots: - void addDownload(QWebEngineDownloadItem *item); - -private slots: - void showItemDetails(int index); - -private: - Ui::DownloadDialog *ui; -}; - -#endif // DOWNLOADDIALOG_H diff --git a/src/lib/bookmarks/bookmarkswidget.cpp b/src/lib/bookmarks/bookmarkswidget.cpp index 38716ce..f2781da 100644 --- a/src/lib/bookmarks/bookmarkswidget.cpp +++ b/src/lib/bookmarks/bookmarkswidget.cpp @@ -24,11 +24,12 @@ #include BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) : - DockingWidget(tr("Bookmarks"), parent), + QWidget(parent), ui(new Ui::BookmarksDialog) { // make sure this dialog does not get deleted on close setAttribute(Qt::WA_DeleteOnClose, false); + setWindowTitle(tr("Bookmarks")); ui->setupUi(this); ui->treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); @@ -49,13 +50,13 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) : xbel = new Xbel(ui->treeWidget); xbel->read(m_path); - connect(ui->addFolder_toolButton, &QToolButton::clicked, [this]() { + connect(ui->addFolder_toolButton, &QToolButton::clicked, this, [&]() { xbel->addFolder(ui->treeWidget->currentItem()); }); - connect(ui->addBookmark_toolButton, &QToolButton::clicked, [this]() { + connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [&]() { xbel->addBookmark(ui->treeWidget->currentItem()); }); - connect(ui->addSeparator_toolButton, &QToolButton::clicked, [this]() { + connect(ui->addSeparator_toolButton, &QToolButton::clicked, this, [&]() { xbel->addSeparator(ui->treeWidget->currentItem()); }); } diff --git a/src/lib/bookmarks/bookmarkswidget.h b/src/lib/bookmarks/bookmarkswidget.h index a31cfea..86f83be 100644 --- a/src/lib/bookmarks/bookmarkswidget.h +++ b/src/lib/bookmarks/bookmarkswidget.h @@ -21,15 +21,14 @@ #ifndef BOOKMARKSDIALOG_H #define BOOKMARKSDIALOG_H -#include "widgets/dockingwidget.h" -#include +#include #include "xbel.h" namespace Ui { class BookmarksDialog; } -class BookmarksWidget : public DockingWidget +class BookmarksWidget : public QWidget { Q_OBJECT diff --git a/src/lib/downloads/downloads.qbs b/src/lib/downloads/downloads.qbs new file mode 100644 index 0000000..121b425 --- /dev/null +++ b/src/lib/downloads/downloads.qbs @@ -0,0 +1,27 @@ +import qbs 1.0 + +Project { + name: "downloads" + + StaticLibrary { + id: downloads + name: "downloads" + + cpp.includePaths: ['../..'] + + Depends { + name: "Qt" + versionAtLeast: "5.9.0" + submodules: ["core", "widgets", "webenginewidgets"] + } + + files: [ + "downloadsform.ui", + "downloadswidget.cpp", + "downloadswidget.h", + "widgets/downloaditemform.ui", + "widgets/downloaditemwidget.cpp", + "widgets/downloaditemwidget.h", + ] + } +} diff --git a/src/lib/downloads/downloadsform.ui b/src/lib/downloads/downloadsform.ui new file mode 100644 index 0000000..5ab770f --- /dev/null +++ b/src/lib/downloads/downloadsform.ui @@ -0,0 +1,81 @@ + + + DownloadDialog + + + + 0 + 0 + 420 + 600 + + + + + 420 + 600 + + + + Downloads + + + + + + + + + Details + + + + + + Type + + + + + + + + + + + + + + Path + + + + + + + Size + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/lib/downloads/downloadswidget.cpp b/src/lib/downloads/downloadswidget.cpp new file mode 100644 index 0000000..651e5a7 --- /dev/null +++ b/src/lib/downloads/downloadswidget.cpp @@ -0,0 +1,86 @@ +/******************************************************************************* + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#include "downloadswidget.h" +#include "ui_downloadsform.h" + +#include +#include +#include +#include +#include +#include "widgets/downloaditemwidget.h" + +DownloadsWidget::DownloadsWidget(const QString path, QWidget *parent) : + QWidget(parent), + ui(new Ui::DownloadDialog) +{ + // make sure this dialog does not get deleted on close + setAttribute(Qt::WA_DeleteOnClose, false); + setWindowTitle(tr("Downloads")); + + ui->setupUi(this); + ui->filePath->setWordWrap(true); + + m_downloadPath = path; + + connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); +} + +DownloadsWidget::~DownloadsWidget() +{ + qDebug("Destroying DownloadsManager"); + + delete ui; +} + +void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) +{ + QString filepath = QFileDialog::getSaveFileName(this, + tr("Save"), + m_downloadPath + "/" + QFileInfo(item->path()).fileName()); + + if(filepath.isEmpty()) { + // user cancelled the save dialog + item->cancel(); + return; + } + + item->setPath(filepath); + + QListWidgetItem *listItem = new QListWidgetItem(); + int rowIndex = ui->listWidget->count(); + ui->listWidget->insertItem(rowIndex, listItem); + + DownloadItemWidget *form = new DownloadItemWidget(item, this); + listItem->setSizeHint(form->size()); + ui->listWidget->setItemWidget(listItem, form); + + item->accept(); + this->show(); +} + +void DownloadsWidget::showItemDetails(int index) +{ + DownloadItemWidget *form = qobject_cast(ui->listWidget->itemWidget(ui->listWidget->item(index))); + ui->mimeType_label->setText(form->item()->mimeType()); + ui->filePath_label->setText(form->item()->path()); + ui->fileSize_label->setText(QString("%1 bytes").arg(form->item()->totalBytes())); +} diff --git a/src/lib/downloads/downloadswidget.h b/src/lib/downloads/downloadswidget.h new file mode 100644 index 0000000..8bfff48 --- /dev/null +++ b/src/lib/downloads/downloadswidget.h @@ -0,0 +1,50 @@ +/******************************************************************************* + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#ifndef DOWNLOADDIALOG_H +#define DOWNLOADDIALOG_H + +#include + +namespace Ui { +class DownloadDialog; +} + +class QWebEngineDownloadItem; +class DownloadsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DownloadsWidget(const QString path, QWidget *parent = 0); + ~DownloadsWidget(); + +public slots: + void addDownload(QWebEngineDownloadItem *item); + +private slots: + void showItemDetails(int index); + +private: + Ui::DownloadDialog *ui; + QString m_downloadPath; +}; + +#endif // DOWNLOADDIALOG_H diff --git a/src/lib/downloads/widgets/downloaditemform.ui b/src/lib/downloads/widgets/downloaditemform.ui new file mode 100644 index 0000000..8a8d148 --- /dev/null +++ b/src/lib/downloads/widgets/downloaditemform.ui @@ -0,0 +1,53 @@ + + + DownloadItemForm + + + + 0 + 0 + 500 + 70 + + + + Form + + + + + + [url] + + + + + + + + + Unknown + + + + + + + x MiB / y MiB + + + + + + + 24 + + + + + + + + + + diff --git a/src/lib/downloads/widgets/downloaditemwidget.cpp b/src/lib/downloads/widgets/downloaditemwidget.cpp new file mode 100644 index 0000000..02fc215 --- /dev/null +++ b/src/lib/downloads/widgets/downloaditemwidget.cpp @@ -0,0 +1,102 @@ +/******************************************************************************* + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#include "downloaditemwidget.h" +#include "ui_downloaditemform.h" + +#include +#include + +DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) : + QWidget(parent), + ui(new Ui::DownloadItemForm) +{ + m_item = item; + + ui->setupUi(this); + ui->url_label->setText(item->url().toString()); + + connect(item, SIGNAL(stateChanged(QWebEngineDownloadItem::DownloadState)), this, SLOT(updateState(QWebEngineDownloadItem::DownloadState))); + connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); + connect(item, SIGNAL(finished()), this, SLOT(updateFinished())); +} + +DownloadItemWidget::~DownloadItemWidget() +{ + delete ui; +} + +QWebEngineDownloadItem *DownloadItemWidget::item() const +{ + return m_item; +} + +QString DownloadItemWidget::sizeString(int size) const +{ + if(size < 1024) { + return QString("%1 bytes").arg(size); + } + // KiB + if(size < 1024 * 1024) { + return QString("%1 kB").arg(size / 1024); + } + // MiB + if(size < 1024 * 1024 * 1024) { + return QString("%1 MB").arg(size / (1024 * 1024)); + } + // GiB + return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); +} + +void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state) +{ + switch (state) { + case QWebEngineDownloadItem::DownloadRequested: + ui->status_label->setText(tr("Requested")); + break; + case QWebEngineDownloadItem::DownloadInProgress: + ui->status_label->setText(tr("In progress")); + break; + case QWebEngineDownloadItem::DownloadCompleted: + ui->status_label->setText(tr("Completed")); + break; + case QWebEngineDownloadItem::DownloadCancelled: + ui->status_label->setText(tr("Cancelled")); + break; + case QWebEngineDownloadItem::DownloadInterrupted: + ui->status_label->setText(tr("Interrupted")); + break; + default: + break; + } +} + +void DownloadItemWidget::updateProgress(qint64 value, qint64 total) +{ + ui->progressBar->setMaximum(total); + ui->progressBar->setValue(value); + ui->filesize_label->setText(QString("%1 / %2").arg(sizeString(value), sizeString(total))); +} + +void DownloadItemWidget::updateFinished() +{ + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); +} diff --git a/src/lib/downloads/widgets/downloaditemwidget.h b/src/lib/downloads/widgets/downloaditemwidget.h new file mode 100644 index 0000000..e2f764e --- /dev/null +++ b/src/lib/downloads/widgets/downloaditemwidget.h @@ -0,0 +1,52 @@ +/******************************************************************************* + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#ifndef DOWNLOADITEMFORM_H +#define DOWNLOADITEMFORM_H + +#include +#include + +namespace Ui { +class DownloadItemForm; +} + +class DownloadItemWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); + ~DownloadItemWidget(); + + QWebEngineDownloadItem *item() const; + QString sizeString(int size) const; + +private slots: + void updateState(QWebEngineDownloadItem::DownloadState state); + void updateProgress(qint64 value, qint64 total); + void updateFinished(); + +private: + Ui::DownloadItemForm *ui; + QWebEngineDownloadItem *m_item; +}; + +#endif // DOWNLOADITEMFORM_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b43f49..1036cbb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,6 +34,8 @@ #include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -140,8 +142,13 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget) +void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget) { + QDockWidget *dock = new QDockWidget(widget->windowTitle(), this); + dock->setWidget(widget); + addDockWidget(area, dock); + + /* QList allDockWidgets = findChildren(); QVector areaDockWidgets; for(QDockWidget *w : allDockWidgets) { @@ -155,7 +162,7 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget) addDockWidget(area, widget); } else { tabifyDockWidget(areaDockWidgets.last(), widget); - } + }*/ } void MainWindow::newTab(const QUrl &url) diff --git a/src/mainwindow.h b/src/mainwindow.h index 5537900..5994f44 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -46,7 +46,7 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); - void addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget); + void addTabbedDock(Qt::DockWidgetArea area, QWidget *widget); public slots: void about(); diff --git a/src/widgets/dockingwidget.cpp b/src/widgets/dockingwidget.cpp deleted file mode 100644 index e501f16..0000000 --- a/src/widgets/dockingwidget.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#include "dockingwidget.h" -#include "mainwindow.h" - -#include - -DockWidget::DockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags) : - QDockWidget(title, parent, flags) -{ -} - -void DockWidget::closeEvent(QCloseEvent *event) -{ - setParent(0); - event->ignore(); -} - -DockingWidget::DockingWidget(const QString &title, QWidget *parent) : - QWidget(parent) -{ - window = nullptr; - dock = new DockWidget(title, 0); - dock->setWidget(this); - dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - - connect(qApp, &QApplication::aboutToQuit, [this]() { - this->setParent(0); - }); -} - -DockingWidget::~DockingWidget() -{ - // If the dock has a parent, it will take care of it - // calling delete later here if the dock has a parent causes a crash - if(!dock->parent()) { - dock->deleteLater(); - } -} - -void DockingWidget::show() -{ - MainWindow *caller = qobject_cast(sender()->parent()); - // if already shown and on the same window - hide the widget - if(isVisible() && window == caller) { - dock->setParent(0); - return; - } - - // show() gets called by a QAction in MainWindow - window = caller; - if(window) { - - // dockable widgets - dock->setParent(window); - //window->addDockWidget(Qt::RightDockWidgetArea, dock); - window->addTabbedDock(Qt::RightDockWidgetArea, dock); - - } else { - qWarning("DockingWidget not called by MainWindow"); - } - - QWidget::show(); -} diff --git a/src/widgets/dockingwidget.h b/src/widgets/dockingwidget.h deleted file mode 100644 index 4b35758..0000000 --- a/src/widgets/dockingwidget.h +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#ifndef DOCKINGWIDGET_H -#define DOCKINGWIDGET_H - -#include -#include - -// Subclass DockWidget to disable QDockWidget from committing sudoku when closing -class DockWidget : public QDockWidget -{ - Q_OBJECT - -public: - explicit DockWidget(const QString &title, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); - -protected: - void closeEvent(QCloseEvent *event); -}; - -class MainWindow; -class DockingWidget : public QWidget -{ - Q_OBJECT -public: - explicit DockingWidget(const QString &title, QWidget *parent = 0); - ~DockingWidget(); - -public slots: - void show(); - -private: - MainWindow *window; - DockWidget *dock; -}; - -#endif // DOCKINGWIDGET_H diff --git a/src/widgets/downloaditemform.ui b/src/widgets/downloaditemform.ui deleted file mode 100644 index 8a8d148..0000000 --- a/src/widgets/downloaditemform.ui +++ /dev/null @@ -1,53 +0,0 @@ - - - DownloadItemForm - - - - 0 - 0 - 500 - 70 - - - - Form - - - - - - [url] - - - - - - - - - Unknown - - - - - - - x MiB / y MiB - - - - - - - 24 - - - - - - - - - - diff --git a/src/widgets/downloaditemwidget.cpp b/src/widgets/downloaditemwidget.cpp deleted file mode 100644 index 02fc215..0000000 --- a/src/widgets/downloaditemwidget.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#include "downloaditemwidget.h" -#include "ui_downloaditemform.h" - -#include -#include - -DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) : - QWidget(parent), - ui(new Ui::DownloadItemForm) -{ - m_item = item; - - ui->setupUi(this); - ui->url_label->setText(item->url().toString()); - - connect(item, SIGNAL(stateChanged(QWebEngineDownloadItem::DownloadState)), this, SLOT(updateState(QWebEngineDownloadItem::DownloadState))); - connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); - connect(item, SIGNAL(finished()), this, SLOT(updateFinished())); -} - -DownloadItemWidget::~DownloadItemWidget() -{ - delete ui; -} - -QWebEngineDownloadItem *DownloadItemWidget::item() const -{ - return m_item; -} - -QString DownloadItemWidget::sizeString(int size) const -{ - if(size < 1024) { - return QString("%1 bytes").arg(size); - } - // KiB - if(size < 1024 * 1024) { - return QString("%1 kB").arg(size / 1024); - } - // MiB - if(size < 1024 * 1024 * 1024) { - return QString("%1 MB").arg(size / (1024 * 1024)); - } - // GiB - return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); -} - -void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state) -{ - switch (state) { - case QWebEngineDownloadItem::DownloadRequested: - ui->status_label->setText(tr("Requested")); - break; - case QWebEngineDownloadItem::DownloadInProgress: - ui->status_label->setText(tr("In progress")); - break; - case QWebEngineDownloadItem::DownloadCompleted: - ui->status_label->setText(tr("Completed")); - break; - case QWebEngineDownloadItem::DownloadCancelled: - ui->status_label->setText(tr("Cancelled")); - break; - case QWebEngineDownloadItem::DownloadInterrupted: - ui->status_label->setText(tr("Interrupted")); - break; - default: - break; - } -} - -void DownloadItemWidget::updateProgress(qint64 value, qint64 total) -{ - ui->progressBar->setMaximum(total); - ui->progressBar->setValue(value); - ui->filesize_label->setText(QString("%1 / %2").arg(sizeString(value), sizeString(total))); -} - -void DownloadItemWidget::updateFinished() -{ - ui->progressBar->setMaximum(100); - ui->progressBar->setValue(100); -} diff --git a/src/widgets/downloaditemwidget.h b/src/widgets/downloaditemwidget.h deleted file mode 100644 index e2f764e..0000000 --- a/src/widgets/downloaditemwidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#ifndef DOWNLOADITEMFORM_H -#define DOWNLOADITEMFORM_H - -#include -#include - -namespace Ui { -class DownloadItemForm; -} - -class DownloadItemWidget : public QWidget -{ - Q_OBJECT - -public: - explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); - ~DownloadItemWidget(); - - QWebEngineDownloadItem *item() const; - QString sizeString(int size) const; - -private slots: - void updateState(QWebEngineDownloadItem::DownloadState state); - void updateProgress(qint64 value, qint64 total); - void updateFinished(); - -private: - Ui::DownloadItemForm *ui; - QWebEngineDownloadItem *m_item; -}; - -#endif // DOWNLOADITEMFORM_H diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index 95cb280..964d9fd 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -47,12 +47,19 @@ MainWindowMenuBar::MainWindowMenuBar(MainWindow *parent) : // Tools menu QMenu *toolsMenu = new QMenu(tr("Tools"), this); addMenu(toolsMenu); - QAction *downloadsAction = toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); + QAction *downloadsAction = toolsMenu->addAction(tr("Downloads")); downloadsAction->setParent(parent); downloadsAction->setShortcut(QKeySequence::fromString(browser->settings()->value("downloads.dialogShortcut").toString())); - QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks"), Browser::instance()->bookmarks(), SLOT(show())); + connect(downloadsAction, &QAction::triggered, this, [&]() { + m_parentWindow->addTabbedDock(Qt::RightDockWidgetArea, browser->downloads()); + }); + + QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); bookmarksAction->setParent(parent); bookmarksAction->setShortcut(QKeySequence(browser->settings()->value("bookmarks.dialogShortcut").toString())); + connect(bookmarksAction, &QAction::triggered, this, [&]() { + m_parentWindow->addTabbedDock(Qt::RightDockWidgetArea, browser->bookmarks()); + }); toolsMenu->addSeparator(); toolsMenu->addAction(tr("Filter"), browser->blocklists(), SLOT(show()), QKeySequence::fromString(browser->settings()->value("blocker.shortcut").toString())); -- cgit v1.2.1