summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatgic78 <matgic78@gmail.com>2009-10-14 16:45:18 +0200
committermatgic78 <matgic78@gmail.com>2009-10-14 16:45:18 +0200
commit92a5daa103a54c2c4253d45cc882da1990bfbd03 (patch)
tree3f021abbc1843b9415b1d573870994da29ceed63
parentHUGE COMMIT (diff)
downloadrekonq-92a5daa103a54c2c4253d45cc882da1990bfbd03.tar.xz
favorites management
-right click menu to set the preview url by selecting one of the 15 last history entries -abitlity to remove previews and manage empty previews (show a toolbutton to set the url) -contextmenu->add to favorites now adds preview in an empty space when there is one -modified the loop used in HomePage::lastVisited because I encountered an infinite loop with it. (and because it is simpler this way)
-rw-r--r--src/homepage.cpp39
-rw-r--r--src/mainwindow.cpp29
-rw-r--r--src/previewimage.cpp180
-rw-r--r--src/previewimage.h22
-rw-r--r--src/urlbar.cpp6
-rw-r--r--src/webpluginfactory.cpp2
-rw-r--r--src/websnap.cpp14
-rw-r--r--src/websnap.h4
8 files changed, 245 insertions, 51 deletions
diff --git a/src/homepage.cpp b/src/homepage.cpp
index 3cc908a9..2749fe58 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>";
@@ -133,35 +134,17 @@ 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 ac9b83bb..8bd05dc7 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1076,18 +1076,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..0d246bf3 100644
--- a/src/previewimage.cpp
+++ b/src/previewimage.cpp
@@ -30,36 +30,79 @@
// 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,
+ const QStringList &argumentNames,
+ const QStringList &argumentValues)
: QLabel()
, ws(0)
- , m_url(url)
+ , m_url(0)
+ , m_isFavorite(false)
+ , m_index(-1)
+ , m_button(0)
{
+ int i;
+
+ i = argumentNames.indexOf(QRegExp(QString("isFavorite"), Qt::CaseInsensitive, QRegExp::FixedString));
+ if(i > -1 && argumentValues.at(i) == "true")
+ m_isFavorite = true;
+
+ i = argumentNames.indexOf(QRegExp(QString("index"), Qt::CaseInsensitive, QRegExp::FixedString));
+ if(i > -1)
+ m_index = argumentValues.at(i).toInt();
+
+ 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 +112,7 @@ PreviewImage::PreviewImage(const QUrl &url)
}
-PreviewImage::~PreviewImage()
-{
- delete ws;
-}
-
-
-void PreviewImage::setSiteImage()
+void PreviewImage::snapFinished()
{
QMovie *m = movie();
delete m;
@@ -85,6 +122,37 @@ 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);
}
@@ -123,6 +191,96 @@ void PreviewImage::mouseReleaseEvent(QMouseEvent *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();
+
+ QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true);
+ QFile::remove(path);
+
+ m_url = "";
+}
+
+
+void PreviewImage::setUrlFromAction()
+{
+ KAction *a = qobject_cast<KAction*>(sender());
+ KUrl url = KUrl(a->data().toString());
+
+ // delete thumb if exists to get a refreshed one.
+ QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(url) + ".png", true);
+ QFile::remove(path);
+
+ 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 );
diff --git a/src/previewimage.h b/src/previewimage.h
index 6ccc5c97..3d2e9411 100644
--- a/src/previewimage.h
+++ b/src/previewimage.h
@@ -30,29 +30,42 @@
// 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,
+ const QStringList &argumentNames = QStringList(),
+ const QStringList &argumentValues = QStringList());
~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 +73,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/urlbar.cpp b/src/urlbar.cpp
index 5776961b..5ad8314e 100644
--- a/src/urlbar.cpp
+++ b/src/urlbar.cpp
@@ -135,10 +135,12 @@ void UrlBar::setUrl(const QUrl& url)
{
if(url.scheme() == "rekonq")
{
+ m_currentUrl = "";
setFocus();
- return;
}
- m_currentUrl = url;
+ else
+ m_currentUrl = url;
+
slotUpdateUrl();
}
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index bb3f4d06..834cba95 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -60,7 +60,7 @@ QObject *WebPluginFactory::create(const QString &mimeType,
if(mimeType == QString("application/image-preview") )
{
- return new PreviewImage(url);
+ return new PreviewImage(url, argumentNames, argumentValues);
}
// 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