00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <unistd.h>
00023
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qtimer.h>
00027
00028 #include <klocale.h>
00029
00030 #include "kauthicon.h"
00031
00032
00033 static const char * const lock_xpm[] = {
00034 "22 22 5 1",
00035 " c None",
00036 ". c #808080",
00037 "+ c #000000",
00038 "@ c #FFFFFF",
00039 "# c #C0C0C0",
00040 " ",
00041 " ",
00042 " ",
00043 " ",
00044 " .+++. ",
00045 " .@@@.+ ",
00046 " ..@+++@.. ",
00047 " +@+...+@+ ",
00048 " +@+. +@+. ",
00049 " +@+. +@+. ",
00050 " +++++++++++ ",
00051 " +#########+. ",
00052 " +#.......#+. ",
00053 " +#@@@@@@@#+. ",
00054 " +#.......#+. ",
00055 " +#########+. ",
00056 " +++++++++++. ",
00057 " ........... ",
00058 " ",
00059 " ",
00060 " ",
00061 " "};
00062
00063
00064 static const char * const openlock_xpm[] = {
00065 "22 22 5 1",
00066 " c None",
00067 ". c #808080",
00068 "+ c #000000",
00069 "@ c #FFFFFF",
00070 "# c #C0C0C0",
00071 " ",
00072 " ",
00073 " .+++. ",
00074 " .@@@.+ ",
00075 " ..@+++@.. ",
00076 " +@+...+@+ ",
00077 " +@+. +@+. ",
00078 " +@+. +@+. ",
00079 " +++. +@+. ",
00080 " ... +@+. ",
00081 " +@+. ",
00082 " +++++++++++ ",
00083 " +#########+. ",
00084 " +#.......#+. ",
00085 " +#@@@@@@@#+. ",
00086 " +#.......#+. ",
00087 " +#########+. ",
00088 " +++++++++++. ",
00089 " ........... ",
00090 " ",
00091 " ",
00092 " "};
00093
00094 KAuthIcon::KAuthIcon(QWidget *parent, const char *name)
00095 : QWidget(parent, name),
00096 lockPM( const_cast< const char** >( lock_xpm)),
00097 openLockPM( const_cast< const char** >(openlock_xpm))
00098 {
00099 lockText = i18n("Editing disabled");
00100 openLockText = i18n("Editing enabled");
00101
00102 lockBox = new QLabel(this);
00103 lockBox->setFrameStyle(QFrame::WinPanel|QFrame::Raised);
00104 lockBox->setPixmap(lockPM);
00105 lockBox->setFixedSize(lockBox->sizeHint());
00106
00107 lockLabel = new QLabel(this);
00108 lockLabel->setFrameStyle(QFrame::NoFrame);
00109
00110
00111 if (lockLabel->fontMetrics().boundingRect(lockText).width() >
00112 lockLabel->fontMetrics().boundingRect(openLockText).width())
00113 lockLabel->setText(lockText);
00114 else
00115 lockLabel->setText(openLockText);
00116 lockLabel->setAlignment(AlignCenter);
00117 lockLabel->setMinimumSize(lockLabel->sizeHint());
00118 lockLabel->setText(lockText);
00119
00120 layout = new QHBoxLayout(this);
00121
00122 layout->addWidget(lockBox, 0, AlignLeft|AlignVCenter);
00123 layout->addSpacing(5);
00124 layout->addWidget(lockLabel, 0, AlignRight|AlignVCenter);
00125
00126 layout->activate();
00127 resize(sizeHint());
00128 }
00129
00130 KAuthIcon::~KAuthIcon()
00131 {
00132 }
00133
00134
00135 QSize KAuthIcon::sizeHint() const
00136 {
00137 return layout->minimumSize();
00138 }
00139
00140
00141
00142
00143 KRootPermsIcon::KRootPermsIcon(QWidget *parent, const char *name)
00144 : KAuthIcon(parent, name)
00145 {
00146 updateStatus();
00147 }
00148
00149
00150 KRootPermsIcon::~KRootPermsIcon()
00151 {
00152 }
00153
00154 void KRootPermsIcon::updateStatus()
00155 {
00156 const bool newRoot = (geteuid() == 0);
00157 lockBox->setPixmap(newRoot ? openLockPM : lockPM);
00158 lockLabel->setText(newRoot ? openLockText : lockText);
00159 update();
00160 if (root != newRoot) {
00161 root = newRoot;
00162 emit authChanged(newRoot);
00163 }
00164 }
00165
00166
00167
00168 KWritePermsIcon::KWritePermsIcon(const QString & fileName,
00169 QWidget *parent, const char *name)
00170 : KAuthIcon(parent, name)
00171 {
00172 fi.setFile(fileName);
00173 updateStatus();
00174 }
00175
00176
00177 KWritePermsIcon::~KWritePermsIcon()
00178 {
00179 }
00180
00181 void KWritePermsIcon::updateStatus()
00182 {
00183 bool newwrite;
00184 newwrite = fi.isWritable();
00185 lockBox->setPixmap(newwrite ? openLockPM : lockPM);
00186 lockLabel->setText(newwrite ? openLockText : lockText);
00187 update();
00188 if (writable != newwrite) {
00189 writable = newwrite;
00190 emit authChanged(newwrite);
00191 }
00192 }
00193
00194 void KAuthIcon::virtual_hook( int, void* )
00195 { }
00196
00197 void KRootPermsIcon::virtual_hook( int id, void* data )
00198 { KAuthIcon::virtual_hook( id, data ); }
00199
00200 void KWritePermsIcon::virtual_hook( int id, void* data )
00201 { KAuthIcon::virtual_hook( id, data ); }
00202
00203 #include "kauthicon.moc"