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

KIO

  • sources
  • kde-4.12
  • 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 );
260  m_permissions = m_entry.numberValue( KIO::UDSEntry::UDS_ACCESS );
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 ( !S_ISDIR( d->m_fileMode ) // Locked dirs have a special icon, use the overlay for files only
963  && !isReadable()) {
964  names.append("object-locked");
965  }
966 
967  if ( checkDesktopFile(*this, false) ) {
968  KDesktopFile cfg( localPath() );
969  const KConfigGroup group = cfg.desktopGroup();
970 
971  // Add a warning emblem if this is an executable desktop file
972  // which is untrusted.
973  if ( group.hasKey( "Exec" ) && !KDesktopFile::isAuthorizedDesktopFile( localPath() ) ) {
974  names.append( "emblem-important" );
975  }
976 
977  if (cfg.hasDeviceType()) {
978  const QString dev = cfg.readDevice();
979  if (!dev.isEmpty()) {
980  KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByDevice(dev);
981  if (mountPoint) // mounted?
982  names.append("emblem-mounted");
983  }
984  }
985  }
986 
987  if ( isHidden() ) {
988  names.append("hidden");
989  }
990 
991 #ifndef Q_OS_WIN
992  if( S_ISDIR( d->m_fileMode ) && d->m_bIsLocalUrl)
993  {
994  if (KSambaShare::instance()->isDirectoryShared( d->m_url.toLocalFile() ) ||
995  KNFSShare::instance()->isDirectoryShared( d->m_url.toLocalFile() ))
996  {
997  //kDebug() << d->m_url.path();
998  names.append("network-workgroup");
999  }
1000  }
1001 #endif // Q_OS_WIN
1002 
1003  if ( d->m_pMimeType && d->m_url.fileName().endsWith( QLatin1String( ".gz" ) ) &&
1004  d->m_pMimeType->is("application/x-gzip") ) {
1005  names.append("application-zip");
1006  }
1007 
1008  return names;
1009 }
1010 
1011 QString KFileItem::comment() const
1012 {
1013  if (!d)
1014  return QString();
1015 
1016  return d->m_entry.stringValue( KIO::UDSEntry::UDS_COMMENT );
1017 }
1018 
1019 // ## where is this used?
1020 QPixmap KFileItem::pixmap( int _size, int _state ) const
1021 {
1022  if (!d)
1023  return QPixmap();
1024 
1025  const QString iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME );
1026  if ( !iconName.isEmpty() )
1027  return DesktopIcon(iconName, _size, _state);
1028 
1029  if (!d->m_pMimeType) {
1030  // No mimetype determined yet, go for a fast default icon
1031  if (S_ISDIR(d->m_fileMode)) {
1032  static const QString * defaultFolderIcon = 0;
1033  if ( !defaultFolderIcon ) {
1034  const KMimeType::Ptr mimeType = KMimeType::mimeType( "inode/directory" );
1035  if ( mimeType )
1036  defaultFolderIcon = &KGlobal::staticQString( mimeType->iconName() );
1037  else
1038  kWarning(7000) << "No mimetype for inode/directory could be found. Check your installation.";
1039  }
1040  if ( defaultFolderIcon )
1041  return DesktopIcon( *defaultFolderIcon, _size, _state );
1042 
1043  }
1044  return DesktopIcon( "unknown", _size, _state );
1045  }
1046 
1047  KMimeType::Ptr mime;
1048  // Use guessed mimetype for the icon
1049  if (!d->m_guessedMimeType.isEmpty())
1050  mime = KMimeType::mimeType( d->m_guessedMimeType );
1051  else
1052  mime = d->m_pMimeType;
1053 
1054  // Support for gzipped files: extract mimetype of contained file
1055  // See also the relevant code in overlays, which adds the zip overlay.
1056  if ( mime->name() == "application/x-gzip" && d->m_url.fileName().endsWith( QLatin1String( ".gz" ) ) )
1057  {
1058  KUrl sf;
1059  sf.setPath( d->m_url.path().left( d->m_url.path().length() - 3 ) );
1060  //kDebug() << "subFileName=" << subFileName;
1061  mime = KMimeType::findByUrl( sf, 0, d->m_bIsLocalUrl );
1062  }
1063 
1064  bool isLocalUrl;
1065  KUrl url = mostLocalUrl(isLocalUrl);
1066 
1067  QPixmap p = KIconLoader::global()->loadMimeTypeIcon( mime->iconName( url ), KIconLoader::Desktop, _size, _state );
1068  //kDebug() << "finding pixmap for " << url.url() << " : " << mime->name();
1069  if (p.isNull())
1070  kWarning() << "Pixmap not found for mimetype " << d->m_pMimeType->name();
1071 
1072  return p;
1073 }
1074 
1075 bool KFileItem::isReadable() const
1076 {
1077  if (!d)
1078  return false;
1079 
1080  /*
1081  struct passwd * user = getpwuid( geteuid() );
1082  bool isMyFile = (QString::fromLocal8Bit(user->pw_name) == d->m_user);
1083  // This gets ugly for the group....
1084  // Maybe we want a static QString for the user and a static QStringList
1085  // for the groups... then we need to handle the deletion properly...
1086  */
1087 
1088  if (d->m_permissions != KFileItem::Unknown) {
1089  // No read permission at all
1090  if ( !(S_IRUSR & d->m_permissions) && !(S_IRGRP & d->m_permissions) && !(S_IROTH & d->m_permissions) )
1091  return false;
1092 
1093  // Read permissions for all: save a stat call
1094  if ( (S_IRUSR|S_IRGRP|S_IROTH) & d->m_permissions )
1095  return true;
1096  }
1097 
1098  // Or if we can't read it [using ::access()] - not network transparent
1099  if ( d->m_bIsLocalUrl && KDE::access( d->m_url.toLocalFile(), R_OK ) == -1 )
1100  return false;
1101 
1102  return true;
1103 }
1104 
1105 bool KFileItem::isWritable() const
1106 {
1107  if (!d)
1108  return false;
1109 
1110  /*
1111  struct passwd * user = getpwuid( geteuid() );
1112  bool isMyFile = (QString::fromLocal8Bit(user->pw_name) == d->m_user);
1113  // This gets ugly for the group....
1114  // Maybe we want a static QString for the user and a static QStringList
1115  // for the groups... then we need to handle the deletion properly...
1116  */
1117 
1118  if (d->m_permissions != KFileItem::Unknown) {
1119  // No write permission at all
1120  if ( !(S_IWUSR & d->m_permissions) && !(S_IWGRP & d->m_permissions) && !(S_IWOTH & d->m_permissions) )
1121  return false;
1122  }
1123 
1124  // Or if we can't read it [using ::access()] - not network transparent
1125  if ( d->m_bIsLocalUrl && KDE::access( d->m_url.toLocalFile(), W_OK ) == -1 )
1126  return false;
1127 
1128  return true;
1129 }
1130 
1131 bool KFileItem::isHidden() const
1132 {
1133  if (!d)
1134  return false;
1135 
1136  // The kioslave can specify explicitly that a file is hidden or shown
1137  if ( d->m_hidden != KFileItemPrivate::Auto )
1138  return d->m_hidden == KFileItemPrivate::Hidden;
1139 
1140  // Prefer the filename that is part of the URL, in case the display name is different.
1141  QString fileName = d->m_url.fileName();
1142  if (fileName.isEmpty()) // e.g. "trash:/"
1143  fileName = d->m_strName;
1144  return fileName.length() > 1 && fileName[0] == '.'; // Just "." is current directory, not hidden.
1145 }
1146 
1147 bool KFileItem::isDir() const
1148 {
1149  if (!d)
1150  return false;
1151 
1152  if (d->m_fileMode == KFileItem::Unknown) {
1153  // Probably the file was deleted already, and KDirLister hasn't told the world yet.
1154  //kDebug() << d << url() << "can't say -> false";
1155  return false; // can't say for sure, so no
1156  }
1157  return (S_ISDIR(d->m_fileMode));
1158 }
1159 
1160 bool KFileItem::isFile() const
1161 {
1162  if (!d)
1163  return false;
1164 
1165  return !isDir();
1166 }
1167 
1168 #ifndef KDE_NO_DEPRECATED
1169 bool KFileItem::acceptsDrops() const
1170 {
1171  // A directory ?
1172  if ( S_ISDIR( mode() ) ) {
1173  return isWritable();
1174  }
1175 
1176  // But only local .desktop files and executables
1177  if ( !d->m_bIsLocalUrl )
1178  return false;
1179 
1180  if ( mimetype() == "application/x-desktop")
1181  return true;
1182 
1183  // Executable, shell script ... ?
1184  if ( QFileInfo(d->m_url.toLocalFile()).isExecutable() )
1185  return true;
1186 
1187  return false;
1188 }
1189 #endif
1190 
1191 QString KFileItem::getStatusBarInfo() const
1192 {
1193  if (!d)
1194  return QString();
1195 
1196  QString text = d->m_strText;
1197  const QString comment = mimeComment();
1198 
1199  if ( d->m_bLink )
1200  {
1201  text += ' ';
1202  if ( comment.isEmpty() )
1203  text += i18n ( "(Symbolic Link to %1)", linkDest() );
1204  else
1205  text += i18n("(%1, Link to %2)", comment, linkDest());
1206  }
1207  else if ( targetUrl() != url() )
1208  {
1209  text += i18n ( " (Points to %1)", targetUrl().pathOrUrl());
1210  }
1211  else if ( S_ISREG( d->m_fileMode ) )
1212  {
1213  text += QString(" (%1, %2)").arg( comment, KIO::convertSize( size() ) );
1214  }
1215  else
1216  {
1217  text += QString(" (%1)").arg( comment );
1218  }
1219  return text;
1220 }
1221 
1222 #ifndef KDE_NO_DEPRECATED
1223 QString KFileItem::getToolTipText(int maxcount) const
1224 {
1225  if (!d)
1226  return QString();
1227 
1228  // we can return QString() if no tool tip should be shown
1229  QString tip;
1230  KFileMetaInfo info = metaInfo();
1231 
1232  // the font tags are a workaround for the fact that the tool tip gets
1233  // screwed if the color scheme uses white as default text color
1234  const QString colorName = QApplication::palette().color(QPalette::ToolTipText).name();
1235  const QString start = "<tr><td align=\"right\"><nobr><font color=\"" + colorName + "\"><b>";
1236  const QString mid = "&nbsp;</b></font></nobr></td><td><nobr><font color=\"" + colorName + "\">";
1237  const char* end = "</font></nobr></td></tr>";
1238 
1239  tip = "<table cellspacing=0 cellpadding=0>";
1240 
1241  tip += start + i18n("Name:") + mid + text() + end;
1242  tip += start + i18n("Type:") + mid;
1243 
1244  QString type = Qt::escape(mimeComment());
1245  if ( d->m_bLink ) {
1246  tip += i18n("Link to %1 (%2)", linkDest(), type) + end;
1247  } else
1248  tip += type + end;
1249 
1250  if ( !S_ISDIR ( d->m_fileMode ) )
1251  tip += start + i18n("Size:") + mid +
1252  QString("%1").arg(KIO::convertSize(size())) +
1253  end;
1254 
1255  tip += start + i18n("Modified:") + mid +
1256  timeString( KFileItem::ModificationTime ) + end
1257 #ifndef Q_WS_WIN //TODO: show win32-specific permissions
1258  +start + i18n("Owner:") + mid + user() + " - " + group() + end +
1259  start + i18n("Permissions:") + mid +
1260  permissionsString() + end
1261 #endif
1262  ;
1263 
1264  if (info.isValid())
1265  {
1266  const QStringList keys = info.preferredKeys();
1267 
1268  // now the rest
1269  QStringList::ConstIterator it = keys.begin();
1270  for (int count = 0; count<maxcount && it!=keys.end() ; ++it)
1271  {
1272  if ( count == 0 )
1273  {
1274  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>";
1275  }
1276 
1277  KFileMetaInfoItem item = info.item( *it );
1278  if ( item.isValid() )
1279  {
1280  QString s = item.value().toString();
1281  if ( !s.isEmpty() )
1282  {
1283  count++;
1284  tip += start +
1285  Qt::escape( item.name() ) + ':' +
1286  mid +
1287  Qt::escape( s ) +
1288  end;
1289  }
1290 
1291  }
1292  }
1293  }
1294  tip += "</table>";
1295 
1296  //kDebug() << "making this the tool tip rich text:\n";
1297  //kDebug() << tip;
1298 
1299  return tip;
1300 }
1301 #endif
1302 
1303 void KFileItem::run( QWidget* parentWidget ) const
1304 {
1305  if (!d) {
1306  kWarning() << "null item";
1307  return;
1308  }
1309 
1310  (void) new KRun( targetUrl(), parentWidget, d->m_fileMode, d->m_bIsLocalUrl );
1311 }
1312 
1313 bool KFileItem::cmp( const KFileItem & item ) const
1314 {
1315  if (!d && !item.d)
1316  return true;
1317 
1318  if (!d || !item.d)
1319  return false;
1320 
1321  return d->cmp(*item.d);
1322 }
1323 
1324 bool KFileItem::operator==(const KFileItem& other) const
1325 {
1326  if (!d && !other.d)
1327  return true;
1328 
1329  if (!d || !other.d)
1330  return false;
1331 
1332  return d->m_url == other.d->m_url;
1333 }
1334 
1335 bool KFileItem::operator!=(const KFileItem& other) const
1336 {
1337  return !operator==(other);
1338 }
1339 
1340 #ifndef KDE_NO_DEPRECATED
1341 void KFileItem::setUDSEntry( const KIO::UDSEntry& _entry, const KUrl& _url,
1342  bool _delayedMimeTypes, bool _urlIsDirectory )
1343 {
1344  if (!d)
1345  return;
1346 
1347  d->m_entry = _entry;
1348  d->m_url = _url;
1349  d->m_strName.clear();
1350  d->m_strText.clear();
1351  d->m_iconName.clear();
1352  d->m_strLowerCaseName.clear();
1353  d->m_pMimeType = 0;
1354  d->m_fileMode = KFileItem::Unknown;
1355  d->m_permissions = KFileItem::Unknown;
1356  d->m_bMarked = false;
1357  d->m_bLink = false;
1358  d->m_bIsLocalUrl = _url.isLocalFile();
1359  d->m_bMimeTypeKnown = false;
1360  d->m_hidden = KFileItemPrivate::Auto;
1361  d->m_guessedMimeType.clear();
1362  d->m_metaInfo = KFileMetaInfo();
1363  d->m_delayedMimeTypes = _delayedMimeTypes;
1364  d->m_useIconNameCache = false;
1365 
1366  d->readUDSEntry( _urlIsDirectory );
1367  d->init();
1368 }
1369 #endif
1370 
1371 KFileItem::operator QVariant() const
1372 {
1373  return qVariantFromValue(*this);
1374 }
1375 
1376 #ifndef KDE_NO_DEPRECATED
1377 void KFileItem::setExtraData( const void *key, void *value )
1378 {
1379  if (!d)
1380  return;
1381 
1382  if ( !key )
1383  return;
1384 
1385  d->m_extra.insert( key, value ); // replaces the value of key if already there
1386 }
1387 #endif
1388 
1389 #ifndef KDE_NO_DEPRECATED
1390 const void * KFileItem::extraData( const void *key ) const
1391 {
1392  if (!d)
1393  return 0;
1394 
1395  return d->m_extra.value( key, 0 );
1396 }
1397 #endif
1398 
1399 #ifndef KDE_NO_DEPRECATED
1400 void KFileItem::removeExtraData( const void *key )
1401 {
1402  if (!d)
1403  return;
1404 
1405  d->m_extra.remove( key );
1406 }
1407 #endif
1408 
1409 QString KFileItem::permissionsString() const
1410 {
1411  if (!d)
1412  return QString();
1413 
1414  if (d->m_access.isNull() && d->m_permissions != KFileItem::Unknown)
1415  d->m_access = d->parsePermissions( d->m_permissions );
1416 
1417  return d->m_access;
1418 }
1419 
1420 // check if we need to cache this
1421 QString KFileItem::timeString( FileTimes which ) const
1422 {
1423  if (!d)
1424  return QString();
1425 
1426  return KGlobal::locale()->formatDateTime( d->time(which) );
1427 }
1428 
1429 #ifndef KDE_NO_DEPRECATED
1430 QString KFileItem::timeString( unsigned int which ) const
1431 {
1432  if (!d)
1433  return QString();
1434 
1435  switch (which) {
1436  case KIO::UDSEntry::UDS_ACCESS_TIME:
1437  return timeString(AccessTime);
1438  case KIO::UDSEntry::UDS_CREATION_TIME:
1439  return timeString(CreationTime);
1440  case KIO::UDSEntry::UDS_MODIFICATION_TIME:
1441  default:
1442  return timeString(ModificationTime);
1443  }
1444 }
1445 #endif
1446 
1447 void KFileItem::setMetaInfo( const KFileMetaInfo & info ) const
1448 {
1449  if (!d)
1450  return;
1451 
1452  d->m_metaInfo = info;
1453 }
1454 
1455 KFileMetaInfo KFileItem::metaInfo(bool autoget, int what) const
1456 {
1457  if (!d)
1458  return KFileMetaInfo();
1459 
1460  if ((isRegularFile() || isDir()) && autoget && !d->m_metaInfo.isValid())
1461  {
1462  bool isLocalUrl;
1463  KUrl url(mostLocalUrl(isLocalUrl));
1464  d->m_metaInfo = KFileMetaInfo(url.toLocalFile(), mimetype(), (KFileMetaInfo::What)what);
1465  }
1466  return d->m_metaInfo;
1467 }
1468 
1469 #ifndef KDE_NO_DEPRECATED
1470 void KFileItem::assign( const KFileItem & item )
1471 {
1472  *this = item;
1473 }
1474 #endif
1475 
1476 KUrl KFileItem::mostLocalUrl(bool &local) const
1477 {
1478  if (!d)
1479  return KUrl();
1480 
1481  QString local_path = localPath();
1482 
1483  if ( !local_path.isEmpty() )
1484  {
1485  local = true;
1486  KUrl url;
1487  url.setPath(local_path);
1488  return url;
1489  }
1490  else
1491  {
1492  local = d->m_bIsLocalUrl;
1493  return d->m_url;
1494  }
1495 }
1496 
1497 KUrl KFileItem::mostLocalUrl() const
1498 {
1499  bool local = false;
1500  return mostLocalUrl(local);
1501 }
1502 
1503 QDataStream & operator<< ( QDataStream & s, const KFileItem & a )
1504 {
1505  if (a.d) {
1506  // We don't need to save/restore anything that refresh() invalidates,
1507  // since that means we can re-determine those by ourselves.
1508  s << a.d->m_url;
1509  s << a.d->m_strName;
1510  s << a.d->m_strText;
1511  } else {
1512  s << KUrl();
1513  s << QString();
1514  s << QString();
1515  }
1516 
1517  return s;
1518 }
1519 
1520 QDataStream & operator>> ( QDataStream & s, KFileItem & a )
1521 {
1522  KUrl url;
1523  QString strName, strText;
1524 
1525  s >> url;
1526  s >> strName;
1527  s >> strText;
1528 
1529  if (!a.d) {
1530  kWarning() << "null item";
1531  return s;
1532  }
1533 
1534  if (url.isEmpty()) {
1535  a.d = 0;
1536  return s;
1537  }
1538 
1539  a.d->m_url = url;
1540  a.d->m_strName = strName;
1541  a.d->m_strText = strText;
1542  a.d->m_bIsLocalUrl = a.d->m_url.isLocalFile();
1543  a.d->m_bMimeTypeKnown = false;
1544  a.refresh();
1545 
1546  return s;
1547 }
1548 
1549 KUrl KFileItem::url() const
1550 {
1551  if (!d)
1552  return KUrl();
1553 
1554  return d->m_url;
1555 }
1556 
1557 mode_t KFileItem::permissions() const
1558 {
1559  if (!d)
1560  return 0;
1561 
1562  return d->m_permissions;
1563 }
1564 
1565 mode_t KFileItem::mode() const
1566 {
1567  if (!d)
1568  return 0;
1569 
1570  return d->m_fileMode;
1571 }
1572 
1573 bool KFileItem::isLink() const
1574 {
1575  if (!d)
1576  return false;
1577 
1578  return d->m_bLink;
1579 }
1580 
1581 bool KFileItem::isLocalFile() const
1582 {
1583  if (!d)
1584  return false;
1585 
1586  return d->m_bIsLocalUrl;
1587 }
1588 
1589 QString KFileItem::text() const
1590 {
1591  if (!d)
1592  return QString();
1593 
1594  return d->m_strText;
1595 }
1596 
1597 QString KFileItem::name( bool lowerCase ) const
1598 {
1599  if (!d)
1600  return QString();
1601 
1602  if ( !lowerCase )
1603  return d->m_strName;
1604  else
1605  if ( d->m_strLowerCaseName.isNull() )
1606  d->m_strLowerCaseName = d->m_strName.toLower();
1607  return d->m_strLowerCaseName;
1608 }
1609 
1610 KUrl KFileItem::targetUrl() const
1611 {
1612  if (!d)
1613  return KUrl();
1614 
1615  const QString targetUrlStr = d->m_entry.stringValue( KIO::UDSEntry::UDS_TARGET_URL );
1616  if (!targetUrlStr.isEmpty())
1617  return KUrl(targetUrlStr);
1618  else
1619  return url();
1620 }
1621 
1622 KUrl KFileItem::nepomukUri() const
1623 {
1624 #ifndef KIO_NO_NEPOMUK
1625  if (!d)
1626  return KUrl();
1627 
1628  const QString nepomukUriStr = d->m_entry.stringValue( KIO::UDSEntry::UDS_NEPOMUK_URI );
1629  if(!nepomukUriStr.isEmpty()) {
1630  return KUrl(nepomukUriStr);
1631  }
1632  else if(targetUrl().isLocalFile()) {
1633  return targetUrl();
1634  }
1635  else {
1636  return KUrl();
1637  }
1638 #else
1639  return KUrl();
1640 #endif
1641 }
1642 
1643 /*
1644  * Mimetype handling.
1645  *
1646  * Initial state: m_pMimeType = 0.
1647  * When mimeTypePtr() is called first: fast mimetype determination,
1648  * might either find an accurate mimetype (-> Final state), otherwise we
1649  * set m_pMimeType but not m_bMimeTypeKnown (-> Intermediate state)
1650  * Intermediate state: determineMimeType() does the real determination -> Final state.
1651  *
1652  * If delayedMimeTypes isn't set, then we always go to the Final state directly.
1653  */
1654 
1655 KMimeType::Ptr KFileItem::mimeTypePtr() const
1656 {
1657  if (!d)
1658  return KMimeType::Ptr();
1659 
1660  if (!d->m_pMimeType) {
1661  // On-demand fast (but not always accurate) mimetype determination
1662  Q_ASSERT(!d->m_url.isEmpty());
1663  bool isLocalUrl;
1664  KUrl url = mostLocalUrl(isLocalUrl);
1665  int accuracy;
1666  d->m_pMimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl,
1667  // use fast mode if delayed mimetype determination can refine it later
1668  d->m_delayedMimeTypes, &accuracy );
1669  // If we used the "fast mode" (no sniffing), and we didn't get a perfect (extension-based) match,
1670  // then determineMimeType will be able to do better.
1671  const bool canDoBetter = d->m_delayedMimeTypes && accuracy < 100;
1672  //kDebug() << "finding mimetype for" << url << ":" << d->m_pMimeType->name() << "canDoBetter=" << canDoBetter;
1673  d->m_bMimeTypeKnown = !canDoBetter;
1674  }
1675  return d->m_pMimeType;
1676 }
1677 
1678 KIO::UDSEntry KFileItem::entry() const
1679 {
1680  if (!d)
1681  return KIO::UDSEntry();
1682 
1683  return d->m_entry;
1684 }
1685 
1686 bool KFileItem::isMarked() const
1687 {
1688  if (!d)
1689  return false;
1690 
1691  return d->m_bMarked;
1692 }
1693 
1694 void KFileItem::mark()
1695 {
1696  if (!d) {
1697  kWarning() << "null item";
1698  return;
1699  }
1700 
1701  d->m_bMarked = true;
1702 }
1703 
1704 void KFileItem::unmark()
1705 {
1706  if (!d) {
1707  kWarning() << "null item";
1708  return;
1709  }
1710 
1711  d->m_bMarked = false;
1712 }
1713 
1714 KFileItem& KFileItem::operator=(const KFileItem& other)
1715 {
1716  d = other.d;
1717  return *this;
1718 }
1719 
1720 bool KFileItem::isNull() const
1721 {
1722  return d == 0;
1723 }
1724 
1725 KFileItemList::KFileItemList()
1726 {
1727 }
1728 
1729 KFileItemList::KFileItemList( const QList<KFileItem> &items )
1730  : QList<KFileItem>( items )
1731 {
1732 }
1733 
1734 KFileItem KFileItemList::findByName( const QString& fileName ) const
1735 {
1736  const_iterator it = begin();
1737  const const_iterator itend = end();
1738  for ( ; it != itend ; ++it ) {
1739  if ( (*it).name() == fileName ) {
1740  return *it;
1741  }
1742  }
1743  return KFileItem();
1744 }
1745 
1746 KFileItem KFileItemList::findByUrl( const KUrl& url ) const {
1747  const_iterator it = begin();
1748  const const_iterator itend = end();
1749  for ( ; it != itend ; ++it ) {
1750  if ( (*it).url() == url ) {
1751  return *it;
1752  }
1753  }
1754  return KFileItem();
1755 }
1756 
1757 KUrl::List KFileItemList::urlList() const {
1758  KUrl::List lst;
1759  const_iterator it = begin();
1760  const const_iterator itend = end();
1761  for ( ; it != itend ; ++it ) {
1762  lst.append( (*it).url() );
1763  }
1764  return lst;
1765 }
1766 
1767 KUrl::List KFileItemList::targetUrlList() const {
1768  KUrl::List lst;
1769  const_iterator it = begin();
1770  const const_iterator itend = end();
1771  for ( ; it != itend ; ++it ) {
1772  lst.append( (*it).targetUrl() );
1773  }
1774  return lst;
1775 }
1776 
1777 
1778 bool KFileItem::isDesktopFile() const
1779 {
1780  return checkDesktopFile(*this, true);
1781 }
1782 
1783 bool KFileItem::isRegularFile() const
1784 {
1785  if (!d)
1786  return false;
1787 
1788  return S_ISREG(d->m_fileMode);
1789 }
1790 
1791 QDebug operator<<(QDebug stream, const KFileItem& item)
1792 {
1793  if (item.isNull()) {
1794  stream << "[null KFileItem]";
1795  } else {
1796  stream << "[KFileItem for" << item.url() << "]";
1797  }
1798  return stream;
1799 }
KIO::UDSEntry::UDS_URL
An alternative URL (If different from the caption).
Definition: udsentry.h:190
QVariant
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:1610
i18n
QString i18n(const char *text)
ksambashare.h
KSharedPtr
Definition: kprotocolmanager.h:31
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:1105
KFileItemList::KFileItemList
KFileItemList()
Creates an empty list of file items.
Definition: kfileitem.cpp:1725
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:1714
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:1147
KFileItem::nepomukUri
KUrl nepomukUri() const
Returns the resource URI to be used for Nepomuk annotations.
Definition: kfileitem.cpp:1622
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:1377
KFileItem::getStatusBarInfo
QString getStatusBarInfo() const
Returns the string to be displayed in the statusbar, e.g.
Definition: kfileitem.cpp:1191
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)
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:1341
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1720
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:1400
iconFromDesktopFile
static QString iconFromDesktopFile(const QString &path)
Definition: kfileitem.cpp:855
QWidget
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:1455
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:1011
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:1557
KFileItem::operator!=
bool operator!=(const KFileItem &other) const
Returns true if both items do not share the same URL.
Definition: kfileitem.cpp:1335
KFileShare::isDirectoryShared
bool isDirectoryShared(const QString &path)
Call this to know if a directory is currently shared.
Definition: kfileshare.cpp:216
QString
KFileItem::isReadable
bool isReadable() const
Checks whether the file or directory is readable.
Definition: kfileitem.cpp:1075
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:1694
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:1746
KFileItem::isLocalFile
bool isLocalFile() const
Returns true if the file is a local file.
Definition: kfileitem.cpp:1581
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:1783
kglobal.h
KIO::UDSEntry::UDS_USER
User ID of the file owner.
Definition: udsentry.h:148
KFileItem::ACL
KACL ACL() const
Returns the access control list for the file.
Definition: kfileitem.cpp:627
KIO::UDSEntry::count
int count() const
count fields
Definition: udsentry.cpp:113
KDesktopFile::readDevice
QString readDevice() const
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:1734
KFileItem::ModificationTime
Definition: kfileitem.h:58
KDesktopFile::hasDeviceType
bool hasDeviceType() const
KFileItem::assign
void assign(const KFileItem &item)
Definition: kfileitem.cpp:1470
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:1223
KFileItem::run
void run(QWidget *parentWidget=0) const
Let's "KRun" this file ! (e.g.
Definition: kfileitem.cpp:1303
KUrl::protocol
QString protocol() const
QStringList
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
KFileItem::mostLocalUrl
KUrl mostLocalUrl() const
Tries to give a local URL for this file item if possible.
Definition: kfileitem.cpp:1497
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:1390
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:1169
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:1324
KFileItem::isFile
bool isFile() const
Returns true if this item represents a file (and not a a directory)
Definition: kfileitem.cpp:1160
KFileItem::group
QString group() const
Returns the group of the file.
Definition: kfileitem.cpp:712
KDesktopFile::readUrl
QString readUrl() const
KFileItem::size
KIO::filesize_t size() const
Returns the size of the file, if known.
Definition: kfileitem.cpp:610
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:1409
KFileItem::refreshMimeType
void refreshMimeType()
Re-reads mimetype information.
Definition: kfileitem.cpp:533
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:1589
KFileItem::isDesktopFile
bool isDesktopFile() const
Checks whether the file is a readable local .desktop file, i.e.
Definition: kfileitem.cpp:1778
KFileItem::isLink
bool isLink() const
Returns true if this item represents a link in the UNIX sense of a link.
Definition: kfileitem.cpp:1573
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
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:1655
KGlobal::locale
KLocale * locale()
KConfigGroup
QSharedData
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
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
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:1686
KFileItem::name
QString name(bool lowerCase=false) const
Return the name of the file item (without a path).
Definition: kfileitem.cpp:1597
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
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:1313
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:1131
KIO::UDSEntry::UDS_GROUP
Group ID of the file owner.
Definition: udsentry.h:153
KFileItem::unmark
void unmark()
Unmarks the item.
Definition: kfileitem.cpp:1704
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:1421
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
KFileItem::mode
mode_t mode() const
Returns the file type (stat.st_mode containing only S_IFDIR, S_IFLNK, ...).
Definition: kfileitem.cpp:1565
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:1678
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()
KFileItem::setMetaInfo
void setMetaInfo(const KFileMetaInfo &info) const
Sets the metainfo of this item to info.
Definition: kfileitem.cpp:1447
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
operator>>
QDataStream & operator>>(QDataStream &s, KFileItem &a)
Definition: kfileitem.cpp:1520
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
KIO::UDSEntry::UDS_SIZE
Size of the file.
Definition: udsentry.h:144
kfileitem.h
KFileItemList::urlList
KUrl::List urlList() const
Definition: kfileitem.cpp:1757
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:1549
QMap< const void *, void * >
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:1476
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:1020
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:1767
QList< KFileItem >
begin
const KShortcut & begin()
KFileItem::AccessTime
Definition: kfileitem.h:59
KFileMetaInfoItem::value
const QVariant & value() const
Retrieve the current value of this item.
Definition: kfilemetainfoitem.cpp:66
operator<<
QDataStream & operator<<(QDataStream &s, const KFileItem &a)
Definition: kfileitem.cpp:1503
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • 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