/*
   
        (c) 2006 by Thomas Michel <tom.michel@arcor.de>

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

        Kwlan is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU Library General Public License for more details.

        You should have received a copy of the GNU Library General Public License
        along with this library; see the file COPYING.LIB.  If not, write to
        the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
        Boston, MA 02110-1301, USA.
*/

#ifndef _KWLANKICKER_H_
#define _KWLANKICKER_H_


#include <sys/types.h>
#include <ksystemtrayicon.h>
#include <QString>
#include <kmenu.h>
#include <QTimer>
#include <QMap>
#include <QAction>
#include <QWidgetAction>

#include "kwlnetworklist.h"


class QWidget;
class KwlanInterface;
class Configuration;
class QProgressBar;

// IDs for WPA MEnu
#define WPASTARTID 1
#define WPASTOPID 2
#define WPALOGID 3
#define WPASETTINGSID 4

// Custom menu class to display signal strength


class KWirelessActionWidget : public QWidget
{
    Q_OBJECT
    public:
        KWirelessActionWidget  (QWidget*, const kwlNetwork & prof, bool isSelected);
        //void paintEvent (QPaintEvent *p); //, const QColorGroup &/*cg*/, bool highlighted, bool /*enabled*/, int x, int y, int w, int h);
        ~KWirelessActionWidget ();

        QWidget*      m_parent;
    public slots:
        void slotTriggered(bool);
    signals:
        void sigTriggered(bool);
        
    protected:
        bool event(QEvent *);

    private:
        QString m_ssid;
        /* elements */
        int m_textHeight;
        int m_widgetHeight;

        int m_space;
};



class KWirelessAction :  public QWidgetAction
{
    Q_OBJECT
            
    public:
        KWirelessAction(QWidget * parent, const kwlNetwork & prof, bool isSelected);
        ~KWirelessAction()
        {
        }
    
    public slots:
        void slotTriggered(bool);
    protected:
        
        QWidget* createWidget ( QWidget * parent );

    private:
        kwlNetwork m_profile;
        //KWirelessActionWidget *m_widget;
        QWidget *m_widget;
};

// Class to show status in systray

class KwlanTrayWin : public KSystemTrayIcon
{
    Q_OBJECT
    public:
        KwlanTrayWin(QWidget *parent=0, const char *name=0);
        virtual ~KwlanTrayWin();
        bool isConnected() const;
        const QString & getInterfaceName() const;
        //void clearProfiles();
        void setInterface(KwlanInterface *interface);
        KwlanInterface* getInterface()
        {
            return m_interface;
        }
        void setProfile(QString profile)
        {
            m_profile = profile;
        }
        QString getProfile()
        {
            return m_profile;
        }
        void setInterfaceName(const QString &ifname);
        QString getIcon();

    signals:
        void sigMonitorInterface(QString interface, bool showWin);
        void sigConfigureInterface(QString interface, bool configure);
        void clicked();
        void aboutSelected();
        void profileChanged(QString profile);
        void interfaceEnable(bool enable);
        void viewLog();
        void editProfiles();
        void scan();
        void sigTrayWinClicked(QString);
        void quitSelected();

        
    public slots:
        void contextMenuAboutToShow ();
        void updateIcon();
        void setIpAddress(const QString &ipaddress);
        void updateNetworks();
        //void setInterfaceEnableMenu(bool up);
        void interfaceEnable();
        void wpaStart();
        void wpaStop();
        void slotHandleWpaMenu(QAction *action);
        void enableStartWpaMenu(bool enable);
        void slotInterfaceGone(KwlanInterface  *interface);
        void slotShowTrayWin(QString interface, bool showWin);
        void slotHandleInterfacesMenu(QAction *action);
        void slotHandleConfigureInterfacesMenu(QAction *action);
        void slotHandleProfilesMenu(QAction *action);
        void slotHandleDialupMenu(QAction *action);
        void mousePressEvent ( QMouseEvent * event );
        void slotSettings();
        void say (QString message);
        void slotQuitSelected();
        void slotAboutSelected();
        bool event(QEvent *event);
        void slotUpdateToolTip();
        //void slotClicked(QMouseEvent*);

    protected:
        //void mouseReleaseEvent( QMouseEvent * );
        QString m_ifname;
        QString m_ipaddress;
        QAction *m_quit, *m_about;  
        QAction *m_interfaceEnableAction;
        //KwlanToolTip *m_tooltip;
        QTimer *m_timer;
    //private slots:
        //void selectProfile(int id);
    private:
        kwlNetworkList m_profiles;
        //bool m_interfaceUp;
        QMenu *m_profileMenu;
        QMenu *m_configureInterfacesMenu, *m_wpaMenu, *m_dialupMenu;
        QAction *m_stopWpa, *m_startWpa, *m_logWpa, *m_settingsWpa;
        QMenu *m_interfacesMenu;
        QMenu *m_contextMenu;
        KwlanInterface *m_interface;
        QString m_profile;
        QString m_confFile;
        Configuration *m_configuration;
        QMap<QString, kwlNetwork >       m_networkMap;
        QWidget *m_parent;
        //KwlanMainWin *m_mainWin;
};

#endif
