mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Added history sidebar
This commit is contained in:
parent
1282e23b71
commit
5bf7d732a8
|
@ -110,7 +110,8 @@ SOURCES += main.cpp\
|
|||
adblock/adblockicon.cpp \
|
||||
tools/docktitlebarwidget.cpp \
|
||||
sidebar/bookmarkssidebar.cpp \
|
||||
bookmarks/bookmarkicon.cpp
|
||||
bookmarks/bookmarkicon.cpp \
|
||||
sidebar/historysidebar.cpp
|
||||
|
||||
HEADERS += 3rdparty/squeezelabel.h \
|
||||
3rdparty/qtwin.h \
|
||||
|
@ -180,7 +181,8 @@ HEADERS += 3rdparty/squeezelabel.h \
|
|||
adblock/adblockicon.h \
|
||||
tools/docktitlebarwidget.h \
|
||||
sidebar/bookmarkssidebar.h \
|
||||
bookmarks/bookmarkicon.h
|
||||
bookmarks/bookmarkicon.h \
|
||||
sidebar/historysidebar.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
@ -206,7 +208,8 @@ FORMS += \
|
|||
other/closedialog.ui \
|
||||
adblock/adblockdialog.ui \
|
||||
tools/docktitlebarwidget.ui \
|
||||
sidebar/bookmarkssidebar.ui
|
||||
sidebar/bookmarkssidebar.ui \
|
||||
sidebar/historysidebar.ui
|
||||
|
||||
RESOURCES += \
|
||||
data/icons.qrc \
|
||||
|
|
|
@ -246,15 +246,26 @@ void QupZilla::setupMenu()
|
|||
actionEncoding->setMenu(m_menuEncoding);
|
||||
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
|
||||
|
||||
m_actionShowBookmarksSideBar = new QAction(tr("Bookmarks"), this);
|
||||
m_actionShowBookmarksSideBar->setCheckable(true);
|
||||
connect(m_actionShowBookmarksSideBar, SIGNAL(triggered()), this, SLOT(showBookmarksSideBar()));
|
||||
m_actionShowHistorySideBar = new QAction(tr("History"), this);
|
||||
m_actionShowHistorySideBar->setCheckable(true);
|
||||
connect(m_actionShowHistorySideBar, SIGNAL(triggered()), this, SLOT(showHistorySideBar()));
|
||||
m_actionShowRssSideBar = new QAction(tr("RSS Reader"), this);
|
||||
m_actionShowRssSideBar->setCheckable(true);
|
||||
connect(m_actionShowRssSideBar, SIGNAL(triggered()), this, SLOT(showRssSideBar()));
|
||||
|
||||
QMenu* toolbarsMenu = new QMenu(tr("Toolbars"));
|
||||
toolbarsMenu->addAction(m_actionShowMenubar);
|
||||
toolbarsMenu->addAction(m_actionShowToolbar);
|
||||
toolbarsMenu->addAction(m_actionShowBookmarksToolbar);
|
||||
toolbarsMenu->addAction(m_actionShowStatusbar);
|
||||
QMenu* sidebarsMenu = new QMenu(tr("Sidebars"));
|
||||
sidebarsMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarksSideBar()))->setCheckable(true);
|
||||
sidebarsMenu->addAction(tr("History"), this, SLOT(showHistorySideBar()))->setCheckable(true);
|
||||
sidebarsMenu->addAction(tr("RSS Reader"), this, SLOT(showRssSideBar()))->setCheckable(true);
|
||||
sidebarsMenu->addAction(m_actionShowBookmarksSideBar);
|
||||
sidebarsMenu->addAction(m_actionShowHistorySideBar);
|
||||
sidebarsMenu->addAction(m_actionShowRssSideBar);
|
||||
connect(sidebarsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowSidebarsMenu()));
|
||||
|
||||
m_menuView->addMenu(toolbarsMenu);
|
||||
m_menuView->addMenu(sidebarsMenu);
|
||||
|
|
|
@ -561,11 +561,40 @@ void QupZilla::showBookmarksSideBar()
|
|||
m_sideBar = new SideBar(this);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_sideBar);
|
||||
m_sideBar->showBookmarks();
|
||||
} else if (m_actionShowBookmarksSideBar->isChecked()){
|
||||
m_sideBar->showBookmarks();
|
||||
} else {
|
||||
delete m_sideBar;
|
||||
}
|
||||
}
|
||||
|
||||
void QupZilla::showHistorySideBar()
|
||||
{
|
||||
if (!m_sideBar) {
|
||||
m_sideBar = new SideBar(this);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_sideBar);
|
||||
m_sideBar->showHistory();
|
||||
} else if (m_actionShowHistorySideBar->isChecked()) {
|
||||
m_sideBar->showHistory();
|
||||
} else {
|
||||
delete m_sideBar;
|
||||
}
|
||||
}
|
||||
|
||||
void QupZilla::aboutToShowSidebarsMenu()
|
||||
{
|
||||
if (!m_sideBar) {
|
||||
m_actionShowBookmarksSideBar->setChecked(false);
|
||||
m_actionShowHistorySideBar->setChecked(false);
|
||||
m_actionShowRssSideBar->setChecked(false);
|
||||
} else {
|
||||
SideBar::SideWidget actWidget = m_sideBar->activeWidget();
|
||||
m_actionShowBookmarksSideBar->setChecked(actWidget == SideBar::Bookmarks);
|
||||
m_actionShowHistorySideBar->setChecked(actWidget == SideBar::History);
|
||||
m_actionShowRssSideBar->setChecked(actWidget == SideBar::RSS);
|
||||
}
|
||||
}
|
||||
|
||||
void QupZilla::showNavigationToolbar()
|
||||
{
|
||||
if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked())
|
||||
|
@ -615,7 +644,7 @@ void QupZilla::showInspector()
|
|||
m_webInspectorDock->setTitleBarWidget(new DockTitleBarWidget(tr("Web Inspector"), m_webInspectorDock));
|
||||
m_webInspectorDock->setObjectName("WebInspector");
|
||||
m_webInspectorDock->setWidget(m_webInspector);
|
||||
m_webInspectorDock->setFeatures(QDockWidget::DockWidgetClosable);
|
||||
m_webInspectorDock->setFeatures(0);
|
||||
m_webInspectorDock->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
} else if (m_webInspectorDock->isVisible()) { //Next tab
|
||||
m_webInspectorDock->show();
|
||||
|
|
|
@ -148,10 +148,12 @@ private slots:
|
|||
void aboutToShowHelpMenu();
|
||||
void aboutToShowViewMenu();
|
||||
void aboutToShowEncodingMenu();
|
||||
void aboutToShowSidebarsMenu();
|
||||
|
||||
void searchOnPage();
|
||||
void showCookieManager();
|
||||
void showHistoryManager();
|
||||
void showHistorySideBar();
|
||||
void showBookmarksManager();
|
||||
void showBookmarksSideBar();
|
||||
void showRSSManager();
|
||||
|
@ -210,6 +212,9 @@ private:
|
|||
QAction* m_actionShowStatusbar;
|
||||
QAction* m_actionShowMenubar;
|
||||
QAction* m_actionShowFullScreen;
|
||||
QAction* m_actionShowBookmarksSideBar;
|
||||
QAction* m_actionShowHistorySideBar;
|
||||
QAction* m_actionShowRssSideBar;
|
||||
QAction* m_actionPrivateBrowsing;
|
||||
QAction* m_actionStop;
|
||||
QAction* m_actionReload;
|
||||
|
|
157
src/sidebar/historysidebar.cpp
Normal file
157
src/sidebar/historysidebar.cpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
#include "historysidebar.h"
|
||||
#include "ui_historysidebar.h"
|
||||
#include "qupzilla.h"
|
||||
|
||||
HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent) :
|
||||
QWidget(parent)
|
||||
,ui(new Ui::HistorySideBar)
|
||||
,p_QupZilla(mainClass)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this, SLOT(itemDoubleClicked(QTreeWidgetItem*)));
|
||||
connect(ui->historyTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||
connect(ui->historyTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
||||
connect(ui->search, SIGNAL(textEdited(QString)), this, SLOT(search()));
|
||||
|
||||
new QShortcut(QKeySequence("Del"), this, SLOT(deleteItem()), 0, Qt::WidgetWithChildrenShortcut);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(refreshTable()));
|
||||
}
|
||||
|
||||
void HistorySideBar::itemDoubleClicked(QTreeWidgetItem* item)
|
||||
{
|
||||
if (!item || item->text(1).isEmpty())
|
||||
return;
|
||||
p_QupZilla->loadAddress(QUrl(item->text(1)));
|
||||
}
|
||||
|
||||
void HistorySideBar::itemControlClicked(QTreeWidgetItem* item)
|
||||
{
|
||||
if (!item || item->text(1).isEmpty())
|
||||
return;
|
||||
p_QupZilla->tabWidget()->addView(QUrl(item->text(1)));
|
||||
}
|
||||
|
||||
void HistorySideBar::loadInNewTab()
|
||||
{
|
||||
if (QAction* action = qobject_cast<QAction*>(sender()))
|
||||
p_QupZilla->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab);
|
||||
}
|
||||
|
||||
void HistorySideBar::contextMenuRequested(const QPoint &position)
|
||||
{
|
||||
if (!ui->historyTree->itemAt(position))
|
||||
return;
|
||||
QString link = ui->historyTree->itemAt(position)->text(1);
|
||||
if (link.isEmpty())
|
||||
return;
|
||||
|
||||
QMenu menu;
|
||||
menu.addAction(tr("Open link in actual tab"), p_QupZilla, SLOT(loadActionUrl()))->setData(link);
|
||||
menu.addAction(tr("Open link in new tab"), this, SLOT(loadInNewTab()))->setData(link);
|
||||
menu.addSeparator();
|
||||
|
||||
menu.addSeparator();
|
||||
menu.addAction(tr("Remove Entry"), this, SLOT(deleteItem()));
|
||||
|
||||
//Prevent choosing first option with double rightclick
|
||||
QPoint pos = QCursor::pos();
|
||||
QPoint p(pos.x(), pos.y()+1);
|
||||
menu.exec(p);
|
||||
}
|
||||
|
||||
void HistorySideBar::deleteItem()
|
||||
{
|
||||
QTreeWidgetItem* item = ui->historyTree->currentItem();
|
||||
if (!item)
|
||||
return;
|
||||
if (item->text(1).isEmpty())
|
||||
return;
|
||||
|
||||
QString id = item->whatsThis(1);
|
||||
QSqlQuery query;
|
||||
query.exec("DELETE FROM history WHERE id="+id);
|
||||
delete item;
|
||||
}
|
||||
|
||||
void HistorySideBar::search()
|
||||
{
|
||||
QString searchText = ui->search->text();
|
||||
refreshTable();
|
||||
|
||||
if (searchText.isEmpty())
|
||||
return;
|
||||
|
||||
ui->historyTree->setUpdatesEnabled(false);
|
||||
|
||||
QList<QTreeWidgetItem*> items = ui->historyTree->findItems("*"+searchText+"*", Qt::MatchRecursive | Qt::MatchWildcard);
|
||||
|
||||
QList<QTreeWidgetItem*> foundItems;
|
||||
foreach(QTreeWidgetItem* fitem, items) {
|
||||
if (fitem->text(1).isEmpty())
|
||||
continue;
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||
item->setText(0, fitem->text(0));
|
||||
item->setText(1, fitem->text(1));
|
||||
item->setWhatsThis(1, fitem->whatsThis(1));
|
||||
item->setIcon(0, LocationBar::icon(QUrl(fitem->text(1))));
|
||||
foundItems.append(item);
|
||||
}
|
||||
ui->historyTree->clear();
|
||||
ui->historyTree->addTopLevelItems(foundItems);
|
||||
ui->historyTree->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
void HistorySideBar::refreshTable()
|
||||
{
|
||||
ui->historyTree->setUpdatesEnabled(false);
|
||||
ui->historyTree->clear();
|
||||
|
||||
QLocale locale(p_QupZilla->activeLanguage().remove(".qm"));
|
||||
|
||||
QSqlQuery query;
|
||||
query.exec("SELECT title, url, id, date FROM history ORDER BY date DESC");
|
||||
|
||||
while(query.next()) {
|
||||
QString title = query.value(0).toString();
|
||||
QUrl url = query.value(1).toUrl();
|
||||
int id = query.value(2).toInt();
|
||||
qint64 unixDate = query.value(3).toLongLong();
|
||||
QDateTime date = QDateTime();
|
||||
date = date.fromMSecsSinceEpoch(unixDate);
|
||||
|
||||
QString localDate; //date.toString("dddd d. MMMM yyyy");
|
||||
//QString day = locale.dayName(date.toString("d").toInt());
|
||||
|
||||
QString month = locale.monthName(date.toString("M").toInt());
|
||||
localDate = date.toString(" d. ") + month + date.toString(" yyyy");
|
||||
|
||||
QTreeWidgetItem* item;
|
||||
QList<QTreeWidgetItem*> findParent = ui->historyTree->findItems(localDate, 0);
|
||||
if (findParent.count() == 1) {
|
||||
item = new QTreeWidgetItem(findParent.at(0));
|
||||
}else{
|
||||
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->historyTree);
|
||||
newParent->setText(0, localDate);
|
||||
newParent->setIcon(0, QIcon(":/icons/menu/history_entry.png"));
|
||||
ui->historyTree->addTopLevelItem(newParent);
|
||||
item = new QTreeWidgetItem(newParent);
|
||||
}
|
||||
|
||||
item->setText(0, title);
|
||||
item->setText(1, url.toEncoded());
|
||||
item->setToolTip(0, title);
|
||||
item->setToolTip(1, url.toEncoded());
|
||||
|
||||
item->setWhatsThis(1, QString::number(id));
|
||||
item->setIcon(0, LocationBar::icon(url));
|
||||
ui->historyTree->addTopLevelItem(item);
|
||||
}
|
||||
|
||||
ui->historyTree->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
HistorySideBar::~HistorySideBar()
|
||||
{
|
||||
delete ui;
|
||||
}
|
38
src/sidebar/historysidebar.h
Normal file
38
src/sidebar/historysidebar.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef HISTORYSIDEBAR_H
|
||||
#define HISTORYSIDEBAR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QPointer>
|
||||
#include <QShortcut>
|
||||
|
||||
namespace Ui {
|
||||
class HistorySideBar;
|
||||
}
|
||||
|
||||
class QupZilla;
|
||||
class HistorySideBar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HistorySideBar(QupZilla* mainClass, QWidget* parent = 0);
|
||||
~HistorySideBar();
|
||||
|
||||
public slots:
|
||||
void refreshTable();
|
||||
|
||||
private slots:
|
||||
void search();
|
||||
void itemDoubleClicked(QTreeWidgetItem* item);
|
||||
void deleteItem();
|
||||
void contextMenuRequested(const QPoint &position);
|
||||
void loadInNewTab();
|
||||
void itemControlClicked(QTreeWidgetItem* item);
|
||||
|
||||
private:
|
||||
Ui::HistorySideBar* ui;
|
||||
QPointer<QupZilla> p_QupZilla;
|
||||
};
|
||||
|
||||
#endif // HISTORYSIDEBAR_H
|
71
src/sidebar/historysidebar.ui
Normal file
71
src/sidebar/historysidebar.ui
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>HistorySideBar</class>
|
||||
<widget class="QWidget" name="HistorySideBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>219</width>
|
||||
<height>457</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="search">
|
||||
<property name="placeholderText">
|
||||
<string>Search...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TreeWidget" name="historyTree">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="headerHidden">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>330</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TreeWidget</class>
|
||||
<extends>QTreeWidget</extends>
|
||||
<header>treewidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -18,15 +18,19 @@
|
|||
#include "sidebar.h"
|
||||
#include "docktitlebarwidget.h"
|
||||
#include "bookmarkssidebar.h"
|
||||
#include "historysidebar.h"
|
||||
#include "qupzilla.h"
|
||||
|
||||
SideBar::SideBar(QWidget* parent) :
|
||||
QDockWidget(parent)
|
||||
,m_activeWidget(None)
|
||||
{
|
||||
setObjectName("SideBar");
|
||||
setWindowTitle(tr("SideBar"));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
m_titleBar = new DockTitleBarWidget("", this);
|
||||
setTitleBarWidget(m_titleBar);
|
||||
setFeatures(0);
|
||||
}
|
||||
|
||||
void SideBar::showBookmarks()
|
||||
|
@ -34,11 +38,15 @@ void SideBar::showBookmarks()
|
|||
m_titleBar->setTitle(tr("Bookmarks"));
|
||||
BookmarksSideBar* bar = new BookmarksSideBar((QupZilla*)parentWidget(), this);
|
||||
setWidget(bar);
|
||||
m_activeWidget = Bookmarks;
|
||||
}
|
||||
|
||||
void SideBar::showHistory()
|
||||
{
|
||||
|
||||
m_titleBar->setTitle(tr("History"));
|
||||
HistorySideBar* bar = new HistorySideBar((QupZilla*)parentWidget(), this);
|
||||
setWidget(bar);
|
||||
m_activeWidget = History;
|
||||
}
|
||||
|
||||
void SideBar::showRSS()
|
||||
|
|
|
@ -25,10 +25,12 @@ class SideBar : public QDockWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum SideWidget { None = 0, Bookmarks, History, RSS };
|
||||
explicit SideBar(QWidget* parent = 0);
|
||||
void showBookmarks();
|
||||
void showHistory();
|
||||
void showRSS();
|
||||
SideWidget activeWidget() { return m_activeWidget; }
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -36,6 +38,7 @@ public slots:
|
|||
|
||||
private:
|
||||
DockTitleBarWidget* m_titleBar;
|
||||
SideWidget m_activeWidget;
|
||||
};
|
||||
|
||||
#endif // SIDEBAR_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user