diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/homepage.cpp | 41 | ||||
-rw-r--r-- | src/mainview.cpp | 24 | ||||
-rw-r--r-- | src/mainview.h | 6 | ||||
-rw-r--r-- | src/mainwindow.cpp | 31 | ||||
-rw-r--r-- | src/previewimage.cpp | 164 | ||||
-rw-r--r-- | src/previewimage.h | 20 | ||||
-rw-r--r-- | src/tabbar.cpp | 83 | ||||
-rw-r--r-- | src/tabbar.h | 4 | ||||
-rw-r--r-- | src/webpluginfactory.cpp | 18 | ||||
-rw-r--r-- | src/websnap.cpp | 14 | ||||
-rw-r--r-- | src/websnap.h | 4 |
11 files changed, 291 insertions, 118 deletions
diff --git a/src/homepage.cpp b/src/homepage.cpp index 80d0d3b6..7cad8911 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -70,7 +70,6 @@ QString HomePage::rekonqHomePage(const KUrl &url) kWarning() << "Couldn't open the home.html file"; return QString(""); } - QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics"); QString menu = homePageMenu(url); @@ -119,6 +118,8 @@ QString HomePage::fillFavorites() speed += "<div class=\"thumbnail\">"; speed += "<object type=\"application/image-preview\" data=\""; speed += urls.at(i) + "\" width=\"200\">"; + speed += "<param name=\"index\" value=\"" + QString::number(i) + "\" />"; + speed += "<param name=\"isFavorite\" value=\"true\" />"; speed += "</object>"; speed += "<br />"; speed += "<a href=\"" + urls.at(i) + "\">" + text + "</a></div>"; @@ -130,38 +131,18 @@ QString HomePage::fillFavorites() QString HomePage::lastVisitedSites() { - HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); - QString last; - int sites = 0; - int i = 0; - do + QList<HistoryItem> history = Application::historyManager()->history(); + for (int i = 0; i < 8 && i < history.size(); ++i) { - QModelIndex index = model->index(i, 0, QModelIndex() ); - if(model->hasChildren(index)) - { - for(int j=0; j< model->rowCount(index) && sites<8; ++j) - { - QModelIndex son = model->index(j, 0, index ); - - QString text = son.data().toString(); - if(text.length() > 20) - { - text.truncate(17); - text += "..."; - } - last += "<div class=\"thumbnail\">"; - last += "<object type=\"application/image-preview\" data=\"" + son.data(HistoryModel::UrlStringRole).toString(); - last += "\" width=\"200\">"; - last += "</object>"; - last += "<br />"; - last += "<a href=\"" + son.data(HistoryModel::UrlStringRole).toString() + "\">" + text + "</a></div>"; - sites++; - } - } - i++; + HistoryItem it = history.at(i); + last += "<div class=\"thumbnail\">"; + last += "<object type=\"application/image-preview\" data=\"" + it.url; + last += "\" width=\"200\">"; + last += "</object>"; + last += "<br />"; + last += "<a href=\"" + it.url + "\">" + it.url + "</a></div>"; } - while( sites<8 || model->hasIndex( i , 0 , QModelIndex() ) ); return last; diff --git a/src/mainview.cpp b/src/mainview.cpp index ba7b720e..a0b0c6e7 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -131,7 +131,7 @@ int MainView::webViewIndex(WebView *webView) const } -void MainView::showTabBar() +void MainView::updateTabBar() { if (ReKonfig::alwaysShowTabBar()) { @@ -139,6 +139,7 @@ void MainView::showTabBar() { m_tabBar->show(); } + m_tabBar->updateNewTabButton(); } else { @@ -152,6 +153,7 @@ void MainView::showTabBar() { m_tabBar->show(); } + m_tabBar->updateNewTabButton(); } } } @@ -283,15 +285,15 @@ WebView *MainView::newWebView(bool focused, bool nearParent) insertTab(currentIndex() + 1, webView, i18n("(Untitled)")); else addTab(webView, i18n("(Untitled)")); - + + updateTabBar(); + if (focused) { setCurrentWidget(webView); } emit tabsChanged(); - - showTabBar(); return webView; } @@ -369,7 +371,7 @@ void MainView::slotCloseOtherTabs(int index) slotCloseTab(i); } - showTabBar(); + updateTabBar(); } @@ -383,7 +385,7 @@ void MainView::slotCloneTab(int index) WebView *tab = newWebView(); tab->setUrl(webView(index)->url()); - showTabBar(); + updateTabBar(); } @@ -418,6 +420,7 @@ void MainView::slotCloseTab(int index) QWidget *webView = widget(index); removeTab(index); + updateTabBar(); // UI operation: do it ASAP!! webView->deleteLater(); // webView is scheduled for deletion. emit tabsChanged(); @@ -426,8 +429,6 @@ void MainView::slotCloseTab(int index) { currentWebView()->setFocus(); } - - showTabBar(); } @@ -578,3 +579,10 @@ KUrl::List MainView::recentlyClosedTabs() { return m_recentlyClosedTabs; } + + +void MainView::resizeEvent(QResizeEvent *event) +{ + updateTabBar(); + KTabWidget::resizeEvent(event); +}
\ No newline at end of file diff --git a/src/mainview.h b/src/mainview.h index 96710919..db4c455d 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -76,7 +76,7 @@ public: * "Always Show TabBar" option * */ - void showTabBar(); + void updateTabBar(); void clear(); /** @@ -136,7 +136,9 @@ private slots: void windowCloseRequested(); - +protected: + virtual void resizeEvent(QResizeEvent *event); + private: /** * This function creates (if not exists) and returns a QLabel diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 69831f97..cf8af892 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -451,7 +451,7 @@ void MainWindow::setupSidePanel() void MainWindow::slotUpdateConfiguration() { // ============== General ================== - mainView()->showTabBar(); + mainView()->updateTabBar(); // =========== Fonts ============== QWebSettings *defaultSettings = QWebSettings::globalSettings(); @@ -1088,18 +1088,33 @@ void MainWindow::slotOpenActionUrl(QAction *action) void MainWindow::addFavoriteLink() { QString name = currentTab()->title(); - QString url = currentTab()->url().pathOrUrl(); + QString url = currentTab()->url().prettyUrl(KUrl::RemoveTrailingSlash); QStringList names = ReKonfig::previewNames(); QStringList urls = ReKonfig::previewUrls(); - names.prepend(name); - if(names.count() > 8) - names.removeLast(); - urls.prepend(url); - if(urls.count() > 8) - urls.removeLast(); + for (int i = 0; i < 8 && i < urls.size() ; ++i) + { + if(urls.at(i).isEmpty() || urls.at(i) == url) + { + names.replace(i, name); + urls.replace(i, url); + break; + } + if(i == 7) + { + names.prepend(name); + if(names.count() > 8) + names.removeLast(); + + urls.prepend(url); + if(urls.count() > 8) + urls.removeLast(); + + break; + } + } ReKonfig::setPreviewNames(names); ReKonfig::setPreviewUrls(urls); diff --git a/src/previewimage.cpp b/src/previewimage.cpp index 7c3752cc..873abccf 100644 --- a/src/previewimage.cpp +++ b/src/previewimage.cpp @@ -30,36 +30,67 @@ // Local Includes #include "application.h" +#include "history.h" +#include "rekonq.h" // KDE Includes #include <KUrl> #include <KStandardDirs> #include <KDebug> +#include <KMenu> +#include <KAction> +#include <KLocale> // Qt Includes #include <QFile> #include <QMovie> #include <QMouseEvent> +#include <QHBoxLayout> -PreviewImage::PreviewImage(const QUrl &url) +PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite) : QLabel() , ws(0) - , m_url(url) + , m_url(0) + , m_isFavorite(isFavorite) + , m_index(index) + , m_button(0) { + setUrl(url); +} + + +PreviewImage::~PreviewImage() +{ + delete ws; +} + + + +void PreviewImage::setUrl(const QUrl& url) +{ + m_url = url; + + if(url.isEmpty()) + { + showEmptyPreview(); + return; + } + m_savePath = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true); if(QFile::exists(m_savePath)) { m_pixmap.load(m_savePath); - setPixmap( m_pixmap ); + setPixmap(m_pixmap); } else { ws = new WebSnap( url ); - connect(ws, SIGNAL(finished()), this, SLOT(setSiteImage())); + connect(ws, SIGNAL(finished()), this, SLOT(snapFinished())); QString path = KStandardDirs::locate("appdata", "pics/busywidget.gif"); + QMovie *movie = new QMovie(path, QByteArray(), this); movie->setSpeed(50); @@ -69,13 +100,7 @@ PreviewImage::PreviewImage(const QUrl &url) } -PreviewImage::~PreviewImage() -{ - delete ws; -} - - -void PreviewImage::setSiteImage() +void PreviewImage::snapFinished() { QMovie *m = movie(); delete m; @@ -85,11 +110,43 @@ void PreviewImage::setSiteImage() setPixmap(m_pixmap); m_pixmap.save(m_savePath); + + if(m_index > -1) + { + // Update title + QStringList names = ReKonfig::previewNames(); + // update url (for added thumbs) + QStringList urls = ReKonfig::previewUrls(); + + // stripTrailingSlash to be sure to get the same string for same adress + urls.replace(m_index, ws->snapUrl().toString(QUrl::StripTrailingSlash)); + names.replace(m_index, ws->snapTitle()); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + } +} + + +void PreviewImage::showEmptyPreview() +{ + clear(); + + QHBoxLayout *layout = new QHBoxLayout(this); + m_button = new QToolButton(this); + m_button->setDefaultAction(historyMenu()); + m_button->setPopupMode(QToolButton::InstantPopup); + m_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + m_button->setText(i18n("Add Preview")); + m_button->setAutoRaise(true); + m_button->setIconSize(QSize(48, 48)); + layout->addWidget(m_button); } void PreviewImage::mouseDoubleClickEvent(QMouseEvent *event) { + kDebug() << "no double click over here, thanks :D"; Q_UNUSED(event); } @@ -119,10 +176,92 @@ void PreviewImage::mousePressEvent(QMouseEvent *event) void PreviewImage::mouseReleaseEvent(QMouseEvent *event) { + kDebug() << "NOOOOOOO... don't leave your finger from the button!!!!"; Q_UNUSED(event) } +void PreviewImage::contextMenuEvent(QContextMenuEvent* event) +{ + if(!m_isFavorite) + return; + + KMenu menu(this); + KAction *a; + + if(!m_url.isEmpty()) + { + a = new KAction(KIcon("edit-delete"), i18n("Remove Thumbnail"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(removeMe())); + menu.addAction(a); + } + menu.addAction(historyMenu()); + + menu.exec(mapToGlobal(event->pos())); +} + + +KActionMenu* PreviewImage::historyMenu() +{ + KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set page to preview"), this); + QList<HistoryItem> history = Application::historyManager()->history(); + + if(history.isEmpty()) + { + KAction *a = new KAction(i18n("History is empty"), this); + a->setEnabled(false); + histMenu->addAction(a); + return histMenu; + } + + int maxItems = 15; + for (int i = 0; i < maxItems && i < history.size() ; ++i) + { + HistoryItem it = history.at(i); + KAction *a = new KAction(Application::icon(it.url), it.title, this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(setUrlFromAction())); + a->setData(it.url); + histMenu->addAction(a); + } + + return histMenu; +} + + +void PreviewImage::removeMe() +{ + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + int index = urls.indexOf(QRegExp(m_url.toString(QUrl::StripTrailingSlash), Qt::CaseSensitive, QRegExp::FixedString)); + + urls.replace(index, QString("")); + names.replace(index, QString("")); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + showEmptyPreview(); + + m_url = ""; +} + + +void PreviewImage::setUrlFromAction() +{ + KAction *a = qobject_cast<KAction*>(sender()); + KUrl url = KUrl(a->data().toString()); + + if(m_button) + { + layout()->deleteLater(); + m_button->menu()->deleteLater(); + m_button->deleteLater(); + } + setUrl(url); +} + + QString PreviewImage::guessNameFromUrl(QUrl url) { QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); @@ -134,6 +273,9 @@ QString PreviewImage::guessNameFromUrl(QUrl url) name.remove('.'); name.remove('-'); name.remove('_'); + name.remove('?'); + name.remove('='); + name.remove('+'); return name; } diff --git a/src/previewimage.h b/src/previewimage.h index 6ccc5c97..0abbe479 100644 --- a/src/previewimage.h +++ b/src/previewimage.h @@ -30,29 +30,40 @@ // Local Includes #include "websnap.h" +// KDE Includes +#include <KActionMenu> + // Qt Includes #include <QLabel> #include <QImage> #include <QUrl> +#include <QToolButton> class PreviewImage : public QLabel { Q_OBJECT public: - PreviewImage(const QUrl &url); + PreviewImage(const QUrl &url, int index, bool isFavorite); ~PreviewImage(); QString guessNameFromUrl(QUrl url); public slots: - void setSiteImage(); + void snapFinished(); + void removeMe(); + void setUrlFromAction(); protected: + void contextMenuEvent(QContextMenuEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); + + void setUrl(const QUrl &url); + KActionMenu *historyMenu(); + void showEmptyPreview(); private: QPixmap m_pixmap; @@ -60,6 +71,11 @@ private: QUrl m_url; QString m_savePath; + + bool m_isFavorite; + int m_index; + + QToolButton *m_button; }; #endif // PREVIEW_IMAGE_H diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 94f2c274..bde1e63e 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -89,11 +89,6 @@ TabBar::~TabBar() void TabBar::postLaunch() { - // HACK this is used to fix add tab button position - QToolButton *secondAddTabButton = new QToolButton(this); - secondAddTabButton->setAutoRaise(true); - secondAddTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - // Find the correct MainWindow of this tab button MainWindowList list = Application::instance()->mainWindowList(); Q_FOREACH(QPointer<MainWindow> w, list) @@ -101,18 +96,12 @@ void TabBar::postLaunch() if (w->isAncestorOf(this)) { m_addTabButton->setDefaultAction(w->actionByName("new_tab")); - secondAddTabButton->setDefaultAction(w->actionByName("new_tab")); break; } } m_addTabButton->setAutoRaise(true); m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - m_addTabButton->show(); - - // stupid tabbar, that's what you gain... - m_parent->setCornerWidget(secondAddTabButton); - m_parent->cornerWidget()->hide(); } @@ -147,13 +136,6 @@ QSize TabBar::tabSizeHint(int index) const } -void TabBar::tabLayoutChange() -{ - setTabButtonPosition(); - KTabBar::tabLayoutChange(); -} - - void TabBar::contextMenuRequested(const QPoint &position) { KMenu menu; @@ -205,37 +187,6 @@ void TabBar::reloadTab() } -void TabBar::setTabButtonPosition() -{ - if(count() >= MIN_WIDTH_DIVISOR - 1) - { - if(m_addTabButton->isVisible()) - { - m_addTabButton->hide(); - m_parent->cornerWidget()->show(); - } - return; - } - - if(m_addTabButton->isHidden()) - { - m_addTabButton->show(); - m_parent->cornerWidget()->hide(); - } - - int tabWidgetWidth = frameSize().width(); - int tabBarWidth = tabSizeHint(0).width()*count(); - int newPosY = height() - m_addTabButton->height(); - int newPosX = tabWidgetWidth - m_addTabButton->width(); - - if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth) - newPosX = tabBarWidth; - - m_addTabButton->move(newPosX, newPosY); - m_addTabButton->show(); -} - - void TabBar::showTabPreview(int tab) { WebView *view = m_parent->webView(tab); @@ -316,3 +267,37 @@ void TabBar::leaveEvent(QEvent *event) KTabBar::leaveEvent(event); } + + +void TabBar::updateNewTabButton() +{ + static bool ButtonInCorner = false; + + int tabWidgetWidth = m_parent->frameSize().width(); + int tabBarWidth = tabSizeHint(0).width() * count(); + + if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth) + { + if(ButtonInCorner) + return; + m_parent->setCornerWidget(m_addTabButton); + ButtonInCorner = true; + } + else + { + if(ButtonInCorner) + { + m_parent->setCornerWidget(0); + m_addTabButton->show(); + ButtonInCorner = false; + } + + int newPosX = tabWidgetWidth - m_addTabButton->width(); + int newPosY = height() - m_addTabButton->height(); + + if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth) + newPosX = tabBarWidth; + + m_addTabButton->move(newPosX, newPosY); + } +} diff --git a/src/tabbar.h b/src/tabbar.h index dd08f7b8..580021c4 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -63,6 +63,7 @@ public: ~TabBar(); void showTabPreview(int tab); + void updateNewTabButton(); signals: void cloneTab(int index); @@ -76,7 +77,6 @@ protected: * Added to fix tab dimension */ virtual QSize tabSizeHint(int index) const; - virtual void tabLayoutChange(); virtual void mouseMoveEvent(QMouseEvent *event); virtual void leaveEvent(QEvent *event); @@ -89,8 +89,6 @@ private slots: void postLaunch(); private: - void setTabButtonPosition(); - MainView *m_parent; QToolButton *m_addTabButton; diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp index bb3f4d06..b9d50697 100644 --- a/src/webpluginfactory.cpp +++ b/src/webpluginfactory.cpp @@ -53,14 +53,22 @@ QObject *WebPluginFactory::create(const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues) const { - Q_UNUSED(argumentNames) - Q_UNUSED(argumentValues) - kDebug() << "loading mimeType: " << mimeType; if(mimeType == QString("application/image-preview") ) - { - return new PreviewImage(url); + { + int number = -1; + bool isFavorite = false; + + int i; + i = argumentNames.indexOf( QString("isFavorite") ); + if(i > -1) + isFavorite = true; + i = argumentNames.indexOf( QString("index") ); + if(i > -1) + number = argumentValues.at(i).toInt(); + + return new PreviewImage(url, number, isFavorite); } // this let QtWebKit using builtin plugins diff --git a/src/websnap.cpp b/src/websnap.cpp index 9e7108b0..83cfe88b 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -130,6 +130,20 @@ void WebSnap::saveResult(bool ok) } + +QString WebSnap::snapTitle() +{ + return m_page.mainFrame()->title(); + return QString(""); +} + + +QUrl WebSnap::snapUrl() +{ + return m_url; +} + + QPixmap WebSnap::previewImage() { return m_image; diff --git a/src/websnap.h b/src/websnap.h index 9a41f65d..53686677 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -52,6 +52,9 @@ public: QPixmap previewImage(); static QPixmap renderPreview(const QWebPage &page, int w, int h); + + QString snapTitle(); + QUrl snapUrl(); signals: void finished(); @@ -65,6 +68,7 @@ private: QPixmap m_image; QUrl m_url; + QString m_snapTitle; }; #endif // WEB_SNAP_H |