diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp
index 77c65266..b81744bb 100644
--- a/src/app/qupzilla.cpp
+++ b/src/app/qupzilla.cpp
@@ -1,1169 +1,1169 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#include "qupzilla.h"
#include "tabwidget.h"
#include "tabbar.h"
#include "webpage.h"
#include "webview.h"
#include "lineedit.h"
#include "historymodel.h"
#include "locationbar.h"
#include "searchtoolbar.h"
#include "websearchbar.h"
#include "downloadmanager.h"
#include "cookiejar.h"
#include "cookiemanager.h"
#include "bookmarksmanager.h"
#include "bookmarkstoolbar.h"
#include "clearprivatedata.h"
#include "sourceviewer.h"
#include "siteinfo.h"
#include "preferences.h"
#include "networkmanager.h"
#include "autofillmodel.h"
#include "networkmanagerproxy.h"
#include "rssmanager.h"
#include "mainapplication.h"
#include "aboutdialog.h"
#include "pluginproxy.h"
#include "qtwin.h"
#include "ui_closedialog.h"
#include "adblockmanager.h"
#include "clickablelabel.h"
#include "docktitlebarwidget.h"
#include "sidebar.h"
#include "iconprovider.h"
#include "progressbar.h"
#include "adblockicon.h"
#include "closedtabsmanager.h"
#include "statusbarmessage.h"
#include "locationbarsettings.h"
#include "browsinglibrary.h"
#include "navigationbar.h"
#include "pagescreen.h"
#include "webinspectordockwidget.h"
#include "bookmarksimportdialog.h"
#include "globalfunctions.h"
const QString QupZilla::VERSION = "1.0.0-rc1";
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
const QString QupZilla::AUTHOR = "David Rosca";
const QString QupZilla::COPYRIGHT = "2010-2011";
const QString QupZilla::WWWADDRESS = "http://qupzilla.co.cc";
const QString QupZilla::WIKIADDRESS = "https://github.com/nowrep/QupZilla/wiki";
const QString QupZilla::WEBKITVERSION = qWebKitVersion();
const QIcon QupZilla::qupzillaIcon()
{
QIcon i;
i.addFile(":icons/exeicons/qupzilla16.png");
i.addFile(":icons/exeicons/qupzilla32.png");
i.addFile(":icons/exeicons/qupzilla48.png");
i.addFile(":icons/exeicons/qupzilla64.png");
i.addFile(":icons/exeicons/qupzilla128.png");
i.addFile(":icons/exeicons/qupzilla256.png");
return i;
}
QupZilla::QupZilla(StartBehaviour behaviour, QUrl startUrl)
: QMainWindow(0)
, m_historyMenuChanged(true)
, m_bookmarksMenuChanged(true)
, m_isClosing(false)
, m_startingUrl(startUrl)
, m_startBehaviour(behaviour)
, m_actionPrivateBrowsing(0)
, m_webInspectorDock(0)
, m_sideBar(0)
, m_statusBarMessage(new StatusBarMessage(this))
, m_sideBarWidth(0)
{
setObjectName("mainwindow");
setAttribute(Qt::WA_DeleteOnClose);
setCursor(Qt::ArrowCursor);
this->setWindowTitle("QupZilla");
setUpdatesEnabled(false);
m_activeProfil = mApp->getActiveProfilPath();
m_activeLanguage = mApp->getActiveLanguage();
QDesktopServices::setUrlHandler("http", this, "loadAddress");
setupUi();
setupMenu();
QTimer::singleShot(0, this, SLOT(postLaunch()));
connect(mApp, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(receiveMessage(MainApplication::MessageType,bool)));
}
void QupZilla::postLaunch()
{
loadSettings();
m_tabWidget->restorePinnedTabs();
//Open tab from command line argument
bool addTab = true;
QStringList arguments = qApp->arguments();
for (int i = 0;iarguments().count();i++) {
QString arg = arguments.at(i);
if (arg.startsWith("-url=")) {
m_tabWidget->addView(QUrl(arg.replace("-url=","")));
addTab = false;
}
}
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-URL-Settings");
int afterLaunch = settings.value("afterLaunch",1).toInt();
settings.endGroup();
settings.beginGroup("SessionRestore");
bool startingAfterCrash = settings.value("isCrashed",false).toBool();
settings.endGroup();
QUrl startUrl;
switch (m_startBehaviour) {
case FirstAppWindow:
if (afterLaunch == 0)
startUrl = QUrl("");
else if (afterLaunch == 1)
startUrl = m_homepage;
else
startUrl = m_homepage;
if ( startingAfterCrash || (addTab && afterLaunch == 2) )
addTab = !mApp->restoreStateSlot(this);
break;
case NewWindow:
if (afterLaunch == 0)
startUrl = QUrl("");
else if (afterLaunch == 1)
startUrl = m_homepage;
else
startUrl = m_homepage;
addTab = true;
break;
case OtherRestoredWindow:
addTab = false;
break;
}
if (!m_startingUrl.isEmpty()) {
startUrl = WebView::guessUrlFromString(m_startingUrl.toString());
addTab = true;
}
if (addTab)
m_tabWidget->addView(startUrl);
aboutToShowHistoryMenu(false);
aboutToShowBookmarksMenu();
- if (m_tabWidget->count() == 0) //Something went really wrong .. add one tab
+ if (m_tabWidget->getTabBar()->normalTabsCount() <= 0) //Something went really wrong .. add one tab
m_tabWidget->addView(m_homepage);
setUpdatesEnabled(true);
emit startingCompleted();
}
void QupZilla::setupUi()
{
int locationBarWidth;
int websearchBarWidth;
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
settings.beginGroup("Browser-View-Settings");
if (settings.value("WindowMaximised", false).toBool()) {
resize(800, 550);
setWindowState(Qt::WindowMaximized);
} else {
setGeometry(settings.value("WindowGeometry", QRect(20, 20, 800, 550)).toRect());
}
locationBarWidth = settings.value("LocationBarWidth", 0).toInt();
websearchBarWidth = settings.value("WebSearchBarWidth", 0).toInt();
QWidget* widget = new QWidget(this);
setCentralWidget(widget);
m_mainLayout = new QVBoxLayout(widget);
m_mainLayout->setContentsMargins(0,0,0,0);
m_mainLayout->setSpacing(0);
m_mainSplitter = new QSplitter(this);
m_mainSplitter->setObjectName("sidebar-splitter");
m_mainSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
m_tabWidget = new TabWidget(this);
m_superMenu = new QMenu(this);
m_navigationBar = new NavigationBar(this);
m_navigationBar->setSplitterSizes(locationBarWidth, websearchBarWidth);
m_bookmarksToolbar = new BookmarksToolbar(this);
m_mainSplitter->addWidget(m_tabWidget);
m_mainLayout->addWidget(m_navigationBar);
m_mainLayout->addWidget(m_bookmarksToolbar);
m_mainLayout->addWidget(m_mainSplitter);
m_mainSplitter->setCollapsible(0, false);
statusBar()->setObjectName("mainwindow-statusbar");
m_progressBar = new ProgressBar(statusBar());
m_privateBrowsing = new QLabel(this);
m_privateBrowsing->setPixmap(QPixmap(":/icons/locationbar/privatebrowsing.png"));
m_privateBrowsing->setVisible(false);
m_privateBrowsing->setToolTip(tr("Private Browsing Enabled"));
m_adblockIcon = new AdBlockIcon(this);
m_ipLabel = new QLabel(this);
m_ipLabel->setObjectName("statusbar-ip-label");
m_ipLabel->setToolTip(tr("IP Address of current page"));
statusBar()->insertPermanentWidget(0, m_progressBar);
statusBar()->insertPermanentWidget(1, m_ipLabel);
statusBar()->insertPermanentWidget(2, m_privateBrowsing);
statusBar()->insertPermanentWidget(3, m_adblockIcon);
}
void QupZilla::setupMenu()
{
menuBar()->setObjectName("mainwindow-menubar");
m_menuTools = new QMenu(tr("&Tools"));
m_menuHelp = new QMenu(tr("&Help"));
m_menuBookmarks = new QMenu(tr("&Bookmarks"));
m_menuHistory = new QMenu(tr("Hi&story"));
connect(m_menuHistory, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryMenu()));
connect(m_menuBookmarks, SIGNAL(aboutToShow()), this, SLOT(aboutToShowBookmarksMenu()));
connect(m_menuHelp, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHelpMenu()));
connect(m_menuTools, SIGNAL(aboutToShow()), this, SLOT(aboutToShowToolsMenu()));
m_menuFile = new QMenu(tr("&File"));
m_menuFile->addAction(QIcon::fromTheme("window-new"), tr("&New Window"), this, SLOT(newWindow()))->setShortcut(QKeySequence("Ctrl+N"));
m_menuFile->addAction(QIcon(":/icons/menu/popup.png"), tr("New Tab"), this, SLOT(addTab()))->setShortcut(QKeySequence("Ctrl+T"));
m_menuFile->addAction(tr("Open Location"), this, SLOT(openLocation()))->setShortcut(QKeySequence("Ctrl+L"));
m_menuFile->addAction(QIcon::fromTheme("document-open"), tr("Open &File"), this, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O"));
m_menuFile->addAction(tr("Close Tab"), m_tabWidget, SLOT(closeTab()))->setShortcut(QKeySequence("Ctrl+W"));
m_menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close Window"), this, SLOT(close()))->setShortcut(QKeySequence("Ctrl+Shift+W"));
m_menuFile->addSeparator();
m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), this, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S"));
m_menuFile->addAction(tr("Save Page Screen"), this, SLOT(savePageScreen()));
m_menuFile->addAction(tr("Send Link..."), this, SLOT(sendLink()));
m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print"), this, SLOT(printPage())); m_menuFile->addSeparator();
m_menuFile->addSeparator();
m_menuFile->addAction(tr("Import bookmarks..."), this, SLOT(showBookmarkImport()));
m_menuFile->addAction(QIcon::fromTheme("application-exit"), tr("Quit"), this, SLOT(quitApp()))->setShortcut(QKeySequence("Ctrl+Q"));
menuBar()->addMenu(m_menuFile);
m_menuEdit = new QMenu(tr("&Edit"));
m_menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"))->setShortcut(QKeySequence("Ctrl+Z"));
m_menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
m_menuEdit->addSeparator();
m_menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("&Cut"))->setShortcut(QKeySequence("Ctrl+X"));
m_menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("C&opy"), this, SLOT(copy()))->setShortcut(QKeySequence("Ctrl+C"));
m_menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("&Paste"))->setShortcut(QKeySequence("Ctrl+V"));
m_menuEdit->addAction(QIcon::fromTheme("edit-delete"), tr("&Delete"))->setShortcut(QKeySequence("Del"));
m_menuEdit->addSeparator();
m_menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &All"), this, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
m_menuEdit->addSeparator();
m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("&Find"), this, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
menuBar()->addMenu(m_menuEdit);
m_menuView = new QMenu(tr("&View"));
m_actionShowToolbar = new QAction(tr("&Navigation Toolbar"), this);
m_actionShowToolbar->setCheckable(true);
connect(m_actionShowToolbar, SIGNAL(triggered(bool)), this, SLOT(showNavigationToolbar()));
m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), this);
m_actionShowBookmarksToolbar->setCheckable(true);
connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), this, SLOT(showBookmarksToolbar()));
m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), this);
m_actionShowStatusbar->setCheckable(true);
connect(m_actionShowStatusbar, SIGNAL(triggered(bool)), this, SLOT(showStatusbar()));
m_actionShowMenubar = new QAction(tr("&Menu Bar"), this);
m_actionShowMenubar->setCheckable(true);
connect(m_actionShowMenubar, SIGNAL(triggered(bool)), this, SLOT(showMenubar()));
m_actionShowFullScreen = new QAction(tr("&Fullscreen"), this);
m_actionShowFullScreen->setCheckable(true);
m_actionShowFullScreen->setShortcut(QKeySequence("F11"));
connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), this, SLOT(fullScreen(bool)));
m_actionStop = new QAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), this);
connect(m_actionStop, SIGNAL(triggered()), this, SLOT(stop()));
m_actionStop->setShortcut(QKeySequence("Esc"));
m_actionReload = new QAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this);
connect(m_actionReload, SIGNAL(triggered()), this, SLOT(reload()));
m_actionReload->setShortcut(QKeySequence("F5"));
QAction* actionEncoding = new QAction(tr("Character &Encoding"), this);
m_menuEncoding = new QMenu(this);
actionEncoding->setMenu(m_menuEncoding);
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
m_actionShowBookmarksSideBar = new QAction(tr("Bookmarks"), this);
m_actionShowBookmarksSideBar->setCheckable(true);
m_actionShowBookmarksSideBar->setShortcut(QKeySequence("Ctrl+B"));
connect(m_actionShowBookmarksSideBar, SIGNAL(triggered()), this, SLOT(showBookmarksSideBar()));
m_actionShowHistorySideBar = new QAction(tr("History"), this);
m_actionShowHistorySideBar->setCheckable(true);
m_actionShowHistorySideBar->setShortcut(QKeySequence("Ctrl+H"));
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);
QMenu* sidebarsMenu = new QMenu(tr("Sidebars"));
sidebarsMenu->addAction(m_actionShowBookmarksSideBar);
sidebarsMenu->addAction(m_actionShowHistorySideBar);
// sidebarsMenu->addAction(m_actionShowRssSideBar);
m_menuView->addMenu(toolbarsMenu);
m_menuView->addMenu(sidebarsMenu);
m_menuView->addAction(m_actionShowStatusbar);
m_menuView->addSeparator();
m_menuView->addAction(m_actionStop);
m_menuView->addAction(m_actionReload);
m_menuView->addSeparator();
m_menuView->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &In"), this, SLOT(zoomIn()))->setShortcut(QKeySequence("Ctrl++"));
m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), this, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-"));
m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), this, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0"));
m_menuView->addSeparator();
m_menuView->addAction(actionEncoding);
m_menuView->addSeparator();
m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), this, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U"));
m_menuView->addAction(m_actionShowFullScreen);
menuBar()->addMenu(m_menuView);
connect(m_menuView, SIGNAL(aboutToShow()), this, SLOT(aboutToShowViewMenu()));
menuBar()->addMenu(m_menuHistory);
menuBar()->addMenu(m_menuBookmarks);
menuBar()->addMenu(m_menuTools);
menuBar()->addMenu(m_menuHelp);
menuBar()->setContextMenuPolicy(Qt::CustomContextMenu);
m_menuClosedTabs = new QMenu(tr("Closed Tabs"));
connect(m_menuClosedTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));
aboutToShowToolsMenu();
aboutToShowHelpMenu();
m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), this);
m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T"));
connect(m_actionRestoreTab, SIGNAL(triggered()), m_tabWidget, SLOT(restoreClosedTab()));
addAction(m_actionRestoreTab);
QAction* reloadByPassCacheAction = new QAction(this);
reloadByPassCacheAction->setShortcut(QKeySequence("Ctrl+F5"));
connect(reloadByPassCacheAction, SIGNAL(triggered()), this, SLOT(reloadByPassCache()));
addAction(reloadByPassCacheAction);
//Make shortcuts available even in fullscreen (menu hidden)
QList actions = menuBar()->actions();
foreach (QAction* action, actions) {
if (action->menu())
actions += action->menu()->actions();
addAction(action);
}
m_superMenu->addMenu(m_menuFile);
m_superMenu->addMenu(m_menuEdit);
m_superMenu->addMenu(m_menuView);
m_superMenu->addMenu(m_menuHistory);
m_superMenu->addMenu(m_menuBookmarks);
m_superMenu->addMenu(m_menuTools);
m_superMenu->addMenu(m_menuHelp);
}
void QupZilla::loadSettings()
{
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
//Url settings
settings.beginGroup("Web-URL-Settings");
m_homepage = settings.value("homepage","qupzilla:start").toUrl();
m_newtab = settings.value("newTabUrl","").toUrl();
settings.endGroup();
QWebSettings* websettings = mApp->webSettings();
websettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
//Browser Window settings
settings.beginGroup("Browser-View-Settings");
m_menuTextColor = settings.value("menuTextColor", QColor(Qt::black)).value();
bool showStatusBar = settings.value("showStatusBar",true).toBool();
bool showHomeIcon = settings.value("showHomeButton",true).toBool();
bool showBackForwardIcons = settings.value("showBackForwardButtons",true).toBool();
bool showBookmarksToolbar = settings.value("showBookmarksToolbar",true).toBool();
bool showNavigationToolbar = settings.value("showNavigationToolbar",true).toBool();
bool showMenuBar = settings.value("showMenubar",true).toBool();
bool showAddTab = settings.value("showAddTabButton", false).toBool();
bool makeTransparent = settings.value("useTransparentBackground",false).toBool();
m_sideBarWidth = settings.value("SideBarWidth", 250).toInt();
QString activeSideBar = settings.value("SideBar", "None").toString();
settings.endGroup();
bool adBlockEnabled = settings.value("AdBlock/enabled", true).toBool();
m_adblockIcon->setEnabled(adBlockEnabled);
statusBar()->setVisible(showStatusBar);
m_bookmarksToolbar->setVisible(showBookmarksToolbar);
m_navigationBar->setVisible(showNavigationToolbar);
menuBar()->setVisible(showMenuBar);
m_navigationBar->buttonSuperMenu()->setVisible(!showMenuBar);
m_navigationBar->buttonHome()->setVisible(showHomeIcon);
m_navigationBar->buttonBack()->setVisible(showBackForwardIcons);
m_navigationBar->buttonNext()->setVisible(showBackForwardIcons);
m_navigationBar->buttonAddTab()->setVisible(showAddTab);
if (activeSideBar != "None") {
if (activeSideBar == "Bookmarks")
m_actionShowBookmarksSideBar->trigger();
else if (activeSideBar == "History")
m_actionShowHistorySideBar->trigger();
}
//Private browsing
m_actionPrivateBrowsing->setChecked( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
m_privateBrowsing->setVisible( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) );
if (!makeTransparent)
return;
//Opacity
#ifdef Q_WS_X11
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_NoSystemBackground, false);
QPalette pal = palette();
QColor bg = pal.window().color();
bg.setAlpha(180);
pal.setColor(QPalette::Window, bg);
setPalette(pal);
ensurePolished(); // workaround Oxygen filling the background
setAttribute(Qt::WA_StyledBackground, false);
#endif
if (QtWin::isCompositionEnabled()) {
QtWin::extendFrameIntoClientArea(this);
setContentsMargins(0, 0, 0, 0);
}
}
void QupZilla::setWindowTitle(const QString &t)
{
if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
QMainWindow::setWindowTitle(t + tr(" (Private Browsing)"));
else
QMainWindow::setWindowTitle(t);
}
void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
{
switch (mes) {
case MainApplication::SetAdBlockIconEnabled:
m_adblockIcon->setEnabled(state);
break;
case MainApplication::CheckPrivateBrowsing:
m_privateBrowsing->setVisible(state);
m_actionPrivateBrowsing->setChecked(state);
if (state)
setWindowTitle(windowTitle());
else
setWindowTitle(windowTitle().remove(tr(" (Private Browsing)")));
break;
case MainApplication::ReloadSettings:
loadSettings();
m_tabWidget->loadSettings();
LocationBarSettings::instance()->loadSettings();
break;
case MainApplication::HistoryStateChanged:
m_historyMenuChanged = true;
break;
case MainApplication::BookmarksChanged:
m_bookmarksMenuChanged = true;
break;
default:
qWarning("Unresolved message sent! This could never happen!");
break;
}
}
void QupZilla::aboutToShowBookmarksMenu()
{
if (!m_bookmarksMenuChanged)
return;
m_bookmarksMenuChanged = false;
m_menuBookmarks->clear();
m_menuBookmarks->addAction(tr("Bookmark &This Page"), this, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
m_menuBookmarks->addAction(tr("Bookmark &All Tabs"), this, SLOT(bookmarkAllTabs()));
m_menuBookmarks->addAction(IconProvider::fromTheme("user-bookmarks"), tr("Organize &Bookmarks"), this, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
m_menuBookmarks->addSeparator();
QSqlQuery query;
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksMenu'");
while(query.next()) {
QString title = query.value(0).toString();
QUrl url = query.value(1).toUrl();
QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray());
if (title.length()>40) {
title.truncate(40);
title+="..";
}
m_menuBookmarks->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url);
}
QMenu* folderBookmarks = new QMenu(tr("Bookmarks In ToolBar"), m_menuBookmarks);
folderBookmarks->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)));
query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar'");
while(query.next()) {
QString title = query.value(0).toString();
QUrl url = query.value(1).toUrl();
QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray());
if (title.length()>40) {
title.truncate(40);
title+="..";
}
folderBookmarks->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url);
}
if (folderBookmarks->isEmpty())
folderBookmarks->addAction(tr("Empty"));
m_menuBookmarks->addMenu(folderBookmarks);
query.exec("SELECT name FROM folders");
while(query.next()) {
QString folderName = query.value(0).toString();
QMenu* tempFolder = new QMenu(folderName, m_menuBookmarks);
tempFolder->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)));
QSqlQuery query2;
query2.exec("SELECT title, url, icon FROM bookmarks WHERE folder='" + folderName + "'");
while(query2.next()) {
QString title = query2.value(0).toString();
QUrl url = query2.value(1).toUrl();
QIcon icon = IconProvider::iconFromBase64(query2.value(2).toByteArray());
if (title.length()>40) {
title.truncate(40);
title+="..";
}
tempFolder->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url);
}
if (tempFolder->isEmpty())
tempFolder->addAction(tr("Empty"));
m_menuBookmarks->addMenu(tempFolder);
}
}
void QupZilla::aboutToShowHistoryMenu(bool loadHistory)
{
if (!weView())
return;
if (!m_historyMenuChanged)
return;
m_historyMenuChanged = false;
if (!loadHistory)
m_historyMenuChanged = true;
m_menuHistory->clear();
m_menuHistory->addAction(IconProvider::standardIcon(QStyle::SP_ArrowBack), tr("&Back"), this, SLOT(goBack()))->setShortcut(QKeySequence("Ctrl+Left"));
m_menuHistory->addAction(IconProvider::standardIcon(QStyle::SP_ArrowForward), tr("&Forward"), this, SLOT(goNext()))->setShortcut(QKeySequence("Ctrl+Right"));
m_menuHistory->addAction(IconProvider::fromTheme("go-home"), tr("&Home"), this, SLOT(goHome()))->setShortcut(QKeySequence("Alt+Home"));
if (!weView()->history()->canGoBack())
m_menuHistory->actions().at(0)->setEnabled(false);
if (!weView()->history()->canGoForward())
m_menuHistory->actions().at(1)->setEnabled(false);
m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), this, SLOT(showHistoryManager()));
m_menuHistory->addSeparator();
if (loadHistory) {
QSqlQuery query;
query.exec("SELECT title, url FROM history ORDER BY date DESC LIMIT 10");
while(query.next()) {
QUrl url = query.value(1).toUrl();
QString title = query.value(0).toString();
if (title.length()>40) {
title.truncate(40);
title+="..";
}
m_menuHistory->addAction(_iconForUrl(url), title, this, SLOT(loadActionUrl()))->setData(url);
}
m_menuHistory->addSeparator();
}
m_menuHistory->addMenu(m_menuClosedTabs);
}
void QupZilla::aboutToShowClosedTabsMenu()
{
m_menuClosedTabs->clear();
int i = 0;
foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) {
QString title = tab.title;
if (title.length()>40) {
title.truncate(40);
title+="..";
}
m_menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i);
i++;
}
m_menuClosedTabs->addSeparator();
if (i == 0)
m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false);
else {
m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs()));
m_menuClosedTabs->addAction(tr("Clear list"), m_tabWidget, SLOT(clearClosedTabsList()));
}
}
void QupZilla::aboutToShowHelpMenu()
{
m_menuHelp->clear();
mApp->plugins()->populateHelpMenu(m_menuHelp);
m_menuHelp->addSeparator();
m_menuHelp->addAction(QIcon(":/icons/menu/qt.png"), tr("About &Qt"), qApp, SLOT(aboutQt()));
m_menuHelp->addAction(QIcon(":/icons/qupzilla.png"), tr("&About QupZilla"), this, SLOT(aboutQupZilla()));
m_menuHelp->addSeparator();
m_menuHelp->addAction(QIcon(":/icons/menu/informations.png"), tr("Informations about application"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:about"));
m_menuHelp->addAction(tr("Report &Issue"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug"));
}
void QupZilla::aboutToShowToolsMenu()
{
m_menuTools->clear();
m_menuTools->addAction(tr("&Web Search"), this, SLOT(webSearch()))->setShortcut(QKeySequence("Ctrl+K"));
m_menuTools->addAction(QIcon::fromTheme("dialog-information"), tr("Page &Info"), this, SLOT(showPageInfo()))->setShortcut(QKeySequence("Ctrl+I"));
m_menuTools->addSeparator();
m_menuTools->addAction(tr("&Download Manager"), this, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
m_menuTools->addAction(tr("&Cookies Manager"), this, SLOT(showCookieManager()));
m_menuTools->addAction(tr("&AdBlock"), AdBlockManager::instance(), SLOT(showDialog()));
m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), this, SLOT(showRSSManager()));
m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent &History"), this, SLOT(showClearPrivateData()));
m_actionPrivateBrowsing = new QAction(tr("&Private Browsing"), this);
m_actionPrivateBrowsing->setShortcut(QKeySequence("Ctrl+Shift+P"));
m_actionPrivateBrowsing->setCheckable(true);
m_actionPrivateBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled));
connect(m_actionPrivateBrowsing, SIGNAL(triggered(bool)), this, SLOT(startPrivate(bool)));
m_menuTools->addAction(m_actionPrivateBrowsing);
m_menuTools->addSeparator();
mApp->plugins()->populateToolsMenu(m_menuTools);
m_menuTools->addAction(QIcon(":/icons/faenza/settings.png"), tr("Pr&eferences"), this, SLOT(showPreferences()))->setShortcut(QKeySequence("Ctrl+P"));
}
void QupZilla::aboutToShowViewMenu()
{
if (!weView())
return;
if (weView()->isLoading())
m_actionStop->setEnabled(true);
else
m_actionStop->setEnabled(false);
m_actionShowToolbar->setChecked(m_navigationBar->isVisible());
m_actionShowMenubar->setChecked(menuBar()->isVisible());
m_actionShowStatusbar->setChecked(statusBar()->isVisible());
m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible());
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::aboutToShowEncodingMenu()
{
m_menuEncoding->clear();
QMenu* menuISO = new QMenu("ISO", this);
QMenu* menuUTF = new QMenu("UTF", this);
QMenu* menuWindows = new QMenu("Windows", this);
QMenu* menuIscii = new QMenu("Iscii", this);
QMenu* menuOther = new QMenu(tr("Other"), this);
QList available = QTextCodec::availableCodecs();
qSort(available);
QString activeCodec = mApp->webSettings()->defaultTextEncoding();
foreach (QByteArray name, available) {
if (QTextCodec::codecForName(name)->aliases().contains(name))
continue;
QAction* action = new QAction(name=="System" ? tr("Default") : name, this);
action->setData(name);
action->setCheckable(true);
connect(action, SIGNAL(triggered()), this, SLOT(changeEncoding()));
if (activeCodec.compare(name, Qt::CaseInsensitive) == 0)
action->setChecked(true);
if (name.startsWith("ISO"))
menuISO->addAction(action);
else if (name.startsWith("UTF"))
menuUTF->addAction(action);
else if (name.startsWith("windows"))
menuWindows->addAction(action);
else if (name.startsWith("Iscii"))
menuIscii->addAction(action);
else if (name == "System")
m_menuEncoding->addAction(action);
else
menuOther->addAction(action);
}
m_menuEncoding->addSeparator();
if (!menuISO->isEmpty())
m_menuEncoding->addMenu(menuISO);
if (!menuUTF->isEmpty())
m_menuEncoding->addMenu(menuUTF);
if (!menuWindows->isEmpty())
m_menuEncoding->addMenu(menuWindows);
if (!menuIscii->isEmpty())
m_menuEncoding->addMenu(menuIscii);
if (!menuOther->isEmpty())
m_menuEncoding->addMenu(menuOther);
}
void QupZilla::changeEncoding()
{
if (QAction* action = qobject_cast(sender())) {
mApp->webSettings()->setDefaultTextEncoding(action->data().toString());
reload();
}
}
void QupZilla::bookmarkPage()
{
mApp->browsingLibrary()->bookmarksManager()->addBookmark(weView());
}
void QupZilla::addBookmark(const QUrl &url, const QString &title, const QIcon &icon)
{
mApp->browsingLibrary()->bookmarksManager()->insertBookmark(url, title, icon);
}
void QupZilla::bookmarkAllTabs()
{
mApp->browsingLibrary()->bookmarksManager()->insertAllTabs();
}
void QupZilla::goHome()
{
loadAddress(m_homepage);
}
void QupZilla::goHomeInNewTab()
{
m_tabWidget->addView(m_homepage, tr("New tab"), TabWidget::NewSelectedTab);
}
void QupZilla::loadActionUrl()
{
if (QAction* action = qobject_cast(sender())) {
loadAddress(action->data().toUrl());
}
}
void QupZilla::loadActionUrlInNewTab()
{
if (QAction* action = qobject_cast(sender())) {
m_tabWidget->addView(action->data().toUrl());
}
}
void QupZilla::loadAddress(const QUrl &url)
{
weView()->load(url);
locationBar()->setText(url.toEncoded());
}
void QupZilla::urlEnter()
{
if (locationBar()->text().isEmpty())
return;
loadAddress(QUrl(WebView::guessUrlFromString(locationBar()->text())));
weView()->setFocus();
}
void QupZilla::showCookieManager()
{
CookieManager* m = mApp->cookieManager();
m->refreshTable();
m->show();
}
void QupZilla::showHistoryManager()
{
mApp->browsingLibrary()->showHistory(this);
}
void QupZilla::showRSSManager()
{
mApp->browsingLibrary()->showRSS(this);
}
void QupZilla::showBookmarksManager()
{
mApp->browsingLibrary()->showBookmarks(this);
}
void QupZilla::showClearPrivateData()
{
ClearPrivateData clear(this, this);
clear.exec();
}
void QupZilla::showDownloadManager()
{
mApp->downManager()->show();
}
void QupZilla::showPreferences()
{
Preferences* prefs = new Preferences(this, this);
prefs->show();
}
void QupZilla::showSource(const QString &selectedHtml)
{
SourceViewer* source = new SourceViewer(weView()->page(), selectedHtml);
qz_centerWidgetToParent(source, this);
source->show();
}
void QupZilla::showPageInfo()
{
SiteInfo* info = new SiteInfo(this, this);
info->setAttribute(Qt::WA_DeleteOnClose);
info->show();
}
void QupZilla::showBookmarksToolbar()
{
bool status = m_bookmarksToolbar->isVisible();
m_bookmarksToolbar->setVisible(!status);
QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat);
settings.setValue("Browser-View-Settings/showBookmarksToolbar", !status);
}
void QupZilla::showBookmarksSideBar()
{
addSideBar();
if (m_sideBar->activeWidget() != SideBar::Bookmarks)
m_sideBar->showBookmarks();
else {
m_sideBar->close();
}
}
void QupZilla::showHistorySideBar()
{
addSideBar();
if (m_sideBar->activeWidget() != SideBar::History)
m_sideBar->showHistory();
else {
m_sideBar->close();
}
}
void QupZilla::addSideBar()
{
if (m_sideBar)
return;
m_sideBar = new SideBar(this);
m_mainSplitter->insertWidget(0, m_sideBar);
m_mainSplitter->setCollapsible(0, false);
QList sizes;
sizes << m_sideBarWidth << width() - m_sideBarWidth;
m_mainSplitter->setSizes(sizes);
}
void QupZilla::saveSideBarWidth()
{
// That +1 is important here, without it, the sidebar width would
// decrease by 1 pixel every close
m_sideBarWidth = m_mainSplitter->sizes().at(0) + 1;
}
void QupZilla::showNavigationToolbar()
{
if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked())
showMenubar();
bool status = m_navigationBar->isVisible();
m_navigationBar->setVisible(!status);
QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat);
settings.setValue("Browser-View-Settings/showNavigationToolbar", !status);
}
void QupZilla::showMenubar()
{
if (!m_navigationBar->isVisible() && !m_actionShowMenubar->isChecked())
showNavigationToolbar();
menuBar()->setVisible(!menuBar()->isVisible());
m_navigationBar->buttonSuperMenu()->setVisible(!menuBar()->isVisible());
QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat);
settings.setValue("Browser-View-Settings/showMenubar", menuBar()->isVisible());
}
void QupZilla::showStatusbar()
{
bool status = statusBar()->isVisible();
statusBar()->setVisible(!status);
QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat);
settings.setValue("Browser-View-Settings/showStatusbar", !status);
}
void QupZilla::showWebInspector()
{
#ifdef Q_WS_WIN
weView()->triggerPageAction(QWebPage::InspectElement);
#else
if (m_webInspectorDock) {
m_webInspectorDock->setPage(weView()->webPage());
m_webInspectorDock->show();
return;
}
m_webInspectorDock = new WebInspectorDockWidget(this);
connect(m_tabWidget, SIGNAL(currentChanged(int)), m_webInspectorDock, SLOT(tabChanged()));
addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock);
#endif
}
void QupZilla::showBookmarkImport()
{
BookmarksImportDialog* b = new BookmarksImportDialog(this);
b->show();
}
void QupZilla::refreshHistory()
{
m_navigationBar->refreshHistory();
}
void QupZilla::aboutQupZilla()
{
AboutDialog about(this);
about.exec();
}
void QupZilla::webSearch()
{
m_navigationBar->searchLine()->setFocus();
m_navigationBar->searchLine()->selectAll();
}
void QupZilla::searchOnPage()
{
if (m_mainLayout->count() == 4) {
SearchToolBar* search = qobject_cast( m_mainLayout->itemAt(3)->widget() );
if (!search)
return;
search->searchLine()->setFocus();
return;
}
SearchToolBar* search = new SearchToolBar(this);
m_mainLayout->insertWidget(3, search);
search->searchLine()->setFocus();
}
void QupZilla::openFile()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Open file..."), QDir::homePath(), "(*.html *.htm *.jpg *.png)");
if (!filePath.isEmpty())
loadAddress(QUrl(filePath));
}
void QupZilla::showNavigationWithFullscreen()
{
bool state;
if (m_navigationVisible)
state = !m_navigationBar->isVisible();
else
state = !m_tabWidget->getTabBar()->isVisible();
if (m_navigationVisible)
m_navigationBar->setVisible(state);
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(state);
if (m_bookmarksToolBarVisible)
m_bookmarksToolbar->setVisible(state);
}
void QupZilla::fullScreen(bool make)
{
if (make) {
m_menuBarVisible = menuBar()->isVisible();
m_statusBarVisible = statusBar()->isVisible();
m_navigationVisible = m_navigationBar->isVisible();
m_bookmarksToolBarVisible = m_bookmarksToolbar->isVisible();
setWindowState(windowState() | Qt::WindowFullScreen);
menuBar()->hide();
statusBar()->hide();
bookmarksToolbar()->hide();
m_navigationBar->hide();
}
else {
setWindowState(windowState() & ~Qt::WindowFullScreen);
menuBar()->setVisible(m_menuBarVisible);
statusBar()->setVisible(m_statusBarVisible);
m_bookmarksToolbar->setVisible(m_bookmarksToolBarVisible);
m_navigationBar->setVisible(m_navigationVisible);
}
m_actionShowFullScreen->setChecked(make);
m_navigationBar->buttonExitFullscreen()->setVisible(make);
m_tabWidget->getTabBar()->setVisible(!make);
emit setWebViewMouseTracking(make);
}
void QupZilla::savePage()
{
QNetworkRequest request(weView()->url());
DownloadManager* dManager = mApp->downManager();
dManager->download(request, false);
}
void QupZilla::printPage()
{
QPrintPreviewDialog* dialog = new QPrintPreviewDialog(this);
connect(dialog, SIGNAL(paintRequested(QPrinter*)), weView(), SLOT(print(QPrinter*)));
dialog->exec();
delete dialog;
}
void QupZilla::savePageScreen()
{
PageScreen* p = new PageScreen(weView(), this);
p->show();
}
void QupZilla::startPrivate(bool state)
{
if (state) {
QString title = tr("Are you sure you want to turn on private browsing?");
QString text1 = tr("When private browsing is turned on, some actions concerning your privacy will be disabled:");
QStringList actions;
actions.append(tr("Webpages are not added to the history."));
actions.append(tr("Current cookies cannot be accessed."));
actions.append(tr("Your session is not stored."));
QString text2 = tr("Until you close the window, you can still click the Back and Forward "
"buttons to return to the webpages you have opened.");
QString message = QString(QLatin1String("%1%2
%4
")).arg(title, text1, actions.join(QLatin1String("")), text2);
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Start Private Browsing"),
message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button != QMessageBox::Yes)
return;
}
mApp->webSettings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, state);
mApp->history()->setSaving(!state);
mApp->cookieJar()->turnPrivateJar(state);
emit message(MainApplication::CheckPrivateBrowsing, state);
}
void QupZilla::closeEvent(QCloseEvent* event)
{
if (mApp->isClosing())
return;
m_isClosing = true;
mApp->saveStateSlot();
mApp->aboutToCloseWindow(this);
if (mApp->windowCount() == 0) {
quitApp() ? event->accept() : event->ignore();
return;
}
event->accept();
}
bool QupZilla::quitApp()
{
if (m_sideBar)
saveSideBarWidth();
QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch",0).toInt();
bool askOnClose = settings.value("Browser-Tabs-Settings/AskOnClosing", false).toBool();
settings.beginGroup("Browser-View-Settings");
settings.setValue("WindowMaximised", windowState().testFlag(Qt::WindowMaximized));
settings.setValue("WindowGeometry", geometry());
settings.setValue("LocationBarWidth", m_navigationBar->splitter()->sizes().at(0));
settings.setValue("WebSearchBarWidth", m_navigationBar->splitter()->sizes().at(1));
settings.setValue("SideBarWidth", m_sideBar ? m_mainSplitter->sizes().at(0) : m_sideBarWidth);
if (askOnClose && afterLaunch != 2 && m_tabWidget->count() > 1) {
QDialog* dialog = new QDialog(this);
Ui_CloseDialog* ui = new Ui_CloseDialog();
ui->setupUi(dialog);
ui->textLabel->setText(tr("There are still %1 open tabs and your session won't be stored. Are you sure to quit?").arg(m_tabWidget->count()));
ui->iconLabel->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
if (dialog->exec() != QDialog::Accepted)
return false;
if (ui->dontAskAgain->isChecked())
settings.setValue("Browser-Tabs-Settings/AskOnClosing", false);
}
mApp->quitApplication();
return true;
}
QupZilla::~QupZilla()
{
delete m_tabWidget;
delete m_navigationBar;
delete m_privateBrowsing;
delete m_adblockIcon;
delete m_bookmarksToolbar;
delete m_progressBar;
if (m_webInspectorDock)
delete m_webInspectorDock;
}
diff --git a/src/autofill/autofillmodel.cpp b/src/autofill/autofillmodel.cpp
index 3522ade7..791b1906 100644
--- a/src/autofill/autofillmodel.cpp
+++ b/src/autofill/autofillmodel.cpp
@@ -1,211 +1,212 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#include "autofillmodel.h"
#include "qupzilla.h"
#include "webview.h"
#include "mainapplication.h"
#include "autofillnotification.h"
AutoFillModel::AutoFillModel(QupZilla* mainClass, QObject* parent) :
QObject(parent)
,p_QupZilla(mainClass)
,m_isStoring(false)
{
QTimer::singleShot(0, this, SLOT(loadSettings()));
}
void AutoFillModel::loadSettings()
{
QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-Browser-Settings");
m_isStoring = settings.value("SavePasswordsOnSites", true).toBool();
settings.endGroup();
}
bool AutoFillModel::isStored(const QUrl &url)
{
if (!isStoringEnabled(url))
return false;
QString server = url.host();
QSqlQuery query;
query.exec("SELECT count(id) FROM autofill WHERE server='"+server+"'");
query.next();
if (query.value(0).toInt()>0)
return true;
return false;
}
bool AutoFillModel::isStoringEnabled(const QUrl &url)
{
if (!m_isStoring)
return false;
QString server = url.host();
QSqlQuery query;
query.exec("SELECT count(id) FROM autofill_exceptions WHERE server='"+server+"'");
query.next();
if (query.value(0).toInt()>0)
return false;
return true;
}
void AutoFillModel::blockStoringfor (const QUrl &url)
{
QString server = url.host();
QSqlQuery query;
query.exec("INSERT INTO autofill_exceptions (server) VALUES ('"+server+"')");
}
QString AutoFillModel::getUsername(const QUrl &url)
{
QString server = url.host();
QSqlQuery query;
query.exec("SELECT username FROM autofill WHERE server='"+server+"'");
query.next();
return query.value(0).toString();
}
QString AutoFillModel::getPassword(const QUrl &url)
{
QString server = url.host();
QSqlQuery query;
query.exec("SELECT password FROM autofill WHERE server='"+server+"'");
query.next();
return query.value(0).toString();
}
///HTTP Authorization
bool AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString &pass)
{
QSqlQuery query;
query.exec("SELECT username FROM autofill WHERE server='"+url.host()+"'");
if (query.next())
return false;
query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)");
query.bindValue(0, url.host());
query.bindValue(1, name);
query.bindValue(2, pass);
return query.exec();
}
///WEB Form
bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &pass)
{
QSqlQuery query;
query.exec("SELECT data FROM autofill WHERE server='"+url.host()+"'");
if (query.next())
return false;
query.prepare("INSERT INTO autofill (server, data, password) VALUES (?,?,?)");
query.bindValue(0, url.host());
query.bindValue(1, data);
query.bindValue(2, pass);
return query.exec();
}
void AutoFillModel::completePage(WebView* view)
{
if (!isStored(view->url()))
return;
QWebElementCollection inputs;
QList frames;
frames.append(view->page()->mainFrame());
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
inputs.append(frame->findAllElements("input"));
frames += frame->childFrames();
}
QSqlQuery query;
query.exec("SELECT data FROM autofill WHERE server='"+view->url().host()+"'");
query.next();
QByteArray data = query.value(0).toByteArray();
if (data.isEmpty())
return;
QList > arguments = QUrl::fromEncoded(QByteArray("http://bla.com/?"+data)).queryItems();
for (int i = 0; iwebSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
return;
+
m_lastOutgoingData = outgoingData;
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
QWebPage* webPage = (QWebPage*)(v.value());
v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102));
WebView* webView = (WebView*)(v.value());
if (!webPage || !webView)
return;
v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101));
QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt();
if (type!=QWebPage::NavigationTypeFormSubmitted)
return;
QString passwordName = "";
QString passwordValue = "";
QUrl siteUrl = webView->url();
QWebElementCollection inputs;
QList frames;
frames.append(webPage->mainFrame());
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
inputs.append(frame->findAllElements("input[type=\"password\"]"));
frames += frame->childFrames();
}
foreach (QWebElement element, inputs) {
passwordName = element.attribute("name");
passwordValue = element.evaluateJavaScript("this.value").toString();
if (!passwordValue.isEmpty())
break;
}
//Return if storing is not enabled, data for this page is already stored, no password element found in sent data
if (passwordName.isEmpty() || !isStoringEnabled(siteUrl) || isStored(siteUrl))
return;
//Return if no password form has been sent
if (!outgoingData.contains((QUrl(passwordName).toEncoded() + "=")) || passwordValue.isEmpty())
return;
AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, outgoingData, passwordValue);
webView->addNotification(aWidget);
}
diff --git a/src/cookies/cookiejar.cpp b/src/cookies/cookiejar.cpp
index 7a12ad38..8e5cdc3d 100644
--- a/src/cookies/cookiejar.cpp
+++ b/src/cookies/cookiejar.cpp
@@ -1,140 +1,141 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#include "cookiejar.h"
#include "qupzilla.h"
-#define COOKIE_DEBUG
+//#define COOKIE_DEBUG
//TODO: black/white listing
-CookieJar::CookieJar(QupZilla* mainClass, QObject* parent) :
- QNetworkCookieJar(parent)
- ,p_QupZilla(mainClass)
+CookieJar::CookieJar(QupZilla* mainClass, QObject* parent)
+ : QNetworkCookieJar(parent)
+ , p_QupZilla(mainClass)
{
- loadSettings();
m_activeProfil = mApp->getActiveProfilPath();
+ loadSettings();
}
void CookieJar::loadSettings()
{
- QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat);
+ QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-Browser-Settings");
- m_allowCookies = settings.value("allowCookies",true).toBool();
- m_allowCookiesFromDomain = settings.value("allowCookiesFromVisitedDomainOnly",false).toBool();
- m_filterTrackingCookie = settings.value("filterTrackingCookie",false).toBool();
+ m_allowCookies = settings.value("allowCookies", true).toBool();
+ m_allowCookiesFromDomain = settings.value("allowCookiesFromVisitedDomainOnly", false).toBool();
+ m_filterTrackingCookie = settings.value("filterTrackingCookie", false).toBool();
m_deleteOnClose = settings.value("deleteCookiesOnClose", false).toBool();
}
void CookieJar::setAllowCookies(bool allow)
{
m_allowCookies = allow;
}
bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QUrl &url)
{
if (!m_allowCookies)
return QNetworkCookieJar::setCookiesFromUrl(QList(), url);
QList newList = cookieList;
QDateTime now = QDateTime::currentDateTime();
foreach (QNetworkCookie cok, newList) {
- if (m_allowCookiesFromDomain && !url.toString().contains(cok.domain())) {
+ if (m_allowCookiesFromDomain && !QString("." + url.host()).contains(cok.domain().remove("www."))) {
#ifdef COOKIE_DEBUG
qDebug() << "purged for domain mismatch" << cok;
#endif
newList.removeOne(cok);
continue;
}
- if (m_filterTrackingCookie && cok.expirationDate() > now.addYears(2)) {
+
+ if (m_filterTrackingCookie && (cok.name().startsWith("__utm") || cok.expirationDate() > now.addYears(1).addMonths(6)) ) {
#ifdef COOKIE_DEBUG
qDebug() << "purged as tracking " << cok;
#endif
newList.removeOne(cok);
continue;
}
}
return QNetworkCookieJar::setCookiesFromUrl(newList, url);
}
void CookieJar::saveCookies()
{
if (m_deleteOnClose)
return;
QList allCookies = getAllCookies();
QFile file(m_activeProfil+"cookies.dat");
file.open(QIODevice::WriteOnly);
QDataStream stream(&file);
int count = allCookies.count();
stream << count;
for (int i = 0; i restoredCookies;
QFile file(m_activeProfil+"cookies.dat");
file.open(QIODevice::ReadOnly);
QDataStream stream(&file);
int count;
stream >> count;
for (int i = 0; i> rawForm;
QNetworkCookie cok = QNetworkCookie::parseCookies(rawForm).at(0);
if (cok.expirationDate() < now)
continue;
if (cok.isSessionCookie())
continue;
restoredCookies.append(cok);
}
file.close();
setAllCookies(restoredCookies);
}
QList CookieJar::getAllCookies()
{
return QNetworkCookieJar::allCookies();
}
void CookieJar::setAllCookies(const QList &cookieList)
{
QNetworkCookieJar::setAllCookies(cookieList);
}
void CookieJar::turnPrivateJar(bool state)
{
if (state) {
m_tempList = QNetworkCookieJar::allCookies();
QNetworkCookieJar::setAllCookies(QList());
} else {
QNetworkCookieJar::setAllCookies(m_tempList);
m_tempList.clear();
}
}
diff --git a/src/cookies/cookiemanager.cpp b/src/cookies/cookiemanager.cpp
index bd310cb8..f67a7fe6 100644
--- a/src/cookies/cookiemanager.cpp
+++ b/src/cookies/cookiemanager.cpp
@@ -1,190 +1,189 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#include "cookiemanager.h"
#include "ui_cookiemanager.h"
#include "qupzilla.h"
#include "cookiejar.h"
#include "mainapplication.h"
#include "globalfunctions.h"
CookieManager::CookieManager(QWidget* parent)
: QWidget(parent)
, ui(new Ui::CookieManager)
{
- setAttribute(Qt::WA_DeleteOnClose);
setWindowModality(Qt::WindowModal);
ui->setupUi(this);
qz_centerWidgetOnScreen(this);
//QTimer::singleShot(0, this, SLOT(refreshTable()));
connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll()));
connect(ui->removeCookie, SIGNAL(clicked()), this, SLOT(removeCookie()));
connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(hide()));
connect(ui->search, SIGNAL(returnPressed()), this, SLOT(search()));
// connect(ui->search, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(search()));
connect(ui->search, SIGNAL(textChanged(QString)), ui->cookieTree, SLOT(filterString(QString)));
ui->search->setInactiveText(tr("Search"));
ui->cookieTree->setDefaultItemShowMode(TreeWidget::ItemsCollapsed);
}
void CookieManager::removeAll()
{
QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"),
tr("Are you sure to delete all cookies on your computer?"), QMessageBox::Yes | QMessageBox::No);
if (button != QMessageBox::Yes)
return;
m_cookies.clear();
mApp->cookieJar()->setAllCookies(m_cookies);
ui->cookieTree->clear();
}
void CookieManager::removeCookie()
{
QTreeWidgetItem* current = ui->cookieTree->currentItem();
if (!current)
return;
if (current->text(1).isEmpty()) { //Remove whole cookie group
QString domain = current->whatsThis(0);
foreach(QNetworkCookie cok, m_cookies) {
if (cok.domain() == domain || cok.domain() == domain.mid(1))
m_cookies.removeOne(cok);
}
ui->cookieTree->deleteItem(current);
mApp->cookieJar()->setAllCookies(m_cookies);
refreshTable(false);
return;
}
int index = current->whatsThis(1).toInt();
m_cookies.removeAt(index);
mApp->cookieJar()->setAllCookies(m_cookies);
refreshTable(false);
if (!ui->search->text().isEmpty())
search();
}
void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent)
{
Q_UNUSED(parent);
if (!current)
return;
ui->removeCookie->setEnabled(true);
if (current->text(1).isEmpty()) {
ui->name->setText(tr(""));
ui->value->setText(tr(""));
ui->server->setText(tr(""));
ui->path->setText(tr(""));
ui->secure->setText(tr(""));
ui->expiration->setText(tr(""));
ui->removeCookie->setText(tr("Remove cookies"));
return;
}
ui->removeCookie->setText(tr("Remove cookie"));
int index = current->whatsThis(1).toInt();
QNetworkCookie cok = m_cookies.at(index);
ui->name->setText(cok.name());
ui->value->setText(cok.value());
ui->server->setText(cok.domain());
ui->path->setText(cok.path());
cok.isSecure() ? ui->secure->setText(tr("Secure only")) : ui->secure->setText(tr("All connections"));
cok.isSessionCookie() ? ui->expiration->setText(tr("Session cookie")) : ui->expiration->setText(QDateTime(cok.expirationDate()).toString("hh:mm:ss dddd d. MMMM yyyy"));
}
void CookieManager::refreshTable(bool refreshCookieJar)
{
if (refreshCookieJar)
m_cookies = mApp->cookieJar()->getAllCookies();
ui->cookieTree->setUpdatesEnabled(false);
ui->cookieTree->clear();
QString cookServer;
for (int i = 0; i findParent = ui->cookieTree->findItems(cookServer, 0);
if (findParent.count() == 1) {
item = new QTreeWidgetItem(findParent.at(0));
}else{
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree);
newParent->setText(0, cookServer);
newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
newParent->setWhatsThis(0, cok.domain());
ui->cookieTree->addTopLevelItem(newParent);
item = new QTreeWidgetItem(newParent);
}
item->setText(0,"."+cookServer);
item->setText(1, cok.name());
item->setWhatsThis(1, QString::number(i));
ui->cookieTree->addTopLevelItem(item);
}
ui->cookieTree->setUpdatesEnabled(true);
}
void CookieManager::search()
{
QString searchText = ui->search->text();
if (searchText.isEmpty()) {
refreshTable(false);
return;
}
refreshTable(false);
ui->cookieTree->setUpdatesEnabled(false);
QList items = ui->cookieTree->findItems(".*"+searchText+"*", Qt::MatchRecursive | Qt::MatchWildcard);
QList foundItems;
foreach(QTreeWidgetItem* fitem, items) {
if (!fitem->text(0).startsWith("."))
continue;
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0, fitem->text(0));
item->setText(1, fitem->text(1));
item->setWhatsThis(1, fitem->whatsThis(1));
foundItems.append(item);
}
ui->cookieTree->clear();
ui->cookieTree->addTopLevelItems(foundItems);
ui->cookieTree->setUpdatesEnabled(true);
}
CookieManager::~CookieManager()
{
delete ui;
}
diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp
index c1e7b1b2..8108664b 100644
--- a/src/webview/tabbar.cpp
+++ b/src/webview/tabbar.cpp
@@ -1,303 +1,313 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#include "tabbar.h"
#include "tabwidget.h"
#include "qupzilla.h"
#include "webtab.h"
#include "iconprovider.h"
#include "toolbutton.h"
#define MAXIMUM_TAB_WIDTH 250
#define MINIMUM_TAB_WIDTH 50
#ifdef Q_WS_WIN
#define PINNED_TAB_WIDTH 38
#else
#define PINNED_TAB_WIDTH 31
#endif
TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
: QTabBar()
, p_QupZilla(mainClass)
, m_tabWidget(tabWidget)
, m_clickedTab(0)
, m_pinnedTabsCount(0)
, m_normalTabWidth(0)
, m_lastTabWidth(0)
, m_adjustingLastTab(false)
{
setObjectName("tabbar");
setContextMenuPolicy(Qt::CustomContextMenu);
setElideMode(Qt::ElideRight);
setTabsClosable(true);
setDocumentMode(true);
setFocusPolicy(Qt::NoFocus);
loadSettings();
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed()));
connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded()));
}
void TabBar::loadSettings()
{
QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat);
settings.beginGroup("Browser-Tabs-Settings");
setMovable( settings.value("makeTabsMovable",true).toBool() );
if (settings.value("ActivateLastTabWhenClosingActual", false).toBool())
setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
settings.endGroup();
}
void TabBar::updateVisibilityWithFullscreen(bool visible)
{
if (visible)
emit showButtons();
else
emit hideButtons();
QTabBar::setVisible(visible);
}
void TabBar::setVisible(bool visible)
{
if (visible) {
if (p_QupZilla->isFullScreen())
return;
emit showButtons();
}
else {
emit hideButtons();
}
QTabBar::setVisible(visible);
}
void TabBar::contextMenuRequested(const QPoint &position)
{
int index = tabAt(position);
m_clickedTab = index;
QMenu menu;
menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab()));
menu.addSeparator();
if (index!=-1) {
WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab));
if (!webTab)
return;
if (p_QupZilla->weView(m_clickedTab)->isLoading())
menu.addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop Tab"), this, SLOT(stopTab()));
else
menu.addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload Tab"), this, SLOT(reloadTab()));
menu.addAction(tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
menu.addSeparator();
menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs()));
menu.addSeparator();
QAction* action = p_QupZilla->actionRestoreTab();
m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false);
menu.addAction(action);
menu.addSeparator();
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab()));
menu.addSeparator();
} else {
menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
menu.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs()));
menu.addSeparator();
QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab()));
m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false);
}
//Prevent choosing first option with double rightclick
QPoint pos = QCursor::pos();
QPoint p(pos.x(), pos.y()+1);
menu.exec(p);
p_QupZilla->actionRestoreTab()->setEnabled(true);
}
QSize TabBar::tabSizeHint(int index) const
{
QSize size = QTabBar::tabSizeHint(index);
WebTab* webTab = qobject_cast(m_tabWidget->widget(index));
TabBar* tabBar = const_cast (this);
tabBar->m_adjustingLastTab = false;
if (webTab && webTab->isPinned()) {
size.setWidth(PINNED_TAB_WIDTH);
} else {
int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width() - m_tabWidget->buttonAddTab()->width();
int normalTabsCount = count() - m_pinnedTabsCount;
if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount) {
tabBar->m_normalTabWidth = MAXIMUM_TAB_WIDTH;
size.setWidth(m_normalTabWidth);
}
else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) {
tabBar->m_normalTabWidth = MINIMUM_TAB_WIDTH;
size.setWidth(m_normalTabWidth);
}
else {
int maxWidthForTab = availableWidth / normalTabsCount;
tabBar->m_normalTabWidth = maxWidthForTab;
//Fill any empty space (gotten from rounding) with last tab
if (index == count() - 1) {
tabBar->m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
tabBar->m_adjustingLastTab = true;
size.setWidth(m_lastTabWidth);
}
else {
tabBar->m_lastTabWidth = maxWidthForTab;
size.setWidth(m_lastTabWidth);
}
}
}
if (index == count() - 1) {
int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth);
if (m_adjustingLastTab)
xForAddTabButton += m_lastTabWidth - m_normalTabWidth;
emit tabBar->moveAddTabButton(xForAddTabButton);
}
return size;
}
//void TabBar::emitMoveAddTabButton(int pox)
//{
// emit moveAddTabButton(pox);
//}
#if 0
void TabBar::tabInserted(int index)
{
// CloseButton* closeButton = new CloseButton(this);
// closeButton->setAutoRaise(true);
// closeButton->setMaximumSize(17,17);
// closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
// connect(closeButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
// setTabButton(index, QTabBar::RightSide, closeButton);
QAbstractButton* button = (QAbstractButton*)tabButton(index, QTabBar::RightSide);
if (!button)
return;
button->resize(17,17);
}
void TabBar::showCloseButton(int index)
{
WebTab* webTab = qobject_cast(m_tabWidget->widget(index));
if (webTab && webTab->isPinned())
return;
CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide);
if (!button)
return;
button->show();
}
void TabBar::hideCloseButton(int index)
{
CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide);
if (!button)
return;
button->hide();
}
#endif
void TabBar::updateCloseButton(int index)
{
QAbstractButton* button = qobject_cast(tabButton(index, QTabBar::RightSide));
if (!button)
return;
WebTab* webTab = qobject_cast(m_tabWidget->widget(index));
if (webTab && webTab->isPinned())
button->hide();
else
button->show();
}
void TabBar::closeCurrentTab()
{
int id = currentIndex();
if (id < 0)
return;
m_tabWidget->closeTab(id);
}
void TabBar::bookmarkTab()
{
p_QupZilla->addBookmark(p_QupZilla->weView(m_clickedTab)->url(), p_QupZilla->weView(m_clickedTab)->title(), p_QupZilla->weView(m_clickedTab)->siteIcon());
}
void TabBar::pinTab()
{
WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab));
if (!webTab)
return;
webTab->pinTab(m_clickedTab);
if (webTab->isPinned())
m_pinnedTabsCount++;
else
m_pinnedTabsCount--;
// Adjust add tab button in proper position
tabSizeHint(count() - 1);
}
void TabBar::pinnedTabClosed()
{
m_pinnedTabsCount--;
}
void TabBar::pinnedTabAdded()
{
m_pinnedTabsCount++;
}
+int TabBar::pinnedTabsCount()
+{
+ return m_pinnedTabsCount;
+}
+
+int TabBar::normalTabsCount()
+{
+ return count() - m_pinnedTabsCount;
+}
+
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) {
m_tabWidget->addView(QUrl(),tr("New tab"), TabWidget::NewTab, true);
return;
}
QTabBar::mouseDoubleClickEvent(event);
}
void TabBar::mousePressEvent(QMouseEvent* event)
{
int id = tabAt(event->pos());
if (id != -1 && event->buttons() == Qt::MiddleButton) {
m_tabWidget->closeTab(id);
return;
}
if (id == -1 && event->buttons() == Qt::MiddleButton) {
m_tabWidget->addView(QUrl(), tr("New tab"), TabWidget::NewSelectedTab, true);
return;
}
QTabBar::mousePressEvent(event);
}
diff --git a/src/webview/tabbar.h b/src/webview/tabbar.h
index bdda15be..e557c30a 100644
--- a/src/webview/tabbar.h
+++ b/src/webview/tabbar.h
@@ -1,101 +1,104 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* ============================================================ */
#ifndef TABBAR_H
#define TABBAR_H
#include
#include
#include
#include
#include
#include
#include
class QupZilla;
class TabWidget;
class TabBar : public QTabBar
{
Q_OBJECT
public:
explicit TabBar(QupZilla* mainClass, TabWidget* tabWidget);
// void hideCloseButton(int index);
// void showCloseButton(int index);
void updateCloseButton(int index);
QSize getTabSizeHint(int index) { return QTabBar::tabSizeHint(index); }
void loadSettings();
QSize getTabSizeHint(int index) const { return QTabBar::tabSizeHint(index); }
void setVisible(bool visible);
void updateVisibilityWithFullscreen(bool visible);
+ int pinnedTabsCount();
+ int normalTabsCount();
+
signals:
void reloadTab(int index);
void stopTab(int index);
void backTab(int index);
void forwardTab(int index);
void closeAllButCurrent(int index);
void closeTab(int index);
void duplicateTab(int index);
void moveAddTabButton(int posX);
void showButtons();
void hideButtons();
public slots:
private slots:
void pinnedTabAdded();
void pinnedTabClosed();
void contextMenuRequested(const QPoint &position);
void reloadTab() { emit reloadTab(m_clickedTab); }
void stopTab() { emit stopTab(m_clickedTab); }
void backTab() { emit backTab(m_clickedTab); }
void forwardTab() { emit forwardTab(m_clickedTab); }
void closeAllButCurrent() { emit closeAllButCurrent(m_clickedTab); }
void closeTab() { emit closeTab(m_clickedTab); }
void duplicateTab() { emit duplicateTab(m_clickedTab); }
void bookmarkTab();
void pinTab();
void closeCurrentTab();
private:
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
QSize tabSizeHint(int index) const;
// void tabInserted(int index);
// void emitMoveAddTabButton(int pox);
QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
bool m_showCloseButtonWithOneTab;
bool m_showTabBarWithOneTab;
int m_clickedTab;
int m_pinnedTabsCount;
int m_normalTabWidth;
int m_lastTabWidth;
bool m_adjustingLastTab;
};
#endif // TABBAR_H