| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kfileitem.cpp

    00001 /* This file is part of the KDE project
    00002    Copyright (C) 1999 David Faure <faure@kde.org>
    00003                  2001 Carsten Pfeiffer <pfeiffer@kde.org>
    00004
    00005    This library is free software; you can redistribute it and/or
    00006    modify it under the terms of the GNU Library General Public
    00007    License as published by the Free Software Foundation; either
    00008    version 2 of the License, or (at your option) any later version.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020 // $Id: kfileitem.cpp,v 1.140.2.4 2003/09/15 12:14:53 aseigo Exp $
    00021
    00022 #include <sys/time.h>
    00023 #include <pwd.h>
    00024 #include <grp.h>
    00025 #include <sys/types.h>
    00026
    00027 #include <assert.h>
    00028 #include <unistd.h>
    00029
    00030 #include "kfileitem.h"
    00031
    00032 #include <qdir.h>
    00033 #include <qfile.h>
    00034 #include <qmap.h>
    00035 #include <qstylesheet.h>
    00036
    00037 #include <klargefile.h>
    00038 #include <kiconloader.h>
    00039 #include <kglobal.h>
    00040 #include <kdebug.h>
    00041 #include <klocale.h>
    00042 #include <kmimetype.h>
    00043 #include <krun.h>
    00044 #include <kfilemetainfo.h>
    00045 #include <kfileshare.h>
    00046
    00047 KFileItem::KFileItem( const KIO::UDSEntry& _entry, const KURL& _url,
    00048                       bool _determineMimeTypeOnDemand, bool _urlIsDirectory ) :
    00049   m_entry( _entry ),
    00050   m_url( _url ),
    00051   m_pMimeType( 0 ),
    00052   m_fileMode( KFileItem::Unknown ),
    00053   m_permissions( KFileItem::Unknown ),
    00054   m_bMarked( false ),
    00055   m_bLink( false ),
    00056   m_bIsLocalURL( _url.isLocalFile() ),
    00057   m_bMimeTypeKnown( false ),
    00058   d(0L)
    00059 {
    00060   bool UDS_URL_seen = false;
    00061   // extract the mode and the filename from the KIO::UDS Entry
    00062   KIO::UDSEntry::ConstIterator it = m_entry.begin();
    00063   for( ; it != m_entry.end(); it++ ) {
    00064     switch ((*it).m_uds) {
    00065
    00066         case KIO::UDS_FILE_TYPE:
    00067           m_fileMode = (mode_t)((*it).m_long);
    00068           break;
    00069
    00070         case KIO::UDS_ACCESS:
    00071           m_permissions = (mode_t)((*it).m_long);
    00072           break;
    00073
    00074         case KIO::UDS_USER:
    00075           m_user = ((*it).m_str);
    00076           break;
    00077
    00078         case KIO::UDS_GROUP:
    00079           m_group = ((*it).m_str);
    00080           break;
    00081
    00082         case KIO::UDS_NAME:
    00083           m_strName = (*it).m_str;
    00084           m_strText = KIO::decodeFileName( m_strName );
    00085           break;
    00086
    00087         case KIO::UDS_URL:
    00088           UDS_URL_seen = true;
    00089           m_url = KURL((*it).m_str);
    00090           break;
    00091
    00092         case KIO::UDS_MIME_TYPE:
    00093           m_pMimeType = KMimeType::mimeType((*it).m_str);
    00094           m_bMimeTypeKnown = true;
    00095           break;
    00096
    00097         case KIO::UDS_GUESSED_MIME_TYPE:
    00098           m_guessedMimeType = (*it).m_str;
    00099           break;
    00100
    00101         case KIO::UDS_LINK_DEST:
    00102           m_bLink = !(*it).m_str.isEmpty(); // we don't store the link dest
    00103           break;
    00104     }
    00105   }
    00106   // avoid creating these QStrings again and again
    00107   static const QString& dot = KGlobal::staticQString(".");
    00108   if ( _urlIsDirectory && !UDS_URL_seen && !m_strName.isEmpty() && m_strName != dot )
    00109     m_url.addPath( m_strName );
    00110   init( _determineMimeTypeOnDemand );
    00111 }
    00112
    00113 KFileItem::KFileItem( mode_t _mode, mode_t _permissions, const KURL& _url, bool _determineMimeTypeOnDemand ) :
    00114   m_entry(), // warning !
    00115   m_url( _url ),
    00116   m_strName( _url.fileName() ),
    00117   m_strText( KIO::decodeFileName( m_strName ) ),
    00118   m_pMimeType( 0 ),
    00119   m_fileMode ( _mode ),
    00120   m_permissions( _permissions ),
    00121   m_bMarked( false ),
    00122   m_bLink( false ),
    00123   m_bIsLocalURL( _url.isLocalFile() ),
    00124   m_bMimeTypeKnown( false ),
    00125   d(0L)
    00126 {
    00127   init( _determineMimeTypeOnDemand );
    00128 }
    00129
    00130 KFileItem::KFileItem( const KURL &url, const QString &mimeType, mode_t mode )
    00131 :  m_url( url ),
    00132   m_strName( url.fileName() ),
    00133   m_strText( KIO::decodeFileName( m_strName ) ),
    00134   m_pMimeType( 0 ),
    00135   m_fileMode( mode ),
    00136   m_permissions( KFileItem::Unknown ),
    00137   m_bMarked( false ),
    00138   m_bLink( false ),
    00139   m_bIsLocalURL( url.isLocalFile() ),
    00140   m_bMimeTypeKnown( !mimeType.isEmpty() ),
    00141   d(0L)
    00142 {
    00143   if (m_bMimeTypeKnown)
    00144     m_pMimeType = KMimeType::mimeType( mimeType );
    00145
    00146   init( false );
    00147 }
    00148
    00149 KFileItem::KFileItem( const KFileItem & item ) :
    00150   d(0L)
    00151 {
    00152     assign( item );
    00153 }
    00154
    00155 KFileItem::~KFileItem()
    00156 {
    00157 }
    00158
    00159 void KFileItem::init( bool _determineMimeTypeOnDemand )
    00160 {
    00161   m_access = QString::null;
    00162   m_size = (KIO::filesize_t) -1;
    00163   //  metaInfo = KFileMetaInfo();
    00164   for ( int i = 0; i < NumFlags; i++ )
    00165       m_time[i] = (time_t) -1;
    00166
    00167   // determine mode and/or permissions if unknown
    00168   if ( m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown )
    00169   {
    00170     mode_t mode = 0;
    00171     if ( m_url.isLocalFile() )
    00172     {
    00173       /* directories may not have a slash at the end if
    00174        * we want to stat() them; it requires that we
    00175        * change into it .. which may not be allowed
    00176        * stat("/is/unaccessible")  -> rwx------
    00177        * stat("/is/unaccessible/") -> EPERM            H.Z.
    00178        * This is the reason for the -1
    00179        */
    00180       KDE_struct_stat buf;
    00181       QCString path = QFile::encodeName(m_url.path( -1 ));
    00182       if ( KDE_lstat( path.data(), &buf ) == 0 )
    00183       {
    00184         mode = buf.st_mode;
    00185         if ( S_ISLNK( mode ) )
    00186         {
    00187           m_bLink = true;
    00188           if ( KDE_stat( path.data(), &buf ) == 0 )
    00189               mode = buf.st_mode;
    00190           else // link pointing to nowhere (see kio/file/file.cc)
    00191               mode = (S_IFMT-1) | S_IRWXU | S_IRWXG | S_IRWXO;
    00192         }
    00193         // While we're at it, store the times
    00194         m_time[ Modification ] = buf.st_mtime;
    00195         m_time[ Access ] = buf.st_atime;
    00196       }
    00197     }
    00198     if ( m_fileMode == KFileItem::Unknown )
    00199       m_fileMode = mode & S_IFMT; // extract file type
    00200     if ( m_permissions == KFileItem::Unknown )
    00201       m_permissions = mode & 07777; // extract permissions
    00202   }
    00203
    00204   // determine the mimetype
    00205   if (!m_pMimeType )
    00206   {
    00207       m_pMimeType = KMimeType::findByURL( m_url, m_fileMode, m_bIsLocalURL,
    00208                                           // use fast mode if not mimetype on demand
    00209                                           _determineMimeTypeOnDemand );
    00210       // if we didn't use fast mode, or if we got a result, then this is the mimetype
    00211       // otherwise, determineMimeType will be able to do better.
    00212       m_bMimeTypeKnown = (!_determineMimeTypeOnDemand) || (m_pMimeType->name() != KMimeType::defaultMimeType());
    00213   }
    00214
    00215 }
    00216
    00217 void KFileItem::refresh()
    00218 {
    00219   m_fileMode = KFileItem::Unknown;
    00220   m_permissions = KFileItem::Unknown;
    00221   m_user = QString::null;
    00222   m_group = QString::null;
    00223   m_access = QString::null;
    00224   m_size = (KIO::filesize_t) -1;
    00225   m_metaInfo = KFileMetaInfo();
    00226   for ( int i = 0; i < NumFlags; i++ )
    00227       m_time[i] = (time_t) -1;
    00228
    00229   // Basically, we can't trust any information we got while listing.
    00230   // Everything could have changed...
    00231   // Clearing m_entry makes it possible to detect changes in the size of the file,
    00232   // the time information, etc.
    00233   m_entry = KIO::UDSEntry();
    00234   init( false );
    00235 }
    00236
    00237 void KFileItem::refreshMimeType()
    00238 {
    00239   m_pMimeType = 0L;
    00240   init( false ); // Will determine the mimetype
    00241 }
    00242
    00243 void KFileItem::setURL( const KURL &url )
    00244 {
    00245   m_url = url;
    00246   m_strName = url.fileName();
    00247   m_strText = KIO::decodeFileName( m_strName );
    00248 }
    00249
    00250 QString KFileItem::linkDest() const
    00251 {
    00252   // Extract it from the KIO::UDSEntry
    00253   KIO::UDSEntry::ConstIterator it = m_entry.begin();
    00254   for( ; it != m_entry.end(); it++ )
    00255     if ( (*it).m_uds == KIO::UDS_LINK_DEST )
    00256       return (*it).m_str;
    00257   // If not in the KIO::UDSEntry, or if UDSEntry empty, use readlink() [if local URL]
    00258   if ( m_bIsLocalURL )
    00259   {
    00260     char buf[1000];
    00261     int n = readlink( QFile::encodeName(m_url.path( -1 )), buf, sizeof(buf)-1 );
    00262     if ( n != -1 )
    00263     {
    00264       buf[ n ] = 0;
    00265       return QFile::decodeName( buf );
    00266     }
    00267   }
    00268   return QString::null;
    00269 }
    00270
    00271 KIO::filesize_t KFileItem::size() const
    00272 {
    00273   if ( m_size != (KIO::filesize_t) -1 )
    00274     return m_size;
    00275
    00276   // Extract it from the KIO::UDSEntry
    00277   KIO::UDSEntry::ConstIterator it = m_entry.begin();
    00278   for( ; it != m_entry.end(); it++ )
    00279     if ( (*it).m_uds == KIO::UDS_SIZE ) {
    00280       m_size = (*it).m_long;
    00281       return m_size;
    00282     }
    00283   // If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
    00284   if ( m_bIsLocalURL )
    00285   {
    00286     KDE_struct_stat buf;
    00287     if ( KDE_stat( QFile::encodeName(m_url.path( -1 )), &buf ) == 0 )
    00288         return buf.st_size;
    00289   }
    00290   return 0L;
    00291 }
    00292
    00293 time_t KFileItem::time( unsigned int which ) const
    00294 {
    00295   unsigned int mappedWhich = 0;
    00296
    00297   switch( which ) {
    00298     case KIO::UDS_MODIFICATION_TIME:
    00299       mappedWhich = Modification;
    00300       break;
    00301     case KIO::UDS_ACCESS_TIME:
    00302       mappedWhich = Access;
    00303       break;
    00304     case KIO::UDS_CREATION_TIME:
    00305       mappedWhich = Creation;
    00306       break;
    00307   }
    00308
    00309   if ( m_time[mappedWhich] != (time_t) -1 )
    00310     return m_time[mappedWhich];
    00311
    00312   // Extract it from the KIO::UDSEntry
    00313   KIO::UDSEntry::ConstIterator it = m_entry.begin();
    00314   for( ; it != m_entry.end(); it++ )
    00315     if ( (*it).m_uds == which ) {
    00316       m_time[mappedWhich] = static_cast<time_t>((*it).m_long);
    00317       return m_time[mappedWhich];
    00318     }
    00319
    00320   // If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
    00321   if ( m_bIsLocalURL )
    00322   {
    00323     KDE_struct_stat buf;
    00324     if ( KDE_stat( QFile::encodeName(m_url.path(-1)), &buf ) == 0 )
    00325     {
    00326         m_time[mappedWhich] = (which == KIO::UDS_MODIFICATION_TIME) ?
    00327                                buf.st_mtime :
    00328                                (which == KIO::UDS_ACCESS_TIME) ? buf.st_atime :
    00329                                static_cast<time_t>(0); // We can't determine creation time for local files
    00330         return m_time[mappedWhich];
    00331     }
    00332   }
    00333   return static_cast<time_t>(0);
    00334 }
    00335
    00336
    00337 QString KFileItem::user() const
    00338 {
    00339   if ( m_user.isEmpty() && m_bIsLocalURL )
    00340   {
    00341     KDE_struct_stat buff;
    00342     if ( KDE_lstat( QFile::encodeName(m_url.path( -1 )), &buff ) == 0) // get uid/gid of the link, if it's a link
    00343     {
    00344       struct passwd *user = getpwuid( buff.st_uid );
    00345       if ( user != 0L )
    00346         m_user = QString::fromLocal8Bit(user->pw_name);
    00347     }
    00348   }
    00349   return m_user;
    00350 }
    00351
    00352 QString KFileItem::group() const
    00353 {
    00354   if (m_group.isEmpty() && m_bIsLocalURL )
    00355   {
    00356     KDE_struct_stat buff;
    00357     if ( KDE_lstat( QFile::encodeName(m_url.path( -1 )), &buff ) == 0) // get uid/gid of the link, if it's a link
    00358     {
    00359       struct group *ge = getgrgid( buff.st_gid );
    00360       if ( ge != 0L ) {
    00361         m_group = QString::fromLocal8Bit(ge->gr_name);
    00362         if (m_group.isEmpty())
    00363           m_group.sprintf("%d",ge->gr_gid);
    00364       } else
    00365         m_group.sprintf("%d",buff.st_gid);
    00366     }
    00367   }
    00368   return m_group;
    00369 }
    00370
    00371 QString KFileItem::mimetype() const
    00372 {
    00373   KFileItem * that = const_cast<KFileItem *>(this);
    00374   return that->determineMimeType()->name();
    00375 }
    00376
    00377 KMimeType::Ptr KFileItem::determineMimeType()
    00378 {
    00379   if ( !m_pMimeType || !m_bMimeTypeKnown )
    00380   {
    00381     m_pMimeType = KMimeType::findByURL( m_url, m_fileMode, m_bIsLocalURL );
    00382     //kdDebug() << "finding mimetype for " << m_url.url() << " : " << m_pMimeType->name() << endl;
    00383     m_bMimeTypeKnown = true;
    00384   }
    00385
    00386   return m_pMimeType;
    00387 }
    00388
    00389 bool KFileItem::isMimeTypeKnown() const
    00390 {
    00391   // The mimetype isn't known if determineMimeType was never called (on-demand determination)
    00392   // or if this fileitem has a guessed mimetype (e.g. ftp symlink) - in which case
    00393   // it always remains "not fully determined"
    00394   return m_bMimeTypeKnown && m_guessedMimeType.isEmpty();
    00395 }
    00396
    00397 QString KFileItem::mimeComment()
    00398 {
    00399  KMimeType::Ptr mType = determineMimeType();
    00400  QString comment = mType->comment( m_url, m_bIsLocalURL );
    00401   if (!comment.isEmpty())
    00402     return comment;
    00403   else
    00404     return mType->name();
    00405 }
    00406
    00407 QString KFileItem::iconName()
    00408 {
    00409   return determineMimeType()->icon(m_url, m_bIsLocalURL);
    00410 }
    00411
    00412 int KFileItem::overlays() const
    00413 {
    00414   int _state = 0;
    00415   if ( m_bLink )
    00416       _state |= KIcon::LinkOverlay;
    00417
    00418   if ( !S_ISDIR( m_fileMode ) // Locked dirs have a special icon, use the overlay for files only
    00419        && !isReadable())
    00420      _state |= KIcon::LockOverlay;
    00421
    00422   if ( m_strName[0] == '.' )
    00423      _state |= KIcon::HiddenOverlay;
    00424
    00425   if( S_ISDIR( m_fileMode ) && m_bIsLocalURL)
    00426   {
    00427     if (KFileShare::isDirectoryShared( m_url.path() ))
    00428     {
    00429       kdDebug()<<"KFileShare::isDirectoryShared : "<<m_url.path()<<endl;
    00430       _state |= KIcon::ShareOverlay;
    00431     }
    00432   }
    00433
    00434   if ( m_pMimeType->name() == "application/x-gzip" && m_url.fileName().right(3) == ".gz" )
    00435      _state |= KIcon::ZipOverlay;
    00436   return _state;
    00437 }
    00438
    00439 QPixmap KFileItem::pixmap( int _size, int _state ) const
    00440 {
    00441   if ( !m_pMimeType )
    00442   {
    00443     static const QString & defaultFolderIcon =
    00444        KGlobal::staticQString(KMimeType::mimeType( "inode/directory" )->KServiceType::icon());
    00445     if ( S_ISDIR( m_fileMode ) )
    00446      return DesktopIcon( defaultFolderIcon, _size, _state );
    00447
    00448     return DesktopIcon( "unknown", _size, _state );
    00449   }
    00450
    00451   _state |= overlays();
    00452
    00453   KMimeType::Ptr mime;
    00454   // Use guessed mimetype if the main one hasn't been determined for sure
    00455   if ( !m_bMimeTypeKnown && !m_guessedMimeType.isEmpty() )
    00456       mime = KMimeType::mimeType( m_guessedMimeType );
    00457   else
    00458       mime = m_pMimeType;
    00459
    00460   // Support for gzipped files: extract mimetype of contained file
    00461   // See also the relevant code in overlays, which adds the zip overlay.
    00462   if ( mime->name() == "application/x-gzip" && m_url.fileName().right(3) == ".gz" )
    00463   {
    00464       QString subFileName = m_url.path().left( m_url.path().length() - 3 );
    00465       //kdDebug() << "KFileItem::pixmap subFileName=" << subFileName << endl;
    00466       mime = KMimeType::findByURL( subFileName, 0, m_bIsLocalURL );
    00467   }
    00468
    00469   QPixmap p = mime->pixmap( m_url, KIcon::Desktop, _size, _state );
    00470   if (p.isNull())
    00471       kdWarning() << "Pixmap not found for mimetype " << m_pMimeType->name() << endl;
    00472
    00473   return p;
    00474 }
    00475
    00476 bool KFileItem::isReadable() const
    00477 {
    00478   /*
    00479   struct passwd * user = getpwuid( geteuid() );
    00480   bool isMyFile = (QString::fromLocal8Bit(user->pw_name) == m_user);
    00481   // This gets ugly for the group....
    00482   // Maybe we want a static QString for the user and a static QStringList
    00483   // for the groups... then we need to handle the deletion properly...
    00484   */
    00485
    00486   // No read permission at all
    00487   if ( !(S_IRUSR & m_permissions) && !(S_IRGRP & m_permissions) && !(S_IROTH & m_permissions) )
    00488       return false;
    00489
    00490   // Or if we can't read it [using ::access()] - not network transparent
    00491   else if ( m_bIsLocalURL && ::access( QFile::encodeName(m_url.path()), R_OK ) == -1 )
    00492       return false;
    00493
    00494   return true;
    00495 }
    00496
    00497 bool KFileItem::isDir() const
    00498 {
    00499   if ( !m_bMimeTypeKnown && !m_guessedMimeType.isEmpty() )
    00500   {
    00501     kdDebug() << " KFileItem::isDir can't say -> false " << endl;
    00502     return false; // can't say for sure, so no
    00503   }
    00504   return S_ISDIR(m_fileMode);
    00505 }
    00506
    00507 bool KFileItem::acceptsDrops()
    00508 {
    00509   // A directory ?
    00510   if ( S_ISDIR( mode() ) )
    00511   {
    00512     if ( m_bIsLocalURL ) // local -> check if we can enter it
    00513        return (::access( QFile::encodeName(m_url.path()), X_OK ) == 0);
    00514     else
    00515        return true; // assume ok for remote urls
    00516   }
    00517
    00518   // But only local .desktop files and executables
    00519   if ( !m_bIsLocalURL )
    00520     return false;
    00521
    00522   if ( mimetype() == "application/x-desktop")
    00523     return true;
    00524
    00525   // Executable, shell script ... ?
    00526   if ( ::access( QFile::encodeName(m_url.path()), X_OK ) == 0 )
    00527     return true;
    00528
    00529   return false;
    00530 }
    00531
    00532 QString KFileItem::getStatusBarInfo()
    00533 {
    00534   QString comment = determineMimeType()->comment( m_url, m_bIsLocalURL );
    00535   QString text = m_strText;
    00536   // Extract from the KIO::UDSEntry the additional info we didn't get previously
    00537   QString myLinkDest = linkDest();
    00538   KIO::filesize_t mySize = size();
    00539
    00540   if ( m_bLink )
    00541   {
    00542       QString tmp;
    00543       if ( comment.isEmpty() )
    00544         tmp = i18n ( "Symbolic Link" );
    00545       else
    00546         tmp = i18n("%1 (Link)").arg(comment);
    00547       text += "->";
    00548       text += myLinkDest;
    00549       text += "  ";
    00550       text += tmp;
    00551   }
    00552   else if ( S_ISREG( m_fileMode ) )
    00553   {
    00554       text += QString(" (%1)").arg( KIO::convertSize( mySize ) );
    00555       text += "  ";
    00556       text += comment;
    00557   }
    00558   else if ( S_ISDIR ( m_fileMode ) )
    00559   {
    00560       text += "/  ";
    00561       text += comment;
    00562     }
    00563     else
    00564     {
    00565       text += "  ";
    00566       text += comment;
    00567     }
    00568     return text;
    00569 }
    00570
    00571 QString KFileItem::getToolTipText(int maxcount)
    00572 {
    00573   // we can return QString::null if no tool tip should be shown
    00574   QString tip;
    00575   KFileMetaInfo info = metaInfo();
    00576
    00577   // the font tags are a workaround for the fact that the tool tip gets
    00578   // screwed if the color scheme uses white as default text color
    00579   const char* start = "<tr><td><nobr><font color=\"black\">";
    00580   const char* mid   = "</font></nobr></td><td><nobr><font color=\"black\">";
    00581   const char* end   = "</font></nobr></td></tr>";
    00582
    00583   tip = "<table cellspacing=0 cellpadding=0>";
    00584
    00585   //kdDebug() << "Found no meta info" << endl;
    00586
    00587   tip += start + i18n("Type:") + mid;
    00588
    00589   QString type = QStyleSheet::escape(determineMimeType()->comment());
    00590   if ( m_bLink )
    00591     tip += i18n("Link to %1").arg(type) + end;
    00592   else
    00593     tip += type + end;
    00594
    00595   if ( !S_ISDIR ( m_fileMode ) )
    00596     tip += start + i18n("Size:") + mid +
    00597            KIO::convertSize( size() ) + end;
    00598
    00599   tip += start + i18n("Modified:") + mid +
    00600          timeString( KIO::UDS_MODIFICATION_TIME) + end +
    00601          start + i18n("Owner:") + mid + user() + " - " + group() + end +
    00602          start + i18n("Permissions:") + mid +
    00603          parsePermissions(m_permissions) + end;
    00604
    00605   if (info.isValid() && !info.isEmpty() )
    00606   {
    00607     QStringList keys = info.preferredKeys();
    00608
    00609     // now the rest
    00610     QStringList::Iterator it = keys.begin();
    00611     for (int count = 0; count<maxcount && it!=keys.end() ; ++it)
    00612     {
    00613       KFileMetaInfoItem item = info.item( *it );
    00614       if ( item.isValid() )
    00615       {
    00616         QString s = item.string();
    00617         if (s.length() > 50) s = s.left(47) + "...";
    00618         if ( !s.isEmpty() )
    00619         {
    00620           count++;
    00621           tip += start +
    00622                    QStyleSheet::escape( item.translatedKey() ) + ":" +
    00623                  mid +
    00624                    QStyleSheet::escape( s ) +
    00625                  end;
    00626         }
    00627
    00628       }
    00629     }
    00630     tip += "</table>";
    00631   }
    00632
    00633   //kdDebug() << "making this the tool tip rich text:\n";
    00634   //kdDebug() << tip << endl;
    00635
    00636   return tip;
    00637 }
    00638
    00639 void KFileItem::run()
    00640 {
    00641   KURL url( m_url );
    00642   // When clicking on a link to e.g. $HOME from the desktop, we want to open $HOME
    00643   // But when following a link on the FTP site, the target be an absolute path
    00644   // that doesn't work in the URL. So we resolve links only on the local filesystem.
    00645   if ( m_bLink && m_bIsLocalURL )
    00646     url = KURL( m_url, linkDest() );
    00647   (void) new KRun( url, m_fileMode, m_bIsLocalURL );
    00648 }
    00649
    00650 bool KFileItem::cmp( const KFileItem & item )
    00651 {
    00652     return ( m_strName == item.m_strName
    00653              && m_bIsLocalURL == item.m_bIsLocalURL
    00654              && m_fileMode == item.m_fileMode
    00655              && m_permissions == item.m_permissions
    00656              && m_user == item.m_user
    00657              && m_group == item.m_group
    00658              && m_bLink == item.m_bLink
    00659              && size() == item.size()
    00660              && time(KIO::UDS_MODIFICATION_TIME) == item.time(KIO::UDS_MODIFICATION_TIME) );
    00661 }
    00662
    00663 void KFileItem::assign( const KFileItem & item )
    00664 {
    00665     m_entry = item.m_entry;
    00666     m_url = item.m_url;
    00667     m_bIsLocalURL = item.m_bIsLocalURL;
    00668     m_strName = item.m_strName;
    00669     m_strText = item.m_strText;
    00670     m_fileMode = item.m_fileMode;
    00671     m_permissions = item.m_permissions;
    00672     m_user = item.m_user;
    00673     m_group = item.m_group;
    00674     m_bLink = item.m_bLink;
    00675     m_pMimeType = item.m_pMimeType;
    00676     m_strLowerCaseName = item.m_strLowerCaseName;
    00677     m_bMimeTypeKnown = item.m_bMimeTypeKnown;
    00678     m_guessedMimeType   = item.m_guessedMimeType;
    00679     m_access            = item.m_access;
    00680     m_metaInfo          = item.m_metaInfo;
    00681     for ( int i = 0; i < NumFlags; i++ )
    00682         m_time[i] = item.m_time[i];
    00683     m_size = item.m_size;
    00684     // note: m_extra is NOT copied, as we'd have no control over who is
    00685     // deleting the data or not.
    00686
    00687     // We had a mimetype previously (probably), so we need to re-determine it
    00688     determineMimeType();
    00689 }
    00690
    00691 void KFileItem::setExtraData( const void *key, void *value )
    00692 {
    00693     if ( !key )
    00694         return;
    00695
    00696     m_extra.replace( key, value );
    00697 }
    00698
    00699 const void * KFileItem::extraData( const void *key ) const
    00700 {
    00701     QMapConstIterator<const void*,void*> it = m_extra.find( key );
    00702     if ( it != m_extra.end() )
    00703         return it.data();
    00704     return 0L;
    00705 }
    00706
    00707 void * KFileItem::extraData( const void *key )
    00708 {
    00709     QMapIterator<const void*,void*> it = m_extra.find( key );
    00710     if ( it != m_extra.end() )
    00711         return it.data();
    00712     return 0L;
    00713 }
    00714
    00715 void KFileItem::removeExtraData( const void *key )
    00716 {
    00717     m_extra.remove( key );
    00718 }
    00719
    00720 QString KFileItem::permissionsString() const
    00721 {
    00722     if (m_access.isNull())
    00723       m_access = parsePermissions( m_permissions );
    00724
    00725     return m_access;
    00726 }
    00727
    00728 QString KFileItem::parsePermissions(mode_t perm) const
    00729 {
    00730     char p[] = "----------";
    00731
    00732     if (isDir())
    00733         p[0]='d';
    00734     else if (isLink())
    00735         p[0]='l';
    00736
    00737     if (perm & QFileInfo::ReadUser)
    00738         p[1]='r';
    00739     if (perm & QFileInfo::WriteUser)
    00740         p[2]='w';
    00741     if (perm & QFileInfo::ExeUser)
    00742         p[3]='x';
    00743
    00744     if (perm & QFileInfo::ReadGroup)
    00745         p[4]='r';
    00746     if (perm & QFileInfo::WriteGroup)
    00747         p[5]='w';
    00748     if (perm & QFileInfo::ExeGroup)
    00749         p[6]='x';
    00750
    00751     if (perm & QFileInfo::ReadOther)
    00752         p[7]='r';
    00753     if (perm & QFileInfo::WriteOther)
    00754         p[8]='w';
    00755     if (perm & QFileInfo::ExeOther)
    00756         p[9]='x';
    00757
    00758     return QString::fromLatin1(p);
    00759 }
    00760
    00761 // check if we need to cache this
    00762 QString KFileItem::timeString( unsigned int which ) const
    00763 {
    00764     QDateTime t;
    00765     t.setTime_t( time(which) );
    00766     return KGlobal::locale()->formatDateTime( t );
    00767 }
    00768
    00769 void KFileItem::setMetaInfo( const KFileMetaInfo & info )
    00770 {
    00771     m_metaInfo = info;
    00772 }
    00773
    00774 const KFileMetaInfo & KFileItem::metaInfo(bool autoget, int) const
    00775 {
    00776     if ( autoget && m_url.isLocalFile() && !m_metaInfo.isValid() )
    00777     {
    00778         m_metaInfo = KFileMetaInfo( m_url.path(), mimetype() );
    00779     }
    00780
    00781     return m_metaInfo;
    00782 }
    00783
    00784 void KFileItem::virtual_hook( int, void* )
    00785 { /*BASE::virtual_hook( id, data );*/ }
    00786

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:30 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001