diff options
-rw-r--r-- | smolbote.qbs | 24 | ||||
-rw-r--r-- | src/browser.cpp | 16 | ||||
-rw-r--r-- | src/browser.h | 7 | ||||
-rw-r--r-- | src/lib/bookmarks/bookmarkswidget.cpp | 9 | ||||
-rw-r--r-- | src/lib/bookmarks/bookmarkswidget.h | 5 | ||||
-rw-r--r-- | src/lib/downloads/downloads.qbs | 27 | ||||
-rw-r--r-- | src/lib/downloads/downloadsform.ui (renamed from src/forms/downloadsform.ui) | 0 | ||||
-rw-r--r-- | src/lib/downloads/downloadswidget.cpp (renamed from src/forms/downloadswidget.cpp) | 15 | ||||
-rw-r--r-- | src/lib/downloads/downloadswidget.h (renamed from src/forms/downloadswidget.h) | 7 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemform.ui (renamed from src/widgets/downloaditemform.ui) | 0 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemwidget.cpp (renamed from src/widgets/downloaditemwidget.cpp) | 0 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemwidget.h (renamed from src/widgets/downloaditemwidget.h) | 0 | ||||
-rw-r--r-- | src/mainwindow.cpp | 11 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/widgets/dockingwidget.cpp | 82 | ||||
-rw-r--r-- | src/widgets/dockingwidget.h | 55 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.cpp | 11 |
17 files changed, 83 insertions, 188 deletions
diff --git a/smolbote.qbs b/smolbote.qbs index 585210e..dec8bec 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -17,6 +17,7 @@ Project { references: [ "src/lib/bookmarks/bookmarks.qbs", + "src/lib/downloads/downloads.qbs", "src/lib/navigation/navigation.qbs" ] @@ -37,6 +38,9 @@ Project { Depends { name: "bookmarks" } + Depends { + name: "downloads" + } Probe { id: git @@ -94,8 +98,6 @@ Project { "src/forms/aboutdialog.ui", "src/webengine/webview.cpp", "src/webengine/webview.h", - "src/widgets/dockingwidget.cpp", - "src/widgets/dockingwidget.h", "src/widgets/loadingbar.cpp", "src/widgets/loadingbar.h", "src/widgets/mainwindowmenubar.cpp", @@ -106,18 +108,6 @@ Project { } Group { - name: "downloads" - files: [ - "src/forms/downloadsform.ui", - "src/forms/downloadswidget.cpp", - "src/forms/downloadswidget.h", - "src/widgets/downloaditemform.ui", - "src/widgets/downloaditemwidget.cpp", - "src/widgets/downloaditemwidget.h", - ] - } - - Group { name: "Request Filter" files: [ "src/filter/blockermanager.cpp", @@ -181,7 +171,7 @@ Project { } } // CppApplication poi - SubProject { - filePath: "src/plugins/plugins.qbs" - } + //SubProject { + // filePath: "src/plugins/plugins.qbs" + //} } 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<BookmarksWidget>(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<DownloadsWidget>(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 <bookmarks/bookmarkswidget.h> -#include "forms/downloadswidget.h" +#include <downloads/downloadswidget.h> #include "settings.h" #include "webengine/webengineprofile.h" @@ -31,6 +31,7 @@ #include "webengine/urlinterceptor.h" #include <memory> +#include <QSharedPointer> #ifdef browser #undef browser @@ -80,8 +81,8 @@ private: QHash<QString, WebEngineProfile *> m_profiles; UrlRequestInterceptor *m_urlRequestInterceptor = nullptr; - BookmarksWidget *m_bookmarksManager = nullptr; - DownloadsWidget *m_downloadManager = nullptr; + QSharedPointer<BookmarksWidget> m_bookmarksManager; + QSharedPointer<DownloadsWidget> m_downloadManager; BlockerManager *m_blocklistManager = nullptr; QObject *m_plugin = nullptr; 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 <QUrl> 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 <QDockWidget> +#include <QWidget> #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/forms/downloadsform.ui b/src/lib/downloads/downloadsform.ui index 5ab770f..5ab770f 100644 --- a/src/forms/downloadsform.ui +++ b/src/lib/downloads/downloadsform.ui diff --git a/src/forms/downloadswidget.cpp b/src/lib/downloads/downloadswidget.cpp index 008e371..651e5a7 100644 --- a/src/forms/downloadswidget.cpp +++ b/src/lib/downloads/downloadswidget.cpp @@ -27,20 +27,27 @@ #include <QListWidget> #include <QLabel> #include "widgets/downloaditemwidget.h" -#include "browser.h" -DownloadsWidget::DownloadsWidget(QWidget *parent) : - DockingWidget(tr("Downloads"), parent), +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; } @@ -48,7 +55,7 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) { QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), - browser->settings()->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); + m_downloadPath + "/" + QFileInfo(item->path()).fileName()); if(filepath.isEmpty()) { // user cancelled the save dialog diff --git a/src/forms/downloadswidget.h b/src/lib/downloads/downloadswidget.h index fed3833..8bfff48 100644 --- a/src/forms/downloadswidget.h +++ b/src/lib/downloads/downloadswidget.h @@ -21,19 +21,19 @@ #ifndef DOWNLOADDIALOG_H #define DOWNLOADDIALOG_H -#include "widgets/dockingwidget.h" +#include <QWidget> namespace Ui { class DownloadDialog; } class QWebEngineDownloadItem; -class DownloadsWidget : public DockingWidget +class DownloadsWidget : public QWidget { Q_OBJECT public: - explicit DownloadsWidget(QWidget *parent = 0); + explicit DownloadsWidget(const QString path, QWidget *parent = 0); ~DownloadsWidget(); public slots: @@ -44,6 +44,7 @@ private slots: private: Ui::DownloadDialog *ui; + QString m_downloadPath; }; #endif // DOWNLOADDIALOG_H diff --git a/src/widgets/downloaditemform.ui b/src/lib/downloads/widgets/downloaditemform.ui index 8a8d148..8a8d148 100644 --- a/src/widgets/downloaditemform.ui +++ b/src/lib/downloads/widgets/downloaditemform.ui diff --git a/src/widgets/downloaditemwidget.cpp b/src/lib/downloads/widgets/downloaditemwidget.cpp index 02fc215..02fc215 100644 --- a/src/widgets/downloaditemwidget.cpp +++ b/src/lib/downloads/widgets/downloaditemwidget.cpp diff --git a/src/widgets/downloaditemwidget.h b/src/lib/downloads/widgets/downloaditemwidget.h index e2f764e..e2f764e 100644 --- a/src/widgets/downloaditemwidget.h +++ b/src/lib/downloads/widgets/downloaditemwidget.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 <QWebEngineHistory> +#include <QDockWidget> + 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<QDockWidget*> allDockWidgets = findChildren<QDockWidget*>(); QVector<QDockWidget*> 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 <http://www.gnu.org/licenses/>. - ** - ******************************************************************************/ - -#include "dockingwidget.h" -#include "mainwindow.h" - -#include <QApplication> - -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<MainWindow *>(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 <http://www.gnu.org/licenses/>. - ** - ******************************************************************************/ - -#ifndef DOCKINGWIDGET_H -#define DOCKINGWIDGET_H - -#include <QWidget> -#include <QDockWidget> - -// 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/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())); |