summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp104
1 files changed, 94 insertions, 10 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 5cad7cb..824b841 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -908,126 +908,140 @@ void ZSafe::findPwd()
dialog->NameField->setText(lastSearchedName);
else
dialog->NameField->setText("");
if (lastSearchedUsername)
dialog->UsernameField->setText(lastSearchedUsername);
else
dialog->UsernameField->setText("");
if (lastSearchedComment)
dialog->CommentField->setText(lastSearchedComment);
else
dialog->CommentField->setText("");
DialogCode result = (DialogCode) dialog->exec();
#ifdef DESKTOP
result = Accepted;
#endif
QString name;
QString username;
QString comment;
if (result == Accepted)
{
name = dialog->NameField->text();
username = dialog->UsernameField->text();
comment = dialog->CommentField->text();
- owarn << name << oendl;
+#ifndef NO_OPIE
+ owarn << name << oendl;
+#else
+ qWarning (name);
+#endif
}
else
{
delete dialog;
return;
}
if (!name.isEmpty() && name != lastSearchedName ||
lastSearchedName.isEmpty() && !name.isEmpty())
{
// set search at the beginning if a new name is given
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
}
lastSearchedName = name;
if (!username.isEmpty() && username != lastSearchedUsername ||
lastSearchedUsername.isEmpty() && !username.isEmpty())
{
// set search at the beginning if a new name is given
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
}
lastSearchedUsername = username;
if (!comment.isEmpty() && comment != lastSearchedComment ||
lastSearchedComment.isEmpty() && !comment.isEmpty())
{
// set search at the beginning if a new name is given
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
}
lastSearchedComment = comment;
ListView->clearSelection();
bool found=FALSE;
// step through all categories
QListViewItem *i;
if (lastSearchedCategory)
i = lastSearchedCategory;
else
i = ListView->firstChild();
for (;
i != NULL;
i = i->nextSibling())
{
+#ifndef NO_OPIE
owarn << i->text(0) << oendl;
+#endif
i->setSelected(FALSE);
// step through all subitems
QListViewItem *si;
if (lastSearchedItem)
si = lastSearchedItem;
else
si = i->firstChild();
// for (si = i->firstChild();
for (;
si != NULL;
si = si->nextSibling())
{
+#ifndef NO_OPIE
owarn << si->text(0) << oendl;
+#else
+ qWarning (si->text(0));
+#endif
if (si->isSelected())
si->setSelected(FALSE);
// ListView->repaintItem(si);
bool n=TRUE;
bool u=TRUE;
bool c=TRUE;
if (!name.isEmpty())
n = (si->text(0)).contains (name, FALSE);
if (!username.isEmpty())
u = (si->text(1)).contains (username, FALSE);
if (!comment.isEmpty())
c = (si->text(3)).contains (comment, FALSE);
if ((n && u && c ) && !found)
{
+#ifndef NO_OPIE
owarn << "Found" << oendl;
+#else
+ qWarning ("Found");
+#endif
selectedItem = si;
si->setSelected(TRUE);
ListView->setCurrentItem(si);
ListView->ensureItemVisible(si);
ListView->triggerUpdate();
lastSearchedCategory = i;
// set to the next item
lastSearchedItem = si->nextSibling();
if (!lastSearchedItem)
{
// no next item within category -> set next category
lastSearchedCategory = i->nextSibling();
if (!lastSearchedCategory)
lastSearchedItem = NULL; // END
}
found = TRUE;
delete dialog;
update();
return;
}
}
lastSearchedCategory = i->nextSibling();
@@ -1255,98 +1269,106 @@ void ZSafe::removeAsciiFile()
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
// 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);
@@ -1398,79 +1420,87 @@ void ZSafe::readAllEntries()
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 ) )
{
+#ifndef NO_OPIE
owarn << "Could not read file " << fn << oendl;
+#else
+ qWarning( QString("Could not read file %1").arg(fn), 2000 );
+#endif
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;
}
}
+#ifndef NO_OPIE
owarn << "ReadAllEntries(): " << oendl;
-
+#else
+ qWarning ("ReadAllEntries(): ");
+#endif
+
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
/* modify QString -> QCString::utf8 */
strcpy (buffer, s.utf8());
QString name;
QString user;
QString password;
QString comment;
QString field5="";
QString field6="";
@@ -1574,53 +1604,64 @@ void ZSafe::readAllEntries()
}
}
if (!isIconAv)
{
c1->setIcon (*getPredefinedIcon(category));
}
c1->setListItem (catI);
c1->initListItem();
categories.insert (c1->getCategoryName(), c1);
}
}
f.close();
}
else
{
}
}
#ifdef UNUSED
void ZSafe::writeAllEntries()
{
+ if (filename.isEmpty())
+ {
+ QMessageBox::critical( 0, tr("ZSafe"),
+ tr("<P>No document defined. You have to create a new document</P>"));
+ return;
+ }
+
// open the file for writing
QString fn = filename + ".txt";
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, tr("ZSafe"),
tr("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);
@@ -1631,79 +1672,86 @@ void ZSafe::writeAllEntries()
oneEntry += "\"";
oneEntry += si->text(2);
oneEntry += "\";";
oneEntry += "\"";
// oneEntry += si->text(3);
QString comment = si->text(3);
comment.replace (QRegExp("\n"), "<br>");
oneEntry += comment;
oneEntry += "\"";
// owarn << oneEntry << oendl;
t << oneEntry << endl;
// owarn << si->text(0) << oendl;
}
}
f.close();
}
void ZSafe::readAllEntries()
{
QString fn = filename + ".txt";
QFile f( fn );
if ( !f.open( IO_ReadOnly ) )
{
+#ifndef NO_OPIE
owarn << "Could not read file " << fn << oendl;
+#else
+ qWarning( QString("Could not read file %1").arg(fn), 2000 );
+#endif
QMessageBox::critical( 0, tr("ZSafe"),
tr("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;
}
}
+#ifndef NO_OPIE
owarn << "ReadAllEntries(): " << oendl;
-
+#else
+ qWarning ("ReadAllEntries(): ");
+#endif
QTextStream t(&f);
while ( !t.eof() )
{
QString s = t.readLine();
s.replace (QRegExp("\";\""), "\"|\"");
// char buffer[1024];
int len=s.length()+1;
#ifdef WIN32
char buffer[512];
#else
char buffer[len];
#endif
strcpy (buffer, s);
QString name;
QString user;
QString password;
QString comment;
// separete the entries
char *i = strtok (buffer, "|");
QString category(&i[1]);
category.truncate(category.length() -1);
@@ -1784,50 +1832,52 @@ void ZSafe::readAllEntries()
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;
- // hide the main window
+#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;
@@ -1843,59 +1893,67 @@ void ZSafe::resume(int)
bool ZSafe::openDocument(const char* _filename, const char* )
{
int retval;
char* entry[FIELD_SIZE];
// #ifndef WIN32
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;
- return false;
+#lese
+ qWarning ("Error loading Document");
+#endif
+ return false;
}
}
else
{
#ifdef WIN32
this->setCaption("Qt ZSafe");
#else
this->setCaption("ZSafe");
#endif
filename = "";
return false;
}
// load the validation entry
if (validationFlag == 0)
{
pwdOk = 1;
break;
}
retval = loadEntry(entry);
if (retval == 1 &&
!strcmp (entry[0], "ZSAFECATEGORY") &&
@@ -2252,124 +2310,138 @@ bool ZSafe::saveDocument(const char* _filename,
char* entry[FIELD_SIZE];
// save the validation entry
{
int i=0;
entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
strcpy(entry[i++], "ZSAFECATEGORY");
entry[i] = (char*)malloc(strlen("name")+1);
strcpy(entry[i++], "name");
entry[i] = (char*)malloc(strlen("username")+1);
strcpy(entry[i++], "username");
entry[i] = (char*)malloc(strlen("password")+1);
strcpy(entry[i++], "password");
entry[i] = (char*)malloc(strlen("comment")+1);
strcpy(entry[i++], "comment");
entry[i] = (char*)malloc(strlen("field5")+1);
strcpy(entry[i++], "field5");
entry[i] = (char*)malloc(strlen("field6")+1);
strcpy(entry[i++], "field6");
retval = saveEntry(entry);
for (int z=0; z<i; z++) free(entry[z]);
if (retval == PWERR_DATA) {
+#ifndef NO_OPIE
owarn << "1: Error writing file, contents not saved" << oendl;
+#else
+ qWarning("1: Error writing file, contents not saved");
+#endif
saveFinalize();
return false;
}
// #ifndef WIN32
conf->writeEntry(APP_KEY+"valzsafe", 1);
// #endif
saveConf();
}
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())
{
int j=0;
entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
strcpy(entry[j++], i->text(0).utf8());
entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
strcpy(entry[j++], si->text(0).utf8());
entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
strcpy(entry[j++], si->text(1).utf8());
entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
strcpy(entry[j++], si->text(2).utf8());
entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
strcpy(entry[j++], si->text(3).utf8());
entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
strcpy(entry[j++], si->text(4).utf8());
entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
strcpy(entry[j++], si->text(5).utf8());
retval = saveEntry(entry);
for (int z=0; z<j; z++)
{
free(entry[z]);
}
if (retval == PWERR_DATA) {
+#ifndef NO_OPIE
owarn << "1: Error writing file, contents not saved" << oendl;
+#else
+ qWarning("1: Error writing file, contents not saved");
+#endif
saveFinalize();
return false;
}
}
}
if (saveFinalize() == PWERR_DATA) {
+#ifndef NO_OPIE
owarn << "2: Error writing file, contents not saved" << oendl;
- return false;
+#else
+ qWarning("2: Error writing file, contents not saved");
+#endif
+ return false;
} else {
#ifndef DESKTOP
Global::statusMessage (tr("Password file saved."));
#endif
modified = false;
return true;
}
}
PasswordForm *newPwdDialog;
bool newPwdDialogResult = false;
void ZSafe::setPasswordDialogDone()
{
newPwdDialogResult = true;
newPwdDialog->close();
}
void ZSafe::getDocPassword(QString title)
{
+#ifndef NO_OPIE
owarn << "getDocPassword" << oendl;
- // open the 'Password' dialog
+#endif
+ // open the 'Password' dialog
PasswordForm *dialog = new PasswordForm(this, title, TRUE);
newPwdDialog = dialog;
newPwdDialogResult = false;
QPixmap image0( ( const char** ) zsafe_xpm );
dialog->setIcon( image0);
connect( dialog->PasswordField, SIGNAL( returnPressed() ),
this, SLOT( setPasswordDialogDone() ) );
// CS: !!!
// int pos = filename.findRev ('/');
QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
#ifdef WIN32
dialog->setCaption("Qt " + ti);
#else
dialog->setCaption(ti);
#endif
// dialog->setCaption(title);
dialog->PasswordField->setFocus();
DialogCode result = (DialogCode) dialog->exec();
#ifdef DESKTOP
result = Accepted;
@@ -2508,50 +2580,52 @@ int ZSafe::saveFinalize(void)
* over, leaving us 3 short, so we fill it in with 3's.
*
* If we come out even, we fill it with 8 8s
*
* um, except that in this instance we are using 4 shorts instead of 8 bytes.
* so, half everything
*/
for (count1 = bufferIndex; count1 < 4; count1++) {
plaintext[count1] = (4 - bufferIndex);
}
krc2->rc2_encrypt (plaintext);
for (count1 = 0; count1 < 4; count1++) {
ciphertext[count1] = iv[count1] ^ plaintext[count1];
if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
}
fclose (fd);
free(buffer);
return retval;
}
void ZSafe::quitMe ()
{
+#ifndef NO_OPIE
owarn << "QUIT..." << oendl;
-
+#endif
+
if (modified)
{
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to save\nbefore exiting?"),
tr("&Save"),
tr("S&ave with\nnew\npassword"),
tr("&Don't Save"),
0 // Enter == button 0
) )
{ // Escape == button 2
case 0: // Save clicked, Alt-S or Enter pressed.
// save
modified = false;
saveDocument(filename, FALSE);
exitZs (1);
break;
case 1: //
// Save with new password
modified = false;
saveDocument(filename, TRUE);
exitZs (1);
break;
case 2: // Don't Save clicked or Alt-D pressed
// don't save but exitZs
@@ -2712,50 +2786,52 @@ void ZSafe::addCategory()
waitDialog.hide();
}
#ifndef WIN32
dialog->show();
#endif
#ifndef DESKTOP
// dialog->move (20, 100);
#endif
DialogCode result = (DialogCode) dialog->exec();
#ifdef DESKTOP
result = Accepted;
#endif
QString category;
QString icon;
QString fullIconPath;
QPixmap *pix;
if (result == Accepted)
{
modified = true;
category = dialog->CategoryField->currentText();
icon = dialog->IconField->currentText()+".png";
+#ifndef NO_OPIE
owarn << category << oendl;
-
+#endif
+
QListViewItem *li = new ShadedListItem( 1, ListView );
Category *c1 = new Category();
c1->setCategoryName(category);
// if (!icon.isEmpty() && !icon.isNull())
if (icon != "predefined.png")
{
// build the full path
fullIconPath = iconPath + icon;
pix = new QPixmap (fullIconPath);
// pix->resize(14, 14);
if (!pix->isNull())
{
// save the full pixmap name into the config file
// #ifndef WIN32
conf->writeEntry(APP_KEY+category, icon);
// #endif
saveConf();
QImage img = pix->convertToImage();
pix->convertFromImage(img.smoothScale(14,14));
c1->setIcon (*pix);
c1->setIconName(icon);
}
else
@@ -3186,83 +3262,91 @@ void ZSafe::editCategory()
DialogCode result = (DialogCode) dialog->exec();
#ifdef DESKTOP
result = Accepted;
#endif
QString fullIconPath;
QPixmap *pix;
if (result == Accepted)
{
modified = true;
if (category != dialog->CategoryField->currentText())
{
categories.remove (category);
// #ifndef WIN32
conf->removeEntry(category);
// #endif
saveConf();
}
category = dialog->CategoryField->currentText();
icon = dialog->IconField->currentText()+".png";
if (cat)
{
+#ifndef NO_OPIE
owarn << "Category found" << oendl;
-
+#else
+ qWarning("Category found");
+#endif
+
// if (!icon.isEmpty() && !icon.isNull())
if (icon != "predefined.png")
{
// build the full path
fullIconPath = iconPath + icon;
pix = new QPixmap (fullIconPath);
if (!pix->isNull())
{
// save the full pixmap name into the config file
// #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)
{
+#ifndef NO_OPIE
owarn << category << oendl;
+#else
+ 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))