summaryrefslogtreecommitdiff
path: root/noncore/apps/zsafe/zsafe.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/zsafe/zsafe.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index a3e805e..a3467e5 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -309,774 +309,774 @@ static const char* const general_data[] = {
".M c #a4b69c",
"#l c #a4b6a4",
".z c #a4baa4",
".f c #aca5ac",
".q c #acaaac",
"#d c #acbeac",
".6 c #acc2ac",
".o c #b4b2b4",
".t c #b4beb4",
"#k c #b4c2ac",
".5 c #b4cab4",
".D c #bdb6bd",
".G c #bdc6b4",
"#c c #bdceb4",
".X c #bdd2bd",
".4 c #bdd6bd",
".1 c #c5bec5",
".e c #c5c2c5",
".u c #c5cac5",
"#b c #c5d6c5",
".J c #c5dec5",
".p c #cdcacd",
".W c #cddecd",
".L c #cde2cd",
".K c #d5eacd",
".V c #d5ead5",
".y c #d5eed5",
"QtQtQtQtQtQtQtQtQtQtQtQtQtQt",
"QtQtQt.#.a.b.cQtQtQtQtQtQtQt",
"QtQt.d.e.f.g.h.i.c.j.dQt.kQt",
".a.l.m.n.o.p.q.r.s.t.u.v.wQt",
".x.y.z.A.B.C.D.p.q.E.F.G.H.I",
".I.J.K.L.M.N.O.P.o.p.Q.R.S.T",
"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3",
"Qt.3.X.W.4.X.5.6.7.8.9.s#.##",
"QtQt#a.X#b#c.5.6#d#e#f#g#h#i",
"QtQtQt#j.7#k.6#d#l#m#n#o#p#q",
"QtQtQtQt.k#r#s#m#t.H#u#v#w#x",
"QtQtQtQtQtQt.k#y#z.v#A#B#C#x",
"QtQtQtQtQtQtQtQt.k#D.w#s#E.k",
"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"};
// exit ZSafe and clear the clipboard for security reasons
void ZSafe::exitZs (int ec)
{
QClipboard *cb = QApplication::clipboard();
cb->clear();
exit (ec);
}
// save the configuration into the file
void ZSafe::saveConf ()
{
if (conf)
{
delete conf;
#ifdef DESKTOP
#ifndef WIN32
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'
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl ),
Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l)
{
IsCut = false;
IsCopy = false;
modified = false;
// set the config file
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 WIN32
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 WIN32
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 );
if ( !name )
setName( "ZSafe" );
#ifdef DESKTOP
#ifdef WIN32
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" ) );
filename = conf->readEntry(APP_KEY+"document");
if (filename.isEmpty() || filename.isNull())
{
// check if the directory application exists, if not
// create it
// #ifndef WIN32
// QString d1("Documents/application");
// #else
QString d1(QDir::homeDirPath() + "/Documents/application");
// #endif
QDir pd1(d1);
if (!pd1.exists())
{
QDir pd1("Documents");
if (!pd1.mkdir("application", FALSE))
{
QMessageBox::critical( 0, tr("ZSafe"),
#ifdef JPATCH_HDE
tr("Can't create directory\n.../Documents/application\n\nZSafe will now exit."));
#else
tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1));
#endif
exitZs (1);
}
}
QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
QDir pd2(d2);
if (!pd2.exists())
{
QDir pd2(QDir::homeDirPath() + "Documents/application");
if (!pd2.mkdir("zsafe", FALSE))
{
QMessageBox::critical( 0, tr("ZSafe"),
#ifdef JPATCH_HDE
tr("Can't create directory\n...//Documents/application/zsafe\n\nZSafe will now exit."));
#else
tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2));
#endif
exitZs (1);
}
}
// set the default filename
filename=d2 + "/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 WIN32
this->setCaption("Qt ZSafe: " + ti);
#else
this->setCaption("ZSafe: " + ti);
#endif
selectedItem = NULL;
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
lastSearchedName = "";
lastSearchedUsername = "";
lastSearchedComment = "";
infoForm = new InfoForm();
categoryDialog = NULL;
// 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( tr( "" ) );
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( tr( "" ) );
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( tr( "" ) );
Delete->setPixmap( trash_img );
QToolTip::add( Delete, tr( "Delete category or entry" ) );
Find = new QToolButton( menu, "Find" );
Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) );
Find->setText( tr( "" ) );
Find->setPixmap( find_img );
QToolTip::add( Find, tr( "Find entry" ) );
/*
QBoxLayout * h = new QHBoxLayout( this );
h->addWidget (menu);
h->addWidget (New);
h->addWidget (Edit);
h->addWidget (Delete);
h->addWidget (Find);
*/
ListView = new ZListView( this, "ListView" );
ListView->addColumn( tr( "Name" ) );
ListView->addColumn( tr( "Field 2" ) );
ListView->addColumn( tr( "Field 3" ) );
ListView->addColumn( tr( "Comment" ) );
ListView->addColumn( tr( "Field 4" ) );
ListView->addColumn( tr( "Field 5" ) );
ListView->setAllColumnsShowFocus(TRUE);
#ifdef DESKTOP
ListView->setResizePolicy(QScrollView::AutoOneFit);
// ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) );
#else
ListView->setResizePolicy(QScrollView::AutoOneFit);
// ListView->setGeometry( QRect( 0, 22,
// this->width(), this->height() - 30 ) );
// ListView->setMaximumSize( QSize( 440, 290 ) );
#endif
ListView->setVScrollBarMode( QListView::Auto );
QBoxLayout * l = new QVBoxLayout( this );
l->addWidget (menu);
l->addWidget (ListView);
#ifndef DESKTOP
// start a timer (100 ms) to load the default document
docuTimer.start( 100, true );
connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) );
raiseFlag = true;
connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) );
#else
// open the default document
openDocument(filename);
#endif
// signals and slots connections for QTollButton
connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) );
connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) );
connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) );
connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) );
// signals and slots connections for QListView
- connect( ListView, SIGNAL( selectionChanged( QListViewItem* ) ),
- this, SLOT( listViewSelected( QListViewItem* ) ) );
- connect( ListView, SIGNAL( doubleClicked( QListViewItem* ) ),
- this, SLOT( showInfo( QListViewItem* ) ) );
- connect( ListView, SIGNAL( returnPressed( QListViewItem* ) ),
- this, SLOT( showInfo( QListViewItem* ) ) );
+ connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ),
+ this, SLOT( listViewSelected(QListViewItem*) ) );
+ connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ),
+ this, SLOT( showInfo(QListViewItem*) ) );
+ connect( ListView, SIGNAL( returnPressed(QListViewItem*) ),
+ this, SLOT( showInfo(QListViewItem*) ) );
}
const QColor *ZSafe::evenRowColor = &Qt::white;
// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
/*
* Destroys the object and frees any allocated resources
*/
ZSafe::~ZSafe()
{
// no need to delete child widgets, Qt does it all for us
quitMe();
}
// load the default document
void ZSafe::slotLoadDocu()
{
openDocument (filename);
}
void ZSafe::deletePwd()
{
if (!selectedItem)
return;
if (!isCategory(selectedItem))
{
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to delete?"),
tr("&Delete"), tr("D&on't Delete"),
0 // Enter == button 0
) ) { // Escape == button 2
case 0: // Delete clicked, Alt-S or Enter pressed.
// Delete
modified = true;
selectedItem->parent()->takeItem(selectedItem);
selectedItem = NULL;
break;
case 1: // Don't delete
break;
}
}
else
{
delCategory();
}
}
void ZSafe::editPwd()
{
if (!selectedItem)
return;
if (!isCategory(selectedItem))
{
// open the 'New Entry' dialog
NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE);
#ifdef WIN32
dialog->setCaption ("Qt " + tr("Edit Entry"));
dialog->setGeometry(200, 250, 220, 310 );
#endif
// set the labels
dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
// set the fields
dialog->NameField->setText(selectedItem->text (0));
dialog->UsernameField->setText(selectedItem->text (1));
dialog->PasswordField->setText(selectedItem->text (2));
QString comment = selectedItem->text (3);
comment.replace (QRegExp("<br>"), "\n");
dialog->Field5->setText(selectedItem->text (4));
dialog->Field6->setText(selectedItem->text (5));
dialog->CommentField->insertLine(comment);
dialog->CommentField->setCursorPosition(0,0);
DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
#ifdef DESKTOP
result = Accepted;
#endif
if (result == Accepted)
{
modified = true;
// edit the selected item
QString name = dialog->NameField->text();
selectedItem->setText (0, tr (name));
QString user = dialog->UsernameField->text();
selectedItem->setText (1, tr (user));
QString pwd = dialog->PasswordField->text();
selectedItem->setText (2, tr (pwd));
QString comment = dialog->CommentField->text();
comment.replace (QRegExp("\n"), "<br>");
selectedItem->setText (3, tr (comment));
QString f5 = dialog->Field5->text();
selectedItem->setText (4, tr (f5));
QString f6 = dialog->Field6->text();
selectedItem->setText (5, tr (f6));
}
delete dialog;
}
else
{
editCategory();
}
}
void ZSafe::newPwd()
{
if (!selectedItem)
return;
if (!isCategory(selectedItem))
selectedItem = selectedItem->parent();
if (isCategory(selectedItem))
{
QString cat = selectedItem->text(0);
// open the 'New Entry' dialog
NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE);
#ifdef WIN32
dialog->setCaption ("Qt " + tr("New Entry"));
dialog->setGeometry(200, 250, 220, 310 );
#endif
// set the labels
dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
retype:
DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
#ifdef DESKTOP
result = Accepted;
#endif
if (result == Accepted)
{
QString name = dialog->NameField->text();
if (cat == name)
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("Entry name must be different\nfrom the category name.") );
goto retype; // it's not a good programming style :-)
}
modified = true;
// add the new item
QListViewItem *i = new ShadedListItem (0, selectedItem);
i->setOpen (TRUE);
i->setText (0, tr (name));
QString user = dialog->UsernameField->text();
i->setText (1, tr (user));
QString pwd = dialog->PasswordField->text();
i->setText (2, tr (pwd));
QString comment = dialog->CommentField->text();
comment.replace (QRegExp("\n"), "<br>");
i->setText (3, tr (comment));
QString f5 = dialog->Field5->text();
i->setText (4, tr (f5));
QString f6 = dialog->Field6->text();
i->setText (5, tr (f6));
}
delete dialog;
}
}
void ZSafe::findPwd()
{
// open the 'Search' dialog
SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
#ifdef WIN32
dialog->setCaption ("Qt " + tr("Search"));
#endif
#ifdef DESKTOP
#endif
if (lastSearchedName)
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();
qWarning (name);
}
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())
{
qWarning (i->text(0));
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())
{
qWarning (si->text(0));
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)
{
qWarning ("Found");
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();
lastSearchedItem = NULL;
}
lastSearchedCategory = NULL;
lastSearchedItem = NULL;
delete dialog;
update();
QMessageBox::information( this, tr("ZSafe"),
tr("Entry not found"), tr("&OK"), 0);
}
QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
{
QString category;
if (_item)
{
if (isCategory(_item))
{
category = _item->text(0);
}
else
{
QListViewItem *cat = _item->parent();
category = cat->text(0);
}
}
else
{
return def;
}
QString app_key = APP_KEY;
#ifndef DESKTOP
#ifndef WIN32
conf->setGroup ("fieldDefs");
#endif
#else
#ifndef WIN32
app_key += "/fieldDefs/";
#endif
#endif
// #ifndef WIN32
QString label = conf->readEntry(app_key+category+"-field"+field,def);
// #else
// QString label(def);
// #endif
#ifndef DESKTOP
conf->setGroup ("zsafe");
#endif
return label;
}
QString ZSafe::getFieldLabel (QString category, QString field, QString def)
{
QString app_key = APP_KEY;
#ifndef DESKTOP
conf->setGroup ("fieldDefs");
#else
#ifndef WIN32
app_key += "/fieldDefs/";
#endif
#endif
// #ifndef WIN32
QString label = conf->readEntry(app_key+category+"-field"+field,
def);
@@ -2198,1177 +2198,1177 @@ bool ZSafe::saveDocument(const char* _filename,
if (firstPasswd != m_password)
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("Passwords must be identical.\nPlease enter again."));
continue;
}
pwdOk = TRUE;
modified = false;
}
}
else if (modified)
{
QString fns(_filename);
fns = fns.right (fns.length() - fns.findRev ('/') - 1);
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
tr("&Save"),
tr("&Don't Save"),
0 // Enter == button 0
) )
{ // Escape == button 2
case 0: // Save clicked, Alt-S or Enter pressed.
modified = false;
break;
case 1: // Don't Save clicked or Alt-D pressed
modified = false;
return true;
}
}
modified = false;
if (m_password.isEmpty())
return false;
int retval = saveInit(_filename, m_password);
// int retval = saveInit(_filename, "test");
if (retval != PWERR_GOOD) {
return false;
}
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) {
qWarning("1: Error writing file, contents not saved");
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) {
qWarning("1: Error writing file, contents not saved");
saveFinalize();
return false;
}
}
}
if (saveFinalize() == PWERR_DATA) {
qWarning("2: Error writing file, contents not saved");
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)
{
qWarning ("getDocPassword");
// open the 'Password' dialog
PasswordForm *dialog = new PasswordForm(this, title, TRUE);
newPwdDialog = dialog;
newPwdDialogResult = false;
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;
#endif
QString password;
if (result == Accepted || newPwdDialogResult)
{
m_password = dialog->PasswordField->text();
}
else
{
exitZs (1);
}
}
int ZSafe::saveInit(const char *_filename, const char *password)
{
char key[128];
unsigned int j = 0;
unsigned int keylength;
// int val;
int count2;
Krc2* krc2 = new Krc2();
/* first we should check the permissions of the filename */
/*
if (QFile::exists(_filename)) {
val = checkFile(_filename);
if (val != PWERR_GOOD)
return val;
} else
{
val = creat (_filename, (S_IRUSR | S_IWUSR));
if (val == -1)
return PWERR_OPEN;
else
close(val);
}
*/
QFileInfo f (_filename);
save_buffer_length = f.size();
save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
fd = fopen (_filename, "wb");
if (fd == NULL)
return PWERR_OPEN;
buffer = (char*)malloc(save_buffer_length);
/* make the key ready */
for (j = 0; password[j] != '\0'; j++) {
key[j] = password[j];
}
keylength = j;
krc2->rc2_expandkey (key, keylength, 128);
/* First, we make the IV */
for (count2 = 0; count2 < 4; count2++) {
iv[count2] = rand ();
putc ((unsigned char) (iv[count2] >> 8), fd);
putc ((unsigned char) (iv[count2] & 0xff), fd);
}
bufferIndex = 0;
return PWERR_GOOD;
}
int ZSafe::saveEntry(char *entry[FIELD_SIZE])
{
char *text1;
int count2, count3;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
buffer = (char*)memset(buffer, '\0', save_buffer_length);
for (count2 = 0; count2 < FIELD_SIZE; count2++) {
text1 = entry[count2];
if (strlen (text1) == 0) {
strncat(buffer, " ", strlen(" "));
} else {
strncat(buffer, text1, strlen(text1));
}
/* Use 255 as the marker. \n is too tough to test for */
buffer[strlen (buffer)] = 255;
} /*for (count2 = 0; count2 < 5; count2++)*/
count2 = 0;
/* I'm using CBC mode and encrypting the data straight from top down.
* At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
* PKCS 5 padding (explained at the code section
*/
while (count2 < (int)strlen (buffer)) {
#ifndef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2 + 1] << 8;
plaintext[bufferIndex] += buffer[count2] & 0xff;
#endif
#ifdef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2] << 8;
plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
#endif
bufferIndex++;
if (bufferIndex == 4) {
krc2->rc2_encrypt (plaintext);
for (count3 = 0; count3 < 4; count3++) {
ciphertext[count3] = iv[count3] ^ plaintext[count3];
/* Now store the ciphertext as the iv */
iv[count3] = plaintext[count3];
/* reset the buffer index */
bufferIndex = 0;
if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
} /*for (count3 = 0; count3 < 5; count3++)*/
} /*if (bufferIndex == 5)*/
/* increment a short, not a byte */
count2 += 2;
} /*while (count2 < strlen (buffer))*/
int ret = PWERR_GOOD;
return ret;
}
int ZSafe::saveFinalize(void)
{
int count1, retval = PWERR_GOOD;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
/* Tack on the PKCS 5 padding
* How it works is we fill up the last n bytes with the value n
*
* So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
* 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 ()
{
qWarning ("QUIT...");
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
exitZs (1);
break;
}
}
exitZs (1);
}
void ZSafe::categoryFieldActivated( const QString& category)
{
if (categoryDialog)
setCategoryDialogFields(categoryDialog, category);
}
void ZSafe::addCategory()
{
if (filename.isEmpty())
{
QMessageBox::critical( 0, tr("ZSafe"),
tr("No document defined.\nYou have to create a new document"));
return;
}
else
{
// open the 'Category' dialog
bool initIcons = false;
// open the 'Category' dialog
CategoryDialog *dialog;
if (categoryDialog)
{
dialog = categoryDialog;
}
else
{
categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
#ifdef WIN32
categoryDialog->setCaption ("Qt " + tr("Category"));
#endif
dialog = categoryDialog;
connect( dialog->CategoryField,
- SIGNAL( activated ( const QString &)),
- this, SLOT( categoryFieldActivated( const QString & ) ) );
+ SIGNAL( activated(const QString&)),
+ this, SLOT( categoryFieldActivated(const QString&) ) );
initIcons = true;
}
#ifdef DESKTOP
#ifndef WIN32
QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
#else
// read all categories from the config file and store
// into a list
QFile f (cfgFile);
QStringList list;
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
QString s;
int n = 1;
while ( !t.eof() ) { // until end of file...
s = t.readLine(); // line of text excluding '\n'
list.append(s);
}
f.close();
}
#endif
#else
// read all categories from the config file and store
// into a list
QFile f (cfgFile);
QStringList list;
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
QString s;
while ( !t.eof() ) { // until end of file...
s = t.readLine(); // line of text excluding '\n'
list.append(s);
}
f.close();
}
#endif
QStringList::Iterator it = list.begin();
QString categ;
QString firstCategory;
dialog->CategoryField->clear(); // remove all items
while( it != list.end() )
{
QString *cat = new QString (*it);
if (cat->contains("-field1", FALSE))
{
#ifdef DESKTOP
#ifndef WIN32
categ = cat->section ("-field1", 0, 0);
#else
int pos = cat->find ("-field1");
categ = cat->left (pos);
#endif
#else
int pos = cat->find ("-field1");
cat->truncate(pos);
categ = *cat;
#endif
if (!categ.isEmpty())
{
dialog->CategoryField->insertItem (categ, -1);
if (firstCategory.isEmpty())
firstCategory = categ;
}
}
++it;
}
if (firstCategory.isEmpty())
setCategoryDialogFields(dialog);
else
setCategoryDialogFields(dialog, firstCategory);
// CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
if (initIcons)
{
Wait waitDialog(this, tr("Wait dialog"));
waitDialog.waitLabel->setText(tr("Gathering icons..."));
waitDialog.show();
qApp->processEvents();
#ifdef DESKTOP
QDir d(iconPath);
#else
QDir d(QPEApplication::qpeDir() + "/pics/");
#endif
d.setFilter( QDir::Files);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
dialog->IconField->insertItem("predefined");
while ( (fi=it.current()) ) { // for each file...
QString fileName = fi->fileName();
if(fileName.right(4) == ".png"){
fileName = fileName.mid(0,fileName.length()-4);
#ifdef DESKTOP
QPixmap imageOfFile;
imageOfFile.load(iconPath + fi->fileName());
#else
QPixmap imageOfFile(Resource::loadPixmap(fileName));
#endif
QImage foo = imageOfFile.convertToImage();
foo = foo.smoothScale(16,16);
imageOfFile.convertFromImage(foo);
dialog->IconField->insertItem(imageOfFile,fileName);
}
++it;
}
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";
qWarning (category);
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)
{
// 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
{
QPixmap folder( ( const char** ) general_data );
c1->setIcon (folder);
}
}
else
{
c1->setIcon (*getPredefinedIcon(category));
}
c1->setListItem (li);
c1->initListItem();
categories.insert (c1->getCategoryName(), c1);
saveCategoryDialogFields(dialog);
}
else
{
// delete dialog;
dialog->hide();
return;
}
}
}
void ZSafe::delCategory()
{
if (!selectedItem)
return;
if (isCategory(selectedItem))
{
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to delete?"),
tr("&Delete"), tr("D&on't Delete"),
0 // Enter == button 0
) ) { // Escape == button 2
case 0: // Delete clicked, Alt-S or Enter pressed.
// Delete from the category list
modified = true;
categories.remove (selectedItem->text(0));
// #ifndef WIN32
conf->removeEntry (selectedItem->text(0));
// #endif
saveConf();
// Delete the selected item and all subitems
// step through all subitems
QListViewItem *si;
for (si = selectedItem->firstChild();
si != NULL; )
{
QListViewItem *_si = si;
si = si->nextSibling();
selectedItem->takeItem(_si); // remove from view list
if (_si) delete _si;
}
ListView->takeItem(selectedItem);
delete selectedItem;
selectedItem = NULL;
break;
case 1: // Don't delete
break;
}
}
}
void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
{
if (!dialog)
return;
QString icon;
if (selectedItem)
{
dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
Category *cat= categories.find (selectedItem->text(0));
if (cat)
{
icon = cat->getIconName();
}
else
icon = conf->readEntry(APP_KEY+selectedItem->text(0));
}
else
{
dialog->Field1->setText(tr("Name"));
dialog->Field2->setText(tr("Username"));
dialog->Field3->setText(tr("Password"));
dialog->Field4->setText(tr("Comment"));
dialog->Field5->setText(tr("Field 4"));
dialog->Field6->setText(tr("Field 5"));
}
#ifdef DESKTOP
QDir d(iconPath);
#else
QDir d(QPEApplication::qpeDir() + "/pics/");
#endif
d.setFilter( QDir::Files);
const QFileInfoList *list = d.entryInfoList();
int i=0;
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
if (icon.isEmpty() || icon.isNull())
{
dialog->IconField->setCurrentItem(0);
}
else
{
while ( (fi=it.current()) )
{ // for each file...
QString fileName = fi->fileName();
if(fileName.right(4) == ".png")
{
fileName = fileName.mid(0,fileName.length()-4);
if(fileName+".png"==icon)
{
dialog->IconField->setCurrentItem(i+1);
break;
}
++i;
}
++it;
}
}
}
void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
{
if (!dialog)
return;
dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
QString icon;
Category *cat= categories.find (category);
if (cat)
{
icon = cat->getIconName();
}
else
icon = conf->readEntry(APP_KEY+category);
#ifdef DESKTOP
QDir d(iconPath);
#else
QDir d(QPEApplication::qpeDir() + "/pics/");
#endif
d.setFilter( QDir::Files);
const QFileInfoList *list = d.entryInfoList();
int i=0;
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
if (icon.isEmpty() || icon.isNull())
{
dialog->IconField->setCurrentItem(0);
}
else
{
while ( (fi=it.current()) )
{ // for each file...
QString fileName = fi->fileName();
if(fileName.right(4) == ".png")
{
fileName = fileName.mid(0,fileName.length()-4);
if(fileName+".png"==icon)
{
dialog->IconField->setCurrentItem(i+1);
break;
}
++i;
}
++it;
}
}
}
void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
{
QString app_key = APP_KEY;
#ifndef DESKTOP
conf->setGroup ("fieldDefs");
#else
#ifndef WIN32
app_key += "/fieldDefs/";
#endif
#endif
QString category = dialog->CategoryField->currentText();
// #ifndef WIN32
conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
// #endif
saveConf();
#ifndef DESKTOP
conf->setGroup ("zsafe");
#endif
}
void ZSafe::editCategory()
{
if (!selectedItem)
return;
if (isCategory(selectedItem))
{
QString category = selectedItem->text(0);
bool initIcons = false;
// open the 'Category' dialog
CategoryDialog *dialog;
if (categoryDialog)
{
dialog = categoryDialog;
}
else
{
categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
#ifdef WIN32
categoryDialog->setCaption ("Qt " + tr("Category"));
#endif
dialog = categoryDialog;
connect( dialog->CategoryField,
- SIGNAL( activated ( const QString &)),
- this, SLOT( categoryFieldActivated( const QString & ) ) );
+ SIGNAL( activated(const QString&)),
+ this, SLOT( categoryFieldActivated(const QString&) ) );
initIcons = true;
}
setCategoryDialogFields(dialog);
#ifdef DESKTOP
#ifndef WIN32
QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
#else
// read all categories from the config file and store
// into a list
QFile f (cfgFile);
QStringList list;
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
QString s;
int n = 1;
while ( !t.eof() ) { // until end of file...
s = t.readLine(); // line of text excluding '\n'
list.append(s);
}
f.close();
}
#endif
#else
// read all categories from the config file and store
// into a list
QFile f (cfgFile);
QStringList list;
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
QString s;
while ( !t.eof() ) { // until end of file...
s = t.readLine(); // line of text excluding '\n'
list.append(s);
}
f.close();
}
#endif
QStringList::Iterator it = list.begin();
QString categ;
dialog->CategoryField->clear(); // remove all items
int i=0;
bool foundCategory = false;
while( it != list.end() )
{
QString *cat = new QString (*it);
if (cat->contains("-field1", FALSE))
{
#ifdef DESKTOP
#ifndef WIN32
categ = cat->section ("-field1", 0, 0);
#else
int pos = cat->find ("-field1");
categ = cat->left (pos);
#endif
#else
int pos = cat->find ("-field1");
cat->truncate(pos);
categ = *cat;
#endif
if (!categ.isEmpty())
{
dialog->CategoryField->insertItem (categ, i);
if (category.compare(categ) == 0)
{
dialog->CategoryField->setCurrentItem(i);
foundCategory = true;
}
i++;
}
}
++it;
}
if (!foundCategory)
{
dialog->CategoryField->insertItem (category, i);
dialog->CategoryField->setCurrentItem(i);
}
QString icon;
Category *cat= categories.find (selectedItem->text(0));
if (cat)
{
icon = cat->getIconName();
}
if (initIcons)
{
Wait waitDialog(this, tr("Wait dialog"));
waitDialog.waitLabel->setText(tr("Gathering icons..."));
waitDialog.show();
qApp->processEvents();
#ifdef DESKTOP
QDir d(iconPath);
#else
QDir d(QPEApplication::qpeDir() + "/pics/");
#endif
d.setFilter( QDir::Files);
const QFileInfoList *list = d.entryInfoList();
int i=0;
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
if (icon.isEmpty() || icon.isNull())
{
dialog->IconField->setCurrentItem(0);
}
dialog->IconField->insertItem("predefined");
while ( (fi=it.current()) ) { // for each file...
QString fileName = fi->fileName();
if(fileName.right(4) == ".png")
{
fileName = fileName.mid(0,fileName.length()-4);
#ifdef DESKTOP
QPixmap imageOfFile;
imageOfFile.load(iconPath + fi->fileName());
#else
QPixmap imageOfFile(Resource::loadPixmap(fileName));
#endif
QImage foo = imageOfFile.convertToImage();
foo = foo.smoothScale(16,16);
imageOfFile.convertFromImage(foo);
dialog->IconField->insertItem(imageOfFile,fileName);
if(fileName+".png"==icon)
dialog->IconField->setCurrentItem(i+1);
++i;
}
++it;
}
waitDialog.hide();
}
else
{
#ifdef DESKTOP
// QDir d(QDir::homeDirPath() + "/pics/");
QDir d(iconPath);
#else
QDir d(QPEApplication::qpeDir() + "/pics/");
#endif
d.setFilter( QDir::Files);
const QFileInfoList *list = d.entryInfoList();
int i=0;
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
if (icon.isEmpty() || icon.isNull())
{
dialog->IconField->setCurrentItem(0);
}
else
{
while ( (fi=it.current()) )
{ // for each file...
QString fileName = fi->fileName();
if(fileName.right(4) == ".png")
{
fileName = fileName.mid(0,fileName.length()-4);
if(fileName+".png"==icon)
{
dialog->IconField->setCurrentItem(i+1);
break;
}
++i;
}
++it;
}
}
}
// dialog->show();
#ifndef DESKTOP
// dialog->move (20, 100);
#endif
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)
{
qWarning("Category found");
// if (!icon.isEmpty() && !icon.isNull())
if (icon != "predefined.png")
{
// build the full path
fullIconPath = iconPath + icon;
pix = new QPixmap (fullIconPath);
if (pix)
{
// 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)
{
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;