webengine/osswebengine/WebKit/qt/Api/qwebpagehistory.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2     Copyright (C) 2007 Trolltech ASA
       
     3 
       
     4     This library is free software; you can redistribute it and/or
       
     5     modify it under the terms of the GNU Library General Public
       
     6     License as published by the Free Software Foundation; either
       
     7     version 2 of the License, or (at your option) any later version.
       
     8 
       
     9     This library is distributed in the hope that it will be useful,
       
    10     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12     Library General Public License for more details.
       
    13 
       
    14     You should have received a copy of the GNU Library General Public License
       
    15     along with this library; see the file COPYING.LIB.  If not, write to
       
    16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    17     Boston, MA 02110-1301, USA.
       
    18 
       
    19     This class provides all functionality needed for loading images, style sheets and html
       
    20     pages from the web. It has a memory cache for these objects.
       
    21 */
       
    22 #ifndef QWEBPAGEHISTORY_H
       
    23 #define QWEBPAGEHISTORY_H
       
    24 
       
    25 #include <QUrl>
       
    26 #include <QString>
       
    27 #include <QIcon>
       
    28 #include <QDateTime>
       
    29 #include <QSharedData>
       
    30 
       
    31 #include <qwebkitglobal.h>
       
    32 
       
    33 #if QT_VERSION < 0x040300
       
    34 template <class T> class QExplicitlySharedDataPointer
       
    35 {
       
    36 public:
       
    37     typedef T Type;
       
    38 
       
    39     inline T &operator*() { return *d; }
       
    40     inline const T &operator*() const { return *d; }
       
    41     inline T *operator->() { return d; }
       
    42     inline const T *operator->() const { return d; }
       
    43     inline operator T *() { return d; }
       
    44     inline operator const T *() const { return d; }
       
    45     inline T *data() { return d; }
       
    46     inline const T *data() const { return d; }
       
    47     inline const T *constData() const { return d; }
       
    48 
       
    49     //inline operator bool () const { return d != 0; }
       
    50 
       
    51     inline bool operator==(const QExplicitlySharedDataPointer<T> &other) const { return d == other.d; }
       
    52     inline bool operator!=(const QExplicitlySharedDataPointer<T> &other) const { return d != other.d; }
       
    53     inline bool operator==(const T *ptr) const { return d == ptr; }
       
    54     inline bool operator!=(const T *ptr) const { return d != ptr; }
       
    55 
       
    56     inline QExplicitlySharedDataPointer() { d = 0; }
       
    57     inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
       
    58 
       
    59     explicit QExplicitlySharedDataPointer(T *data);
       
    60     inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
       
    61     inline QExplicitlySharedDataPointer<T> & operator=(const QExplicitlySharedDataPointer<T> &o) {
       
    62         if (o.d != d) {
       
    63             T *x = o.d;
       
    64             if (x) x->ref.ref();
       
    65             x = qAtomicSetPtr(&d, x);
       
    66             if (x && !x->ref.deref())
       
    67                 delete x;
       
    68         }
       
    69         return *this;
       
    70     }
       
    71     inline QExplicitlySharedDataPointer &operator=(T *o) {
       
    72         if (o != d) {
       
    73             T *x = o;
       
    74             if (x) x->ref.ref();
       
    75             x = qAtomicSetPtr(&d, x);
       
    76             if (x && !x->ref.deref())
       
    77                 delete x;
       
    78         }
       
    79         return *this;
       
    80     }
       
    81 
       
    82     inline bool operator!() const { return !d; }
       
    83 
       
    84 private:
       
    85 
       
    86     T *d;
       
    87 };
       
    88 template <class T>
       
    89 Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
       
    90 { if (d) d->ref.ref(); }
       
    91 #endif
       
    92 
       
    93 class QWebPage;
       
    94 
       
    95 class QWebHistoryItemPrivate;
       
    96 class QWEBKIT_EXPORT QWebHistoryItem
       
    97 {
       
    98 public:
       
    99     QWebHistoryItem(const QWebHistoryItem &other);
       
   100     QWebHistoryItem &operator=(const QWebHistoryItem &other);
       
   101     ~QWebHistoryItem();
       
   102 
       
   103     QList<QWebHistoryItem*> children() const;
       
   104 
       
   105     QUrl originalUrl() const;
       
   106     QUrl currentUrl() const;
       
   107 
       
   108     QString title() const;
       
   109     QDateTime lastVisited() const;
       
   110 
       
   111     QPixmap icon() const;
       
   112 
       
   113     QWebHistoryItem(QWebHistoryItemPrivate *priv);
       
   114 private:
       
   115     friend class QWebPageHistory;
       
   116     friend class QWebPage;
       
   117     QExplicitlySharedDataPointer<QWebHistoryItemPrivate> d;
       
   118 };
       
   119 
       
   120 class QWebPageHistoryPrivate;
       
   121 class QWEBKIT_EXPORT QWebPageHistory
       
   122 {
       
   123 public:
       
   124     QWebPageHistory(const QWebPageHistory &other);
       
   125     QWebPageHistory &operator=(const QWebPageHistory &other);
       
   126     ~QWebPageHistory();
       
   127 
       
   128     void clear();
       
   129     
       
   130     QList<QWebHistoryItem> items() const;
       
   131     QList<QWebHistoryItem> backItems(int maxItems) const;
       
   132     QList<QWebHistoryItem> forwardItems(int maxItems) const;
       
   133 
       
   134     bool canGoBack() const;
       
   135     bool canGoForward() const;
       
   136 
       
   137     void goBack();
       
   138     void goForward();
       
   139     void goToItem(QWebHistoryItem *item);
       
   140 
       
   141     QWebHistoryItem backItem() const;
       
   142     QWebHistoryItem currentItem() const;
       
   143     QWebHistoryItem forwardItem() const;
       
   144     QWebHistoryItem itemAtIndex(int i) const;
       
   145 
       
   146     
       
   147     QWebPageHistory(QWebPageHistoryPrivate *priv);
       
   148 private:
       
   149     QExplicitlySharedDataPointer<QWebPageHistoryPrivate> d;
       
   150 };
       
   151 
       
   152 #endif