@ -17,7 +17,7 @@
* Free Software Foundation , Inc . , *
* Free Software Foundation , Inc . , *
* 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA . *
* 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "mainwindow .h"
# include "main.h"
# include <qpushbutton.h>
# include <qpushbutton.h>
# include <qpalette.h>
# include <qpalette.h>
@ -43,72 +43,97 @@
CEditEntryDlg : : CEditEntryDlg ( QWidget * parent , const char * name , bool modal , Qt : : WFlags fl )
CEditEntryDlg : : CEditEntryDlg ( PwDatabase * _db , CEntry * _entry , QWidget * parent , const char * name , bool modal , Qt : : WFlags fl )
: EditEntry Dialog( parent , name , modal , fl )
: Q Dialog( parent , name , modal , fl )
{
{
Q_ASSERT ( _db ) ;
pw = ( ( CMainWindow * ) parentWidget ( ) ) - > db ;
Q_ASSERT ( _entry ) ;
mainwnd = ( ( CMainWindow * ) parentWidget ( ) ) ;
entry = _entry ;
mainwnd - > CreateBanner ( Banner , mainwnd - > Icon_Key32x32 , trUtf8 ( " Eintrag bearbeiten " ) ) ;
db = _db ;
setupUi ( this ) ;
createBanner ( Banner , Icon_Key32x32 , trUtf8 ( " Eintrag bearbeiten " ) ) ;
ModFlag = false ;
ModFlag = false ;
}
connect ( Edit_Password_w , SIGNAL ( editingFinished ( ) ) , this , SLOT ( OnPasswordwLostFocus ( ) ) ) ;
connect ( Edit_Password_w , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( OnPasswordwTextChanged ( const QString & ) ) ) ;
CEditEntryDlg : : ~ CEditEntryDlg ( )
connect ( Edit_Password , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( OnPasswordTextChanged ( const QString & ) ) ) ;
{
connect ( ButtonEchoMode , SIGNAL ( clicked ( ) ) , this , SLOT ( ChangeEchoMode ( ) ) ) ;
connect ( ButtonCancel , SIGNAL ( clicked ( ) ) , this , SLOT ( OnButtonCancel ( ) ) ) ;
connect ( ButtonOpenAttachment , SIGNAL ( clicked ( ) ) , this , SLOT ( OnNewAttachment ( ) ) ) ;
connect ( ButtonDeleteAttachment , SIGNAL ( clicked ( ) ) , this , SLOT ( OnDeleteAttachment ( ) ) ) ;
connect ( ButtonSaveAttachment , SIGNAL ( clicked ( ) ) , this , SLOT ( OnSaveAttachment ( ) ) ) ;
connect ( ButtonGenPw , SIGNAL ( clicked ( ) ) , this , SLOT ( OnButtonGenPw ( ) ) ) ;
connect ( ButtonOK , SIGNAL ( clicked ( ) ) , this , SLOT ( OnButtonOK ( ) ) ) ;
connect ( CheckBox_ExpiresNever , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnCheckBoxExpiresNeverChanged ( int ) ) ) ;
ButtonOpenAttachment - > setIcon ( * Icon_FileOpen ) ;
ButtonDeleteAttachment - > setIcon ( * Icon_EditDelete ) ;
ButtonSaveAttachment - > setIcon ( * Icon_FileSave ) ;
}
void CEditEntryDlg : : showEvent ( QShowEvent * event ) {
if ( event - > spontaneous ( ) = = false ) {
if ( entry - > pBinaryData = = NULL ) {
if ( entry - > pBinaryData = = NULL ) {
ButtonSaveAttachment - > setDisabled ( true ) ;
ButtonSaveAttachment - > setDisabled ( true ) ;
ButtonDeleteAttachment - > setDisabled ( true ) ;
ButtonDeleteAttachment - > setDisabled ( true ) ; }
}
setCaption ( entry - > Title ) ;
setCaption ( entry - > Title ) ;
setIcon ( mainwnd - > EntryIcons [ entry - > ImageID ] ) ;
setIcon ( EntryIcons [ entry - > ImageID ] ) ;
Edit_Title - > setText ( entry - > Title ) ;
Edit_Title - > setText ( entry - > Title ) ;
Edit_UserName - > setText ( entry - > UserName ) ;
Edit_UserName - > setText ( entry - > UserName ) ;
Edit_URL - > setText ( entry - > URL ) ;
Edit_URL - > setText ( entry - > URL ) ;
Edit_Password - > setText ( entry - > Password . getString ( ) ) ;
Edit_Password - > setText ( entry - > Password . getString ( ) ) ;
Edit_Password_w - > setText ( entry - > Password . getString ( ) ) ;
Edit_Password_w - > setText ( entry - > Password . getString ( ) ) ;
entry - > Password . delRef ( ) ;
entry - > Password . delRef ( ) ;
if ( ! mainwnd - > config - > ShowPasswords ) ChangeEchoMode ( ) ;
if ( ! config . ShowPasswords )
ChangeEchoMode ( ) ;
OnPasswordwLostFocus ( ) ;
OnPasswordwLostFocus ( ) ;
int bits = ( entry - > Password . length ( ) * 8 ) ;
int bits = ( entry - > Password . length ( ) * 8 ) ;
Label_Bits - > setText ( QString : : number ( bits ) + " Bit " ) ;
Label_Bits - > setText ( QString : : number ( bits ) + " Bit " ) ;
if ( bits > 128 ) bits = 128 ;
if ( bits > 128 )
Progress_Quali - > setProgress ( bits , 128 ) ;
bits = 128 ;
Progress_Quali - > setPercentageVisible ( false ) ;
Progress_Quali - > setValue ( 100 * bits / 128 ) ;
Edit_Attachment - > setText ( entry - > BinaryDesc ) ;
Edit_Attachment - > setText ( entry - > BinaryDesc ) ;
Edit_Comment - > setText ( entry - > Additional ) ;
Edit_Comment - > setText ( entry - > Additional ) ;
InitGroupComboBox ( ) ;
InitGroupComboBox ( ) ;
InitIconComboBox ( ) ;
InitIconComboBox ( ) ;
Edit_Expire_Date - > setText ( ( entry - > Expire . GetString ( 0 ) ) . mid ( 0 , 10 ) ) ;
if ( entry - > BinaryDataLength = = 0 )
Edit_Expire_Time - > setText ( ( entry - > Expire . GetString ( 0 ) ) . mid ( 11 , 8 ) ) ;
Label_AttachmentSize - > setText ( " " ) ;
if ( entry - > BinaryDataLength = = 0 ) {
else {
Label_AttachmentSize - > setText ( " " ) ;
QString unit ;
}
int faktor ;
else
int prec ;
{
QString unit ;
int faktor ;
int prec ;
if ( entry - > BinaryDataLength < 1000 ) { unit = " Byte " ; faktor = 1 ; prec = 0 ; }
if ( entry - > BinaryDataLength < 1000 ) { unit = " Byte " ; faktor = 1 ; prec = 0 ; }
else { if ( entry - > BinaryDataLength < 1000000 ) { unit = " kB " ; faktor = 1000 ; prec = 1 ; }
else { if ( entry - > BinaryDataLength < 1000000 ) { unit = " kB " ; faktor = 1000 ; prec = 1 ; }
else { unit = " MB " ; faktor = 1000000 ; prec = 1 ; }
else { unit = " MB " ; faktor = 1000000 ; prec = 1 ; }
}
}
Label_AttachmentSize - > setText ( QString : : number ( ( float ) entry - > BinaryDataLength / ( float ) faktor , ' f ' , prec ) + unit ) ;
Label_AttachmentSize - > setText ( QString : : number ( ( float ) entry - > BinaryDataLength / ( float ) faktor , ' f ' , prec ) + unit ) ;
}
if ( entry - > Expire = = Date_Never ) {
DateTime_Expire - > setDisabled ( true ) ;
CheckBox_ExpiresNever - > setChecked ( true ) ;
}
}
else {
DateTime_Expire - > setDateTime ( entry - > Expire ) ;
}
}
CEditEntryDlg : : ~ CEditEntryDlg ( )
{
}
void CEditEntryDlg : : showEvent ( QShowEvent * event ) {
if ( event - > spontaneous ( ) = = false ) {
}
}
}
}
void CEditEntryDlg : : InitIconComboBox ( ) {
void CEditEntryDlg : : InitIconComboBox ( ) {
for ( int i = 0 ; i < 52 ; i + + ) {
for ( int i = 0 ; i < 52 ; i + + ) {
Combo_IconPicker - > insertItem ( ( ( CMainWindow * ) parentWidget ( ) ) - > EntryIcons [ i ] , " " , i ) ;
Combo_IconPicker - > insertItem ( EntryIcons [ i ] , " " , i ) ;
}
}
Combo_IconPicker - > setCurrentItem ( entry - > ImageID ) ;
Combo_IconPicker - > setCurrentItem ( entry - > ImageID ) ;
}
}
@ -117,38 +142,26 @@ Combo_IconPicker->setCurrentItem(entry->ImageID);
void CEditEntryDlg : : InitGroupComboBox ( ) {
void CEditEntryDlg : : InitGroupComboBox ( ) {
QString tmp ;
QString tmp ;
int i ;
int i ;
for ( i = 0 ; i ! = pw - > Groups . size ( ) ; i + + ) {
for ( i = 0 ; i ! = db - > Groups . size ( ) ; i + + ) {
tmp = " " ;
tmp = " " ;
for ( int j = 0 ; j < pw - > Groups [ i ] . Level ; j + + ) tmp + = " " ;
for ( int j = 0 ; j < db - > Groups [ i ] . Level ; j + + ) tmp + = " " ;
Combo_Group - > insertItem ( ( ( CMainWindow * ) parentWidget ( ) ) - > EntryIcons [ pw - > Groups [ i ] . ImageID ] ,
Combo_Group - > insertItem ( EntryIcons [ db - > Groups [ i ] . ImageID ] ,
tmp + pw - > Groups [ i ] . Name , i ) ;
tmp + db - > Groups [ i ] . Name , i ) ;
}
}
Combo_Group - > setCurrentItem ( pw - > getGroupIndex ( entry - > GroupID ) ) ;
Combo_Group - > setCurrentItem ( db - > getGroupIndex ( entry - > GroupID ) ) ;
}
}
void CEditEntryDlg : : OnButtonOK ( )
void CEditEntryDlg : : OnButtonOK ( )
{
{
if ( QString : : compare ( Edit_Password - > text ( ) , Edit_Password_w - > text ( ) ) ! = 0 ) {
if ( QString : : compare ( Edit_Password - > text ( ) , Edit_Password_w - > text ( ) ) ! = 0 ) {
QMessageBox : : warning ( NULL , " Stopp " , QString : : fromUtf8 ( " Passwort und Passwortwiederholung stimmen \n nicht überein. " ) , " OK " ) ;
QMessageBox : : warning ( NULL , " Stopp " , QString : : fromUtf8 ( " Passwort und Passwortwiederholung stimmen \n nicht überein. " ) , " OK " ) ;
return ;
return ;
}
}
QString str = Edit_Expire_Date - > text ( ) ;
if ( CPwmTime : : IsValidDate ( str ) = = false ) {
QMessageBox : : warning ( NULL , " Stopp " , QString : : fromUtf8 ( str + " ist kein gültiges Datum. " ) , " OK " ) ;
return ;
}
str = Edit_Expire_Time - > text ( ) ;
if ( CheckBox_ExpiresNever - > state ( ) = = Qt : : Checked ) {
if ( CPwmTime : : IsValidTime ( str ) = = false ) {
DateTime_Expire - > setDateTime ( Date_Never ) ; }
QMessageBox : : warning ( NULL , " Stopp " , QString : : fromUtf8 ( str + " ist keine gültige Uhrzeit. " ) , " OK " ) ;
return ;
}
CPwmTime tmp_Expire ;
if ( DateTime_Expire - > dateTime ( ) ! = entry - > Expire )
tmp_Expire . SetDate ( Edit_Expire_Date - > text ( ) ) ;
tmp_Expire . SetTime ( Edit_Expire_Time - > text ( ) ) ;
if ( tmp_Expire ! = entry - > Expire )
ModFlag = true ;
ModFlag = true ;
if ( entry - > Title ! = Edit_Title - > text ( ) )
if ( entry - > Title ! = Edit_Title - > text ( ) )
ModFlag = true ;
ModFlag = true ;
@ -163,18 +176,17 @@ if(passw!=Edit_Password->text())
ModFlag = true ;
ModFlag = true ;
entry - > Password . delRef ( ) ;
entry - > Password . delRef ( ) ;
entry - > Expire . SetDate ( Edit_Expire_Date - > text ( ) ) ;
entry - > Expire = DateTime_Expire - > dateTime ( ) ;
entry - > Expire . SetTime ( Edit_Expire_Time - > text ( ) ) ;
entry - > LastAccess = QDateTime : : currentDateTime ( ) ;
entry - > LastAccess . SetToNow ( ) ;
if ( ModFlag ) entry - > LastMod = QDateTime : : currentDateTime ( ) ;
if ( ModFlag ) entry - > LastMod . SetToNow ( ) ;
entry - > Title = Edit_Title - > text ( ) ;
entry - > Title = Edit_Title - > text ( ) ;
entry - > UserName = Edit_UserName - > text ( ) ;
entry - > UserName = Edit_UserName - > text ( ) ;
entry - > URL = Edit_URL - > text ( ) ;
entry - > URL = Edit_URL - > text ( ) ;
QString s = Edit_Password - > text ( ) ;
QString s = Edit_Password - > text ( ) ;
entry - > Password . setString ( s , true ) ;
entry - > Password . setString ( s , true ) ;
entry - > Additional = Edit_Comment - > text ( ) ;
entry - > Additional = Edit_Comment - > text ( ) ;
if ( Combo_Group - > currentItem ( ) ! = pw - > getGroupIndex ( entry - > GroupID ) ) {
if ( Combo_Group - > currentItem ( ) ! = db - > getGroupIndex ( entry - > GroupID ) ) {
pw - > moveEntry ( entry , & pw - > Groups [ Combo_Group - > currentItem ( ) ] ) ;
db - > moveEntry ( entry , & db - > Groups [ Combo_Group - > currentItem ( ) ] ) ;
}
}
entry - > ImageID = Combo_IconPicker - > currentItem ( ) ;
entry - > ImageID = Combo_IconPicker - > currentItem ( ) ;
done ( 1 ) ;
done ( 1 ) ;
@ -182,7 +194,7 @@ done(1);
void CEditEntryDlg : : OnButtonCancel ( )
void CEditEntryDlg : : OnButtonCancel ( )
{
{
entry - > LastAccess . SetToNow ( ) ;
entry - > LastAccess = QDateTime : : currentDateTime ( ) ;
done ( 0 ) ;
done ( 0 ) ;
}
}
@ -207,7 +219,7 @@ Edit_Password_w->setText("");
int bits = ( Edit_Password - > text ( ) . length ( ) * 8 ) ;
int bits = ( Edit_Password - > text ( ) . length ( ) * 8 ) ;
Label_Bits - > setText ( QString : : number ( bits ) + " Bit " ) ;
Label_Bits - > setText ( QString : : number ( bits ) + " Bit " ) ;
if ( bits > 128 ) bits = 128 ;
if ( bits > 128 ) bits = 128 ;
Progress_Quali - > setProgress ( bits , 128 ) ;
Progress_Quali - > setValue ( 100 * bits / 128 ) ;
}
}
void CEditEntryDlg : : OnPasswordwTextChanged ( const QString & w )
void CEditEntryDlg : : OnPasswordwTextChanged ( const QString & w )
@ -237,30 +249,6 @@ Edit_Password_w->setPaletteBackgroundColor(QColor(255,255,255)); ///@FIXME Stand
}
}
void CEditEntryDlg : : OnExpDateLostFocus ( )
{
QString str = Edit_Expire_Date - > text ( ) ;
if ( CPwmTime : : IsValidDate ( str ) = = false ) {
Edit_Expire_Date - > setPaletteBackgroundColor ( QColor ( 255 , 125 , 125 ) ) ;
}
else
{
Edit_Expire_Date - > setPaletteBackgroundColor ( QColor ( 255 , 255 , 255 ) ) ; ///@FIXME Standart-Hintergrundfarbe nicht weiß
}
}
void CEditEntryDlg : : OnExpTimeLostFocus ( )
{
QString str = Edit_Expire_Time - > text ( ) ;
if ( CPwmTime : : IsValidTime ( str ) = = false ) {
Edit_Expire_Time - > setPaletteBackgroundColor ( QColor ( 255 , 125 , 125 ) ) ;
}
else
{
Edit_Expire_Time - > setPaletteBackgroundColor ( QColor ( 255 , 255 , 255 ) ) ; ///@FIXME Standart-Hintergrundfarbe nicht weiß
}
}
void CEditEntryDlg : : OnNewAttachment ( )
void CEditEntryDlg : : OnNewAttachment ( )
{
{
QString filename = Q3FileDialog : : getOpenFileName ( QDir : : homeDirPath ( ) , " " , this , QString : : fromUtf8 ( " Anhang hinzufügen... " ) ) ;
QString filename = Q3FileDialog : : getOpenFileName ( QDir : : homeDirPath ( ) , " " , this , QString : : fromUtf8 ( " Anhang hinzufügen... " ) ) ;
@ -355,12 +343,15 @@ pDlg->show();
}
}
void CEditEntryDlg : : OnCheckBoxExpiresNeverChanged ( int state ) {
if ( state = = Qt : : Unchecked ) {
DateTime_Expire - > setDisabled ( false ) ;
}
else
{
DateTime_Expire - > setDisabled ( true ) ;
}
}