Qt 4.8
qurlinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qurlinfo.h"
43 
44 #ifndef QT_NO_URLINFO
45 
46 #include "qurl.h"
47 #include "qdir.h"
48 #include <limits.h>
49 
51 
53 {
54 public:
56  permissions(0),
57  size(0),
58  isDir(false),
59  isFile(true),
60  isSymLink(false),
61  isWritable(true),
62  isReadable(true),
63  isExecutable(false)
64  {}
65 
71 
74  bool isDir;
75  bool isFile;
76  bool isSymLink;
77  bool isWritable;
78  bool isReadable;
80 };
81 
82 
136 {
137  d = 0;
138 }
139 
145 {
146  if (ui.d) {
147  d = new QUrlInfoPrivate;
148  *d = *ui.d;
149  } else {
150  d = 0;
151  }
152 }
153 
167  const QString &group, qint64 size, const QDateTime &lastModified,
168  const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
169  bool isWritable, bool isReadable, bool isExecutable)
170 {
171  d = new QUrlInfoPrivate;
172  d->name = name;
173  d->permissions = permissions;
174  d->owner = owner;
175  d->group = group;
176  d->size = size;
177  d->lastModified = lastModified;
178  d->lastRead = lastRead;
179  d->isDir = isDir;
180  d->isFile = isFile;
181  d->isSymLink = isSymLink;
182  d->isWritable = isWritable;
183  d->isReadable = isReadable;
184  d->isExecutable = isExecutable;
185 }
186 
187 
201  const QString &group, qint64 size, const QDateTime &lastModified,
202  const QDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
203  bool isWritable, bool isReadable, bool isExecutable)
204 {
205  d = new QUrlInfoPrivate;
206  d->name = QFileInfo(url.path()).fileName();
207  d->permissions = permissions;
208  d->owner = owner;
209  d->group = group;
210  d->size = size;
211  d->lastModified = lastModified;
212  d->lastRead = lastRead;
213  d->isDir = isDir;
214  d->isFile = isFile;
215  d->isSymLink = isSymLink;
216  d->isWritable = isWritable;
217  d->isReadable = isReadable;
218  d->isExecutable = isExecutable;
219 }
220 
221 
233 {
234  if (!d)
235  d = new QUrlInfoPrivate;
236  d->name = name;
237 }
238 
239 
252 void QUrlInfo::setDir(bool b)
253 {
254  if (!d)
255  d = new QUrlInfoPrivate;
256  d->isDir = b;
257 }
258 
259 
272 void QUrlInfo::setFile(bool b)
273 {
274  if (!d)
275  d = new QUrlInfoPrivate;
276  d->isFile = b;
277 }
278 
279 
291 {
292  if (!d)
293  d = new QUrlInfoPrivate;
294  d->isSymLink = b;
295 }
296 
297 
309 {
310  if (!d)
311  d = new QUrlInfoPrivate;
312  d->isWritable = b;
313 }
314 
315 
327 {
328  if (!d)
329  d = new QUrlInfoPrivate;
330  d->isReadable = b;
331 }
332 
343 {
344  if (!d)
345  d = new QUrlInfoPrivate;
346  d->owner = s;
347 }
348 
359 {
360  if (!d)
361  d = new QUrlInfoPrivate;
362  d->group = s;
363 }
364 
375 {
376  if (!d)
377  d = new QUrlInfoPrivate;
378  d->size = size;
379 }
380 
391 {
392  if (!d)
393  d = new QUrlInfoPrivate;
394  d->permissions = p;
395 }
396 
408 {
409  if (!d)
410  d = new QUrlInfoPrivate;
411  d->lastModified = dt;
412 }
413 
430 {
431  if (!d)
432  d = new QUrlInfoPrivate;
433  d->lastRead = dt;
434 }
435 
441 {
442  delete d;
443 }
444 
450 {
451  if (ui.d) {
452  if (!d)
453  d= new QUrlInfoPrivate;
454  *d = *ui.d;
455  } else {
456  delete d;
457  d = 0;
458  }
459  return *this;
460 }
461 
469 {
470  if (!d)
471  return QString();
472  return d->name;
473 }
474 
483 {
484  if (!d)
485  return 0;
486  return d->permissions;
487 }
488 
496 {
497  if (!d)
498  return QString();
499  return d->owner;
500 }
501 
509 {
510  if (!d)
511  return QString();
512  return d->group;
513 }
514 
522 {
523  if (!d)
524  return 0;
525  return d->size;
526 }
527 
535 {
536  if (!d)
537  return QDateTime();
538  return d->lastModified;
539 }
540 
548 {
549  if (!d)
550  return QDateTime();
551  return d->lastRead;
552 }
553 
560 bool QUrlInfo::isDir() const
561 {
562  if (!d)
563  return false;
564  return d->isDir;
565 }
566 
573 bool QUrlInfo::isFile() const
574 {
575  if (!d)
576  return false;
577  return d->isFile;
578 }
579 
587 {
588  if (!d)
589  return false;
590  return d->isSymLink;
591 }
592 
600 {
601  if (!d)
602  return false;
603  return d->isWritable;
604 }
605 
613 {
614  if (!d)
615  return false;
616  return d->isReadable;
617 }
618 
626 {
627  if (!d)
628  return false;
629  return d->isExecutable;
630 }
631 
639 bool QUrlInfo::greaterThan(const QUrlInfo &i1, const QUrlInfo &i2,
640  int sortBy)
641 {
642  switch (sortBy) {
643  case QDir::Name:
644  return i1.name() > i2.name();
645  case QDir::Time:
646  return i1.lastModified() > i2.lastModified();
647  case QDir::Size:
648  return i1.size() > i2.size();
649  default:
650  return false;
651  }
652 }
653 
660 bool QUrlInfo::lessThan(const QUrlInfo &i1, const QUrlInfo &i2,
661  int sortBy)
662 {
663  return !greaterThan(i1, i2, sortBy);
664 }
665 
672 bool QUrlInfo::equal(const QUrlInfo &i1, const QUrlInfo &i2,
673  int sortBy)
674 {
675  switch (sortBy) {
676  case QDir::Name:
677  return i1.name() == i2.name();
678  case QDir::Time:
679  return i1.lastModified() == i2.lastModified();
680  case QDir::Size:
681  return i1.size() == i2.size();
682  default:
683  return false;
684  }
685 }
686 
694 bool QUrlInfo::operator==(const QUrlInfo &other) const
695 {
696  if (!d)
697  return other.d == 0;
698  if (!other.d)
699  return false;
700 
701  return (d->name == other.d->name &&
702  d->permissions == other.d->permissions &&
703  d->owner == other.d->owner &&
704  d->group == other.d->group &&
705  d->size == other.d->size &&
706  d->lastModified == other.d->lastModified &&
707  d->lastRead == other.d->lastRead &&
708  d->isDir == other.d->isDir &&
709  d->isFile == other.d->isFile &&
710  d->isSymLink == other.d->isSymLink &&
711  d->isWritable == other.d->isWritable &&
712  d->isReadable == other.d->isReadable &&
713  d->isExecutable == other.d->isExecutable);
714 }
715 
736 bool QUrlInfo::isValid() const
737 {
738  return d != 0;
739 }
740 
742 
743 #endif // QT_NO_URLINFO
virtual void setSize(qint64 size)
Specifies the size of the URL.
Definition: qurlinfo.cpp:374
double d
Definition: qnumeric_p.h:62
virtual void setFile(bool b)
If b is true then the URL is set to be a file; if is false then the URL is set not to be a file (whic...
Definition: qurlinfo.cpp:272
QString owner() const
Returns the owner of the URL.
Definition: qurlinfo.cpp:495
bool isFile() const
Returns true if the URL is a file; otherwise returns false.
Definition: qurlinfo.cpp:573
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isExecutable() const
Returns true if the URL is executable; otherwise returns false.
Definition: qurlinfo.cpp:625
bool isReadable() const
Returns true if the URL is readable; otherwise returns false.
Definition: qurlinfo.cpp:612
static bool greaterThan(const QString &s1, const QString &s2)
bool isWritable() const
Returns true if the URL is writable; otherwise returns false.
Definition: qurlinfo.cpp:599
virtual void setGroup(const QString &s)
Specifies that the owning group of the URL is called s.
Definition: qurlinfo.cpp:358
bool isSymLink() const
Returns true if the URL is a symbolic link; otherwise returns false.
Definition: qurlinfo.cpp:586
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void setDir(bool b)
If b is true then the URL is set to be a directory; if b is false then the URL is set not to be a dir...
Definition: qurlinfo.cpp:252
QDateTime lastModified() const
Returns the last modification date of the URL.
Definition: qurlinfo.cpp:534
virtual void setOwner(const QString &s)
Specifies that the owner of the URL is called s.
Definition: qurlinfo.cpp:342
QDateTime lastModified
Definition: qurlinfo.cpp:72
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
The QUrlInfo class stores information about URLs.
Definition: qurlinfo.h:60
virtual void setName(const QString &name)
Sets the name of the URL to name.
Definition: qurlinfo.cpp:232
virtual void setPermissions(int p)
Specifies that the URL has access permissions p.
Definition: qurlinfo.cpp:390
QString name() const
Returns the file name of the URL.
Definition: qurlinfo.cpp:468
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QUrlInfoPrivate * d
Definition: qurlinfo.h:122
static bool equal(const QUrlInfo &i1, const QUrlInfo &i2, int sortBy)
Returns true if i1 equals to i2; otherwise returns false.
Definition: qurlinfo.cpp:672
QString group() const
Returns the group of the URL.
Definition: qurlinfo.cpp:508
static bool greaterThan(const QUrlInfo &i1, const QUrlInfo &i2, int sortBy)
Returns true if i1 is greater than i2; otherwise returns false.
Definition: qurlinfo.cpp:639
bool operator==(const QUrlInfo &i) const
Returns true if this QUrlInfo is equal to other; otherwise returns false.
Definition: qurlinfo.cpp:694
__int64 qint64
Definition: qglobal.h:942
QString owner
Definition: qurlinfo.cpp:68
static bool lessThan(const QUrlInfo &i1, const QUrlInfo &i2, int sortBy)
Returns true if i1 is less than i2; otherwise returns false.
Definition: qurlinfo.cpp:660
bool isDir() const
Returns true if the URL is a directory; otherwise returns false.
Definition: qurlinfo.cpp:560
QDateTime lastRead() const
Returns the date when the URL was last read.
Definition: qurlinfo.cpp:547
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
virtual ~QUrlInfo()
Destroys the URL info object.
Definition: qurlinfo.cpp:440
void setLastRead(const QDateTime &dt)
Specifies that the object the URL refers to was last read at dt.
Definition: qurlinfo.cpp:429
virtual void setSymLink(bool b)
Specifies that the URL refers to a symbolic link if b is true and that it does not if b is false...
Definition: qurlinfo.cpp:290
QUrlInfo & operator=(const QUrlInfo &ui)
Assigns the values of ui to this QUrlInfo object.
Definition: qurlinfo.cpp:449
int permissions() const
Returns the permissions of the URL.
Definition: qurlinfo.cpp:482
QString name
Definition: qurlinfo.cpp:66
virtual void setWritable(bool b)
Specifies that the URL is writable if b is true and not writable if b is false.
Definition: qurlinfo.cpp:308
virtual void setLastModified(const QDateTime &dt)
Specifies that the object the URL refers to was last modified at dt.
Definition: qurlinfo.cpp:407
virtual void setReadable(bool b)
Specifies that the URL is readable if b is true and not readable if b is false.
Definition: qurlinfo.cpp:326
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
bool isValid() const
Returns true if the URL info is valid; otherwise returns false.
Definition: qurlinfo.cpp:736
qint64 size() const
Returns the size of the URL.
Definition: qurlinfo.cpp:521
QString group
Definition: qurlinfo.cpp:69
static QString fileName(const QString &fileUrl)
QUrlInfo()
Constructs an invalid QUrlInfo object with default values.
Definition: qurlinfo.cpp:135
QDateTime lastRead
Definition: qurlinfo.cpp:73