/*************************************************************************** ExpiredElementsDialog.h - description ------------------- begin : Sat Jun 21 2003 copyright : (C) 2003 by Alexander Theel email : alex.theel@gmx.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ExpiredElementsDialog.h" #include #include // ------------------------------------------------------------------------------- ExpiredElementsDialog::ExpiredElementsDialog( QWidget* pParent ) : ExpiredElementsDialogInterface(pParent, "expiredElementsDialog", TRUE) , mpCollection( NULLPTR ) // ------------------------------------------------------------------------------- { connect( pExpiryList, SIGNAL(clicked(QListViewItem*)), this, SLOT(previewEntry(QListViewItem*)) ); connect( pRemoveFromListButton, SIGNAL(clicked()), this, SLOT(removeSelectedItemsFromDeletionList()) ); connect( buttonOk, SIGNAL(clicked()), this, SLOT(deleteRemainingEntries()) ); } // ------------------------------------------------------------------------------- int ExpiredElementsDialog::setUp( CInformationCollection* pCollection ) // ------------------------------------------------------------------------------- { if ( (NULLPTR == pCollection) || (NULLPTR == pExpiryList) || (NULLPTR == buttonOk) ) return 0; mpCollection = pCollection; expiredElementsMap.clear(); pExpiryList->clear(); checkEntryForExpiryDate( mpCollection->getRootElement() ); if ( pExpiryList->childCount() > 0 ) { show(); return exec(); } else { return 0; } buttonOk->setEnabled( true ); } // ------------------------------------------------------------------------------- void ExpiredElementsDialog::checkEntryForExpiryDate( CInformationElement* pElement ) // ------------------------------------------------------------------------------- { if ( NULLPTR == pElement ) return; if ( pElement->expires() ) { //std::cout<<"ExpiredElementsDialog::checkEntryForExpiryDate; found: "<getDescription()<getExpiryDate() < QDate::currentDate() ) { QListViewItem* pItem = new QListViewItem( pExpiryList, pElement->getDescription() ); pItem->setPixmap( 0, QPixmap(pElement->getIconFileName()) ); expiredElementsMap.insert( pItem, pElement ); //std::cout<<"icon="<getIconFileName()< it(*pElement->getChildren()); CInformationElement* x; while( (x = it.current()) != 0 ){ ++it; checkEntryForExpiryDate( x ); } } // ------------------------------------------------------------------------------- void ExpiredElementsDialog::removeSelectedItemsFromDeletionList( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR == pExpiryList ) return; QListViewItem* x = pExpiryList->firstChild(); QListViewItem* pItemAbove = NULLPTR; while ( NULLPTR != x ) { //std::cout<<"rem; x->getDescription()="<text(0)<isSelected( x ) ) { CInformationElement* pElement = expiredElementsMap.find( x ); if ( NULLPTR != pElement ) { pElement->setExpiryDate( false ); // remove expiry date } expiredElementsMap.remove( x ); // remove from dictionary // removing x from qlistview is not a good idea, because // otherwise 'x' would be '0'; -> loop would be left after first // element is removed -> so delete previouse element pItemAbove = x; x = x->nextSibling(); DELETE( pItemAbove ); // remove from qlistview } else { x = x->nextSibling(); } } clearPreview(); // if list is empty, disable the button if ( 0 == pExpiryList->childCount() ) { if ( buttonOk ) buttonOk->setEnabled( false ); } } // ------------------------------------------------------------------------------- // Removes everything from the preview. // ------------------------------------------------------------------------------- void ExpiredElementsDialog::clearPreview( void ) // ------------------------------------------------------------------------------- { pElementIconLabel->setPixmap( QPixmap("") ); pElementNameLabel->setText( "" ); pChildCountLabel->setText( "-" ); pTextEdit->setText( "" ); } // ------------------------------------------------------------------------------- void ExpiredElementsDialog::previewEntry( QListViewItem* pItem ) // ------------------------------------------------------------------------------- { if ( NULLPTR == pItem ) return; CInformationElement* pElement = expiredElementsMap.find( pItem ); previewEntry( pElement ); } // ------------------------------------------------------------------------------- void ExpiredElementsDialog::previewEntry( CInformationElement* pElement ) // ------------------------------------------------------------------------------- { if ( NULLPTR == pElement ) return; pElementIconLabel->setPixmap( QPixmap(pElement->getIconFileName()) ); pElementNameLabel->setText( pElement->getDescription() ); pChildCountLabel->setText( QString::number( pElement->childCount() ) ); pTextEdit->setText( pElement->getInformation() ); } // ------------------------------------------------------------------------------- void ExpiredElementsDialog::deleteRemainingEntries( void ) // ------------------------------------------------------------------------------- { //std::cout<<"ExpiredElementsDialog::deleteRemainingEntries()"<firstChild(); x != NULLPTR; x = x->nextSibling() ) { CInformationElement* pElement = expiredElementsMap.find( x ); // It could be the case that the parent of this element was deleted // before. Hence this element does not exist anymore. if ( pElement ) { pElement->deleteSelf(); // remove "actual" information element from collection } } }