diff options
| -rw-r--r-- | src/data/home.html | 76 | ||||
| -rw-r--r-- | src/rekonqpage/newtabpage.cpp | 155 | ||||
| -rw-r--r-- | src/rekonqpage/newtabpage.h | 19 | ||||
| -rw-r--r-- | src/webpage.cpp | 10 | ||||
| -rw-r--r-- | src/webpage.h | 3 | ||||
| -rw-r--r-- | src/websnap.cpp | 52 | ||||
| -rw-r--r-- | src/websnap.h | 14 | 
7 files changed, 277 insertions, 52 deletions
| diff --git a/src/data/home.html b/src/data/home.html index 9d8f390f..8db3d894 100644 --- a/src/data/home.html +++ b/src/data/home.html @@ -54,6 +54,10 @@ margin-top: 0.5em;  a{  color: #3F7AB7;  text-decoration: none; +-webkit-transition-property: color; +-webkit-transition-duration: 0.5s; +-webkit-transition-timing-function: ease; +  }  a:hover{  color: black; @@ -118,18 +122,61 @@ margin-top: -5%;  /* Thumbnail class */  .thumbnail { -text-align: center;  display: inline-block; -width:25%; -margin-top: 7%; -min-width:250px; -min-height:192px; +width:25%; margin-top: 7%; +min-width:250px; min-height:192px; +} + +.preview { +display: block; +width: 200px; +height: 150px; +padding: 14px 16px; +background: url(%2/bg.png) no-repeat; +-webkit-background-size: 100% 100%;  +-webkit-background-clip: padding; +} +.thumbnail:hover .preview , .thumbnail:hover .button img { +opacity: 0.8; +} + +.button img, .preview { +-webkit-transition-property: opacity; +-webkit-transition-duration: 0.8s; +-webkit-transition-timing-function: ease-in-out; +} + +.button img { +display: inline-block; +width: 16px; +height: 16px; +opacity: 0;  } -.thumbnail object{ +.remove { +    float: right; +} +.modify { +    float: left; +} + +.title { +display: block; +width: 200px; +height: 15px; +padding: 0 14px;  text-align: center; -width:228px; -height:192px; +} + +.thumbnail a { +text-align:center; +} +.thumbnail a:hover { +color:#3F7AB7; +} + +.thumbnail span { +  }  /* -------------------------------------------------------- */ @@ -162,11 +209,14 @@ margin-bottom: 0.5em;          </a>      </div>      <div class="thumbnail"> -        <object type="application/image-preview" data=""> -            <param name="title" /> -            <param name="index" /> -            <param name="isFavorite" /> -        </object> +        <a> +            <img class="preview"></img> +            <div class="title"> +                <a class="button modify"><img /></a> +                <span><a></a></span> +                <a class="button remove"><img /></a> +            </div> +        </a>      </div>      <h3></h3>      <a></a> diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index 66f74b86..4299c8bb 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -46,6 +46,7 @@  // Qt Includes  #include <QFile> +#include <websnap.h>  NewTabPage::NewTabPage(QWebFrame *frame) @@ -72,6 +73,16 @@ NewTabPage::~NewTabPage()  void NewTabPage::generate(const KUrl &url)  {     +    if(KUrl("about:preview").isParentOf(url)) +    { +        if(url.directory() == QString("preview/remove")) +        { +            removePreview(url.fileName().toInt()); +            return; +        } +    } +     +          QWebPage *page = m_root.webFrame()->page();      page->mainFrame()->setHtml(m_html); @@ -80,26 +91,26 @@ void NewTabPage::generate(const KUrl &url)      browsingMenu(url);      QString title; -    if(url == KUrl("about:closedTabs")) +    if(url == KUrl("about:home") || url == KUrl("about:favorites")) +    { +        favoritesPage(); +        title = i18n("Favorites"); +    } +    else if(url == KUrl("about:closedTabs"))      {          closedTabsPage();          title = i18n("Closed Tabs");      } -    if(url == KUrl("about:history")) +    else if(url == KUrl("about:history"))      {          historyPage();          title = i18n("History");      } -    if(url == KUrl("about:bookmarks")) +    else if(url == KUrl("about:bookmarks"))      {          bookmarksPage();          title = i18n("Bookmarks");      } -    if(url == KUrl("about:home") || url == KUrl("about:favorites")) -    { -        favoritesPage(); -        title = i18n("Favorites"); -    }      m_root.document().findFirst("title").setPlainText(title);  } @@ -114,34 +125,111 @@ void NewTabPage::favoritesPage()      for(int i=0; i<8; ++i)      { -        QWebElement speed = markup(".thumbnail"); -        speed.findFirst("object").setAttribute("data" , urls.at(i)); -        speed.findFirst("param[name=title]").setAttribute("value", names.at(i)); -        speed.findFirst("param[name=index]").setAttribute("value", QString::number(i)); -        speed.findFirst("param[name=isFavorite]").setAttribute("value", "true"); +        QWebElement speed; +         +        if(urls.at(i).isEmpty()) +            speed = emptyPreview(); +        else if(!QFile::exists(WebSnap::fileForUrl(urls.at(i)).toLocalFile())) +            speed = loadingPreview(i, urls.at(i)); +        else +            speed = validPreview(i, urls.at(i), names.at(i)); +         +        speed.setAttribute("id", "preview" + QVariant(i).toString());          m_root.appendInside(speed);      }  } -// FIXME : port to new PreviewImage API to use... -/*QString NewTabPage::lastVisitedPage() +QWebElement NewTabPage::emptyPreview()  { -    QString last; -    QList<HistoryItem> history =  Application::historyManager()->history(); -    for (int i = 0; i < 8 && i < history.size(); ++i)  -    { -        HistoryItem it = history.at(i); -        last += "<div class=\"thumbnail\">"; -        last += "<object type=\"application/image-preview\" data=\"" + it.url +  "\" >"; -        last += "</object>"; -        last += "<br />"; -        last += "<a href=\"" + it.url + "\">" + it.title + "</a></div>"; -    } +    QWebElement prev = markup(".thumbnail"); +     +    prev.findFirst("img").setAttribute("src" , QString("file:///") + +                    KIconLoader::global()->iconPath("insert-image", KIconLoader::Desktop)); +    prev.findFirst("span").appendInside(i18n("Set a Preview...")); +     +    return prev; +} + + +QWebElement NewTabPage::loadingPreview(int index, KUrl url) +{ +    QWebElement prev = markup(".thumbnail"); +     +    prev.findFirst("img").setAttribute("src" ,  +    QString("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); +    prev.findFirst("span").appendInside(i18n("Loading Preview...")); +    WebSnap *snap = new WebSnap(url); +    snap->SetData(QVariant(index)); +    connect(snap, SIGNAL(finished()), SLOT(snapFinished())); +     +    return prev; +} + +QWebElement NewTabPage::validPreview(int index, KUrl url, QString title) +{ +    QWebElement prev = markup(".thumbnail"); +    KUrl previewPath = WebSnap::fileForUrl(url); +    QString iString = QVariant(index).toString(); +     +    prev.findFirst(".preview").setAttribute("src" , previewPath.toMimeDataString()); +    prev.findFirst("a").setAttribute("href", url.toMimeDataString()); +    prev.findFirst("span > a").setAttribute("href", url.toMimeDataString()); +    prev.findFirst("span").appendInside(checkTitle(title)); +     +    prev.findFirst(".modify img").setAttribute("src", QString("file:///") + +    KIconLoader::global()->iconPath("insert-image", KIconLoader::DefaultState)); +    prev.findFirst(".modify").setAttribute("href", QString("about:preview/modify/" + iString )); +     +    prev.findFirst(".remove img").setAttribute("src", QString("file:///") + +    KIconLoader::global()->iconPath("edit-delete", KIconLoader::DefaultState)); +    prev.findFirst(".remove").setAttribute("href", QString("about:preview/remove/" + iString )); +     +    return prev; +} -    return last; -}*/ +void NewTabPage::snapFinished() +{ +    WebSnap *snap = qobject_cast<WebSnap*>(sender()); +    QWebElement thumb = m_root.findFirst("#preview" + snap->data().toString()); +    thumb.findFirst("img").setAttribute("src", WebSnap::fileForUrl(snap->snapUrl()).toMimeDataString()); +    thumb.findFirst("p").setPlainText(snap->snapTitle()); +     +    // Save the new config +    QStringList names = ReKonfig::previewNames(); +    QStringList urls = ReKonfig::previewUrls(); +     +    // stripTrailingSlash to be sure to get the same string for same address +    urls.replace(snap->data().toInt(), snap->snapUrl().toString(QUrl::StripTrailingSlash)); +    names.replace(snap->data().toInt() , snap->snapTitle()); +     +    ReKonfig::setPreviewNames(names); +    ReKonfig::setPreviewUrls(urls); +     +    ReKonfig::self()->writeConfig(); +} + + +void NewTabPage::removePreview(int index) +{ +    QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); +     +     +    QStringList names = ReKonfig::previewNames(); +    QStringList urls = ReKonfig::previewUrls(); +     +    urls.replace(index, QString("")); +    names.replace(index, QString("")); +     +    ReKonfig::setPreviewNames(names); +    ReKonfig::setPreviewUrls(urls); +     +    // sync file data +    ReKonfig::self()->writeConfig(); +     +    prev.replace(emptyPreview()); +}  void NewTabPage::browsingMenu(const KUrl ¤tUrl) @@ -278,3 +366,14 @@ void NewTabPage::closedTabsPage()          m_root.appendInside(closed);      }  } + + +QString NewTabPage::checkTitle(QString title) +{ +    if(title.length() > 23) +    { +        title.truncate(20); +        title += "..."; +    } +    return title; +} diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h index 003aa84e..84880a10 100644 --- a/src/rekonqpage/newtabpage.h +++ b/src/rekonqpage/newtabpage.h @@ -28,9 +28,6 @@  #define REKONQ_NEW_TAB_PAGE -// rekonq Includes -#include <webpage.h> -  // KDE Includes  #include <KUrl> @@ -41,11 +38,12 @@  // Forward Includes  class KBookmark; +class WebPage; -class NewTabPage +class NewTabPage : public QObject  { -     +Q_OBJECT  public:      NewTabPage(QWebFrame *frame);      ~NewTabPage(); @@ -56,12 +54,19 @@ public:       *  new tab page       */      void generate(const KUrl &url = KUrl("about:home")); +     +protected slots: +    void snapFinished(); +    void removePreview(int index);  protected:  // these are the function to build the new tab page      void browsingMenu(const KUrl ¤tUrl);      void favoritesPage(); -    //QString lastVisitedPage(); +    QWebElement emptyPreview(); +    QWebElement loadingPreview(int index, KUrl url); +    QWebElement validPreview(int index, KUrl url, QString title); +          void historyPage();      void bookmarksPage();      void closedTabsPage(); @@ -77,6 +82,8 @@ private:      {         return m_root.document().findFirst("#models > " + selector).clone();      } +     +    QString checkTitle(QString title);      QString m_html; diff --git a/src/webpage.cpp b/src/webpage.cpp index b2bedffc..59df13e7 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -72,6 +72,7 @@  WebPage::WebPage(QObject *parent)          : KWebPage(parent, KWalletIntegration) +        , m_newTabPage(0)  {      setForwardUnsupportedContent(true); @@ -114,10 +115,19 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r          if(risp == KMessageBox::Cancel)              return false;      } +     +    if (request.url().scheme() == QLatin1String("about")) +    { +        if(m_newTabPage == 0) +            m_newTabPage = new NewTabPage(frame); +        m_newTabPage->generate(request.url()); +        return false; +    }      if (frame && m_protHandler.preHandling( request, frame ))      {          return false; +      }      m_requestedUrl = request.url(); diff --git a/src/webpage.h b/src/webpage.h index 9169ad60..5671b5d9 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -32,8 +32,10 @@  #define WEBPAGE_H +  // Local Includes  #include "protocolhandler.h" +#include "newtabpage.h"  // KDE Includes  #include <KWebPage> @@ -76,6 +78,7 @@ private:      QUrl m_requestedUrl;      ProtocolHandler m_protHandler; +    NewTabPage *m_newTabPage;  };  #endif diff --git a/src/websnap.cpp b/src/websnap.cpp index 7dcbb836..e5db7c4e 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -115,16 +115,62 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)  } +KUrl WebSnap::fileForUrl(KUrl url) +{ +    QString filePath =  +            KStandardDirs::locateLocal("cache", QString("thumbs/") + WebSnap::guessNameFromUrl(url) + ".png", true); +    return KUrl(filePath); +} + + +void WebSnap::SetData(QVariant data) +{ +    m_data = data; +} + +QVariant& WebSnap::data() +{ +    return m_data; +} + + + +QString WebSnap::guessNameFromUrl(QUrl url) +{ +    QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); +     +    // TODO learn Regular Expressions :) +    // and implement something better here.. +    name.remove('/'); +    name.remove('&'); +    name.remove('.'); +    name.remove('-'); +    name.remove('_'); +    name.remove('?'); +    name.remove('='); +    name.remove('+'); +     +    return name; +} + +  void WebSnap::saveResult(bool ok)  {      // crude error-checking      if (!ok)       {          kDebug() << "Error loading site.."; -        return; +        m_snapTitle = "Error..."; +        m_image = QPixmap();      } - -    m_image = renderPreview(m_page, WIDTH, HEIGHT); +    else +    { +        m_image = renderPreview(m_page, WIDTH, HEIGHT); +    } +     +    m_image.save(fileForUrl(m_url).toLocalFile()); +    kDebug() << "finished"; +          emit finished();  } diff --git a/src/websnap.h b/src/websnap.h index 6c5b4af9..04fded57 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -51,18 +51,26 @@ public:      WebSnap(const QUrl &url);      ~WebSnap(); -    QPixmap previewImage(); +    QPixmap previewImage(); // TODO : remove +          static QPixmap renderPreview(const QWebPage &page, int w, int h); +    static KUrl fileForUrl(KUrl url); +     +    static QString guessNameFromUrl(QUrl url); +          QString snapTitle();      QUrl snapUrl(); +     +    void SetData(QVariant data); +    QVariant& data();  signals:      void finished();  private slots:      void load(); -    void saveResult(bool ok); +    void saveResult(bool ok = true);  private:      QWebPage m_page; @@ -70,6 +78,8 @@ private:      QUrl m_url;      QString m_snapTitle; +     +    QVariant m_data;  };  #endif // WEB_SNAP_H | 
