author | llornkcor <llornkcor> | 2004-07-14 07:17:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-07-14 07:17:17 (UTC) |
commit | c70dbfde7f9605be295cdc7f789c7e3e8d823d39 (patch) (unidiff) | |
tree | 75c5fa13be08c30515685f1a6ef6b237809bbc71 | |
parent | a309681894af2632f9db2fcc252a058f218a82b2 (diff) | |
download | opie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.zip opie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.tar.gz opie-c70dbfde7f9605be295cdc7f789c7e3e8d823d39.tar.bz2 |
allow new user to create new doc on first startup
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 137 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.h | 1 |
2 files changed, 54 insertions, 84 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f3d57f8..41c572a 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -345,49 +345,49 @@ static const char* const general_data[] = { | |||
345 | "QtQtQtQt.k#r#s#m#t.H#u#v#w#x", | 345 | "QtQtQtQt.k#r#s#m#t.H#u#v#w#x", |
346 | "QtQtQtQtQtQt.k#y#z.v#A#B#C#x", | 346 | "QtQtQtQtQtQt.k#y#z.v#A#B#C#x", |
347 | "QtQtQtQtQtQtQtQt.k#D.w#s#E.k", | 347 | "QtQtQtQtQtQtQtQt.k#D.w#s#E.k", |
348 | "QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; | 348 | "QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; |
349 | 349 | ||
350 | // exit ZSafe and clear the clipboard for security reasons | 350 | // exit ZSafe and clear the clipboard for security reasons |
351 | void ZSafe::exitZs (int ec) | 351 | void ZSafe::exitZs (int ec) |
352 | { | 352 | { |
353 | QClipboard *cb = QApplication::clipboard(); | 353 | QClipboard *cb = QApplication::clipboard(); |
354 | cb->clear(); | 354 | cb->clear(); |
355 | 355 | ||
356 | exit (ec); | 356 | exit (ec); |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | // save the configuration into the file | 360 | // save the configuration into the file |
361 | void ZSafe::saveConf () | 361 | void ZSafe::saveConf () |
362 | { | 362 | { |
363 | if (conf) | 363 | if (conf) |
364 | { | 364 | { |
365 | delete conf; | 365 | delete conf; |
366 | 366 | ||
367 | #ifdef DESKTOP | 367 | #ifdef DESKTOP |
368 | #ifndef Q_WS_WIN | 368 | #ifndef Q_WS_WIN |
369 | conf = new QSettings (); | 369 | conf = new QSettings(); |
370 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); | 370 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); |
371 | #else | 371 | #else |
372 | conf = new QSettings (cfgFile); | 372 | conf = new QSettings (cfgFile); |
373 | conf->insertSearchPath (QSettings::Unix, cfgFile); | 373 | conf->insertSearchPath (QSettings::Unix, cfgFile); |
374 | #endif | 374 | #endif |
375 | #else | 375 | #else |
376 | conf = new Config (cfgFile, Config::File); | 376 | conf = new Config (cfgFile, Config::File); |
377 | conf->setGroup ("zsafe"); | 377 | conf->setGroup ("zsafe"); |
378 | #endif | 378 | #endif |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | /* | 383 | /* |
384 | * Constructs a ZSafe which is a child of 'parent', with the | 384 | * Constructs a ZSafe which is a child of 'parent', with the |
385 | * name 'name' and widget flags set to 'f' | 385 | * name 'name' and widget flags set to 'f' |
386 | * | 386 | * |
387 | * The dialog will by default be modeless, unless you set 'modal' to | 387 | * The dialog will by default be modeless, unless you set 'modal' to |
388 | * TRUE to construct a modal dialog. | 388 | * TRUE to construct a modal dialog. |
389 | */ | 389 | */ |
390 | ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) | 390 | ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) |
391 | : QDialog( parent, name, modal, fl ), | 391 | : QDialog( parent, name, modal, fl ), |
392 | Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) | 392 | Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) |
393 | { | 393 | { |
@@ -472,101 +472,98 @@ ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) | |||
472 | 472 | ||
473 | #else | 473 | #else |
474 | 474 | ||
475 | #ifdef JPATCH_HDE | 475 | #ifdef JPATCH_HDE |
476 | int DeskS; | 476 | int DeskS; |
477 | if(DeskW > DeskH) | 477 | if(DeskW > DeskH) |
478 | { | 478 | { |
479 | DeskS = DeskW; | 479 | DeskS = DeskW; |
480 | } | 480 | } |
481 | else | 481 | else |
482 | { | 482 | { |
483 | DeskS = DeskH; | 483 | DeskS = DeskH; |
484 | } | 484 | } |
485 | resize( DeskW, DeskH ); | 485 | resize( DeskW, DeskH ); |
486 | setMinimumSize( QSize( DeskS, DeskS ) ); | 486 | setMinimumSize( QSize( DeskS, DeskS ) ); |
487 | setMaximumSize( QSize( DeskS, DeskS ) ); | 487 | setMaximumSize( QSize( DeskS, DeskS ) ); |
488 | #else | 488 | #else |
489 | resize( DeskW, DeskH-30 ); | 489 | resize( DeskW, DeskH-30 ); |
490 | #endif | 490 | #endif |
491 | 491 | ||
492 | #endif | 492 | #endif |
493 | setCaption( tr( "ZSafe" ) ); | 493 | setCaption( tr( "ZSafe" ) ); |
494 | QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; | 494 | QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; |
495 | QString filename = conf->readEntry(APP_KEY+"document"); | 495 | QString filename = conf->readEntry(APP_KEY+"document"); |
496 | if (filename.isEmpty() || filename.isNull()) | 496 | if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() ) |
497 | { | 497 | { |
498 | |||
499 | // check if the directory application exists, if not | 498 | // check if the directory application exists, if not |
500 | // create it | 499 | // create it |
501 | // #ifndef Q_WS_WIN | 500 | // #ifndef Q_WS_WIN |
502 | // QString d1("Documents/application"); | 501 | // QString d1("Documents/application"); |
503 | // #else | 502 | // #else |
504 | QString d1(QDir::homeDirPath() + "/Documents/application"); | 503 | QString d1(QDir::homeDirPath() + "/Documents/application"); |
505 | // #endif | 504 | // #endif |
506 | QDir pd1(d1); | 505 | QDir pd1(d1); |
507 | if (!pd1.exists()) | 506 | if (!pd1.exists()) |
508 | { | 507 | { |
509 | |||
510 | QDir pd2(QDir::homeDirPath() + "/Documents"); | 508 | QDir pd2(QDir::homeDirPath() + "/Documents"); |
511 | if (!pd2.exists()) { | 509 | if (!pd2.exists()) { |
512 | QDir pd3(QDir::homeDirPath()); | 510 | QDir pd3(QDir::homeDirPath()); |
513 | if (!pd3.mkdir("Documents", FALSE)) { | 511 | if (!pd3.mkdir("Documents", FALSE)) { |
514 | } | 512 | } |
515 | } | 513 | } |
516 | 514 | ||
517 | if (!pd2.mkdir("application", FALSE)) | 515 | if (!pd2.mkdir("application", FALSE)) |
518 | { | 516 | { |
519 | QMessageBox::critical( 0, tr("ZSafe"), | 517 | QMessageBox::critical( 0, tr("ZSafe"), |
520 | #ifdef JPATCH_HDE | 518 | #ifdef JPATCH_HDE |
521 | tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); | 519 | tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); |
522 | #else | 520 | #else |
523 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); | 521 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); |
524 | #endif | 522 | #endif |
525 | exitZs (1); | 523 | exitZs (1); |
526 | } | 524 | } |
527 | } | 525 | } |
528 | // #ifndef Q_WS_WIN | 526 | // #ifndef Q_WS_WIN |
529 | // QString d2("Documents/application/zsafe"); | 527 | // QString d2("Documents/application/zsafe"); |
530 | // #else | 528 | // #else |
531 | QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); | 529 | QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); |
532 | // #endif | 530 | // #endif |
533 | QDir pd2(d2); | 531 | QDir pd2(d2); |
534 | if (!pd2.exists()) | 532 | if (!pd2.exists()) |
535 | { | 533 | { |
536 | if (!pd1.mkdir("zsafe", FALSE)) | 534 | if (!pd1.mkdir("zsafe", FALSE)) |
537 | { | 535 | { |
538 | QMessageBox::critical( 0, tr("ZSafe"), | 536 | QMessageBox::critical( 0, tr("ZSafe"), |
539 | #ifdef JPATCH_HDE | 537 | #ifdef JPATCH_HDE |
540 | tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); | 538 | tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); |
541 | #else | 539 | #else |
542 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); | 540 | tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); |
543 | #endif | 541 | #endif |
544 | exitZs (1); | 542 | exitZs (1); |
545 | } | 543 | } |
546 | } | 544 | } |
547 | 545 | ||
548 | // set the default filename | ||
549 | filename = zsafeAppDirPath + "/passwords.zsf"; | 546 | filename = zsafeAppDirPath + "/passwords.zsf"; |
550 | 547 | ||
551 | // save the current filename to the config file | 548 | // save the current filename to the config file |
552 | conf->writeEntry(APP_KEY+"document", filename); | 549 | conf->writeEntry(APP_KEY+"document", filename); |
553 | saveConf(); | 550 | saveConf(); |
554 | } | 551 | } |
555 | //if (filename == "INVALIDPWD") | 552 | //if (filename == "INVALIDPWD") |
556 | //filename = ""; | 553 | //filename = ""; |
557 | 554 | ||
558 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 555 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
559 | #ifdef Q_WS_WIN | 556 | #ifdef Q_WS_WIN |
560 | this->setCaption("Qt ZSafe: " + ti); | 557 | this->setCaption("Qt ZSafe: " + ti); |
561 | #else | 558 | #else |
562 | this->setCaption("ZSafe: " + ti); | 559 | this->setCaption("ZSafe: " + ti); |
563 | #endif | 560 | #endif |
564 | 561 | ||
565 | selectedItem = NULL; | 562 | selectedItem = NULL; |
566 | lastSearchedCategory = NULL; | 563 | lastSearchedCategory = NULL; |
567 | lastSearchedItem = NULL; | 564 | lastSearchedItem = NULL; |
568 | lastSearchedName = ""; | 565 | lastSearchedName = ""; |
569 | lastSearchedUsername = ""; | 566 | lastSearchedUsername = ""; |
570 | lastSearchedComment = ""; | 567 | lastSearchedComment = ""; |
571 | 568 | ||
572 | infoForm = new InfoForm(this, "show_info", TRUE); | 569 | infoForm = new InfoForm(this, "show_info", TRUE); |
@@ -1318,74 +1315,49 @@ void ZSafe::removeAsciiFile() | |||
1318 | if ( !f.remove() ) | 1315 | if ( !f.remove() ) |
1319 | { | 1316 | { |
1320 | #ifndef NO_OPIE | 1317 | #ifndef NO_OPIE |
1321 | owarn << "Could not remove file " << fn << oendl; | 1318 | owarn << "Could not remove file " << fn << oendl; |
1322 | #else | 1319 | #else |
1323 | qWarning( QString("Could not remove file %1").arg(fn),2000 ); | 1320 | qWarning( QString("Could not remove file %1").arg(fn),2000 ); |
1324 | #endif | 1321 | #endif |
1325 | QMessageBox::critical( 0, tr("ZSafe"), | 1322 | QMessageBox::critical( 0, tr("ZSafe"), |
1326 | tr("Could not remove text file.") ); | 1323 | tr("Could not remove text file.") ); |
1327 | return; | 1324 | return; |
1328 | } | 1325 | } |
1329 | } | 1326 | } |
1330 | } | 1327 | } |
1331 | 1328 | ||
1332 | void ZSafe::writeAllEntries() | 1329 | void ZSafe::writeAllEntries() |
1333 | { | 1330 | { |
1334 | if (filename.isEmpty()) | 1331 | if (filename.isEmpty()) |
1335 | { | 1332 | { |
1336 | QMessageBox::critical( 0, tr("ZSafe"), | 1333 | QMessageBox::critical( 0, tr("ZSafe"), |
1337 | tr("No document defined.\nYou have to create a new document")); | 1334 | tr("No document defined.\nYou have to create a new document")); |
1338 | return; | 1335 | return; |
1339 | } | 1336 | } |
1340 | 1337 | ||
1341 | // open the file dialog | 1338 | // open the file dialog |
1342 | #ifndef DESKTOP | 1339 | QString fn = zsaveDialog(); |
1343 | #ifndef NO_OPIE | ||
1344 | QMap<QString, QStringList> mimeTypes; | ||
1345 | mimeTypes.insert(tr("All"), QStringList() ); | ||
1346 | mimeTypes.insert(tr("Text"), "text/*" ); | ||
1347 | QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
1348 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1349 | QString::null, | ||
1350 | mimeTypes, | ||
1351 | this, | ||
1352 | tr ("Export text file")); | ||
1353 | #else | ||
1354 | QString fn = ScQtFileEdit::getSaveAsFileName(this, | ||
1355 | tr ("Export text file"), | ||
1356 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1357 | "*.txt"); | ||
1358 | #endif | ||
1359 | #else | ||
1360 | QString fn = QFileDialog::getSaveFileName( | ||
1361 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
1362 | "ZSafe (*.txt)", | ||
1363 | this, | ||
1364 | "ZSafe File Dialog" | ||
1365 | "Choose a text file" ); | ||
1366 | #endif | ||
1367 | |||
1368 | // open the new document | 1340 | // open the new document |
1369 | if (fn && fn.length() > 0 ) | 1341 | if (fn && fn.length() > 0 ) |
1370 | { | 1342 | { |
1371 | QFile f( fn ); | 1343 | QFile f( fn ); |
1372 | if ( !f.open( IO_WriteOnly ) ) { | 1344 | if ( !f.open( IO_WriteOnly ) ) { |
1373 | #ifndef NO_OPIE | 1345 | #ifndef NO_OPIE |
1374 | owarn << "Could not write to file " << fn << oendl; | 1346 | owarn << "Could not write to file " << fn << oendl; |
1375 | #else | 1347 | #else |
1376 | qWarning( QString("Could not write to file %1").arg(fn),2000 ); | 1348 | qWarning( QString("Could not write to file %1").arg(fn),2000 ); |
1377 | #endif | 1349 | #endif |
1378 | QMessageBox::critical( 0, "ZSafe", | 1350 | QMessageBox::critical( 0, "ZSafe", |
1379 | QString("Could not export to text file.") ); | 1351 | QString("Could not export to text file.") ); |
1380 | return; | 1352 | return; |
1381 | } | 1353 | } |
1382 | QTextStream t( &f ); | 1354 | QTextStream t( &f ); |
1383 | 1355 | ||
1384 | QListViewItem *i; | 1356 | QListViewItem *i; |
1385 | // step through all categories | 1357 | // step through all categories |
1386 | for (i = ListView->firstChild(); | 1358 | for (i = ListView->firstChild(); |
1387 | i != NULL; | 1359 | i != NULL; |
1388 | i = i->nextSibling()) | 1360 | i = i->nextSibling()) |
1389 | { | 1361 | { |
1390 | // step through all subitems | 1362 | // step through all subitems |
1391 | QListViewItem *si; | 1363 | QListViewItem *si; |
@@ -1900,48 +1872,50 @@ void ZSafe::resume(int) | |||
1900 | i = i->nextSibling()) | 1872 | i = i->nextSibling()) |
1901 | { | 1873 | { |
1902 | // step through all subitems | 1874 | // step through all subitems |
1903 | QListViewItem *si; | 1875 | QListViewItem *si; |
1904 | for (si = i->firstChild(); | 1876 | for (si = i->firstChild(); |
1905 | si != NULL; ) | 1877 | si != NULL; ) |
1906 | { | 1878 | { |
1907 | QListViewItem *_si = si; | 1879 | QListViewItem *_si = si; |
1908 | si = si->nextSibling(); | 1880 | si = si->nextSibling(); |
1909 | i->takeItem(_si); // remove from view list | 1881 | i->takeItem(_si); // remove from view list |
1910 | if (_si) delete _si; | 1882 | if (_si) delete _si; |
1911 | } | 1883 | } |
1912 | } | 1884 | } |
1913 | 1885 | ||
1914 | // ask for password and read again | 1886 | // ask for password and read again |
1915 | openDocument(filename); | 1887 | openDocument(filename); |
1916 | } | 1888 | } |
1917 | } | 1889 | } |
1918 | 1890 | ||
1919 | //--------------------------------------------- | 1891 | //--------------------------------------------- |
1920 | 1892 | ||
1921 | 1893 | ||
1922 | bool ZSafe::openDocument(const char* _filename, const char* ) | 1894 | bool ZSafe::openDocument(const char* _filename, const char* ) |
1923 | { | 1895 | { |
1896 | QString name= _filename; | ||
1897 | qWarning("openDocument "+name); | ||
1924 | int retval; | 1898 | int retval; |
1925 | char* entry[FIELD_SIZE]; | 1899 | char* entry[FIELD_SIZE]; |
1926 | // #ifndef Q_WS_WIN | 1900 | // #ifndef Q_WS_WIN |
1927 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); | 1901 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); |
1928 | // #else | 1902 | // #else |
1929 | // int validationFlag = 1; | 1903 | // int validationFlag = 1; |
1930 | // #endif | 1904 | // #endif |
1931 | 1905 | ||
1932 | int pwdOk = 0; | 1906 | int pwdOk = 0; |
1933 | int numberOfTries = 3; | 1907 | int numberOfTries = 3; |
1934 | for (int i=0; i < numberOfTries; i++) | 1908 | for (int i=0; i < numberOfTries; i++) |
1935 | { | 1909 | { |
1936 | QFile f(_filename); | 1910 | QFile f(_filename); |
1937 | if (f.exists()) | 1911 | if (f.exists()) |
1938 | { | 1912 | { |
1939 | // ask with a dialog for the password | 1913 | // ask with a dialog for the password |
1940 | if (m_password.isEmpty()) | 1914 | if (m_password.isEmpty()) |
1941 | getDocPassword(tr("Enter Password")); | 1915 | getDocPassword(tr("Enter Password")); |
1942 | if (m_password.isEmpty() && validationFlag == 0) | 1916 | if (m_password.isEmpty() && validationFlag == 0) |
1943 | { | 1917 | { |
1944 | #ifndef NO_OPIE | 1918 | #ifndef NO_OPIE |
1945 | owarn << "Wrong password" << oendl; | 1919 | owarn << "Wrong password" << oendl; |
1946 | #else | 1920 | #else |
1947 | qWarning ("Wrong password"); | 1921 | qWarning ("Wrong password"); |
@@ -1949,49 +1923,63 @@ bool ZSafe::openDocument(const char* _filename, const char* ) | |||
1949 | QMessageBox::critical( 0, tr("ZSafe"), | 1923 | QMessageBox::critical( 0, tr("ZSafe"), |
1950 | tr("Wrong password.\n\nZSafe will now exit.") ); | 1924 | tr("Wrong password.\n\nZSafe will now exit.") ); |
1951 | exitZs (1); | 1925 | exitZs (1); |
1952 | } | 1926 | } |
1953 | 1927 | ||
1954 | retval = loadInit(_filename, m_password); | 1928 | retval = loadInit(_filename, m_password); |
1955 | if (retval != PWERR_GOOD) | 1929 | if (retval != PWERR_GOOD) |
1956 | { | 1930 | { |
1957 | #ifndef NO_OPIE | 1931 | #ifndef NO_OPIE |
1958 | owarn << "Error loading Document" << oendl; | 1932 | owarn << "Error loading Document" << oendl; |
1959 | #else | 1933 | #else |
1960 | qWarning ("Error loading Document"); | 1934 | qWarning ("Error loading Document"); |
1961 | #endif | 1935 | #endif |
1962 | return false; | 1936 | return false; |
1963 | } | 1937 | } |
1964 | } | 1938 | } |
1965 | else | 1939 | else |
1966 | { | 1940 | { |
1967 | #ifdef Q_WS_WIN | 1941 | #ifdef Q_WS_WIN |
1968 | this->setCaption("Qt ZSafe"); | 1942 | this->setCaption("Qt ZSafe"); |
1969 | #else | 1943 | #else |
1970 | this->setCaption("ZSafe"); | 1944 | this->setCaption("ZSafe"); |
1971 | #endif | 1945 | #endif |
1972 | filename = ""; | 1946 | filename = ""; |
1947 | switch( QMessageBox::warning( this, tr("ZSafe"), | ||
1948 | tr("<P>You must create a new document first. Ok to create?</P>"), | ||
1949 | tr("&Yes"), tr("&No."), | ||
1950 | 0 | ||
1951 | ) ) | ||
1952 | { | ||
1953 | case 1: // No | ||
1973 | return false; | 1954 | return false; |
1955 | break; | ||
1956 | case 0: // Yes | ||
1957 | newDocument(); | ||
1958 | return false; | ||
1959 | break; | ||
1960 | } | ||
1961 | |||
1974 | } | 1962 | } |
1975 | 1963 | ||
1976 | 1964 | ||
1977 | // load the validation entry | 1965 | // load the validation entry |
1978 | if (validationFlag == 0) | 1966 | if (validationFlag == 0) |
1979 | { | 1967 | { |
1980 | pwdOk = 1; | 1968 | pwdOk = 1; |
1981 | break; | 1969 | break; |
1982 | } | 1970 | } |
1983 | 1971 | ||
1984 | retval = loadEntry(entry); | 1972 | retval = loadEntry(entry); |
1985 | if (retval == 1 && | 1973 | if (retval == 1 && |
1986 | !strcmp (entry[0], "ZSAFECATEGORY") && | 1974 | !strcmp (entry[0], "ZSAFECATEGORY") && |
1987 | !strcmp (entry[1], "name") && | 1975 | !strcmp (entry[1], "name") && |
1988 | !strcmp (entry[2], "username") && | 1976 | !strcmp (entry[2], "username") && |
1989 | !strcmp (entry[3], "password") && | 1977 | !strcmp (entry[3], "password") && |
1990 | !strcmp (entry[4], "comment") ) | 1978 | !strcmp (entry[4], "comment") ) |
1991 | { | 1979 | { |
1992 | for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); | 1980 | for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); |
1993 | pwdOk = 1; | 1981 | pwdOk = 1; |
1994 | break; | 1982 | break; |
1995 | } | 1983 | } |
1996 | else | 1984 | else |
1997 | // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); | 1985 | // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); |
@@ -3426,73 +3414,49 @@ void ZSafe::pasteItem() | |||
3426 | { | 3414 | { |
3427 | if (copiedItem) | 3415 | if (copiedItem) |
3428 | { | 3416 | { |
3429 | // add the new item | 3417 | // add the new item |
3430 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3418 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3431 | // i->setOpen (TRUE); | 3419 | // i->setOpen (TRUE); |
3432 | i->setText (0, copiedItem->text(0)); | 3420 | i->setText (0, copiedItem->text(0)); |
3433 | i->setText (1, copiedItem->text(1)); | 3421 | i->setText (1, copiedItem->text(1)); |
3434 | i->setText (2, copiedItem->text(2)); | 3422 | i->setText (2, copiedItem->text(2)); |
3435 | i->setText (3, copiedItem->text(3)); | 3423 | i->setText (3, copiedItem->text(3)); |
3436 | i->setText (4, copiedItem->text(4)); | 3424 | i->setText (4, copiedItem->text(4)); |
3437 | i->setText (5, copiedItem->text(5)); | 3425 | i->setText (5, copiedItem->text(5)); |
3438 | selectedItem->setOpen( TRUE ); | 3426 | selectedItem->setOpen( TRUE ); |
3439 | } | 3427 | } |
3440 | } | 3428 | } |
3441 | } | 3429 | } |
3442 | IsCut = false; | 3430 | IsCut = false; |
3443 | IsCopy = false; | 3431 | IsCopy = false; |
3444 | } | 3432 | } |
3445 | 3433 | ||
3446 | void ZSafe::newDocument() | 3434 | void ZSafe::newDocument() |
3447 | { | 3435 | { |
3448 | 3436 | ||
3449 | // open the file dialog | 3437 | // open the file dialog |
3450 | #ifndef DESKTOP | 3438 | QString newFile = zsaveDialog(); |
3451 | #ifndef NO_OPIE | ||
3452 | QMap<QString, QStringList> mimeTypes; | ||
3453 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3454 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | ||
3455 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3456 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3457 | QString::null, | ||
3458 | mimeTypes, | ||
3459 | this, | ||
3460 | tr ("Create new ZSafe document")); | ||
3461 | #else | ||
3462 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | ||
3463 | tr ("Create new ZSafe document"), | ||
3464 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3465 | "*.zsf"); | ||
3466 | #endif | ||
3467 | #else | ||
3468 | QString newFile = QFileDialog::getSaveFileName( | ||
3469 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3470 | "ZSafe (*.zsf)", | ||
3471 | this, | ||
3472 | "ZSafe File Dialog" | ||
3473 | "Choose a ZSafe file" ); | ||
3474 | #endif | ||
3475 | 3439 | ||
3476 | // open the new document | 3440 | // open the new document |
3477 | if (newFile && newFile.length() > 0 ) | 3441 | if (newFile && newFile.length() > 0 ) |
3478 | { | 3442 | { |
3479 | // save the previous opened document | 3443 | // save the previous opened document |
3480 | if (!filename.isEmpty()) | 3444 | if (!filename.isEmpty()) |
3481 | saveDocument(filename, FALSE); | 3445 | saveDocument(filename, FALSE); |
3482 | 3446 | ||
3483 | modified = true; | 3447 | modified = true; |
3484 | 3448 | ||
3485 | // clear the password list | 3449 | // clear the password list |
3486 | QListViewItem *i; | 3450 | QListViewItem *i; |
3487 | QListViewItem *c = NULL; | 3451 | QListViewItem *c = NULL; |
3488 | // step through all categories | 3452 | // step through all categories |
3489 | for (i = ListView->firstChild(); | 3453 | for (i = ListView->firstChild(); |
3490 | i != NULL; | 3454 | i != NULL; |
3491 | i = i->nextSibling()) | 3455 | i = i->nextSibling()) |
3492 | { | 3456 | { |
3493 | if (c) delete c; // delete the previous category | 3457 | if (c) delete c; // delete the previous category |
3494 | 3458 | ||
3495 | c = i; | 3459 | c = i; |
3496 | // step through all subitems | 3460 | // step through all subitems |
3497 | QListViewItem *si; | 3461 | QListViewItem *si; |
3498 | for (si = i->firstChild(); | 3462 | for (si = i->firstChild(); |
@@ -3592,75 +3556,49 @@ void ZSafe::loadDocument() | |||
3592 | } | 3556 | } |
3593 | if (c) delete c; // delete the previous category | 3557 | if (c) delete c; // delete the previous category |
3594 | categories.clear(); | 3558 | categories.clear(); |
3595 | m_password = ""; | 3559 | m_password = ""; |
3596 | selectedItem = NULL; | 3560 | selectedItem = NULL; |
3597 | filename = newFile; | 3561 | filename = newFile; |
3598 | 3562 | ||
3599 | // save the current filename to the config file | 3563 | // save the current filename to the config file |
3600 | conf->writeEntry(APP_KEY+"document", filename); | 3564 | conf->writeEntry(APP_KEY+"document", filename); |
3601 | saveConf(); | 3565 | saveConf(); |
3602 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 3566 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
3603 | #ifdef Q_WS_WIN | 3567 | #ifdef Q_WS_WIN |
3604 | this->setCaption("Qt ZSafe: " + ti); | 3568 | this->setCaption("Qt ZSafe: " + ti); |
3605 | #else | 3569 | #else |
3606 | this->setCaption("ZSafe: " + ti); | 3570 | this->setCaption("ZSafe: " + ti); |
3607 | #endif | 3571 | #endif |
3608 | 3572 | ||
3609 | openDocument(filename); | 3573 | openDocument(filename); |
3610 | } | 3574 | } |
3611 | } | 3575 | } |
3612 | 3576 | ||
3613 | void ZSafe::saveDocumentAs() | 3577 | void ZSafe::saveDocumentAs() |
3614 | { | 3578 | { |
3615 | 3579 | ||
3616 | #ifndef DESKTOP | 3580 | QString newFile = zsaveDialog(); |
3617 | #ifndef NO_OPIE | ||
3618 | QMap<QString, QStringList> mimeTypes; | ||
3619 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3620 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | ||
3621 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3622 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3623 | QString::null, | ||
3624 | mimeTypes, | ||
3625 | this, | ||
3626 | tr ("Save ZSafe document as..")); | ||
3627 | #else | ||
3628 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | ||
3629 | tr ("Save ZSafe document as.."), | ||
3630 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3631 | "*.zsf"); | ||
3632 | #endif | ||
3633 | #else | ||
3634 | // open the file dialog | ||
3635 | QString newFile = QFileDialog::getSaveFileName( | ||
3636 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3637 | "ZSafe (*.zsf)", | ||
3638 | this, | ||
3639 | "ZSafe File Dialog" | ||
3640 | "Choose a ZSafe file" ); | ||
3641 | #endif | ||
3642 | |||
3643 | // open the new document | 3581 | // open the new document |
3644 | if (newFile && newFile.length() > 0 ) | 3582 | if (newFile && newFile.length() > 0 ) |
3645 | { | 3583 | { |
3646 | // save the previous opened document | 3584 | // save the previous opened document |
3647 | if (!filename.isEmpty()) | 3585 | if (!filename.isEmpty()) |
3648 | saveDocument(filename, FALSE); | 3586 | saveDocument(filename, FALSE); |
3649 | 3587 | ||
3650 | selectedItem = NULL; | 3588 | selectedItem = NULL; |
3651 | filename = newFile; | 3589 | filename = newFile; |
3652 | 3590 | ||
3653 | // save the current filename to the config file | 3591 | // save the current filename to the config file |
3654 | conf->writeEntry(APP_KEY+"document", filename); | 3592 | conf->writeEntry(APP_KEY+"document", filename); |
3655 | saveConf(); | 3593 | saveConf(); |
3656 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 3594 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
3657 | #ifdef Q_WS_WIN | 3595 | #ifdef Q_WS_WIN |
3658 | this->setCaption("Qt ZSafe: " + ti); | 3596 | this->setCaption("Qt ZSafe: " + ti); |
3659 | #else | 3597 | #else |
3660 | this->setCaption("ZSafe: " + ti); | 3598 | this->setCaption("ZSafe: " + ti); |
3661 | #endif | 3599 | #endif |
3662 | 3600 | ||
3663 | QMessageBox::information( this, tr("ZSafe"), | 3601 | QMessageBox::information( this, tr("ZSafe"), |
3664 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); | 3602 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); |
3665 | 3603 | ||
3666 | saveDocumentWithPwd(); | 3604 | saveDocumentWithPwd(); |
@@ -3832,48 +3770,50 @@ void ZSafe::setDocument(const QString& fileref) | |||
3832 | i != NULL; | 3770 | i != NULL; |
3833 | i = i->nextSibling()) | 3771 | i = i->nextSibling()) |
3834 | { | 3772 | { |
3835 | if (c) delete c; // delete the previous category | 3773 | if (c) delete c; // delete the previous category |
3836 | 3774 | ||
3837 | c = i; | 3775 | c = i; |
3838 | // step through all subitems | 3776 | // step through all subitems |
3839 | QListViewItem *si; | 3777 | QListViewItem *si; |
3840 | for (si = i->firstChild(); | 3778 | for (si = i->firstChild(); |
3841 | si != NULL; ) | 3779 | si != NULL; ) |
3842 | { | 3780 | { |
3843 | QListViewItem *_si = si; | 3781 | QListViewItem *_si = si; |
3844 | si = si->nextSibling(); | 3782 | si = si->nextSibling(); |
3845 | i->takeItem(_si); // remove from view list | 3783 | i->takeItem(_si); // remove from view list |
3846 | if (_si) delete _si; | 3784 | if (_si) delete _si; |
3847 | } | 3785 | } |
3848 | } | 3786 | } |
3849 | if (c) delete c; // delete the previous category | 3787 | if (c) delete c; // delete the previous category |
3850 | categories.clear(); | 3788 | categories.clear(); |
3851 | 3789 | ||
3852 | m_password = ""; | 3790 | m_password = ""; |
3853 | selectedItem = NULL; | 3791 | selectedItem = NULL; |
3854 | 3792 | ||
3855 | openDocument(filename); | 3793 | openDocument(filename); |
3794 | #else | ||
3795 | Q_UNUSED(fileref); | ||
3856 | #endif | 3796 | #endif |
3857 | } | 3797 | } |
3858 | 3798 | ||
3859 | 3799 | ||
3860 | void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { | 3800 | void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { |
3861 | if(item ==0) return; | 3801 | if(item ==0) return; |
3862 | switch (mouse) { | 3802 | switch (mouse) { |
3863 | case 1: | 3803 | case 1: |
3864 | { | 3804 | { |
3865 | #ifdef DESKTOP | 3805 | #ifdef DESKTOP |
3866 | QDragObject *d = new QTextDrag( item->text(column) , this ); | 3806 | QDragObject *d = new QTextDrag( item->text(column) , this ); |
3867 | d->dragCopy(); | 3807 | d->dragCopy(); |
3868 | #endif | 3808 | #endif |
3869 | } | 3809 | } |
3870 | break; | 3810 | break; |
3871 | case 2: | 3811 | case 2: |
3872 | { | 3812 | { |
3873 | QClipboard *cb = QApplication::clipboard(); | 3813 | QClipboard *cb = QApplication::clipboard(); |
3874 | 3814 | ||
3875 | QIconSet copy_img((const char**) copy_xpm); | 3815 | QIconSet copy_img((const char**) copy_xpm); |
3876 | QIconSet edit_img((const char**) edit_xpm); | 3816 | QIconSet edit_img((const char**) edit_xpm); |
3877 | QPixmap folder_open_img((const char**) folder_open_xpm); | 3817 | QPixmap folder_open_img((const char**) folder_open_xpm); |
3878 | QPixmap editdelete_img((const char**) editdelete_xpm); | 3818 | QPixmap editdelete_img((const char**) editdelete_xpm); |
3879 | 3819 | ||
@@ -3883,24 +3823,53 @@ void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int colum | |||
3883 | int showItem = m->insertItem(folder_open_img, tr( "Show Info" )); | 3823 | int showItem = m->insertItem(folder_open_img, tr( "Show Info" )); |
3884 | int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" )); | 3824 | int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" )); |
3885 | m->setFocus(); | 3825 | m->setFocus(); |
3886 | int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ; | 3826 | int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ; |
3887 | if(me == copyItem) { | 3827 | if(me == copyItem) { |
3888 | copyClip( item->text(column) ) ; | 3828 | copyClip( item->text(column) ) ; |
3889 | } else if (me == cancelItem) { | 3829 | } else if (me == cancelItem) { |
3890 | cb->clear(); | 3830 | cb->clear(); |
3891 | } else if (me == editItem) { | 3831 | } else if (me == editItem) { |
3892 | editPwd(); | 3832 | editPwd(); |
3893 | } else if (me == showItem) { | 3833 | } else if (me == showItem) { |
3894 | showInfo(item); | 3834 | showInfo(item); |
3895 | } | 3835 | } |
3896 | } | 3836 | } |
3897 | break; | 3837 | break; |
3898 | }; | 3838 | }; |
3899 | } | 3839 | } |
3900 | 3840 | ||
3901 | void ZSafe::copyClip( const QString &text) { | 3841 | void ZSafe::copyClip( const QString &text) { |
3902 | QClipboard *cb = QApplication::clipboard(); | 3842 | QClipboard *cb = QApplication::clipboard(); |
3903 | cb->setText( text); | 3843 | cb->setText( text); |
3904 | } | 3844 | } |
3905 | 3845 | ||
3906 | 3846 | ||
3847 | QString ZSafe::zsaveDialog() { | ||
3848 | |||
3849 | QString fn; | ||
3850 | #ifndef DESKTOP | ||
3851 | #ifndef NO_OPIE | ||
3852 | QMap<QString, QStringList> mimeTypes; | ||
3853 | mimeTypes.insert(tr("All"), QStringList() ); | ||
3854 | mimeTypes.insert(tr("Text"), "text/*" ); | ||
3855 | fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | ||
3856 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3857 | QString::null, | ||
3858 | mimeTypes, | ||
3859 | this, | ||
3860 | tr ("Export text file")); | ||
3861 | #else | ||
3862 | fn = ScQtFileEdit::getSaveAsFileName(this, | ||
3863 | tr ("Export text file"), | ||
3864 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3865 | "*.txt"); | ||
3866 | #endif | ||
3867 | #else | ||
3868 | fn = QFileDialog::getSaveFileName( | ||
3869 | QDir::homeDirPath() + "/Documents/application/zsafe", | ||
3870 | "ZSafe (*.txt)", | ||
3871 | this, | ||
3872 | "ZSafe"); | ||
3873 | #endif | ||
3874 | return fn; | ||
3875 | } | ||
diff --git a/noncore/apps/zsafe/zsafe.h b/noncore/apps/zsafe/zsafe.h index ca041ff..7419797 100644 --- a/noncore/apps/zsafe/zsafe.h +++ b/noncore/apps/zsafe/zsafe.h | |||
@@ -132,48 +132,49 @@ public: | |||
132 | 132 | ||
133 | QTimer docuTimer; | 133 | QTimer docuTimer; |
134 | 134 | ||
135 | 135 | ||
136 | bool openDocument(const char* filename, const char* format=0); | 136 | bool openDocument(const char* filename, const char* format=0); |
137 | int loadInit(const char* filename, const char *password); | 137 | int loadInit(const char* filename, const char *password); |
138 | int loadEntry(char *entry[4]); | 138 | int loadEntry(char *entry[4]); |
139 | int loadFinalize(void); | 139 | int loadFinalize(void); |
140 | bool saveDocument(const char* filename, bool withPwd, const char* format=0); | 140 | bool saveDocument(const char* filename, bool withPwd, const char* format=0); |
141 | int saveInit(const char *filename, const char *password); | 141 | int saveInit(const char *filename, const char *password); |
142 | int saveEntry(char *entry[4]); | 142 | int saveEntry(char *entry[4]); |
143 | int saveFinalize(void); | 143 | int saveFinalize(void); |
144 | void saveConf(); | 144 | void saveConf(); |
145 | QPixmap * getPredefinedIcon(QString category); | 145 | QPixmap * getPredefinedIcon(QString category); |
146 | QString getFieldLabel (QListViewItem *_item, QString field, QString def); | 146 | QString getFieldLabel (QListViewItem *_item, QString field, QString def); |
147 | QString getFieldLabel (QString category, QString field, QString def); | 147 | QString getFieldLabel (QString category, QString field, QString def); |
148 | void setCategoryDialogFields(CategoryDialog *dialog); | 148 | void setCategoryDialogFields(CategoryDialog *dialog); |
149 | void setCategoryDialogFields(CategoryDialog *dialog, QString category); | 149 | void setCategoryDialogFields(CategoryDialog *dialog, QString category); |
150 | void saveCategoryDialogFields(CategoryDialog *dialog); | 150 | void saveCategoryDialogFields(CategoryDialog *dialog); |
151 | 151 | ||
152 | 152 | ||
153 | void resume(int signum); | 153 | void resume(int signum); |
154 | void exitZs (int ec); | 154 | void exitZs (int ec); |
155 | 155 | ||
156 | QString zsaveDialog(); | ||
156 | 157 | ||
157 | public slots: | 158 | public slots: |
158 | virtual void deletePwd(); | 159 | virtual void deletePwd(); |
159 | virtual void editPwd(); | 160 | virtual void editPwd(); |
160 | virtual void newPwd(); | 161 | virtual void newPwd(); |
161 | virtual void findPwd(); | 162 | virtual void findPwd(); |
162 | virtual void quitMe(); | 163 | virtual void quitMe(); |
163 | virtual void listViewSelected( QListViewItem *_item); | 164 | virtual void listViewSelected( QListViewItem *_item); |
164 | virtual void showInfo( QListViewItem *_item); | 165 | virtual void showInfo( QListViewItem *_item); |
165 | virtual void writeAllEntries(); | 166 | virtual void writeAllEntries(); |
166 | virtual void readAllEntries(); | 167 | virtual void readAllEntries(); |
167 | virtual void removeAsciiFile(); | 168 | virtual void removeAsciiFile(); |
168 | virtual void setPasswordDialogDone(); | 169 | virtual void setPasswordDialogDone(); |
169 | 170 | ||
170 | virtual void addCategory(); | 171 | virtual void addCategory(); |
171 | virtual void delCategory(); | 172 | virtual void delCategory(); |
172 | virtual void editCategory(); | 173 | virtual void editCategory(); |
173 | virtual void cutItem(); | 174 | virtual void cutItem(); |
174 | virtual void copyItem(); | 175 | virtual void copyItem(); |
175 | virtual void pasteItem(); | 176 | virtual void pasteItem(); |
176 | 177 | ||
177 | virtual void newDocument(); | 178 | virtual void newDocument(); |
178 | virtual void loadDocument(); | 179 | virtual void loadDocument(); |
179 | virtual void saveDocumentAs(); | 180 | virtual void saveDocumentAs(); |