Falkon Develop
Cross-platform Qt-based web browser
browsinglibrary.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 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 "browsinglibrary.h"
19#include "ui_browsinglibrary.h"
22#include "historymanager.h"
23#include "bookmarksmanager.h"
24#include "mainapplication.h"
25#include "qztools.h"
26#include "settings.h"
27
28#include <QMenu>
29#include <QCloseEvent>
30
32 : QWidget(parent)
33 , ui(new Ui::BrowsingLibrary)
34 , m_historyManager(new HistoryManager(window))
35 , m_bookmarksManager(new BookmarksManager(window))
36{
37 ui->setupUi(this);
38
39 Settings settings;
40 settings.beginGroup(QSL("BrowsingLibrary"));
41 resize(settings.value(QSL("size"), QSize(760, 470)).toSize());
42 m_historyManager->restoreState(settings.value(QSL("historyState"), QByteArray()).toByteArray());
43 settings.endGroup();
44
46
47 QIcon historyIcon;
48 historyIcon.addFile(QSL(":/icons/other/bighistory.svg"), QSize(), QIcon::Normal);
49 historyIcon.addFile(QSL(":/icons/other/bighistory-selected.svg"), QSize(), QIcon::Selected);
50
51 QIcon bookmarksIcon;
52 bookmarksIcon.addFile(QSL(":/icons/other/bigstar.svg"), QSize(), QIcon::Normal);
53 bookmarksIcon.addFile(QSL(":/icons/other/bigstar-selected.svg"), QSize(), QIcon::Selected);
54
55 ui->tabs->AddTab(m_historyManager, historyIcon, tr("History"));
56 ui->tabs->AddTab(m_bookmarksManager, bookmarksIcon, tr("Bookmarks"));
57 ui->tabs->SetMode(FancyTabWidget::Mode_LargeSidebar);
58 ui->tabs->setFocus();
59
60 auto* m = new QMenu(this);
61 m->addAction(tr("Import Bookmarks..."), this, &BrowsingLibrary::importBookmarks);
62 m->addAction(tr("Export Bookmarks..."), this, &BrowsingLibrary::exportBookmarks);
63 ui->importExport->setMenu(m);
64
65 connect(ui->tabs, &FancyTabWidget::CurrentChanged, ui->searchLine, &QLineEdit::clear);
66 connect(ui->searchLine, &QLineEdit::textChanged, this, &BrowsingLibrary::search);
67
68 QzTools::setWmClass(QSL("Browsing Library"), this);
69}
70
71void BrowsingLibrary::search()
72{
73 if (ui->tabs->current_index() == 0) {
74 m_historyManager->search(ui->searchLine->text());
75 }
76 else {
77 m_bookmarksManager->search(ui->searchLine->text());
78 }
79}
80
81void BrowsingLibrary::importBookmarks()
82{
83 auto* d = new BookmarksImportDialog(this);
84 d->open();
85}
86
87void BrowsingLibrary::exportBookmarks()
88{
89 auto* d = new BookmarksExportDialog(this);
90 d->open();
91}
92
94{
95 ui->tabs->SetCurrentIndex(0);
96 show();
97 m_historyManager->setMainWindow(window);
98
99 raise();
100 activateWindow();
101}
102
104{
105 ui->tabs->SetCurrentIndex(1);
106 show();
107 m_bookmarksManager->setMainWindow(window);
108
109 raise();
110 activateWindow();
111}
112
113void BrowsingLibrary::closeEvent(QCloseEvent* e)
114{
115 Settings settings;
116 settings.beginGroup(QSL("BrowsingLibrary"));
117 settings.setValue(QSL("size"), size());
118 settings.setValue(QSL("historyState"), m_historyManager->saveState());
119 settings.endGroup();
120 e->accept();
121}
122
123void BrowsingLibrary::keyPressEvent(QKeyEvent* e)
124{
125 if (e->key() == Qt::Key_Escape
126 || (e->key() == Qt::Key_W && e->modifiers() == Qt::ControlModifier)) {
127 close();
128 }
129
130 QWidget::keyPressEvent(e);
131}
132
134{
135 delete ui;
136}
void setMainWindow(BrowserWindow *window)
void search(const QString &string)
void showHistory(BrowserWindow *window)
BrowsingLibrary(BrowserWindow *window, QWidget *parent=nullptr)
void showBookmarks(BrowserWindow *window)
~BrowsingLibrary() override
void restoreState(const QByteArray &state)
QByteArray saveState()
void search(const QString &searchText)
void setMainWindow(BrowserWindow *window)
static void setWmClass(const QString &name, const QWidget *widget)
Definition: qztools.cpp:874
static void centerWidgetOnScreen(QWidget *w)
Definition: qztools.cpp:116
void beginGroup(const QString &prefix)
Definition: settings.cpp:79
void endGroup()
Definition: settings.cpp:84
QVariant value(const QString &key, const QVariant &defaultValue=QVariant())
Definition: settings.cpp:74
void setValue(const QString &key, const QVariant &defaultValue=QVariant())
Definition: settings.cpp:69
#define QSL(x)
Definition: qzcommon.h:40