• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kauthicon.cpp
1 /* This file is part of the KDE libraries
2  Copyright (c) 1999 Preston Brown <pbrown@kde.org>
3 
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.
7 
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.
12 
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 Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 /*
19  * KAuthIcon - an icon which shows whether privileges are in effect
20  */
21 
22 #include <unistd.h> // For getuid
23 
24 #include <tqlayout.h>
25 #include <tqlabel.h>
26 #include <tqtimer.h>
27 
28 #include <tdelocale.h>
29 
30 #include "kauthicon.h"
31 
32 /* XPM */
33 static const char * const lock_xpm[] = {
34 "22 22 5 1",
35 " c None",
36 ". c #808080",
37 "+ c #000000",
38 "@ c #FFFFFF",
39 "# c #C0C0C0",
40 " ",
41 " ",
42 " ",
43 " ",
44 " .+++. ",
45 " .@@@.+ ",
46 " ..@+++@.. ",
47 " +@+...+@+ ",
48 " +@+. +@+. ",
49 " +@+. +@+. ",
50 " +++++++++++ ",
51 " +#########+. ",
52 " +#.......#+. ",
53 " +#@@@@@@@#+. ",
54 " +#.......#+. ",
55 " +#########+. ",
56 " +++++++++++. ",
57 " ........... ",
58 " ",
59 " ",
60 " ",
61 " "};
62 
63 /* XPM */
64 static const char * const openlock_xpm[] = {
65 "22 22 5 1",
66 " c None",
67 ". c #808080",
68 "+ c #000000",
69 "@ c #FFFFFF",
70 "# c #C0C0C0",
71 " ",
72 " ",
73 " .+++. ",
74 " .@@@.+ ",
75 " ..@+++@.. ",
76 " +@+...+@+ ",
77 " +@+. +@+. ",
78 " +@+. +@+. ",
79 " +++. +@+. ",
80 " ... +@+. ",
81 " +@+. ",
82 " +++++++++++ ",
83 " +#########+. ",
84 " +#.......#+. ",
85 " +#@@@@@@@#+. ",
86 " +#.......#+. ",
87 " +#########+. ",
88 " +++++++++++. ",
89 " ........... ",
90 " ",
91 " ",
92 " "};
93 
94 KAuthIcon::KAuthIcon(TQWidget *parent, const char *name)
95  : TQWidget(parent, name),
96  lockPM( const_cast< const char** >( lock_xpm)),
97  openLockPM( const_cast< const char** >(openlock_xpm))
98 {
99  lockText = i18n("Editing disabled");
100  openLockText = i18n("Editing enabled");
101 
102  lockBox = new TQLabel(this);
103  lockBox->setFrameStyle(TQFrame::WinPanel|TQFrame::Raised);
104  lockBox->setPixmap(lockPM);
105  lockBox->setFixedSize(lockBox->sizeHint());
106 
107  lockLabel = new TQLabel(this);
108  lockLabel->setFrameStyle(TQFrame::NoFrame);
109 
110  // set fixed size of this frame to whichever phrase is longer
111  if (lockLabel->fontMetrics().boundingRect(lockText).width() >
112  lockLabel->fontMetrics().boundingRect(openLockText).width())
113  lockLabel->setText(lockText);
114  else
115  lockLabel->setText(openLockText);
116  lockLabel->setAlignment(AlignCenter);
117  lockLabel->setMinimumSize(lockLabel->sizeHint());
118  lockLabel->setText(lockText);
119 
120  layout = new TQHBoxLayout(this);
121 
122  layout->addWidget(lockBox, 0, AlignLeft|AlignVCenter);
123  layout->addSpacing(5);
124  layout->addWidget(lockLabel, 0, AlignRight|AlignVCenter);
125 
126  layout->activate();
127  resize(sizeHint());
128 }
129 
130 KAuthIcon::~KAuthIcon()
131 {
132 }
133 
134 
135 TQSize KAuthIcon::sizeHint() const
136 {
137  return layout->minimumSize();
138 }
139 
140 
141 /************************************************************************/
142 
143 KRootPermsIcon::KRootPermsIcon(TQWidget *parent, const char *name)
144  : KAuthIcon(parent, name)
145 {
146  updateStatus();
147 }
148 
149 
150 KRootPermsIcon::~KRootPermsIcon()
151 {
152 }
153 
154 void KRootPermsIcon::updateStatus()
155 {
156  const bool newRoot = (geteuid() == 0);
157  lockBox->setPixmap(newRoot ? openLockPM : lockPM);
158  lockLabel->setText(newRoot ? openLockText : lockText);
159  update();
160  if (root != newRoot) {
161  root = newRoot;
162  emit authChanged(newRoot);
163  }
164 }
165 
166 /************************************************************************/
167 
168 KWritePermsIcon::KWritePermsIcon(const TQString & fileName,
169  TQWidget *parent, const char *name)
170  : KAuthIcon(parent, name)
171 {
172  fi.setFile(fileName);
173  updateStatus();
174 }
175 
176 
177 KWritePermsIcon::~KWritePermsIcon()
178 {
179 }
180 
181 void KWritePermsIcon::updateStatus()
182 {
183  bool newwrite;
184  newwrite = fi.isWritable();
185  lockBox->setPixmap(newwrite ? openLockPM : lockPM);
186  lockLabel->setText(newwrite ? openLockText : lockText);
187  update();
188  if (writable != newwrite) {
189  writable = newwrite;
190  emit authChanged(newwrite);
191  }
192 }
193 
194 void KAuthIcon::virtual_hook( int, void* )
195 { /*BASE::virtual_hook( id, data );*/ }
196 
197 void KRootPermsIcon::virtual_hook( int id, void* data )
198 { KAuthIcon::virtual_hook( id, data ); }
199 
200 void KWritePermsIcon::virtual_hook( int id, void* data )
201 { KAuthIcon::virtual_hook( id, data ); }
202 
203 #include "kauthicon.moc"
tdelocale.h
KAuthIcon::KAuthIcon
KAuthIcon(TQWidget *parent=0, const char *name=0)
Constructor.
Definition: kauthicon.cpp:94
KAuthIcon::updateStatus
virtual void updateStatus()=0
Re-implement this method if you want the icon to update itself when something external has changed (i...
KAuthIcon::authChanged
void authChanged(bool authorized)
this signal is emitted when authorization has changed from its previous state.
KAuthIcon
A base class for authorization icon widgets.
Definition: kauthicon.h:47

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.