[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kio
From:       David Faure <faure () kde ! org>
Date:       2006-11-20 11:58:09
Message-ID: 1164023889.623438.10869.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 606415 by dfaure:

Added KFileItem::isNull(), convenient with implicitly-shared classes.
Rename determineMimeTypeOnDemand booleans to delayedMimeTypes like in kdirlister \
(SC+BC, it's just an arg name) Avoid determining the mimetype as a side effect in \
iconName() or overlays() when delayedMimeTypes is on. This must be only one of the \
reasons why delayedMimeTypes is broken in kde3.


 M  +30 -20    kio/kfileitem.cpp  
 M  +19 -10    kio/kfileitem.h  
 M  +12 -0     tests/kfileitemtest.cpp  
 M  +1 -0      tests/kfileitemtest.h  


--- trunk/KDE/kdelibs/kio/kio/kfileitem.cpp #606414:606415
@@ -55,7 +55,7 @@
     KFileItemPrivate(const KIO::UDSEntry& entry,
                      mode_t mode, mode_t permissions,
                      const KUrl& url, bool urlIsDirectory,
-                     bool determineMimeTypeOnDemand)
+                     bool delayedMimeTypes)
         : m_entry( entry ),
           m_url( url ),
           m_pMimeType( 0 ),
@@ -65,7 +65,7 @@
           m_bLink( false ),
           m_bIsLocalUrl( url.isLocalFile() ),
           m_bMimeTypeKnown( false ),
-          m_bDetermineMimeTypeOnDemand( determineMimeTypeOnDemand ),
+          m_delayedMimeTypes( delayedMimeTypes ),
           m_hidden( Auto )
     {
         if (!entry.isEmpty()) {
@@ -159,7 +159,7 @@
     bool m_bIsLocalUrl:1;
 
     mutable bool m_bMimeTypeKnown:1;
-    bool m_bDetermineMimeTypeOnDemand:1;
+    bool m_delayedMimeTypes:1;
 
     // Auto: check leading dot.
     enum { Auto, Hidden, Shown } m_hidden:3;
@@ -434,22 +434,27 @@
 
 ///////
 
+KFileItem::KFileItem()
+    : d(0)
+{
+}
+
 KFileItem::KFileItem( const KIO::UDSEntry& entry, const KUrl& url,
-                      bool determineMimeTypeOnDemand, bool urlIsDirectory ) :
-    d(new KFileItemPrivate(entry, KFileItem::Unknown, KFileItem::Unknown,
-                           url, urlIsDirectory, determineMimeTypeOnDemand))
+                      bool delayedMimeTypes, bool urlIsDirectory )
+    : d(new KFileItemPrivate(entry, KFileItem::Unknown, KFileItem::Unknown,
+                             url, urlIsDirectory, delayedMimeTypes))
 {
 }
 
-KFileItem::KFileItem( mode_t mode, mode_t permissions, const KUrl& url, bool \
                determineMimeTypeOnDemand ) :
-    d(new KFileItemPrivate(KIO::UDSEntry(), mode, permissions,
-                           url, false, determineMimeTypeOnDemand))
+KFileItem::KFileItem( mode_t mode, mode_t permissions, const KUrl& url, bool \
delayedMimeTypes ) +    : d(new KFileItemPrivate(KIO::UDSEntry(), mode, permissions,
+                             url, false, delayedMimeTypes))
 {
 }
 
-KFileItem::KFileItem( const KUrl &url, const QString &mimeType, mode_t mode ) :
-    d(new KFileItemPrivate(KIO::UDSEntry(), mode, KFileItem::Unknown,
-                           url, false, false))
+KFileItem::KFileItem( const KUrl &url, const QString &mimeType, mode_t mode )
+    : d(new KFileItemPrivate(KIO::UDSEntry(), mode, KFileItem::Unknown,
+                             url, false, false))
 {
     d->m_bMimeTypeKnown = !mimeType.isEmpty();
     if (d->m_bMimeTypeKnown)
@@ -665,8 +670,8 @@
     bool isLocalUrl;
     KUrl url = mostLocalUrl(isLocalUrl);
 
-    //kDebug() << "finding icon for " << url.url() << " : " << \
                d->m_pMimeType->name() << endl;
-    return determineMimeType()->iconName(url);
+    //kDebug() << "finding icon for " << url.url() << " : " << mimeTypePtr()->name() \
<< endl; +    return mimeTypePtr()->iconName(url);
 }
 
 int KFileItem::overlays() const
@@ -692,7 +697,7 @@
         }
     }
 
