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 / knotifydialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.7 KB  |  342 lines

  1. /*
  2.   Copyright (C) 2000,2002 Carsten Pfeiffer <pfeiffer@kde.org>
  3.   Copyright (C) 2002 Neil Stevens <neil@qualityassistant.com>
  4.  
  5.   This program is free software; you can redistribute it and/or
  6.   modify it under the terms of the GNU Library General Public
  7.   License version 2 as published by the Free Software Foundation;
  8.  
  9.   This program is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.   General Public License for more details.
  13.  
  14.   You should have received a copy of the GNU Library General Public License
  15.   along with this library,  If not, write to the Free Software Foundation,
  16.   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18.  
  19. #ifndef KNOTIFYDIALOG_H
  20. #define KNOTIFYDIALOG_H
  21.  
  22. #include <klistview.h>
  23. #include <kdialogbase.h>
  24. #include <kinstance.h>
  25. #include <kglobal.h>
  26.  
  27. #include "knotifywidgetbase.h"
  28.  
  29. class QShowEvent;
  30.  
  31. namespace KNotify
  32. {
  33.     class KNotifyWidget;
  34. }
  35.  
  36. /**
  37.  * KNotifyDialog presents an interface for configuring an application's
  38.  * KNotify events.
  39.  *
  40.  * Rather than requiring the user to wade through the entire list of
  41.  * applications' events in KControl, your application can make the list
  42.  * of its own notifications available here.
  43.  *
  44.  * Typical usage is calling the static configure() method:
  45.  * \code
  46.  * (void) KNotifyDialog::configure( someParentWidget );
  47.  * \endcode
  48.  *
  49.  * @since 3.1
  50.  * @author Carsten Pfeiffer <pfeiffer@kde.org>
  51.  */
  52. class KIO_EXPORT KNotifyDialog : public KDialogBase
  53. {
  54.     Q_OBJECT
  55.  
  56. public:
  57.     /**
  58.      * If you want a non-modal dialog, you need to instantiate KNotifyDialog
  59.      * yourself instead of using the configure() method.
  60.      *
  61.      * KDE4.0 modal default will be false.
  62.      * 
  63.      * @param parent The parent widget for the dialog
  64.      * @param name The widget name
  65.      * @param modal If true, this will be a modal dialog, otherwise non-modal.
  66.      * @param aboutData A pointer to a KAboutData object. KAboutData::appName()
  67.      *                  will be used to find the KNotify events (in the eventsrc file).
  68.      *                  Set this to 0L if you want to add all events yourself with
  69.      * addApplicationEvents().
  70.      */
  71.     KNotifyDialog( QWidget *parent = 0, const char *name = 0,
  72.                    bool modal = true,
  73.                    const KAboutData *aboutData =
  74.                    KGlobal::instance()->aboutData() );
  75.     /**
  76.      * Destroys the KNotifyDialog
  77.      */
  78.     virtual ~KNotifyDialog();
  79.  
  80.     /**
  81.      * Convenience method to create exec() a modal KNotifyDialog.
  82.      *
  83.      * @param parent The parent widget for the dialog
  84.      * @param name The widget name
  85.      * @param aboutData A pointer to a KAboutData object. KAboutData::appName()
  86.      *                  will be used to find the KNotify events (in the eventsrc file).
  87.      * @see exec for the return values.
  88.      * @return The value of QDialog::exec()
  89.      */
  90.     static int configure( QWidget *parent = 0, const char *name = 0,
  91.                           const KAboutData *aboutData = KGlobal::instance()->aboutData() );
  92.  
  93.     /**
  94.      * With this method, you can add the KNotify events of one eventsrc
  95.      * files to the view.
  96.      * KNotifyDialog can handle events for multiple applications (i.e. eventsrc files).
  97.      * Successive calls with a different @p appName will add them.
  98.      * @param appName The application's name, i.e. the name passed to the 
  99.      *                KApplication constructor or KAboutData.
  100.      * @see clearApplicationEvents()
  101.      */
  102.     virtual void addApplicationEvents( const char *appName );
  103.  
  104.     /**
  105.      * With this method, you can add the KNotify events of one eventsrc
  106.      * files to the view.
  107.      * KNotifyDialog can handle events for multiple applications (i.e. eventsrc files).
  108.      * Successive calls with a different @p path will add them.
  109.      * @param path The absolute or relative path to the eventsrc file to be configured.
  110.      *             A relative path would be e.g. "kwin/eventsrc".
  111.      * @see clearApplicationEvents()
  112.      */
  113.     virtual void addApplicationEvents( const QString& path );
  114.  
  115.     /**
  116.      * Removes all the events added with addApplicationEvents()
  117.      * @see addApplicationEvents()
  118.      */
  119.     virtual void clearApplicationEvents();
  120.  
  121. private slots:
  122.     void slotDefault();
  123.  
  124. private:
  125.     enum
  126.     {
  127.         COL_FILENAME = 1
  128.     };
  129.  
  130.     void updateView();
  131.  
  132.     KNotify::KNotifyWidget * m_notifyWidget;
  133.  
  134.     class Private;
  135.     Private *d;
  136. };
  137.  
  138.  
  139. namespace KNotify
  140. {
  141.     class Application;
  142.     class Event;
  143.     class ListViewItem;
  144.     typedef QPtrList<Event> EventList;
  145.     typedef QPtrListIterator<Application> ApplicationListIterator;
  146.     typedef QPtrListIterator<Event> EventListIterator;
  147.  
  148.     /**
  149.      * @internal
  150.      */
  151.     class KIO_EXPORT Application
  152.     {
  153.     public:
  154.         Application( const QString &path );
  155.         ~Application();
  156.  
  157.         QString text() const { return m_description; }
  158.         QString icon() const { return m_icon; }
  159.         const EventList& eventList();
  160.         void reloadEvents( bool revertToDefaults = false );
  161.         void save();
  162.  
  163.         QString appName() const { return m_appname; }
  164.  
  165.     private:
  166.         QString m_icon;
  167.         QString m_description;
  168.         QString m_appname;
  169.         EventList *m_events;
  170.  
  171.         KConfig *kc; // The file that defines the events.
  172.         KConfig *config; // The file that contains the settings for the events
  173.     };
  174.  
  175.  
  176.     class KIO_EXPORT ApplicationList : public QPtrList<Application>
  177.     {
  178.         virtual int compareItems ( QPtrCollection::Item item1,
  179.                                    QPtrCollection::Item item2 )
  180.         {
  181.             return (static_cast<Application*>( item1 )->text() >=
  182.                 static_cast<Application*>( item2 )->text()) ? 1 : -1;
  183.         }
  184.     };
  185.  
  186.     /**
  187.      * @internal
  188.      */
  189.     class KIO_EXPORT KNotifyWidget : public KNotifyWidgetBase
  190.     {
  191.         Q_OBJECT
  192.  
  193.     public:
  194.         KNotifyWidget( QWidget* parent = 0, const char* name = 0,
  195.                        bool handleAllApps = false );
  196.         ~KNotifyWidget();
  197.  
  198.         KListView * eventsView() {
  199.             return m_listview;
  200.         }
  201.  
  202.         void addVisibleApp( Application *app );
  203.         ApplicationList& visibleApps() { return m_visibleApps; }
  204.         ApplicationList& allApps() { return m_allApps; }
  205.  
  206.         /**
  207.          * Returns 0L if no application events could be found
  208.          * The returned pointer must be freed by the caller (easiest done
  209.          * by putting it into an ApplicationList with setAutoDelete( true )).
  210.          */
  211.         Application * addApplicationEvents( const QString& path );
  212.  
  213.         void resetDefaults( bool ask );
  214.         void sort( bool ascending = true );
  215.  
  216.     public slots:
  217.         /**
  218.          * Clears the view and all the Application events.
  219.          */
  220.         virtual void clear();
  221.         /**
  222.          * Clears only the view and the visible Application events.
  223.          * E.g. useful if you want to set new visible events with
  224.          * addVisibleApp()
  225.          */
  226.         virtual void clearVisible();
  227.         virtual void save();
  228.         virtual void showAdvanced( bool show );
  229.         void toggleAdvanced();
  230.  
  231.  
  232.     signals:
  233.         void changed( bool hasChanges );
  234.  
  235.     protected:
  236.         /**
  237.          * May return 0L, if there is no current event selected.
  238.          */
  239.         Event * currentEvent();
  240.         virtual void showEvent( QShowEvent * );
  241.         virtual void enableAll( int what, bool enable );
  242.  
  243.         void reload( bool revertToDefaults = false );
  244.  
  245.     protected slots:
  246.         void playSound();
  247.  
  248.     private slots:
  249.         void slotItemClicked( QListViewItem *item, const QPoint& point, 
  250.                               int col );
  251.         void slotEventChanged( QListViewItem * );
  252.         void soundToggled( bool on );
  253.         void loggingToggled( bool on );
  254.         void executeToggled( bool on );
  255.         void messageBoxChanged();
  256.         void stderrToggled( bool on );
  257.         void taskbarToggled( bool on );
  258.  
  259.         void soundFileChanged( const QString& text );
  260.         void logfileChanged( const QString& text );
  261.         void commandlineChanged( const QString& text );
  262.  
  263.         void openSoundDialog( KURLRequester * );
  264.         void openLogDialog( KURLRequester * );
  265.         void openExecDialog( KURLRequester * );
  266.  
  267.         void enableAll();
  268.  
  269.     private:
  270.         void updateWidgets( ListViewItem *item );
  271.         void updatePixmaps( ListViewItem *item );
  272.  
  273.         static QString makeRelative( const QString& );
  274.         void addToView( const EventList& events );
  275.         void widgetChanged( QListViewItem *item,
  276.                             int what, bool on, QWidget *buddy = 0L );
  277.         void selectItem( QListViewItem *item );
  278.  
  279.         ApplicationList m_visibleApps;
  280.         ApplicationList m_allApps;
  281.  
  282.         class Private;
  283.         Private *d;
  284.  
  285.     };
  286.  
  287.  
  288. ///////////////////////////////////////////////////////////////////
  289. ///////////////////////////////////////////////////////////////////
  290.  
  291.  
  292.     /**
  293.      * @internal
  294.      */
  295.     class Event
  296.     {
  297.         friend class Application;
  298.  
  299.     public:
  300.         QString text() const { return description; }
  301.  
  302.         int presentation;
  303.         int dontShow;
  304.         QString logfile;
  305.         QString soundfile;
  306.         QString commandline;
  307.  
  308.         const Application *application() const { return m_app; }
  309.  
  310.     private:
  311.         Event( const Application *app ) {
  312.             presentation = 0;
  313.             dontShow = 0;
  314.             m_app = app;
  315.         }
  316.         QString name;
  317.         QString description;
  318.         QString configGroup;
  319.  
  320.         const Application *m_app;
  321.     };
  322.  
  323.     /**
  324.      * @internal
  325.      */
  326.     class ListViewItem : public QListViewItem
  327.     {
  328.     public:
  329.         ListViewItem( QListView *view, Event *event );
  330.  
  331.         Event& event() { return *m_event; }
  332.         virtual int compare (QListViewItem * i, int col, bool ascending) const;
  333.  
  334.     private:
  335.         Event * m_event;
  336.     };
  337.  
  338. }
  339.  
  340.  
  341. #endif
  342.