1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Added option "Don't load tabs until selected" when restoring session.

This commit is contained in:
nowrep 2012-03-11 15:17:12 +01:00
parent 4dc7095d6e
commit efab78ae5e
10 changed files with 500 additions and 317 deletions

View File

@ -627,12 +627,11 @@ void BookmarksManager::insertAllTabs()
}
foreach(WebTab * tab, getQupZilla()->tabWidget()->allTabs(false)) {
TabbedWebView* view = tab->view();
if (view->url().isEmpty()) {
if (tab->url().isEmpty()) {
continue;
}
m_bookmarksModel->saveBookmark(view->url(), view->title(), view->icon(), BookmarksModel::fromTranslatedFolder(combo->currentText()));
m_bookmarksModel->saveBookmark(tab->url(), tab->title(), tab->icon(), BookmarksModel::fromTranslatedFolder(combo->currentText()));
}
delete dialog;

View File

@ -101,6 +101,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
settings.endGroup();
ui->afterLaunch->setCurrentIndex(afterLaunch);
ui->checkUpdates->setChecked(settings.value("Web-Browser-Settings/CheckUpdates", DEFAULT_CHECK_UPDATES).toBool());
ui->dontLoadTabsUntilSelected->setChecked(settings.value("Web-Browser-Settings/LoadTabsOnActivation", false).toBool());
ui->newTabFrame->setVisible(false);
if (m_newTabUrl.isEmpty()) {
@ -788,6 +789,7 @@ void Preferences::saveSettings()
settings.setValue("wheelScrollLines", ui->wheelScroll->value());
settings.setValue("DoNotTrack", ui->doNotTrack->isChecked());
settings.setValue("CheckUpdates", ui->checkUpdates->isChecked());
settings.setValue("LoadTabsOnActivation", ui->dontLoadTabsUntilSelected->isChecked());
settings.setValue("DefaultZoom", ui->defaultZoom->value());
settings.setValue("XSSAuditing", ui->xssAuditing->isChecked());
settings.setValue("UserAgent", ui->changeUserAgent->isChecked() ? ui->userAgentCombo->currentText() : "");

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>829</width>
<height>484</height>
<height>496</height>
</rect>
</property>
<property name="windowTitle">
@ -292,24 +292,24 @@
</item>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;b&gt;Profiles&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Startup profile:</string>
</property>
</widget>
</item>
<item row="8" column="2">
<item row="9" column="2">
<widget class="QComboBox" name="startProfile"/>
</item>
<item row="9" column="1" colspan="3">
<item row="10" column="1" colspan="3">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
@ -391,42 +391,42 @@
</layout>
</widget>
</item>
<item row="5" column="1" colspan="2">
<item row="6" column="1" colspan="2">
<widget class="QCheckBox" name="checkUpdates">
<property name="text">
<string>Check for updates on start</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QLabel" name="label_45">
<property name="text">
<string>Active profile:</string>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="8" column="2">
<widget class="QLabel" name="activeProfile">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="15" column="1" colspan="2">
<item row="16" column="1" colspan="2">
<widget class="QLabel" name="label_17">
<property name="text">
<string>In order to change language, you must restart browser.</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="3">
<item row="12" column="0" colspan="3">
<widget class="QLabel" name="label_11">
<property name="text">
<string>&lt;b&gt;Language&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="13" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_16">
@ -449,10 +449,10 @@
</item>
</layout>
</item>
<item row="12" column="2">
<item row="13" column="2">
<widget class="QComboBox" name="languages"/>
</item>
<item row="10" column="1">
<item row="11" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -465,6 +465,13 @@
</property>
</spacer>
</item>
<item row="5" column="1" colspan="2">
<widget class="QCheckBox" name="dontLoadTabsUntilSelected">
<property name="text">
<string>Don't load tabs until selected</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="stackedWidgetPage2">
@ -1690,7 +1697,112 @@
</widget>
<widget class="QWidget" name="stackedWidgetPage6">
<layout class="QGridLayout" name="gridLayout_12">
<item row="5" column="0">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="26" column="1" colspan="4">
<widget class="QCheckBox" name="jscanAccessClipboard">
<property name="text">
<string>JavaScript can access clipboard</string>
</property>
</widget>
</item>
<item row="25" column="1" colspan="4">
<widget class="QCheckBox" name="blockPopup">
<property name="text">
<string>Block popup windows</string>
</property>
</widget>
</item>
<item row="20" column="1" colspan="4">
<widget class="QCheckBox" name="sendReferer">
<property name="text">
<string>Send Referer header to servers</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="3">
<widget class="QCheckBox" name="filterTracking">
<property name="text">
<string>Filter tracking cookies</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="5">
<widget class="QLabel" name="label_12">
<property name="text">
<string>&lt;b&gt;Cookies&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="4">
<widget class="QCheckBox" name="saveCookies">
<property name="text">
<string>Allow storing of cookies</string>
</property>
</widget>
</item>
<item row="13" column="0">
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="12" column="1" colspan="4">
<widget class="QCheckBox" name="matchExactly">
<property name="text">
<string>Match domain exactly</string>
</property>
</widget>
</item>
<item row="21" column="1" colspan="4">
<widget class="QCheckBox" name="doNotTrack">
<property name="text">
<string>Send Do Not Track header to servers</string>
</property>
</widget>
</item>
<item row="18" column="0" colspan="5">
<widget class="QLabel" name="label_50">
<property name="text">
<string>&lt;b&gt;Other&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="17" column="0" colspan="4">
<widget class="QLabel" name="label_49">
<property name="text">
<string>Edit CA certificates in SSL Manager</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="4">
<spacer name="horizontalSpacer_22">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="28" column="0" colspan="5">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -1703,177 +1815,71 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_12">
<property name="text">
<string>&lt;b&gt;Cookies&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QCheckBox" name="filterTracking">
<property name="text">
<string>Filter tracking cookies</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QCheckBox" name="saveCookies">
<property name="text">
<string>Allow storing of cookies</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="deleteCookiesOnClose">
<property name="text">
<string>Delete cookies on close</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QCheckBox" name="matchExactly">
<property name="text">
<string>Match domain exactly</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="4">
<widget class="QLabel" name="label_19">
<property name="text">
<string>&lt;b&gt;Warning:&lt;/b&gt; Match domain exactly and filter tracking cookies options can lead to deny some cookies from sites. If you have problems with cookies, try to disable this options first!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QPushButton" name="cookieManagerBut">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cookies Manager</string>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0" colspan="4">
<widget class="QLabel" name="label_48">
<property name="text">
<string>&lt;b&gt;SSL Certificates&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="7" column="3">
<widget class="QPushButton" name="sslManagerButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SSL Manager</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="QLabel" name="label_49">
<property name="text">
<string>Edit CA certificates in SSL Manager</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<spacer name="horizontalSpacer_22">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="1" colspan="3">
<widget class="QCheckBox" name="jscanAccessClipboard">
<property name="text">
<string>JavaScript can access clipboard</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="4">
<widget class="QLabel" name="label_50">
<property name="text">
<string>&lt;b&gt;Other&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="3">
<widget class="QCheckBox" name="doNotTrack">
<property name="text">
<string>Send Do Not Track header to servers</string>
</property>
</widget>
</item>
<item row="12" column="1" colspan="3">
<widget class="QCheckBox" name="sendReferer">
<property name="text">
<string>Send Referer header to servers</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="3">
<widget class="QCheckBox" name="blockPopup">
<property name="text">
<string>Block popup windows</string>
</property>
</widget>
</item>
</layout>
<item row="13" column="4">
<widget class="QPushButton" name="cookieManagerBut">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cookies Manager</string>
</property>
</widget>
</item>
<item row="17" column="4">
<widget class="QPushButton" name="sslManagerButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SSL Manager</string>
</property>
</widget>
</item>
<item row="10" column="2" colspan="2">
<widget class="QCheckBox" name="deleteCookiesOnClose">
<property name="text">
<string>Delete cookies on close</string>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="15" column="0" colspan="5">
<widget class="QLabel" name="label_48">
<property name="text">
<string>&lt;b&gt;SSL Certificates&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="14" column="0" colspan="5">
<widget class="QLabel" name="label_19">
<property name="text">
<string>&lt;b&gt;Warning:&lt;/b&gt; Match domain exactly and filter tracking cookies options can lead to deny some cookies from sites. If you have problems with cookies, try to disable this options first!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
@ -2184,11 +2190,6 @@
<tabstop>closeDownManOnFinish</tabstop>
<tabstop>downlaodNativeSystemDialog</tabstop>
<tabstop>allowPassManager</tabstop>
<tabstop>saveCookies</tabstop>
<tabstop>deleteCookiesOnClose</tabstop>
<tabstop>matchExactly</tabstop>
<tabstop>filterTracking</tabstop>
<tabstop>cookieManagerBut</tabstop>
<tabstop>useOSDNotifications</tabstop>
<tabstop>useNativeSystemNotifications</tabstop>
<tabstop>doNotUseNotifications</tabstop>

View File

@ -289,7 +289,9 @@ void TabBar::bookmarkTab()
return;
}
p_QupZilla->addBookmark(view->url(), view->title(), view->icon());
WebTab* tab = view->webTab();
p_QupZilla->addBookmark(tab->url(), tab->title(), tab->icon());
}
void TabBar::pinTab()
@ -434,7 +436,10 @@ void TabBar::dropEvent(QDropEvent* event)
}
}
else {
p_QupZilla->weView(index)->load(mime->urls().first());
WebTab* tab = p_QupZilla->weView(index)->webTab();
if (tab->isRestored()) {
tab->view()->load(mime->urls().first());
}
}
}

