summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-07-14 07:17:17 (UTC)
committer llornkcor <llornkcor>2004-07-14 07:17:17 (UTC)
commitc70dbfde7f9605be295cdc7f789c7e3e8d823d39 (patch) (side-by-side diff)
tree75c5fa13be08c30515685f1a6ef6b237809bbc71
parenta309681894af2632f9db2fcc252a058f218a82b2 (diff)
downloadopie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.zip
opie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.tar.gz
opie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.tar.bz2
allow new user to create new doc on first startup
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp133
-rw-r--r--noncore/apps/zsafe/zsafe.h1
2 files changed, 52 insertions, 82 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
@@ -488,30 +488,28 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
#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());
if (!pd3.mkdir("Documents", FALSE)) {
}
}
if (!pd2.mkdir("application", FALSE))
@@ -540,17 +538,16 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
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 = "";
@@ -1334,42 +1331,17 @@ 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
@@ -1916,16 +1888,18 @@ void ZSafe::resume(int)
}
}
//---------------------------------------------
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
@@ -1965,17 +1939,31 @@ bool ZSafe::openDocument(const char* _filename, const char* )
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;
@@ -3442,41 +3430,17 @@ void ZSafe::pasteItem()
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);
@@ -3608,43 +3572,17 @@ void ZSafe::loadDocument()
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;
@@ -3848,16 +3786,18 @@ void ZSafe::setDocument(const QString& fileref)
}
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:
@@ -3899,8 +3839,37 @@ void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int colum
}
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
@@ -148,16 +148,17 @@ public:
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);