[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Completion (Was: Key management)
From:       Carsten Pfeiffer <carpdjih () cetus ! zrz ! TU-Berlin ! DE>
Date:       1999-11-25 19:40:08
[Download RAW message or body]

On Thu, Nov 25, 1999 at 06:58:59AM -0500, Dawit Alemayehu wrote:

Hi,

I wanted to delay this until after KRASH, but now is a good time, I think.

Why restrict completion to URL-completion or command-completion?
Everything should be completable, email-addresses in a mailer,
phone-numbers in an address-book, commands, everything a user can enter
somewhere what the system knows about.
Therefore, I made a simple but generic KCompletion-class based on
QStringList which can be used for that purpose. I already wrote a new
KURLCompletion, derived from KCompletion, which not only works on
directories, but also on remote urls via KIO.
Due to that dependency, I wanted to add that class either to KIO or kfile
(it's already used in the new kfile), while the basic KCompletion-class
could go into kdecore.

KEdit could easily be extended to make use of this and automatically use
the user-configured completion-mode.

Cheers, 
Carsten Pfeiffer
-- 
http://www.geocities.com/SiliconValley/1632/

["kcompletion.h" (text/plain)]

#ifndef KCOMPLETION_H
#define KCOMPLETION_H

#include <qobject.h>
#include <qstringlist.h>

class KCompletion : public QObject
{
  Q_OBJECT

public:
  KCompletion();
  ~KCompletion();


public slots:
  /**
   * Attempts to find an item in the list of available completions,
   * that begins with string. Will either return the alphabetically
   * first matching item (if more than one matches) or QString::null.
   * A non-null return-value will also be emitted via the signal
   * @ref match. Additionally, all matching items are emitted via
   * the signal @ref matches.
   */
  virtual QString makeCompletion( const QString& string );
  
  /**
   * Returns the alphabetically next item from the matching-items--list
   * When reaching the beginning, the list is rotated, so it will return
   * the last match. When there is no match, QString::null is returned.
   */
  QString	previousMatch();

  /**
   * Returns the alphabetically previous item from the matching-items--list
   * When reaching the last item, the list is rotated, so it will return
   * the first match. When there is no match, QString::null is returned.
   */
  QString	nextMatch();

  /**
   * Sets the list of items available for completion
   */
  void 		setItemList( const QStringList& );
  
  /**
   * Adds an item to the list of available completions
   */
  void 		addItem( const QString& );
  
  /**
   * Removes an item from the list of available completions
   */
  void 		removeItem( const QString& );
  
  /**
   * Clears the list of available completions
   */
  void 		clear();


signals:
  /**
   * The alphabetically first matching item.
   */
  void 		match( const QString& );

  /**
   * A list of all matching items. Only emitted if the list differs from a
   * previously emitted list. The list may be empty (no matching items at all).
   */
  void 		matches( const QStringList& );


private:
  QStringList 	myItemList;
  QStringList 	myMatches;
  QStringList::Iterator myIterator;
  QString 	myLastString;

};


#endif // KCOMPLETION_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic