/*************************************************************************** CPropertyDialog.cpp - description ------------------- begin : Tue Mar 28 2000 copyright : (C) 2000 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 "../../../icons/blank.xpm" #include "CPropertyDialog.h" #include "../../../global.h" #include "../../../information/CTreeInformationElement.h" #include "../../../CTuxCardsConfiguration.h" #include #include #include #include #include #include #include // ------------------------------------------------------------------------------- CPropertyDialog::CPropertyDialog( QWidget* pParent, CTuxCardsConfiguration& refTuxConfiguration ) : IPropertyDialog( pParent, "CPropertyDialog", TRUE ) , mBlankIcon( blank_xpm ) , mIconSelector() , miMode( MODE_NONE ) , miChoice( 0 ) , mpEditingElement( NULLPTR ) , mrefTuxConfiguration( refTuxConfiguration ) // ------------------------------------------------------------------------------- { connect( mpIconButton, SIGNAL(clicked()), this, SLOT(chooseIcon()) ); connect( mpExpiryCheckBox, SIGNAL(toggled(bool)), this, SLOT(activateExpiryDate(bool)) ); connect( mpButtonApply, SIGNAL(clicked()), this, SLOT(changeProperties()) ); // connect( mpEncryptCheckBox, SIGNAL(clicked()), this, SLOT(checkEncryption()) ); } // ------------------------------------------------------------------------------- CPropertyDialog::~CPropertyDialog( void ) // ------------------------------------------------------------------------------- { mpEditingElement = NULLPTR; // do not kill this pointer } // ------------------------------------------------------------------------------- void CPropertyDialog::setUp( CInformationElement* pElement, int iMode ) // ------------------------------------------------------------------------------- { if ( NULLPTR == pElement ) return; if ( iMode == MODE_CHANGE_PROPERTIES ) { setCaption("Change Properties of existing Entry"); setAttributes( pElement->getDescription(), pElement->getIconFileName(), pElement->expires(), pElement->getExpiryDate()/*, pElement->isEncryptionEnabled(), pElement->isCurrentlyEncrypted()*/ ); mpTextFormatChoser->setEnabled( FALSE ); } else if ( iMode == MODE_CREATE_NEW_ELEMENT ) { setCaption( "Add new Entry" ); setAttributes( "", "none" ); mpTextFormatChoser->setEnabled( TRUE ); } else { return; } miMode = iMode; mpEditingElement = pElement; show(); exec(); } // ------------------------------------------------------------------------------- void CPropertyDialog::setAttributes( QString sDescription, QString sIconFilename, bool bExpires, QDate expiryDate/*, bool bIsEncryptionEnabled, bool isCurrentlyEncrypted*/ ) // ------------------------------------------------------------------------------- { if ( sIconFilename == "none" ) { // entry without icon mpNoIconRB->setChecked(true); mpUseIconRB->setChecked(false); mpIconButton->setPixmap( mBlankIcon ); } else { mpIconButton->setPixmap( sIconFilename ); mpNoIconRB->setChecked(false); mpUseIconRB->setChecked(true); } mpLocationLabel->setText( sIconFilename ); mpNameLine->setText(sDescription); mpExpiryCheckBox->setChecked( bExpires ); mpExpiryDateEditor->setDate( expiryDate ); /* if ( bIsEncryptionEnabled ) { mpEncryptCheckBox->setChecked( true ); mpEncryptCheckBox->setEnabled( !isCurrentlyEncrypted ); // mpPasswdLineOne->setText( "*******" ); // mpPasswdLineTwo->setText( "*******" ); mpPasswdLineOne->setEnabled( false ); mpPasswdLineTwo->setEnabled( false ); } else { mpEncryptCheckBox->setChecked( false ); } */ } /** * open a filedialog to let user select his icon */ // ------------------------------------------------------------------------------- void CPropertyDialog::chooseIcon( void ) // ------------------------------------------------------------------------------- { // getting iconfileName if( ! mIconSelector.exec() ) return; QString h = mIconSelector.getIconFileName(); if( h == "" ) return; // if 'h' is a valid fileName, test whether it is a valid Pixmap QPixmap pix(h); if ( ! pix.isNull() ) { mpIconButton->setPixmap(h); mpLocationLabel->setText(h); } } // ------------------------------------------------------------------------------- QString CPropertyDialog::getName( void ) // ------------------------------------------------------------------------------- { return mpNameLine->text(); } // ------------------------------------------------------------------------------- QString CPropertyDialog::getIconFileName( void ) // ------------------------------------------------------------------------------- { if ( mpUseIconRB->isChecked() ) return mpLocationLabel->text(); else return "none"; } /** * This slot is called when the apply-Button is pressed. * The set attributes are applied to the currently edited informationElement. */ // ------------------------------------------------------------------------------- void CPropertyDialog::changeProperties( void ) // ------------------------------------------------------------------------------- { if ( NULLPTR == mpEditingElement ) return; // if ( (NULLPTR == mpPasswdLineOne) || (NULLPTR == mpPasswdLineTwo) ) // return; if ( getName().stripWhiteSpace().isEmpty() ) { int iAnswer = QMessageBox::warning( this, "TuxCards", "The name of your note is empty.\n" "Do you want to change this?", QMessageBox::Yes, QMessageBox::No ); if ( QMessageBox::Yes == iAnswer ) { show(); return; } } /* // is set to 'true' if the encryption mode is changed bool bEncryptionModeChanged = false; // is set to 'true' if entry should be encrypted; // this is only important if 'bEncryptionModeChanged' is 'true' bool bEncrypt = false; if ( NULLPTR != mpEncryptCheckBox ) { if ( mpEditingElement->isEncryptionEnabled() != mpEncryptCheckBox->isChecked() ) { bEncryptionModeChanged = true; if ( mpEncryptCheckBox->isChecked() ) { if ( mpPasswdLineOne->text().stripWhiteSpace().isEmpty() ) { (void) QMessageBox::warning( this, "TuxCards", "Encryption is turned on, but\n" "no password is entered.", "Change it." ); show(); return; } if ( 0 != mpPasswdLineOne->text().stripWhiteSpace().compare( mpPasswdLineTwo->text().stripWhiteSpace()) ) { (void) QMessageBox::warning( this, "TuxCards", "Passwords do not match.", "Change it." ); mpPasswdLineOne->setText(""); mpPasswdLineTwo->setText(""); show(); return; } bEncrypt = true; } else { // if ( tmpPasswd == "" ) // { // QMessageBox::information("Geht nicht, " // "encryption can only be removed if entry is decrypted."); // // mpEncryptCheckBox->setChecked( false ); // bEncrypt = false; // } } } } */ if ( miMode == MODE_CHANGE_PROPERTIES ) { // change properties: name & icon mpEditingElement->setBatched( TRUE ); mpEditingElement->setDescription( getName() ); mpEditingElement->setIconFileName( getIconFileName() ); mpEditingElement->setExpiryDate( mpExpiryCheckBox->isChecked(), mpExpiryDateEditor->date() ); mpEditingElement->setBatched( FALSE ); // only do something if encryption mode has changed // if ( bEncryptionModeChanged ) // mpEditingElement->enableEncryption( bEncrypt, mpPasswdLineOne->text().stripWhiteSpace() ); } else if ( miMode == MODE_CREATE_NEW_ELEMENT ) { InformationFormat* pInfoFormat = InformationFormat::getByString( mpTextFormatChoser->currentText() ); CTreeInformationElement* pNewElement = new CTreeInformationElement( mpEditingElement, getName(), "", pInfoFormat, getIconFileName(), mpExpiryCheckBox->isChecked(), mpExpiryDateEditor->date() ); if ( NULLPTR != pNewElement ) { // only do something if encryption mode has changed // if ( bEncryptionModeChanged ) // pNewElement->enableEncryption( bEncrypt, mpPasswdLineOne->text().stripWhiteSpace() ); } mpEditingElement->addChild( pNewElement ); ((CTreeInformationElement*)mpEditingElement)->setOpen(true); } close(); } // ------------------------------------------------------------------------------- void CPropertyDialog::activateExpiryDate( bool bActivate ) // ------------------------------------------------------------------------------- { //std::cout<<"PropertyDialog::activateExpiryDate activate="<date()="<date().toString()<setMinValue( currentDate ); if ( mpExpiryDateEditor->date() < currentDate ) { mpExpiryDateEditor->setDate( currentDate/*.addDays( DEFAULT_DURATION )*/ ); } } mpExpiryDateEditor->setEnabled( bActivate ); } /* // ------------------------------------------------------------------------------- void CPropertyDialog::checkEncryption() // ------------------------------------------------------------------------------- { if ( (!mpEncryptCheckBox) || (!mpEncryptCheckBox->isEnabled()) ) return; if ( !mrefTuxConfiguration.askForUsingEncryption() ) { mpEncryptCheckBox->setChecked( false ); } } */