author | ulf69 <ulf69> | 2004-10-29 05:20:48 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-29 05:20:48 (UTC) |
commit | 41e3625b8c38ff45e70b59416a519d59a5f4d937 (patch) (side-by-side diff) | |
tree | 587b57d51bc77a699fd63cf10e53bf6f9f72a1b7 /pwmanager | |
parent | 08a4582f8e5184b8abb7d97781c4fc37ee7edf90 (diff) | |
download | kdepimpi-41e3625b8c38ff45e70b59416a519d59a5f4d937.zip kdepimpi-41e3625b8c38ff45e70b59416a519d59a5f4d937.tar.gz kdepimpi-41e3625b8c38ff45e70b59416a519d59a5f4d937.tar.bz2 |
display alternating category text in the add/edit dialogbox
-rw-r--r-- | pwmanager/pwmanager/addentrywnd_emb.cpp | 45 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywnd_emb.h | 8 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywndimpl.cpp | 7 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywndimpl.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 4 |
5 files changed, 51 insertions, 15 deletions
diff --git a/pwmanager/pwmanager/addentrywnd_emb.cpp b/pwmanager/pwmanager/addentrywnd_emb.cpp index dd09d13..f065058 100644 --- a/pwmanager/pwmanager/addentrywnd_emb.cpp +++ b/pwmanager/pwmanager/addentrywnd_emb.cpp @@ -1,140 +1,143 @@ /* This file is part of PwManager/Platform independent. Copyright (c) 2004 Ulf Schenk 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. $Id$ */ #include "addentrywnd_emb.h" +#include "pwmdoc.h" #include <qlayout.h> #include <qlabel.h> #include <qtabwidget.h> #include <qgroupbox.h> #include <klocale.h> #include <kcombobox.h> #include <klineedit.h> #include <qpushbutton.h> #include <qmultilineedit.h> /* * Constructs a addEntryWnd as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ -addEntryWnd::addEntryWnd( QWidget* parent, const char* name) +addEntryWnd::addEntryWnd( PwMDoc* d, QWidget* parent, const char* name) : KDialogBase( KDialogBase::Plain, i18n( "edit/add a password entry" ), KDialogBase::Ok | KDialogBase::Cancel, - KDialogBase::Ok, parent, name, true ) + KDialogBase::Ok, parent, name, true ), doc(d) { QWidget *page = plainPage(); QVBoxLayout *pageLayout = new QVBoxLayout( page ); QTabWidget* mTabWidget = new QTabWidget( page ); pageLayout->addWidget( mTabWidget ); //////////////////////////////////////////////////////////////////// // This is the Password tab QWidget *tab1 = new QWidget( mTabWidget ); QGridLayout *layout = new QGridLayout( tab1, 3, 1 ); layout->setMargin( KDialogBase::marginHint() ); layout->setSpacing( KDialogBase::spacingHint() ); int i = 0; descLineEdit = new KLineEdit( tab1, "descLineEdit" ); - QLabel* label = new QLabel( descLineEdit, i18n("Description:"), tab1 ); - layout->addWidget( label, i, 0 ); + descLineLabel = new QLabel( descLineEdit, i18n("Description:"), tab1 ); + layout->addWidget( descLineLabel, i, 0 ); layout->addWidget( descLineEdit, i, 1 ); i++; categoryComboBox = new KComboBox( tab1 ); - label = new QLabel( categoryComboBox, i18n("Category:"), tab1 ); + QLabel* label = new QLabel( categoryComboBox, i18n("Category:"), tab1 ); layout->addWidget( label, i, 0 ); layout->addWidget( categoryComboBox, i, 1 ); i++; categoryComboBox->setEditable( TRUE ); categoryComboBox->setSizeLimit( 100 ); categoryComboBox->setAutoCompletion( TRUE ); categoryComboBox->setDuplicatesEnabled( FALSE ); + connect(categoryComboBox,SIGNAL(activated(const QString&)), SLOT(categorySelected(const QString&))); + usernameLineEdit = new KLineEdit( tab1, "usernameLineEdit" ); - label = new QLabel( usernameLineEdit, i18n("Username:"), tab1 ); - layout->addWidget( label, i, 0 ); + usernameLineLabel = new QLabel( usernameLineEdit, i18n("Username:"), tab1 ); + layout->addWidget( usernameLineLabel, i, 0 ); layout->addWidget( usernameLineEdit, i, 1 ); i++; pwLineEdit = new KLineEdit( tab1, "pwLineEdit" ); pwLineEdit->setEchoMode( QLineEdit::Password ); - label = new QLabel( pwLineEdit, i18n("Password:"), tab1 ); - layout->addWidget( label, i, 0 ); + pwLineLabel = new QLabel( pwLineEdit, i18n("Password:"), tab1 ); + layout->addWidget( pwLineLabel, i, 0 ); layout->addWidget( pwLineEdit, i, 1 ); i++; revealButton = new QPushButton( i18n("&Reveal"), tab1, "revealButton" ); revealButton->setToggleButton( TRUE ); layout->addWidget( revealButton, i, 0 ); generateButton = new QPushButton( i18n("&Generate"), tab1, "generateButton" ); layout->addWidget( generateButton, i, 1 ); i++; urlLineEdit = new KLineEdit( tab1, "urlLineEdit" ); label = new QLabel( urlLineEdit, i18n("URL:"), tab1 ); layout->addWidget( label, i, 0 ); layout->addWidget( urlLineEdit, i, 1 ); i++; mTabWidget->addTab( tab1, i18n( "&Password" ) ); //////////////////////////////////////////////////////////////////// // This is the Comment tab QWidget *tab2 = new QWidget( mTabWidget ); layout = new QGridLayout( tab2, 3, 1 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); i = 0; commentTextEdit = new QMultiLineEdit(tab2); layout->addMultiCellWidget( commentTextEdit, i, i, 0, 0 ); i++; mTabWidget->addTab( tab2, i18n( "&Comments" ) ); //////////////////////////////////////////////////////////////////// // This is the Launcher tab QWidget *tab3 = new QWidget( mTabWidget ); layout = new QGridLayout( tab3, 3, 1 ); layout->setMargin( KDialogBase::marginHintSmall() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); i = 0; launcherLineEdit = new KLineEdit( tab3, "launcherLineEdit" ); label = new QLabel( launcherLineEdit, i18n("Launcher:"), tab3 ); @@ -151,49 +154,73 @@ addEntryWnd::addEntryWnd( QWidget* parent, const char* name) layout->addWidget( label2, i, 1 ); i++; layout->addWidget( label3, i, 0 ); layout->addWidget( label4, i, 1 ); i++; layout->addWidget( label5, i, 0 ); i++; layout->addWidget( label, i, 0 ); layout->addWidget( launcherLineEdit, i, 1 ); i++; mTabWidget->addTab( tab3, i18n( "&Launcher" ) ); // signals and slots connections connect( generateButton, SIGNAL( clicked() ), this, SLOT( generateButton_slot() ) ); connect( revealButton, SIGNAL( toggled(bool) ), this, SLOT( revealButton_slot() ) ); } /* * Destroys the object and frees any allocated resources */ addEntryWnd::~addEntryWnd() { // no need to delete child widgets, Qt does it all for us } void addEntryWnd::slotOk() { qWarning( "addEntryWnd::slotOk(): Not implemented yet" ); } void addEntryWnd::revealButton_slot() { qWarning( "addEntryWnd::revealButton_slot(): Not implemented yet" ); } void addEntryWnd::generateButton_slot() { qWarning( "addEntryWnd::generateButton_slot(): Not implemented yet" ); } void addEntryWnd::advancedCommentButton_slot(bool) { qWarning( "addEntryWnd::advancedCommentButton_slot(bool): Not implemented yet" ); } +void addEntryWnd::categorySelected ( const QString & string ) +{ + unsigned int idx; + bool found = doc->findCategory(string, &idx); + + if (found == true) + { + qDebug("addEntryWnd::categorySelected found"); + PwMCategoryItem* catitem = doc->getCategoryEntry(idx); + + descLineLabel->setText(catitem->desc_text.c_str()); + usernameLineLabel->setText(catitem->name_text.c_str()); + pwLineLabel->setText(catitem->pw_text.c_str()); + return; + } + else + { + qDebug("addEntryWnd::categorySelected NOT found"); + BUG(); + } + + +} + diff --git a/pwmanager/pwmanager/addentrywnd_emb.h b/pwmanager/pwmanager/addentrywnd_emb.h index 83761dc..966d9d2 100644 --- a/pwmanager/pwmanager/addentrywnd_emb.h +++ b/pwmanager/pwmanager/addentrywnd_emb.h @@ -1,72 +1,78 @@ /* This file is part of PwManager/Platform independent. Copyright (c) 2004 Ulf Schenk 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. $Id$ */ #ifndef ADDENTRYWND_EMB_H #define ADDENTRYWND_EMB_H #include <qvariant.h> #include <kdialogbase.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QSpacerItem; class KLineEdit; class QPushButton; class KComboBox; class QLabel; class QGroupBox; class QMultiLineEdit; +class PwMDoc; class addEntryWnd : public KDialogBase { Q_OBJECT public: - addEntryWnd( QWidget* parent = 0, const char* name = 0); + addEntryWnd( PwMDoc* doc, QWidget* parent = 0, const char* name = 0); ~addEntryWnd(); KLineEdit* launcherLineEdit; QPushButton* generateButton; KLineEdit* descLineEdit; KComboBox* categoryComboBox; KLineEdit* usernameLineEdit; KLineEdit* pwLineEdit; KLineEdit* urlLineEdit; + QLabel* descLineLabel; + QLabel* usernameLineLabel; + QLabel* pwLineLabel; QPushButton* revealButton; QMultiLineEdit* commentTextEdit; + PwMDoc* doc; public slots: virtual void revealButton_slot(); virtual void generateButton_slot(); virtual void advancedCommentButton_slot(bool on); protected slots: virtual void slotOk(); + virtual void categorySelected ( const QString & string ); }; #endif // ADDENTRYWND_H diff --git a/pwmanager/pwmanager/addentrywndimpl.cpp b/pwmanager/pwmanager/addentrywndimpl.cpp index d47f32c..fa6b6c0 100644 --- a/pwmanager/pwmanager/addentrywndimpl.cpp +++ b/pwmanager/pwmanager/addentrywndimpl.cpp @@ -1,165 +1,168 @@ /*************************************************************************** * * * copyright (C) 2003, 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * Many very good improvements and the original implementations of * * them came from Matt Scifo <mscifo@o1.com> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #include "addentrywndimpl.h" #include "pwmexception.h" #include "pwgenwndimpl.h" #ifndef PWM_EMBEDDED #include "advcommeditimpl.h" #endif #include "htmlgen.h" #include <kmessagebox.h> #include <klocale.h> #include <qpushbutton.h> #include <qlabel.h> #include <qlayout.h> #ifndef PWM_EMBEDDED AddEntryWndImpl::AddEntryWndImpl() : addEntryWnd( 0, "AddEntryWndImpl", TRUE) #else -AddEntryWndImpl::AddEntryWndImpl( QWidget* parent, const char* name) - : addEntryWnd( parent, name) +AddEntryWndImpl::AddEntryWndImpl( PwMDoc* doc, QWidget* parent, const char* name) + : addEntryWnd( doc, parent, name) #endif { #ifndef PWM_EMBEDDED editAdvCommentButton = 0; commentTextEdit = 0; #endif switchComment(false); pwGen = new PwGenWndImpl(this); } AddEntryWndImpl::~AddEntryWndImpl() { #ifndef PWM_EMBEDDED delete_ifnot_null(editAdvCommentButton); delete_ifnot_null(commentTextEdit); #endif delete pwGen; } #ifdef PWM_EMBEDDED void AddEntryWndImpl::slotOk() { slotApply(); if (pwLineEdit->text().isEmpty()) { KMessageBox::error(this, i18n("Sorry, you haven't set a password."), i18n("no password")); return; } if (descLineEdit->text().isEmpty()) { KMessageBox::error(this, i18n("You haven't set a \"Description\"."), i18n("Description not set")); return; } KDialogBase::slotOk(); } #else void AddEntryWndImpl::okButton_slot() { if (pwLineEdit->text().isEmpty()) { KMessageBox::error(this, i18n("Sorry, you haven't set a password."), i18n("no password")); return; } if (descLineEdit->text().isEmpty()) { KMessageBox::error(this, i18n ("You haven't set a \"Description\"."), i18n("Description not set")); return; } done(1); } void AddEntryWndImpl::cancelButton_slot() { done(2); } #endif void AddEntryWndImpl::setCurrCategory(const QString &cat) { int i, count = categoryComboBox->count(); for (i = 0; i < count; ++i) { if (categoryComboBox->text(i) == cat) { categoryComboBox->setCurrentItem(i); +#ifdef PWM_EMBEDDED + categorySelected(cat); +#endif return; } } BUG(); } void AddEntryWndImpl::revealButton_slot() { if (revealButton->isOn()) { pwLineEdit->setEchoMode(QLineEdit::Normal); } else { pwLineEdit->setEchoMode(QLineEdit::Password); } } void AddEntryWndImpl::generateButton_slot() { if (!pwGen->exec()) return; setPassword(pwGen->getPassword()); } QString AddEntryWndImpl::getComment() { #ifndef PWM_EMBEDDED if (isAdvancedComment()) { return advCommentDta; } #endif return commentTextEdit->text(); } void AddEntryWndImpl::setComment(const QString &comm) { #ifndef PWM_EMBEDDED if (HtmlGen::isHtml(comm)) { advancedCommentButton->setOn(true); advCommentDta = comm; } else { advancedCommentButton->setOn(false); commentTextEdit->setText(comm); } #else commentTextEdit->setText(comm); #endif } void AddEntryWndImpl::advancedCommentButton_slot(bool on) diff --git a/pwmanager/pwmanager/addentrywndimpl.h b/pwmanager/pwmanager/addentrywndimpl.h index ce9a594..e13eb54 100644 --- a/pwmanager/pwmanager/addentrywndimpl.h +++ b/pwmanager/pwmanager/addentrywndimpl.h @@ -1,96 +1,96 @@ /*************************************************************************** * * * copyright (C) 2003, 2004 by Michael Buesch * * email: mbuesch@freenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License version 2 * * as published by the Free Software Foundation. * * * ***************************************************************************/ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk * This file is originaly based on version 1.0.1 of pwmanager * and was modified to run on embedded devices that run microkde * * $Id$ **************************************************************************/ #ifndef __ADDENTRYWNDIMPL_H #define __ADDENTRYWNDIMPL_H #ifndef PWM_EMBEDDED #include <qlineedit.h> #include <qtextedit.h> #include <qcombobox.h> #include "addentrywnd.h" #else #include <klineedit.h> #include <kcombobox.h> #include <qmultilineedit.h> #include "addentrywnd_emb.h" #endif #include <qpushbutton.h> class PwGenWndImpl; /** "add/edit" Window */ class AddEntryWndImpl : public addEntryWnd { Q_OBJECT public: #ifndef PWM_EMBEDDED AddEntryWndImpl(); #else - AddEntryWndImpl( QWidget* parent = 0, const char* name = 0); + AddEntryWndImpl( PwMDoc* doc, QWidget* parent = 0, const char* name = 0); #endif ~AddEntryWndImpl(); /* get... functions */ QString getDescription() { return descLineEdit->text(); } QString getCategory() { return categoryComboBox->currentText(); } QString getUsername() { return usernameLineEdit->text(); } QString getPassword() { return pwLineEdit->text(); } QString getUrl() { return urlLineEdit->text(); } QString getLauncher() { return launcherLineEdit->text(); } QString getComment(); /* set... functions */ void setDescription(const QString &desc) { descLineEdit->setText(desc); } void setCurrCategory(const QString &cat); void addCategory(const QString &cat) { categoryComboBox->insertItem(cat); } void setUsername(const QString &name) { usernameLineEdit->setText(name); } void setPassword(const QString &pw) { pwLineEdit->setText(pw); } void setUrl(const QString &url) { urlLineEdit->setText(url); } void setLauncher(const QString launcher) { launcherLineEdit->setText(launcher); } void setComment(const QString &comm); /** are we using an advanced comment */ bool isAdvancedComment() { return useAdvComment; } public slots: #ifndef PWM_EMBEDDED //MOC_SKIP_BEGIN /** OK button pressed */ void okButton_slot(); /** cancel button pressed */ void cancelButton_slot(); //MOC_SKIP_END #else virtual void slotOk(); diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index bd98d72..9642a43 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp @@ -588,97 +588,97 @@ void PwM::quitButton_slot() void PwM::save_slot() { save(); } bool PwM::save() { if (!curDoc()->saveDocUi(curDoc())) return false; showStatMsg(i18n("Successfully saved data.")); updateCaption(); return true; } void PwM::saveAs_slot() { saveAs(); } bool PwM::saveAs() { if (!curDoc()->saveAsDocUi(curDoc())) return false; showStatMsg(i18n("Successfully saved data.")); updateCaption(); return true; } //US ENH : changed code to run with older MOC void PwM::addPwd_slot() { addPwd_slot1(0, 0); } void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) { PwMDoc *doc; if (_doc) { doc = _doc; } else { doc = curDoc(); } PWM_ASSERT(doc); doc->timer()->getLock(DocTimer::id_autoLockTimer); #ifndef PWM_EMBEDDED AddEntryWndImpl w; #else - AddEntryWndImpl w(this, "addentrywndimpl"); + AddEntryWndImpl w(doc, this, "addentrywndimpl"); #endif vector<string> catList; doc->getCategoryList(&catList); unsigned i, size = catList.size(); for (i = 0; i < size; ++i) { w.addCategory(catList[i].c_str()); } w.setCurrCategory(view->getCurrentCategory()); if (pw) w.pwLineEdit->setText(*pw); tryAgain: if (w.exec() == 1) { PwMDataItem d; //US BUG: to initialize all values of curEntr with meaningfulldata, // we call clear on it. Reason: Metadata will be uninitialized otherwise. // another option would be to create a constructor for PwMDataItem d.clear(true); d.desc = w.getDescription().latin1(); d.name = w.getUsername().latin1(); d.pw = w.getPassword().latin1(); d.comment = w.getComment().latin1(); d.url = w.getUrl().latin1(); d.launcher = w.getLauncher().latin1(); PwMerror ret = doc->addEntry(w.getCategory(), &d); if (ret == e_entryExists) { KMessageBox::error(this, i18n ("An entry with this \"Description\",\n" "does already exist.\n" "Please select another description."), i18n("entry already exists.")); goto tryAgain; } else if (ret == e_maxAllowedEntr) { KMessageBox::error(this, i18n("The maximum possible number of\nentries" "has been reached.\nYou can't add more entries."), i18n("maximum number of entries")); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } setVirgin(false); doc->timer()->putLock(DocTimer::id_autoLockTimer); } @@ -687,97 +687,97 @@ void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) void PwM::editPwd_slot() { editPwd_slot3(0,0,0); } void PwM::editPwd_slot1(const QString *category) { editPwd_slot3(category, 0, 0); } void PwM::editPwd_slot3(const QString *category, const int *index, PwMDoc *_doc) { PwMDoc *doc; if (_doc) { doc = _doc; } else { doc = curDoc(); } PWM_ASSERT(doc); if (doc->isDocEmpty()) return; if (doc->isDeepLocked()) return; doc->timer()->getLock(DocTimer::id_autoLockTimer); unsigned int curEntryIndex; if (index) { curEntryIndex = *index; } else { if (!(view->getCurEntryIndex(&curEntryIndex))) { printDebug("couldn't get index. Maybe we have a binary entry here."); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } QString curCategory; if (category) { curCategory = *category; } else { curCategory = view->getCurrentCategory(); } PwMDataItem currItem; if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } BUG_ON(currItem.binary); - AddEntryWndImpl w; + AddEntryWndImpl w(doc); vector<string> catList; doc->getCategoryList(&catList); unsigned i, size = catList.size(); for (i = 0; i < size; ++i) { w.addCategory(catList[i].c_str()); } w.setCurrCategory(curCategory); w.setDescription(currItem.desc.c_str()); w.setUsername(currItem.name.c_str()); w.setPassword(currItem.pw.c_str()); w.setUrl(currItem.url.c_str()); w.setLauncher(currItem.launcher.c_str()); w.setComment(currItem.comment.c_str()); if (w.exec() == 1) { currItem.desc = w.getDescription().latin1(); currItem.name = w.getUsername().latin1(); currItem.pw = w.getPassword().latin1(); currItem.comment = w.getComment().latin1(); currItem.url = w.getUrl().latin1(); currItem.launcher = w.getLauncher().latin1(); if (!doc->editEntry(curCategory, w.getCategory(), curEntryIndex, &currItem)) { KMessageBox::error(this, i18n("Couldn't edit the entry.\n" "Maybe you changed the category and\n" "this entry is already present\nin the new " "category?"), i18n("couldn't edit entry.")); doc->timer()->putLock(DocTimer::id_autoLockTimer); return; } } doc->timer()->putLock(DocTimer::id_autoLockTimer); } void PwM::deletePwd_slot() { PWM_ASSERT(curDoc()); if (curDoc()->isDocEmpty()) return; if (curDoc()->isDeepLocked()) return; curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); unsigned int curEntryIndex = 0; if (!(view->getCurEntryIndex(&curEntryIndex))) { printDebug("couldn't get index"); curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); return; |