1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Fully implemented #58 + little improvement in locationbar

- it will now show empty url when going in history back or
  forward to speed dial
This commit is contained in:
nowrep 2011-12-12 18:30:08 +01:00
parent c69022b670
commit 42b5ad7947
5 changed files with 84 additions and 13 deletions

View File

@ -193,12 +193,18 @@ void LocationBar::showRSSIcon(bool state)
void LocationBar::showUrl(const QUrl &url, bool empty)
{
if (hasFocus() || (url.isEmpty() && empty) || url.toString() == "qupzilla:speeddial") {
if (hasFocus() || (url.isEmpty() && empty)) {
return;
}
QString encodedUrl = url.toEncoded();
if (url.toString() == "qupzilla:speeddial") {
encodedUrl = "";
}
if (url.toEncoded() != text()) {
setText(url.toEncoded());
setText(encodedUrl);
setCursorPosition(0);
}
p_QupZilla->statusBarMessage()->clearMessage();

View File

@ -105,7 +105,10 @@ NavigationBar::NavigationBar(QupZilla* mainClass, QWidget* parent)
connect(m_menuBack, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryBackMenu()));
connect(m_menuForward, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryNextMenu()));
connect(m_buttonBack, SIGNAL(clicked()), this, SLOT(goBack()));
connect(m_buttonBack, SIGNAL(middleMouseClicked()), this, SLOT(goBackInNewTab()));
connect(m_buttonNext, SIGNAL(clicked()), this, SLOT(goForward()));
connect(m_buttonNext, SIGNAL(middleMouseClicked()), this, SLOT(goForwardInNewTab()));
connect(m_reloadStop->buttonStop(), SIGNAL(clicked()), p_QupZilla, SLOT(stop()));
connect(m_reloadStop->buttonReload(), SIGNAL(clicked()), p_QupZilla, SLOT(reload()));
connect(m_buttonHome, SIGNAL(clicked()), p_QupZilla, SLOT(goHome()));
@ -248,17 +251,23 @@ void NavigationBar::goAtHistoryIndex()
refreshHistory();
}
void NavigationBar::goAtHistoryIndexInNewTab()
void NavigationBar::goAtHistoryIndexInNewTab(int index)
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
TabWidget* tabWidget = p_QupZilla->tabWidget();
tabWidget->duplicateTab(tabWidget->currentIndex());
int index = tabWidget->count() - 1;
QWebHistory* history = p_QupZilla->weView(index)->page()->history();
history->goToItem(history->itemAt(action->data().toInt()));
index = action->data().toInt();
}
if (index == -1) {
return;
}
TabWidget* tabWidget = p_QupZilla->tabWidget();
tabWidget->duplicateTab(tabWidget->currentIndex());
int tabIndex = tabWidget->count() - 1;
QWebHistory* history = p_QupZilla->weView(tabIndex)->page()->history();
history->goToItem(history->itemAt(index));
}
void NavigationBar::refreshHistory()
@ -274,12 +283,48 @@ void NavigationBar::refreshHistory()
void NavigationBar::goBack()
{
WebHistoryWrapper::goBack(p_QupZilla->weView()->page()->history());
QWebHistory* history = p_QupZilla->weView()->page()->history();
WebHistoryWrapper::goBack(history);
}
void NavigationBar::goBackInNewTab()
{
QWebHistory* history = p_QupZilla->weView()->page()->history();
QList<QWebHistoryItem> backItems = WebHistoryWrapper::backItems(1, history);
if (backItems.isEmpty()) {
return;
}
int itemIndex = WebHistoryWrapper::indexOfItem(history->items(), backItems.at(0));
if (itemIndex == -1) {
return;
}
goAtHistoryIndexInNewTab(itemIndex);
}
void NavigationBar::goForward()
{
WebHistoryWrapper::goForward(p_QupZilla->weView()->page()->history());
QWebHistory* history = p_QupZilla->weView()->page()->history();
WebHistoryWrapper::goForward(history);
}
void NavigationBar::goForwardInNewTab()
{
QWebHistory* history = p_QupZilla->weView()->page()->history();
QList<QWebHistoryItem> forwardItems = WebHistoryWrapper::forwardItems(1, history);
if (forwardItems.isEmpty()) {
return;
}
int itemIndex = WebHistoryWrapper::indexOfItem(history->items(), forwardItems.at(0));
if (itemIndex == -1) {
return;
}
goAtHistoryIndexInNewTab(itemIndex);
}
NavigationBar::~NavigationBar()

View File

@ -55,14 +55,16 @@ public slots:
void refreshHistory();
void goBack();
void goBackInNewTab();
void goForward();
void goForwardInNewTab();
private slots:
void aboutToShowHistoryNextMenu();
void aboutToShowHistoryBackMenu();
void goAtHistoryIndex();
void goAtHistoryIndexInNewTab();
void goAtHistoryIndexInNewTab(int index = -1);
void clearHistory();

View File

@ -93,3 +93,20 @@ void WebHistoryWrapper::goForward(QWebHistory* history)
history->goToItem(items.at(0));
}
int WebHistoryWrapper::indexOfItem(const QList<QWebHistoryItem> &list, const QWebHistoryItem &item)
{
for (int i = 0; i < list.count(); i++) {
QWebHistoryItem it = list.at(i);
if (it.lastVisited() == item.lastVisited() &&
it.originalUrl() == item.originalUrl() &&
it.title() == item.title() &&
it.url() == item.url())
{
return i;
}
}
return -1;
}

View File

@ -37,6 +37,7 @@ public:
static void goBack(QWebHistory* history);
static void goForward(QWebHistory* history);
static int indexOfItem(const QList<QWebHistoryItem> &list, const QWebHistoryItem &item);
signals: