certmanager Library API Documentation

dnattributeorderconfigwidget.cpp

00001 /* -*- c++ -*- 00002 dnattributeorderconfigwidget.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klar�vdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 00031 */ 00032 00033 #ifdef HAVE_CONFIG_H 00034 #include <config.h> 00035 #endif 00036 00037 #include "dnattributeorderconfigwidget.h" 00038 00039 #include "kleo/dn.h" 00040 00041 #include <klocale.h> 00042 #include <kdebug.h> 00043 #include <kdialog.h> 00044 #include <kiconloader.h> 00045 #include <kconfig.h> 00046 #include <kapplication.h> 00047 00048 #include <qtoolbutton.h> 00049 #include <qlayout.h> 00050 #include <qheader.h> 00051 #include <qlabel.h> 00052 #include <qlistview.h> 00053 #include <qtooltip.h> 00054 00055 #include <assert.h> 00056 00057 struct Kleo::DNAttributeOrderConfigWidget::Private { 00058 enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 }; 00059 00060 QListView * availableLV; 00061 QListView * currentLV; 00062 QToolButton * navTB[6]; 00063 00064 QListViewItem * placeHolderItem; 00065 00066 Kleo::DNAttributeMapper * mapper; 00067 }; 00068 00069 static void prepare( QListView * lv ) { 00070 lv->setAllColumnsShowFocus( true ); 00071 lv->setResizeMode( QListView::LastColumn ); 00072 lv->header()->setClickEnabled( false ); 00073 lv->addColumn( QString::null ); 00074 lv->addColumn( i18n("Description") ); 00075 } 00076 00077 Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget( DNAttributeMapper * mapper, QWidget * parent, const char * name, WFlags f ) 00078 : QWidget( parent, name, f ), d( 0 ) 00079 { 00080 assert( mapper ); 00081 d = new Private(); 00082 d->mapper = mapper; 00083 00084 QGridLayout * glay = new QGridLayout( this, 2, 3, 0, KDialog::spacingHint() ); 00085 glay->setColStretch( 0, 1 ); 00086 glay->setColStretch( 2, 1 ); 00087 00088 int row = -1; 00089 00090 ++row; 00091 glay->addWidget( new QLabel( i18n("Available attributes:"), this ), row, 0 ); 00092 glay->addWidget( new QLabel( i18n("Current attribute order:"), this ), row, 2 ); 00093 00094 00095 ++row; 00096 glay->setRowStretch( row, 1 ); 00097 00098 d->availableLV = new QListView( this ); 00099 prepare( d->availableLV ); 00100 d->availableLV->setSorting( 0 ); 00101 glay->addWidget( d->availableLV, row, 0 ); 00102 00103 d->currentLV = new QListView( this ); 00104 prepare( d->currentLV ); 00105 d->currentLV->setSorting( -1 ); 00106 glay->addWidget( d->currentLV, row, 2 ); 00107 00108 connect( d->availableLV, SIGNAL(selectionChanged(QListViewItem*)), 00109 SLOT(slotAvailableSelectionChanged(QListViewItem*)) ); 00110 connect( d->currentLV, SIGNAL(selectionChanged(QListViewItem*)), 00111 SLOT(slotCurrentOrderSelectionChanged(QListViewItem*)) ); 00112 00113 d->placeHolderItem = new QListViewItem( d->availableLV, "_X_", i18n("All others") ); 00114 00115 // the up/down/left/right arrow cross: 00116 00117 QGridLayout * xlay = new QGridLayout( 5, 3, 0, "xlay" ); 00118 xlay->setAlignment( AlignCenter ); 00119 00120 static const struct { 00121 const char * icon; 00122 int row, col; 00123 const char * tooltip; 00124 const char * slot; 00125 } navButtons[] = { 00126 { "2uparrow", 0, 1, I18N_NOOP( "Move to top" ), SLOT(slotDoubleUpButtonClicked()) }, 00127 { "1uparrow", 1, 1, I18N_NOOP( "Move one up" ), SLOT(slotUpButtonClicked()) }, 00128 { "1leftarrow", 2, 0, I18N_NOOP( "Remove from current attribute order" ), SLOT(slotLeftButtonClicked()) }, 00129 { "1rightarrow", 2, 2, I18N_NOOP( "Add to current attribute order" ), SLOT(slotRightButtonClicked()) }, 00130 { "1downarrow", 3, 1, I18N_NOOP( "Move one down" ), SLOT(slotDownButtonClicked()) }, 00131 { "2downarrow", 4, 1, I18N_NOOP( "Move to bottom" ), SLOT(slotDoubleDownButtonClicked()) } 00132 }; 00133 00134 for ( unsigned int i = 0 ; i < sizeof navButtons / sizeof *navButtons ; ++i ) { 00135 QToolButton * tb = d->navTB[i] = new QToolButton( this ); 00136 tb->setIconSet( SmallIconSet( navButtons[i].icon ) ); 00137 tb->setEnabled( false ); 00138 QToolTip::add( tb, i18n( navButtons[i].tooltip ) ); 00139 xlay->addWidget( tb, navButtons[i].row, navButtons[i].col ); 00140 connect( tb, SIGNAL(clicked()), navButtons[i].slot ); 00141 } 00142 00143 glay->addLayout( xlay, row, 1 ); 00144 } 00145 00146 Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget() { 00147 delete d; d = 0; 00148 } 00149 00150 void Kleo::DNAttributeOrderConfigWidget::load() { 00151 // save the _X_ item: 00152 takePlaceHolderItem(); 00153 // clear the rest: 00154 d->availableLV->clear(); 00155 d->currentLV->clear(); 00156 00157 const QStringList order = d->mapper->attributeOrder(); 00158 00159 // fill the RHS listview: 00160 QListViewItem * last = 0; 00161 for ( QStringList::const_iterator it = order.begin() ; it != order.end() ; ++it ) { 00162 const QString attr = (*it).upper(); 00163 if ( attr == "_X_" ) { 00164 takePlaceHolderItem(); 00165 d->currentLV->insertItem( d->placeHolderItem ); 00166 d->placeHolderItem->moveItem( last ); 00167 last = d->placeHolderItem; 00168 } else 00169 last = new QListViewItem( d->currentLV, last, attr, d->mapper->name2label( attr ) ); 00170 } 00171 00172 // fill the LHS listview with what's left: 00173 00174 const QStringList all = Kleo::DNAttributeMapper::instance()->names(); 00175 for ( QStringList::const_iterator it = all.begin() ; it != all.end() ; ++it ) 00176 if ( order.find( *it ) == order.end() ) 00177 (void)new QListViewItem( d->availableLV, *it, d->mapper->name2label( *it ) ); 00178 00179 if ( !d->placeHolderItem->listView() ) 00180 d->availableLV->insertItem( d->placeHolderItem ); 00181 } 00182 00183 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() { 00184 if ( QListView * lv = d->placeHolderItem->listView() ) 00185 lv->takeItem( d->placeHolderItem ); 00186 } 00187 00188 void Kleo::DNAttributeOrderConfigWidget::save() const { 00189 QStringList order; 00190 for ( QListViewItemIterator it( d->currentLV ) ; it.current() ; ++it ) 00191 order.push_back( it.current()->text( 0 ) ); 00192 00193 d->mapper->setAttributeOrder( order ); 00194 } 00195 00196 void Kleo::DNAttributeOrderConfigWidget::defaults() { 00197 qDebug( "Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()" ); 00198 } 00199 00200 00201 00202 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged( QListViewItem * item ) { 00203 d->navTB[Private::Right]->setEnabled( item ); 00204 } 00205 00206 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged( QListViewItem * item ) { 00207 enableDisableButtons( item ); 00208 } 00209 00210 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons( QListViewItem * item ) { 00211 d->navTB[Private::UUp ]->setEnabled( item && item->itemAbove() ); 00212 d->navTB[Private::Up ]->setEnabled( item && item->itemAbove() ); 00213 d->navTB[Private::Left ]->setEnabled( item ); 00214 d->navTB[Private::Down ]->setEnabled( item && item->itemBelow() ); 00215 d->navTB[Private::DDown]->setEnabled( item && item->itemBelow() ); 00216 } 00217 00218 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() { 00219 QListViewItem * item = d->currentLV->selectedItem(); 00220 if ( !item ) 00221 return; 00222 QListViewItem * above = item->itemAbove(); 00223 if ( !above ) 00224 return; 00225 above->moveItem( item ); // moves "above" to after "item", ie. "item" one up 00226 enableDisableButtons( item ); 00227 emit changed(); 00228 } 00229 00230 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() { 00231 QListViewItem * item = d->currentLV->selectedItem(); 00232 if ( !item ) 00233 return; 00234 if ( item == d->currentLV->firstChild() ) 00235 return; 00236 d->currentLV->takeItem( item ); 00237 d->currentLV->insertItem( item ); 00238 d->currentLV->setSelected( item, true ); 00239 enableDisableButtons( item ); 00240 emit changed(); 00241 } 00242 00243 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() { 00244 QListViewItem * item = d->currentLV->selectedItem(); 00245 if ( !item ) 00246 return; 00247 QListViewItem * below = item->itemBelow(); 00248 if ( !below ) 00249 return; 00250 item->moveItem( below ); // moves "item" to after "below", ie. "item" one down 00251 enableDisableButtons( item ); 00252 emit changed(); 00253 } 00254 00255 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() { 00256 QListViewItem * item = d->currentLV->selectedItem(); 00257 if ( !item ) 00258 return; 00259 QListViewItem * last = d->currentLV->lastItem(); 00260 assert( last ); 00261 if ( item == last ) 00262 return; 00263 item->moveItem( last ); // moves "item" to after "last", ie. to the bottom 00264 enableDisableButtons( item ); 00265 emit changed(); 00266 } 00267 00268 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() { 00269 QListViewItem * right = d->currentLV->selectedItem(); 00270 if ( !right ) 00271 return; 00272 QListViewItem * next = right->itemBelow(); 00273 if ( !next ) 00274 next = right->itemAbove(); 00275 d->currentLV->takeItem( right ); 00276 d->availableLV->insertItem( right ); 00277 if ( next ) 00278 d->currentLV->setSelected( next, true ); 00279 enableDisableButtons( next ); 00280 emit changed(); 00281 } 00282 00283 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() { 00284 QListViewItem * left = d->availableLV->selectedItem(); 00285 if ( !left ) 00286 return; 00287 QListViewItem * next = left->itemBelow(); 00288 if ( !next ) 00289 next = left->itemAbove(); 00290 d->availableLV->takeItem( left ); 00291 d->currentLV->insertItem( left ); 00292 if ( QListViewItem * right = d->currentLV->selectedItem() ) { 00293 if ( QListViewItem * above = right->itemAbove() ) 00294 left->moveItem( above ); // move new item immediately before old selected 00295 d->currentLV->setSelected( right, false ); 00296 } 00297 d->currentLV->setSelected( left, true ); 00298 enableDisableButtons( left ); 00299 d->navTB[Private::Right]->setEnabled( next ); 00300 if ( next ) 00301 d->availableLV->setSelected( next, true ); 00302 emit changed(); 00303 } 00304 00305 00306 00307 void Kleo::DNAttributeOrderConfigWidget::virtual_hook( int, void* ) {} 00308 00309 #include "dnattributeorderconfigwidget.moc"
KDE Logo
This file is part of the documentation for certmanager Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:46 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003