View File

@ -150,20 +150,14 @@ void TabWidget::resizeEvent(QResizeEvent* e)
QTabWidget::resizeEvent(e);
}
TabbedWebView* TabWidget::weView()
WebTab* TabWidget::weTab()
{
return weView(currentIndex());
return weTab(currentIndex());
}
TabbedWebView* TabWidget::weView(int index)
WebTab* TabWidget::weTab(int index)
{
WebTab* webTab = qobject_cast<WebTab*>(widget(index));
if (!webTab) {
return 0;
}
return webTab->view();
return qobject_cast<WebTab*>(widget(index));
}
void TabWidget::createKeyPressEvent(QKeyEvent* event)
@ -192,24 +186,24 @@ void TabWidget::moveAddTabButton(int posX)
void TabWidget::aboutToShowTabsMenu()
{
m_menuTabs->clear();
TabbedWebView* actView = weView();
if (!actView) {
WebTab* actTab = weTab();
if (!actTab) {
return;
}
for (int i = 0; i < count(); i++) {
TabbedWebView* view = weView(i);
if (!view) {
WebTab* tab = weTab(i);
if (!tab) {
continue;
}
QAction* action = new QAction(this);
if (view == actView) {
if (tab == actTab) {
action->setIcon(QIcon(":/icons/menu/dot.png"));
}
else {
action->setIcon(view->icon());
action->setIcon(tab->icon());
}
if (view->title().isEmpty()) {
if (view->isLoading()) {
if (tab->title().isEmpty()) {
if (tab->isLoading()) {
action->setText(tr("Loading..."));
action->setIcon(QIcon(":/icons/other/progress.gif"));
}
@ -218,7 +212,7 @@ void TabWidget::aboutToShowTabsMenu()
}
}
else {
QString title = view->title();
QString title = tab->title();
title.replace("&", "&&");
if (title.length() > 40) {
title.truncate(40);
@ -288,7 +282,7 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
index = insertTab(position, new WebTab(p_QupZilla, locBar), "");
}
TabbedWebView* webView = weView(index);
TabbedWebView* webView = weTab(index)->view();
locBar->setWebView(webView);
setTabText(index, title);
@ -335,14 +329,15 @@ void TabWidget::closeTab(int index)
index = currentIndex();
}
TabbedWebView* webView = weView(index);
WebPage* webPage = webView->webPage();
WebTab* webTab = webView->webTab();
if (!webView || !webPage || !webTab) {
WebTab* webTab = weTab(index);
if (!webTab) {
return;
}
TabbedWebView* webView = webTab->view();
WebPage* webPage = webView->webPage();
if (count() == 1) {
if (m_dontQuitWithOneTab) {
webView->load(m_urlOnNewTab);
@ -391,13 +386,14 @@ void TabWidget::currentTabChanged(int index)
m_isClosingToLastTabIndex = false;
m_lastBackgroundTabIndex = -1;
TabbedWebView* webView = weView();
LocationBar* locBar = webView->webTab()->locationBar();
WebTab* webTab = weTab(index);
LocationBar* locBar = webTab->locationBar();
if (m_locationBars->indexOf(locBar) != -1) {
m_locationBars->setCurrentWidget(locBar);
}
webTab->setCurrentTab();
p_QupZilla->currentTabChanged();
m_tabBar->updateCloseButton(index);
}
@ -416,7 +412,7 @@ void TabWidget::setTabText(int index, const QString &text)
QString newtext = text;
newtext.replace("&", "&&"); // Avoid Alt+letter shortcuts
if (WebTab* webTab = qobject_cast<WebTab*>(p_QupZilla->tabWidget()->widget(index))) {
if (WebTab* webTab = weTab(index)) {
if (webTab->isPinned()) {
newtext = "";
}
@ -427,7 +423,7 @@ void TabWidget::setTabText(int index, const QString &text)
void TabWidget::reloadTab(int index)
{
weView(index)->reload();
weTab(index)->reload();
}
void TabWidget::showTabBar()
@ -449,44 +445,37 @@ void TabWidget::reloadAllTabs()
void TabWidget::stopTab(int index)
{
weView(index)->stop();
}
void TabWidget::backTab(int index)
{
weView(index)->back();
}
void TabWidget::forwardTab(int index)
{
weView(index)->forward();
weTab(index)->stop();
}
void TabWidget::closeAllButCurrent(int index)
{
WebTab* akt = qobject_cast<WebTab*>(widget(index));
WebTab* akt = weTab(index);
foreach(WebTab * tab, allTabs(false)) {
if (akt == widget(tab->view()->tabIndex())) {
int tabIndex = tab->tabIndex();
if (akt == widget(tabIndex)) {
continue;
}
closeTab(tab->view()->tabIndex());
closeTab(tabIndex);
}
}
int TabWidget::duplicateTab(int index)
{
const QUrl &url = weView(index)->url();
WebView* view = weTab(index)->view();
const QUrl &url = view->url();
QByteArray history;
QDataStream tabHistoryStream(&history, QIODevice::WriteOnly);
tabHistoryStream << *weView(index)->history();
tabHistoryStream << *view->history();
QNetworkRequest req(url);
req.setRawHeader("Referer", url.toEncoded());
int id = addView(req, tabText(index), Qz::NT_CleanNotSelectedTab);
QDataStream historyStream(history);
historyStream >> *weView(id)->history();
historyStream >> *view->history();
return id;
}
@ -508,10 +497,8 @@ void TabWidget::restoreClosedTab()
}
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab, false, tab.position);
QDataStream historyStream(tab.history);
historyStream >> *weView(index)->history();
weView(index)->load(tab.url);
WebTab* webTab = weTab(index);
webTab->p_restoreTab(tab.url, tab.history);
}
void TabWidget::restoreAllClosedTabs()
@ -524,10 +511,8 @@ void TabWidget::restoreAllClosedTabs()
foreach(const ClosedTabsManager::Tab & tab, closedTabs) {
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab);
QDataStream historyStream(tab.history);
historyStream >> *weView(index)->history();
weView(index)->load(tab.url);
WebTab* webTab = weTab(index);
webTab->p_restoreTab(tab.url, tab.history);
}
m_closedTabsManager->clearList();
@ -576,15 +561,18 @@ QList<WebTab*> TabWidget::allTabs(bool withPinned)
QList<WebTab*> allTabs;
for (int i = 0; i < count(); i++) {
WebTab* tab = qobject_cast<WebTab*>(widget(i));
WebTab* tab = weTab(i);
if (!tab || (!withPinned && tab->isPinned())) {
continue;
}
allTabs.append(tab);
}
return allTabs;
}
static const qint32 TabWidgetFileVersion = 0xaaf;
void TabWidget::savePinnedTabs()
{
QByteArray data;
@ -593,9 +581,8 @@ void TabWidget::savePinnedTabs()
QStringList tabs;
QList<QByteArray> tabsHistory;
for (int i = 0; i < count(); ++i) {
if (TabbedWebView* tab = weView(i)) {
WebTab* webTab = qobject_cast<WebTab*>(widget(i));
if (!webTab || !webTab->isPinned()) {
if (WebTab* tab = weTab(i)) {
if (!tab->isPinned()) {
continue;
}
@ -645,16 +632,18 @@ void TabWidget::restorePinnedTabs()
QByteArray historyState = tabHistory.value(i);
int addedIndex;
if (!historyState.isEmpty()) {
addedIndex = addView(QUrl(), Qz::NT_CleanSelectedTab);
QDataStream historyStream(historyState);
historyStream >> *weView(addedIndex)->history();
weView(addedIndex)->load(url);
weTab(i)->p_restoreTab(url, historyState);
}
else {
addedIndex = addView(url);
}
WebTab* webTab = qobject_cast<WebTab*>(widget(addedIndex));
WebTab* webTab = weTab(addedIndex);
if (webTab) {
webTab->setPinned(true);
emit pinnedTabAdded();
@ -667,72 +656,64 @@ void TabWidget::restorePinnedTabs()
QByteArray TabWidget::saveState()
{
QList<WebTab::SavedTab> tabList;
for (int i = 0; i < count(); ++i) {
WebTab* webTab = weTab(i);
if (!webTab || webTab->isPinned()) {
continue;
}
WebTab::SavedTab tab(webTab);
tabList.append(tab);
}
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
QStringList tabs;
QList<QByteArray> tabsHistory;
for (int i = 0; i < count(); ++i) {
if (TabbedWebView* tab = weView(i)) {
WebTab* webTab = qobject_cast<WebTab*>(widget(i));
if (webTab && webTab->isPinned()) {
continue;
}
stream << TabWidgetFileVersion;
stream << tabList.count();
tabs.append(tab->url().toEncoded());
if (tab->history()->count() != 0) {
QByteArray tabHistory;
QDataStream tabHistoryStream(&tabHistory, QIODevice::WriteOnly);
tabHistoryStream << *tab->history();
tabsHistory.append(tabHistory);
}
else {
tabsHistory << QByteArray();
}
}
else {
tabs.append(QString::null);
tabsHistory.append(QByteArray());
}
foreach(const WebTab::SavedTab & tab, tabList) {
stream << tab;
}
stream << tabs;
stream << currentIndex();
stream << tabsHistory;
return data;
}
bool TabWidget::restoreState(const QByteArray &state)
bool TabWidget::restoreState(QByteArray &state)
{
QByteArray sd = state;
QDataStream stream(&sd, QIODevice::ReadOnly);
QDataStream stream(&state, QIODevice::ReadOnly);
if (stream.atEnd()) {
return false;
}
QStringList openTabs;
int currentTab;
QList<QByteArray> tabHistory;
stream >> openTabs;
stream >> currentTab;
stream >> tabHistory;
qint32 fileVersion = 0;
int tabListCount = 0;
int currentTab = 0;
for (int i = 0; i < openTabs.count(); ++i) {
QUrl url = QUrl::fromEncoded(openTabs.at(i).toUtf8());
stream >> fileVersion;
stream >> tabListCount;
QByteArray historyState = tabHistory.value(i);
if (!historyState.isEmpty()) {
int index = addView(QUrl(), Qz::NT_CleanSelectedTab);
QDataStream historyStream(historyState);
historyStream >> *weView(index)->history();
weView(index)->load(url);
}
else {
addView(url);
}
if (fileVersion != TabWidgetFileVersion) {
return false;
}
for (int i = 0; i < tabListCount; ++i) {
WebTab::SavedTab tab;
stream >> tab;
int index = addView(QUrl(), Qz::NT_CleanSelectedTab);
weTab(index)->restoreTab(tab);
}
stream >> currentTab;
setCurrentIndex(currentTab);
currentTabChanged(currentTab);
return true;
}

View File

@ -56,7 +56,7 @@ public:
~TabWidget();
QByteArray saveState();
bool restoreState(const QByteArray &state);
bool restoreState(QByteArray &state);
void savePinnedTabs();
void restorePinnedTabs();
@ -113,8 +113,9 @@ private slots:
private:
void resizeEvent(QResizeEvent* e);
inline TabbedWebView* weView();
inline TabbedWebView* weView(int index);
WebTab* weTab();
WebTab* weTab(int index);
bool m_hideTabBarWithOneTab;
bool m_dontQuitWithOneTab;

View File

@ -22,8 +22,57 @@
#include "tabbar.h"
#include "tabwidget.h"
#include "locationbar.h"
#include "globalfunctions.h"
#include "webviewsettings.h"
#include <QVBoxLayout>
#include <QWebHistory>
#include <QLabel>
WebTab::SavedTab::SavedTab(WebTab* webTab)
{
if (webTab->isRestored()) {
WebView* view = webTab->view();
title = view->title();
url = view->url();
icon = view->icon();
QDataStream historyStream(&history, QIODevice::WriteOnly);
historyStream << *view->history();
}
else {
*this = webTab->savedTab();
}
}
void WebTab::SavedTab::clear()
{
title.clear();
url.clear();
icon = QIcon();
history.clear();
}
QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab)
{
stream << tab.title;
stream << tab.url;
stream << tab.icon;
stream << tab.history;
return stream;
}
QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
{
stream >> tab.title;
stream >> tab.url;
stream >> tab.icon;
stream >> tab.history;
return stream;
}
WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
: QWidget()
@ -54,12 +103,71 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
connect(m_locationBar.data(), SIGNAL(loadUrl(QUrl)), m_view, SLOT(load(QUrl)));
}
TabbedWebView* WebTab::view()
TabbedWebView* WebTab::view() const
{
return m_view;
}
bool WebTab::isPinned()
void WebTab::setCurrentTab()
{
if (!isRestored()) {
p_restoreTab(m_savedTab);
m_savedTab.clear();
}
}
QUrl WebTab::url() const
{
if (isRestored()) {
return m_view->url();
}
else {
return m_savedTab.url;
}
}
QString WebTab::title() const
{
if (isRestored()) {
return m_view->title();
}
else {
return m_savedTab.title;
}
}
QIcon WebTab::icon() const
{
if (isRestored()) {
return m_view->icon();
}
else {
return m_savedTab.icon;
}
}
QWebHistory* WebTab::history() const
{
return m_view->history();
}
void WebTab::reload()
{
m_view->reload();
}
void WebTab::stop()
{
m_view->stop();
}
bool WebTab::isLoading() const
{
return m_view->isLoading();
}
bool WebTab::isPinned() const
{
return m_pinned;
}
@ -74,12 +182,12 @@ void WebTab::setLocationBar(LocationBar* bar)
m_locationBar = bar;
}
LocationBar* WebTab::locationBar()
LocationBar* WebTab::locationBar() const
{
return m_locationBar.data();
}
bool WebTab::inspectorVisible()
bool WebTab::inspectorVisible() const
{
return m_inspectorVisible;
}
@ -89,6 +197,45 @@ void WebTab::setInspectorVisible(bool v)
m_inspectorVisible = v;
}
WebTab::SavedTab WebTab::savedTab() const
{
return m_savedTab;
}
bool WebTab::isRestored() const
{
return m_savedTab.isEmpty();
}
void WebTab::restoreTab(const WebTab::SavedTab &tab)
{
if (WebViewSettings::loadTabsOnActivation) {
m_savedTab = tab;
int index = tabIndex();
m_view->animationLoading(index, false)->setPixmap(tab.icon.pixmap(16, 16));
m_view->tabWidget()->setTabText(index, tab.title);
m_locationBar.data()->showUrl(tab.url);
}
else {
p_restoreTab(tab);
}
}
void WebTab::p_restoreTab(const QUrl &url, const QByteArray &history)
{
QDataStream historyStream(history);
historyStream >> *m_view->history();
m_view->load(url);
}
void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
{
p_restoreTab(tab.url, tab.history);
}
void WebTab::showNotification(QWidget* notif)
{
if (m_layout->count() > 1) {
@ -99,7 +246,7 @@ void WebTab::showNotification(QWidget* notif)
notif->show();
}
int WebTab::tabIndex()
int WebTab::tabIndex() const
{
return m_view->tabIndex();
}

View File

@ -20,45 +20,87 @@
#include <QWidget>
#include <QWeakPointer>
#include <QIcon>
#include <QUrl>
#include "qz_namespace.h"
class QVBoxLayout;
class QWebHistory;
class QupZilla;
class LocationBar;
class WebView;
class TabbedWebView;
class QT_QUPZILLA_EXPORT WebTab : public QWidget
{
Q_OBJECT
public:
struct SavedTab {
QString title;
QUrl url;
QIcon icon;
QByteArray history;
SavedTab() { }
SavedTab(WebTab* webTab);
bool isEmpty() const { return url.isEmpty(); }
void clear();
friend QT_QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab);
friend QT_QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab);
};
explicit WebTab(QupZilla* mainClass, LocationBar* locationBar);
~WebTab();
TabbedWebView* view();
bool isPinned();
TabbedWebView* view() const;
void setCurrentTab();
QUrl url() const;
QString title() const;
QIcon icon() const;
QWebHistory* history() const;
void reload();
void stop();
bool isLoading() const;
bool isPinned() const;
void pinTab(int index);
void setPinned(bool state);
void setLocationBar(LocationBar* bar);
LocationBar* locationBar();
int tabIndex() const;
bool inspectorVisible();
void setLocationBar(LocationBar* bar);
LocationBar* locationBar() const;
bool inspectorVisible() const;
void setInspectorVisible(bool v);
SavedTab savedTab() const;
bool isRestored() const;
void restoreTab(const SavedTab &tab);
void p_restoreTab(const SavedTab &tab);
void p_restoreTab(const QUrl &url, const QByteArray &history);
void disconnectObjects();
private slots:
void showNotification(QWidget* notif);
private:
int tabIndex();
QupZilla* p_QupZilla;
TabbedWebView* m_view;
QVBoxLayout* m_layout;
QWeakPointer<LocationBar> m_locationBar;
SavedTab m_savedTab;
bool m_pinned;
bool m_inspectorVisible;
};

View File

@ -2,6 +2,7 @@
#include "settings.h"
int WebViewSettings::defaultZoom = 100;
bool WebViewSettings::loadTabsOnActivation = false;
WebViewSettings::WebViewSettings()
{
@ -11,7 +12,10 @@ void WebViewSettings::loadSettings()
{
Settings settings;
settings.beginGroup("Web-Browser-Settings");
defaultZoom = settings.value("DefaultZoom", 100).toInt();
loadTabsOnActivation = settings.value("LoadTabsOnActivation", false).toBool();
settings.endGroup();
}

View File

@ -11,6 +11,7 @@ public:
static void loadSettings();
static int defaultZoom;
static bool loadTabsOnActivation;
};
#endif // WEBVIEWSETTINGS_H