-    if ( mimetype() == "application/x-gzip" && d->m_url.fileName().endsWith( \
QLatin1String( ".gz" ) ) ) +    if ( d->m_pMimeType && \
d->m_pMimeType->is("application/x-gzip") && d->m_url.fileName().endsWith( \
QLatin1String( ".gz" ) ) )  _state |= K3Icon::ZipOverlay;
     return _state;
 }
@@ -960,7 +965,7 @@
 }
 
 void KFileItem::setUDSEntry( const KIO::UDSEntry& _entry, const KUrl& _url,
-                             bool _determineMimeTypeOnDemand, bool _urlIsDirectory )
+                             bool _delayedMimeTypes, bool _urlIsDirectory )
 {
     d->m_entry = _entry;
     d->m_url = _url;
@@ -977,7 +982,7 @@
     d->m_hidden = KFileItemPrivate::Auto;
     d->m_guessedMimeType.clear();
     d->m_metaInfo = KFileMetaInfo();
-    d->m_bDetermineMimeTypeOnDemand = _determineMimeTypeOnDemand;
+    d->m_delayedMimeTypes = _delayedMimeTypes;
 
     d->readUDSEntry( _urlIsDirectory );
     d->init();
@@ -1132,7 +1137,7 @@
  *   set m_pMimeType but not m_bMimeTypeKnown (-> Intermediate state)
  * Intermediate state: determineMimeType() does the real determination -> Final \
                state.
  *
- * If determineMimeTypeOnDemand isn't set, then we always go to the Final state \
directly. + * If delayedMimeTypes isn't set, then we always go to the Final state \
                directly.
  */
 
 KMimeType::Ptr KFileItem::mimeTypePtr() const
@@ -1146,11 +1151,11 @@
 
         d->m_pMimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl,
                                                // use fast mode if not mimetype on \
                demand
-                                               d->m_bDetermineMimeTypeOnDemand, \
&accurate ); +                                               d->m_delayedMimeTypes, \
                &accurate );
         //kDebug() << "finding mimetype for " << url.url() << " : " << \
                m_pMimeType->name() << endl;
         // if we didn't use fast mode, or if we got a result, then this is the \
mimetype  // otherwise, determineMimeType will be able to do better.
-        d->m_bMimeTypeKnown = (!d->m_bDetermineMimeTypeOnDemand) || accurate;
+        d->m_bMimeTypeKnown = (!d->m_delayedMimeTypes) || accurate;
     }
     return d->m_pMimeType;
 }
@@ -1180,3 +1185,8 @@
     d = other.d;
     return *this;
 }
