home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kurlcompletion.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-01  |  7.3 KB  |  236 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2000 David Smith  <dsmith@algonet.se>
  3.  
  4.     This class was inspired by a previous KURLCompletion by
  5.     Henner Zeller <zeller@think.de>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22.  
  23. #ifndef KURLCOMPLETION_H
  24. #define KURLCOMPLETION_H
  25.  
  26. #include <kcompletion.h>
  27. #include <kio/jobclasses.h>
  28. #include <qstring.h>
  29. #include <qstringlist.h>
  30.  
  31. class KURL;
  32. class KURLCompletionPrivate;
  33.  
  34. /**
  35.  * This class does completion of URLs including user directories (~user)
  36.  * and environment variables.  Remote URLs are passed to KIO.
  37.  *
  38.  * @short Completion of a single URL
  39.  * @author David Smith <dsmith@algonet.se>
  40.  */
  41. class KIO_EXPORT KURLCompletion : public KCompletion
  42. {
  43.     Q_OBJECT
  44.  
  45. public:
  46.     /**
  47.      * Determines how completion is done.
  48.      * @li ExeCompletion - executables in $PATH or with full path.
  49.      * @li FileCompletion - all files with full path or in dir(), URLs
  50.      * are listed using KIO.
  51.      * @li DirCompletion - Same as FileCompletion but only returns directories.
  52.      */
  53.     enum Mode { ExeCompletion=1, FileCompletion, DirCompletion };
  54.  
  55.     /**
  56.      * Constructs a KURLCompletion object in FileCompletion mode.
  57.      */
  58.     KURLCompletion();
  59.     /**
  60.      * This overloaded constructor allows you to set the Mode to ExeCompletion
  61.      * or FileCompletion without using setMode. Default is FileCompletion.
  62.      */
  63.     KURLCompletion(Mode);
  64.     /**
  65.      * Destructs the KURLCompletion object.
  66.      */
  67.     virtual ~KURLCompletion();
  68.  
  69.     /**
  70.      * Finds completions to the given text.
  71.      *
  72.      * Remote URLs are listed with KIO. For performance reasons, local files
  73.      * are listed with KIO only if KURLCOMPLETION_LOCAL_KIO is set.
  74.      * The completion is done asyncronously if KIO is used.
  75.      *
  76.      * Returns the first match for user, environment, and local dir completion
  77.      * and QString::null for asynchronous completion (KIO or threaded).
  78.      *
  79.      * @param text the text to complete
  80.      * @return the first match, or QString::null if not found
  81.      */
  82.     virtual QString makeCompletion(const QString &text); // KDE4: remove return value, it's often null due to threading
  83.  
  84.     /**
  85.      * Sets the current directory (used as base for completion).
  86.      * Default = $HOME.
  87.      * @param dir the current directory, either as a path or URL
  88.      */
  89.     virtual void setDir(const QString &dir);
  90.  
  91.     /**
  92.      * Returns the current directory, as it was given in setDir
  93.      * @return the current directory (path or URL)
  94.      */
  95.     virtual QString dir() const;
  96.  
  97.     /**
  98.      * Check whether asynchronous completion is in progress.
  99.      * @return true if asynchronous completion is in progress
  100.      */
  101.     virtual bool isRunning() const;
  102.  
  103.     /**
  104.      * Stops asynchronous completion.
  105.      */
  106.     virtual void stop();
  107.  
  108.     /**
  109.      * Returns the completion mode: exe or file completion (default FileCompletion).
  110.      * @return the completion mode
  111.      */
  112.     virtual Mode mode() const;
  113.  
  114.     /**
  115.      * Changes the completion mode: exe or file completion
  116.      * @param mode the new completion mode
  117.      */
  118.     virtual void setMode( Mode mode );
  119.  
  120.     /**
  121.      * Checks whether environment variables are completed and
  122.      * whether they are replaced internally while finding completions.
  123.      * Default is enabled.
  124.      * @return true if environment vvariables will be replaced
  125.      */
  126.     virtual bool replaceEnv() const;
  127.  
  128.     /**
  129.      * Enables/disables completion and replacement (internally) of
  130.      * environment variables in URLs. Default is enabled.
  131.      * @param replace true to replace environment variables
  132.      */
  133.     virtual void setReplaceEnv( bool replace );
  134.  
  135.     /**
  136.      * Returns whether ~username is completed and whether ~username
  137.      * is replaced internally with the user's home directory while
  138.      * finding completions. Default is enabled.
  139.      * @return true to replace tilde with the home directory
  140.      */
  141.     virtual bool replaceHome() const;
  142.  
  143.     /**
  144.      * Enables/disables completion of ~username and replacement
  145.      * (internally) of ~username with the user's home directory.
  146.      * Default is enabled.
  147.      * @param replace true to replace tilde with the home directory
  148.      */
  149.     virtual void setReplaceHome( bool replace );
  150.  
  151.     /**
  152.      * Replaces username and/or environment variables, depending on the
  153.      * current settings and returns the filtered url. Only works with
  154.      * local files, i.e. returns back the original string for non-local
  155.      * urls.
  156.      * @param text the text to process
  157.      * @return the path or URL resulting from this operation. If you
  158.          * want to convert it to a KURL, use KURL::fromPathOrURL.
  159.      */
  160.     QString replacedPath( const QString& text );
  161.  
  162.     /**
  163.      * @internal I'll let ossi add a real one to KShell :)
  164.      * @since 3.2
  165.     */
  166.     static QString replacedPath( const QString& text,
  167.                                      bool replaceHome, bool replaceEnv = true );
  168.  
  169.     class MyURL;
  170. protected:
  171.     // Called by KCompletion, adds '/' to directories
  172.     void postProcessMatch( QString *match ) const;
  173.     void postProcessMatches( QStringList *matches ) const;
  174.     void postProcessMatches( KCompletionMatches* matches ) const;
  175.  
  176.     virtual void customEvent( QCustomEvent *e );
  177.  
  178. protected slots:
  179.     void slotEntries( KIO::Job *, const KIO::UDSEntryList& );
  180.     void slotIOFinished( KIO::Job * );
  181.  
  182. private:
  183.  
  184.     bool isAutoCompletion();
  185.  
  186.     bool userCompletion(const MyURL &url, QString *match);
  187.     bool envCompletion(const MyURL &url, QString *match);
  188.     bool exeCompletion(const MyURL &url, QString *match);
  189.     bool fileCompletion(const MyURL &url, QString *match);
  190.     bool urlCompletion(const MyURL &url, QString *match);
  191.  
  192.     // List a directory using readdir()
  193.     void listDir( const QString& dir,
  194.                   QStringList *matches,
  195.                   const QString& filter,
  196.                   bool only_exe,
  197.                   bool no_hidden );
  198.  
  199.     // List the next dir in m_dirs
  200.     QString listDirectories(const QStringList &,
  201.                             const QString &,
  202.                             bool only_exe = false,
  203.                             bool only_dir = false,
  204.                             bool no_hidden = false,
  205.                             bool stat_files = true);
  206.  
  207.     void listURLs( const QValueList<KURL *> &urls,
  208.                    const QString &filter = QString::null,
  209.                    bool only_exe = false,
  210.                    bool no_hidden = false );
  211.  
  212.     void addMatches( const QStringList & );
  213.     QString finished();
  214.  
  215.     void init();
  216.  
  217.     void setListedURL(int compl_type /* enum ComplType */,
  218.                       const QString& dir = QString::null,
  219.                       const QString& filter = QString::null,
  220.                       bool no_hidden = false );
  221.  
  222.     bool isListedURL( int compl_type /* enum ComplType */,
  223.                       const QString& dir = QString::null,
  224.                       const QString& filter = QString::null,
  225.                       bool no_hidden = false );
  226.  
  227.     void adjustMatch( QString& match ) const;
  228.  
  229. protected:
  230.     virtual void virtual_hook( int id, void* data );
  231. private:
  232.     KURLCompletionPrivate *d;
  233. };
  234.  
  235. #endif // KURLCOMPLETION_H
  236.