author | zcarsten <zcarsten> | 2003-08-14 07:10:23 (UTC) |
---|---|---|
committer | zcarsten <zcarsten> | 2003-08-14 07:10:23 (UTC) |
commit | 1ff9232b95b7f8ea0d841a3b9219eaa7e82f1d62 (patch) (side-by-side diff) | |
tree | 953026506eca01ba05fbee7a97e6c321750587f0 | |
parent | 7812d22080064f97d964dcbc3b085fde586a97d7 (diff) | |
download | opie-1ff9232b95b7f8ea0d841a3b9219eaa7e82f1d62.zip opie-1ff9232b95b7f8ea0d841a3b9219eaa7e82f1d62.tar.gz opie-1ff9232b95b7f8ea0d841a3b9219eaa7e82f1d62.tar.bz2 |
code clean up against previous version
-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 @@ -80,48 +80,52 @@ #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" @@ -476,65 +480,73 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) 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; @@ -754,80 +766,63 @@ void ZSafe::editPwd() // 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); @@ -850,75 +845,60 @@ retype: #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 @@ -1524,86 +1504,69 @@ void ZSafe::readAllEntries() 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; @@ -1761,78 +1724,66 @@ void ZSafe::readAllEntries() 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; @@ -1988,88 +1939,73 @@ bool ZSafe::openDocument(const char* _filename, const char* ) 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); @@ -3282,55 +3218,51 @@ void ZSafe::editCategory() // #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; |