diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-08-10 17:34:04 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:05 +0100 |
commit | 08ca2545eede86a0f6de42be596b063de1321ddb (patch) | |
tree | 9f1d9986b04d7db3ace13f9304eae704d9c189eb /src/webwindow | |
parent | FindBar. Rewamped and restored (diff) | |
download | rekonq-08ca2545eede86a0f6de42be596b063de1321ddb.tar.xz |
Manage Bookmarks Toolbar show/hide (&& create/delete)
Diffstat (limited to 'src/webwindow')
-rw-r--r-- | src/webwindow/rekonqfactory.cpp | 36 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 66 | ||||
-rw-r--r-- | src/webwindow/webwindow.h | 5 |
3 files changed, 90 insertions, 17 deletions
diff --git a/src/webwindow/rekonqfactory.cpp b/src/webwindow/rekonqfactory.cpp index 78cd0367..8b09c0bd 100644 --- a/src/webwindow/rekonqfactory.cpp +++ b/src/webwindow/rekonqfactory.cpp @@ -44,20 +44,40 @@ #include <QDomElement> -QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActionCollection *ac) +// Only used internally +bool readDocument(QDomDocument & document, const QString & filePath) { - QString xmlFilePath; - xmlFilePath = KStandardDirs::locateLocal( "data", "rekonq/rekonqui.rc"); - if (!QFile::exists(xmlFilePath)) + QFile sessionFile(filePath); + + if (!sessionFile.exists()) + return false; + + if (!sessionFile.open(QFile::ReadOnly)) { - xmlFilePath = KStandardDirs::locate( "data", "rekonq/rekonqui.rc"); - kDebug() << "general xmlfile: " << xmlFilePath; + kDebug() << "Unable to open xml file" << sessionFile.fileName(); + return false; } - QFile xmlFile(xmlFilePath); + if (!document.setContent(&sessionFile, false)) + { + kDebug() << "Unable to parse xml file" << sessionFile.fileName(); + return false; + } + + return true; +} + + +// --------------------------------------------------------------------------------------------------------- + +QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActionCollection *ac) +{ QDomDocument document("rekonqui.rc"); - document.setContent(&xmlFile, false); + QString xmlFilePath = KStandardDirs::locate( "data", "rekonq/rekonqui.rc"); + + if (!readDocument(document, xmlFilePath)) + return 0; // Toolbars ---------------------------------------------------------------------- QDomNodeList elementToolbarList = document.elementsByTagName(QL1S("ToolBar")); diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 0af79cb6..83c49859 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -27,6 +27,9 @@ #include "webwindow.h" #include "webwindow.moc" +// Auto Includes +#include "rekonq.h" + #include "application.h" #include "adblockmanager.h" @@ -72,7 +75,6 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) , _tab(new WebTab(this)) , _bar(new UrlBar(_tab)) , _mainToolBar(0) - , _bookmarksBar(0) , m_findBar(new FindBar(this)) , m_loadStopReloadAction(0) , m_rekonqMenu(0) @@ -92,22 +94,30 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) // setting up rekonq tools setupTools(); + // layout + QVBoxLayout *l = new QVBoxLayout(this); + // main toolbar _mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this, actionCollection())); + l->addWidget(_mainToolBar); - _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this, actionCollection())); - BookmarkManager::self()->registerBookmarkBar(_bookmarksBar); + if (ReKonfig::showBookmarksToolbar()) + { + _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this, actionCollection())); + BookmarkManager::self()->registerBookmarkBar(_bookmarksBar.data()); - // layout - QVBoxLayout *l = new QVBoxLayout(this); - l->addWidget(_mainToolBar); - l->addWidget(_bookmarksBar); + l->addWidget(_bookmarksBar.data()); + } + l->addWidget(_tab); l->addWidget(m_findBar); l->setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0); + // bookmarks toolbar + connect(rApp, SIGNAL(toggleBookmarksToolbar(bool)), this, SLOT(toggleBookmarksToolbar(bool))); + // things changed signals connect(_tab->view(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); @@ -135,7 +145,11 @@ WebWindow::~WebWindow() { m_hidePopupTimer->stop(); - BookmarkManager::self()->removeBookmarkBar(_bookmarksBar); + if (!_bookmarksBar.isNull()) + { + BookmarkManager::self()->removeBookmarkBar(_bookmarksBar.data()); + _bookmarksBar.clear(); + } } @@ -189,6 +203,13 @@ void WebWindow::setupActions() KStandardAction::preferences(this, SLOT(preferences()), actionCollection()); KStandardAction::quit(rApp, SLOT(queryQuit()), actionCollection()); + // Bookmark Toolbar + a = new KAction(KIcon("bookmarks-bar"), i18n("Bookmarks Toolbar"), this); + a->setCheckable(true); + a->setChecked(ReKonfig::showBookmarksToolbar()); + actionCollection()->addAction(QL1S("show_bookmarks_toolbar"), a); + connect(a, SIGNAL(toggled(bool)), this, SLOT(toggleBookmarksToolbar(bool))); + // find action a = KStandardAction::find(m_findBar, SLOT(show()), actionCollection()); KShortcut findShortcut = KStandardShortcut::find(); @@ -816,3 +837,32 @@ void WebWindow::preferences() s->show(); } + + +void WebWindow::toggleBookmarksToolbar(bool b) +{ + bool actual = !_bookmarksBar.isNull(); + if (actual == b) + return; + + if (b) + { + _bookmarksBar = qobject_cast<BookmarkToolBar *>(RekonqFactory::createWidget(QL1S("bookmarkToolBar"), this, actionCollection())); + BookmarkManager::self()->registerBookmarkBar(_bookmarksBar.data()); + + qobject_cast<QVBoxLayout *>(layout())->insertWidget(1, _bookmarksBar.data()); + } + else + { + qobject_cast<QVBoxLayout *>(layout())->removeWidget(_bookmarksBar.data()); + + BookmarkManager::self()->removeBookmarkBar(_bookmarksBar.data()); + delete _bookmarksBar.data(); + _bookmarksBar.clear(); + } + + ReKonfig::setShowBookmarksToolbar(b); + QAction *a = actionByName(QL1S("show_bookmarks_toolbar")); + a->setChecked(b); + rApp->bookmarksToolbarToggled(b); +} diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h index 697d74e3..37f9c3c0 100644 --- a/src/webwindow/webwindow.h +++ b/src/webwindow/webwindow.h @@ -110,6 +110,9 @@ private Q_SLOTS: void fileOpen(); void fileSaveAs(); + // bookmarks bar + void toggleBookmarksToolbar(bool); + // Tools Menu slots void viewPageSource(); void viewFullScreen(bool enable); @@ -136,7 +139,7 @@ private: UrlBar *_bar; KToolBar *_mainToolBar; - BookmarkToolBar *_bookmarksBar; + QWeakPointer<BookmarkToolBar> _bookmarksBar; FindBar *m_findBar; |