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 / kurlcombobox.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  7.8 KB  |  230 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License version 2, as published by the Free Software Foundation.
  7.  
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU Library General Public License
  14.     along with this library; see the file COPYING.LIB.  If not, write to
  15.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.     Boston, MA 02110-1301, USA.
  17. */
  18.  
  19. #ifndef KURLCOMBOBOX_H
  20. #define KURLCOMBOBOX_H
  21.  
  22. #include <qevent.h>
  23. #include <qptrlist.h>
  24. #include <qmap.h>
  25. #include <qpixmap.h>
  26. #include <qstringlist.h>
  27.  
  28. #include <kcombobox.h>
  29. #include <kurl.h>
  30.  
  31. /**
  32.  * This combobox shows a number of recent URLs/directories, as well as some
  33.  * default directories.
  34.  * It will manage the default dirs root-directory, home-directory and
  35.  * Desktop-directory, as well as a number of URLs set via setURLs()
  36.  * and one additional entry to be set via setURL().
  37.  *
  38.  * @short A combo box showing a number of recent URLs/directories
  39.  * @author Carsten Pfeiffer <pfeiffer@kde.org>
  40.  */
  41. class KIO_EXPORT KURLComboBox : public KComboBox
  42. {
  43.     Q_OBJECT
  44.     Q_PROPERTY(QStringList urls READ urls WRITE setURLs DESIGNABLE true)
  45.     Q_PROPERTY(int maxItems READ maxItems WRITE setMaxItems DESIGNABLE true)
  46.  
  47. public:
  48.     /**
  49.      * This enum describes which kind of items is shown in the combo box.
  50.      */
  51.     enum Mode { Files = -1, Directories = 1, Both = 0 };
  52.     /**
  53.      * This Enumeration is used in setURL() to determine which items
  54.      * will be removed when the given list is larger than maxItems().
  55.      *
  56.      * @li RemoveTop means that items will be removed from top
  57.      * @li RemoveBottom means, that items will be removed from the bottom
  58.      */
  59.     enum OverLoadResolving { RemoveTop, RemoveBottom };
  60.  
  61.     /**
  62.      * Constructs a KURLComboBox.
  63.      * @param mode is either Files, Directories or Both and controls the
  64.      * following behavior:
  65.      * @li Files  all inserted URLs will be treated as files, therefore the
  66.      *            url shown in the combo will never show a trailing /
  67.      *            the icon will be the one associated with the file's mimetype.
  68.      * @li Directories  all inserted URLs will be treated as directories, will
  69.      *                  have a trailing slash in the combobox. The current
  70.      *                  directory will show the "open folder" icon, other
  71.      *                  directories the "folder" icon.
  72.      * @li Both  Don't mess with anything, just show the url as given.
  73.      * @param parent The parent object of this widget.
  74.      * @param name The name of this widget.
  75.      */
  76.     KURLComboBox( Mode mode, QWidget *parent=0, const char *name=0 );
  77.     KURLComboBox( Mode mode, bool rw, QWidget *parent=0, const char *name=0 );
  78.     /**
  79.      * Destructs the combo box.
  80.      */
  81.     ~KURLComboBox();
  82.  
  83.     /**
  84.      * Sets the current url. This combo handles exactly one url additionally
  85.      * to the default items and those set via setURLs(). So you can call
  86.      * setURL() as often as you want, it will always replace the previous one
  87.      * set via setURL().
  88.      * If @p url is already in the combo, the last item will stay there
  89.      * and the existing item becomes the current item.
  90.      * The current item will always have the open-directory-pixmap as icon.
  91.      *
  92.      * Note that you won't receive any signals, e.g. textChanged(),
  93.      * returnPressed() or activated() upon calling this method.
  94.      */
  95.     void setURL( const KURL& url );
  96.  
  97.     /**
  98.      * Inserts @p urls into the combobox below the "default urls" (see
  99.      * addDefaultURL).
  100.      *
  101.      * If the list of urls contains more items than maxItems, the first items
  102.      * will be stripped.
  103.      */
  104.     void setURLs( QStringList urls );
  105.  
  106.     /**
  107.      * Inserts @p urls into the combobox below the "default urls" (see
  108.      * addDefaultURL).
  109.      *
  110.      * If the list of urls contains more items than maxItems, the @p remove
  111.      * parameter determines whether the first or last items will be stripped.
  112.      */
  113.     void setURLs( QStringList urls, OverLoadResolving remove );
  114.  
  115.     /**
  116.      * @returns a list of all urls currently handled. The list contains at most
  117.      * maxItems() items.
  118.      * Use this to save the list of urls in a config-file and reinsert them
  119.      * via setURLs() next time.
  120.      * Note that all default urls set via addDefaultURL() are not
  121.      * returned, they will automatically be set via setURLs() or setURL().
  122.      * You will always get fully qualified urls, i.e. with protocol like
  123.      * file:/
  124.      */
  125.     QStringList urls() const;
  126.  
  127.     /**
  128.      * Sets how many items should be handled and displayed by the combobox.
  129.      * @see maxItems
  130.      */
  131.     void setMaxItems( int );
  132.  
  133.     /**
  134.      * @returns the maximum of items the combobox handles.
  135.      * @see setMaxItems
  136.      */
  137.     int maxItems() const { return myMaximum; }
  138.  
  139.     /**
  140.      * Adds a url that will always be shown in the combobox, it can't be
  141.      * "rotated away". Default urls won't be returned in urls() and don't
  142.      * have to be set via setURLs().
  143.      * If you want to specify a special pixmap, use the overloaded method with
  144.      * the pixmap parameter.
  145.      * Default URLs will be inserted into the combobox by setDefaults()
  146.      */
  147.     void addDefaultURL( const KURL& url, const QString& text = QString::null );
  148.  
  149.     /**
  150.      * Adds a url that will always be shown in the combobox, it can't be
  151.      * "rotated away". Default urls won't be returned in urls() and don't
  152.      * have to be set via setURLs().
  153.      * If you don't need to specify a pixmap, use the overloaded method without
  154.      * the pixmap parameter.
  155.      * Default URLs will be inserted into the combobox by setDefaults()
  156.      */
  157.     void addDefaultURL( const KURL& url, const QPixmap& pix,
  158.             const QString& text = QString::null );
  159.  
  160.     /**
  161.      * Clears all items and inserts the default urls into the combo. Will be
  162.      * called implicitly upon the first call to setURLs() or setURL()
  163.      * @see addDefaultURL
  164.      */
  165.     void setDefaults();
  166.  
  167.     /**
  168.      * Removes any occurrence of @p url. If @p checkDefaultURLs is false
  169.      * default-urls won't be removed.
  170.      */
  171.     void removeURL( const KURL& url, bool checkDefaultURLs = true );
  172.  
  173. signals:
  174.     /**
  175.      * Emitted when an item was clicked at.
  176.      * @param url is the url of the now current item. If it is a local url,
  177.      * it won't have a protocol (file:/), otherwise it will.
  178.      */
  179.     void urlActivated( const KURL& url );
  180.  
  181.  
  182. protected slots:
  183.     void slotActivated( int );
  184.  
  185.  
  186. protected:
  187.     struct _KURLComboItem {
  188.     QString text;
  189.     KURL url;
  190.     QPixmap pixmap;
  191.     };
  192.     typedef _KURLComboItem KURLComboItem;
  193.     QPtrList<KURLComboItem> itemList;
  194.     QPtrList<KURLComboItem> defaultList;
  195.     QMap<int,const KURLComboItem*> itemMapper;
  196.  
  197.     void init( Mode mode );
  198.     void insertURLItem( const KURLComboItem * );
  199.  
  200.     /**
  201.      * Uses KMimeType::pixmapForURL() to return a proper pixmap for @p url.
  202.      * In directory mode, a folder icon is always returned.
  203.      */
  204.     QPixmap getPixmap( const KURL& url ) const;
  205.  
  206.     /**
  207.      * Updates @p item with @p pixmap and sets the url instead of the text
  208.      * of the KURLComboItem.
  209.      * Also works around a Qt bug.
  210.      */
  211.     void updateItem( const KURLComboItem *item, int index, const QPixmap& pix);
  212.  
  213.     QPixmap opendirPix;
  214.     int firstItemIndex;
  215.  
  216.  
  217. private:
  218.     bool urlAdded;
  219.     int myMaximum;
  220.     Mode myMode; // can be used as parameter to KUR::path( int ) or url( int )
  221.                  // to specify if we want a trailing slash or not
  222.  
  223. private:
  224.     class KURLComboBoxPrivate;
  225.     KURLComboBoxPrivate *d;
  226. };
  227.  
  228.  
  229. #endif // KURLCOMBOBOX_H
  230.