diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2008-12-02 16:22:28 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2008-12-02 16:22:28 +0100 |
commit | 15ecefe10101dd068c4e075fca23ba64519bedb1 (patch) | |
tree | 0985bb87525a74c1bc2d6edb5bca29fff8140301 | |
parent | New BookmarkMenu implementation (diff) | |
download | rekonq-0.0.1.tar.xz |
New Bookmarks menu, sharing bkmrs with Konqueror0.0.1
(And that's reKonq 1st feature!!)
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/bookmarks.cpp | 41 | ||||
-rw-r--r-- | src/bookmarks.h | 28 | ||||
-rw-r--r-- | src/browsermainwindow.cpp | 19 | ||||
-rw-r--r-- | src/browsermainwindow.h | 7 | ||||
-rw-r--r-- | src/tabwidget.cpp | 50 | ||||
-rw-r--r-- | src/webview.h | 10 |
7 files changed, 115 insertions, 41 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bb01a78e..1e2a3866 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ SET( rekonq_SRCS edittableview.cpp edittreeview.cpp history.cpp + bookmarks.cpp modelmenu.cpp networkaccessmanager.cpp urlbar.cpp diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index 29c175e8..6f9c3beb 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -17,42 +17,55 @@ * * ============================================================ */ +// Local Includes #include "bookmarks.h" #include "bookmarks.moc" +#include "browsermainwindow.h" +#include "webview.h" + +// KDE Includes +#include <KMimeType> OwnBookMarks::OwnBookMarks(KMainWindow *parent) + : QObject(parent) + , KBookmarkOwner() +{ + m_parent = qobject_cast<BrowserMainWindow*>( parent ); + connect( this, SIGNAL( openUrl( const QUrl &) ) , parent , SLOT( loadUrl( const QUrl & ) ) ); +} + + +void OwnBookMarks::openBookmark (const KBookmark & b, Qt::MouseButtons , Qt::KeyboardModifiers ) { + emit openUrl( (QUrl)b.url() ); +} +QString OwnBookMarks::currentUrl() const +{ + QUrl url = m_parent->currentTab()->url(); + return url.path(); } -virtual void OwnBookMarks::openBookmark (const KBookmark & , Qt::MouseButtons , Qt::KeyboardModifiers ) +QString OwnBookMarks::currentTitle() const { + QString title = m_parent->windowTitle(); + return title.remove( " - reKonq" ); } // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -BookmarkMenu::BookmarkMenu(KMainWindow *parent) +BookmarksMenu::BookmarksMenu(KMainWindow *parent) : KMenu(parent) + , m_owner( new OwnBookMarks( parent ) ) { - m_parent = parent; - KUrl bookfile = KUrl( "~/.kde/share/apps/konqueror/bookmarks.xml" ); // share konqueror bookmarks m_manager = KBookmarkManager::managerForExternalFile( bookfile.path() ); - m_owner = new OwnBookMarks(parent); - m_ac = new KActionCollection( this ); - setActions(); - m_menu = m_bookmarkMenu = new KBookmarkMenu( m_manager , m_owner, this, m_ac ); + m_menu = new KBookmarkMenu( m_manager , m_owner, this, m_ac ); } - - - void BookmarkMenu::setActions() -{ - m_ac->addAction( KStandardAction::addBookmark( m_parent, SLOT( slotAddBookmark() ) , this ) ); -}
\ No newline at end of file diff --git a/src/bookmarks.h b/src/bookmarks.h index 4f527436..80362e1c 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h @@ -20,36 +20,48 @@ #ifndef BOOKMARKS_H #define BOOKMARKS_H +// KDE Includes #include <KBookmarkOwner> #include <KBookmarkManager> #include <KBookmarkMenu> +#include <KActionCollection> +#include <KMainWindow> -class OwnBookMarks : public KBookMarkOwner +class BrowserMainWindow; + +class OwnBookMarks : public QObject , public KBookmarkOwner { Q_OBJECT public: - OwnBookMarks(KMainWindow *parent); + OwnBookMarks(KMainWindow * ); virtual void openBookmark (const KBookmark & , Qt::MouseButtons , Qt::KeyboardModifiers ); + + // KBookmarkOwner interface: + virtual QString currentUrl() const; + virtual QString currentTitle() const; + +signals: + void openUrl(const QUrl &); // FIXME pass all to KUrl!! + +private: + BrowserMainWindow *m_parent; }; -class BookmarkMenu : public KMenu +class BookmarksMenu : public KMenu { Q_OBJECT public: - BookmarkMenu(KMainWindow *parent); + BookmarksMenu(KMainWindow * parent); private: - void setActions(); - KBookmarkManager *m_manager; OwnBookMarks *m_owner; KActionCollection *m_ac; KBookmarkMenu *m_menu; - KMainWindow *m_parent; }; -#endif +#endif diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp index 5b91fdb0..57c6e4bf 100644 --- a/src/browsermainwindow.cpp +++ b/src/browsermainwindow.cpp @@ -27,7 +27,7 @@ #include "history.h" #include "settings.h" #include "tabwidget.h" -// #include "toolbarsearch.h" +#include "bookmarks.h" #include "webview.h" // UI Includes @@ -67,7 +67,6 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags) , m_historyForward(0) , m_stop(0) , m_reload(0) - , m_bookmarkMenu(0) { // delete widget accepting close event setAttribute(Qt::WA_DeleteOnClose, true); @@ -340,13 +339,15 @@ void BrowserMainWindow::setupMenu() // ------------------------------------------------------------- BOOKMARKS -------------------------------------------------------------------------------------------------- - KMenu* bookmarksMenu = new KMenu( i18n("&Bookmarks"), this ); - - KUrl bookfile = KUrl( "~/.kde/share/apps/konqueror/bookmarks.xml" ); - KBookmarkManager *mgr = KBookmarkManager::managerForExternalFile( bookfile.path() ); //FIXME hardcoded path - KActionCollection * ac = new KActionCollection( this ); - ac->addAction( "Add Bookmark" , KStandardAction::addBookmark( this, SLOT( slotAddBookmark() ) , this ) ); - m_bookmarkMenu = new KBookmarkMenu( mgr , 0 , bookmarksMenu , ac ); + BookmarksMenu *bookmarksMenu = new BookmarksMenu( this ); + bookmarksMenu->setTitle( i18n("&Bookmarks") ); +// m_bookmarksMenu = new KMenu( i18n("&Bookmarks"), this ); +// +// KUrl bookfile = KUrl( "~/.kde/share/apps/konqueror/bookmarks.xml" ); +// KBookmarkManager *mgr = KBookmarkManager::managerForExternalFile( bookfile.path() ); //FIXME hardcoded path +// KActionCollection * ac = new KActionCollection( this ); +// ac->addAction( "Add Bookmark" , KStandardAction::addBookmark( this, SLOT( slotAddBookmark() ) , this ) ); +// m_bookmarkMenu = new KBookmarkMenu( mgr , 0 , bookmarksMenu , ac ); menuBar()->addMenu( bookmarksMenu ); diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h index 5ead8dda..3c459d18 100644 --- a/src/browsermainwindow.h +++ b/src/browsermainwindow.h @@ -32,7 +32,6 @@ #include <KToolBar> #include <KAction> #include <KMenu> -#include <KBookmarkMenu> // Qt Includes #include <QUrl> @@ -41,7 +40,6 @@ class AutoSaver; class QWebFrame; class TabWidget; -// class ToolbarSearch; class WebView; /*! @@ -49,7 +47,8 @@ class WebView; Handles the tab widget and all the actions */ -class BrowserMainWindow : public KMainWindow { +class BrowserMainWindow : public KMainWindow +{ Q_OBJECT public: @@ -150,8 +149,6 @@ private: FindBar *m_findBar; QString m_lastSearch; - - KBookmarkMenu* m_bookmarkMenu; }; #endif // BROWSERMAINWINDOW_H diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 9ce8aa59..efa77a95 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -179,8 +179,10 @@ void TabBar::reloadTab() } } + // -------------------------------------------------------------------------------------------------------------------------------------------------------- + TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) , m_recentlyClosedTabsAction(0) @@ -258,6 +260,7 @@ TabWidget::TabWidget(QWidget *parent) m_lineEdits = new QStackedWidget(this); } + void TabWidget::clear() { // clear the recently closed tabs @@ -269,6 +272,7 @@ void TabWidget::clear() } } + void TabWidget::moveTab(int fromIndex, int toIndex) { disconnect(this, SIGNAL(currentChanged(int)), @@ -285,6 +289,7 @@ void TabWidget::moveTab(int fromIndex, int toIndex) setCurrentIndex(toIndex); } + // When index is -1 index chooses the current tab void TabWidget::reloadTab(int index) { @@ -299,6 +304,7 @@ void TabWidget::reloadTab(int index) } + void TabWidget::addWebAction(KAction *action, QWebPage::WebAction webAction) { if (!action) @@ -306,6 +312,7 @@ void TabWidget::addWebAction(KAction *action, QWebPage::WebAction webAction) m_actions.append(new WebActionMapper(action, webAction, this)); } + void TabWidget::currentChanged(int index) { WebView *webView = this->webView(index); @@ -347,46 +354,55 @@ void TabWidget::currentChanged(int index) webView->setFocus(); } + KAction *TabWidget::newTabAction() const { return m_newTabAction; } + KAction *TabWidget::closeTabAction() const { return m_closeTabAction; } + KAction *TabWidget::recentlyClosedTabsAction() const { return m_recentlyClosedTabsAction; } + KAction *TabWidget::nextTabAction() const { return m_nextTabAction; } + KAction *TabWidget::previousTabAction() const { return m_previousTabAction; } + QWidget *TabWidget::lineEditStack() const { return m_lineEdits; } + KLineEdit *TabWidget::currentLineEdit() const { return lineEdit(m_lineEdits->currentIndex()); } + WebView *TabWidget::currentWebView() const { return webView(currentIndex()); } + KLineEdit *TabWidget::lineEdit(int index) const { UrlBar *urlLineEdit = qobject_cast<UrlBar*>(m_lineEdits->widget(index)); @@ -395,6 +411,7 @@ KLineEdit *TabWidget::lineEdit(int index) const return 0; } + WebView *TabWidget::webView(int index) const { QWidget *widget = this->widget(index); @@ -418,12 +435,14 @@ WebView *TabWidget::webView(int index) const return 0; } + int TabWidget::webViewIndex(WebView *webView) const { int index = indexOf(webView); return index; } + WebView *TabWidget::newTab(bool makeCurrent) { // line edit @@ -491,6 +510,7 @@ WebView *TabWidget::newTab(bool makeCurrent) return webView; } + void TabWidget::reloadAllTabs() { for (int i = 0; i < count(); ++i) @@ -503,6 +523,7 @@ void TabWidget::reloadAllTabs() } } + void TabWidget::lineEditReturnPressed() { if (KLineEdit *lineEdit = qobject_cast<KLineEdit*>(sender())) @@ -513,6 +534,7 @@ void TabWidget::lineEditReturnPressed() } } + void TabWidget::windowCloseRequested() { WebPage *webPage = qobject_cast<WebPage*>(sender()); @@ -527,6 +549,7 @@ void TabWidget::windowCloseRequested() } } + void TabWidget::closeOtherTabs(int index) { if (-1 == index) @@ -537,6 +560,7 @@ void TabWidget::closeOtherTabs(int index) closeTab(i); } + // When index is -1 index chooses the current tab void TabWidget::cloneTab(int index) { @@ -548,6 +572,7 @@ void TabWidget::cloneTab(int index) tab->setUrl(webView(index)->url()); } + // When index is -1 index chooses the current tab void TabWidget::closeTab(int index) { @@ -591,6 +616,7 @@ void TabWidget::closeTab(int index) emit lastTabClosed(); } + void TabWidget::webViewLoadStarted() { WebView *webView = qobject_cast<WebView*>(sender()); @@ -601,6 +627,7 @@ void TabWidget::webViewLoadStarted() } } + void TabWidget::webViewIconChanged() { WebView *webView = qobject_cast<WebView*>(sender()); @@ -612,6 +639,7 @@ void TabWidget::webViewIconChanged() } } + void TabWidget::webViewTitleChanged(const QString &title) { WebView *webView = qobject_cast<WebView*>(sender()); @@ -624,6 +652,7 @@ void TabWidget::webViewTitleChanged(const QString &title) BrowserApplication::historyManager()->updateHistoryItem(webView->url(), title); } + void TabWidget::webViewUrlChanged(const QUrl &url) { WebView *webView = qobject_cast<WebView*>(sender()); @@ -634,6 +663,7 @@ void TabWidget::webViewUrlChanged(const QUrl &url) emit tabsChanged(); } + void TabWidget::aboutToShowRecentTabsMenu() { m_recentlyClosedTabsMenu->clear(); @@ -648,12 +678,14 @@ void TabWidget::aboutToShowRecentTabsMenu() } } + void TabWidget::aboutToShowRecentTriggeredAction(QAction *action) { QUrl url = action->data().toUrl(); loadUrlInCurrentTab(url); } + void TabWidget::mouseDoubleClickEvent(QMouseEvent *event) { if ( !childAt(event->pos()) @@ -666,6 +698,7 @@ void TabWidget::mouseDoubleClickEvent(QMouseEvent *event) QTabWidget::mouseDoubleClickEvent(event); } + void TabWidget::contextMenuEvent(QContextMenuEvent *event) { if (!childAt(event->pos())) { @@ -675,6 +708,7 @@ void TabWidget::contextMenuEvent(QContextMenuEvent *event) QTabWidget::contextMenuEvent(event); } + void TabWidget::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::MidButton && !childAt(event->pos()) @@ -690,6 +724,7 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) } } + void TabWidget::loadUrlInCurrentTab(const QUrl &url) { WebView *webView = currentWebView(); @@ -700,6 +735,7 @@ void TabWidget::loadUrlInCurrentTab(const QUrl &url) } } + void TabWidget::nextTab() { int next = currentIndex() + 1; @@ -708,6 +744,7 @@ void TabWidget::nextTab() setCurrentIndex(next); } + void TabWidget::previousTab() { int next = currentIndex() - 1; @@ -716,8 +753,10 @@ void TabWidget::previousTab() setCurrentIndex(next); } + static const qint32 TabWidgetMagic = 0xaa; + QByteArray TabWidget::saveState() const { int version = 1; @@ -744,6 +783,7 @@ QByteArray TabWidget::saveState() const return data; } + bool TabWidget::restoreState(const QByteArray &state) { int version = 1; @@ -776,6 +816,10 @@ bool TabWidget::restoreState(const QByteArray &state) return true; } + +// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + WebActionMapper::WebActionMapper(KAction *root, QWebPage::WebAction webAction, QObject *parent) : QObject(parent) , m_currentParent(0) @@ -789,16 +833,19 @@ WebActionMapper::WebActionMapper(KAction *root, QWebPage::WebAction webAction, Q root->setEnabled(false); } + void WebActionMapper::rootDestroyed() { m_root = 0; } + void WebActionMapper::currentDestroyed() { updateCurrent(0); } + void WebActionMapper::addChild(KAction *action) { if (!action) @@ -811,6 +858,7 @@ QWebPage::WebAction WebActionMapper::webAction() const return m_webAction; } + void WebActionMapper::rootTriggered() { if (m_currentParent) @@ -820,6 +868,7 @@ void WebActionMapper::rootTriggered() } } + void WebActionMapper::childChanged() { if (KAction *source = qobject_cast<KAction*>(sender())) @@ -834,6 +883,7 @@ void WebActionMapper::childChanged() } } + void WebActionMapper::updateCurrent(QWebPage *currentParent) { if (m_currentParent) diff --git a/src/webview.h b/src/webview.h index ccd44a6f..f81544a0 100644 --- a/src/webview.h +++ b/src/webview.h @@ -32,7 +32,9 @@ class QSslError; QT_END_NAMESPACE class BrowserMainWindow; -class WebPage : public QWebPage { + +class WebPage : public QWebPage +{ Q_OBJECT signals: @@ -45,9 +47,6 @@ public: protected: bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type); QWebPage *createWindow(QWebPage::WebWindowType type); -// #if !defined(QT_NO_UITOOLS) -// QObject *createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); -// #endif private slots: void handleUnsupportedContent(QNetworkReply *reply); @@ -62,7 +61,8 @@ private: QUrl m_loadingUrl; }; -class WebView : public QWebView { +class WebView : public QWebView +{ Q_OBJECT public: |