summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-01-03 18:31:13 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-01-03 18:31:13 +0100
commit4b363ed35e880a6a74ac7784fcad713c62902f3a (patch)
treec2fcf830a13d10c45ac15ad947fb20b4e381a1e2 /src
parentDo NOT load previews if not present (diff)
downloadrekonq-4b363ed35e880a6a74ac7784fcad713c62902f3a.tar.xz
improve closed tabs management
- remove reopened tabs from the closed tabs list. - limit them to MAX 8 elements (it seems enough to me) - save history also when there is just one tab closed - DON'T save history when you opened a "rekonq" page BUG:271224
Diffstat (limited to 'src')
-rw-r--r--src/mainview.cpp112
-rw-r--r--src/mainview.h8
-rw-r--r--src/mainwindow.cpp5
-rw-r--r--src/mainwindow.h2
-rw-r--r--src/newtabpage.cpp109
-rw-r--r--src/newtabpage.h7
-rw-r--r--src/tabbar.cpp16
-rw-r--r--src/tabbar.h2
-rw-r--r--src/webtab.cpp2
-rw-r--r--src/webtab.h3
10 files changed, 154 insertions, 112 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 50fff2ac..62851590 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
* Copyright (C) 2010 by Matthieu Gicquel <matgic78 at gmail dot com>
@@ -421,14 +421,45 @@ void MainView::closeTab(int index, bool del)
if (index < 0 || index >= count())
return;
+ WebTab *tabToClose = webTab(index);
+ if (!tabToClose)
+ return;
+
+ if (tabToClose->view()->isModified())
+ {
+ int risp = KMessageBox::warningContinueCancel(this,
+ i18n("This tab contains changes that have not been submitted.\n"
+ "Closing the tab will discard these changes.\n"
+ "Do you really want to close this tab?\n"),
+ i18n("Closing Modified Tab"), KGuiItem(i18n("Close &Tab"), "tab-close"), KStandardGuiItem::cancel());
+ if (risp != KMessageBox::Continue)
+ return;
+ }
+
+ kDebug() << "URL: " << tabToClose->url();
+ kDebug() << "rekonq page: " << tabToClose->page()->isOnRekonqPage();
+
+ if (!tabToClose->url().isEmpty()
+ && tabToClose->url().scheme() != QL1S("about")
+ && !tabToClose->page()->isOnRekonqPage()
+ && !QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)
+ )
+ {
+ const int recentlyClosedTabsLimit = 8;
+ TabHistory history(tabToClose->view()->history());
+
+ m_recentlyClosedTabs.removeAll(history);
+ if (m_recentlyClosedTabs.count() == recentlyClosedTabsLimit)
+ m_recentlyClosedTabs.removeLast();
+ m_recentlyClosedTabs.prepend(history);
+ }
+
+ // what to do if there is just one tab...
if (count() == 1)
{
if (ReKonfig::lastTabClosesWindow())
{
emit closeWindow();
-// // closing window...
-// MainWindow *w = qobject_cast<MainWindow *>(parent());
-// w->close();
return;
}
@@ -453,34 +484,7 @@ void MainView::closeTab(int index, bool del)
}
return;
}
-
- WebTab *tabToClose = webTab(index);
- if (!tabToClose)
- return;
-
- if (tabToClose->view()->isModified())
- {
- int risp = KMessageBox::warningContinueCancel(this,
- i18n("This tab contains changes that have not been submitted.\n"
- "Closing the tab will discard these changes.\n"
- "Do you really want to close this tab?\n"),
- i18n("Closing Modified Tab"), KGuiItem(i18n("Close &Tab"), "tab-close"), KStandardGuiItem::cancel());
- if (risp != KMessageBox::Continue)
- return;
- }
-
- if (!tabToClose->url().isEmpty()
- && !QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)
- )
- {
- const int recentlyClosedTabsLimit = 10;
- TabHistory history(tabToClose->view()->history());
-
- m_recentlyClosedTabs.removeAll(history);
- if (m_recentlyClosedTabs.count() == recentlyClosedTabsLimit)
- m_recentlyClosedTabs.removeLast();
- m_recentlyClosedTabs.prepend(history);
- }
+ // else...
removeTab(index);
updateTabBar(); // UI operation: do it ASAP!!
@@ -494,6 +498,7 @@ void MainView::closeTab(int index, bool del)
}
}
+
void MainView::webViewLoadStarted()
{
WebView *view = qobject_cast<WebView *>(sender());
@@ -623,37 +628,34 @@ void MainView::previousTab()
}
-void MainView::openLastClosedTab()
+void MainView::openClosedTab()
{
- if (m_recentlyClosedTabs.isEmpty())
+ KAction *action = qobject_cast<KAction *>(sender());
+ if (!action)
return;
- TabHistory history = m_recentlyClosedTabs.takeFirst();
- WebView *view = rApp->mainWindow()->mainView()->newWebTab()->view();
-
- history.applyHistory(view->history());
+ int index = action->data().toInt();
+ kDebug() << "TAB INDEX TO RESTORE:" << index;
+ restoreClosedTab(index);
}
-void MainView::openClosedTab()
+void MainView::restoreClosedTab(int i, bool inNewTab)
{
- KAction *action = qobject_cast<KAction *>(sender());
- if (action)
- {
- WebView *view = rApp->mainWindow()->mainView()->newWebTab()->view();
- TabHistory history;
- Q_FOREACH(const TabHistory & item, m_recentlyClosedTabs)
- {
- if (item.history == action->data().toByteArray())
- {
- history = item;
- break;
- }
- }
- history.applyHistory(view->history());
+ if (m_recentlyClosedTabs.isEmpty())
+ return;
- m_recentlyClosedTabs.removeAll(history);
- }
+ TabHistory history = m_recentlyClosedTabs.takeAt(i);
+
+ WebView *view = inNewTab
+ ? newWebTab()->view()
+ : currentWebTab()->view()
+ ;
+
+ history.applyHistory(view->history());
+
+ // just to get sure...
+ m_recentlyClosedTabs.removeAll(history);
}
diff --git a/src/mainview.h b/src/mainview.h
index 4e6f1bbb..28185e48 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
* Copyright (C) 2010 by Matthieu Gicquel <matgic78 at gmail dot com>
@@ -106,6 +106,8 @@ public:
return m_recentlyClosedTabs;
}
+ void restoreClosedTab(int i, bool inNewTab = true);
+
Q_SIGNALS:
// current tab signals
void currentTitle(const QString &url);
@@ -144,8 +146,6 @@ public Q_SLOTS:
void nextTab();
void previousTab();
- void openLastClosedTab();
- void openClosedTab();
void switchToTab(const int index);
void loadFavorite(const int index);
@@ -164,6 +164,8 @@ private Q_SLOTS:
void windowCloseRequested();
+ void openClosedTab();
+
protected:
virtual void resizeEvent(QResizeEvent *event);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 01310bfb..98936e96 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
* Copyright (C) 2010 by Matthieu Gicquel <matgic78 at gmail dot com>
@@ -451,9 +451,10 @@ void MainWindow::setupActions()
connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab()));
a = new KAction(KIcon("tab-new"), i18n("Open Last Closed Tab"), this);
+ a->setData(0); // last tab has always index = 0
a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
actionCollection()->addAction(QL1S("open_last_closed_tab"), a);
- connect(a, SIGNAL(triggered(bool)), m_view, SLOT(openLastClosedTab()));
+ connect(a, SIGNAL(triggered(bool)), m_view, SLOT(openClosedTab()));
// Closed Tabs Menu
KActionMenu *closedTabsMenu = new KActionMenu(KIcon("tab-new"), i18n("Closed Tabs"), this);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 2b413900..04a59a14 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -3,7 +3,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
* Copyright (C) 2010 by Matthieu Gicquel <matgic78 at gmail dot com>
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp
index 0372aad3..00c7f81d 100644
--- a/src/newtabpage.cpp
+++ b/src/newtabpage.cpp
@@ -81,6 +81,7 @@ NewTabPage::NewTabPage(QWebFrame *frame)
void NewTabPage::generate(const KUrl &url)
{
+ // about:preview links
if (KUrl("about:preview").isParentOf(url))
{
if (url.fileName() == QL1S("add"))
@@ -113,6 +114,7 @@ void NewTabPage::generate(const KUrl &url)
}
}
+ // about:tabs links
if (KUrl("about:tabs").isParentOf(url))
{
if (url.fileName() == QL1S("show"))
@@ -133,6 +135,7 @@ void NewTabPage::generate(const KUrl &url)
w->raise();
return;
}
+
if (url.fileName() == QL1S("remove"))
{
const int winIndex = url.queryItem(QL1S("win")).toInt();
@@ -147,6 +150,19 @@ void NewTabPage::generate(const KUrl &url)
}
}
+ // about:closedTabs links
+ if (KUrl("about:closedTabs").isParentOf(url))
+ {
+ if (url.fileName() == QL1S("restore"))
+ {
+ const int tabIndex = url.queryItem(QL1S("tab")).toInt();
+ kDebug() << "tab = " << tabIndex;
+
+ rApp->mainWindow()->mainView()->restoreClosedTab(tabIndex, false);
+ return;
+ }
+ }
+
if (url == KUrl("about:downloads/clear"))
{
rApp->downloadManager()->clearDownloadsHistory();
@@ -407,6 +423,7 @@ void NewTabPage::closedTabsPage()
QList<TabHistory> links = rApp->mainWindow()->mainView()->recentlyClosedTabs();
+ kDebug() << "CLOSED TABS: " << links.count();
if (links.isEmpty())
{
m_root.addClass(QL1S("empty"));
@@ -417,12 +434,13 @@ void NewTabPage::closedTabsPage()
for (int i = 0; i < links.count(); ++i)
{
TabHistory item = links.at(i);
+ kDebug() << "URL " << i << " : " << item.url;
QWebElement prev;
if (item.url.isEmpty())
continue;
- prev = validPreview(i, item.url, item.title);
+ prev = closedTabPreview(i, item.url, item.title);
prev.setAttribute(QL1S("id"), QL1S("preview") + QVariant(i).toString());
hideControls(prev);
@@ -543,7 +561,6 @@ QWebElement NewTabPage::emptyPreview(int index)
QL1S("about:preview/modify/") + QVariant(index).toString());
setupPreview(prev, index);
- //hideControls(prev);
return prev;
}
@@ -570,6 +587,39 @@ QWebElement NewTabPage::emptyPreview(int index)
// connect(snap, SIGNAL(snapDone(bool)), frame->page(), SLOT(updateImage(bool)), Qt::UniqueConnection);
// return prev;
// }
+//
+//
+// void NewTabPage::updateThumbs()
+// {
+// // Update page, but only if open
+// if (m_root.document().findAll(QL1S("#rekonq-newtabpage")).count() == 0)
+// return;
+// if (m_root.findAll(QL1S(".favorites")).count() == 0 && m_root.findAll(QL1S(".closedTabs")).count() == 0)
+// return;
+//
+// QStringList urls = ReKonfig::previewUrls();
+// QStringList names = ReKonfig::previewNames();
+//
+// for (int i = 0; i < urls.count(); i++)
+// {
+// KUrl url = KUrl(urls.at(i));
+// QString title = names.at(i);
+//
+// if (WebSnap::existsImage(url))
+// {
+// QWebElement prev = m_root.findFirst(QL1S("#preview") + QVariant(i).toString());
+// if (KUrl(prev.findFirst("a").attribute(QL1S("href"))) == url)
+// {
+// QWebElement newPrev = validPreview(i, url, title);
+//
+// if (m_root.findAll(QL1S(".closedTabs")).count() != 0)
+// hideControls(newPrev);
+//
+// prev.replace(newPrev);
+// }
+// }
+// }
+// }
QWebElement NewTabPage::validPreview(int index, const KUrl &url, const QString &title)
@@ -611,6 +661,28 @@ QWebElement NewTabPage::tabPreview(int winIndex, int tabIndex, const KUrl &url,
}
+QWebElement NewTabPage::closedTabPreview(int index, const KUrl &url, const QString &title)
+{
+ QWebElement prev = markup(QL1S(".thumbnail"));
+
+ QString previewPath = WebSnap::existsImage(url)
+ ? QL1S("file://") + WebSnap::imagePathFromUrl(url)
+ : rApp->iconManager()->iconPathForUrl(url)
+ ;
+
+ QString href = QL1S("about:closedTabs/restore?tab=") + QString::number(index);
+
+ prev.findFirst(QL1S(".preview img")).setAttribute(QL1S("src") , previewPath);
+ prev.findFirst(QL1S("a")).setAttribute(QL1S("href"), href);
+ prev.findFirst(QL1S("span a")).setAttribute(QL1S("href"), href);
+ prev.findFirst(QL1S("span a")).setPlainText(checkTitle(title));
+
+ setupPreview(prev, index);
+ showControls(prev);
+ return prev;
+}
+
+
void NewTabPage::hideControls(QWebElement e)
{
e.findFirst(QL1S(".remove")).setStyleProperty(QL1S("visibility"), QL1S("hidden"));
@@ -651,39 +723,6 @@ void NewTabPage::setupTabPreview(QWebElement e, int winIndex, int tabIndex)
}
-void NewTabPage::updateThumbs()
-{
- // Update page, but only if open
- if (m_root.document().findAll(QL1S("#rekonq-newtabpage")).count() == 0)
- return;
- if (m_root.findAll(QL1S(".favorites")).count() == 0 && m_root.findAll(QL1S(".closedTabs")).count() == 0)
- return;
-
- QStringList urls = ReKonfig::previewUrls();
- QStringList names = ReKonfig::previewNames();
-
- for (int i = 0; i < urls.count(); i++)
- {
- KUrl url = KUrl(urls.at(i));
- QString title = names.at(i);
-
- if (WebSnap::existsImage(url))
- {
- QWebElement prev = m_root.findFirst(QL1S("#preview") + QVariant(i).toString());
- if (KUrl(prev.findFirst("a").attribute(QL1S("href"))) == url)
- {
- QWebElement newPrev = validPreview(i, url, title);
-
- if (m_root.findAll(QL1S(".closedTabs")).count() != 0)
- hideControls(newPrev);
-
- prev.replace(newPrev);
- }
- }
- }
-}
-
-
void NewTabPage::removePreview(int index)
{
QStringList names = ReKonfig::previewNames();
diff --git a/src/newtabpage.h b/src/newtabpage.h
index 40627c6c..b4f3bcd6 100644
--- a/src/newtabpage.h
+++ b/src/newtabpage.h
@@ -57,12 +57,6 @@ public:
*/
void generate(const KUrl &url = KUrl("about:home"));
- /**
- * This method updates thumbs, removing loading previews
- * and providing a real picture
- */
- void updateThumbs();
-
private:
// these are the "high-level" functions to build the new tab page.
// Basically, you call browsingMenu + one of the *Page methods
@@ -84,6 +78,7 @@ private:
QWebElement emptyPreview(int index);
QWebElement validPreview(int index, const KUrl &url, const QString &title);
QWebElement tabPreview(int winIndex, int tabIndex, const KUrl &url, const QString &title);
+ QWebElement closedTabPreview(int index, const KUrl &url, const QString &title);
void removePreview(int index);
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 1634f284..4834095a 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -3,7 +3,7 @@
* This file is a part of the rekonq project
*
* Copyright (C) 2008 Benjamin C. Meyer <ben@meyerhome.net>
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
@@ -380,26 +380,28 @@ void TabBar::setupHistoryActions()
MainView *mv = qobject_cast<MainView *>(parent());
QAction *openLastClosedTabAction = w->actionByName(QL1S("open_last_closed_tab"));
- openLastClosedTabAction->setEnabled(mv->recentlyClosedTabs().size() > 0);
+
+ bool closedTabsAvailable = (mv->recentlyClosedTabs().size() > 0);
+ openLastClosedTabAction->setEnabled(closedTabsAvailable);
// update closed tabs menu
KActionMenu *am = qobject_cast<KActionMenu *>(w->actionByName(QL1S("closed_tab_menu")));
if (!am)
return;
- bool isEnabled = (mv->recentlyClosedTabs().size() > 0);
- am->setEnabled(isEnabled);
+ am->setEnabled(closedTabsAvailable);
if (am->menu())
am->menu()->clear();
- if (!isEnabled)
+ if (!closedTabsAvailable)
return;
- Q_FOREACH(const TabHistory & item, mv->recentlyClosedTabs())
+ for (int i = 0; i < mv->recentlyClosedTabs().count(); ++i)
{
+ TabHistory item = mv->recentlyClosedTabs().at(i);
KAction *a = new KAction(rApp->iconManager()->iconForUrl(item.url), item.title, this);
- a->setData(item.history);
+ a->setData(i);
connect(a, SIGNAL(triggered()), mv, SLOT(openClosedTab()));
am->addAction(a);
}
diff --git a/src/tabbar.h b/src/tabbar.h
index 78d48cdb..c536039b 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -3,7 +3,7 @@
* This file is a part of the rekonq project
*
* Copyright (C) 2008 Benjamin C. Meyer <ben@meyerhome.net>
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
diff --git a/src/webtab.cpp b/src/webtab.cpp
index 0dd2ac44..9516f83c 100644
--- a/src/webtab.cpp
+++ b/src/webtab.cpp
@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
*
diff --git a/src/webtab.h b/src/webtab.h
index 4e13cef9..c3d3099b 100644
--- a/src/webtab.h
+++ b/src/webtab.h
@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2011 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
*
@@ -90,6 +90,7 @@ public:
{
return m_part;
}
+
void setPart(KParts::ReadOnlyPart *p, const KUrl &u);
void showMessageBar();