From 00a5c704f35dff4531c53d21807e3f195991f9be Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 19 May 2012 00:24:30 +0200 Subject: reordering favorites by drag & drop WARNING: this code is very tricky, but I think results are really nice. Let's see what will happen... --- src/newtabpage.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'src/newtabpage.cpp') diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 5101b0e1..9e50ef19 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -80,7 +80,7 @@ NewTabPage::NewTabPage(QWebFrame *frame) else { m_html = file.readAll(); - m_html.replace(QL1S("%2"), dataPath); + m_html.replace(QL1S("$DEFAULT_PATH"), dataPath); } } @@ -241,6 +241,14 @@ void NewTabPage::generate(const KUrl &url) return; } + + if (url == KUrl("about:favorites/save")) + { + saveFavorites(); + return; + } + + loadPageForUrl(url); } @@ -268,6 +276,9 @@ void NewTabPage::loadPageForUrl(const KUrl &url, const QString & filter) favoritesPage(); updateWindowIcon(); title = i18n("Favorites"); + m_root.document().findFirst(QL1S("title")).setPlainText(title); + initJS(); + return; } else if (encodedUrl == QByteArray("about:closedTabs")) { @@ -949,3 +960,76 @@ void NewTabPage::updateWindowIcon() int currentIndex = rApp->mainWindow()->mainView()->currentIndex(); rApp->mainWindow()->changeWindowIcon(currentIndex); } + + +void NewTabPage::initJS() +{ + QWebFrame *parentFrame = qobject_cast(parent()); + QString oldHTML = parentFrame->toHtml(); + + QString includes; + includes += QL1S(""); + includes += QL1S(""); + includes += QL1S(""); + + QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html"); + QString dataPath = QL1S("file://") + htmlFilePath; + dataPath.remove(QL1S("/htmls/home.html")); + + includes.replace(QL1S("$DEFAULT_PATH"), dataPath); + + oldHTML.replace(QL1S(""), includes); + + QString javascript; + javascript += QL1S(""); + javascript += QL1S(""); + + oldHTML.replace(QL1S(""), javascript); + + parentFrame->setHtml(oldHTML); +} + + +void NewTabPage::saveFavorites() +{ + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + QStringList newNames = names; + QStringList newUrls = urls; + + QWebElementCollection coll = m_root.document().findAll( QL1S(".thumbnail") ); + QList list = coll.toList(); + + int i = 0; + + Q_FOREACH(QWebElement e, list) + { + if (!e.hasAttribute(QL1S("id"))) + continue; + + QString id = e.attribute(QL1S("id")); + kDebug() << "id: " << id; + int index = id.remove(QL1S("preview")).toInt(); + kDebug() << "INDEX: " << index; + + newNames.replace(i, names.at(index)); + newUrls.replace(i, urls.at(index)); + i++; + } + + ReKonfig::setPreviewNames(newNames); + ReKonfig::setPreviewUrls(newUrls); + + loadPageForUrl(KUrl("about:favorites")); +} -- cgit v1.2.1