subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kauthicon.h
blob05ba2d1e621fb138167b5d2da3d442450add6c6f
1 /* This file is part of the KDE libraries
2 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
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.
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.
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 Steet, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #ifndef _KAUTHICON_H
19 #define _KAUTHICON_H "$Id$"
21 #include <qfileinfo.h>
22 #include <qpixmap.h>
23 #include <qstring.h>
24 #include <qwidget.h>
26 #include <kdelibs_export.h>
28 class QHBoxLayout;
29 class QLabel;
30 class KAuthIconPrivate;
32 /**
33 * @short A base class for authorization icon widgets
35 * This is the base class from which different authorization icon widget
36 * which actually do something should be derived. You can use these
37 * widgets to show that the user has (or doesn't have) the ability to do
38 * something, and why that is.
40 * One of the most useful things you can do with this is connect
41 * authChanged(bool) to setEnabled(bool) for a widget to turn it on and
42 * off depending on the status of whatever it is you are monitoring.
44 * @see KRootPermsIcon, KWritePermsIcon
45 * @author Preston Brown <pbrown@kde.org>
47 class KDEUI_EXPORT KAuthIcon : public QWidget
49 Q_OBJECT
51 public:
52 /**
53 * Constructor.
55 KAuthIcon(QWidget *parent = 0, const char *name = 0);
56 ~KAuthIcon();
58 virtual QSize sizeHint() const;
59 /**
60 * return the status of whatever is being monitored.
62 virtual bool status() const = 0;
64 public slots:
65 /**
66 * Re-implement this method if you want the icon to update itself
67 * when something external has changed (i.e. a file on disk, uid/gid).
69 virtual void updateStatus() = 0;
71 signals:
72 /**
73 * this signal is emitted when authorization has changed from
74 * its previous state.
75 * @param authorized will be true if the type of authorization
76 * described by the icon is true, otherwise it will be false.
78 void authChanged(bool authorized);
80 protected:
81 QHBoxLayout *layout;
83 QLabel *lockBox;
84 QLabel *lockLabel;
85 QPixmap lockPM;
86 QPixmap openLockPM;
87 QString lockText;
88 QString openLockText;
90 protected:
91 virtual void virtual_hook( int id, void* data );
92 private:
93 KAuthIconPrivate *d;
96 class KRootPermsIconPrivate;
97 /**
98 * Icon to show whether or not a user has root permissions.
100 * @see KAuthIcon
101 * @author Preston Brown <pbrown@kde.org>
103 class KDEUI_EXPORT KRootPermsIcon : public KAuthIcon
105 Q_OBJECT
107 public:
108 KRootPermsIcon(QWidget *parent = 0, const char *name = 0);
109 ~KRootPermsIcon();
112 * return whether or not the current user has root permissions.
114 bool status() const { return root; }
116 public slots:
117 void updateStatus();
119 protected:
120 bool root;
122 protected:
123 virtual void virtual_hook( int id, void* data );
124 private:
125 KRootPermsIconPrivate *d;
128 class KWritePermsIconPrivate;
130 * Auth icon for write permission display.
132 * @see KAuthIcon
133 * @author Preston Brown <pbrown@kde.org>
135 class KDEUI_EXPORT KWritePermsIcon : public KAuthIcon
137 Q_OBJECT
138 Q_PROPERTY( QString fileName READ fileName WRITE setFileName )
140 public:
141 KWritePermsIcon(const QString & fileName, QWidget *parent = 0, const char *name = 0);
142 ~KWritePermsIcon();
144 * @return whether or not the monitored file is writable.
146 bool status() const { return writable; }
149 * make the icon watch a new filename.
150 * @param fileName the new file to monitor / display status for.
152 void setFileName(const QString & fileName) { fi.setFile(fileName); updateStatus(); }
155 * return the filename of the currently watched file.
156 * @since 3.4
158 QString fileName() const { return fi.fileName(); }
160 public slots:
161 void updateStatus();
163 protected:
164 bool writable;
165 QFileInfo fi;
167 protected:
168 virtual void virtual_hook( int id, void* data );
169 private:
170 KWritePermsIconPrivate *d;
173 #endif