-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index abf6511..ef16b46 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -2283,1034 +2283,1118 @@ bool ZSafe::saveDocument(const char* _filename, | |||
2283 | if (retval == PWERR_DATA) { | 2283 | if (retval == PWERR_DATA) { |
2284 | qWarning("1: Error writing file, contents not saved"); | 2284 | qWarning("1: Error writing file, contents not saved"); |
2285 | saveFinalize(); | 2285 | saveFinalize(); |
2286 | return false; | 2286 | return false; |
2287 | } | 2287 | } |
2288 | 2288 | ||
2289 | } | 2289 | } |
2290 | } | 2290 | } |
2291 | 2291 | ||
2292 | if (saveFinalize() == PWERR_DATA) { | 2292 | if (saveFinalize() == PWERR_DATA) { |
2293 | qWarning("2: Error writing file, contents not saved"); | 2293 | qWarning("2: Error writing file, contents not saved"); |
2294 | return false; | 2294 | return false; |
2295 | } else { | 2295 | } else { |
2296 | #ifndef DESKTOP | 2296 | #ifndef DESKTOP |
2297 | Global::statusMessage (tr("Password file saved.")); | 2297 | Global::statusMessage (tr("Password file saved.")); |
2298 | #endif | 2298 | #endif |
2299 | modified = false; | 2299 | modified = false; |
2300 | return true; | 2300 | return true; |
2301 | } | 2301 | } |
2302 | } | 2302 | } |
2303 | 2303 | ||
2304 | PasswordForm *newPwdDialog; | 2304 | PasswordForm *newPwdDialog; |
2305 | bool newPwdDialogResult = false; | 2305 | bool newPwdDialogResult = false; |
2306 | void ZSafe::setPasswordDialogDone() | 2306 | void ZSafe::setPasswordDialogDone() |
2307 | { | 2307 | { |
2308 | newPwdDialogResult = true; | 2308 | newPwdDialogResult = true; |
2309 | newPwdDialog->close(); | 2309 | newPwdDialog->close(); |
2310 | } | 2310 | } |
2311 | 2311 | ||
2312 | void ZSafe::getDocPassword(QString title) | 2312 | void ZSafe::getDocPassword(QString title) |
2313 | { | 2313 | { |
2314 | qWarning ("getDocPassword"); | 2314 | qWarning ("getDocPassword"); |
2315 | // open the 'Password' dialog | 2315 | // open the 'Password' dialog |
2316 | PasswordForm *dialog = new PasswordForm(this, title, TRUE); | 2316 | PasswordForm *dialog = new PasswordForm(this, title, TRUE); |
2317 | newPwdDialog = dialog; | 2317 | newPwdDialog = dialog; |
2318 | newPwdDialogResult = false; | 2318 | newPwdDialogResult = false; |
2319 | 2319 | ||
2320 | connect( dialog->PasswordField, SIGNAL( returnPressed() ), | 2320 | connect( dialog->PasswordField, SIGNAL( returnPressed() ), |
2321 | this, SLOT( setPasswordDialogDone() ) ); | 2321 | this, SLOT( setPasswordDialogDone() ) ); |
2322 | 2322 | ||
2323 | // CS: !!! | 2323 | // CS: !!! |
2324 | // int pos = filename.findRev ('/'); | 2324 | // int pos = filename.findRev ('/'); |
2325 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 2325 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
2326 | #ifdef WIN32 | 2326 | #ifdef WIN32 |
2327 | dialog->setCaption("Qt " + ti); | 2327 | dialog->setCaption("Qt " + ti); |
2328 | #else | 2328 | #else |
2329 | dialog->setCaption(ti); | 2329 | dialog->setCaption(ti); |
2330 | #endif | 2330 | #endif |
2331 | // dialog->setCaption(title); | 2331 | // dialog->setCaption(title); |
2332 | 2332 | ||
2333 | dialog->PasswordField->setFocus(); | 2333 | dialog->PasswordField->setFocus(); |
2334 | DialogCode result = (DialogCode) dialog->exec(); | 2334 | DialogCode result = (DialogCode) dialog->exec(); |
2335 | #ifdef DESKTOP | 2335 | #ifdef DESKTOP |
2336 | result = Accepted; | 2336 | result = Accepted; |
2337 | #endif | 2337 | #endif |
2338 | 2338 | ||
2339 | QString password; | 2339 | QString password; |
2340 | if (result == Accepted || newPwdDialogResult) | 2340 | if (result == Accepted || newPwdDialogResult) |
2341 | { | 2341 | { |
2342 | m_password = dialog->PasswordField->text(); | 2342 | m_password = dialog->PasswordField->text(); |
2343 | } | 2343 | } |
2344 | else | 2344 | else |
2345 | { | 2345 | { |
2346 | exitZs (1); | 2346 | exitZs (1); |
2347 | } | 2347 | } |
2348 | } | 2348 | } |
2349 | 2349 | ||
2350 | int ZSafe::saveInit(const char *_filename, const char *password) | 2350 | int ZSafe::saveInit(const char *_filename, const char *password) |
2351 | { | 2351 | { |
2352 | char key[128]; | 2352 | char key[128]; |
2353 | unsigned int j = 0; | 2353 | unsigned int j = 0; |
2354 | unsigned int keylength; | 2354 | unsigned int keylength; |
2355 | // int val; | 2355 | // int val; |
2356 | int count2; | 2356 | int count2; |
2357 | Krc2* krc2 = new Krc2(); | 2357 | Krc2* krc2 = new Krc2(); |
2358 | 2358 | ||
2359 | /* first we should check the permissions of the filename */ | 2359 | /* first we should check the permissions of the filename */ |
2360 | /* | 2360 | /* |
2361 | if (QFile::exists(_filename)) { | 2361 | if (QFile::exists(_filename)) { |
2362 | val = checkFile(_filename); | 2362 | val = checkFile(_filename); |
2363 | if (val != PWERR_GOOD) | 2363 | if (val != PWERR_GOOD) |
2364 | return val; | 2364 | return val; |
2365 | } else | 2365 | } else |
2366 | { | 2366 | { |
2367 | val = creat (_filename, (S_IRUSR | S_IWUSR)); | 2367 | val = creat (_filename, (S_IRUSR | S_IWUSR)); |
2368 | if (val == -1) | 2368 | if (val == -1) |
2369 | return PWERR_OPEN; | 2369 | return PWERR_OPEN; |
2370 | else | 2370 | else |
2371 | close(val); | 2371 | close(val); |
2372 | } | 2372 | } |
2373 | */ | 2373 | */ |
2374 | QFileInfo f (_filename); | 2374 | QFileInfo f (_filename); |
2375 | save_buffer_length = f.size(); | 2375 | save_buffer_length = f.size(); |
2376 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; | 2376 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; |
2377 | 2377 | ||
2378 | fd = fopen (_filename, "wb"); | 2378 | fd = fopen (_filename, "wb"); |
2379 | if (fd == NULL) | 2379 | if (fd == NULL) |
2380 | return PWERR_OPEN; | 2380 | return PWERR_OPEN; |
2381 | 2381 | ||
2382 | buffer = (char*)malloc(save_buffer_length); | 2382 | buffer = (char*)malloc(save_buffer_length); |
2383 | 2383 | ||
2384 | /* make the key ready */ | 2384 | /* make the key ready */ |
2385 | for (j = 0; password[j] != '\0'; j++) { | 2385 | for (j = 0; password[j] != '\0'; j++) { |
2386 | key[j] = password[j]; | 2386 | key[j] = password[j]; |
2387 | } | 2387 | } |
2388 | keylength = j; | 2388 | keylength = j; |
2389 | krc2->rc2_expandkey (key, keylength, 128); | 2389 | krc2->rc2_expandkey (key, keylength, 128); |
2390 | 2390 | ||
2391 | /* First, we make the IV */ | 2391 | /* First, we make the IV */ |
2392 | for (count2 = 0; count2 < 4; count2++) { | 2392 | for (count2 = 0; count2 < 4; count2++) { |
2393 | iv[count2] = rand (); | 2393 | iv[count2] = rand (); |
2394 | putc ((unsigned char) (iv[count2] >> 8), fd); | 2394 | putc ((unsigned char) (iv[count2] >> 8), fd); |
2395 | putc ((unsigned char) (iv[count2] & 0xff), fd); | 2395 | putc ((unsigned char) (iv[count2] & 0xff), fd); |
2396 | } | 2396 | } |
2397 | 2397 | ||
2398 | bufferIndex = 0; | 2398 | bufferIndex = 0; |
2399 | return PWERR_GOOD; | 2399 | return PWERR_GOOD; |
2400 | } | 2400 | } |
2401 | 2401 | ||
2402 | 2402 | ||
2403 | int ZSafe::saveEntry(char *entry[FIELD_SIZE]) | 2403 | int ZSafe::saveEntry(char *entry[FIELD_SIZE]) |
2404 | { | 2404 | { |
2405 | char *text1; | 2405 | char *text1; |
2406 | int count2, count3; | 2406 | int count2, count3; |
2407 | unsigned short ciphertext[4]; | 2407 | unsigned short ciphertext[4]; |
2408 | Krc2* krc2 = new Krc2(); | 2408 | Krc2* krc2 = new Krc2(); |
2409 | 2409 | ||
2410 | buffer = (char*)memset(buffer, '\0', save_buffer_length); | 2410 | buffer = (char*)memset(buffer, '\0', save_buffer_length); |
2411 | 2411 | ||
2412 | for (count2 = 0; count2 < FIELD_SIZE; count2++) { | 2412 | for (count2 = 0; count2 < FIELD_SIZE; count2++) { |
2413 | text1 = entry[count2]; | 2413 | text1 = entry[count2]; |
2414 | if (strlen (text1) == 0) { | 2414 | if (strlen (text1) == 0) { |
2415 | strncat(buffer, " ", strlen(" ")); | 2415 | strncat(buffer, " ", strlen(" ")); |
2416 | } else { | 2416 | } else { |
2417 | strncat(buffer, text1, strlen(text1)); | 2417 | strncat(buffer, text1, strlen(text1)); |
2418 | } | 2418 | } |
2419 | /* Use 255 as the marker. \n is too tough to test for */ | 2419 | /* Use 255 as the marker. \n is too tough to test for */ |
2420 | buffer[strlen (buffer)] = 255; | 2420 | buffer[strlen (buffer)] = 255; |
2421 | } /*for (count2 = 0; count2 < 5; count2++)*/ | 2421 | } /*for (count2 = 0; count2 < 5; count2++)*/ |
2422 | count2 = 0; | 2422 | count2 = 0; |
2423 | /* I'm using CBC mode and encrypting the data straight from top down. | 2423 | /* I'm using CBC mode and encrypting the data straight from top down. |
2424 | * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. | 2424 | * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. |
2425 | * PKCS 5 padding (explained at the code section | 2425 | * PKCS 5 padding (explained at the code section |
2426 | */ | 2426 | */ |
2427 | while (count2 < (int)strlen (buffer)) { | 2427 | while (count2 < (int)strlen (buffer)) { |
2428 | #ifndef WORDS_BIGENDIAN | 2428 | #ifndef WORDS_BIGENDIAN |
2429 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; | 2429 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; |
2430 | plaintext[bufferIndex] += buffer[count2] & 0xff; | 2430 | plaintext[bufferIndex] += buffer[count2] & 0xff; |
2431 | #endif | 2431 | #endif |
2432 | #ifdef WORDS_BIGENDIAN | 2432 | #ifdef WORDS_BIGENDIAN |
2433 | plaintext[bufferIndex] = buffer[count2] << 8; | 2433 | plaintext[bufferIndex] = buffer[count2] << 8; |
2434 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; | 2434 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; |
2435 | #endif | 2435 | #endif |
2436 | bufferIndex++; | 2436 | bufferIndex++; |
2437 | if (bufferIndex == 4) { | 2437 | if (bufferIndex == 4) { |
2438 | krc2->rc2_encrypt (plaintext); | 2438 | krc2->rc2_encrypt (plaintext); |
2439 | 2439 | ||
2440 | for (count3 = 0; count3 < 4; count3++) { | 2440 | for (count3 = 0; count3 < 4; count3++) { |
2441 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; | 2441 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; |
2442 | 2442 | ||
2443 | /* Now store the ciphertext as the iv */ | 2443 | /* Now store the ciphertext as the iv */ |
2444 | iv[count3] = plaintext[count3]; | 2444 | iv[count3] = plaintext[count3]; |
2445 | 2445 | ||
2446 | /* reset the buffer index */ | 2446 | /* reset the buffer index */ |
2447 | bufferIndex = 0; | 2447 | bufferIndex = 0; |
2448 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; | 2448 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; |
2449 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; | 2449 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; |
2450 | } /*for (count3 = 0; count3 < 5; count3++)*/ | 2450 | } /*for (count3 = 0; count3 < 5; count3++)*/ |
2451 | } /*if (bufferIndex == 5)*/ | 2451 | } /*if (bufferIndex == 5)*/ |
2452 | /* increment a short, not a byte */ | 2452 | /* increment a short, not a byte */ |
2453 | count2 += 2; | 2453 | count2 += 2; |
2454 | } /*while (count2 < strlen (buffer))*/ | 2454 | } /*while (count2 < strlen (buffer))*/ |
2455 | int ret = PWERR_GOOD; | 2455 | int ret = PWERR_GOOD; |
2456 | return ret; | 2456 | return ret; |
2457 | } | 2457 | } |
2458 | 2458 | ||
2459 | int ZSafe::saveFinalize(void) | 2459 | int ZSafe::saveFinalize(void) |
2460 | { | 2460 | { |
2461 | int count1, retval = PWERR_GOOD; | 2461 | int count1, retval = PWERR_GOOD; |
2462 | unsigned short ciphertext[4]; | 2462 | unsigned short ciphertext[4]; |
2463 | Krc2* krc2 = new Krc2(); | 2463 | Krc2* krc2 = new Krc2(); |
2464 | 2464 | ||
2465 | /* Tack on the PKCS 5 padding | 2465 | /* Tack on the PKCS 5 padding |
2466 | * How it works is we fill up the last n bytes with the value n | 2466 | * How it works is we fill up the last n bytes with the value n |
2467 | * | 2467 | * |
2468 | * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left | 2468 | * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left |
2469 | * over, leaving us 3 short, so we fill it in with 3's. | 2469 | * over, leaving us 3 short, so we fill it in with 3's. |
2470 | * | 2470 | * |
2471 | * If we come out even, we fill it with 8 8s | 2471 | * If we come out even, we fill it with 8 8s |
2472 | * | 2472 | * |
2473 | * um, except that in this instance we are using 4 shorts instead of 8 bytes. | 2473 | * um, except that in this instance we are using 4 shorts instead of 8 bytes. |
2474 | * so, half everything | 2474 | * so, half everything |
2475 | */ | 2475 | */ |
2476 | for (count1 = bufferIndex; count1 < 4; count1++) { | 2476 | for (count1 = bufferIndex; count1 < 4; count1++) { |
2477 | plaintext[count1] = (4 - bufferIndex); | 2477 | plaintext[count1] = (4 - bufferIndex); |
2478 | } | 2478 | } |
2479 | krc2->rc2_encrypt (plaintext); | 2479 | krc2->rc2_encrypt (plaintext); |
2480 | for (count1 = 0; count1 < 4; count1++) { | 2480 | for (count1 = 0; count1 < 4; count1++) { |
2481 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; | 2481 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; |
2482 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; | 2482 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; |
2483 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; | 2483 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; |
2484 | } | 2484 | } |
2485 | 2485 | ||
2486 | fclose (fd); | 2486 | fclose (fd); |
2487 | free(buffer); | 2487 | free(buffer); |
2488 | return retval; | 2488 | return retval; |
2489 | } | 2489 | } |
2490 | 2490 | ||
2491 | void ZSafe::quitMe () | 2491 | void ZSafe::quitMe () |
2492 | { | 2492 | { |
2493 | qWarning ("QUIT..."); | 2493 | qWarning ("QUIT..."); |
2494 | 2494 | ||
2495 | if (modified) | 2495 | if (modified) |
2496 | { | 2496 | { |
2497 | switch( QMessageBox::information( this, tr("ZSafe"), | 2497 | switch( QMessageBox::information( this, tr("ZSafe"), |
2498 | tr("Do you want to save\nbefore exiting?"), | 2498 | tr("Do you want to save\nbefore exiting?"), |
2499 | tr("&Save"), | 2499 | tr("&Save"), |
2500 | tr("S&ave with\nnew\npassword"), | 2500 | tr("S&ave with\nnew\npassword"), |
2501 | tr("&Don't Save"), | 2501 | tr("&Don't Save"), |
2502 | 0 // Enter == button 0 | 2502 | 0 // Enter == button 0 |
2503 | ) ) | 2503 | ) ) |
2504 | { // Escape == button 2 | 2504 | { // Escape == button 2 |
2505 | case 0: // Save clicked, Alt-S or Enter pressed. | 2505 | case 0: // Save clicked, Alt-S or Enter pressed. |
2506 | // save | 2506 | // save |
2507 | modified = false; | 2507 | modified = false; |
2508 | saveDocument(filename, FALSE); | 2508 | saveDocument(filename, FALSE); |
2509 | exitZs (1); | 2509 | exitZs (1); |
2510 | break; | 2510 | break; |
2511 | case 1: // | 2511 | case 1: // |
2512 | // Save with new password | 2512 | // Save with new password |
2513 | modified = false; | 2513 | modified = false; |
2514 | saveDocument(filename, TRUE); | 2514 | saveDocument(filename, TRUE); |
2515 | exitZs (1); | 2515 | exitZs (1); |
2516 | break; | 2516 | break; |
2517 | case 2: // Don't Save clicked or Alt-D pressed | 2517 | case 2: // Don't Save clicked or Alt-D pressed |
2518 | // don't save but exitZs | 2518 | // don't save but exitZs |
2519 | exitZs (1); | 2519 | exitZs (1); |
2520 | break; | 2520 | break; |
2521 | } | 2521 | } |
2522 | } | 2522 | } |
2523 | exitZs (1); | 2523 | exitZs (1); |
2524 | 2524 | ||
2525 | } | 2525 | } |
2526 | 2526 | ||
2527 | void ZSafe::categoryFieldActivated( const QString& category) | 2527 | void ZSafe::categoryFieldActivated( const QString& category) |
2528 | { | 2528 | { |
2529 | if (categoryDialog) | 2529 | if (categoryDialog) |
2530 | setCategoryDialogFields(categoryDialog, category); | 2530 | setCategoryDialogFields(categoryDialog, category); |
2531 | } | 2531 | } |
2532 | 2532 | ||
2533 | void ZSafe::addCategory() | 2533 | void ZSafe::addCategory() |
2534 | { | 2534 | { |
2535 | if (filename.isEmpty()) | 2535 | if (filename.isEmpty()) |
2536 | { | 2536 | { |
2537 | QMessageBox::critical( 0, tr("ZSafe"), | 2537 | QMessageBox::critical( 0, tr("ZSafe"), |
2538 | tr("No document defined.\nYou have to create a new document")); | 2538 | tr("No document defined.\nYou have to create a new document")); |
2539 | return; | 2539 | return; |
2540 | } | 2540 | } |
2541 | else | 2541 | else |
2542 | { | 2542 | { |
2543 | // open the 'Category' dialog | 2543 | // open the 'Category' dialog |
2544 | bool initIcons = false; | 2544 | bool initIcons = false; |
2545 | // open the 'Category' dialog | 2545 | // open the 'Category' dialog |
2546 | CategoryDialog *dialog; | 2546 | CategoryDialog *dialog; |
2547 | if (categoryDialog) | 2547 | if (categoryDialog) |
2548 | { | 2548 | { |
2549 | dialog = categoryDialog; | 2549 | dialog = categoryDialog; |
2550 | } | 2550 | } |
2551 | else | 2551 | else |
2552 | { | 2552 | { |
2553 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); | 2553 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); |
2554 | #ifdef WIN32 | 2554 | #ifdef WIN32 |
2555 | categoryDialog->setCaption ("Qt " + tr("Category")); | 2555 | categoryDialog->setCaption ("Qt " + tr("Category")); |
2556 | #endif | 2556 | #endif |
2557 | dialog = categoryDialog; | 2557 | dialog = categoryDialog; |
2558 | connect( dialog->CategoryField, | 2558 | connect( dialog->CategoryField, |
2559 | SIGNAL( activated ( const QString &)), | 2559 | SIGNAL( activated ( const QString &)), |
2560 | this, SLOT( categoryFieldActivated( const QString & ) ) ); | 2560 | this, SLOT( categoryFieldActivated( const QString & ) ) ); |
2561 | initIcons = true; | 2561 | initIcons = true; |
2562 | } | 2562 | } |
2563 | 2563 | ||
2564 | #ifdef DESKTOP | 2564 | #ifdef DESKTOP |
2565 | #ifndef WIN32 | 2565 | #ifndef WIN32 |
2566 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); | 2566 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); |
2567 | #else | 2567 | #else |
2568 | // read all categories from the config file and store | 2568 | // read all categories from the config file and store |
2569 | // into a list | 2569 | // into a list |
2570 | QFile f (cfgFile); | 2570 | QFile f (cfgFile); |
2571 | QStringList list; | 2571 | QStringList list; |
2572 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2572 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2573 | QTextStream t( &f ); // use a text stream | 2573 | QTextStream t( &f ); // use a text stream |
2574 | QString s; | 2574 | QString s; |
2575 | int n = 1; | 2575 | int n = 1; |
2576 | while ( !t.eof() ) { // until end of file... | 2576 | while ( !t.eof() ) { // until end of file... |
2577 | s = t.readLine(); // line of text excluding '\n' | 2577 | s = t.readLine(); // line of text excluding '\n' |
2578 | list.append(s); | 2578 | list.append(s); |
2579 | } | 2579 | } |
2580 | f.close(); | 2580 | f.close(); |
2581 | } | 2581 | } |
2582 | #endif | 2582 | #endif |
2583 | #else | 2583 | #else |
2584 | // read all categories from the config file and store | 2584 | // read all categories from the config file and store |
2585 | // into a list | 2585 | // into a list |
2586 | QFile f (cfgFile); | 2586 | QFile f (cfgFile); |
2587 | QStringList list; | 2587 | QStringList list; |
2588 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2588 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2589 | QTextStream t( &f ); // use a text stream | 2589 | QTextStream t( &f ); // use a text stream |
2590 | QString s; | 2590 | QString s; |
2591 | while ( !t.eof() ) { // until end of file... | 2591 | while ( !t.eof() ) { // until end of file... |
2592 | s = t.readLine(); // line of text excluding '\n' | 2592 | s = t.readLine(); // line of text excluding '\n' |
2593 | list.append(s); | 2593 | list.append(s); |
2594 | } | 2594 | } |
2595 | f.close(); | 2595 | f.close(); |
2596 | } | 2596 | } |
2597 | #endif | 2597 | #endif |
2598 | QStringList::Iterator it = list.begin(); | 2598 | QStringList::Iterator it = list.begin(); |
2599 | QString categ; | 2599 | QString categ; |
2600 | dialog->CategoryField->clear(); // remove all items | 2600 | dialog->CategoryField->clear(); // remove all items |
2601 | while( it != list.end() ) | 2601 | while( it != list.end() ) |
2602 | { | 2602 | { |
2603 | QString *cat = new QString (*it); | 2603 | QString *cat = new QString (*it); |
2604 | if (cat->contains("-field1", FALSE)) | 2604 | if (cat->contains("-field1", FALSE)) |
2605 | { | 2605 | { |
2606 | #ifdef DESKTOP | 2606 | #ifdef DESKTOP |
2607 | #ifndef WIN32 | 2607 | #ifndef WIN32 |
2608 | categ = cat->section ("-field1", 0, 0); | 2608 | categ = cat->section ("-field1", 0, 0); |
2609 | #else | 2609 | #else |
2610 | int pos = cat->find ("-field1"); | 2610 | int pos = cat->find ("-field1"); |
2611 | categ = cat->left (pos); | 2611 | categ = cat->left (pos); |
2612 | #endif | 2612 | #endif |
2613 | #else | 2613 | #else |
2614 | int pos = cat->find ("-field1"); | 2614 | int pos = cat->find ("-field1"); |
2615 | cat->truncate(pos); | 2615 | cat->truncate(pos); |
2616 | categ = *cat; | 2616 | categ = *cat; |
2617 | #endif | 2617 | #endif |
2618 | if (!categ.isEmpty()) | 2618 | if (!categ.isEmpty()) |
2619 | { | 2619 | { |
2620 | dialog->CategoryField->insertItem (categ, -1); | 2620 | dialog->CategoryField->insertItem (categ, -1); |
2621 | } | 2621 | } |
2622 | } | 2622 | } |
2623 | ++it; | 2623 | ++it; |
2624 | } | 2624 | } |
2625 | 2625 | ||
2626 | 2626 | ||
2627 | setCategoryDialogFields(dialog); | 2627 | setCategoryDialogFields(dialog); |
2628 | 2628 | ||
2629 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); | 2629 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); |
2630 | 2630 | ||
2631 | if (initIcons) | 2631 | if (initIcons) |
2632 | { | 2632 | { |
2633 | Wait waitDialog(this, tr("Wait dialog")); | 2633 | Wait waitDialog(this, tr("Wait dialog")); |
2634 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 2634 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2635 | waitDialog.show(); | 2635 | waitDialog.show(); |
2636 | qApp->processEvents(); | 2636 | qApp->processEvents(); |
2637 | 2637 | ||
2638 | #ifdef DESKTOP | 2638 | #ifdef DESKTOP |
2639 | QDir d(iconPath); | 2639 | QDir d(iconPath); |
2640 | #else | 2640 | #else |
2641 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2641 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2642 | #endif | 2642 | #endif |
2643 | d.setFilter( QDir::Files); | 2643 | d.setFilter( QDir::Files); |
2644 | 2644 | ||
2645 | const QFileInfoList *list = d.entryInfoList(); | 2645 | const QFileInfoList *list = d.entryInfoList(); |
2646 | QFileInfoListIterator it( *list ); // create list iterator | 2646 | QFileInfoListIterator it( *list ); // create list iterator |
2647 | QFileInfo *fi; // pointer for traversing | 2647 | QFileInfo *fi; // pointer for traversing |
2648 | 2648 | ||
2649 | dialog->IconField->insertItem("predefined"); | 2649 | dialog->IconField->insertItem("predefined"); |
2650 | while ( (fi=it.current()) ) { // for each file... | 2650 | while ( (fi=it.current()) ) { // for each file... |
2651 | QString fileName = fi->fileName(); | 2651 | QString fileName = fi->fileName(); |
2652 | if(fileName.right(4) == ".png"){ | 2652 | if(fileName.right(4) == ".png"){ |
2653 | fileName = fileName.mid(0,fileName.length()-4); | 2653 | fileName = fileName.mid(0,fileName.length()-4); |
2654 | #ifdef DESKTOP | 2654 | #ifdef DESKTOP |
2655 | QPixmap imageOfFile; | 2655 | QPixmap imageOfFile; |
2656 | imageOfFile.load(iconPath + fi->fileName()); | 2656 | imageOfFile.load(iconPath + fi->fileName()); |
2657 | #else | 2657 | #else |
2658 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 2658 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
2659 | #endif | 2659 | #endif |
2660 | QImage foo = imageOfFile.convertToImage(); | 2660 | QImage foo = imageOfFile.convertToImage(); |
2661 | foo = foo.smoothScale(16,16); | 2661 | foo = foo.smoothScale(16,16); |
2662 | imageOfFile.convertFromImage(foo); | 2662 | imageOfFile.convertFromImage(foo); |
2663 | dialog->IconField->insertItem(imageOfFile,fileName); | 2663 | dialog->IconField->insertItem(imageOfFile,fileName); |
2664 | } | 2664 | } |
2665 | ++it; | 2665 | ++it; |
2666 | } | 2666 | } |
2667 | waitDialog.hide(); | 2667 | waitDialog.hide(); |
2668 | } | 2668 | } |
2669 | 2669 | ||
2670 | #ifndef WIN32 | 2670 | #ifndef WIN32 |
2671 | dialog->show(); | 2671 | dialog->show(); |
2672 | #endif | 2672 | #endif |
2673 | #ifndef DESKTOP | 2673 | #ifndef DESKTOP |
2674 | // dialog->move (20, 100); | 2674 | // dialog->move (20, 100); |
2675 | #endif | 2675 | #endif |
2676 | DialogCode result = (DialogCode) dialog->exec(); | 2676 | DialogCode result = (DialogCode) dialog->exec(); |
2677 | #ifdef DESKTOP | 2677 | #ifdef DESKTOP |
2678 | result = Accepted; | 2678 | result = Accepted; |
2679 | #endif | 2679 | #endif |
2680 | 2680 | ||
2681 | QString category; | 2681 | QString category; |
2682 | QString icon; | 2682 | QString icon; |
2683 | QString fullIconPath; | 2683 | QString fullIconPath; |
2684 | QPixmap *pix; | 2684 | QPixmap *pix; |
2685 | if (result == Accepted) | 2685 | if (result == Accepted) |
2686 | { | 2686 | { |
2687 | modified = true; | 2687 | modified = true; |
2688 | category = dialog->CategoryField->currentText(); | 2688 | category = dialog->CategoryField->currentText(); |
2689 | icon = dialog->IconField->currentText()+".png"; | 2689 | icon = dialog->IconField->currentText()+".png"; |
2690 | 2690 | ||
2691 | qWarning (category); | 2691 | qWarning (category); |
2692 | 2692 | ||
2693 | QListViewItem *li = new ShadedListItem( 1, ListView ); | 2693 | QListViewItem *li = new ShadedListItem( 1, ListView ); |
2694 | Category *c1 = new Category(); | 2694 | Category *c1 = new Category(); |
2695 | c1->setCategoryName(category); | 2695 | c1->setCategoryName(category); |
2696 | 2696 | ||
2697 | // if (!icon.isEmpty() && !icon.isNull()) | 2697 | // if (!icon.isEmpty() && !icon.isNull()) |
2698 | if (icon != "predefined.png") | 2698 | if (icon != "predefined.png") |
2699 | { | 2699 | { |
2700 | // build the full path | 2700 | // build the full path |
2701 | fullIconPath = iconPath + icon; | 2701 | fullIconPath = iconPath + icon; |
2702 | pix = new QPixmap (fullIconPath); | 2702 | pix = new QPixmap (fullIconPath); |
2703 | // pix->resize(14, 14); | 2703 | // pix->resize(14, 14); |
2704 | if (pix) | 2704 | if (pix) |
2705 | { | 2705 | { |
2706 | // save the full pixmap name into the config file | 2706 | // save the full pixmap name into the config file |
2707 | // #ifndef WIN32 | 2707 | // #ifndef WIN32 |
2708 | conf->writeEntry(APP_KEY+category, icon); | 2708 | conf->writeEntry(APP_KEY+category, icon); |
2709 | // #endif | 2709 | // #endif |
2710 | saveConf(); | 2710 | saveConf(); |
2711 | QImage img = pix->convertToImage(); | 2711 | QImage img = pix->convertToImage(); |
2712 | pix->convertFromImage(img.smoothScale(14,14)); | 2712 | pix->convertFromImage(img.smoothScale(14,14)); |
2713 | c1->setIcon (*pix); | 2713 | c1->setIcon (*pix); |
2714 | c1->setIconName(icon); | 2714 | c1->setIconName(icon); |
2715 | } | 2715 | } |
2716 | else | 2716 | else |
2717 | { | 2717 | { |
2718 | QPixmap folder( ( const char** ) general_data ); | 2718 | QPixmap folder( ( const char** ) general_data ); |
2719 | c1->setIcon (folder); | 2719 | c1->setIcon (folder); |
2720 | } | 2720 | } |
2721 | } | 2721 | } |
2722 | else | 2722 | else |
2723 | { | 2723 | { |
2724 | c1->setIcon (*getPredefinedIcon(category)); | 2724 | c1->setIcon (*getPredefinedIcon(category)); |
2725 | } | 2725 | } |
2726 | 2726 | ||
2727 | c1->setListItem (li); | 2727 | c1->setListItem (li); |
2728 | c1->initListItem(); | 2728 | c1->initListItem(); |
2729 | categories.insert (c1->getCategoryName(), c1); | 2729 | categories.insert (c1->getCategoryName(), c1); |
2730 | 2730 | ||
2731 | saveCategoryDialogFields(dialog); | 2731 | saveCategoryDialogFields(dialog); |
2732 | } | 2732 | } |
2733 | else | 2733 | else |
2734 | { | 2734 | { |
2735 | // delete dialog; | 2735 | // delete dialog; |
2736 | dialog->hide(); | 2736 | dialog->hide(); |
2737 | return; | 2737 | return; |
2738 | } | 2738 | } |
2739 | 2739 | ||
2740 | } | 2740 | } |
2741 | 2741 | ||
2742 | } | 2742 | } |
2743 | 2743 | ||
2744 | void ZSafe::delCategory() | 2744 | void ZSafe::delCategory() |
2745 | { | 2745 | { |
2746 | if (!selectedItem) | 2746 | if (!selectedItem) |
2747 | return; | 2747 | return; |
2748 | if (isCategory(selectedItem)) | 2748 | if (isCategory(selectedItem)) |
2749 | { | 2749 | { |
2750 | switch( QMessageBox::information( this, tr("ZSafe"), | 2750 | switch( QMessageBox::information( this, tr("ZSafe"), |
2751 | tr("Do you want to delete?"), | 2751 | tr("Do you want to delete?"), |
2752 | tr("&Delete"), tr("D&on't Delete"), | 2752 | tr("&Delete"), tr("D&on't Delete"), |
2753 | 0 // Enter == button 0 | 2753 | 0 // Enter == button 0 |
2754 | ) ) { // Escape == button 2 | 2754 | ) ) { // Escape == button 2 |
2755 | case 0: // Delete clicked, Alt-S or Enter pressed. | 2755 | case 0: // Delete clicked, Alt-S or Enter pressed. |
2756 | // Delete from the category list | 2756 | // Delete from the category list |
2757 | modified = true; | 2757 | modified = true; |
2758 | categories.remove (selectedItem->text(0)); | 2758 | categories.remove (selectedItem->text(0)); |
2759 | // #ifndef WIN32 | 2759 | // #ifndef WIN32 |
2760 | conf->removeEntry (selectedItem->text(0)); | 2760 | conf->removeEntry (selectedItem->text(0)); |
2761 | // #endif | 2761 | // #endif |
2762 | saveConf(); | 2762 | saveConf(); |
2763 | 2763 | ||
2764 | // Delete the selected item and all subitems | 2764 | // Delete the selected item and all subitems |
2765 | // step through all subitems | 2765 | // step through all subitems |
2766 | QListViewItem *si; | 2766 | QListViewItem *si; |
2767 | for (si = selectedItem->firstChild(); | 2767 | for (si = selectedItem->firstChild(); |
2768 | si != NULL; ) | 2768 | si != NULL; ) |
2769 | { | 2769 | { |
2770 | QListViewItem *_si = si; | 2770 | QListViewItem *_si = si; |
2771 | si = si->nextSibling(); | 2771 | si = si->nextSibling(); |
2772 | selectedItem->takeItem(_si); // remove from view list | 2772 | selectedItem->takeItem(_si); // remove from view list |
2773 | if (_si) delete _si; | 2773 | if (_si) delete _si; |
2774 | } | 2774 | } |
2775 | ListView->takeItem(selectedItem); | 2775 | ListView->takeItem(selectedItem); |
2776 | delete selectedItem; | 2776 | delete selectedItem; |
2777 | 2777 | ||
2778 | selectedItem = NULL; | 2778 | selectedItem = NULL; |
2779 | break; | 2779 | break; |
2780 | case 1: // Don't delete | 2780 | case 1: // Don't delete |
2781 | break; | 2781 | break; |
2782 | } | 2782 | } |
2783 | 2783 | ||
2784 | } | 2784 | } |
2785 | } | 2785 | } |
2786 | 2786 | ||
2787 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) | 2787 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) |
2788 | { | 2788 | { |
2789 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 2789 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
2790 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 2790 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); |
2791 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | 2791 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); |
2792 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | 2792 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); |
2793 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | 2793 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); |
2794 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | 2794 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); |
2795 | |||
2796 | QString icon; | ||
2797 | Category *cat= categories.find (selectedItem->text(0)); | ||
2798 | if (cat) | ||
2799 | { | ||
2800 | icon = cat->getIconName(); | ||
2801 | } | ||
2802 | |||
2803 | #ifdef DESKTOP | ||
2804 | QDir d(iconPath); | ||
2805 | #else | ||
2806 | QDir d(QPEApplication::qpeDir() + "/pics/"); | ||
2807 | #endif | ||
2808 | d.setFilter( QDir::Files); | ||
2809 | |||
2810 | const QFileInfoList *list = d.entryInfoList(); | ||
2811 | int i=0; | ||
2812 | QFileInfoListIterator it( *list ); // create list iterator | ||
2813 | QFileInfo *fi; // pointer for traversing | ||
2814 | if (icon.isEmpty() || icon.isNull()) | ||
2815 | { | ||
2816 | dialog->IconField->setCurrentItem(0); | ||
2817 | } | ||
2818 | else | ||
2819 | { | ||
2820 | while ( (fi=it.current()) ) | ||
2821 | { // for each file... | ||
2822 | QString fileName = fi->fileName(); | ||
2823 | if(fileName.right(4) == ".png") | ||
2824 | { | ||
2825 | fileName = fileName.mid(0,fileName.length()-4); | ||
2826 | |||
2827 | if(fileName+".png"==icon) | ||
2828 | { | ||
2829 | dialog->IconField->setCurrentItem(i+1); | ||
2830 | break; | ||
2831 | } | ||
2832 | ++i; | ||
2833 | } | ||
2834 | ++it; | ||
2835 | } | ||
2836 | } | ||
2795 | } | 2837 | } |
2796 | 2838 | ||
2797 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) | 2839 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) |
2798 | { | 2840 | { |
2799 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); | 2841 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); |
2800 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); | 2842 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); |
2801 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); | 2843 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); |
2802 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); | 2844 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); |
2803 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); | 2845 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); |
2804 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); | 2846 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); |
2847 | |||
2848 | QString icon; | ||
2849 | Category *cat= categories.find (category); | ||
2850 | if (cat) | ||
2851 | { | ||
2852 | icon = cat->getIconName(); | ||
2853 | } | ||
2854 | |||
2855 | #ifdef DESKTOP | ||
2856 | QDir d(iconPath); | ||
2857 | #else | ||
2858 | QDir d(QPEApplication::qpeDir() + "/pics/"); | ||
2859 | #endif | ||
2860 | d.setFilter( QDir::Files); | ||
2861 | |||
2862 | const QFileInfoList *list = d.entryInfoList(); | ||
2863 | int i=0; | ||
2864 | QFileInfoListIterator it( *list ); // create list iterator | ||
2865 | QFileInfo *fi; // pointer for traversing | ||
2866 | if (icon.isEmpty() || icon.isNull()) | ||
2867 | { | ||
2868 | dialog->IconField->setCurrentItem(0); | ||
2869 | } | ||
2870 | else | ||
2871 | { | ||
2872 | while ( (fi=it.current()) ) | ||
2873 | { // for each file... | ||
2874 | QString fileName = fi->fileName(); | ||
2875 | if(fileName.right(4) == ".png") | ||
2876 | { | ||
2877 | fileName = fileName.mid(0,fileName.length()-4); | ||
2878 | |||
2879 | if(fileName+".png"==icon) | ||
2880 | { | ||
2881 | dialog->IconField->setCurrentItem(i+1); | ||
2882 | break; | ||
2883 | } | ||
2884 | ++i; | ||
2885 | } | ||
2886 | ++it; | ||
2887 | } | ||
2888 | } | ||
2805 | } | 2889 | } |
2806 | 2890 | ||
2807 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) | 2891 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) |
2808 | { | 2892 | { |
2809 | QString app_key = APP_KEY; | 2893 | QString app_key = APP_KEY; |
2810 | #ifndef DESKTOP | 2894 | #ifndef DESKTOP |
2811 | conf->setGroup ("fieldDefs"); | 2895 | conf->setGroup ("fieldDefs"); |
2812 | #else | 2896 | #else |
2813 | #ifndef WIN32 | 2897 | #ifndef WIN32 |
2814 | app_key += "/fieldDefs/"; | 2898 | app_key += "/fieldDefs/"; |
2815 | #endif | 2899 | #endif |
2816 | #endif | 2900 | #endif |
2817 | QString category = dialog->CategoryField->currentText(); | 2901 | QString category = dialog->CategoryField->currentText(); |
2818 | // #ifndef WIN32 | 2902 | // #ifndef WIN32 |
2819 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); | 2903 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); |
2820 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); | 2904 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); |
2821 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); | 2905 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); |
2822 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); | 2906 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); |
2823 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); | 2907 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); |
2824 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); | 2908 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); |
2825 | // #endif | 2909 | // #endif |
2826 | saveConf(); | 2910 | saveConf(); |
2827 | #ifndef DESKTOP | 2911 | #ifndef DESKTOP |
2828 | conf->setGroup ("zsafe"); | 2912 | conf->setGroup ("zsafe"); |
2829 | #endif | 2913 | #endif |
2830 | } | 2914 | } |
2831 | 2915 | ||
2832 | void ZSafe::editCategory() | 2916 | void ZSafe::editCategory() |
2833 | { | 2917 | { |
2834 | if (!selectedItem) | 2918 | if (!selectedItem) |
2835 | return; | 2919 | return; |
2836 | if (isCategory(selectedItem)) | 2920 | if (isCategory(selectedItem)) |
2837 | { | 2921 | { |
2838 | QString category = selectedItem->text(0); | 2922 | QString category = selectedItem->text(0); |
2839 | bool initIcons = false; | 2923 | bool initIcons = false; |
2840 | // open the 'Category' dialog | 2924 | // open the 'Category' dialog |
2841 | CategoryDialog *dialog; | 2925 | CategoryDialog *dialog; |
2842 | if (categoryDialog) | 2926 | if (categoryDialog) |
2843 | { | 2927 | { |
2844 | dialog = categoryDialog; | 2928 | dialog = categoryDialog; |
2845 | } | 2929 | } |
2846 | else | 2930 | else |
2847 | { | 2931 | { |
2848 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); | 2932 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); |
2849 | #ifdef WIN32 | 2933 | #ifdef WIN32 |
2850 | categoryDialog->setCaption ("Qt " + tr("Category")); | 2934 | categoryDialog->setCaption ("Qt " + tr("Category")); |
2851 | #endif | 2935 | #endif |
2852 | dialog = categoryDialog; | 2936 | dialog = categoryDialog; |
2853 | connect( dialog->CategoryField, | 2937 | connect( dialog->CategoryField, |
2854 | SIGNAL( activated ( const QString &)), | 2938 | SIGNAL( activated ( const QString &)), |
2855 | this, SLOT( categoryFieldActivated( const QString & ) ) ); | 2939 | this, SLOT( categoryFieldActivated( const QString & ) ) ); |
2856 | initIcons = true; | 2940 | initIcons = true; |
2857 | } | 2941 | } |
2858 | setCategoryDialogFields(dialog); | 2942 | setCategoryDialogFields(dialog); |
2859 | 2943 | ||
2860 | #ifdef DESKTOP | 2944 | #ifdef DESKTOP |
2861 | #ifndef WIN32 | 2945 | #ifndef WIN32 |
2862 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); | 2946 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); |
2863 | #else | 2947 | #else |
2864 | // read all categories from the config file and store | 2948 | // read all categories from the config file and store |
2865 | // into a list | 2949 | // into a list |
2866 | QFile f (cfgFile); | 2950 | QFile f (cfgFile); |
2867 | QStringList list; | 2951 | QStringList list; |
2868 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2952 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2869 | QTextStream t( &f ); // use a text stream | 2953 | QTextStream t( &f ); // use a text stream |
2870 | QString s; | 2954 | QString s; |
2871 | int n = 1; | 2955 | int n = 1; |
2872 | while ( !t.eof() ) { // until end of file... | 2956 | while ( !t.eof() ) { // until end of file... |
2873 | s = t.readLine(); // line of text excluding '\n' | 2957 | s = t.readLine(); // line of text excluding '\n' |
2874 | list.append(s); | 2958 | list.append(s); |
2875 | } | 2959 | } |
2876 | f.close(); | 2960 | f.close(); |
2877 | } | 2961 | } |
2878 | #endif | 2962 | #endif |
2879 | #else | 2963 | #else |
2880 | // read all categories from the config file and store | 2964 | // read all categories from the config file and store |
2881 | // into a list | 2965 | // into a list |
2882 | QFile f (cfgFile); | 2966 | QFile f (cfgFile); |
2883 | QStringList list; | 2967 | QStringList list; |
2884 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2968 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2885 | QTextStream t( &f ); // use a text stream | 2969 | QTextStream t( &f ); // use a text stream |
2886 | QString s; | 2970 | QString s; |
2887 | while ( !t.eof() ) { // until end of file... | 2971 | while ( !t.eof() ) { // until end of file... |
2888 | s = t.readLine(); // line of text excluding '\n' | 2972 | s = t.readLine(); // line of text excluding '\n' |
2889 | list.append(s); | 2973 | list.append(s); |
2890 | } | 2974 | } |
2891 | f.close(); | 2975 | f.close(); |
2892 | } | 2976 | } |
2893 | #endif | 2977 | #endif |
2894 | QStringList::Iterator it = list.begin(); | 2978 | QStringList::Iterator it = list.begin(); |
2895 | QString categ; | 2979 | QString categ; |
2896 | dialog->CategoryField->clear(); // remove all items | 2980 | dialog->CategoryField->clear(); // remove all items |
2897 | int i=0; | 2981 | int i=0; |
2898 | bool foundCategory = false; | 2982 | bool foundCategory = false; |
2899 | while( it != list.end() ) | 2983 | while( it != list.end() ) |
2900 | { | 2984 | { |
2901 | QString *cat = new QString (*it); | 2985 | QString *cat = new QString (*it); |
2902 | if (cat->contains("-field1", FALSE)) | 2986 | if (cat->contains("-field1", FALSE)) |
2903 | { | 2987 | { |
2904 | #ifdef DESKTOP | 2988 | #ifdef DESKTOP |
2905 | #ifndef WIN32 | 2989 | #ifndef WIN32 |
2906 | categ = cat->section ("-field1", 0, 0); | 2990 | categ = cat->section ("-field1", 0, 0); |
2907 | #else | 2991 | #else |
2908 | int pos = cat->find ("-field1"); | 2992 | int pos = cat->find ("-field1"); |
2909 | categ = cat->left (pos); | 2993 | categ = cat->left (pos); |
2910 | #endif | 2994 | #endif |
2911 | #else | 2995 | #else |
2912 | int pos = cat->find ("-field1"); | 2996 | int pos = cat->find ("-field1"); |
2913 | cat->truncate(pos); | 2997 | cat->truncate(pos); |
2914 | categ = *cat; | 2998 | categ = *cat; |
2915 | #endif | 2999 | #endif |
2916 | if (!categ.isEmpty()) | 3000 | if (!categ.isEmpty()) |
2917 | { | 3001 | { |
2918 | dialog->CategoryField->insertItem (categ, i); | 3002 | dialog->CategoryField->insertItem (categ, i); |
2919 | if (category.compare(categ) == 0) | 3003 | if (category.compare(categ) == 0) |
2920 | { | 3004 | { |
2921 | dialog->CategoryField->setCurrentItem(i); | 3005 | dialog->CategoryField->setCurrentItem(i); |
2922 | foundCategory = true; | 3006 | foundCategory = true; |
2923 | } | 3007 | } |
2924 | i++; | 3008 | i++; |
2925 | } | 3009 | } |
2926 | } | 3010 | } |
2927 | ++it; | 3011 | ++it; |
2928 | } | 3012 | } |
2929 | if (!foundCategory) | 3013 | if (!foundCategory) |
2930 | { | 3014 | { |
2931 | dialog->CategoryField->insertItem (category, i); | 3015 | dialog->CategoryField->insertItem (category, i); |
2932 | dialog->CategoryField->setCurrentItem(i); | 3016 | dialog->CategoryField->setCurrentItem(i); |
2933 | } | 3017 | } |
2934 | 3018 | ||
2935 | QString icon; | 3019 | QString icon; |
2936 | Category *cat= categories.find (selectedItem->text(0)); | 3020 | Category *cat= categories.find (selectedItem->text(0)); |
2937 | if (cat) | 3021 | if (cat) |
2938 | { | 3022 | { |
2939 | icon = cat->getIconName(); | 3023 | icon = cat->getIconName(); |
2940 | } | 3024 | } |
2941 | 3025 | ||
2942 | if (initIcons) | 3026 | if (initIcons) |
2943 | { | 3027 | { |
2944 | 3028 | ||
2945 | Wait waitDialog(this, tr("Wait dialog")); | 3029 | Wait waitDialog(this, tr("Wait dialog")); |
2946 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 3030 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2947 | waitDialog.show(); | 3031 | waitDialog.show(); |
2948 | qApp->processEvents(); | 3032 | qApp->processEvents(); |
2949 | 3033 | ||
2950 | #ifdef DESKTOP | 3034 | #ifdef DESKTOP |
2951 | QDir d(iconPath); | 3035 | QDir d(iconPath); |
2952 | #else | 3036 | #else |
2953 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3037 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2954 | #endif | 3038 | #endif |
2955 | d.setFilter( QDir::Files); | 3039 | d.setFilter( QDir::Files); |
2956 | 3040 | ||
2957 | const QFileInfoList *list = d.entryInfoList(); | 3041 | const QFileInfoList *list = d.entryInfoList(); |
2958 | int i=0; | 3042 | int i=0; |
2959 | QFileInfoListIterator it( *list ); // create list iterator | 3043 | QFileInfoListIterator it( *list ); // create list iterator |
2960 | QFileInfo *fi; // pointer for traversing | 3044 | QFileInfo *fi; // pointer for traversing |
2961 | if (icon.isEmpty() || icon.isNull()) | 3045 | if (icon.isEmpty() || icon.isNull()) |
2962 | { | 3046 | { |
2963 | dialog->IconField->setCurrentItem(0); | 3047 | dialog->IconField->setCurrentItem(0); |
2964 | } | 3048 | } |
2965 | 3049 | ||
2966 | dialog->IconField->insertItem("predefined"); | 3050 | dialog->IconField->insertItem("predefined"); |
2967 | while ( (fi=it.current()) ) { // for each file... | 3051 | while ( (fi=it.current()) ) { // for each file... |
2968 | QString fileName = fi->fileName(); | 3052 | QString fileName = fi->fileName(); |
2969 | if(fileName.right(4) == ".png") | 3053 | if(fileName.right(4) == ".png") |
2970 | { | 3054 | { |
2971 | fileName = fileName.mid(0,fileName.length()-4); | 3055 | fileName = fileName.mid(0,fileName.length()-4); |
2972 | #ifdef DESKTOP | 3056 | #ifdef DESKTOP |
2973 | QPixmap imageOfFile; | 3057 | QPixmap imageOfFile; |
2974 | imageOfFile.load(iconPath + fi->fileName()); | 3058 | imageOfFile.load(iconPath + fi->fileName()); |
2975 | #else | 3059 | #else |
2976 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 3060 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
2977 | #endif | 3061 | #endif |
2978 | QImage foo = imageOfFile.convertToImage(); | 3062 | QImage foo = imageOfFile.convertToImage(); |
2979 | foo = foo.smoothScale(16,16); | 3063 | foo = foo.smoothScale(16,16); |
2980 | imageOfFile.convertFromImage(foo); | 3064 | imageOfFile.convertFromImage(foo); |
2981 | dialog->IconField->insertItem(imageOfFile,fileName); | 3065 | dialog->IconField->insertItem(imageOfFile,fileName); |
2982 | if(fileName+".png"==icon) | 3066 | if(fileName+".png"==icon) |
2983 | dialog->IconField->setCurrentItem(i+1); | 3067 | dialog->IconField->setCurrentItem(i+1); |
2984 | ++i; | 3068 | ++i; |
2985 | } | 3069 | } |
2986 | ++it; | 3070 | ++it; |
2987 | } | 3071 | } |
2988 | waitDialog.hide(); | 3072 | waitDialog.hide(); |
2989 | } | 3073 | } |
2990 | else | 3074 | else |
2991 | { | 3075 | { |
2992 | #ifdef DESKTOP | 3076 | #ifdef DESKTOP |
2993 | // QDir d(QDir::homeDirPath() + "/pics/"); | 3077 | // QDir d(QDir::homeDirPath() + "/pics/"); |
2994 | QDir d(iconPath); | 3078 | QDir d(iconPath); |
2995 | #else | 3079 | #else |
2996 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3080 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2997 | #endif | 3081 | #endif |
2998 | d.setFilter( QDir::Files); | 3082 | d.setFilter( QDir::Files); |
2999 | 3083 | ||
3000 | const QFileInfoList *list = d.entryInfoList(); | 3084 | const QFileInfoList *list = d.entryInfoList(); |
3001 | int i=0; | 3085 | int i=0; |
3002 | QFileInfoListIterator it( *list ); // create list iterator | 3086 | QFileInfoListIterator it( *list ); // create list iterator |
3003 | QFileInfo *fi; // pointer for traversing | 3087 | QFileInfo *fi; // pointer for traversing |
3004 | if (icon.isEmpty() || icon.isNull()) | 3088 | if (icon.isEmpty() || icon.isNull()) |
3005 | { | 3089 | { |
3006 | dialog->IconField->setCurrentItem(0); | 3090 | dialog->IconField->setCurrentItem(0); |
3007 | } | 3091 | } |
3008 | else | 3092 | else |
3009 | { | 3093 | { |
3010 | 3094 | ||
3011 | while ( (fi=it.current()) ) | 3095 | while ( (fi=it.current()) ) |
3012 | { // for each file... | 3096 | { // for each file... |
3013 | QString fileName = fi->fileName(); | 3097 | QString fileName = fi->fileName(); |
3014 | if(fileName.right(4) == ".png") | 3098 | if(fileName.right(4) == ".png") |
3015 | { | 3099 | { |
3016 | fileName = fileName.mid(0,fileName.length()-4); | 3100 | fileName = fileName.mid(0,fileName.length()-4); |
3017 | 3101 | ||
3018 | 3102 | ||
3019 | if(fileName+".png"==icon) | 3103 | if(fileName+".png"==icon) |
3020 | { | 3104 | { |
3021 | dialog->IconField->setCurrentItem(i+1); | 3105 | dialog->IconField->setCurrentItem(i+1); |
3022 | break; | 3106 | break; |
3023 | } | 3107 | } |
3024 | ++i; | 3108 | ++i; |
3025 | } | 3109 | } |
3026 | ++it; | 3110 | ++it; |
3027 | } | 3111 | } |
3028 | } | 3112 | } |
3029 | } | 3113 | } |
3030 | 3114 | ||
3031 | // dialog->show(); | 3115 | // dialog->show(); |
3032 | #ifndef DESKTOP | 3116 | #ifndef DESKTOP |
3033 | // dialog->move (20, 100); | 3117 | // dialog->move (20, 100); |
3034 | #endif | 3118 | #endif |
3035 | DialogCode result = (DialogCode) dialog->exec(); | 3119 | DialogCode result = (DialogCode) dialog->exec(); |
3036 | #ifdef DESKTOP | 3120 | #ifdef DESKTOP |
3037 | result = Accepted; | 3121 | result = Accepted; |
3038 | #endif | 3122 | #endif |
3039 | 3123 | ||
3040 | QString fullIconPath; | 3124 | QString fullIconPath; |
3041 | QPixmap *pix; | 3125 | QPixmap *pix; |
3042 | if (result == Accepted) | 3126 | if (result == Accepted) |
3043 | { | 3127 | { |
3044 | modified = true; | 3128 | modified = true; |
3045 | if (category != dialog->CategoryField->currentText()) | 3129 | if (category != dialog->CategoryField->currentText()) |
3046 | { | 3130 | { |
3047 | categories.remove (category); | 3131 | categories.remove (category); |
3048 | // #ifndef WIN32 | 3132 | // #ifndef WIN32 |
3049 | conf->removeEntry(category); | 3133 | conf->removeEntry(category); |
3050 | // #endif | 3134 | // #endif |
3051 | saveConf(); | 3135 | saveConf(); |
3052 | } | 3136 | } |
3053 | 3137 | ||
3054 | category = dialog->CategoryField->currentText(); | 3138 | category = dialog->CategoryField->currentText(); |
3055 | icon = dialog->IconField->currentText()+".png"; | 3139 | icon = dialog->IconField->currentText()+".png"; |
3056 | 3140 | ||
3057 | if (cat) | 3141 | if (cat) |
3058 | { | 3142 | { |
3059 | qWarning("Category found"); | 3143 | qWarning("Category found"); |
3060 | 3144 | ||
3061 | // if (!icon.isEmpty() && !icon.isNull()) | 3145 | // if (!icon.isEmpty() && !icon.isNull()) |
3062 | if (icon != "predefined.png") | 3146 | if (icon != "predefined.png") |
3063 | { | 3147 | { |
3064 | // build the full path | 3148 | // build the full path |
3065 | fullIconPath = iconPath + icon; | 3149 | fullIconPath = iconPath + icon; |
3066 | pix = new QPixmap (fullIconPath); | 3150 | pix = new QPixmap (fullIconPath); |
3067 | if (pix) | 3151 | if (pix) |
3068 | { | 3152 | { |
3069 | // save the full pixmap name into the config file | 3153 | // save the full pixmap name into the config file |
3070 | // #ifndef WIN32 | 3154 | // #ifndef WIN32 |
3071 | conf->writeEntry(APP_KEY+category, icon); | 3155 | conf->writeEntry(APP_KEY+category, icon); |
3072 | // #endif | 3156 | // #endif |
3073 | saveConf(); | 3157 | saveConf(); |
3074 | QImage img = pix->convertToImage(); | 3158 | QImage img = pix->convertToImage(); |
3075 | pix->convertFromImage(img.smoothScale(14,14)); | 3159 | pix->convertFromImage(img.smoothScale(14,14)); |
3076 | cat->setIconName (icon); | 3160 | cat->setIconName (icon); |
3077 | cat->setIcon (*pix); | 3161 | cat->setIcon (*pix); |
3078 | } | 3162 | } |
3079 | } | 3163 | } |
3080 | else | 3164 | else |
3081 | { | 3165 | { |
3082 | // #ifndef WIN32 | 3166 | // #ifndef WIN32 |
3083 | conf->removeEntry (category); | 3167 | conf->removeEntry (category); |
3084 | // #endif | 3168 | // #endif |
3085 | saveConf(); | 3169 | saveConf(); |
3086 | cat->setIcon (*getPredefinedIcon(category)); | 3170 | cat->setIcon (*getPredefinedIcon(category)); |
3087 | } | 3171 | } |
3088 | 3172 | ||
3089 | // change the category name of the selected category | 3173 | // change the category name of the selected category |
3090 | QListViewItem *catItem = cat->getListItem(); | 3174 | QListViewItem *catItem = cat->getListItem(); |
3091 | if (catItem) | 3175 | if (catItem) |
3092 | { | 3176 | { |
3093 | qWarning (category); | 3177 | qWarning (category); |
3094 | catItem->setText( 0, tr( category ) ); | 3178 | catItem->setText( 0, tr( category ) ); |
3095 | cat->setCategoryName (tr(category)); | 3179 | cat->setCategoryName (tr(category)); |
3096 | cat->initListItem(); | 3180 | cat->initListItem(); |
3097 | categories.insert (category, cat); | 3181 | categories.insert (category, cat); |
3098 | } | 3182 | } |
3099 | } | 3183 | } |
3100 | saveCategoryDialogFields(dialog); | 3184 | saveCategoryDialogFields(dialog); |
3101 | } | 3185 | } |
3102 | else | 3186 | else |
3103 | { | 3187 | { |
3104 | // delete dialog; | 3188 | // delete dialog; |
3105 | dialog->hide(); | 3189 | dialog->hide(); |
3106 | return; | 3190 | return; |
3107 | } | 3191 | } |
3108 | 3192 | ||
3109 | } | 3193 | } |
3110 | } | 3194 | } |
3111 | 3195 | ||
3112 | void ZSafe::cutItem() | 3196 | void ZSafe::cutItem() |
3113 | { | 3197 | { |
3114 | if (!selectedItem) | 3198 | if (!selectedItem) |
3115 | return; | 3199 | return; |
3116 | if (!isCategory(selectedItem)) | 3200 | if (!isCategory(selectedItem)) |
3117 | { | 3201 | { |
3118 | IsCut = true; | 3202 | IsCut = true; |
3119 | copiedItem = selectedItem; | 3203 | copiedItem = selectedItem; |
3120 | } | 3204 | } |
3121 | } | 3205 | } |
3122 | 3206 | ||
3123 | void ZSafe::copyItem() | 3207 | void ZSafe::copyItem() |
3124 | { | 3208 | { |
3125 | if (!selectedItem) | 3209 | if (!selectedItem) |
3126 | return; | 3210 | return; |
3127 | if (!isCategory(selectedItem)) | 3211 | if (!isCategory(selectedItem)) |
3128 | { | 3212 | { |
3129 | IsCopy = true; | 3213 | IsCopy = true; |
3130 | copiedItem = selectedItem; | 3214 | copiedItem = selectedItem; |
3131 | } | 3215 | } |
3132 | } | 3216 | } |
3133 | 3217 | ||
3134 | // paste item into category | 3218 | // paste item into category |
3135 | void ZSafe::pasteItem() | 3219 | void ZSafe::pasteItem() |
3136 | { | 3220 | { |
3137 | if (!selectedItem) | 3221 | if (!selectedItem) |
3138 | return; | 3222 | return; |
3139 | if (isCategory(selectedItem)) | 3223 | if (isCategory(selectedItem)) |
3140 | { | 3224 | { |
3141 | modified = true; | 3225 | modified = true; |
3142 | if (IsCut) | 3226 | if (IsCut) |
3143 | { | 3227 | { |
3144 | if (copiedItem) | 3228 | if (copiedItem) |
3145 | { | 3229 | { |
3146 | // add the new item | 3230 | // add the new item |
3147 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3231 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3148 | // i->setOpen (TRUE); | 3232 | // i->setOpen (TRUE); |
3149 | i->setText (0, copiedItem->text(0)); | 3233 | i->setText (0, copiedItem->text(0)); |
3150 | i->setText (1, copiedItem->text(1)); | 3234 | i->setText (1, copiedItem->text(1)); |
3151 | i->setText (2, copiedItem->text(2)); | 3235 | i->setText (2, copiedItem->text(2)); |
3152 | i->setText (3, copiedItem->text(3)); | 3236 | i->setText (3, copiedItem->text(3)); |
3153 | i->setText (4, copiedItem->text(4)); | 3237 | i->setText (4, copiedItem->text(4)); |
3154 | i->setText (5, copiedItem->text(5)); | 3238 | i->setText (5, copiedItem->text(5)); |
3155 | selectedItem->setOpen( TRUE ); | 3239 | selectedItem->setOpen( TRUE ); |
3156 | 3240 | ||
3157 | // remove the cutted item | 3241 | // remove the cutted item |
3158 | copiedItem->parent()->takeItem(copiedItem); | 3242 | copiedItem->parent()->takeItem(copiedItem); |
3159 | selectedItem = NULL; | 3243 | selectedItem = NULL; |
3160 | } | 3244 | } |
3161 | } | 3245 | } |
3162 | else if (IsCopy) | 3246 | else if (IsCopy) |
3163 | { | 3247 | { |
3164 | if (copiedItem) | 3248 | if (copiedItem) |
3165 | { | 3249 | { |
3166 | // add the new item | 3250 | // add the new item |
3167 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3251 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3168 | // i->setOpen (TRUE); | 3252 | // i->setOpen (TRUE); |
3169 | i->setText (0, copiedItem->text(0)); | 3253 | i->setText (0, copiedItem->text(0)); |
3170 | i->setText (1, copiedItem->text(1)); | 3254 | i->setText (1, copiedItem->text(1)); |
3171 | i->setText (2, copiedItem->text(2)); | 3255 | i->setText (2, copiedItem->text(2)); |
3172 | i->setText (3, copiedItem->text(3)); | 3256 | i->setText (3, copiedItem->text(3)); |
3173 | i->setText (4, copiedItem->text(4)); | 3257 | i->setText (4, copiedItem->text(4)); |
3174 | i->setText (5, copiedItem->text(5)); | 3258 | i->setText (5, copiedItem->text(5)); |
3175 | selectedItem->setOpen( TRUE ); | 3259 | selectedItem->setOpen( TRUE ); |
3176 | } | 3260 | } |
3177 | } | 3261 | } |
3178 | } | 3262 | } |
3179 | IsCut = false; | 3263 | IsCut = false; |
3180 | IsCopy = false; | 3264 | IsCopy = false; |
3181 | } | 3265 | } |
3182 | 3266 | ||
3183 | void ZSafe::newDocument() | 3267 | void ZSafe::newDocument() |
3184 | { | 3268 | { |
3185 | 3269 | ||
3186 | // open the file dialog | 3270 | // open the file dialog |
3187 | #ifndef DESKTOP | 3271 | #ifndef DESKTOP |
3188 | #ifndef NO_OPIE | 3272 | #ifndef NO_OPIE |
3189 | QMap<QString, QStringList> mimeTypes; | 3273 | QMap<QString, QStringList> mimeTypes; |
3190 | mimeTypes.insert(tr("All"), QStringList() ); | 3274 | mimeTypes.insert(tr("All"), QStringList() ); |
3191 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | 3275 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); |
3192 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | 3276 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, |
3193 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3277 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3194 | QString::null, | 3278 | QString::null, |
3195 | mimeTypes, | 3279 | mimeTypes, |
3196 | this, | 3280 | this, |
3197 | tr ("Create new ZSafe document")); | 3281 | tr ("Create new ZSafe document")); |
3198 | #else | 3282 | #else |
3199 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | 3283 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, |
3200 | tr ("Create new ZSafe document"), | 3284 | tr ("Create new ZSafe document"), |
3201 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3285 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3202 | "*.zsf"); | 3286 | "*.zsf"); |
3203 | #endif | 3287 | #endif |
3204 | #else | 3288 | #else |
3205 | QString newFile = QFileDialog::getSaveFileName( | 3289 | QString newFile = QFileDialog::getSaveFileName( |
3206 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3290 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3207 | "ZSafe (*.zsf)", | 3291 | "ZSafe (*.zsf)", |
3208 | this, | 3292 | this, |
3209 | "ZSafe File Dialog" | 3293 | "ZSafe File Dialog" |
3210 | "Choose a ZSafe file" ); | 3294 | "Choose a ZSafe file" ); |
3211 | #endif | 3295 | #endif |
3212 | 3296 | ||
3213 | // open the new document | 3297 | // open the new document |
3214 | if (newFile && newFile.length() > 0 ) | 3298 | if (newFile && newFile.length() > 0 ) |
3215 | { | 3299 | { |
3216 | // save the previous opened document | 3300 | // save the previous opened document |
3217 | if (!filename.isEmpty()) | 3301 | if (!filename.isEmpty()) |
3218 | saveDocument(filename, FALSE); | 3302 | saveDocument(filename, FALSE); |
3219 | 3303 | ||
3220 | modified = true; | 3304 | modified = true; |
3221 | 3305 | ||
3222 | // clear the password list | 3306 | // clear the password list |
3223 | QListViewItem *i; | 3307 | QListViewItem *i; |
3224 | QListViewItem *c = NULL; | 3308 | QListViewItem *c = NULL; |
3225 | // step through all categories | 3309 | // step through all categories |
3226 | for (i = ListView->firstChild(); | 3310 | for (i = ListView->firstChild(); |
3227 | i != NULL; | 3311 | i != NULL; |
3228 | i = i->nextSibling()) | 3312 | i = i->nextSibling()) |
3229 | { | 3313 | { |
3230 | if (c) delete c; // delete the previous category | 3314 | if (c) delete c; // delete the previous category |
3231 | 3315 | ||
3232 | c = i; | 3316 | c = i; |
3233 | // step through all subitems | 3317 | // step through all subitems |
3234 | QListViewItem *si; | 3318 | QListViewItem *si; |
3235 | for (si = i->firstChild(); | 3319 | for (si = i->firstChild(); |
3236 | si != NULL; ) | 3320 | si != NULL; ) |
3237 | { | 3321 | { |
3238 | QListViewItem *_si = si; | 3322 | QListViewItem *_si = si; |
3239 | si = si->nextSibling(); | 3323 | si = si->nextSibling(); |
3240 | i->takeItem(_si); // remove from view list | 3324 | i->takeItem(_si); // remove from view list |
3241 | if (_si) delete _si; | 3325 | if (_si) delete _si; |
3242 | } | 3326 | } |
3243 | } | 3327 | } |
3244 | if (c) delete c; // delete the previous category | 3328 | if (c) delete c; // delete the previous category |
3245 | categories.clear(); | 3329 | categories.clear(); |
3246 | 3330 | ||
3247 | // m_password = ""; | 3331 | // m_password = ""; |
3248 | selectedItem = NULL; | 3332 | selectedItem = NULL; |
3249 | 3333 | ||
3250 | filename = newFile; | 3334 | filename = newFile; |
3251 | 3335 | ||
3252 | // save the current filename to the config file | 3336 | // save the current filename to the config file |
3253 | conf->writeEntry(APP_KEY+"document", filename); | 3337 | conf->writeEntry(APP_KEY+"document", filename); |
3254 | saveConf(); | 3338 | saveConf(); |
3255 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 3339 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
3256 | #ifdef WIN32 | 3340 | #ifdef WIN32 |
3257 | this->setCaption("Qt ZSafe: " + ti); | 3341 | this->setCaption("Qt ZSafe: " + ti); |
3258 | #else | 3342 | #else |
3259 | this->setCaption("ZSafe: " + ti); | 3343 | this->setCaption("ZSafe: " + ti); |
3260 | #endif | 3344 | #endif |
3261 | 3345 | ||
3262 | // openDocument(filename); | 3346 | // openDocument(filename); |
3263 | 3347 | ||
3264 | QMessageBox::information( this, tr("ZSafe"), | 3348 | QMessageBox::information( this, tr("ZSafe"), |
3265 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); | 3349 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); |
3266 | 3350 | ||
3267 | saveDocumentWithPwd(); | 3351 | saveDocumentWithPwd(); |
3268 | } | 3352 | } |
3269 | } | 3353 | } |
3270 | 3354 | ||
3271 | void ZSafe::loadDocument() | 3355 | void ZSafe::loadDocument() |
3272 | { | 3356 | { |
3273 | 3357 | ||
3274 | // open the file dialog | 3358 | // open the file dialog |
3275 | #ifndef DESKTOP | 3359 | #ifndef DESKTOP |
3276 | #ifndef NO_OPIE | 3360 | #ifndef NO_OPIE |
3277 | QMap<QString, QStringList> mimeTypes; | 3361 | QMap<QString, QStringList> mimeTypes; |
3278 | mimeTypes.insert(tr("All"), QStringList() ); | 3362 | mimeTypes.insert(tr("All"), QStringList() ); |
3279 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | 3363 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); |
3280 | QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 3364 | QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
3281 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3365 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3282 | QString::null, | 3366 | QString::null, |
3283 | mimeTypes, | 3367 | mimeTypes, |
3284 | this, | 3368 | this, |
3285 | tr ("Open ZSafe document")); | 3369 | tr ("Open ZSafe document")); |
3286 | #else | 3370 | #else |
3287 | QString newFile = ScQtFileEdit::getOpenFileName(this, | 3371 | QString newFile = ScQtFileEdit::getOpenFileName(this, |
3288 | tr ("Open ZSafe document"), | 3372 | tr ("Open ZSafe document"), |
3289 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3373 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3290 | "*.zsf"); | 3374 | "*.zsf"); |
3291 | #endif | 3375 | #endif |
3292 | #else | 3376 | #else |
3293 | QString newFile = QFileDialog::getOpenFileName( | 3377 | QString newFile = QFileDialog::getOpenFileName( |
3294 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3378 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3295 | "ZSafe (*.zsf)", | 3379 | "ZSafe (*.zsf)", |
3296 | this, | 3380 | this, |
3297 | "ZSafe File Dialog" | 3381 | "ZSafe File Dialog" |
3298 | "Choose a ZSafe file" ); | 3382 | "Choose a ZSafe file" ); |
3299 | #endif | 3383 | #endif |
3300 | 3384 | ||
3301 | // open the new document | 3385 | // open the new document |
3302 | if (newFile && newFile.length() > 0 ) | 3386 | if (newFile && newFile.length() > 0 ) |
3303 | { | 3387 | { |
3304 | // save the previous opened document | 3388 | // save the previous opened document |
3305 | if (!filename.isEmpty()) | 3389 | if (!filename.isEmpty()) |
3306 | saveDocument(filename, FALSE); | 3390 | saveDocument(filename, FALSE); |
3307 | 3391 | ||
3308 | // clear the password list | 3392 | // clear the password list |
3309 | QListViewItem *i; | 3393 | QListViewItem *i; |
3310 | QListViewItem *c = NULL; | 3394 | QListViewItem *c = NULL; |
3311 | // step through all categories | 3395 | // step through all categories |
3312 | for (i = ListView->firstChild(); | 3396 | for (i = ListView->firstChild(); |
3313 | i != NULL; | 3397 | i != NULL; |
3314 | i = i->nextSibling()) | 3398 | i = i->nextSibling()) |
3315 | { | 3399 | { |
3316 | if (c) delete c; // delete the previous category | 3400 | if (c) delete c; // delete the previous category |