summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp169
1 files changed, 113 insertions, 56 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 29044745..b2c1fed1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -45,7 +45,6 @@
#include "findbar.h"
#include "sidepanel.h"
#include "urlbar.h"
-#include "stackedurlbar.h"
// Ui Includes
#include "ui_cleardata.h"
@@ -89,11 +88,16 @@
MainWindow::MainWindow()
- : KXmlGuiWindow()
- , m_view(new MainView(this))
- , m_findBar(new FindBar(this))
- , m_sidePanel(0)
+ : KMainWindow()
+ , m_view(new MainView(this))
+ , m_findBar(new FindBar(this))
+ , m_sidePanel(0)
+ , m_historyBackMenu(0)
+ , m_ac( new KActionCollection(this) )
{
+ // enable window size "auto-save"
+ setAutoSaveSettings();
+
// updating rekonq configuration
slotUpdateConfiguration();
@@ -117,27 +121,20 @@ MainWindow::MainWindow()
// then, setup our actions
setupActions();
- // setting up toolbars && location bar: this has to be done BEFORE setupGUI!!
- setupBars();
-
// Bookmark Menu
KActionMenu *bmMenu = Application::bookmarkProvider()->bookmarkActionMenu();
bmMenu->setIcon(KIcon("rating"));
actionCollection()->addAction(QLatin1String("bookmarksActionMenu"), bmMenu);
((KActionMenu *)actionByName("bookmarksActionMenu"))->setDelayed(false);
- // Side Panel: this has to be done BEFORE setupGUI!!
+ // setting Side Panel
setupSidePanel();
- // setting up rekonq tools: to be done BEFORE setupGUI!
+ // setting up rekonq tools
setupTools();
-
- // a call to KXmlGuiWindow::setupGUI() populates the GUI
- // with actions, using KXMLGUI.
- // It also applies the saved mainwindow settings, if any, and ask the
- // mainwindow to automatically save settings if changed: window size,
- // toolbar position, icon size, etc.
- setupGUI();
+
+ // setting up rekonq toolbar(s)
+ setupToolbar();
// no more status bar..
setStatusBar(0);
@@ -159,11 +156,27 @@ SidePanel *MainWindow::sidePanel()
}
-void MainWindow::postLaunch()
+void MainWindow::setupToolbar()
{
- // setup history menu: this has to be done AFTER setupGUI!!
- setupHistoryMenu();
+ KToolBar *mainToolBar = new KToolBar( QString("MainToolBar"), this, Qt::TopToolBarArea);
+ mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
+ mainToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
+ mainToolBar->addAction( actionByName("history_back") );
+ mainToolBar->addAction( actionByName("history_forward") );
+ mainToolBar->addSeparator();
+ mainToolBar->addAction( actionByName("stop_reload") );
+ mainToolBar->addAction( actionByName(KStandardAction::name(KStandardAction::Home)) );
+ mainToolBar->addAction( actionByName("url_bar") );
+ mainToolBar->addAction( actionByName("bookmarksActionMenu") );
+ mainToolBar->addAction( actionByName("rekonq_tools") );
+
+ KToolBar::setToolBarsEditable(false);
+ KToolBar::setToolBarsLocked(true);
+}
+
+void MainWindow::postLaunch()
+{
// --------- connect signals and slots
connect(m_view, SIGNAL(setCurrentTitle(const QString &)), this, SLOT(slotUpdateWindowTitle(const QString &)));
connect(m_view, SIGNAL(printRequested(QWebFrame *)), this, SLOT(printRequested(QWebFrame *)));
@@ -176,13 +189,19 @@ void MainWindow::postLaunch()
connect(m_findBar, SIGNAL(searchString(const QString &)), this, SLOT(slotFind(const QString &)));
// bookmarks loading
- connect(Application::bookmarkProvider(), SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)), Application::instance(), SLOT(loadUrl(const KUrl&, const Rekonq::OpenType&)));
+ connect(Application::bookmarkProvider(), SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)),
+ Application::instance(), SLOT(loadUrl(const KUrl&, const Rekonq::OpenType&)));
// setting up toolbars to NOT have context menu enabled
setContextMenuPolicy(Qt::DefaultContextMenu);
// accept d'n'd
setAcceptDrops(true);
+
+ // set CookieJar window Id
+ const qlonglong winId = window()->winId();
+ Application::cookieJar()->setWindowId(winId);
+ Application::networkAccessManager()->metaData().insert("window-id", QString::number(winId));
}
@@ -194,31 +213,33 @@ QSize MainWindow::sizeHint() const
}
-void MainWindow::setupBars()
+KActionCollection *MainWindow::actionCollection () const
{
+ return m_ac;
+}
+
+
+void MainWindow::setupActions()
+{
+ // this let shortcuts work..
+ actionCollection()->addAssociatedWidget(this);
+
KAction *a;
// location bar
a = new KAction(i18n("Location Bar"), this);
a->setShortcut(KShortcut(Qt::Key_F6));
- a->setDefaultWidget(m_view->urlBarStack());
+ a->setDefaultWidget(m_view->urlBar());
actionCollection()->addAction(QLatin1String("url_bar"), a);
// bookmarks bar
KAction *bookmarkBarAction = Application::bookmarkProvider()->bookmarkToolBarAction();
a = actionCollection()->addAction(QLatin1String("bookmarks_bar"), bookmarkBarAction);
-}
-
-
-void MainWindow::setupActions()
-{
- KAction *a;
// Standard Actions
KStandardAction::open(this, SLOT(slotFileOpen()), actionCollection());
- KStandardAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
- KStandardAction::printPreview(this, SLOT(slotFilePrintPreview()), actionCollection());
- KStandardAction::print(this, SLOT(slotFilePrint()), actionCollection());
+ KStandardAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
+ KStandardAction::print(this, SLOT(slotFilePrintPreview()), actionCollection());
KStandardAction::quit(this , SLOT(close()), actionCollection());
KStandardAction::find(m_findBar, SLOT(show()) , actionCollection());
KStandardAction::findNext(this, SLOT(slotFindNext()) , actionCollection());
@@ -235,13 +256,6 @@ void MainWindow::setupActions()
// WEB Actions (NO KStandardActions..)
a = KStandardAction::redisplay(m_view, SLOT(slotWebReload()), actionCollection());
a->setText(i18n("Reload"));
- KStandardAction::back(m_view, SLOT(slotWebBack()), actionCollection());
- KStandardAction::forward(m_view, SLOT(slotWebForward()), actionCollection());
- KStandardAction::undo(m_view, SLOT(slotWebUndo()), actionCollection());
- KStandardAction::redo(m_view, SLOT(slotWebRedo()), actionCollection());
- KStandardAction::cut(m_view, SLOT(slotWebCut()), actionCollection());
- KStandardAction::copy(m_view, SLOT(slotWebCopy()), actionCollection());
- KStandardAction::paste(m_view, SLOT(slotWebPaste()), actionCollection());
a = new KAction(KIcon("process-stop"), i18n("&Stop"), this);
a->setShortcut(KShortcut(Qt::CTRL | Qt::Key_Period));
@@ -297,6 +311,11 @@ void MainWindow::setupActions()
connect(m_historyBackAction, SIGNAL(triggered(bool)), this, SLOT(slotOpenPrevious()));
actionCollection()->addAction(QLatin1String("history_back"), m_historyBackAction);
+ m_historyBackMenu = new KMenu(this);
+ m_historyBackAction->setMenu(m_historyBackMenu);
+ connect(m_historyBackMenu, SIGNAL(aboutToShow()), this, SLOT(slotAboutToShowBackMenu()));
+ connect(m_historyBackMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenActionUrl(QAction *)));
+
m_historyForwardAction = new KAction(KIcon("go-next"), i18n("Forward"), this);
connect(m_historyForwardAction, SIGNAL(triggered(bool)), this, SLOT(slotOpenNext()));
actionCollection()->addAction(QLatin1String("history_forward"), m_historyForwardAction);
@@ -331,13 +350,21 @@ void MainWindow::setupActions()
void MainWindow::setupTools()
{
- KActionMenu *toolsMenu = new KActionMenu(KIcon("configure"), i18n("rekonq tools"), this);
+ KActionMenu *toolsMenu = new KActionMenu(KIcon("configure"), i18n("&Tools"), this);
toolsMenu->setDelayed(false);
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::SaveAs)));
- toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::PrintPreview)));
+ toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Print)));
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Find)));
+ KActionMenu *fontMenu = new KActionMenu(KIcon("page-zoom"), i18n("Zoom"), this);
+ fontMenu->addAction(actionByName(QLatin1String("smaller_font")));
+ fontMenu->addAction(actionByName(QLatin1String("normal_font")));
+ fontMenu->addAction(actionByName(QLatin1String("bigger_font")));
+ toolsMenu->addAction(fontMenu);
+
+ toolsMenu->addSeparator();
+
KActionMenu *webMenu = new KActionMenu(KIcon("applications-development-web"), i18n("Web Development"), this);
webMenu->addAction(actionByName(QLatin1String("web_inspector")));
webMenu->addAction(actionByName(QLatin1String("page_source")));
@@ -355,8 +382,8 @@ void MainWindow::setupTools()
toolsMenu->addSeparator();
- // TODO: decide if re-enable this when rekonq docs will be written
- // toolsMenu->addAction(KStandardAction::helpContents(this, SLOT(appHelpActivated()), actionCollection()));
+ helpMenu()->setIcon(KIcon("help-browser"));
+ toolsMenu->addAction(helpMenu()->menuAction());
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Preferences)));
// adding rekonq_tools to rekonq actionCollection
@@ -468,8 +495,8 @@ void MainWindow::slotUpdateBrowser()
void MainWindow::slotOpenLocation()
{
- m_view->currentUrlBar()->selectAll();
- m_view->currentUrlBar()->setFocus();
+ m_view->urlBar()->selectAll();
+ m_view->urlBar()->setFocus();
}
@@ -552,14 +579,6 @@ void MainWindow::slotFilePrintPreview()
}
-void MainWindow::slotFilePrint()
-{
- if (!currentTab())
- return;
- printRequested(currentTab()->page()->mainFrame());
-}
-
-
void MainWindow::printRequested(QWebFrame *frame)
{
QPrinter printer;
@@ -591,7 +610,7 @@ void MainWindow::slotPrivateBrowsing(bool enable)
if (button == KMessageBox::Yes)
{
settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
- m_view->currentUrlBar()->setBackgroundColor(Qt::lightGray); // palette().color(QPalette::Active, QPalette::Background));
+ m_view->urlBar()->setBackgroundColor(Qt::lightGray); // palette().color(QPalette::Active, QPalette::Background));
}
else
{
@@ -601,7 +620,7 @@ void MainWindow::slotPrivateBrowsing(bool enable)
else
{
settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, false);
- m_view->currentUrlBar()->setBackgroundColor(palette().color(QPalette::Active, QPalette::Base));
+ m_view->urlBar()->setBackgroundColor(palette().color(QPalette::Active, QPalette::Base));
m_lastSearch.clear();
m_view->clear();
@@ -876,7 +895,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
return;
}
- KXmlGuiWindow::keyPressEvent(event);
+ KMainWindow::keyPressEvent(event);
}
@@ -1000,3 +1019,41 @@ void MainWindow::clearPrivateData()
// this let crash rekonq.
// delete dialog;
}
+
+
+void MainWindow::slotAboutToShowBackMenu()
+{
+ m_historyBackMenu->clear();
+ if (!currentTab())
+ return;
+ QWebHistory *history = currentTab()->history();
+ int historyCount = history->count();
+ for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i)
+ {
+ QWebHistoryItem item = history->backItems(history->count()).at(i);
+ KAction *action = new KAction(this);
+ action->setData(-1*(historyCount - i - 1));
+ QIcon icon = Application::instance()->icon(item.url());
+ action->setIcon(icon);
+ action->setText(item.title());
+ m_historyBackMenu->addAction(action);
+ }
+}
+
+
+void MainWindow::slotOpenActionUrl(QAction *action)
+{
+ int offset = action->data().toInt();
+ QWebHistory *history = currentTab()->history();
+ if (offset < 0)
+ {
+ history->goToItem(history->backItems(-1*offset).first()); // back
+ }
+ else
+ {
+ if (offset > 0)
+ {
+ history->goToItem(history->forwardItems(history->count() - offset + 1).back()); // forward
+ }
+ }
+}