summaryrefslogtreecommitdiffstats
path: root/lib/qextfileinfo.h
blob: 1fbe10932cc434f2f532a1ea964384426d545fe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
    From WebMaker - KDE HTML Editor
    Copyright (C) 1998, 1999 Alexei Dets <dets@services.ru>
    Rewritten for Quanta Plus: (C) 2002 Andras Mantia <amantia@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
*/

#ifndef _TQEXTFILEINFO_H_
#define _TQEXTFILEINFO_H_

#include <kio/global.h>
#include <kio/job.h>
#include <kurl.h>
#include <kfileitem.h>

#include <tqobject.h>
#include <tqptrlist.h>
#include <tqdict.h>
#include <tqregexp.h>

class QExtFileInfo:public TQObject
{
 Q_OBJECT
  
public:
  QExtFileInfo() {};
  ~QExtFileInfo() {};

  /**
   * Works like TQDir::canonicalPath, but it does not return an empty
   * string if the path does not exists, but tries to find if there
   * is a part of the path which exists and resolv the symlinks for
   * that part. The ending slash is kept in the result.
   * Example:
   * /home/user/foo points to /mnt/foo
   * /home/user/foo/foo2 does not exists
   * QExtFileInfo::canonicalPath("/home/user/foo/foo2/") will return
   * /mnt/foo/foo2/ .
   * @param path the path to resolve
   * @return the canonical path (symlinks resolved)
   */
  static TQString canonicalPath(const TQString& path);

  /**
   * Similar to TQDir::homeDirPath(), but returns a resolved path.
   *
   */
  static TQString homeDirPath();

  /** Returns the relative url of urlToConvert to baseURL. */
  static KURL toRelative(const KURL& urlToConvert, const KURL& baseURL, bool resolveSymlinks = true);
  /** Convert relative url to absolute, based on baseURL. */
  static KURL toAbsolute(const KURL& urlToConvert, const KURL& baseURL);
  /** Returns a recursive list of files under path, matching the specified file mask. */
  static KURL::List allFiles( const KURL& path, const TQString &mask, TQWidget *window);
  /** Returns a recursive list of files under path, matching the specified file mask.
      The returned urls are relative to path.
  */
  static KURL::List allFilesRelative( const KURL& path, const TQString &mask, TQWidget *window, bool resolveSymlinks = true);
  /** Returns a recursive list of files under path, matching the specified file mask.
      The returned list contains detailed information about each url.
      The user should delete the KFileItems and clear the dict
      after they are not needed.
  */
  static TQDict<KFileItem> allFilesDetailed(const KURL& path, const TQString &mask, TQWidget *window);
  /** Creates a dir if don't exists. */
  static bool createDir(const KURL & path, TQWidget *window);
  /** Returns the parent directory of dir. */
  static KURL cdUp(const KURL &dir);
  /** Returns the filename from a path string. */
  static TQString shortName(const TQString &fname );
  /** Returns the path to the url. */
  static KURL path(const KURL &);
  /** Returns the user's home directory as an url. */
  static KURL home();
  /** A slightly better working alternative of TDEIO::NetAccess::exists().
      Checks for the existance of the url. readingOnly is true if we check if
      the url is readable, and false if we check if it is writable.*/
  static bool exists(const KURL& url, bool readingOnly, TQWidget *window);
  /** Synchronous copy, like NetAccess::file_copy in KDE 3.2, just that it doesn't show a progress dialog */
  static bool copy( const KURL& src, const KURL& dest, int permissions=-1,
                    bool overwrite=false, bool resume=false, TQWidget* window = 0L );
  /** Reenters the event loop. You must call tqApp->exit_loop() to exit it. */
  void enter_loop();

private:
  /** Internal methods called by the above ones. They start their own event loop and
      exit when the even loop is exited */
  bool internalExists(const KURL& url, bool readingOnly, TQWidget *window);
  bool internalCopy(const KURL& src, const KURL& target, int permissions,
                    bool overwrite, bool resume, TQWidget* window);
  KURL::List allFilesInternal(const KURL& startURL, const TQString& mask, TQWidget *window);
  TQDict<KFileItem> allFilesDetailedInternal(const KURL& startURL, const TQString& mask, TQWidget *window);
  KURL::List allLocalFiles(const TQString& startPath, const TQString& mask);

  bool bJobOK;
  static TQString lastErrorMsg;
  TDEIO::UDSEntry m_entry;
  KURL::List dirListItems;
  TQDict<KFileItem> detailedDirListItems;
  TQPtrList<TQRegExp> lstFilters;
  int m_listJobCount;
  TQString m_listStartURL;

private slots:
  void slotListResult(TDEIO::Job *job);
  void slotResult(TDEIO::Job * job);
  void slotNewEntries(TDEIO::Job *job, const TDEIO::UDSEntryList& udsList);
  void slotNewDetailedEntries(TDEIO::Job *job, const TDEIO::UDSEntryList& udsList);
public slots:
  /** Timeout occurred while waiting for some network function to return. */
  void slotTimeout();
};


#endif