diff options
-rw-r--r-- | data/rekonq.desktop | 2 | ||||
-rw-r--r-- | src/homepage.cpp | 41 | ||||
-rw-r--r-- | src/mainwindow.cpp | 29 | ||||
-rw-r--r-- | src/previewimage.cpp | 164 | ||||
-rw-r--r-- | src/previewimage.h | 20 | ||||
-rw-r--r-- | src/webpluginfactory.cpp | 18 | ||||
-rw-r--r-- | src/websnap.cpp | 14 | ||||
-rw-r--r-- | src/websnap.h | 4 |
8 files changed, 236 insertions, 56 deletions
diff --git a/data/rekonq.desktop b/data/rekonq.desktop index fc862690..62998336 100644 --- a/data/rekonq.desktop +++ b/data/rekonq.desktop @@ -17,7 +17,7 @@ Icon=rekonq Type=Application Exec=rekonq %u X-DocPath=rekonq/index.html -Categories=Qt;KDE;Network; +Categories=Qt;KDE;Network;WebBrowser; Terminal=false MimeType=text/html;application/xhtml+xml;application/xml; X-DBUS-StartupType=Unique 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/mainwindow.cpp b/src/mainwindow.cpp index a75c3d16..6dd1024b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1089,18 +1089,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/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 |