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
@@ -400,245 +400,242 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
cfgFile=QDir::homeDirPath();
cfgFile += "/.zsafe.cfg";
// set the icon path
#ifdef NO_OPIE
QString qpedir ((const char *)getenv("QPEDIR"));
#else
QString qpedir ((const char *)getenv("OPIEDIR"));
#endif
#ifdef DESKTOP
iconPath = QDir::homeDirPath() + "/pics/";
#else
if (qpedir.isEmpty())
iconPath = "/home/QtPalmtop/pics/";
else
iconPath = qpedir + "/pics/";
#endif
// create a zsafe configuration object
#ifdef DESKTOP
#ifndef Q_WS_WIN
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 ("zsafePrefs");
#endif
#ifdef DESKTOP
// #ifndef Q_WS_WIN
expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false);
// #endif
#else
expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0);
#endif
#ifndef DESKTOP
conf->setGroup ("zsafe");
#endif
QPixmap copy_img((const char**) copy_xpm);
QPixmap cut_img((const char**) cut_xpm);
QPixmap edit_img((const char**) edit_xpm);
QPixmap editdelete_img((const char**) editdelete_xpm);
QPixmap find_img((const char**) find_xpm);
QPixmap folder_open_img((const char**) folder_open_xpm);
QPixmap help_icon_img((const char**) help_icon_xpm);
QPixmap new_img((const char**) new_xpm);
QPixmap paste_img((const char**) paste_xpm);
QPixmap quit_icon_img((const char**) quit_icon_xpm);
QPixmap save_img((const char**) save_xpm);
QPixmap trash_img((const char**) trash_xpm);
QPixmap expand_img((const char**) expand_xpm);
QPixmap export_img((const char**) export_xpm);
QPixmap import_img((const char**) import_xpm);
QPixmap bank_cards( ( const char** ) bank_cards_data );
QPixmap passwords( ( const char** ) passwords_data );
QPixmap software( ( const char** ) software_data );
QPixmap general( ( const char** ) general_data );
QPixmap image0( ( const char** ) zsafe_xpm );
if ( !name )
setName( "ZSafe" );
#ifdef DESKTOP
#ifdef Q_WS_WIN
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" ) );
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))
{
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
// QString d2("Documents/application/zsafe");
// #else
QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
// #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
selectedItem = NULL;
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
lastSearchedName = "";
lastSearchedUsername = "";
lastSearchedComment = "";
infoForm = new InfoForm(this, "show_info", TRUE);
categoryDialog = NULL;
infoForm->setIcon( image0);
// 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()) );
file->insertItem( save_img, tr("S&ave document with new Password"), this,
SLOT(saveDocumentWithPwd()) );
file->insertSeparator();
file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) );
file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) );
file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) );
file->insertSeparator();
file->insertItem( expand_img, tr("&Open entries expanded"), this,
SLOT(setExpandFlag()), 0, 'o');
file->setItemChecked('o', expandTree);
file->insertSeparator();
file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) );
menu->insertItem( tr("&File"), file );
QPopupMenu *cat = new QPopupMenu( this );
cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) );
cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) );
cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) );
menu->insertItem( tr("&Category"), cat );
QPopupMenu *it = new QPopupMenu( this );
it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) );
it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) );
it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) );
it->insertSeparator();
it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) );
it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) );
it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) );
it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) );
menu->insertItem( tr("&Entry"), it );
QPopupMenu *help = new QPopupMenu( this );
help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) );
menu->insertItem( tr("&Help"), help );
// toolbar icons
New = new QToolButton( menu, "New" );
New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) );
New->setMouseTracking( TRUE );
New->setText( "" );
New->setPixmap( new_img );
QToolTip::add( New, tr( "New entry" ) );
Edit = new QToolButton( menu, "Edit" );
Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) );
Edit->setText( "" );
Edit->setPixmap( edit_img );
QToolTip::add( Edit, tr( "Edit category or entry" ) );
Delete = new QToolButton( menu, "Delete" );
Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
Delete->setText( "" );
Delete->setPixmap( trash_img );
@@ -1246,218 +1243,193 @@ void ZSafe::listViewSelected( QListViewItem *_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 Q_WS_WIN
// 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 (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() )
{
#ifndef NO_OPIE
owarn << "Could not remove file " << fn << oendl;
#else
qWarning( QString("Could not remove file %1").arg(fn),2000 );
#endif
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
-
+ 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 );
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 += "\"";
// owarn << oneEntry << oendl;
t << oneEntry << endl;
// owarn << si->text(0) << oendl;
}
}
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" );
@@ -1828,242 +1800,258 @@ void ZSafe::readAllEntries()
}
}
else
{
QListViewItem *catI = new ShadedListItem( 1, ListView );
// create and insert a new item
QListViewItem * item = new ShadedListItem( 0, catI );
item->setText( 0, tr( name ) );
item->setText( 1, tr( user ) );
item->setText( 2, tr( password ) );
item->setText( 3, tr( comment ) );
catI->setOpen( TRUE );
Category *c1 = new Category();
c1->setCategoryName(category);
QString icon;
QString fullIconPath;
QPixmap *pix;
// #ifndef Q_WS_WIN
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->isNull())
{
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)
{
#ifndef NO_OPIE
owarn << "Resume" << oendl;
#endif
// hide the main window
if ( !showpwd )
{
infoForm->hide();
// open zsafe again
m_password = "";
selectedItem = NULL;
// clear the password list
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; )
{
QListViewItem *_si = si;
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
if (m_password.isEmpty())
getDocPassword(tr("Enter Password"));
if (m_password.isEmpty() && validationFlag == 0)
{
#ifndef NO_OPIE
owarn << "Wrong password" << oendl;
#else
qWarning ("Wrong password");
#endif
QMessageBox::critical( 0, tr("ZSafe"),
tr("Wrong password.\n\nZSafe will now exit.") );
exitZs (1);
}
retval = loadInit(_filename, m_password);
if (retval != PWERR_GOOD)
{
#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") &&
!strcmp (entry[4], "comment") )
{
for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
pwdOk = 1;
break;
}
else
// for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
fclose (fd);
m_password = "";
if (i < numberOfTries - 1)
{
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 );
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 ) );
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 );
item->setText( 0, tr( name ) );
item->setText( 1, tr( user ) );
@@ -3354,385 +3342,335 @@ void ZSafe::editCategory()
qWarning (category);
#endif
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
+ 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;
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 Q_WS_WIN
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 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);
#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;
#ifdef JPATCH_HDE
info = "<html><body><div align=""center"">";
info += "<b>";
info += tr("Zaurus Password Manager<br>");
info += tr("ZSafe version 2.1.2-jv01b<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><br>";
info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>");
info += "HADECO R&D<br>";
info += "r&d@hadeco.co.jp<br>";
info += "http://www.hadeco.co.jp/r&d/<br>";
info += "<br></div>";
info += "</body></html>";
#else
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>";
#endif
// 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 Q_WS_WIN
conf->writeEntry (APP_KEY+"expandTree", expandTree);
// #endif
@@ -3760,147 +3698,178 @@ void ZSafe::resizeEvent ( QResizeEvent * )
#else
DeskW = this->width();
DeskH = this->height();
#endif
if (New)
New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
if (Edit)
Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
if (Delete)
Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
if (Find)
Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
}
void ZSafe::slotRaiseTimer()
{
if (infoForm->isVisible())
infoForm->raise();
raiseFlag = true;
}
QPixmap * ZSafe::getPredefinedIcon(QString category)
{
QPixmap *pm;
if (category == "Bank cards")
pm = new QPixmap((const char**)bank_cards_data);
else if (category == "Passwords")
pm = new QPixmap((const char**)passwords_data);
else if (category == "Software")
pm = new QPixmap((const char**)software_data);
else if (category == "General")
pm = new QPixmap((const char**)general_data);
else
pm = new QPixmap((const char**)general_data);
return pm;
}
void ZSafe::setDocument(const QString& fileref)
{
#ifndef DESKTOP
// stop the timer to prevent loading of the default document
docuTimer.stop();
DocLnk link(fileref);
if ( link.isValid() )
{
// if (filename != link.file())
// saveDocument(filename, FALSE);
filename = link.file();
}
else
{
// if (filename != fileref)
// saveDocument(filename, FALSE);
filename = fileref;
}
// 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);
#else
this->setCaption("ZSafe: " + ti);
#endif
// 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;
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:
{
QClipboard *cb = QApplication::clipboard();
QIconSet copy_img((const char**) copy_xpm);
QIconSet edit_img((const char**) edit_xpm);
QPixmap folder_open_img((const char**) folder_open_xpm);
QPixmap editdelete_img((const char**) editdelete_xpm);
QPopupMenu *m = new QPopupMenu(this);
int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" ));
int editItem = m->insertItem(edit_img, tr( "Edit" ));
int showItem = m->insertItem(folder_open_img, tr( "Show Info" ));
int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" ));
m->setFocus();
int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ;
if(me == copyItem) {
copyClip( item->text(column) ) ;
} else if (me == cancelItem) {
cb->clear();
} 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
@@ -60,138 +60,139 @@ protected:
public:
ZSafe( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = WDestructiveClose );
~ZSafe();
static const QColor *evenRowColor;
static const QColor *oddRowColor;
QToolButton* Edit;
QToolButton* Delete;
QToolButton* Find;
QToolButton* New;
ZListView* ListView;
QString cfgFile;
QString iconPath;
InfoForm *infoForm;
CategoryDialog *categoryDialog;
QListViewItem *selectedItem; // current selected item
QListViewItem *copiedItem; // copied item
bool IsCopy;
bool IsCut;
bool modified; // true if database is modified
bool showpwd; // show PWD Dialog
QListViewItem *lastSearchedCategory;
QListViewItem *lastSearchedItem;
QString lastSearchedName;
QString lastSearchedUsername;
QString lastSearchedComment;
CategoryList categories; // list of categories
bool isCategory(QListViewItem *_item);
void getDocPassword(QString title);
QString filename;
enum {
PWERR_GOOD, // success
PWERR_OPEN, // can't open filedescriptor / can't create file
PWERR_PERM, // permissions are bad
PWERR_SYML, // is a symlink
PWERR_STAT, // can't get file status
PWERR_DATA // can't read correct data
};
long load_buffer_length;
long save_buffer_length;
/** password for the file */
QString m_password;
/** globals needed for file loading */
int lastcount, size;
/** these three are needed in all save functions and initialized in save _init() */
FILE *fd;
unsigned short iv[4];
char *buffer;
/** these two are global because save_entry() and save_finalize() both n eed them */
int bufferIndex;
unsigned short plaintext[4];
#ifdef DESKTOP
// #ifndef WIN32
QSettings *conf;
// #endif
#else
Config *conf;
#endif
bool expandTree;
QPopupMenu *file;
QTimer docuTimer;
bool openDocument(const char* filename, const char* format=0);
int loadInit(const char* filename, const char *password);
int loadEntry(char *entry[4]);
int loadFinalize(void);
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();
virtual void editCategory();
virtual void cutItem();
virtual void copyItem();
virtual void pasteItem();
virtual void newDocument();
virtual void loadDocument();
virtual void saveDocumentAs();
virtual void saveDocumentWithoutPwd();
virtual void saveDocumentWithPwd();
virtual void about();
virtual void setExpandFlag();
virtual void categoryFieldActivated( const QString& str);
virtual void ListPressed(int, QListViewItem *, const QPoint&, int);
virtual void copyClip( const QString &text);
private slots:
void setDocument(const QString& fileref);
void slotLoadDocu();
void slotRaiseTimer();
};
#endif // ZSAFE_H