• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
kfileitem.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 1999-2006 David Faure <faure@kde.org>
3  2001 Carsten Pfeiffer <pfeiffer@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kfileitem.h"
22 
23 #include <config.h>
24 #include <config-kio.h>
25 
26 #include <sys/time.h>
27 #include <pwd.h>
28 #include <grp.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 
32 #include <assert.h>
33 #include <unistd.h>
34 
35 #include <QtCore/QDate>
36 #include <QtCore/QDir>
37 #include <QtCore/QFile>
38 #include <QtCore/QMap>
39 #include <QtGui/QApplication>
40 #include <QtGui/QPalette>
41 #include <QTextDocument>
42 
43 #include <kdebug.h>
44 #include <kfilemetainfo.h>
45 #include <kglobal.h>
46 #include <kiconloader.h>
47 #include <klocale.h>
48 #include <kmimetype.h>
49 #include <krun.h>
50 #include <kde_file.h>
51 #include <kdesktopfile.h>
52 #include <kmountpoint.h>
53 #include <kconfiggroup.h>
54 #ifndef Q_OS_WIN
55 #include <knfsshare.h>
56 #include <ksambashare.h>
57 #endif
58 #include <kfilesystemtype_p.h>
59 
60 class KFileItemPrivate : public QSharedData
61 {
62 public:
63  KFileItemPrivate(const KIO::UDSEntry& entry,
64  mode_t mode, mode_t permissions,
65  const KUrl& itemOrDirUrl,
66  bool urlIsDirectory,
67  bool delayedMimeTypes)
68  : m_entry( entry ),
69  m_url(itemOrDirUrl),
70  m_strName(),
71  m_strText(),
72  m_iconName(),
73  m_strLowerCaseName(),
74  m_pMimeType( 0 ),
75  m_fileMode( mode ),
76  m_permissions( permissions ),
77  m_bMarked( false ),
78  m_bLink( false ),
79  m_bIsLocalUrl(itemOrDirUrl.isLocalFile()),
80  m_bMimeTypeKnown( false ),
81  m_delayedMimeTypes( delayedMimeTypes ),
82  m_useIconNameCache(false),
83  m_hidden(Auto),
84  m_slow(SlowUnknown)
85  {
86  if (entry.count() != 0) {
87  readUDSEntry( urlIsDirectory );
88  } else {
89  Q_ASSERT(!urlIsDirectory);
90  m_strName = itemOrDirUrl.fileName();
91  m_strText = KIO::decodeFileName( m_strName );
92  }
93  init();
94  }
95 
96  ~KFileItemPrivate()
97  {
98  }
99 
106  void init();
107 
108  QString localPath() const;
109  KIO::filesize_t size() const;
110  KDateTime time( KFileItem::FileTimes which ) const;
111  void setTime(KFileItem::FileTimes which, long long time_t_val) const;
112  bool cmp( const KFileItemPrivate & item ) const;
113  QString user() const;
114  QString group() const;
115  bool isSlow() const;
116 
121  void readUDSEntry( bool _urlIsDirectory );
122 
126  QString parsePermissions( mode_t perm ) const;
127 
131  mutable KIO::UDSEntry m_entry;
135  KUrl m_url;
136 
140  QString m_strName;
141 
146  QString m_strText;
147 
151  mutable QString m_iconName;
152 
156  mutable QString m_strLowerCaseName;
157 
161  mutable KMimeType::Ptr m_pMimeType;
162 
166  mode_t m_fileMode;
170  mode_t m_permissions;
171 
175  bool m_bMarked:1;
179  bool m_bLink:1;
183  bool m_bIsLocalUrl:1;
184 
185  mutable bool m_bMimeTypeKnown:1;
186  mutable bool m_delayedMimeTypes:1;
187 
189  mutable bool m_useIconNameCache:1;
190 
191  // Auto: check leading dot.
192  enum { Auto, Hidden, Shown } m_hidden:3;
193 
194  // Slow? (nfs/smb/ssh)
195  mutable enum { SlowUnknown, Fast, Slow } m_slow:3;
196 
197  // For special case like link to dirs over FTP
198  QString m_guessedMimeType;
199  mutable QString m_access;
200 #ifndef KDE_NO_DEPRECATED
201  QMap<const void*, void*> m_extra; // DEPRECATED
202 #endif
203  mutable KFileMetaInfo m_metaInfo;
204 
205  enum { NumFlags = KFileItem::CreationTime + 1 };
206  mutable KDateTime m_time[3];
207 };
208 
209 void KFileItemPrivate::init()
210 {
211  m_access.clear();
212  // metaInfo = KFileMetaInfo();
213 
214  // determine mode and/or permissions if unknown
215  // TODO: delay this until requested
216  if ( m_fileMode == KFileItem::Unknown || m_permissions == KFileItem::Unknown )
217  {
218  mode_t mode = 0;
219  if ( m_url.isLocalFile() )
220  {
221  /* directories may not have a slash at the end if
222  * we want to stat() them; it requires that we
223  * change into it .. which may not be allowed
224  * stat("/is/unaccessible") -> rwx------
225  * stat("/is/unaccessible/") -> EPERM H.Z.
226  * This is the reason for the -1
227  */
228  KDE_struct_stat buf;
229  const QString path = m_url.toLocalFile( KUrl::RemoveTrailingSlash );
230  if ( KDE::lstat( path, &buf ) == 0 )
231  {
232  mode = buf.st_mode;
233  if ( S_ISLNK( mode ) )
234  {
235  m_bLink = true;
236  if ( KDE::stat( path, &buf ) == 0 )
237  mode = buf.st_mode;
238  else // link pointing to nowhere (see kio/file/file.cc)
239  mode = (S_IFMT-1) | S_IRWXU | S_IRWXG | S_IRWXO;
240  }
241  // While we're at it, store the times
242  setTime(KFileItem::ModificationTime, buf.st_mtime);
243  setTime(KFileItem::AccessTime, buf.st_atime);
244  if ( m_fileMode == KFileItem::Unknown )
245  m_fileMode = mode & S_IFMT; // extract file type
246  if ( m_permissions == KFileItem::Unknown )
247  m_permissions = mode & 07777; // extract permissions
248  } else {
249  kDebug() << path << "does not exist anymore";
250  }
251  }
252  }
253 }
254 
255 void KFileItemPrivate::readUDSEntry( bool _urlIsDirectory )
256 {
257  // extract fields from the KIO::UDS Entry
258 
259  m_fileMode = m_entry.numberValue( KIO::UDSEntry::UDS_FILE_TYPE, KFileItem::Unknown );
260  m_permissions = m_entry.numberValue( KIO::UDSEntry::UDS_ACCESS, KFileItem::Unknown );
261  m_strName = m_entry.stringValue( KIO::UDSEntry::UDS_NAME );
262 
263  const QString displayName = m_entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_NAME );
264  if (!displayName.isEmpty())
265  m_strText = displayName;
266  else
267  m_strText = KIO::decodeFileName( m_strName );
268 
269  const QString urlStr = m_entry.stringValue( KIO::UDSEntry::UDS_URL );
270  const bool UDS_URL_seen = !urlStr.isEmpty();
271  if ( UDS_URL_seen ) {
272  m_url = KUrl( urlStr );
273  if ( m_url.isLocalFile() )
274  m_bIsLocalUrl = true;
275  }
276  const QString mimeTypeStr = m_entry.stringValue( KIO::UDSEntry::UDS_MIME_TYPE );
277  m_bMimeTypeKnown = !mimeTypeStr.isEmpty();
278  if ( m_bMimeTypeKnown )
279  m_pMimeType = KMimeType::mimeType( mimeTypeStr );
280 
281  m_guessedMimeType = m_entry.stringValue( KIO::UDSEntry::UDS_GUESSED_MIME_TYPE );
282  m_bLink = !m_entry.stringValue( KIO::UDSEntry::UDS_LINK_DEST ).isEmpty(); // we don't store the link dest
283 
284  const int hiddenVal = m_entry.numberValue( KIO::UDSEntry::UDS_HIDDEN, -1 );
285  m_hidden = hiddenVal == 1 ? Hidden : ( hiddenVal == 0 ? Shown : Auto );
286 
287  // avoid creating these QStrings again and again
288  static const QString& dot = KGlobal::staticQString(".");
289  if ( _urlIsDirectory && !UDS_URL_seen && !m_strName.isEmpty() && m_strName != dot )
290  m_url.addPath( m_strName );
291 
292  m_iconName.clear();
293 }
294 
295 inline //because it is used only in one place
296 KIO::filesize_t KFileItemPrivate::size() const
297 {
298  // Extract it from the KIO::UDSEntry
299  long long fieldVal = m_entry.numberValue( KIO::UDSEntry::UDS_SIZE, -1 );
300  if ( fieldVal != -1 ) {
301  return fieldVal;
302  }
303 
304  // If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
305  if ( m_bIsLocalUrl ) {
306  KDE_struct_stat buf;
307  if ( KDE::stat( m_url.toLocalFile(KUrl::RemoveTrailingSlash), &buf ) == 0 )
308  return buf.st_size;
309  }
310  return 0;
311 }
312 
313 void KFileItemPrivate::setTime(KFileItem::FileTimes mappedWhich, long long time_t_val) const
314 {
315  m_time[mappedWhich].setTime_t(time_t_val);
316  m_time[mappedWhich] = m_time[mappedWhich].toLocalZone(); // #160979
317 }
318 
319 KDateTime KFileItemPrivate::time( KFileItem::FileTimes mappedWhich ) const
320 {
321  if ( !m_time[mappedWhich].isNull() )
322  return m_time[mappedWhich];
323 
324  // Extract it from the KIO::UDSEntry
325  long long fieldVal = -1;
326  switch ( mappedWhich ) {
327  case KFileItem::ModificationTime:
328  fieldVal = m_entry.numberValue( KIO::UDSEntry::UDS_MODIFICATION_TIME, -1 );
329  break;
330  case KFileItem::AccessTime:
331  fieldVal = m_entry.numberValue( KIO::UDSEntry::UDS_ACCESS_TIME, -1 );
332  break;
333  case KFileItem::CreationTime:
334  fieldVal = m_entry.numberValue( KIO::UDSEntry::UDS_CREATION_TIME, -1 );
335  break;
336  }
337  if ( fieldVal != -1 ) {
338  setTime(mappedWhich, fieldVal);
339  return m_time[mappedWhich];
340  }
341 
342  // If not in the KIO::UDSEntry, or if UDSEntry empty, use stat() [if local URL]
343  if ( m_bIsLocalUrl )
344  {
345  KDE_struct_stat buf;
346  if ( KDE::stat( m_url.toLocalFile(KUrl::RemoveTrailingSlash), &buf ) == 0 )
347  {
348  setTime(KFileItem::ModificationTime, buf.st_mtime);
349  setTime(KFileItem::AccessTime, buf.st_atime);
350  m_time[KFileItem::CreationTime] = KDateTime();
351  return m_time[mappedWhich];
352  }
353  }
354  return KDateTime();
355 }
356 
357 inline //because it is used only in one place
358 bool KFileItemPrivate::cmp( const KFileItemPrivate & item ) const
359 {
360 #if 0
361  kDebug() << "Comparing" << m_url << "and" << item.m_url;
362  kDebug() << " name" << (m_strName == item.m_strName);
363  kDebug() << " local" << (m_bIsLocalUrl == item.m_bIsLocalUrl);
364  kDebug() << " mode" << (m_fileMode == item.m_fileMode);
365  kDebug() << " perm" << (m_permissions == item.m_permissions);
366  kDebug() << " UDS_USER" << (user() == item.user());
367  kDebug() << " UDS_GROUP" << (group() == item.group());
368  kDebug() << " UDS_EXTENDED_ACL" << (m_entry.stringValue( KIO::UDSEntry::UDS_EXTENDED_ACL ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_EXTENDED_ACL ));
369  kDebug() << " UDS_ACL_STRING" << (m_entry.stringValue( KIO::UDSEntry::UDS_ACL_STRING ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_ACL_STRING ));
370  kDebug() << " UDS_DEFAULT_ACL_STRING" << (m_entry.stringValue( KIO::UDSEntry::UDS_DEFAULT_ACL_STRING ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_DEFAULT_ACL_STRING ));
371  kDebug() << " m_bLink" << (m_bLink == item.m_bLink);
372  kDebug() << " m_hidden" << (m_hidden == item.m_hidden);
373  kDebug() << " size" << (size() == item.size());
374  kDebug() << " ModificationTime" << (time(KFileItem::ModificationTime) == item.time(KFileItem::ModificationTime));
375  kDebug() << " UDS_ICON_NAME" << (m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME ));
376 #endif
377  return ( m_strName == item.m_strName
378  && m_bIsLocalUrl == item.m_bIsLocalUrl
379  && m_fileMode == item.m_fileMode
380  && m_permissions == item.m_permissions
381  && user() == item.user()
382  && group() == item.group()
383  && m_entry.stringValue( KIO::UDSEntry::UDS_EXTENDED_ACL ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_EXTENDED_ACL )
384  && m_entry.stringValue( KIO::UDSEntry::UDS_ACL_STRING ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_ACL_STRING )
385  && m_entry.stringValue( KIO::UDSEntry::UDS_DEFAULT_ACL_STRING ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_DEFAULT_ACL_STRING )
386  && m_bLink == item.m_bLink
387  && m_hidden == item.m_hidden
388  && size() == item.size()
389  && time(KFileItem::ModificationTime) == item.time(KFileItem::ModificationTime) // TODO only if already known!
390  && m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME ) == item.m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME )
391  );
392 
393  // Don't compare the mimetypes here. They might not be known, and we don't want to
394  // do the slow operation of determining them here.
395 }
396 
397 inline //because it is used only in one place
398 QString KFileItemPrivate::parsePermissions(mode_t perm) const
399 {
400  static char buffer[ 12 ];
401 
402  char uxbit,gxbit,oxbit;
403 
404  if ( (perm & (S_IXUSR|S_ISUID)) == (S_IXUSR|S_ISUID) )
405  uxbit = 's';
406  else if ( (perm & (S_IXUSR|S_ISUID)) == S_ISUID )
407  uxbit = 'S';
408  else if ( (perm & (S_IXUSR|S_ISUID)) == S_IXUSR )
409  uxbit = 'x';
410  else
411  uxbit = '-';
412 
413  if ( (perm & (S_IXGRP|S_ISGID)) == (S_IXGRP|S_ISGID) )
414  gxbit = 's';
415  else if ( (perm & (S_IXGRP|S_ISGID)) == S_ISGID )
416  gxbit = 'S';
417  else if ( (perm & (S_IXGRP|S_ISGID)) == S_IXGRP )
418  gxbit = 'x';
419  else
420  gxbit = '-';
421 
422  if ( (perm & (S_IXOTH|S_ISVTX)) == (S_IXOTH|S_ISVTX) )
423  oxbit = 't';
424  else if ( (perm & (S_IXOTH|S_ISVTX)) == S_ISVTX )
425  oxbit = 'T';
426  else if ( (perm & (S_IXOTH|S_ISVTX)) == S_IXOTH )
427  oxbit = 'x';
428  else
429  oxbit = '-';
430 
431  // Include the type in the first char like kde3 did; people are more used to seeing it,
432  // even though it's not really part of the permissions per se.
433  if (m_bLink)
434  buffer[0] = 'l';
435  else if (m_fileMode != KFileItem::Unknown) {
436  if (S_ISDIR(m_fileMode))
437  buffer[0] = 'd';
438  else if (S_ISSOCK(m_fileMode))
439  buffer[0] = 's';
440  else if (S_ISCHR(m_fileMode))
441  buffer[0] = 'c';
442  else if (S_ISBLK(m_fileMode))
443  buffer[0] = 'b';
444  else if (S_ISFIFO(m_fileMode))
445  buffer[0] = 'p';
446  else
447  buffer[0] = '-';
448  } else {
449  buffer[0] = '-';
450  }
451 
452  buffer[1] = ((( perm & S_IRUSR ) == S_IRUSR ) ? 'r' : '-' );
453  buffer[2] = ((( perm & S_IWUSR ) == S_IWUSR ) ? 'w' : '-' );
454  buffer[3] = uxbit;
455  buffer[4] = ((( perm & S_IRGRP ) == S_IRGRP ) ? 'r' : '-' );
456  buffer[5] = ((( perm & S_IWGRP ) == S_IWGRP ) ? 'w' : '-' );
457  buffer[6] = gxbit;
458  buffer[7] = ((( perm & S_IROTH ) == S_IROTH ) ? 'r' : '-' );
459  buffer[8] = ((( perm & S_IWOTH ) == S_IWOTH ) ? 'w' : '-' );
460  buffer[9] = oxbit;
461  // if (hasExtendedACL())
462  if (m_entry.contains(KIO::UDSEntry::UDS_EXTENDED_ACL)) {
463  buffer[10] = '+';
464  buffer[11] = 0;
465  } else {
466  buffer[10] = 0;
467  }
468 
469  return QString::fromLatin1(buffer);
470 }
471 
472 
474 
475 KFileItem::KFileItem()
476  : d(0)
477 {
478 }
479 
480 KFileItem::KFileItem( const KIO::UDSEntry& entry, const KUrl& itemOrDirUrl,
481  bool delayedMimeTypes, bool urlIsDirectory )
482  : d(new KFileItemPrivate(entry, KFileItem::Unknown, KFileItem::Unknown,
483  itemOrDirUrl, urlIsDirectory, delayedMimeTypes))
484 {
485 }
486 
487 KFileItem::KFileItem( mode_t mode, mode_t permissions, const KUrl& url, bool delayedMimeTypes )
488  : d(new KFileItemPrivate(KIO::UDSEntry(), mode, permissions,
489  url, false, delayedMimeTypes))
490 {
491 }
492 
493 KFileItem::KFileItem( const KUrl &url, const QString &mimeType, mode_t mode )
494  : d(new KFileItemPrivate(KIO::UDSEntry(), mode, KFileItem::Unknown,
495  url, false, false))
496 {
497  d->m_bMimeTypeKnown = !mimeType.isEmpty();
498  if (d->m_bMimeTypeKnown)
499  d->m_pMimeType = KMimeType::mimeType( mimeType );
500 }
501 
502 
503 KFileItem::KFileItem(const KFileItem& other)
504  : d(other.d)
505 {
506 }
507 
508 KFileItem::~KFileItem()
509 {
510 }
511 
512 void KFileItem::refresh()
513 {
514  if (!d) {
515  kWarning() << "null item";
516  return;
517  }
518 
519  d->m_fileMode = KFileItem::Unknown;
520  d->m_permissions = KFileItem::Unknown;
521  d->m_metaInfo = KFileMetaInfo();
522  d->m_hidden = KFileItemPrivate::Auto;
523  refreshMimeType();
524 
525  // Basically, we can't trust any information we got while listing.
526  // Everything could have changed...
527  // Clearing m_entry makes it possible to detect changes in the size of the file,
528  // the time information, etc.
529  d->m_entry.clear();
530  d->init();
531 }
532 
533 void KFileItem::refreshMimeType()
534 {
535  if (!d)
536  return;
537 
538  d->m_pMimeType = 0;
539  d->m_bMimeTypeKnown = false;
540  d->m_iconName.clear();
541 }
542 
543 void KFileItem::setUrl( const KUrl &url )
544 {
545  if (!d) {
546  kWarning() << "null item";
547  return;
548  }
549 
550  d->m_url = url;
551  setName( url.fileName() );
552 }
553 
554 void KFileItem::setName( const QString& name )
555 {
556  if (!d) {
557  kWarning() << "null item";
558  return;
559  }
560 
561  d->m_strName = name;
562  d->m_strText = KIO::decodeFileName( d->m_strName );
563  if (d->m_entry.contains(KIO::UDSEntry::UDS_NAME))
564  d->m_entry.insert(KIO::UDSEntry::UDS_NAME, d->m_strName); // #195385
565 
566 }
567 
568 QString KFileItem::linkDest() const
569 {
570  if (!d)
571  return QString();
572 
573  // Extract it from the KIO::UDSEntry
574  const QString linkStr = d->m_entry.stringValue( KIO::UDSEntry::UDS_LINK_DEST );
575  if ( !linkStr.isEmpty() )
576  return linkStr;
577 
578  // If not in the KIO::UDSEntry, or if UDSEntry empty, use readlink() [if local URL]
579  if ( d->m_bIsLocalUrl )
580  {
581  char buf[1000];
582  int n = readlink( QFile::encodeName(d->m_url.toLocalFile( KUrl::RemoveTrailingSlash )), buf, sizeof(buf)-1 );
583  if ( n != -1 )
584  {
585  buf[ n ] = 0;
586  return QFile::decodeName( buf );
587  }
588  }
589  return QString();
590 }
591 
592 QString KFileItemPrivate::localPath() const
593 {
594  if (m_bIsLocalUrl) {
595  return m_url.toLocalFile();
596  }
597 
598  // Extract the local path from the KIO::UDSEntry
599  return m_entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
600 }
601 
602 QString KFileItem::localPath() const
603 {
604  if (!d)
605  return QString();
606 
607  return d->localPath();
608 }
609 
610 KIO::filesize_t KFileItem::size() const
611 {
612  if (!d)
613  return 0;
614 
615  return d->size();
616 }
617 
618 bool KFileItem::hasExtendedACL() const
619 {
620  if (!d)
621  return false;
622 
623  // Check if the field exists; its value doesn't matter
624  return d->m_entry.contains(KIO::UDSEntry::UDS_EXTENDED_ACL);
625 }
626 
627 KACL KFileItem::ACL() const
628 {
629  if (!d)
630  return KACL();
631 
632  if ( hasExtendedACL() ) {
633  // Extract it from the KIO::UDSEntry
634  const QString fieldVal = d->m_entry.stringValue( KIO::UDSEntry::UDS_ACL_STRING );
635  if ( !fieldVal.isEmpty() )
636  return KACL( fieldVal );
637  }
638  // create one from the basic permissions
639  return KACL( d->m_permissions );
640 }
641 
642 KACL KFileItem::defaultACL() const
643 {
644  if (!d)
645  return KACL();
646 
647  // Extract it from the KIO::UDSEntry
648  const QString fieldVal = d->m_entry.stringValue( KIO::UDSEntry::UDS_DEFAULT_ACL_STRING );
649  if ( !fieldVal.isEmpty() )
650  return KACL(fieldVal);
651  else
652  return KACL();
653 }
654 
655 KDateTime KFileItem::time( FileTimes which ) const
656 {
657  if (!d)
658  return KDateTime();
659 
660  return d->time(which);
661 }
662 
663 #ifndef KDE_NO_DEPRECATED
664 time_t KFileItem::time( unsigned int which ) const
665 {
666  if (!d)
667  return 0;
668 
669  switch (which) {
670  case KIO::UDSEntry::UDS_ACCESS_TIME:
671  return d->time(AccessTime).toTime_t();
672  case KIO::UDSEntry::UDS_CREATION_TIME:
673  return d->time(CreationTime).toTime_t();
674  case KIO::UDSEntry::UDS_MODIFICATION_TIME:
675  default:
676  return d->time(ModificationTime).toTime_t();
677  }
678 }
679 #endif
680 
681 QString KFileItem::user() const
682 {
683  if (!d)
684  return QString();
685 
686  return d->user();
687 }
688 
689 QString KFileItemPrivate::user() const
690 {
691  QString userName = m_entry.stringValue(KIO::UDSEntry::UDS_USER);
692  if (userName.isEmpty() && m_bIsLocalUrl) {
693 #ifdef Q_WS_WIN
694  QFileInfo a(m_url.toLocalFile( KUrl::RemoveTrailingSlash ));
695  userName = a.owner();
696  m_entry.insert( KIO::UDSEntry::UDS_USER, userName );
697 #else
698  KDE_struct_stat buff;
699  if ( KDE::lstat( m_url.toLocalFile( KUrl::RemoveTrailingSlash ), &buff ) == 0) // get uid/gid of the link, if it's a link
700  {
701  struct passwd *pwuser = getpwuid( buff.st_uid );
702  if ( pwuser != 0 ) {
703  userName = QString::fromLocal8Bit(pwuser->pw_name);
704  m_entry.insert( KIO::UDSEntry::UDS_USER, userName );
705  }
706  }
707 #endif
708  }
709  return userName;
710 }
711 
712 QString KFileItem::group() const
713 {
714  if (!d)
715  return QString();
716 
717  return d->group();
718 }
719 
720 QString KFileItemPrivate::group() const
721 {
722  QString groupName = m_entry.stringValue( KIO::UDSEntry::UDS_GROUP );
723  if (groupName.isEmpty() && m_bIsLocalUrl )
724  {
725 #ifdef Q_WS_WIN
726  QFileInfo a(m_url.toLocalFile( KUrl::RemoveTrailingSlash ));
727  groupName = a.group();
728  m_entry.insert( KIO::UDSEntry::UDS_GROUP, groupName );
729 #else
730  KDE_struct_stat buff;
731  if ( KDE::lstat( m_url.toLocalFile( KUrl::RemoveTrailingSlash ), &buff ) == 0) // get uid/gid of the link, if it's a link
732  {
733  struct group *ge = getgrgid( buff.st_gid );
734  if ( ge != 0 ) {
735  groupName = QString::fromLocal8Bit(ge->gr_name);
736  if (groupName.isEmpty())
737  groupName.sprintf("%d",ge->gr_gid);
738  }
739  else
740  groupName.sprintf("%d",buff.st_gid);
741  m_entry.insert( KIO::UDSEntry::UDS_GROUP, groupName );
742  }
743 #endif
744  }
745  return groupName;
746 }
747 
748 bool KFileItemPrivate::isSlow() const
749 {
750  if (m_slow == SlowUnknown) {
751  const QString path = localPath();
752  if (!path.isEmpty()) {
753  const KFileSystemType::Type fsType = KFileSystemType::fileSystemType(path);
754  m_slow = (fsType == KFileSystemType::Nfs || fsType == KFileSystemType::Smb) ? Slow : Fast;
755  } else {
756  m_slow = Slow;
757  }
758  }
759  return m_slow == Slow;
760 }
761 
762 bool KFileItem::isSlow() const
763 {
764  if (!d)
765  return false;
766 
767  return d->isSlow();
768 }
769 
770 QString KFileItem::mimetype() const
771 {
772  if (!d)
773  return QString();
774 
775  KFileItem * that = const_cast<KFileItem *>(this);
776  return that->determineMimeType()->name();
777 }
778 
779 KMimeType::Ptr KFileItem::determineMimeType() const
780 {
781  if (!d)
782  return KMimeType::Ptr();
783 
784  if ( !d->m_pMimeType || !d->m_bMimeTypeKnown )
785  {
786  bool isLocalUrl;
787  KUrl url = mostLocalUrl(isLocalUrl);
788 
789  d->m_pMimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl );
790  Q_ASSERT(d->m_pMimeType);
791  //kDebug() << d << "finding final mimetype for" << url << ":" << d->m_pMimeType->name();
792  d->m_bMimeTypeKnown = true;
793  }
794 
795  if (d->m_delayedMimeTypes) { // if we delayed getting the iconName up till now, this is the right point in time to do so
796  d->m_delayedMimeTypes = false;
797  d->m_useIconNameCache = false;
798  (void)iconName();
799  }
800 
801  return d->m_pMimeType;
802 }
803 
804 bool KFileItem::isMimeTypeKnown() const
805 {
806  if (!d)
807  return false;
808 
809  // The mimetype isn't known if determineMimeType was never called (on-demand determination)
810  // or if this fileitem has a guessed mimetype (e.g. ftp symlink) - in which case
811  // it always remains "not fully determined"
812  return d->m_bMimeTypeKnown && d->m_guessedMimeType.isEmpty();
813 }
814 
815 bool KFileItem::isFinalIconKnown() const
816 {
817  if (!d) {
818  return false;
819  }
820  return d->m_bMimeTypeKnown && (!d->m_delayedMimeTypes);
821 }
822 
823 QString KFileItem::mimeComment() const
824 {
825  if (!d)
826  return QString();
827 
828  const QString displayType = d->m_entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_TYPE );
829  if (!displayType.isEmpty())
830  return displayType;
831 
832  KMimeType::Ptr mType = determineMimeType();
833 
834  bool isLocalUrl;
835  KUrl url = mostLocalUrl(isLocalUrl);
836 
837  KMimeType::Ptr mime = mimeTypePtr();
838  // This cannot move to kio_file (with UDS_DISPLAY_TYPE) because it needs
839  // the mimetype to be determined, which is done here, and possibly delayed...
840  if (isLocalUrl && !d->isSlow() && mime->is("application/x-desktop")) {
841  KDesktopFile cfg( url.toLocalFile() );
842  QString comment = cfg.desktopGroup().readEntry( "Comment" );
843  if (!comment.isEmpty())
844  return comment;
845  }
846 
847  QString comment = d->isSlow() ? mType->comment() : mType->comment(url);
848  //kDebug() << "finding comment for " << url.url() << " : " << d->m_pMimeType->name();
849  if (!comment.isEmpty())
850  return comment;
851  else
852  return mType->name();
853 }
854 
855 static QString iconFromDesktopFile(const QString& path)
856 {
857  KDesktopFile cfg( path );
858  const QString icon = cfg.readIcon();
859  if ( cfg.hasLinkType() ) {
860  const KConfigGroup group = cfg.desktopGroup();
861  const QString type = cfg.readPath();
862  const QString emptyIcon = group.readEntry( "EmptyIcon" );
863  if ( !emptyIcon.isEmpty() ) {
864  const QString u = cfg.readUrl();
865  const KUrl url( u );
866  if ( url.protocol() == "trash" ) {
867  // We need to find if the trash is empty, preferably without using a KIO job.
868  // So instead kio_trash leaves an entry in its config file for us.
869  KConfig trashConfig( "trashrc", KConfig::SimpleConfig );
870  if ( trashConfig.group("Status").readEntry( "Empty", true ) ) {
871  return emptyIcon;
872  }
873  }
874  }
875  }
876  return icon;
877 }
878 
879 QString KFileItem::iconName() const
880 {
881  if (!d)
882  return QString();
883 
884  if (d->m_useIconNameCache && !d->m_iconName.isEmpty()) {
885  return d->m_iconName;
886  }
887 
888  d->m_iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME );
889  if (!d->m_iconName.isEmpty()) {
890  d->m_useIconNameCache = d->m_bMimeTypeKnown;
891  return d->m_iconName;
892  }
893 
894  bool isLocalUrl;
895  KUrl url = mostLocalUrl(isLocalUrl);
896 
897  KMimeType::Ptr mime;
898  // Use guessed mimetype for the icon
899  if (!d->m_guessedMimeType.isEmpty()) {
900  mime = KMimeType::mimeType( d->m_guessedMimeType );
901  } else {
902  mime = mimeTypePtr();
903  }
904 
905  const bool delaySlowOperations = d->m_delayedMimeTypes;
906 
907  if (isLocalUrl && !delaySlowOperations && mime->is("application/x-desktop")) {
908  d->m_iconName = iconFromDesktopFile(url.toLocalFile());
909  if (!d->m_iconName.isEmpty()) {
910  d->m_useIconNameCache = d->m_bMimeTypeKnown;
911  return d->m_iconName;
912  }
913  }
914 
915  // KDE5: handle .directory files here too, and get rid of
916  // KFolderMimeType and the url argument in KMimeType::iconName().
917 
918  if (delaySlowOperations)
919  d->m_iconName = mime->iconName();
920  else
921  d->m_iconName = mime->iconName(url);
922  d->m_useIconNameCache = d->m_bMimeTypeKnown;
923  //kDebug() << "finding icon for" << url << ":" << d->m_iconName;
924  return d->m_iconName;
925 }
926 
931 static bool checkDesktopFile(const KFileItem& item, bool _determineMimeType)
932 {
933  // only local files
934  bool isLocal;
935  const KUrl url = item.mostLocalUrl(isLocal);
936  if (!isLocal)
937  return false;
938 
939  // only regular files
940  if (!item.isRegularFile())
941  return false;
942 
943  // only if readable
944  if (!item.isReadable())
945  return false;
946 
947  // return true if desktop file
948  KMimeType::Ptr mime = _determineMimeType ? item.determineMimeType() : item.mimeTypePtr();
949  return mime->is("application/x-desktop");
950 }
951 
952 QStringList KFileItem::overlays() const
953 {
954  if (!d)
955  return QStringList();
956 
957  QStringList names = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_OVERLAY_NAMES ).split(',');
958  if ( d->m_bLink ) {
959  names.append("emblem-symbolic-link");
960  }
961 
962  if (!isReadable()) {
963  names.append("object-locked");
964  }
965 
966  if ( checkDesktopFile(*this, false) ) {
967  KDesktopFile cfg( localPath() );
968  const KConfigGroup group = cfg.desktopGroup();
969 
970  // Add a warning emblem if this is an executable desktop file
971  // which is untrusted.
972  if ( group.hasKey( "Exec" ) && !KDesktopFile::isAuthorizedDesktopFile( localPath() ) ) {
973  names.append( "emblem-important" );
974  }
975 
976  if (cfg.hasDeviceType()) {
977  const QString dev = cfg.readDevice();
978  if (!dev.isEmpty()) {
979  KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByDevice(dev);
980  if (mountPoint) // mounted?
981  names.append("emblem-mounted");
982  }
983  }
984  }
985 
986  if ( isHidden() ) {
987  names.append("hidden");
988  }
989 
990 #ifndef Q_OS_WIN
991  if( S_ISDIR( d->m_fileMode ) && d->m_bIsLocalUrl)
992  {
993  if (KSambaShare::instance()->isDirectoryShared( d->m_url.toLocalFile() ) ||
994  KNFSShare::instance()->isDirectoryShared( d->m_url.toLocalFile() ))
995  {
996  //kDebug() << d->m_url.path();
997  names.append("network-workgroup");
998  }
999  }
1000 #endif // Q_OS_WIN
1001 
1002  return names;
1003 }
1004 
1005 QString KFileItem::comment() const
1006 {
1007  if (!d)
1008  return QString();
1009 
1010  return d->m_entry.stringValue( KIO::UDSEntry::UDS_COMMENT );
1011 }
1012 
1013 // ## where is this used?
1014 QPixmap KFileItem::pixmap( int _size, int _state ) const
1015 {
1016  if (!d)
1017  return QPixmap();
1018 
1019  const QString iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME );
1020  if ( !iconName.isEmpty() )
1021  return DesktopIcon(iconName, _size, _state);
1022 
1023  if (!d->m_pMimeType) {
1024  // No mimetype determined yet, go for a fast default icon
1025  if (S_ISDIR(d->m_fileMode)) {
1026  static const QString * defaultFolderIcon = 0;
1027  if ( !defaultFolderIcon ) {
1028  const KMimeType::Ptr mimeType = KMimeType::mimeType( "inode/directory" );
1029  if ( mimeType )
1030  defaultFolderIcon = &KGlobal::staticQString( mimeType->iconName() );
1031  else
1032  kWarning(7000) << "No mimetype for inode/directory could be found. Check your installation.";
1033  }
1034  if ( defaultFolderIcon )
1035  return DesktopIcon( *defaultFolderIcon, _size, _state );
1036 
1037  }
1038  return DesktopIcon( "unknown", _size, _state );
1039  }
1040 
1041  KMimeType::Ptr mime;
1042  // Use guessed mimetype for the icon
1043  if (!d->m_guessedMimeType.isEmpty())
1044  mime = KMimeType::mimeType( d->m_guessedMimeType );
1045  else
1046  mime = d->m_pMimeType;
1047 
1048  // Support for gzipped files: extract mimetype of contained file
1049  // See also the relevant code in overlays, which adds the zip overlay.
1050  if ( mime->name() == "application/x-gzip" && d->m_url.fileName().endsWith( QLatin1String( ".gz" ) ) )
1051  {
1052  KUrl sf;
1053  sf.setPath( d->m_url.path().left( d->m_url.path().length() - 3 ) );
1054  //kDebug() << "subFileName=" << subFileName;
1055  mime = KMimeType::findByUrl( sf, 0, d->m_bIsLocalUrl );
1056  }
1057 
1058  bool isLocalUrl;
1059  KUrl url = mostLocalUrl(isLocalUrl);
1060 
1061  QPixmap p = KIconLoader::global()->loadMimeTypeIcon( mime->iconName( url ), KIconLoader::Desktop, _size, _state );
1062  //kDebug() << "finding pixmap for " << url.url() << " : " << mime->name();
1063  if (p.isNull())
1064  kWarning() << "Pixmap not found for mimetype " << d->m_pMimeType->name();
1065 
1066  return p;
1067 }
1068 
1069 bool KFileItem::isReadable() const
1070 {
1071  if (!d)
1072  return false;
1073 
1074  /*
1075  struct passwd * user = getpwuid( geteuid() );
1076  bool isMyFile = (QString::fromLocal8Bit(user->pw_name) == d->m_user);
1077  // This gets ugly for the group....
1078  // Maybe we want a static QString for the user and a static QStringList
1079  // for the groups... then we need to handle the deletion properly...
1080  */
1081 
1082  if (d->m_permissions != KFileItem::Unknown) {
1083  // No read permission at all
1084  if ( !(S_IRUSR & d->m_permissions) && !(S_IRGRP & d->m_permissions) && !(S_IROTH & d->m_permissions) )
1085  return false;
1086 
1087  // Read permissions for all: save a stat call
1088  if ( (S_IRUSR|S_IRGRP|S_IROTH) & d->m_permissions )
1089  return true;
1090  }
1091 
1092  // Or if we can't read it [using ::access()] - not network transparent
1093  if ( d->m_bIsLocalUrl && KDE::access( d->m_url.toLocalFile(), R_OK ) == -1 )
1094  return false;
1095 
1096  return true;
1097 }
1098 
1099 bool KFileItem::isWritable() const
1100 {
1101  if (!d)
1102  return false;
1103 
1104  /*
1105  struct passwd * user = getpwuid( geteuid() );
1106  bool isMyFile = (QString::fromLocal8Bit(user->pw_name) == d->m_user);
1107  // This gets ugly for the group....
1108  // Maybe we want a static QString for the user and a static QStringList
1109  // for the groups... then we need to handle the deletion properly...
1110  */
1111 
1112  if (d->m_permissions != KFileItem::Unknown) {
1113  // No write permission at all
1114  if ( !(S_IWUSR & d->m_permissions) && !(S_IWGRP & d->m_permissions) && !(S_IWOTH & d->m_permissions) )
1115  return false;
1116  }
1117 
1118  // Or if we can't read it [using ::access()] - not network transparent
1119  if ( d->m_bIsLocalUrl && KDE::access( d->m_url.toLocalFile(), W_OK ) == -1 )
1120  return false;
1121 
1122  return true;
1123 }
1124 
1125 bool KFileItem::isHidden() const
1126 {
1127  if (!d)
1128  return false;
1129 
1130  // The kioslave can specify explicitly that a file is hidden or shown
1131  if ( d->m_hidden != KFileItemPrivate::Auto )
1132  return d->m_hidden == KFileItemPrivate::Hidden;
1133 
1134  // Prefer the filename that is part of the URL, in case the display name is different.
1135  QString fileName = d->m_url.fileName();
1136  if (fileName.isEmpty()) // e.g. "trash:/"
1137  fileName = d->m_strName;
1138  return fileName.length() > 1 && fileName[0] == '.'; // Just "." is current directory, not hidden.
1139 }
1140 
1141 bool KFileItem::isDir() const
1142 {
1143  if (!d)
1144  return false;
1145 
1146  if (d->m_fileMode == KFileItem::Unknown) {
1147  // Probably the file was deleted already, and KDirLister hasn't told the world yet.
1148  //kDebug() << d << url() << "can't say -> false";
1149  return false; // can't say for sure, so no
1150  }
1151  return (S_ISDIR(d->m_fileMode));
1152 }
1153 
1154 bool KFileItem::isFile() const
1155 {
1156  if (!d)
1157  return false;
1158 
1159  return !isDir();
1160 }
1161 
1162 #ifndef KDE_NO_DEPRECATED
1163 bool KFileItem::acceptsDrops() const
1164 {
1165  // A directory ?
1166  if ( S_ISDIR( mode() ) ) {
1167  return isWritable();
1168  }
1169 
1170  // But only local .desktop files and executables
1171  if ( !d->m_bIsLocalUrl )
1172  return false;
1173 
1174  if ( mimetype() == "application/x-desktop")
1175  return true;
1176 
1177  // Executable, shell script ... ?
1178  if ( QFileInfo(d->m_url.toLocalFile()).isExecutable() )
1179  return true;
1180 
1181  return false;
1182 }
1183 #endif
1184 
1185 QString KFileItem::getStatusBarInfo() const
1186 {
1187  if (!d)
1188  return QString();
1189 
1190  QString text = d->m_strText;
1191  const QString comment = mimeComment();
1192 
1193  if ( d->m_bLink )
1194  {
1195  text += ' ';
1196  if ( comment.isEmpty() )
1197  text += i18n ( "(Symbolic Link to %1)", linkDest() );
1198  else
1199  text += i18n("(%1, Link to %2)", comment, linkDest());
1200  }
1201  else if ( targetUrl() != url() )
1202  {
1203  text += i18n ( " (Points to %1)", targetUrl().pathOrUrl());
1204  }
1205  else if ( S_ISREG( d->m_fileMode ) )
1206  {
1207  text += QString(" (%1, %2)").arg( comment, KIO::convertSize( size() ) );
1208  }
1209  else
1210  {
1211  text += QString(" (%1)").arg( comment );
1212  }
1213  return text;
1214 }
1215 
1216 #ifndef KDE_NO_DEPRECATED
1217 QString KFileItem::getToolTipText(int maxcount) const
1218 {
1219  if (!d)
1220  return QString();
1221 
1222  // we can return QString() if no tool tip should be shown
1223  QString tip;
1224  KFileMetaInfo info = metaInfo();
1225 
1226  // the font tags are a workaround for the fact that the tool tip gets
1227  // screwed if the color scheme uses white as default text color
1228  const QString colorName = QApplication::palette().color(QPalette::ToolTipText).name();
1229  const QString start = "<tr><td align=\"right\"><nobr><font color=\"" + colorName + "\"><b>";
1230  const QString mid = "&nbsp;</b></font></nobr></td><td><nobr><font color=\"" + colorName + "\">";
1231  const char* end = "</font></nobr></td></tr>";
1232 
1233  tip = "<table cellspacing=0 cellpadding=0>";
1234 
1235  tip += start + i18n("Name:") + mid + text() + end;
1236  tip += start + i18n("Type:") + mid;
1237 
1238  QString type = Qt::escape(mimeComment());
1239  if ( d->m_bLink ) {
1240  tip += i18n("Link to %1 (%2)", linkDest(), type) + end;
1241  } else
1242  tip += type + end;
1243 
1244  if ( !S_ISDIR ( d->m_fileMode ) )
1245  tip += start + i18n("Size:") + mid +
1246  QString("%1").arg(KIO::convertSize(size())) +
1247  end;
1248 
1249  tip += start + i18n("Modified:") + mid +
1250  timeString( KFileItem::ModificationTime ) + end
1251 #ifndef Q_WS_WIN //TODO: show win32-specific permissions
1252  +start + i18n("Owner:") + mid + user() + " - " + group() + end +
1253  start + i18n("Permissions:") + mid +
1254  permissionsString() + end
1255 #endif
1256  ;
1257 
1258  if (info.isValid())
1259  {
1260  const QStringList keys = info.preferredKeys();
1261 
1262  // now the rest
1263  QStringList::ConstIterator it = keys.begin();
1264  for (int count = 0; count<maxcount && it!=keys.end() ; ++it)
1265  {
1266  if ( count == 0 )
1267  {
1268  tip += "<tr><td colspan=2><center><s>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</s></center></td></tr>";
1269  }
1270 
1271  KFileMetaInfoItem item = info.item( *it );
1272  if ( item.isValid() )
1273  {
1274  QString s = item.value().toString();
1275  if ( !s.isEmpty() )
1276  {
1277  count++;
1278  tip += start +
1279  Qt::escape( item.name() ) + ':' +
1280  mid +
1281  Qt::escape( s ) +
1282  end;
1283  }
1284 
1285  }
1286  }
1287  }
1288  tip += "</table>";
1289 
1290  //kDebug() << "making this the tool tip rich text:\n";
1291  //kDebug() << tip;
1292 
1293  return tip;
1294 }
1295 #endif
1296 
1297 void KFileItem::run( QWidget* parentWidget ) const
1298 {
1299  if (!d) {
1300  kWarning() << "null item";
1301  return;
1302  }
1303 
1304  (void) new KRun( targetUrl(), parentWidget, d->m_fileMode, d->m_bIsLocalUrl );
1305 }
1306 
1307 bool KFileItem::cmp( const KFileItem & item ) const
1308 {
1309  if (!d && !item.d)
1310  return true;
1311 
1312  if (!d || !item.d)
1313  return false;
1314 
1315  return d->cmp(*item.d);
1316 }
1317 
1318 bool KFileItem::operator==(const KFileItem& other) const
1319 {
1320  if (!d && !other.d)
1321  return true;
1322 
1323  if (!d || !other.d)
1324  return false;
1325 
1326  return d->m_url == other.d->m_url;
1327 }
1328 
1329 bool KFileItem::operator!=(const KFileItem& other) const
1330 {
1331  return !operator==(other);
1332 }
1333 
1334 #ifndef KDE_NO_DEPRECATED
1335 void KFileItem::setUDSEntry( const KIO::UDSEntry& _entry, const KUrl& _url,
1336  bool _delayedMimeTypes, bool _urlIsDirectory )
1337 {
1338  if (!d)
1339  return;
1340 
1341  d->m_entry = _entry;
1342  d->m_url = _url;
1343  d->m_strName.clear();
1344  d->m_strText.clear();
1345  d->m_iconName.clear();
1346  d->m_strLowerCaseName.clear();
1347  d->m_pMimeType = 0;
1348  d->m_fileMode = KFileItem::Unknown;
1349  d->m_permissions = KFileItem::Unknown;
1350  d->m_bMarked = false;
1351  d->m_bLink = false;
1352  d->m_bIsLocalUrl = _url.isLocalFile();
1353  d->m_bMimeTypeKnown = false;
1354  d->m_hidden = KFileItemPrivate::Auto;
1355  d->m_guessedMimeType.clear();
1356  d->m_metaInfo = KFileMetaInfo();
1357  d->m_delayedMimeTypes = _delayedMimeTypes;
1358  d->m_useIconNameCache = false;
1359 
1360  d->readUDSEntry( _urlIsDirectory );
1361  d->init();
1362 }
1363 #endif
1364 
1365 KFileItem::operator QVariant() const
1366 {
1367  return qVariantFromValue(*this);
1368 }
1369 
1370 #ifndef KDE_NO_DEPRECATED
1371 void KFileItem::setExtraData( const void *key, void *value )
1372 {
1373  if (!d)
1374  return;
1375 
1376  if ( !key )
1377  return;
1378 
1379  d->m_extra.insert( key, value ); // replaces the value of key if already there
1380 }
1381 #endif
1382 
1383 #ifndef KDE_NO_DEPRECATED
1384 const void * KFileItem::extraData( const void *key ) const
1385 {
1386  if (!d)
1387  return 0;
1388 
1389  return d->m_extra.value( key, 0 );
1390 }
1391 #endif
1392 
1393 #ifndef KDE_NO_DEPRECATED
1394 void KFileItem::removeExtraData( const void *key )
1395 {
1396  if (!d)
1397  return;
1398 
1399  d->m_extra.remove( key );
1400 }
1401 #endif
1402 
1403 QString KFileItem::permissionsString() const
1404 {
1405  if (!d)
1406  return QString();
1407 
1408  if (d->m_access.isNull() && d->m_permissions != KFileItem::Unknown)
1409  d->m_access = d->parsePermissions( d->m_permissions );
1410 
1411  return d->m_access;
1412 }
1413 
1414 // check if we need to cache this
1415 QString KFileItem::timeString( FileTimes which ) const
1416 {
1417  if (!d)
1418  return QString();
1419 
1420  return KGlobal::locale()->formatDateTime( d->time(which) );
1421 }
1422 
1423 #ifndef KDE_NO_DEPRECATED
1424 QString KFileItem::timeString( unsigned int which ) const
1425 {
1426  if (!d)
1427  return QString();
1428 
1429  switch (which) {
1430  case KIO::UDSEntry::UDS_ACCESS_TIME:
1431  return timeString(AccessTime);
1432  case KIO::UDSEntry::UDS_CREATION_TIME:
1433  return timeString(CreationTime);
1434  case KIO::UDSEntry::UDS_MODIFICATION_TIME:
1435  default:
1436  return timeString(ModificationTime);
1437  }
1438 }
1439 #endif
1440 
1441 void KFileItem::setMetaInfo( const KFileMetaInfo & info ) const
1442 {
1443  if (!d)
1444  return;
1445 
1446  d->m_metaInfo = info;
1447 }
1448 
1449 KFileMetaInfo KFileItem::metaInfo(bool autoget, int what) const
1450 {
1451  if (!d)
1452  return KFileMetaInfo();
1453 
1454  if ((isRegularFile() || isDir()) && autoget && !d->m_metaInfo.isValid())
1455  {
1456  bool isLocalUrl;
1457  KUrl url(mostLocalUrl(isLocalUrl));
1458  d->m_metaInfo = KFileMetaInfo(url.toLocalFile(), mimetype(), (KFileMetaInfo::What)what);
1459  }
1460  return d->m_metaInfo;
1461 }
1462 
1463 #ifndef KDE_NO_DEPRECATED
1464 void KFileItem::assign( const KFileItem & item )
1465 {
1466  *this = item;
1467 }
1468 #endif
1469 
1470 KUrl KFileItem::mostLocalUrl(bool &local) const
1471 {
1472  if (!d)
1473  return KUrl();
1474 
1475  QString local_path = localPath();
1476 
1477  if ( !local_path.isEmpty() )
1478  {
1479  local = true;
1480  KUrl url;
1481  url.setPath(local_path);
1482  return url;
1483  }
1484  else
1485  {
1486  local = d->m_bIsLocalUrl;
1487  return d->m_url;
1488  }
1489 }
1490 
1491 KUrl KFileItem::mostLocalUrl() const
1492 {
1493  bool local = false;
1494  return mostLocalUrl(local);
1495 }
1496 
1497 QDataStream & operator<< ( QDataStream & s, const KFileItem & a )
1498 {
1499  if (a.d) {
1500  // We don't need to save/restore anything that refresh() invalidates,
1501  // since that means we can re-determine those by ourselves.
1502  s << a.d->m_url;
1503  s << a.d->m_strName;
1504  s << a.d->m_strText;
1505  } else {
1506  s << KUrl();
1507  s << QString();
1508  s << QString();
1509  }
1510 
1511  return s;
1512 }
1513 
1514 QDataStream & operator>> ( QDataStream & s, KFileItem & a )
1515 {
1516  KUrl url;
1517  QString strName, strText;
1518 
1519  s >> url;
1520  s >> strName;
1521  s >> strText;
1522 
1523  if (!a.d) {
1524  kWarning() << "null item";
1525  return s;
1526  }
1527 
1528  if (url.isEmpty()) {
1529  a.d = 0;
1530  return s;
1531  }
1532 
1533  a.d->m_url = url;
1534  a.d->m_strName = strName;
1535  a.d->m_strText = strText;
1536  a.d->m_bIsLocalUrl = a.d->m_url.isLocalFile();
1537  a.d->m_bMimeTypeKnown = false;
1538  a.refresh();
1539 
1540  return s;
1541 }
1542 
1543 KUrl KFileItem::url() const
1544 {
1545  if (!d)
1546  return KUrl();
1547 
1548  return d->m_url;
1549 }
1550 
1551 mode_t KFileItem::permissions() const
1552 {
1553  if (!d)
1554  return 0;
1555 
1556  return d->m_permissions;
1557 }
1558 
1559 mode_t KFileItem::mode() const
1560 {
1561  if (!d)
1562  return 0;
1563 
1564  return d->m_fileMode;
1565 }
1566 
1567 bool KFileItem::isLink() const
1568 {
1569  if (!d)
1570  return false;
1571 
1572  return d->m_bLink;
1573 }
1574 
1575 bool KFileItem::isLocalFile() const
1576 {
1577  if (!d)
1578  return false;
1579 
1580  return d->m_bIsLocalUrl;
1581 }
1582 
1583 QString KFileItem::text() const
1584 {
1585  if (!d)
1586  return QString();
1587 
1588  return d->m_strText;
1589 }
1590 
1591 QString KFileItem::name( bool lowerCase ) const
1592 {
1593  if (!d)
1594  return QString();
1595 
1596  if ( !lowerCase )
1597  return d->m_strName;
1598  else
1599  if ( d->m_strLowerCaseName.isNull() )
1600  d->m_strLowerCaseName = d->m_strName.toLower();
1601  return d->m_strLowerCaseName;
1602 }
1603 
1604 KUrl KFileItem::targetUrl() const
1605 {
1606  if (!d)
1607  return KUrl();
1608 
1609  const QString targetUrlStr = d->m_entry.stringValue( KIO::UDSEntry::UDS_TARGET_URL );
1610  if (!targetUrlStr.isEmpty())
1611  return KUrl(targetUrlStr);
1612  else
1613  return url();
1614 }
1615 
1616 KUrl KFileItem::nepomukUri() const
1617 {
1618 #ifndef KIO_NO_NEPOMUK
1619  if (!d)
1620  return KUrl();
1621 
1622  const QString nepomukUriStr = d->m_entry.stringValue( KIO::UDSEntry::UDS_NEPOMUK_URI );
1623  if(!nepomukUriStr.isEmpty()) {
1624  return KUrl(nepomukUriStr);
1625  }
1626  else if(targetUrl().isLocalFile()) {
1627  return targetUrl();
1628  }
1629  else {
1630  return KUrl();
1631  }
1632 #else
1633  return KUrl();
1634 #endif
1635 }
1636 
1637 /*
1638  * Mimetype handling.
1639  *
1640  * Initial state: m_pMimeType = 0.
1641  * When mimeTypePtr() is called first: fast mimetype determination,
1642  * might either find an accurate mimetype (-> Final state), otherwise we
1643  * set m_pMimeType but not m_bMimeTypeKnown (-> Intermediate state)
1644  * Intermediate state: determineMimeType() does the real determination -> Final state.
1645  *
1646  * If delayedMimeTypes isn't set, then we always go to the Final state directly.
1647  */
1648 
1649 KMimeType::Ptr KFileItem::mimeTypePtr() const
1650 {
1651  if (!d)
1652  return KMimeType::Ptr();
1653 
1654  if (!d->m_pMimeType) {
1655  // On-demand fast (but not always accurate) mimetype determination
1656  Q_ASSERT(!d->m_url.isEmpty());
1657  bool isLocalUrl;
1658  KUrl url = mostLocalUrl(isLocalUrl);
1659  int accuracy;
1660  d->m_pMimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl,
1661  // use fast mode if delayed mimetype determination can refine it later
1662  d->m_delayedMimeTypes, &accuracy );
1663  // If we used the "fast mode" (no sniffing), and we didn't get a perfect (extension-based) match,
1664  // then determineMimeType will be able to do better.
1665  const bool canDoBetter = d->m_delayedMimeTypes && accuracy < 100;
1666  //kDebug() << "finding mimetype for" << url << ":" << d->m_pMimeType->name() << "canDoBetter=" << canDoBetter;
1667  d->m_bMimeTypeKnown = !canDoBetter;
1668  }
1669  return d->m_pMimeType;
1670 }
1671 
1672 KIO::UDSEntry KFileItem::entry() const
1673 {
1674  if (!d)
1675  return KIO::UDSEntry();
1676 
1677  return d->m_entry;
1678 }
1679 
1680 bool KFileItem::isMarked() const
1681 {
1682  if (!d)
1683  return false;
1684 
1685  return d->m_bMarked;
1686 }
1687 
1688 void KFileItem::mark()
1689 {
1690  if (!d) {
1691  kWarning() << "null item";
1692  return;
1693  }
1694 
1695  d->m_bMarked = true;
1696 }
1697 
1698 void KFileItem::unmark()
1699 {
1700  if (!d) {
1701  kWarning() << "null item";
1702  return;
1703  }
1704 
1705  d->m_bMarked = false;
1706 }
1707 
1708 KFileItem& KFileItem::operator=(const KFileItem& other)
1709 {
1710  d = other.d;
1711  return *this;
1712 }
1713 
1714 bool KFileItem::isNull() const
1715 {
1716  return d == 0;
1717 }
1718 
1719 KFileItemList::KFileItemList()
1720 {
1721 }
1722 
1723 KFileItemList::KFileItemList( const QList<KFileItem> &items )
1724  : QList<KFileItem>( items )
1725 {
1726 }
1727 
1728 KFileItem KFileItemList::findByName( const QString& fileName ) const
1729 {
1730  const_iterator it = begin();
1731  const const_iterator itend = end();
1732  for ( ; it != itend ; ++it ) {
1733  if ( (*it).name() == fileName ) {
1734  return *it;
1735  }
1736  }
1737  return KFileItem();
1738 }
1739 
1740 KFileItem KFileItemList::findByUrl( const KUrl& url ) const {
1741  const_iterator it = begin();
1742  const const_iterator itend = end();
1743  for ( ; it != itend ; ++it ) {
1744  if ( (*it).url() == url ) {
1745  return *it;
1746  }
1747  }
1748  return KFileItem();
1749 }
1750 
1751 KUrl::List KFileItemList::urlList() const {
1752  KUrl::List lst;
1753  const_iterator it = begin();
1754  const const_iterator itend = end();
1755  for ( ; it != itend ; ++it ) {
1756  lst.append( (*it).url() );
1757  }
1758  return lst;
1759 }
1760 
1761 KUrl::List KFileItemList::targetUrlList() const {
1762  KUrl::List lst;
1763  const_iterator it = begin();
1764  const const_iterator itend = end();
1765  for ( ; it != itend ; ++it ) {
1766  lst.append( (*it).targetUrl() );
1767  }
1768  return lst;
1769 }
1770 
1771 
1772 bool KFileItem::isDesktopFile() const
1773 {
1774  return checkDesktopFile(*this, true);
1775 }
1776 
1777 bool KFileItem::isRegularFile() const
1778 {
1779  if (!d)
1780  return false;
1781 
1782  return S_ISREG(d->m_fileMode);
1783 }
1784 
1785 QDebug operator<<(QDebug stream, const KFileItem& item)
1786 {
1787  if (item.isNull()) {
1788  stream << "[null KFileItem]";
1789  } else {
1790  stream << "[KFileItem for" << item.url() << "]";
1791  }
1792  return stream;
1793 }
KIO::UDSEntry::UDS_URL
An alternative URL (If different from the caption).
Definition: udsentry.h:190
KFileItem::targetUrl
KUrl targetUrl() const
Returns the target url of the file, which is the same as url() in cases where the slave doesn't speci...
Definition: kfileitem.cpp:1604
i18n
QString i18n(const char *text)
ksambashare.h
KSharedPtr
Definition: kprotocolmanager.h:31
QWidget
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KFileItem::isWritable
bool isWritable() const
Checks whether the file or directory is writable.
Definition: kfileitem.cpp:1099
KFileItemList::KFileItemList
KFileItemList()
Creates an empty list of file items.
Definition: kfileitem.cpp:1719
KFileMetaInfo::isValid
bool isValid() const
Definition: kfilemetainfo.cpp:372
KUrl::RemoveTrailingSlash
KFileItem::determineMimeType
KMimeType::Ptr determineMimeType() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:779
KFileItem::operator=
KFileItem & operator=(const KFileItem &other)
Assignment operator.
Definition: kfileitem.cpp:1708
KFileMetaInfoItem
Definition: kfilemetainfoitem.h:34
KIO::UDSEntry::UDS_TARGET_URL
This file is a shortcut or mount, pointing to an URL in a different hierarchy.
Definition: udsentry.h:215
KFileSystemType::Type
Type
KFileItem::isDir
bool isDir() const
Returns true if this item represents a directory.
Definition: kfileitem.cpp:1141
KFileItem::nepomukUri
KUrl nepomukUri() const
Returns the resource URI to be used for Nepomuk annotations.
Definition: kfileitem.cpp:1616
kdebug.h
KFileItem::FileTimes
FileTimes
The timestamps associated with a file.
Definition: kfileitem.h:56
DesktopIcon
QPixmap DesktopIcon(const QString &name, int force_size, int state, const QStringList &overlays)
kmimetype.h
KFileItem::setExtraData
void setExtraData(const void *key, void *value)
This allows to associate some "extra" data to a KFileItem.
Definition: kfileitem.cpp:1371
KFileItem::getStatusBarInfo
QString getStatusBarInfo() const
Returns the string to be displayed in the statusbar, e.g.
Definition: kfileitem.cpp:1185
QColor::name
QString name() const
KIconLoader::global
static KIconLoader * global()
KIO::UDSEntry
Universal Directory Service.
Definition: udsentry.h:58
group
KFileItem::mimetype
QString mimetype() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:770
KFileItem::user
QString user() const
Returns the owner of the file.
Definition: kfileitem.cpp:681
KIO::UDSEntry::UDS_ACL_STRING
The access control list serialized into a single string.
Definition: udsentry.h:203
kmountpoint.h
KMountPoint::currentMountPoints
static List currentMountPoints(DetailsNeededFlags infoNeeded=BasicInfoNeeded)
QDataStream
KFileItem::setUDSEntry
void setUDSEntry(const KIO::UDSEntry &entry, const KUrl &url, bool delayedMimeTypes=false, bool urlIsDirectory=false)
Reinitialize KFileItem with a new UDSEntry.
Definition: kfileitem.cpp:1335
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1714
KFileItem::isFinalIconKnown
bool isFinalIconKnown() const
Definition: kfileitem.cpp:815
KFileItem::removeExtraData
void removeExtraData(const void *key)
Removes the extra data associated with an item via key.
Definition: kfileitem.cpp:1394
iconFromDesktopFile
static QString iconFromDesktopFile(const QString &path)
Definition: kfileitem.cpp:855
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QMap< const void *, void * >
KIO::UDSEntry::UDS_DEFAULT_ACL_STRING
The default access control list serialized into a single string.
Definition: udsentry.h:206
KFileItem::refresh
void refresh()
Throw away and re-read (for local files) all information about the file.
Definition: kfileitem.cpp:512
KIO::decodeFileName
QString decodeFileName(const QString &str)
Decodes (from the filename to the text displayed) This doesn't do anything anymore, it used to do the opposite of encodeFileName when encodeFileName was using %2F for '/'.
Definition: global.cpp:153
KIO::UDSEntry::UDS_FILE_TYPE
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
Definition: udsentry.h:181
KMountPoint::List::findByDevice
Ptr findByDevice(const QString &device) const
isExecutable
bool isExecutable(const QString &file)
KDE::stat
int stat(const QString &path, KDE_struct_stat *buf)
KFileItem::metaInfo
KFileMetaInfo metaInfo(bool autoget=true, int what=KFileMetaInfo::ContentInfo|KFileMetaInfo::TechnicalInfo) const
Returns the metainfo of this item.
Definition: kfileitem.cpp:1449
KConfig::SimpleConfig
KConfig::group
KConfigGroup group(const QByteArray &group)
KFileItem::setUrl
void setUrl(const KUrl &url)
Sets the item's URL.
Definition: kfileitem.cpp:543
KSambaShare::instance
static KSambaShare * instance()
Definition: ksambashare.cpp:498
kiconloader.h
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::UDSEntry::UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
Definition: udsentry.h:166
KFileItem::comment
QString comment() const
A comment which can contain anything - even rich text.
Definition: kfileitem.cpp:1005
KFileItem::setName
void setName(const QString &name)
Sets the item's name (i.e.
Definition: kfileitem.cpp:554
KFileItem::permissions
mode_t permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions).
Definition: kfileitem.cpp:1551
KFileItem::operator!=
bool operator!=(const KFileItem &other) const
Returns true if both items do not share the same URL.
Definition: kfileitem.cpp:1329
KFileShare::isDirectoryShared
bool isDirectoryShared(const QString &path)
Call this to know if a directory is currently shared.
Definition: kfileshare.cpp:216
KFileItem::isReadable
bool isReadable() const
Checks whether the file or directory is readable.
Definition: kfileitem.cpp:1069
checkDesktopFile
static bool checkDesktopFile(const KFileItem &item, bool _determineMimeType)
Returns true if this is a desktop file.
Definition: kfileitem.cpp:931
kdesktopfile.h
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KIconLoader::Desktop
KFileItem::KFileItem
KFileItem()
Null KFileItem.
Definition: kfileitem.cpp:475
KFileItem::mark
void mark()
Marks the item.
Definition: kfileitem.cpp:1688
KUrl
KIO::UDSEntry::UDS_HIDDEN
Treat the file as a hidden file (if set to 1) or as a normal file (if set to 0).
Definition: udsentry.h:169
knfsshare.h
KFileSystemType::fileSystemType
Type fileSystemType(const QString &path)
KRun
To open files with their associated applications in KDE, use KRun.
Definition: krun.h:59
KUrl::setPath
void setPath(const QString &path)
KIO::UDSEntry::UDS_COMMENT
A comment which will be displayed as is to the user.
Definition: udsentry.h:254
KIO::UDSEntry::UDS_DISPLAY_TYPE
User-readable type of file (if not specified, the mimetype's description is used) ...
Definition: udsentry.h:220
KIO::UDSEntry::UDS_GUESSED_MIME_TYPE
A mime type to be used for displaying only.
Definition: udsentry.h:196
KDesktopFile::isAuthorizedDesktopFile
static bool isAuthorizedDesktopFile(const QString &path)
KFileItemList::findByUrl
KFileItem findByUrl(const KUrl &url) const
Find a KFileItem by URL and return it.
Definition: kfileitem.cpp:1740
KFileItem::isLocalFile
bool isLocalFile() const
Returns true if the file is a local file.
Definition: kfileitem.cpp:1575
KFileItem::Unknown
Definition: kfileitem.h:48
KFileItem::isRegularFile
bool isRegularFile() const
Return true if this item is a regular file, false otherwise (directory, link, character/block device...
Definition: kfileitem.cpp:1777
kglobal.h
KIO::UDSEntry::UDS_USER
User ID of the file owner.
Definition: udsentry.h:148
QSharedData
KFileItem::ACL
KACL ACL() const
Returns the access control list for the file.
Definition: kfileitem.cpp:627
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
KIO::UDSEntry::count
int count() const
count fields
Definition: udsentry.cpp:113
QList::append
void append(const T &value)
KDesktopFile::readDevice
QString readDevice() const
QString::insert
QString & insert(int position, QChar ch)
KFileMetaInfo
KFileMetaInfo provides metadata extracted from a file or other resource.
Definition: kfilemetainfo.h:56
KFileItemList::findByName
KFileItem findByName(const QString &fileName) const
Find a KFileItem by name and return it.
Definition: kfileitem.cpp:1728
KFileItem::ModificationTime
Definition: kfileitem.h:58
KDesktopFile::hasDeviceType
bool hasDeviceType() const
KFileItem::assign
void assign(const KFileItem &item)
Definition: kfileitem.cpp:1464
KFileItem::getToolTipText
QString getToolTipText(int maxcount=6) const
Returns the string to be displayed in the tool tip when the mouse is over this item.
Definition: kfileitem.cpp:1217
KFileItem::run
void run(QWidget *parentWidget=0) const
Let's "KRun" this file ! (e.g.
Definition: kfileitem.cpp:1297
KUrl::protocol
QString protocol() const
KFileItem::localPath
QString localPath() const
Returns the local path if isLocalFile() == true or the KIO item has a UDS_LOCAL_PATH atom...
Definition: kfileitem.cpp:602
KFileItem::linkDest
QString linkDest() const
Returns the link destination if isLink() == true.
Definition: kfileitem.cpp:568
QString::isEmpty
bool isEmpty() const
KFileItem::mostLocalUrl
KUrl mostLocalUrl() const
Tries to give a local URL for this file item if possible.
Definition: kfileitem.cpp:1491
KIO::UDSEntry::UDS_ACCESS_TIME
The last time the file was opened.
Definition: udsentry.h:175
KFileItem::extraData
const void * extraData(const void *key) const
Retrieves the extra data with the given key.
Definition: kfileitem.cpp:1384
Unknown
KIconLoader::loadMimeTypeIcon
QPixmap loadMimeTypeIcon(const QString &iconName, KIconLoader::Group group, int size=0, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=0) const
KFileItem::mimeComment
QString mimeComment() const
Returns the user-readable string representing the type of this file, like "OpenDocument Text File"...
Definition: kfileitem.cpp:823
KFileItem::acceptsDrops
bool acceptsDrops() const
Returns true if files can be dropped over this item.
Definition: kfileitem.cpp:1163
KFileItem::~KFileItem
~KFileItem()
Destructs the KFileItem.
Definition: kfileitem.cpp:508
KFileItem::operator==
bool operator==(const KFileItem &other) const
Returns true if both items share the same URL.
Definition: kfileitem.cpp:1318
KFileItem::isFile
bool isFile() const
Returns true if this item represents a file (and not a a directory)
Definition: kfileitem.cpp:1154
QString
KFileItem::group
QString group() const
Returns the group of the file.
Definition: kfileitem.cpp:712
QList< KFileItem >
KDesktopFile::readUrl
QString readUrl() const
KFileItem::size
KIO::filesize_t size() const
Returns the size of the file, if known.
Definition: kfileitem.cpp:610
QApplication::palette
QPalette palette()
KFileItem::iconName
QString iconName() const
Returns the full path name to the icon that represents this mime type.
Definition: kfileitem.cpp:879
KFileItem::permissionsString
QString permissionsString() const
Returns the access permissions for the file as a string.
Definition: kfileitem.cpp:1403
KFileItem::refreshMimeType
void refreshMimeType()
Re-reads mimetype information.
Definition: kfileitem.cpp:533
QStringList
QPixmap
KIO::UDSEntry::UDS_MODIFICATION_TIME
The last time the file was modified.
Definition: udsentry.h:173
KDesktopFile::hasLinkType
bool hasLinkType() const
KFileItem::text
QString text() const
Returns the text of the file item.
Definition: kfileitem.cpp:1583
QFileInfo
QList::end
iterator end()
KFileItem::isDesktopFile
bool isDesktopFile() const
Checks whether the file is a readable local .desktop file, i.e.
Definition: kfileitem.cpp:1772
KFileItem::isLink
bool isLink() const
Returns true if this item represents a link in the UNIX sense of a link.
Definition: kfileitem.cpp:1567
QPixmap::isNull
bool isNull() const
KIO::UDSEntry::UDS_ICON_OVERLAY_NAMES
A comma-separated list of supplementary icon overlays which will be added to the list of overlays cre...
Definition: udsentry.h:241
KFileMetaInfoItem::isValid
bool isValid() const
Is this a valid item.
Definition: kfilemetainfoitem.cpp:95
KDateTime
KDesktopFile
KLocale::formatDateTime
QString formatDateTime(const QDateTime &dateTime, DateFormat format=ShortDate, bool includeSecs=false) const
KDE::lstat
int lstat(const QString &path, KDE_struct_stat *buf)
KConfigGroup::hasKey
bool hasKey(const QString &key) const
QDebug
KFileMetaInfo::What
What
This is used to specify what a KFileMetaInfo object should read, so you can specify if you want to re...
Definition: kfilemetainfo.h:64
KFileItem::mimeTypePtr
KMimeType::Ptr mimeTypePtr() const
Returns the currently known mimetype of the file item.
Definition: kfileitem.cpp:1649
KGlobal::locale
KLocale * locale()
KConfigGroup
KUrl::List
krun.h
KConfig
kfilemetainfo.h
kfilesystemtype_p.h
KFileItem::hasExtendedACL
bool hasExtendedACL() const
Tells if the file has extended access level information ( Posix ACL )
Definition: kfileitem.cpp:618
KFileSystemType::Nfs
KFileItem::time
KDateTime time(FileTimes which) const
Requests the modification, access or creation time, depending on which.
Definition: kfileitem.cpp:655
QLatin1String
KIO::UDSEntry::UDS_ACCESS
Access permissions (part of the mode returned by stat)
Definition: udsentry.h:171
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
KFileItem::defaultACL
KACL defaultACL() const
Returns the default access control list for the directory.
Definition: kfileitem.cpp:642
KNFSShare::isDirectoryShared
bool isDirectoryShared(const QString &path) const
Whether or not the given path is shared by NFS.
Definition: knfsshare.cpp:185
Qt::escape
QString escape(const QString &plain)
KDE::access
int access(const QString &path, int mode)
KFileMetaInfo::item
KFileMetaInfoItem & item(const QString &key)
Definition: kfilemetainfo.cpp:367
KFileItem::isMarked
bool isMarked() const
Used when updating a directory.
Definition: kfileitem.cpp:1680
KFileItem::name
QString name(bool lowerCase=false) const
Return the name of the file item (without a path).
Definition: kfileitem.cpp:1591
KIO::UDSEntry::UDS_NAME
Filename - as displayed in directory listings etc.
Definition: udsentry.h:163
KACL
The KACL class encapsulates a POSIX Access Control List.
Definition: kacl.h:47
KIO::UDSEntry::UDS_LINK_DEST
Name of the file where the link points to Allows to check for a symlink (don't use S_ISLNK !) ...
Definition: udsentry.h:184
KFileItem::CreationTime
Definition: kfileitem.h:60
QList::ConstIterator
typedef ConstIterator
KFileItem::cmp
bool cmp(const KFileItem &item) const
Somewhat like a comparison operator, but more explicit, and it can detect that two fileitems differ i...
Definition: kfileitem.cpp:1307
KIO::UDSEntry::UDS_CREATION_TIME
The time the file was created.
Definition: udsentry.h:177
KFileItem::isHidden
bool isHidden() const
Checks whether the file is hidden.
Definition: kfileitem.cpp:1125
QString::length
int length() const
KIO::UDSEntry::UDS_GROUP
Group ID of the file owner.
Definition: udsentry.h:153
KFileItem::unmark
void unmark()
Unmarks the item.
Definition: kfileitem.cpp:1698
KFileSystemType::Smb
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KFileItem::timeString
QString timeString(FileTimes which=ModificationTime) const
Requests the modification, access or creation time as a string, depending on which.
Definition: kfileitem.cpp:1415
KIO::UDSEntry::UDS_DISPLAY_NAME
If set, contains the label to display instead of the 'real name' in UDS_NAME.
Definition: udsentry.h:211
KDesktopFile::readIcon
QString readIcon() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KFileItem::mode
mode_t mode() const
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).
Definition: kfileitem.cpp:1559
KDesktopFile::readPath
QString readPath() const
KIO::UDSEntry::UDS_EXTENDED_ACL
Indicates that the entry has extended ACL entries.
Definition: udsentry.h:201
KIO::UDSEntry::UDS_MIME_TYPE
A mime type; the slave should set it if it's known.
Definition: udsentry.h:192
KFileMetaInfoItem::name
const QString & name() const
Localized name of the predicate.
Definition: kfilemetainfoitem.cpp:54
KGlobal::staticQString
const QString & staticQString(const char *str)
KFileItem::isMimeTypeKnown
bool isMimeTypeKnown() const
Definition: kfileitem.cpp:804
KFileItem::isSlow
bool isSlow() const
Definition: kfileitem.cpp:762
KFileItem::entry
KIO::UDSEntry entry() const
Returns the UDS entry.
Definition: kfileitem.cpp:1672
KUrl::isLocalFile
bool isLocalFile() const
KFileMetaInfo::preferredKeys
QStringList preferredKeys() const
Deprecated.
Definition: kfilemetainfo.cpp:377
KNFSShare::instance
static KNFSShare * instance()
Returns the one and only instance of KNFSShare.
Definition: knfsshare.cpp:216
KIO::convertSize
QString convertSize(KIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53
end
const KShortcut & end()
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
KFileItem::setMetaInfo
void setMetaInfo(const KFileMetaInfo &info) const
Sets the metainfo of this item to info.
Definition: kfileitem.cpp:1441
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
operator>>
QDataStream & operator>>(QDataStream &s, KFileItem &a)
Definition: kfileitem.cpp:1514
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
KIO::UDSEntry::UDS_SIZE
Size of the file.
Definition: udsentry.h:144
QList::begin
iterator begin()
kfileitem.h
KFileItemList::urlList
KUrl::List urlList() const
Definition: kfileitem.cpp:1751
KFileItem::overlays
QStringList overlays() const
Returns the overlays (bitfield of KIconLoader::*Overlay flags) that are used for this item's pixmap...
Definition: kfileitem.cpp:952
KFileItem::url
KUrl url() const
Returns the url of the file.
Definition: kfileitem.cpp:1543
QFile::encodeName
QByteArray encodeName(const QString &fileName)
QFile::decodeName
QString decodeName(const QByteArray &localFileName)
KIO::UDSEntry::UDS_NEPOMUK_URI
The URI of the corresponding Nepomuk resource.
Definition: udsentry.h:234
KFileItem::mostLocalUrl
KUrl mostLocalUrl(bool &local) const
Tries to give a local URL for this file item if possible.
Definition: kfileitem.cpp:1470
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:45
kconfiggroup.h
KFileItem::pixmap
QPixmap pixmap(int _size, int _state=0) const
Returns a pixmap representing the file.
Definition: kfileitem.cpp:1014
KIO::UDSEntry::UDS_ICON_NAME
Name of the icon, that should be used for displaying.
Definition: udsentry.h:151
KFileItemList::targetUrlList
KUrl::List targetUrlList() const
Definition: kfileitem.cpp:1761
KFileItem::AccessTime
Definition: kfileitem.h:59
KFileMetaInfoItem::value
const QVariant & value() const
Retrieve the current value of this item.
Definition: kfilemetainfoitem.cpp:66
QVariant
operator<<
QDataStream & operator<<(QDataStream &s, const KFileItem &a)
Definition: kfileitem.cpp:1497
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal