diff options
| author | Andrea Diamantini <adjam7@gmail.com> | 2010-03-16 01:45:50 +0100 | 
|---|---|---|
| committer | Andrea Diamantini <adjam7@gmail.com> | 2010-03-16 01:45:50 +0100 | 
| commit | c4a3ac8eb53f109a3da1f53f279fc86edcb92597 (patch) | |
| tree | 8ef689aac509629d33fce88c6b2ad31e8837285f /src | |
| parent | Merge commit 'refs/merge-requests/104' of git://gitorious.org/rekonq/mainline... (diff) | |
| download | rekonq-c4a3ac8eb53f109a3da1f53f279fc86edcb92597.tar.xz | |
First bunch of fixes for the NewTabPage + WebSnap chain.
It seems clear (to me) that they leaks memory, so they urgently need
fixes. And a complete redesign.
This is just a first (the easiest) part of it:
- Removed some unuseful methods,
- Added some documentation for the WebSnap class
- Cleaned code, in general
Diffstat (limited to 'src')
| -rw-r--r-- | src/application.cpp | 2 | ||||
| -rw-r--r-- | src/rekonqpage/newtabpage.cpp | 5 | ||||
| -rw-r--r-- | src/rekonqpage/newtabpage.h | 24 | ||||
| -rw-r--r-- | src/rekonqpage/previewselectorbar.cpp | 6 | ||||
| -rw-r--r-- | src/tabbar.cpp | 2 | ||||
| -rw-r--r-- | src/websnap.cpp | 46 | ||||
| -rw-r--r-- | src/websnap.h | 25 | 
7 files changed, 50 insertions, 60 deletions
diff --git a/src/application.cpp b/src/application.cpp index 96254e07..b8d6f52f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -353,7 +353,7 @@ MainWindow *Application::newMainWindow()  void Application::removeMainWindow(MainWindow *window)  { -    m_mainWindows.removeAt(m_mainWindows.indexOf(window, 0)); +    m_mainWindows.removeOne(window);  } diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index 845dcf51..6fd5160d 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -56,7 +56,6 @@  NewTabPage::NewTabPage(QWebFrame *frame)      : m_root(frame->documentElement()) -    , m_url(KUrl())  {      QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html");      QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics");     @@ -98,7 +97,7 @@ void NewTabPage::generate(KUrl url)      }      QWebPage *page = m_root.webFrame()->page(); -    page->mainFrame()->setHtml(m_html,m_url); +    page->mainFrame()->setHtml(m_html);      m_root = page->mainFrame()->documentElement().findFirst("#content"); @@ -109,7 +108,6 @@ void NewTabPage::generate(KUrl url)      {          favoritesPage();          title = i18n("Favorites"); -        url = KUrl("about:favorites");      }      else if(url == KUrl("about:closedTabs"))      { @@ -127,7 +125,6 @@ void NewTabPage::generate(KUrl url)          title = i18n("Bookmarks");      } -    m_url = url;      m_root.document().findFirst("title").setPlainText(title);  } diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h index d4c57299..fd04e60a 100644 --- a/src/rekonqpage/newtabpage.h +++ b/src/rekonqpage/newtabpage.h @@ -62,7 +62,8 @@ public:      void snapFinished(int index, KUrl url, QString title);      void removePreview(int index); -protected:  // these are the function to build the new tab page +protected:   +    // these are the functions to build the new tab page      void browsingMenu(const KUrl ¤tUrl);      void favoritesPage(); @@ -70,13 +71,15 @@ protected:  // these are the function to build the new tab page      void bookmarksPage();      void closedTabsPage(); +    // Previews handling      QWebElement emptyPreview(int index);      QWebElement loadingPreview(int index, KUrl url);      QWebElement validPreview(int index, KUrl url, QString title); -    /** This function takes a QwebElement with the .thumbnail structure. -        It hides the "remove" and "modify" buttons-> -    */ +    /** This function takes a QwebElement with the .thumbnail structure, +     *  hiding the "remove" and "modify" buttons +     * +     */      void hideControls(QWebElement e);      void showControls(QWebElement e);      void setupPreview(QWebElement e, int index); @@ -84,10 +87,13 @@ protected:  // these are the function to build the new tab page  private:      void createBookItem(const KBookmark &bookmark, QWebElement parent); -    /** This function helps to get faster a new markup of one type,it isn't easy to create one with QWebElement. -        It gets it in the #models div of home.html. -        It works for all elements defined here. -    */ +    /** This function helps to get faster a new markup of one type, +     *  it isn't easy to create one with QWebElement. +     * +     *  It gets it in the #models div of home.html. +     *  It works for all elements defined here. +     * +     */      inline QWebElement markup(QString selector)       {         return m_root.document().findFirst("#models > " + selector).clone(); @@ -98,8 +104,6 @@ private:      QString m_html;      QWebElement m_root; -     -    KUrl m_url;  };  #endif // REKONQ_NEW_TAB_PAGE diff --git a/src/rekonqpage/previewselectorbar.cpp b/src/rekonqpage/previewselectorbar.cpp index d7676e3c..924a5439 100644 --- a/src/rekonqpage/previewselectorbar.cpp +++ b/src/rekonqpage/previewselectorbar.cpp @@ -119,10 +119,10 @@ void PreviewSelectorBar::clicked()      if(page)      { -        KUrl url = page->mainFrame()->url(); - -        WebSnap::savePreview(WebSnap::renderPreview(*page), url); +        // this is done just lo let the render process being faster.. +        WebSnap::renderPreview(*page); +        KUrl url = page->mainFrame()->url();                  QStringList names = ReKonfig::previewNames();          QStringList urls = ReKonfig::previewUrls(); diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 44972548..0f4e1064 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -170,7 +170,7 @@ void TabBar::showTabPreview(int tab)      m_previewPopup.data()->setFixedSize(w, h);      QLabel *l = new QLabel(); -    l->setPixmap( WebSnap::renderPreview( *indexedTab->page() , w, h) ); +    l->setPixmap( WebSnap::renderPreview( *indexedTab->page(), w, h, false) );      m_previewPopup.data()->setView(l);      m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); diff --git a/src/websnap.cpp b/src/websnap.cpp index ceb24b4f..906bbc1e 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -60,15 +60,11 @@ WebSnap::WebSnap(const QUrl& url, QWebFrame *frame, int index)      m_page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);      connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); +          QTimer::singleShot(0, this, SLOT(load()));  } -WebSnap::~WebSnap() -{ -} - -  void WebSnap::load()  {      m_page.mainFrame()->load(m_url); @@ -77,7 +73,7 @@ void WebSnap::load()  // NOTE please, be careful modifying this.   // You are playing with fire.. -QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h) +QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h, bool save)  {      // prepare page      page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); @@ -87,7 +83,10 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h)      // find the best size      QSize size;      int width = page.mainFrame()->contentsSize().width(); -    if (width < 640) width = 640; +    if (width < 640)  +    { +        width = 640; +    }      size = QSize(width,width*((0.0+h)/w));      page.setViewportSize(size); @@ -106,15 +105,16 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h)      page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);      page.setViewportSize(oldSize); -    return QPixmap::fromImage(pageImage); -} - - -void WebSnap::savePreview(QPixmap pm, KUrl url) -{ -    kDebug() << "saving preview"; -    QFile::remove(fileForUrl(url).toLocalFile()); -    pm.save(fileForUrl(url).toLocalFile()); +    QPixmap pm = QPixmap::fromImage(pageImage); +    if(save) +    { +        KUrl url( page.mainFrame()->url() ); +        kDebug() << "saving preview"; +        QFile::remove( fileForUrl(url).toLocalFile() ); +        pm.save(fileForUrl(url).toLocalFile()); +    } +     +    return pm;  } @@ -164,7 +164,7 @@ void WebSnap::saveResult(bool ok)      NewTabPage p( m_frame );      p.snapFinished(m_previewIndex, m_url, m_snapTitle); -    deleteLater(); +    this->deleteLater();  } @@ -172,15 +172,3 @@ QString WebSnap::snapTitle()  {      return m_page.mainFrame()->title();  } - - -QUrl WebSnap::snapUrl() -{ -    return m_url; -} - - -QPixmap WebSnap::previewImage() -{ -    return m_image; -} diff --git a/src/websnap.h b/src/websnap.h index 49b60769..73ed04ca 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -46,9 +46,17 @@  /** - * This class renders a site producing an image based - * on that. + * This class is used in many classes of rekonq to produce an image  + * based on the site corresponding to the url passed as argument. + * It also cached the images to not retrieve them everytime :) + *   * Heavily based on Graphics-Dojo WebSnap example (thanks!) + * + * We use this in the following rekonq classes: + * - TabBar class:          to show a tab preview                (given a page, you show WITHOUT saving an image) + * - NewTabPage class:      to show the favorites page "preview" (given an url, you show AND save an image) + * - PreviewSelector class: to save new favorite selection       (given a page, you show AND save an image) + *   */  class REKONQ_TESTS_EXPORT WebSnap : public QObject  { @@ -56,20 +64,13 @@ class REKONQ_TESTS_EXPORT WebSnap : public QObject  public:      WebSnap(const QUrl &url, QWebFrame *frame, int index); -    ~WebSnap(); -     -    QPixmap previewImage(); // TODO : remove -     -    static QPixmap renderPreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); -     +        +    static QPixmap renderPreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT, bool save = true); +              static KUrl fileForUrl(KUrl url); -          static QString guessNameFromUrl(QUrl url); -    static void savePreview(QPixmap pm, KUrl url); -          QString snapTitle(); -    QUrl snapUrl();  private slots:      void load();  | 
