# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kauthicon.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (c) 1999 Preston Brown <pbrown@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018 /*
    00019  * KAuthIcon - an icon which shows whether privileges are in effect
    00020  */
    00021
    00022 #include <unistd.h> // For getuid
    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 /* XPM */
    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 /* XPM */
    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   // set fixed size of this frame to whichever phrase is longer
    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 { /*BASE::virtual_hook( id, data );*/ }
    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"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:13 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003