-rw-r--r-- | noncore/apps/zsafe/config.in | 2 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 85 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.pro | 2 |
3 files changed, 85 insertions, 4 deletions
diff --git a/noncore/apps/zsafe/config.in b/noncore/apps/zsafe/config.in index 53956ad..4b1e968 100644 --- a/noncore/apps/zsafe/config.in +++ b/noncore/apps/zsafe/config.in @@ -1,5 +1,5 @@ config ZSAFE boolean "zsafe (Zaurus Password Manager)" default "y" - depends ( LIBQPE || LIBQPE-X11 ) + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index bd03031..abf6511 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -1,124 +1,129 @@ /**************************************************************************** ** ** Created: Sat Apr 6 17:57:45 2002 ** ** Author: Carsten Schneider <CarstenSchneider@t-online.de> ** ** $Id$ ** ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html ** ** Compile Flags: -** Zaurus arm : none +** Zaurus arm : -DNO_OPIE +** Zaurus Opie arm: none ** Linux Desktop : -DDESKTOP ** Windows Desktop: -DDESKTOP -DWIN32 ** ****************************************************************************/ #include "zsafe.h" #include "newdialog.h" #include "searchdialog.h" #include "categorydialog.h" #include "passworddialog.h" #include "infoform.h" #include "zlistview.h" #include "shadedlistitem.h" #ifndef DESKTOP +#ifndef NO_OPIE +#include <opie/ofiledialog.h> +#else #include "scqtfileedit.h" #endif +#endif #include <qclipboard.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #ifndef WIN32 #include <unistd.h> #endif #include <string.h> #include <errno.h> #include <qmenubar.h> #include <qpopupmenu.h> #ifdef DESKTOP #include <qfiledialog.h> #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 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" @@ -1102,329 +1107,368 @@ void ZSafe::showInfo( QListViewItem *_item) text += ":<br></b></u><blockquote>"; text += entry; text += "</blockquote>"; // text += "<br>"; } entry = selectedItem->text(2); if (!entry.isEmpty() && entry.compare(" ")) { text += "<u><b>"; text += getFieldLabel (selectedItem, "3", tr("Password")); text += ":<br> </b></u><blockquote>"; text += entry; text += "</blockquote>"; // text += "<br>"; } entry = selectedItem->text(4); if (!entry.isEmpty() && entry.compare(" ")) { text += "<u><b>"; text += getFieldLabel (selectedItem, "5", tr("Field 4")); text += ":<br> </b></u><blockquote>"; text += entry; text += "</blockquote>"; // text += "<br>"; } entry = selectedItem->text(5); if (!entry.isEmpty() && entry.compare(" ")) { text += "<u><b>"; text += getFieldLabel (selectedItem, "6", tr("Field 5")); text += ":<br> </b></u><blockquote>"; text += entry; text += "</blockquote>"; // text += "<br>"; } entry = selectedItem->text(3); if (!entry.isEmpty() && entry.compare(" ")) { text += "<u><b>"; text += getFieldLabel (selectedItem, "4", tr("Comment")); text += ":<br> </b></u>"; QString comment = selectedItem->text(3); comment.replace (QRegExp("\n"), "<br>"); text += comment; // text += "<br>"; } text += "</body></html>"; infoForm->InfoText->setText(text); infoForm->hide(); #ifdef DESKTOP infoForm->show(); #else infoForm->showMaximized(); #endif } } void ZSafe::listViewSelected( QListViewItem *_item) { if (!_item) return; if (selectedItem != NULL) selectedItem->setSelected(FALSE); selectedItem = _item; #ifndef DESKTOP // set the column text dependent on the selected item ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); #endif #ifdef WIN32 // set the column text dependent on the selected item ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); #endif } bool ZSafe::isCategory(QListViewItem *_item) { + if (_item == NULL) + return FALSE; + QString categoryName = _item->text (0); if (categories.find ((const char *)categoryName)) return TRUE; else return FALSE; } void ZSafe::removeAsciiFile() { // QString fn = filename + ".txt"; // open the file dialog #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("Text"), "text/*" ); + QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Remove text file")); +#else QString fn = ScQtFileEdit::getOpenFileName(this, tr ("Remove text file"), QDir::homeDirPath() + "/Documents/application/zsafe", "*.txt"); +#endif #else QString fn = QFileDialog::getOpenFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.txt)", this, "ZSafe File Dialog" "Choose a text file" ); #endif if (fn && fn.length() > 0 ) { QFile f( fn ); if ( !f.remove() ) { qWarning( QString("Could not remove file %1").arg(fn), 2000 ); QMessageBox::critical( 0, tr("ZSafe"), tr("Could not remove text file.") ); return; } } } void ZSafe::writeAllEntries() { if (filename.isEmpty()) { QMessageBox::critical( 0, tr("ZSafe"), tr("No document defined.\nYou have to create a new document")); return; } // open the file dialog #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("Text"), "text/*" ); + QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Export text file")); +#else QString fn = ScQtFileEdit::getSaveAsFileName(this, tr ("Export text file"), QDir::homeDirPath() + "/Documents/application/zsafe", "*.txt"); +#endif #else QString fn = QFileDialog::getSaveFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.txt)", this, "ZSafe File Dialog" "Choose a text file" ); #endif // open the new document if (fn && fn.length() > 0 ) { QFile f( fn ); if ( !f.open( IO_WriteOnly ) ) { qWarning( QString("Could not write to file %1").arg(fn), 2000 ); QMessageBox::critical( 0, "ZSafe", QString("Could not export to text file.") ); return; } QTextStream t( &f ); QListViewItem *i; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; si = si->nextSibling()) { QString oneEntry; oneEntry += "\""; oneEntry += i->text(0); oneEntry += "\";"; oneEntry += "\""; oneEntry += si->text(0); oneEntry += "\";"; oneEntry += "\""; oneEntry += si->text(1); oneEntry += "\";"; oneEntry += "\""; oneEntry += si->text(2); oneEntry += "\";"; oneEntry += "\""; QString comment = si->text(3); comment.replace (QRegExp("\n"), "<br>"); oneEntry += comment; oneEntry += "\";"; oneEntry += "\""; oneEntry += si->text(4); oneEntry += "\";"; oneEntry += "\""; oneEntry += si->text(5); oneEntry += "\""; // qWarning (oneEntry); t << oneEntry << endl; // qWarning (si->text(0)); } } f.close(); } } void ZSafe::readAllEntries() { if (filename.isEmpty()) { QMessageBox::critical( 0, tr("ZSafe"), tr("No document defined.\nYou have to create a new document")); return; } // open the file dialog #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("Text"), "text/*" ); + QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Import text file")); +#else QString fn = ScQtFileEdit::getOpenFileName(this, tr ("Import text file"), QDir::homeDirPath() + "/Documents/application/zsafe", "*.txt"); +#endif #else QString fn = QFileDialog::getOpenFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.txt)", this, "ZSafe File Dialog" "Choose a text file" ); #endif if (fn && fn.length() > 0 ) { QFile f( fn ); if ( !f.open( IO_ReadOnly ) ) { qWarning( QString("Could not read file %1").arg(fn), 2000 ); QMessageBox::critical( 0, "ZSafe", QString("Could not import text file.") ); return; } modified = true; // clear the password list selectedItem = NULL; QListViewItem *i; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; ) // si = si->nextSibling()) { QListViewItem *_si = si; si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } qWarning ("ReadAllEntries(): "); QTextStream t(&f); while ( !t.eof() ) { QString s = t.readLine(); s.replace (QRegExp("\";\""), "\"|\""); // char buffer[1024]; #ifndef WIN32 char buffer[s.length()+1]; #else char buffer[4048]; #endif strcpy (buffer, s); QString name; QString user; QString password; QString comment; QString field5=""; QString field6=""; // separete the entries char *i = strtok (buffer, "|"); QString category(&i[1]); category.truncate(category.length() -1); int idx=0; while ((i = strtok (NULL, "|")) != 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; @@ -3048,355 +3092,392 @@ void ZSafe::editCategory() { qWarning (category); catItem->setText( 0, tr( category ) ); cat->setCategoryName (tr(category)); 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) { if (copiedItem) { // add the new item QListViewItem *i = new ShadedListItem (0, selectedItem); // i->setOpen (TRUE); i->setText (0, copiedItem->text(0)); i->setText (1, copiedItem->text(1)); i->setText (2, copiedItem->text(2)); i->setText (3, copiedItem->text(3)); i->setText (4, copiedItem->text(4)); i->setText (5, copiedItem->text(5)); selectedItem->setOpen( TRUE ); // remove the cutted item copiedItem->parent()->takeItem(copiedItem); selectedItem = NULL; } } else if (IsCopy) { if (copiedItem) { // add the new item QListViewItem *i = new ShadedListItem (0, selectedItem); // i->setOpen (TRUE); i->setText (0, copiedItem->text(0)); i->setText (1, copiedItem->text(1)); i->setText (2, copiedItem->text(2)); i->setText (3, copiedItem->text(3)); i->setText (4, copiedItem->text(4)); i->setText (5, copiedItem->text(5)); selectedItem->setOpen( TRUE ); } } } IsCut = false; IsCopy = false; } void ZSafe::newDocument() { // open the file dialog #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); + QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Create new ZSafe document")); +#else QString newFile = ScQtFileEdit::getSaveAsFileName(this, tr ("Create new ZSafe document"), QDir::homeDirPath() + "/Documents/application/zsafe", "*.zsf"); +#endif #else QString newFile = QFileDialog::getSaveFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.zsf)", this, "ZSafe File Dialog" "Choose a ZSafe file" ); #endif // open the new document if (newFile && newFile.length() > 0 ) { // save the previous opened document if (!filename.isEmpty()) saveDocument(filename, FALSE); modified = true; // clear the password list QListViewItem *i; QListViewItem *c = NULL; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { if (c) delete c; // delete the previous category c = i; // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; ) { QListViewItem *_si = si; si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } if (c) delete c; // delete the previous category categories.clear(); // m_password = ""; - // selectedItem = NULL; + selectedItem = NULL; filename = newFile; // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif // openDocument(filename); QMessageBox::information( this, tr("ZSafe"), tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); saveDocumentWithPwd(); } } void ZSafe::loadDocument() { // open the file dialog #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); + QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Open ZSafe document")); +#else QString newFile = ScQtFileEdit::getOpenFileName(this, tr ("Open ZSafe document"), QDir::homeDirPath() + "/Documents/application/zsafe", "*.zsf"); +#endif #else QString newFile = QFileDialog::getOpenFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.zsf)", this, "ZSafe File Dialog" "Choose a ZSafe file" ); #endif // open the new document if (newFile && newFile.length() > 0 ) { // save the previous opened document if (!filename.isEmpty()) saveDocument(filename, FALSE); // clear the password list QListViewItem *i; QListViewItem *c = NULL; // step through all categories for (i = ListView->firstChild(); i != NULL; i = i->nextSibling()) { if (c) delete c; // delete the previous category c = i; // step through all subitems QListViewItem *si; for (si = i->firstChild(); si != NULL; ) { QListViewItem *_si = si; si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } if (c) delete c; // delete the previous category categories.clear(); m_password = ""; selectedItem = NULL; filename = newFile; // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif openDocument(filename); } } void ZSafe::saveDocumentAs() { #ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); + QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Save ZSafe document as..")); +#else QString newFile = ScQtFileEdit::getSaveAsFileName(this, tr ("Save ZSafe document as.."), QDir::homeDirPath() + "/Documents/application/zsafe", "*.zsf"); +#endif #else // open the file dialog QString newFile = QFileDialog::getSaveFileName( QDir::homeDirPath() + "/Documents/application/zsafe", "ZSafe (*.zsf)", this, "ZSafe File Dialog" "Choose a ZSafe file" ); #endif // open the new document if (newFile && newFile.length() > 0 ) { // save the previous opened document if (!filename.isEmpty()) saveDocument(filename, FALSE); + selectedItem = NULL; filename = newFile; // save the current filename to the config file conf->writeEntry(APP_KEY+"document", filename); saveConf(); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef WIN32 this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif QMessageBox::information( this, tr("ZSafe"), tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); saveDocumentWithPwd(); } } void ZSafe::saveDocumentWithoutPwd() { saveDocument(filename, FALSE); } void ZSafe::saveDocumentWithPwd() { saveDocument(filename, TRUE); } void ZSafe::about() { QString info; info = "<html><body><div align=""center"">"; info += "<b>"; info += tr("Zaurus Password Manager<br>"); info += tr("ZSafe version 2.1.2<br>"); info += "</b>"; info += tr("by Carsten Schneider<br>"); info += "zcarsten@gmx.net<br>"; info += "http://z-soft.z-portal.info/zsafe"; info += "<br>"; info += tr("Translations by Robert Ernst<br>"); info += "robert.ernst@linux-solutions.at<br>"; info += "<br></div>"; info += "</body></html>"; // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); QMessageBox mb( this, tr("ZSafe")); mb.setText (info); mb.setButtonText (QMessageBox::Ok, tr ("&OK")); QPixmap zsafe_img((const char**) zsafe_xpm); mb.setIconPixmap (zsafe_img); mb.exec(); } void ZSafe::setExpandFlag() { expandTree = !expandTree; file->setItemChecked('o', expandTree); #ifndef DESKTOP conf->setGroup ("zsafePrefs"); #endif // #ifndef WIN32 conf->writeEntry (APP_KEY+"expandTree", expandTree); // #endif saveConf(); } void ZSafe::paintEvent( QPaintEvent * ) { if (raiseFlag) { raiseFlag = false; raiseTimer.start (1, true); if (infoForm->isVisible()) infoForm->raise(); } } void ZSafe::resizeEvent ( QResizeEvent * ) { // qWarning ("resizeEvent"); #ifndef DESKTOP DeskW = appl->desktop()->width(); DeskH = appl->desktop()->height(); #else DeskW = this->width(); DeskH = this->height(); #endif qWarning( QString("Width : %1").arg(DeskW), 2000 ); qWarning( QString("Height: %1").arg(DeskH), 2000 ); New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); diff --git a/noncore/apps/zsafe/zsafe.pro b/noncore/apps/zsafe/zsafe.pro index ae4c793..5cb74dd 100644 --- a/noncore/apps/zsafe/zsafe.pro +++ b/noncore/apps/zsafe/zsafe.pro @@ -1,22 +1,22 @@ TEMPLATE = app CONFIG = qt warn_on release DESTDIR = $(OPIEDIR)/bin HEADERS = zsafe.h krc2.h category.h categorylist.h zlistview.h \ scqtfiledlg.h SOURCES = main.cpp zsafe.cpp krc2.cpp category.cpp \ categorylist.cpp zlistview.cpp shadedlistitem.cpp\ scqtfileedit.cpp scqtfileedit.moc.cpp \ scqtfiledlg.cpp INTERFACES = newdialog.ui searchdialog.ui passworddialog.ui categorydialog.ui INTERFACES += infoform.ui wait.ui INCLUDEPATH += $(OPIEDIR)/include INCLUDEPATH += . INCLUDEPATH += $(OPIEDIR)/noncore/apps/zsafe DEPENDPATH += $(OPIEDIR)/include -LIBS += -Wl,-rpath,$(OPIEDIR)/lib -L$(OPIEDIR)/lib -lqpe +LIBS += -Wl,-rpath,$(OPIEDIR)/lib -L$(OPIEDIR)/lib -lqpe -lopie TARGET = zsafe TRANSLATIONS = $(OPIEDIR)/noncore/apps/zsafe/i18n/de/zsafe.ts #include ( $(OPIEDIR)/include.pro ) |