+
+bool KFileItem::isNull() const
+{
+    return d == 0;
+}
--- trunk/KDE/kdelibs/kio/kio/kfileitem.h #606414:606415
@@ -47,18 +47,24 @@
     enum { Unknown = (mode_t) - 1 };
 
     /**
+     * Null KFileItem. Doesn't represent any file, only exists for convenience.
+     */
+    KFileItem();
+
+    /**
      * Creates an item representing a file, from a UDSEntry.
      * This is the preferred constructor when using KIO::listDir().
      *
      * @param entry the KIO entry used to get the file, contains info about it
      * @param url the file url
-     * @param determineMimeTypeOnDemand specifies if the mimetype of the given
-     *       URL should be determined immediately or on demand
+     * @param delayedMimeTypes specifies if the mimetype of the given
+     *       URL should be determined immediately or on demand.
+     *       See the bool delayedMimeTypes in the KDirLister constructor.
      * @param urlIsDirectory specifies if the url is just the directory of the
      *       fileitem and the filename from the UDSEntry should be used.
      */
     KFileItem( const KIO::UDSEntry& entry, const KUrl& url,
-               bool determineMimeTypeOnDemand = false,
+               bool delayedMimeTypes = false,
                bool urlIsDirectory = false );
 
     /**
@@ -71,11 +77,11 @@
      * Set to KFileItem::Unknown if you don't know the mode or the permission.
      * @param url the file url
      *
-     * @param determineMimeTypeOnDemand specify if the mimetype of the given URL
+     * @param delayedMimeTypes specify if the mimetype of the given URL
      *       should be determined immediately or on demand
      */
     KFileItem( mode_t mode, mode_t permissions, const KUrl& url,
-               bool determineMimeTypeOnDemand = false );
+               bool delayedMimeTypes = false );
 
     /**
      * Creates an item representing a file, for which the mimetype is already known.
@@ -282,7 +288,7 @@
 
     /**
      * Returns the mimetype of the file item.
-     * If @p determineMimeTypeOnDemand was used in the constructor, this will \
determine +     * If @p delayedMimeTypes was used in the constructor, this will \
                determine
      * the mimetype first. Equivalent to determineMimeType()->name()
      * @return the mime type of the file
      */
@@ -290,7 +296,7 @@
 
     /**
      * Returns the mimetype of the file item.
-     * If determineMimeTypeOnDemand was used in the constructor, this will determine
+     * If delayedMimeTypes was used in the constructor, this will determine
      * the mimetype first.
      * @return the mime type
      */
@@ -514,7 +520,7 @@
      *
      * @param entry the UDSEntry to assign to this KFileItem
      * @param url the file url
-     * @param determineMimeTypeOnDemand specifies if the mimetype of the given
+     * @param delayedMimeTypes specifies if the mimetype of the given
      *        URL should be determined immediately or on demand
      * @param urlIsDirectory specifies if the url is just the directory of the
      *        fileitem and the filename from the UDSEntry should be used.
@@ -523,7 +529,7 @@
      * now that it's a value class?
      */
     KDE_DEPRECATED void setUDSEntry( const KIO::UDSEntry& entry, const KUrl& url,
-                                     bool determineMimeTypeOnDemand = false,
+                                     bool delayedMimeTypes = false,
                                      bool urlIsDirectory = false );
 
     /**
@@ -532,7 +538,10 @@
      */
     KUrl mostLocalUrl(bool &local) const; // KDE4 TODO: bool* local = 0
 
-    /////////////
+    /**
+     * Return true if default-constructed
+     */
+    bool isNull() const;
 
 private:
     QSharedDataPointer<KFileItemPrivate> d;
--- trunk/KDE/kdelibs/kio/tests/kfileitemtest.cpp #606414:606415
@@ -58,6 +58,18 @@
     QCOMPARE(symlinkItem.permissionsString(), QString("lrw----r--"));
 }
 
+void KFileItemTest::testNull()
+{
+    KFileItem null;
+    QVERIFY(null.isNull());
+    KFileItem fileItem(KUrl("/"), QString(), KFileItem::Unknown);
+    QVERIFY(!fileItem.isNull());
+    fileItem.mark();
+    null = fileItem;
+    QVERIFY(!null.isNull());
+    QVERIFY(null.isMarked());
+}
+
 void KFileItemTest::testDetach()
 {
     KFileItem fileItem(KUrl("/"), QString(), KFileItem::Unknown);
--- trunk/KDE/kdelibs/kio/tests/kfileitemtest.h #606414:606415
@@ -27,6 +27,7 @@
 private Q_SLOTS:
     void initTestCase();
     void testPermissionsString();
+    void testNull();
     void testDetach();
     void testBasic();
     void testMimeTypeOnDemand();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic