-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 106 |
1 files changed, 19 insertions, 87 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index d55624b..43565ee 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -56,96 +56,100 @@ #ifndef WIN32 #include <qsettings.h> #else #include "qsettings.h" #endif #include <qapplication.h> #else #include <qfile.h> #include <qpe/fileselector.h> #include <qpe/global.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #endif #include <qtimer.h> #include <qlayout.h> #include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> #include <qheader.h> #include <qlistview.h> #include <qtoolbutton.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qimage.h> #include <qpixmap.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qregexp.h> #include <qdir.h> #include <qtextbrowser.h> #include <qlabel.h> #include <qcombobox.h> #include "krc2.h" #include "wait.h" extern int DeskW, DeskH; #ifdef DESKTOP extern QApplication *appl; #else extern QPEApplication *appl; #endif +#ifdef JPATCH_HDE +#define tr(arg) arg +#endif + #ifdef DESKTOP #ifndef WIN32 const QString APP_KEY="/.zsafe/"; #else const QString APP_KEY=""; #endif #else const QString APP_KEY=""; #endif // include xmp images #include "pics/zsafe/copy.xpm" #include "pics/zsafe/cut.xpm" #include "pics/zsafe/edit.xpm" #include "pics/zsafe/editdelete.xpm" #include "pics/zsafe/find.xpm" #include "pics/zsafe/folder_open.xpm" #include "pics/zsafe/help_icon.xpm" #include "pics/zsafe/new.xpm" #include "pics/zsafe/paste.xpm" #include "pics/zsafe/quit_icon.xpm" #include "pics/zsafe/save.xpm" #include "pics/zsafe/trash.xpm" #include "pics/zsafe/expand.xpm" #include "pics/zsafe/export.xpm" #include "pics/zsafe/import.xpm" #include "pics/zsafe/zsafe.xpm" static const char* const bank_cards_data[] = { "14 14 16 1", ". c None", "# c #000000", "b c #0000de", "a c #0000e6", "j c #41de83", "k c #4acecd", "h c #4aced5", "g c #5a40cd", "d c #5a44d5", "l c #9440d5", "m c #b4ce4a", "n c #cd4883", "e c #d5ae10", "f c #de3ce6", "i c #e640e6", "c c #ffffff", "..............", @@ -452,113 +456,121 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) #ifdef DESKTOP #ifdef WIN32 setGeometry(100, 150, DeskW, DeskH-30 ); #else resize( DeskW, DeskH-30 ); #endif #else #ifdef JPATCH_HDE int DeskS; if(DeskW > DeskH) { DeskS = DeskW; } else { DeskS = DeskH; } resize( DeskW, DeskH ); setMinimumSize( QSize( DeskS, DeskS ) ); setMaximumSize( QSize( DeskS, DeskS ) ); #else resize( DeskW, DeskH-30 ); #endif #endif // setCaption( tr( "ZSafe" ) ); filename = conf->readEntry(APP_KEY+"document"); if (filename.isEmpty() || filename.isNull()) { // check if the directory application exists, if not // create it // #ifndef WIN32 // QString d1("Documents/application"); // #else QString d1(QDir::homeDirPath() + "/Documents/application"); // #endif QDir pd1(d1); if (!pd1.exists()) { QDir pd1("Documents"); if (!pd1.mkdir("application", FALSE)) { QMessageBox::critical( 0, tr("ZSafe"), +#ifdef JPATCH_HDE + tr("Can't create directory\n.../Documents/application\n\nZSafe will now exit.")); +#else tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1)); +#endif exitZs (1); } } // #ifndef WIN32 // QString d2("Documents/application/zsafe"); // #else QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); // #endif QDir pd2(d2); if (!pd2.exists()) { QDir pd2("Documents/application"); if (!pd2.mkdir("zsafe", FALSE)) { QMessageBox::critical( 0, tr("ZSafe"), +#ifdef JPATCH_HDE + tr("Can't create directory\n...//Documents/application/zsafe\n\nZSafe will now exit.")); +#else tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2)); +#endif exitZs (1); } } // set the default filename filename=d2 + "/passwords.zsf"; // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); } //if (filename == "INVALIDPWD") //filename = ""; QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif selectedItem = NULL; lastSearchedCategory = NULL; lastSearchedItem = NULL; lastSearchedName = ""; lastSearchedUsername = ""; lastSearchedComment = ""; infoForm = new InfoForm(); categoryDialog = NULL; // add a menu bar QMenuBar *menu = new QMenuBar( this ); // add file menu // QPopupMenu *file = new QPopupMenu( this ); file = new QPopupMenu( this ); // #ifdef DESKTOP file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); file->insertSeparator(); // #endif file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); @@ -730,219 +742,187 @@ void ZSafe::deletePwd() } } void ZSafe::editPwd() { if (!selectedItem) return; if (!isCategory(selectedItem)) { // open the 'New Entry' dialog NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE); #ifdef WIN32 dialog->setCaption ("Qt " + tr("Edit Entry")); dialog->setGeometry(200, 250, 220, 310 ); #endif // set the labels dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); // set the fields dialog->NameField->setText(selectedItem->text (0)); dialog->UsernameField->setText(selectedItem->text (1)); dialog->PasswordField->setText(selectedItem->text (2)); QString comment = selectedItem->text (3); comment.replace (QRegExp("<br>"), "\n"); dialog->Field5->setText(selectedItem->text (4)); dialog->Field6->setText(selectedItem->text (5)); dialog->CommentField->insertLine(comment); dialog->CommentField->setCursorPosition(0,0); #ifdef DESKTOP #ifndef WIN32 dialog->show(); #endif #else dialog->showMaximized(); #endif DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif if (result == Accepted) { -#ifdef JPATCH_HDE - // edit the selected item - QString name = dialog->NameField->text(); - selectedItem->setText (0, name); - QString user = dialog->UsernameField->text(); - selectedItem->setText (1, user); - QString pwd = dialog->PasswordField->text(); - selectedItem->setText (2, pwd); - QString comment = dialog->CommentField->text(); - comment.replace (QRegExp("\n"), "<br>"); - selectedItem->setText (3, comment); - QString f5 = dialog->Field5->text(); - selectedItem->setText (4, f5); - QString f6 = dialog->Field6->text(); - selectedItem->setText (5, f6); -#else modified = true; // edit the selected item QString name = dialog->NameField->text(); selectedItem->setText (0, tr (name)); QString user = dialog->UsernameField->text(); selectedItem->setText (1, tr (user)); QString pwd = dialog->PasswordField->text(); selectedItem->setText (2, tr (pwd)); QString comment = dialog->CommentField->text(); comment.replace (QRegExp("\n"), "<br>"); selectedItem->setText (3, tr (comment)); QString f5 = dialog->Field5->text(); selectedItem->setText (4, tr (f5)); QString f6 = dialog->Field6->text(); selectedItem->setText (5, tr (f6)); -#endif } delete dialog; } else { editCategory(); } } void ZSafe::newPwd() { if (!selectedItem) return; if (!isCategory(selectedItem)) selectedItem = selectedItem->parent(); if (isCategory(selectedItem)) { QString cat = selectedItem->text(0); // open the 'New Entry' dialog NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE); #ifdef WIN32 dialog->setCaption ("Qt " + tr("New Entry")); dialog->setGeometry(200, 250, 220, 310 ); #endif // set the labels dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); retype: #ifdef DESKTOP #ifndef WIN32 dialog->show(); #endif #else dialog->showMaximized(); #endif DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif if (result == Accepted) { QString name = dialog->NameField->text(); if (cat == name) { QMessageBox::critical( 0, tr("ZSafe"), tr("Entry name must be different\nfrom the category name.") ); goto retype; // it's not a good programming style :-) } modified = true; // add the new item QListViewItem *i = new ShadedListItem (0, selectedItem); i->setOpen (TRUE); -#ifdef JPATCH_HDE - i->setText (0, name); - QString user = dialog->UsernameField->text(); - i->setText (1, user); - QString pwd = dialog->PasswordField->text(); - i->setText (2, pwd); - QString comment = dialog->CommentField->text(); - comment.replace (QRegExp("\n"), "<br>"); - i->setText (3, comment); - QString f5 = dialog->Field5->text(); - i->setText (4, f5); - QString f6 = dialog->Field6->text(); - i->setText (5, f6); -#else i->setText (0, tr (name)); QString user = dialog->UsernameField->text(); i->setText (1, tr (user)); QString pwd = dialog->PasswordField->text(); i->setText (2, tr (pwd)); QString comment = dialog->CommentField->text(); comment.replace (QRegExp("\n"), "<br>"); i->setText (3, tr (comment)); QString f5 = dialog->Field5->text(); i->setText (4, tr (f5)); QString f6 = dialog->Field6->text(); i->setText (5, tr (f6)); -#endif } delete dialog; } } void ZSafe::findPwd() { // open the 'Search' dialog SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); #ifdef WIN32 dialog->setCaption ("Qt " + tr("Search")); #endif #ifdef DESKTOP #endif if (lastSearchedName) dialog->NameField->setText(lastSearchedName); else dialog->NameField->setText(""); if (lastSearchedUsername) dialog->UsernameField->setText(lastSearchedUsername); else dialog->UsernameField->setText(""); if (lastSearchedComment) dialog->CommentField->setText(lastSearchedComment); else dialog->CommentField->setText(""); DialogCode result = (DialogCode) dialog->exec(); #ifdef DESKTOP result = Accepted; #endif QString name; QString username; QString comment; if (result == Accepted) { name = dialog->NameField->text(); username = dialog->UsernameField->text(); comment = dialog->CommentField->text(); qWarning (name); } else { delete dialog; return; @@ -1500,134 +1480,117 @@ void ZSafe::readAllEntries() int idx=0; while ((i = strtok (NULL, "|")) != NULL) { switch (idx) { case 0: name = QString::fromUtf8(&i[1]); name.truncate(name.length() -1); // name break; case 1: // user user = QString::fromUtf8(&i[1]); user.truncate(user.length() -1); break; case 2: // password password = QString::fromUtf8(&i[1]); password.truncate(password.length() -1); break; case 3: // comment comment = QString::fromUtf8(&i[1]); comment.truncate(comment.length() -1); break; case 4: // field5 field5 = QString::fromUtf8(&i[1]); field5.truncate(field5.length() -1); break; case 5: // field6 field6 = QString::fromUtf8(&i[1]); field6.truncate(field6.length() -1); break; } idx++; } Category *cat= categories.find (category); if (cat) { // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); - item->setText( 4, field5 ); - item->setText( 5, field6 ); -#else item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); catItem->setOpen( TRUE ); -#endif } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); - item->setText( 4, field5 ); - item->setText( 5, field6 ); -#else item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); -#endif + catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); if (pix) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); } } f.close(); } else { } } #ifdef UNUSED void ZSafe::writeAllEntries() { @@ -1737,126 +1700,114 @@ void ZSafe::readAllEntries() QString name; QString user; QString password; QString comment; // separete the entries char *i = strtok (buffer, "|"); QString category(&i[1]); category.truncate(category.length() -1); int idx=0; while (i = strtok (NULL, "|")) { switch (idx) { case 0: name = &i[1]; name.truncate(name.length() -1); // name break; case 1: // user user = &i[1]; user.truncate(user.length() -1); break; case 2: // password password = &i[1]; password.truncate(password.length() -1); break; case 3: // comment comment = &i[1]; comment.truncate(comment.length() -1); break; } idx++; } Category *cat= categories.find (category); if (cat) { // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); -#else item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); -#endif + catItem->setOpen( TRUE ); } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); -#else item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); -#endif + catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); if (pix) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); } } f.close(); } #endif // UNUSED void ZSafe::resume(int) { qWarning ("Resume"); // hide the main window infoForm->hide(); // open zsafe again @@ -1964,136 +1915,121 @@ bool ZSafe::openDocument(const char* _filename, const char* ) { switch( QMessageBox::warning( this, tr("ZSafe"), tr("Wrong password.\nEnter again?"), tr("&Yes"), tr("&No."), 0 ) ) { case 1: // No exitZs (1); break; case 0: // Yes continue; } } } if (pwdOk == 0) { // unset the document entry conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); if (conf) delete conf; exitZs (1); } retval = loadEntry(entry); int numberOfEntries=0; while (retval == 1) { QString category( QString::fromUtf8(entry[0]) ); QString name( QString::fromUtf8(entry[1]) ); QString user( QString::fromUtf8(entry[2]) ); QString password( QString::fromUtf8(entry[3]) ); QString comment( QString::fromUtf8(entry[4]) ); QString field5( QString::fromUtf8(entry[5]) ); QString field6( QString::fromUtf8(entry[6]) ); // add the subitems to the categories Category *cat= categories.find (category); if (cat) { // use the existend item QListViewItem *catItem = cat->getListItem(); if (catItem) { QListViewItem * item = new ShadedListItem( 0, catItem ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); - item->setText( 4, field5 ); - item->setText( 5, field6 ); -#else item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); -#endif + if (expandTree) catItem->setOpen( TRUE ); numberOfEntries++; } } else { QListViewItem *catI = new ShadedListItem( 1, ListView ); // create and insert a new item QListViewItem * item = new ShadedListItem( 0, catI ); -#ifdef JPATCH_HDE - item->setText( 0, name ); - item->setText( 1, user ); - item->setText( 2, password ); - item->setText( 3, comment ); - item->setText( 4, field5 ); - item->setText( 5, field6 ); -#else + item->setText( 0, tr( name ) ); item->setText( 1, tr( user ) ); item->setText( 2, tr( password ) ); item->setText( 3, tr( comment ) ); item->setText( 4, tr( field5 ) ); item->setText( 5, tr( field6 ) ); -#endif + if (expandTree) catI->setOpen( TRUE ); Category *c1 = new Category(); c1->setCategoryName(category); QString icon; QString fullIconPath; QPixmap *pix; // #ifndef WIN32 icon = conf->readEntry(APP_KEY+category); // #endif bool isIconAv = false; if (!icon.isEmpty() && !icon.isNull()) { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); if (pix) { QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); c1->setIconName (icon); c1->setIcon (*pix); isIconAv = true; } } if (!isIconAv) { c1->setIcon (*getPredefinedIcon(category)); } c1->setListItem (catI); c1->initListItem(); categories.insert (c1->getCategoryName(), c1); numberOfEntries++; } for (int count = 0; count < FIELD_SIZE; count++) { free(entry[count]); } retval = loadEntry(entry); if (retval == 2) { // m_parent->slotStatusHelpMsg("Last entry loaded"); } } // end while if (numberOfEntries == 0) @@ -3258,103 +3194,99 @@ void ZSafe::editCategory() { categories.remove (category); // #ifndef WIN32 conf->removeEntry(category); // #endif saveConf(); } category = dialog->CategoryField->currentText(); icon = dialog->IconField->currentText()+".png"; if (cat) { qWarning("Category found"); // if (!icon.isEmpty() && !icon.isNull()) if (icon != "predefined.png") { // build the full path fullIconPath = iconPath + icon; pix = new QPixmap (fullIconPath); if (pix) { // save the full pixmap name into the config file // #ifndef WIN32 conf->writeEntry(APP_KEY+category, icon); // #endif saveConf(); QImage img = pix->convertToImage(); pix->convertFromImage(img.smoothScale(14,14)); cat->setIconName (icon); cat->setIcon (*pix); } } else { // #ifndef WIN32 conf->removeEntry (category); // #endif saveConf(); cat->setIcon (*getPredefinedIcon(category)); } // change the category name of the selected category QListViewItem *catItem = cat->getListItem(); if (catItem) { qWarning (category); -#ifdef JPATCH_HDE - catItem->setText( 0, category ); - cat->setCategoryName (category); -#else catItem->setText( 0, tr( category ) ); cat->setCategoryName (tr(category)); -#endif + cat->initListItem(); categories.insert (category, cat); } } saveCategoryDialogFields(dialog); } else { // delete dialog; dialog->hide(); return; } } } void ZSafe::cutItem() { if (!selectedItem) return; if (!isCategory(selectedItem)) { IsCut = true; copiedItem = selectedItem; } } void ZSafe::copyItem() { if (!selectedItem) return; if (!isCategory(selectedItem)) { IsCopy = true; copiedItem = selectedItem; } } // paste item into category void ZSafe::pasteItem() { if (!selectedItem) return; if (isCategory(selectedItem)) { modified = true; if (IsCut) { |