summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp204
1 files changed, 121 insertions, 83 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index cbef274a..f0cb5e61 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -38,6 +38,7 @@
#include "settingsdialog.h"
#include "historymanager.h"
#include "bookmarksmanager.h"
+#include "bookmarkstoolbar.h"
#include "webtab.h"
#include "mainview.h"
#include "findbar.h"
@@ -57,6 +58,7 @@
#include <KShortcut>
#include <KStandardAction>
#include <KAction>
+#include <KEditToolBar>
#include <KToggleFullScreenAction>
#include <KActionCollection>
#include <KMessageBox>
@@ -105,7 +107,7 @@ MainWindow::MainWindow()
, m_analyzerPanel(0)
, m_historyBackMenu(0)
, m_encodingMenu(new KMenu(this))
- , m_bookmarksBar(new BookmarkToolBar(QString("BookmarkToolBar"), this, Qt::TopToolBarArea, true, false, true))
+ , m_bookmarksBar(0)
, m_popup(new KPassivePopup(this))
, m_hidePopup(new QTimer(this))
{
@@ -139,16 +141,16 @@ MainWindow::MainWindow()
// setting up rekonq toolbar(s)
setupToolbars();
- // 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.
+ // 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();
-
+
// no menu bar in rekonq: we have other plans..
menuBar()->setVisible(false);
-
+
// no more status bar..
setStatusBar(0);
@@ -164,7 +166,7 @@ MainWindow::~MainWindow()
Application::bookmarkProvider()->removeToolBar(m_bookmarksBar);
Application::bookmarkProvider()->removeBookmarkPanel(m_bookmarksPanel);
Application::instance()->removeMainWindow(this);
-
+
delete m_view;
delete m_findBar;
delete m_zoomBar;
@@ -187,7 +189,7 @@ MainWindow::~MainWindow()
void MainWindow::setupToolbars()
{
kDebug() << "setup toolbars...";
-
+
KAction *a;
// location bar
@@ -197,34 +199,42 @@ void MainWindow::setupToolbars()
KToolBar *mainBar = toolBar("mainToolBar");
- // bookmarks bar
- KAction *bookmarkBarAction = Application::bookmarkProvider()->bookmarkToolBarAction(m_bookmarksBar);
- a = actionCollection()->addAction( QL1S("bookmarks_bar"), bookmarkBarAction);
-
mainBar->show(); // this just to fix reopening rekonq after fullscreen close
-
- // =========== Bookmarks ToolBar ================================
- m_bookmarksBar->setAcceptDrops(true);
- Application::bookmarkProvider()->setupBookmarkBar(m_bookmarksBar);
}
-void MainWindow::postLaunch()
+void MainWindow::initBookmarkBar()
{
- KToolBar *mainBar = toolBar("mainToolBar");
-
- QToolButton *bookmarksButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("bookmarksActionMenu") )));
- if(bookmarksButton)
- {
- connect(actionByName(QL1S("bookmarksActionMenu")), SIGNAL(triggered()), bookmarksButton, SLOT(showMenu()));
- }
-
- QToolButton *toolsButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("rekonq_tools") )));
- if(toolsButton)
+ KToolBar *XMLGUIBkBar = toolBar("bookmarkToolBar");
+ if (!XMLGUIBkBar)
+ return;
+
+ if (m_bookmarksBar)
{
- connect(actionByName(QL1S("rekonq_tools")), SIGNAL(triggered()), toolsButton, SLOT(showMenu()));
+ Application::bookmarkProvider()->removeToolBar(m_bookmarksBar);
+ delete m_bookmarksBar;
}
-
+ m_bookmarksBar = new BookmarkToolBar(XMLGUIBkBar, this);
+ Application::bookmarkProvider()->registerBookmarkBar(m_bookmarksBar);
+}
+
+
+void MainWindow::configureToolbars()
+{
+ if (autoSaveSettings())
+ saveAutoSaveSettings();
+
+ KEditToolBar dlg(factory(), this);
+ // The bookmark bar needs to be refill after the UI changes are finished
+ connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(initBookmarkBar()));
+ dlg.exec();
+}
+
+
+void MainWindow::postLaunch()
+{
+ setupBookmarksAndToolsShortcuts();
+
// setting popup notification
m_popup->setAutoDelete(false);
connect(Application::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), m_popup, SLOT(hide()));
@@ -258,12 +268,15 @@ void MainWindow::postLaunch()
connect(m_view, SIGNAL(currentChanged(int)), m_zoomBar, SLOT(updateSlider(int)));
// Ctrl + wheel handling
connect(this->currentTab()->view(), SIGNAL(zoomChanged(int)), m_zoomBar, SLOT(setValue(int)));
-
+
// setting up toolbars to NOT have context menu enabled
setContextMenuPolicy(Qt::DefaultContextMenu);
// accept d'n'd
setAcceptDrops(true);
+
+ // Bookmark ToolBar (needs to be setup after the call to setupGUI())
+ initBookmarkBar();
}
@@ -278,7 +291,7 @@ QSize MainWindow::sizeHint() const
void MainWindow::setupActions()
{
kDebug() << "setup actions...";
-
+
// this let shortcuts work..
actionCollection()->addAssociatedWidget(this);
@@ -389,7 +402,7 @@ void MainWindow::setupActions()
a->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() : KStandardShortcut::tabPrev());
actionCollection()->addAction(QL1S("show_prev_tab"), a);
connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab()));
-
+
a = new KAction(KIcon("tab-new"), i18n("Open Closed Tabs"), this);
a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
actionCollection()->addAction(QL1S("open_closed_tabs"), a);
@@ -455,7 +468,7 @@ void MainWindow::setupTools()
toolsMenu->setDelayed(false);
toolsMenu->setShortcutConfigurable(true);
toolsMenu->setShortcut( KShortcut(Qt::ALT + Qt::Key_T) );
-
+
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Open)));
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::SaveAs)));
toolsMenu->addAction(actionByName(KStandardAction::name(KStandardAction::Print)));
@@ -547,7 +560,7 @@ void MainWindow::setupPanels()
addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorPanel);
m_webInspectorPanel->hide();
-
+
// STEP 4
// Setup Network analyzer panel
m_analyzerPanel = new NetworkAnalyzerPanel( i18n("Network Analyzer"), this);
@@ -584,7 +597,7 @@ void MainWindow::fileSaveAs()
srcUrl = w->url();
}
kDebug() << "URL to save: " << srcUrl;
-
+
QString name = srcUrl.fileName();
if (name.isNull())
{
@@ -621,7 +634,7 @@ void MainWindow::updateActions()
{
kDebug() << "updating actions..";
bool rekonqPage = currentTab()->page()->isOnRekonqPage();
-
+
QAction *historyBackAction = actionByName(KStandardAction::name(KStandardAction::Back));
if( rekonqPage && currentTab()->view()->history()->count() > 0 )
historyBackAction->setEnabled(true);
@@ -837,7 +850,7 @@ void MainWindow::setWidgetsVisible(bool makeVisible)
KToolBar *mainBar = toolBar("mainToolBar");
KToolBar *bookBar = toolBar("bookmarksToolBar");
-
+
if (!makeVisible)
{
// save current state, if in windowed mode
@@ -885,10 +898,10 @@ void MainWindow::viewPageSource()
void MainWindow::homePage(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers keyboardModifiers)
{
- KUrl homeUrl = ReKonfig::useNewTabPage()
+ KUrl homeUrl = ReKonfig::useNewTabPage()
? KUrl( QL1S("about:home") )
: KUrl( ReKonfig::homePage() );
-
+
if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier)
Application::instance()->loadUrl( homeUrl, Rekonq::NewTab);
else
@@ -930,7 +943,7 @@ void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifie
{
QWebHistory *history = currentTab()->view()->history();
QWebHistoryItem *item = 0;
-
+
if (currentTab()->page()->isOnRekonqPage())
{
item = new QWebHistoryItem(history->currentItem());
@@ -946,7 +959,7 @@ void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifie
if(!item)
return;
-
+
if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier)
{
Application::instance()->loadUrl(item->url(), Rekonq::NewTab);
@@ -977,10 +990,10 @@ void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers k
item = new QWebHistoryItem(history->forwardItem());
}
}
-
+
if(!item)
return;
-
+
if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier)
{
Application::instance()->loadUrl(item->url(), Rekonq::NewTab);
@@ -989,7 +1002,7 @@ void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers k
{
history->goToItem(*item);
}
-
+
updateActions();
}
@@ -1181,7 +1194,7 @@ void MainWindow::aboutToShowBackMenu()
offset = pivot - 8;
/*
- * Need a bug report upstream.
+ * Need a bug report upstream.
* Seems setHtml() do some garbage in history
* Here history->currentItem() have backItem url and currentItem (error page) title
*/
@@ -1195,7 +1208,7 @@ void MainWindow::aboutToShowBackMenu()
action->setText(item.title());
m_historyBackMenu->addAction(action);
}
-
+
for (int i = listCount - 1; i >= 0; --i)
{
QWebHistoryItem item = historyList.at(i);
@@ -1236,7 +1249,7 @@ void MainWindow::setEncoding(QAction *qa)
currentTab()->view()->reload();
return;
}
-
+
currentTab()->view()->settings()->setDefaultTextEncoding(currentCodec);
currentTab()->view()->reload();
}
@@ -1246,7 +1259,7 @@ void MainWindow::populateEncodingMenu()
{
QStringList codecs;
QList<int> mibs = QTextCodec::availableMibs();
- Q_FOREACH (const int &mib, mibs)
+ Q_FOREACH (const int &mib, mibs)
{
QString codec = QLatin1String(QTextCodec::codecForMib(mib)->name());
codecs.append(codec);
@@ -1261,13 +1274,13 @@ void MainWindow::populateEncodingMenu()
KMenu *isciiMenu = new KMenu( QL1S("ISCII"), m_encodingMenu);
KMenu *uniMenu = new KMenu( QL1S("Unicode"), m_encodingMenu);
KMenu *otherMenu = new KMenu( i18n("Other"), m_encodingMenu);
-
+
QAction *a;
bool isDefaultCodecUsed = true;
-
+
Q_FOREACH(const QString &codec, codecs)
{
-
+
if( codec.startsWith( QL1S("ISO"), Qt::CaseInsensitive ) )
a = isoMenu->addAction(codec);
else if( codec.startsWith( QL1S("win") ) )
@@ -1276,9 +1289,9 @@ void MainWindow::populateEncodingMenu()
a = isciiMenu->addAction(codec);
else if( codec.startsWith( QL1S("UT") ) )
a = uniMenu->addAction(codec);
- else
+ else
a = otherMenu->addAction(codec);
-
+
a->setCheckable(true);
if (currentCodec == codec)
{
@@ -1286,11 +1299,11 @@ void MainWindow::populateEncodingMenu()
isDefaultCodecUsed = false;
}
}
-
+
a = new QAction( i18nc("Default website encoding", "Default"), this);
a->setCheckable(true);
a->setChecked(isDefaultCodecUsed);
-
+
m_encodingMenu->addAction( a );
m_encodingMenu->addMenu( isoMenu );
m_encodingMenu->addMenu( winMenu );
@@ -1312,34 +1325,59 @@ bool MainWindow::queryClose()
// this should fux bug 240432
if(Application::instance()->sessionSaving())
return true;
-
- if (m_view->count() > 1)
+
+ if (m_view->count() > 1)
{
- int answer = KMessageBox::questionYesNoCancel(
- this,
+ int answer = KMessageBox::questionYesNoCancel(
+ this,
i18np("Are you sure you want to close the window?\n" "You have 1 tab open.",
- "Are you sure you want to close the window?\n" "You have %1 tabs open.",
+ "Are you sure you want to close the window?\n" "You have %1 tabs open.",
m_view->count()),
- i18n("Are you sure you want to close the window?"),
- KStandardGuiItem::quit(),
- KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")),
- KStandardGuiItem::cancel(),
- "confirmClosingMultipleTabs"
- );
-
- switch (answer)
- {
- case KMessageBox::Yes:
- // Quit
- return true;
-
- case KMessageBox::No:
- // Close only the current tab
+ i18n("Are you sure you want to close the window?"),
+ KStandardGuiItem::quit(),
+ KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")),
+ KStandardGuiItem::cancel(),
+ "confirmClosingMultipleTabs"
+ );
+
+ switch (answer)
+ {
+ case KMessageBox::Yes:
+ // Quit
+ return true;
+
+ case KMessageBox::No:
+ // Close only the current tab
m_view->closeTab();
-
- default:
- return false;
- }
- }
- return true;
+
+ default:
+ return false;
+ }
+ }
+ return true;
+}
+
+
+void MainWindow::saveNewToolbarConfig()
+{
+ KXmlGuiWindow::saveNewToolbarConfig();
+ setupBookmarksAndToolsShortcuts();
+}
+
+
+void MainWindow::setupBookmarksAndToolsShortcuts()
+{
+ KToolBar *mainBar = toolBar("mainToolBar");
+
+ QToolButton *bookmarksButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("bookmarksActionMenu") )));
+ if(bookmarksButton)
+ {
+ connect(actionByName(QL1S("bookmarksActionMenu")), SIGNAL(triggered()), bookmarksButton, SLOT(showMenu()));
+ }
+
+ QToolButton *toolsButton = qobject_cast<QToolButton*>(mainBar->widgetForAction(actionByName( QL1S("rekonq_tools") )));
+ if(toolsButton)
+ {
+ connect(actionByName(QL1S("rekonq_tools")), SIGNAL(triggered()), toolsButton, SLOT(showMenu()));
+ }
}