summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp132
-rw-r--r--noncore/apps/zsafe/zsafe.h8
2 files changed, 122 insertions, 18 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 189453e..5cad7cb 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -45,24 +45,25 @@ using namespace Opie::Ui;
#include <stdlib.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#ifdef DESKTOP
#include <qfiledialog.h>
+#include <qdragobject.h>
#ifndef WIN32
#include <qsettings.h>
#else
#include "qsettings.h"
#endif
#include <qapplication.h>
#else
#include <qfile.h>
#include <qpe/fileselector.h>
#include <qpe/global.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
@@ -384,24 +385,25 @@ static const char* const general_data[] = {
* 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;
+ showpwd = 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
@@ -448,25 +450,26 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
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 )
+ QPixmap image0( ( const char** ) zsafe_xpm );
+ if ( !name )
setName( "ZSafe" );
#ifdef DESKTOP
#ifdef WIN32
setGeometry(100, 150, DeskW, DeskH-30 );
#else
resize( DeskW, DeskH-30 );
#endif
#else
#ifdef JPATCH_HDE
@@ -483,63 +486,101 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
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 ( !QDir( zsafeAppDirPath ).exists() )
+
+ // 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 pd2(QDir::homeDirPath() + "/Documents");
+ if (!pd2.exists()) {
+ QDir pd3(QDir::homeDirPath());
+ if (!pd3.mkdir("Documents", FALSE)) {
+ }
+ }
+
+ if (!pd2.mkdir("application", FALSE))
{
- //FIXME: Pending someone to look into why QDir.mkdir does not work as expected
- QString cmdline = QString().sprintf( "mkdir -p %s", (const char*) zsafeAppDirPath );
- ::system( cmdline );
+ 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);
}
- if ( !QDir( zsafeAppDirPath ).exists() )
+ }
+// #ifndef WIN32
+ // 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, "ZSafe", tr("Can't create application data directory.\nZSafe will now exit."));
- exitZs (1);
+ 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 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;
+ 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()) );
@@ -657,24 +698,31 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
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*) ) );
+#ifndef DESKTOP
+ QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
+#endif
+ connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
+ this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
+
+ this->setIcon( image0);
}
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
@@ -1507,25 +1555,25 @@ void ZSafe::readAllEntries()
QString icon;
QString fullIconPath;
QPixmap *pix;
// #ifndef WIN32
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)
+ 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));
}
@@ -1722,25 +1770,25 @@ void ZSafe::readAllEntries()
QString icon;
QString fullIconPath;
QPixmap *pix;
// #ifndef WIN32
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)
+ 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));
}
@@ -1751,24 +1799,26 @@ void ZSafe::readAllEntries()
}
f.close();
}
#endif // UNUSED
void ZSafe::resume(int)
{
owarn << "Resume" << oendl;
// 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())
{
@@ -1777,24 +1827,25 @@ void ZSafe::resume(int)
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* )
{
int retval;
char* entry[FIELD_SIZE];
// #ifndef WIN32
int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
// #else
@@ -1945,25 +1996,25 @@ bool ZSafe::openDocument(const char* _filename, const char* )
QString icon;
QString fullIconPath;
QPixmap *pix;
// #ifndef WIN32
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)
+ 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));
}
@@ -2293,24 +2344,27 @@ void ZSafe::setPasswordDialogDone()
newPwdDialogResult = true;
newPwdDialog->close();
}
void ZSafe::getDocPassword(QString title)
{
owarn << "getDocPassword" << oendl;
// 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);
@@ -2683,25 +2737,25 @@ void ZSafe::addCategory()
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)
+ 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
@@ -3152,25 +3206,25 @@ void ZSafe::editCategory()
icon = dialog->IconField->currentText()+".png";
if (cat)
{
owarn << "Category found" << oendl;
// if (!icon.isEmpty() && !icon.isNull())
if (icon != "predefined.png")
{
// build the full path
fullIconPath = iconPath + icon;
pix = new QPixmap (fullIconPath);
- if (pix)
+ 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);
}
}
@@ -3683,13 +3737,59 @@ void ZSafe::setDocument(const QString& fileref)
}
if (c) delete c; // delete the previous category
categories.clear();
m_password = "";
selectedItem = NULL;
openDocument(filename);
#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);
+}
+
diff --git a/noncore/apps/zsafe/zsafe.h b/noncore/apps/zsafe/zsafe.h
index eef5cdc..ca041ff 100644
--- a/noncore/apps/zsafe/zsafe.h
+++ b/noncore/apps/zsafe/zsafe.h
@@ -52,44 +52,45 @@ class ZSafe : public QDialog
protected:
void paintEvent( QPaintEvent * e );
void resizeEvent ( QResizeEvent * );
bool raiseFlag;
QTimer raiseTimer;
public:
ZSafe( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = WDestructiveClose );
~ZSafe();
- static const QColor *evenRowColor;
- static const QColor *oddRowColor;
+ 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);
@@ -174,20 +175,23 @@ public slots:
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