summaryrefslogtreecommitdiff
path: root/noncore/apps/zsafe/zsafe.cpp
Unidiff
Diffstat (limited to 'noncore/apps/zsafe/zsafe.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp132
1 files changed, 116 insertions, 16 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
@@ -51,12 +51,13 @@ using namespace Opie::Ui;
51 51
52#include <qmenubar.h> 52#include <qmenubar.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54 54
55#ifdef DESKTOP 55#ifdef DESKTOP
56#include <qfiledialog.h> 56#include <qfiledialog.h>
57#include <qdragobject.h>
57#ifndef WIN32 58#ifndef WIN32
58#include <qsettings.h> 59#include <qsettings.h>
59#else 60#else
60#include "qsettings.h" 61#include "qsettings.h"
61#endif 62#endif
62#include <qapplication.h> 63#include <qapplication.h>
@@ -390,12 +391,13 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
390 : QDialog( parent, name, modal, fl ), 391 : QDialog( parent, name, modal, fl ),
391 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) 392 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l)
392{ 393{
393 IsCut = false; 394 IsCut = false;
394 IsCopy = false; 395 IsCopy = false;
395 modified = false; 396 modified = false;
397 showpwd = false;
396 398
397 // set the config file 399 // set the config file
398 cfgFile=QDir::homeDirPath(); 400 cfgFile=QDir::homeDirPath();
399 cfgFile += "/.zsafe.cfg"; 401 cfgFile += "/.zsafe.cfg";
400 // set the icon path 402 // set the icon path
401#ifdef NO_OPIE 403#ifdef NO_OPIE
@@ -454,13 +456,14 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
454 QPixmap import_img((const char**) import_xpm); 456 QPixmap import_img((const char**) import_xpm);
455 457
456 QPixmap bank_cards( ( const char** ) bank_cards_data ); 458 QPixmap bank_cards( ( const char** ) bank_cards_data );
457 QPixmap passwords( ( const char** ) passwords_data ); 459 QPixmap passwords( ( const char** ) passwords_data );
458 QPixmap software( ( const char** ) software_data ); 460 QPixmap software( ( const char** ) software_data );
459 QPixmap general( ( const char** ) general_data ); 461 QPixmap general( ( const char** ) general_data );
460 if ( !name ) 462 QPixmap image0( ( const char** ) zsafe_xpm );
463 if ( !name )
461 setName( "ZSafe" ); 464 setName( "ZSafe" );
462 465
463#ifdef DESKTOP 466#ifdef DESKTOP
464#ifdef WIN32 467#ifdef WIN32
465 setGeometry(100, 150, DeskW, DeskH-30 ); 468 setGeometry(100, 150, DeskW, DeskH-30 );
466#else 469#else
@@ -489,32 +492,69 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
489#endif 492#endif
490 setCaption( tr( "ZSafe" ) ); 493 setCaption( tr( "ZSafe" ) );
491 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; 494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe";
492 QString filename = conf->readEntry(APP_KEY+"document"); 495 QString filename = conf->readEntry(APP_KEY+"document");
493 if (filename.isEmpty() || filename.isNull()) 496 if (filename.isEmpty() || filename.isNull())
494 { 497 {
495 if ( !QDir( zsafeAppDirPath ).exists() ) 498
499 // check if the directory application exists, if not
500 // create it
501// #ifndef WIN32
502 // QString d1("Documents/application");
503// #else
504 QString d1(QDir::homeDirPath() + "/Documents/application");
505// #endif
506 QDir pd1(d1);
507 if (!pd1.exists())
508 {
509
510 QDir pd2(QDir::homeDirPath() + "/Documents");
511 if (!pd2.exists()) {
512 QDir pd3(QDir::homeDirPath());
513 if (!pd3.mkdir("Documents", FALSE)) {
514 }
515 }
516
517 if (!pd2.mkdir("application", FALSE))
496 { 518 {
497 //FIXME: Pending someone to look into why QDir.mkdir does not work as expected 519 QMessageBox::critical( 0, tr("ZSafe"),
498 QString cmdline = QString().sprintf( "mkdir -p %s", (const char*) zsafeAppDirPath ); 520#ifdef JPATCH_HDE
499 ::system( cmdline ); 521 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>"));
522#else
523 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1));
524#endif
525 exitZs (1);
500 } 526 }
501 if ( !QDir( zsafeAppDirPath ).exists() ) 527 }
528// #ifndef WIN32
529 // QString d2("Documents/application/zsafe");
530// #else
531 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
532// #endif
533 QDir pd2(d2);
534 if (!pd2.exists())
535 {
536 if (!pd1.mkdir("zsafe", FALSE))
502 { 537 {
503 QMessageBox::critical( 0, "ZSafe", tr("Can't create application data directory.\nZSafe will now exit.")); 538 QMessageBox::critical( 0, tr("ZSafe"),
504 exitZs (1); 539#ifdef JPATCH_HDE
540 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P"));
541#else
542 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2));
543#endif
544 exitZs (1);
505 } 545 }
506 } 546 }
507 547
508 // set the default filename 548 // set the default filename
509 filename = zsafeAppDirPath + "/passwords.zsf"; 549 filename = zsafeAppDirPath + "/passwords.zsf";
510 550
511 // save the current filename to the config file 551 // save the current filename to the config file
512 conf->writeEntry(APP_KEY+"document", filename); 552 conf->writeEntry(APP_KEY+"document", filename);
513 saveConf(); 553 saveConf();
514 554 }
515 //if (filename == "INVALIDPWD") 555 //if (filename == "INVALIDPWD")
516 //filename = ""; 556 //filename = "";
517 557
518 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 558 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
519#ifdef WIN32 559#ifdef WIN32
520 this->setCaption("Qt ZSafe: " + ti); 560 this->setCaption("Qt ZSafe: " + ti);
@@ -528,12 +568,13 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
528 lastSearchedName = ""; 568 lastSearchedName = "";
529 lastSearchedUsername = ""; 569 lastSearchedUsername = "";
530 lastSearchedComment = ""; 570 lastSearchedComment = "";
531 571
532 infoForm = new InfoForm(); 572 infoForm = new InfoForm();
533 categoryDialog = NULL; 573 categoryDialog = NULL;
574 infoForm->setIcon( image0);
534 575
535 // add a menu bar 576 // add a menu bar
536 QMenuBar *menu = new QMenuBar( this ); 577 QMenuBar *menu = new QMenuBar( this );
537 578
538 // add file menu 579 // add file menu
539 // QPopupMenu *file = new QPopupMenu( this ); 580 // QPopupMenu *file = new QPopupMenu( this );
@@ -663,12 +704,19 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
663 this, SLOT( listViewSelected(QListViewItem*) ) ); 704 this, SLOT( listViewSelected(QListViewItem*) ) );
664 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), 705 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ),
665 this, SLOT( showInfo(QListViewItem*) ) ); 706 this, SLOT( showInfo(QListViewItem*) ) );
666 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), 707 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ),
667 this, SLOT( showInfo(QListViewItem*) ) ); 708 this, SLOT( showInfo(QListViewItem*) ) );
668 709
710 #ifndef DESKTOP
711 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
712#endif
713 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
714 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
715
716 this->setIcon( image0);
669} 717}
670 718
671const QColor *ZSafe::evenRowColor = &Qt::white; 719const QColor *ZSafe::evenRowColor = &Qt::white;
672// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 720// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
673const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 721const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
674 722
@@ -1513,13 +1561,13 @@ void ZSafe::readAllEntries()
1513 bool isIconAv = false; 1561 bool isIconAv = false;
1514 if (!icon.isEmpty() && !icon.isNull()) 1562 if (!icon.isEmpty() && !icon.isNull())
1515 { 1563 {
1516 // build the full path 1564 // build the full path
1517 fullIconPath = iconPath + icon; 1565 fullIconPath = iconPath + icon;
1518 pix = new QPixmap (fullIconPath); 1566 pix = new QPixmap (fullIconPath);
1519 if (pix) 1567 if (!pix->isNull())
1520 { 1568 {
1521 QImage img = pix->convertToImage(); 1569 QImage img = pix->convertToImage();
1522 pix->convertFromImage(img.smoothScale(14,14)); 1570 pix->convertFromImage(img.smoothScale(14,14));
1523 c1->setIconName (icon); 1571 c1->setIconName (icon);
1524 c1->setIcon (*pix); 1572 c1->setIcon (*pix);
1525 isIconAv = true; 1573 isIconAv = true;
@@ -1728,13 +1776,13 @@ void ZSafe::readAllEntries()
1728 bool isIconAv = false; 1776 bool isIconAv = false;
1729 if (!icon.isEmpty() && !icon.isNull()) 1777 if (!icon.isEmpty() && !icon.isNull())
1730 { 1778 {
1731 // build the full path 1779 // build the full path
1732 fullIconPath = iconPath + icon; 1780 fullIconPath = iconPath + icon;
1733 pix = new QPixmap (fullIconPath); 1781 pix = new QPixmap (fullIconPath);
1734 if (pix) 1782 if (!pix->isNull())
1735 { 1783 {
1736 QImage img = pix->convertToImage(); 1784 QImage img = pix->convertToImage();
1737 pix->convertFromImage(img.smoothScale(14,14)); 1785 pix->convertFromImage(img.smoothScale(14,14));
1738 c1->setIconName (icon); 1786 c1->setIconName (icon);
1739 c1->setIcon (*pix); 1787 c1->setIcon (*pix);
1740 isIconAv = true; 1788 isIconAv = true;
@@ -1757,12 +1805,14 @@ void ZSafe::readAllEntries()
1757 1805
1758void ZSafe::resume(int) 1806void ZSafe::resume(int)
1759{ 1807{
1760 owarn << "Resume" << oendl; 1808 owarn << "Resume" << oendl;
1761 // hide the main window 1809 // hide the main window
1762 1810
1811 if ( !showpwd )
1812 {
1763 infoForm->hide(); 1813 infoForm->hide();
1764 // open zsafe again 1814 // open zsafe again
1765 m_password = ""; 1815 m_password = "";
1766 selectedItem = NULL; 1816 selectedItem = NULL;
1767 1817
1768 // clear the password list 1818 // clear the password list
@@ -1783,12 +1833,13 @@ void ZSafe::resume(int)
1783 if (_si) delete _si; 1833 if (_si) delete _si;
1784 } 1834 }
1785 } 1835 }
1786 1836
1787 // ask for password and read again 1837 // ask for password and read again
1788 openDocument(filename); 1838 openDocument(filename);
1839 }
1789} 1840}
1790 1841
1791//--------------------------------------------- 1842//---------------------------------------------
1792 1843
1793 1844
1794bool ZSafe::openDocument(const char* _filename, const char* ) 1845bool ZSafe::openDocument(const char* _filename, const char* )
@@ -1951,13 +2002,13 @@ bool ZSafe::openDocument(const char* _filename, const char* )
1951 bool isIconAv = false; 2002 bool isIconAv = false;
1952 if (!icon.isEmpty() && !icon.isNull()) 2003 if (!icon.isEmpty() && !icon.isNull())
1953 { 2004 {
1954 // build the full path 2005 // build the full path
1955 fullIconPath = iconPath + icon; 2006 fullIconPath = iconPath + icon;
1956 pix = new QPixmap (fullIconPath); 2007 pix = new QPixmap (fullIconPath);
1957 if (pix) 2008 if (!pix->isNull())
1958 { 2009 {
1959 QImage img = pix->convertToImage(); 2010 QImage img = pix->convertToImage();
1960 pix->convertFromImage(img.smoothScale(14,14)); 2011 pix->convertFromImage(img.smoothScale(14,14));
1961 c1->setIconName (icon); 2012 c1->setIconName (icon);
1962 c1->setIcon (*pix); 2013 c1->setIcon (*pix);
1963 isIconAv = true; 2014 isIconAv = true;
@@ -2299,12 +2350,15 @@ void ZSafe::getDocPassword(QString title)
2299 owarn << "getDocPassword" << oendl; 2350 owarn << "getDocPassword" << oendl;
2300 // open the 'Password' dialog 2351 // open the 'Password' dialog
2301 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2352 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2302 newPwdDialog = dialog; 2353 newPwdDialog = dialog;
2303 newPwdDialogResult = false; 2354 newPwdDialogResult = false;
2304 2355
2356 QPixmap image0( ( const char** ) zsafe_xpm );
2357 dialog->setIcon( image0);
2358
2305 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2359 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2306 this, SLOT( setPasswordDialogDone() ) ); 2360 this, SLOT( setPasswordDialogDone() ) );
2307 2361
2308 // CS: !!! 2362 // CS: !!!
2309 // int pos = filename.findRev ('/'); 2363 // int pos = filename.findRev ('/');
2310 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2364 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
@@ -2689,13 +2743,13 @@ void ZSafe::addCategory()
2689 if (icon != "predefined.png") 2743 if (icon != "predefined.png")
2690 { 2744 {
2691 // build the full path 2745 // build the full path
2692 fullIconPath = iconPath + icon; 2746 fullIconPath = iconPath + icon;
2693 pix = new QPixmap (fullIconPath); 2747 pix = new QPixmap (fullIconPath);
2694 // pix->resize(14, 14); 2748 // pix->resize(14, 14);
2695 if (pix) 2749 if (!pix->isNull())
2696 { 2750 {
2697 // save the full pixmap name into the config file 2751 // save the full pixmap name into the config file
2698// #ifndef WIN32 2752// #ifndef WIN32
2699 conf->writeEntry(APP_KEY+category, icon); 2753 conf->writeEntry(APP_KEY+category, icon);
2700// #endif 2754// #endif
2701 saveConf(); 2755 saveConf();
@@ -3158,13 +3212,13 @@ void ZSafe::editCategory()
3158 // if (!icon.isEmpty() && !icon.isNull()) 3212 // if (!icon.isEmpty() && !icon.isNull())
3159 if (icon != "predefined.png") 3213 if (icon != "predefined.png")
3160 { 3214 {
3161 // build the full path 3215 // build the full path
3162 fullIconPath = iconPath + icon; 3216 fullIconPath = iconPath + icon;
3163 pix = new QPixmap (fullIconPath); 3217 pix = new QPixmap (fullIconPath);
3164 if (pix) 3218 if (!pix->isNull())
3165 { 3219 {
3166 // save the full pixmap name into the config file 3220 // save the full pixmap name into the config file
3167// #ifndef WIN32 3221// #ifndef WIN32
3168 conf->writeEntry(APP_KEY+category, icon); 3222 conf->writeEntry(APP_KEY+category, icon);
3169// #endif 3223// #endif
3170 saveConf(); 3224 saveConf();
@@ -3689,7 +3743,53 @@ void ZSafe::setDocument(const QString& fileref)
3689 3743
3690 openDocument(filename); 3744 openDocument(filename);
3691#endif 3745#endif
3692} 3746}
3693 3747
3694 3748
3749void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) {
3750 if(item ==0) return;
3751 switch (mouse) {
3752 case 1:
3753 {
3754#ifdef DESKTOP
3755 QDragObject *d = new QTextDrag( item->text(column) , this );
3756 d->dragCopy();
3757#endif
3758 }
3759 break;
3760 case 2:
3761 {
3762 QClipboard *cb = QApplication::clipboard();
3763
3764 QIconSet copy_img((const char**) copy_xpm);
3765 QIconSet edit_img((const char**) edit_xpm);
3766 QPixmap folder_open_img((const char**) folder_open_xpm);
3767 QPixmap editdelete_img((const char**) editdelete_xpm);
3768
3769 QPopupMenu *m = new QPopupMenu(this);
3770 int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" ));
3771 int editItem = m->insertItem(edit_img, tr( "Edit" ));
3772 int showItem = m->insertItem(folder_open_img, tr( "Show Info" ));
3773 int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" ));
3774 m->setFocus();
3775 int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ;
3776 if(me == copyItem) {
3777 copyClip( item->text(column) ) ;
3778 } else if (me == cancelItem) {
3779 cb->clear();
3780 } else if (me == editItem) {
3781 editPwd();
3782 } else if (me == showItem) {
3783 showInfo(item);
3784 }
3785 }
3786 break;
3787 };
3788}
3789
3790void ZSafe::copyClip( const QString &text) {
3791 QClipboard *cb = QApplication::clipboard();
3792 cb->setText( text);
3793}
3794
3695 3795