-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 137 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.h | 1 |
2 files changed, 54 insertions, 84 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f3d57f8..41c572a 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -353,33 +353,33 @@ static const char* const general_data[] = { QClipboard *cb = QApplication::clipboard(); cb->clear(); exit (ec); } // save the configuration into the file void ZSafe::saveConf () { if (conf) { delete conf; #ifdef DESKTOP #ifndef Q_WS_WIN - conf = new QSettings (); + conf = new QSettings(); conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); #else conf = new QSettings (cfgFile); conf->insertSearchPath (QSettings::Unix, cfgFile); #endif #else conf = new Config (cfgFile, Config::File); conf->setGroup ("zsafe"); #endif } } /* * Constructs a ZSafe which is a child of 'parent', with the * name 'name' and widget flags set to 'f' @@ -480,49 +480,47 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) } else { DeskS = DeskH; } resize( DeskW, DeskH ); setMinimumSize( QSize( DeskS, DeskS ) ); setMaximumSize( QSize( DeskS, DeskS ) ); #else resize( DeskW, DeskH-30 ); #endif #endif setCaption( tr( "ZSafe" ) ); QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; QString filename = conf->readEntry(APP_KEY+"document"); - if (filename.isEmpty() || filename.isNull()) + if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() ) { - // check if the directory application exists, if not // create it // #ifndef Q_WS_WIN // QString d1("Documents/application"); // #else QString d1(QDir::homeDirPath() + "/Documents/application"); // #endif QDir pd1(d1); if (!pd1.exists()) { - QDir pd2(QDir::homeDirPath() + "/Documents"); if (!pd2.exists()) { - QDir pd3(QDir::homeDirPath()); + QDir pd3(QDir::homeDirPath()); if (!pd3.mkdir("Documents", FALSE)) { } } if (!pd2.mkdir("application", FALSE)) { QMessageBox::critical( 0, tr("ZSafe"), #ifdef JPATCH_HDE tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); #else tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); #endif exitZs (1); } } // #ifndef Q_WS_WIN @@ -532,33 +530,32 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) // #endif QDir pd2(d2); if (!pd2.exists()) { if (!pd1.mkdir("zsafe", FALSE)) { QMessageBox::critical( 0, tr("ZSafe"), #ifdef JPATCH_HDE tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); #else tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); #endif exitZs (1); } } - // set the default filename filename = zsafeAppDirPath + "/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 Q_WS_WIN this->setCaption("Qt ZSafe: " + ti); #else this->setCaption("ZSafe: " + ti); #endif @@ -1326,58 +1323,33 @@ void ZSafe::removeAsciiFile() 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 - + QString fn = zsaveDialog(); // open the new document if (fn && fn.length() > 0 ) { QFile f( fn ); if ( !f.open( IO_WriteOnly ) ) { #ifndef NO_OPIE owarn << "Could not write to file " << fn << oendl; #else qWarning( QString("Could not write to file %1").arg(fn),2000 ); #endif QMessageBox::critical( 0, "ZSafe", QString("Could not export to text file.") ); return; } QTextStream t( &f ); @@ -1908,32 +1880,34 @@ void ZSafe::resume(int) si = si->nextSibling(); i->takeItem(_si); // remove from view list if (_si) delete _si; } } // ask for password and read again openDocument(filename); } } //--------------------------------------------- bool ZSafe::openDocument(const char* _filename, const char* ) { + QString name= _filename; + qWarning("openDocument "+name); int retval; char* entry[FIELD_SIZE]; // #ifndef Q_WS_WIN int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); // #else // int validationFlag = 1; // #endif int pwdOk = 0; int numberOfTries = 3; for (int i=0; i < numberOfTries; i++) { QFile f(_filename); if (f.exists()) { // ask with a dialog for the password @@ -1957,33 +1931,47 @@ bool ZSafe::openDocument(const char* _filename, const char* ) #ifndef NO_OPIE owarn << "Error loading Document" << oendl; #else qWarning ("Error loading Document"); #endif return false; } } else { #ifdef Q_WS_WIN this->setCaption("Qt ZSafe"); #else this->setCaption("ZSafe"); #endif filename = ""; + switch( QMessageBox::warning( this, tr("ZSafe"), + tr("<P>You must create a new document first. Ok to create?</P>"), + tr("&Yes"), tr("&No."), + 0 + ) ) + { + case 1: // No return false; + break; + case 0: // Yes + newDocument(); + return false; + break; + } + } // load the validation entry if (validationFlag == 0) { pwdOk = 1; break; } retval = loadEntry(entry); if (retval == 1 && !strcmp (entry[0], "ZSAFECATEGORY") && !strcmp (entry[1], "name") && !strcmp (entry[2], "username") && !strcmp (entry[3], "password") && @@ -3434,57 +3422,33 @@ void ZSafe::pasteItem() 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 + QString newFile = zsaveDialog(); // 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; @@ -3600,59 +3564,33 @@ void ZSafe::loadDocument() conf->writeEntry(APP_KEY+"document", filename); saveConf(); QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); #ifdef Q_WS_WIN 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 - +QString newFile = zsaveDialog(); // 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 Q_WS_WIN this->setCaption("Qt ZSafe: " + ti); @@ -3840,32 +3778,34 @@ void ZSafe::setDocument(const QString& fileref) 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; openDocument(filename); +#else +Q_UNUSED(fileref); #endif } void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { if(item ==0) return; switch (mouse) { case 1: { #ifdef DESKTOP QDragObject *d = new QTextDrag( item->text(column) , this ); d->dragCopy(); #endif } break; case 2: @@ -3891,16 +3831,45 @@ void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int colum } else if (me == editItem) { editPwd(); } else if (me == showItem) { showInfo(item); } } break; }; } void ZSafe::copyClip( const QString &text) { QClipboard *cb = QApplication::clipboard(); cb->setText( text); } +QString ZSafe::zsaveDialog() { + + QString fn; +#ifndef DESKTOP +#ifndef NO_OPIE + QMap<QString, QStringList> mimeTypes; + mimeTypes.insert(tr("All"), QStringList() ); + mimeTypes.insert(tr("Text"), "text/*" ); + fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, + QDir::homeDirPath() + "/Documents/application/zsafe", + QString::null, + mimeTypes, + this, + tr ("Export text file")); +#else + fn = ScQtFileEdit::getSaveAsFileName(this, + tr ("Export text file"), + QDir::homeDirPath() + "/Documents/application/zsafe", + "*.txt"); +#endif +#else + fn = QFileDialog::getSaveFileName( + QDir::homeDirPath() + "/Documents/application/zsafe", + "ZSafe (*.txt)", + this, + "ZSafe"); +#endif + return fn; +} diff --git a/noncore/apps/zsafe/zsafe.h b/noncore/apps/zsafe/zsafe.h index ca041ff..7419797 100644 --- a/noncore/apps/zsafe/zsafe.h +++ b/noncore/apps/zsafe/zsafe.h @@ -140,32 +140,33 @@ public: bool saveDocument(const char* filename, bool withPwd, const char* format=0); int saveInit(const char *filename, const char *password); int saveEntry(char *entry[4]); int saveFinalize(void); void saveConf(); QPixmap * getPredefinedIcon(QString category); QString getFieldLabel (QListViewItem *_item, QString field, QString def); QString getFieldLabel (QString category, QString field, QString def); void setCategoryDialogFields(CategoryDialog *dialog); void setCategoryDialogFields(CategoryDialog *dialog, QString category); void saveCategoryDialogFields(CategoryDialog *dialog); void resume(int signum); void exitZs (int ec); + QString zsaveDialog(); public slots: virtual void deletePwd(); virtual void editPwd(); virtual void newPwd(); virtual void findPwd(); virtual void quitMe(); virtual void listViewSelected( QListViewItem *_item); virtual void showInfo( QListViewItem *_item); virtual void writeAllEntries(); virtual void readAllEntries(); virtual void removeAsciiFile(); virtual void setPasswordDialogDone(); virtual void addCategory(); virtual void delCategory(); |