author | zcarsten <zcarsten> | 2003-08-06 20:59:20 (UTC) |
---|---|---|
committer | zcarsten <zcarsten> | 2003-08-06 20:59:20 (UTC) |
commit | 557e7a9f407e77a3f5bcfda5de9a8408379165ac (patch) (unidiff) | |
tree | 4ad5296b9f4858b3e0791c321116449d7c99ef00 | |
parent | e14f10f07d8477ee49cd487587732e27a3307878 (diff) | |
download | opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.zip opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.tar.gz opie-557e7a9f407e77a3f5bcfda5de9a8408379165ac.tar.bz2 |
bug fixed: icon handling
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index e86b3d2..9341425 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -2301,1089 +2301,1093 @@ bool ZSafe::saveDocument(const char* _filename, | |||
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 | QString firstCategory; | 2600 | QString firstCategory; |
2601 | dialog->CategoryField->clear(); // remove all items | 2601 | dialog->CategoryField->clear(); // remove all items |
2602 | while( it != list.end() ) | 2602 | while( it != list.end() ) |
2603 | { | 2603 | { |
2604 | QString *cat = new QString (*it); | 2604 | QString *cat = new QString (*it); |
2605 | if (cat->contains("-field1", FALSE)) | 2605 | if (cat->contains("-field1", FALSE)) |
2606 | { | 2606 | { |
2607 | #ifdef DESKTOP | 2607 | #ifdef DESKTOP |
2608 | #ifndef WIN32 | 2608 | #ifndef WIN32 |
2609 | categ = cat->section ("-field1", 0, 0); | 2609 | categ = cat->section ("-field1", 0, 0); |
2610 | #else | 2610 | #else |
2611 | int pos = cat->find ("-field1"); | 2611 | int pos = cat->find ("-field1"); |
2612 | categ = cat->left (pos); | 2612 | categ = cat->left (pos); |
2613 | #endif | 2613 | #endif |
2614 | #else | 2614 | #else |
2615 | int pos = cat->find ("-field1"); | 2615 | int pos = cat->find ("-field1"); |
2616 | cat->truncate(pos); | 2616 | cat->truncate(pos); |
2617 | categ = *cat; | 2617 | categ = *cat; |
2618 | #endif | 2618 | #endif |
2619 | if (!categ.isEmpty()) | 2619 | if (!categ.isEmpty()) |
2620 | { | 2620 | { |
2621 | dialog->CategoryField->insertItem (categ, -1); | 2621 | dialog->CategoryField->insertItem (categ, -1); |
2622 | if (firstCategory.isEmpty()) | 2622 | if (firstCategory.isEmpty()) |
2623 | firstCategory = categ; | 2623 | firstCategory = categ; |
2624 | } | 2624 | } |
2625 | } | 2625 | } |
2626 | ++it; | 2626 | ++it; |
2627 | } | 2627 | } |
2628 | 2628 | ||
2629 | 2629 | ||
2630 | if (firstCategory.isEmpty()) | 2630 | if (firstCategory.isEmpty()) |
2631 | setCategoryDialogFields(dialog); | 2631 | setCategoryDialogFields(dialog); |
2632 | else | 2632 | else |
2633 | setCategoryDialogFields(dialog, firstCategory); | 2633 | setCategoryDialogFields(dialog, firstCategory); |
2634 | 2634 | ||
2635 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); | 2635 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); |
2636 | 2636 | ||
2637 | if (initIcons) | 2637 | if (initIcons) |
2638 | { | 2638 | { |
2639 | Wait waitDialog(this, tr("Wait dialog")); | 2639 | Wait waitDialog(this, tr("Wait dialog")); |
2640 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 2640 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2641 | waitDialog.show(); | 2641 | waitDialog.show(); |
2642 | qApp->processEvents(); | 2642 | qApp->processEvents(); |
2643 | 2643 | ||
2644 | #ifdef DESKTOP | 2644 | #ifdef DESKTOP |
2645 | QDir d(iconPath); | 2645 | QDir d(iconPath); |
2646 | #else | 2646 | #else |
2647 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2647 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2648 | #endif | 2648 | #endif |
2649 | d.setFilter( QDir::Files); | 2649 | d.setFilter( QDir::Files); |
2650 | 2650 | ||
2651 | const QFileInfoList *list = d.entryInfoList(); | 2651 | const QFileInfoList *list = d.entryInfoList(); |
2652 | QFileInfoListIterator it( *list ); // create list iterator | 2652 | QFileInfoListIterator it( *list ); // create list iterator |
2653 | QFileInfo *fi; // pointer for traversing | 2653 | QFileInfo *fi; // pointer for traversing |
2654 | 2654 | ||
2655 | dialog->IconField->insertItem("predefined"); | 2655 | dialog->IconField->insertItem("predefined"); |
2656 | while ( (fi=it.current()) ) { // for each file... | 2656 | while ( (fi=it.current()) ) { // for each file... |
2657 | QString fileName = fi->fileName(); | 2657 | QString fileName = fi->fileName(); |
2658 | if(fileName.right(4) == ".png"){ | 2658 | if(fileName.right(4) == ".png"){ |
2659 | fileName = fileName.mid(0,fileName.length()-4); | 2659 | fileName = fileName.mid(0,fileName.length()-4); |
2660 | #ifdef DESKTOP | 2660 | #ifdef DESKTOP |
2661 | QPixmap imageOfFile; | 2661 | QPixmap imageOfFile; |
2662 | imageOfFile.load(iconPath + fi->fileName()); | 2662 | imageOfFile.load(iconPath + fi->fileName()); |
2663 | #else | 2663 | #else |
2664 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 2664 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
2665 | #endif | 2665 | #endif |
2666 | QImage foo = imageOfFile.convertToImage(); | 2666 | QImage foo = imageOfFile.convertToImage(); |
2667 | foo = foo.smoothScale(16,16); | 2667 | foo = foo.smoothScale(16,16); |
2668 | imageOfFile.convertFromImage(foo); | 2668 | imageOfFile.convertFromImage(foo); |
2669 | dialog->IconField->insertItem(imageOfFile,fileName); | 2669 | dialog->IconField->insertItem(imageOfFile,fileName); |
2670 | } | 2670 | } |
2671 | ++it; | 2671 | ++it; |
2672 | } | 2672 | } |
2673 | waitDialog.hide(); | 2673 | waitDialog.hide(); |
2674 | } | 2674 | } |
2675 | 2675 | ||
2676 | #ifndef WIN32 | 2676 | #ifndef WIN32 |
2677 | dialog->show(); | 2677 | dialog->show(); |
2678 | #endif | 2678 | #endif |
2679 | #ifndef DESKTOP | 2679 | #ifndef DESKTOP |
2680 | // dialog->move (20, 100); | 2680 | // dialog->move (20, 100); |
2681 | #endif | 2681 | #endif |
2682 | DialogCode result = (DialogCode) dialog->exec(); | 2682 | DialogCode result = (DialogCode) dialog->exec(); |
2683 | #ifdef DESKTOP | 2683 | #ifdef DESKTOP |
2684 | result = Accepted; | 2684 | result = Accepted; |
2685 | #endif | 2685 | #endif |
2686 | 2686 | ||
2687 | QString category; | 2687 | QString category; |
2688 | QString icon; | 2688 | QString icon; |
2689 | QString fullIconPath; | 2689 | QString fullIconPath; |
2690 | QPixmap *pix; | 2690 | QPixmap *pix; |
2691 | if (result == Accepted) | 2691 | if (result == Accepted) |
2692 | { | 2692 | { |
2693 | modified = true; | 2693 | modified = true; |
2694 | category = dialog->CategoryField->currentText(); | 2694 | category = dialog->CategoryField->currentText(); |
2695 | icon = dialog->IconField->currentText()+".png"; | 2695 | icon = dialog->IconField->currentText()+".png"; |
2696 | 2696 | ||
2697 | qWarning (category); | 2697 | qWarning (category); |
2698 | 2698 | ||
2699 | QListViewItem *li = new ShadedListItem( 1, ListView ); | 2699 | QListViewItem *li = new ShadedListItem( 1, ListView ); |
2700 | Category *c1 = new Category(); | 2700 | Category *c1 = new Category(); |
2701 | c1->setCategoryName(category); | 2701 | c1->setCategoryName(category); |
2702 | 2702 | ||
2703 | // if (!icon.isEmpty() && !icon.isNull()) | 2703 | // if (!icon.isEmpty() && !icon.isNull()) |
2704 | if (icon != "predefined.png") | 2704 | if (icon != "predefined.png") |
2705 | { | 2705 | { |
2706 | // build the full path | 2706 | // build the full path |
2707 | fullIconPath = iconPath + icon; | 2707 | fullIconPath = iconPath + icon; |
2708 | pix = new QPixmap (fullIconPath); | 2708 | pix = new QPixmap (fullIconPath); |
2709 | // pix->resize(14, 14); | 2709 | // pix->resize(14, 14); |
2710 | if (pix) | 2710 | if (pix) |
2711 | { | 2711 | { |
2712 | // save the full pixmap name into the config file | 2712 | // save the full pixmap name into the config file |
2713 | // #ifndef WIN32 | 2713 | // #ifndef WIN32 |
2714 | conf->writeEntry(APP_KEY+category, icon); | 2714 | conf->writeEntry(APP_KEY+category, icon); |
2715 | // #endif | 2715 | // #endif |
2716 | saveConf(); | 2716 | saveConf(); |
2717 | QImage img = pix->convertToImage(); | 2717 | QImage img = pix->convertToImage(); |
2718 | pix->convertFromImage(img.smoothScale(14,14)); | 2718 | pix->convertFromImage(img.smoothScale(14,14)); |
2719 | c1->setIcon (*pix); | 2719 | c1->setIcon (*pix); |
2720 | c1->setIconName(icon); | 2720 | c1->setIconName(icon); |
2721 | } | 2721 | } |
2722 | else | 2722 | else |
2723 | { | 2723 | { |
2724 | QPixmap folder( ( const char** ) general_data ); | 2724 | QPixmap folder( ( const char** ) general_data ); |
2725 | c1->setIcon (folder); | 2725 | c1->setIcon (folder); |
2726 | } | 2726 | } |
2727 | } | 2727 | } |
2728 | else | 2728 | else |
2729 | { | 2729 | { |
2730 | c1->setIcon (*getPredefinedIcon(category)); | 2730 | c1->setIcon (*getPredefinedIcon(category)); |
2731 | } | 2731 | } |
2732 | 2732 | ||
2733 | c1->setListItem (li); | 2733 | c1->setListItem (li); |
2734 | c1->initListItem(); | 2734 | c1->initListItem(); |
2735 | categories.insert (c1->getCategoryName(), c1); | 2735 | categories.insert (c1->getCategoryName(), c1); |
2736 | 2736 | ||
2737 | saveCategoryDialogFields(dialog); | 2737 | saveCategoryDialogFields(dialog); |
2738 | } | 2738 | } |
2739 | else | 2739 | else |
2740 | { | 2740 | { |
2741 | // delete dialog; | 2741 | // delete dialog; |
2742 | dialog->hide(); | 2742 | dialog->hide(); |
2743 | return; | 2743 | return; |
2744 | } | 2744 | } |
2745 | 2745 | ||
2746 | } | 2746 | } |
2747 | 2747 | ||
2748 | } | 2748 | } |
2749 | 2749 | ||
2750 | void ZSafe::delCategory() | 2750 | void ZSafe::delCategory() |
2751 | { | 2751 | { |
2752 | if (!selectedItem) | 2752 | if (!selectedItem) |
2753 | return; | 2753 | return; |
2754 | if (isCategory(selectedItem)) | 2754 | if (isCategory(selectedItem)) |
2755 | { | 2755 | { |
2756 | switch( QMessageBox::information( this, tr("ZSafe"), | 2756 | switch( QMessageBox::information( this, tr("ZSafe"), |
2757 | tr("Do you want to delete?"), | 2757 | tr("Do you want to delete?"), |
2758 | tr("&Delete"), tr("D&on't Delete"), | 2758 | tr("&Delete"), tr("D&on't Delete"), |
2759 | 0 // Enter == button 0 | 2759 | 0 // Enter == button 0 |
2760 | ) ) { // Escape == button 2 | 2760 | ) ) { // Escape == button 2 |
2761 | case 0: // Delete clicked, Alt-S or Enter pressed. | 2761 | case 0: // Delete clicked, Alt-S or Enter pressed. |
2762 | // Delete from the category list | 2762 | // Delete from the category list |
2763 | modified = true; | 2763 | modified = true; |
2764 | categories.remove (selectedItem->text(0)); | 2764 | categories.remove (selectedItem->text(0)); |
2765 | // #ifndef WIN32 | 2765 | // #ifndef WIN32 |
2766 | conf->removeEntry (selectedItem->text(0)); | 2766 | conf->removeEntry (selectedItem->text(0)); |
2767 | // #endif | 2767 | // #endif |
2768 | saveConf(); | 2768 | saveConf(); |
2769 | 2769 | ||
2770 | // Delete the selected item and all subitems | 2770 | // Delete the selected item and all subitems |
2771 | // step through all subitems | 2771 | // step through all subitems |
2772 | QListViewItem *si; | 2772 | QListViewItem *si; |
2773 | for (si = selectedItem->firstChild(); | 2773 | for (si = selectedItem->firstChild(); |
2774 | si != NULL; ) | 2774 | si != NULL; ) |
2775 | { | 2775 | { |
2776 | QListViewItem *_si = si; | 2776 | QListViewItem *_si = si; |
2777 | si = si->nextSibling(); | 2777 | si = si->nextSibling(); |
2778 | selectedItem->takeItem(_si); // remove from view list | 2778 | selectedItem->takeItem(_si); // remove from view list |
2779 | if (_si) delete _si; | 2779 | if (_si) delete _si; |
2780 | } | 2780 | } |
2781 | ListView->takeItem(selectedItem); | 2781 | ListView->takeItem(selectedItem); |
2782 | delete selectedItem; | 2782 | delete selectedItem; |
2783 | 2783 | ||
2784 | selectedItem = NULL; | 2784 | selectedItem = NULL; |
2785 | break; | 2785 | break; |
2786 | case 1: // Don't delete | 2786 | case 1: // Don't delete |
2787 | break; | 2787 | break; |
2788 | } | 2788 | } |
2789 | 2789 | ||
2790 | } | 2790 | } |
2791 | } | 2791 | } |
2792 | 2792 | ||
2793 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) | 2793 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) |
2794 | { | 2794 | { |
2795 | if (!dialog) | 2795 | if (!dialog) |
2796 | return; | 2796 | return; |
2797 | 2797 | ||
2798 | QString icon; | 2798 | QString icon; |
2799 | if (selectedItem) | 2799 | if (selectedItem) |
2800 | { | 2800 | { |
2801 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 2801 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
2802 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 2802 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); |
2803 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | 2803 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); |
2804 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | 2804 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); |
2805 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | 2805 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); |
2806 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | 2806 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); |
2807 | 2807 | ||
2808 | Category *cat= categories.find (selectedItem->text(0)); | 2808 | Category *cat= categories.find (selectedItem->text(0)); |
2809 | if (cat) | 2809 | if (cat) |
2810 | { | 2810 | { |
2811 | icon = cat->getIconName(); | 2811 | icon = cat->getIconName(); |
2812 | } | 2812 | } |
2813 | else | ||
2814 | icon = conf->readEntry(APP_KEY+selectedItem->text(0)); | ||
2813 | } | 2815 | } |
2814 | else | 2816 | else |
2815 | { | 2817 | { |
2816 | dialog->Field1->setText(tr("Name")); | 2818 | dialog->Field1->setText(tr("Name")); |
2817 | dialog->Field2->setText(tr("Username")); | 2819 | dialog->Field2->setText(tr("Username")); |
2818 | dialog->Field3->setText(tr("Password")); | 2820 | dialog->Field3->setText(tr("Password")); |
2819 | dialog->Field4->setText(tr("Comment")); | 2821 | dialog->Field4->setText(tr("Comment")); |
2820 | dialog->Field5->setText(tr("Field 4")); | 2822 | dialog->Field5->setText(tr("Field 4")); |
2821 | dialog->Field6->setText(tr("Field 5")); | 2823 | dialog->Field6->setText(tr("Field 5")); |
2822 | } | 2824 | } |
2823 | 2825 | ||
2824 | #ifdef DESKTOP | 2826 | #ifdef DESKTOP |
2825 | QDir d(iconPath); | 2827 | QDir d(iconPath); |
2826 | #else | 2828 | #else |
2827 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2829 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2828 | #endif | 2830 | #endif |
2829 | d.setFilter( QDir::Files); | 2831 | d.setFilter( QDir::Files); |
2830 | 2832 | ||
2831 | const QFileInfoList *list = d.entryInfoList(); | 2833 | const QFileInfoList *list = d.entryInfoList(); |
2832 | int i=0; | 2834 | int i=0; |
2833 | QFileInfoListIterator it( *list ); // create list iterator | 2835 | QFileInfoListIterator it( *list ); // create list iterator |
2834 | QFileInfo *fi; // pointer for traversing | 2836 | QFileInfo *fi; // pointer for traversing |
2835 | if (icon.isEmpty() || icon.isNull()) | 2837 | if (icon.isEmpty() || icon.isNull()) |
2836 | { | 2838 | { |
2837 | dialog->IconField->setCurrentItem(0); | 2839 | dialog->IconField->setCurrentItem(0); |
2838 | } | 2840 | } |
2839 | else | 2841 | else |
2840 | { | 2842 | { |
2841 | while ( (fi=it.current()) ) | 2843 | while ( (fi=it.current()) ) |
2842 | { // for each file... | 2844 | { // for each file... |
2843 | QString fileName = fi->fileName(); | 2845 | QString fileName = fi->fileName(); |
2844 | if(fileName.right(4) == ".png") | 2846 | if(fileName.right(4) == ".png") |
2845 | { | 2847 | { |
2846 | fileName = fileName.mid(0,fileName.length()-4); | 2848 | fileName = fileName.mid(0,fileName.length()-4); |
2847 | 2849 | ||
2848 | if(fileName+".png"==icon) | 2850 | if(fileName+".png"==icon) |
2849 | { | 2851 | { |
2850 | dialog->IconField->setCurrentItem(i+1); | 2852 | dialog->IconField->setCurrentItem(i+1); |
2851 | break; | 2853 | break; |
2852 | } | 2854 | } |
2853 | ++i; | 2855 | ++i; |
2854 | } | 2856 | } |
2855 | ++it; | 2857 | ++it; |
2856 | } | 2858 | } |
2857 | } | 2859 | } |
2858 | } | 2860 | } |
2859 | 2861 | ||
2860 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) | 2862 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) |
2861 | { | 2863 | { |
2862 | if (!dialog) | 2864 | if (!dialog) |
2863 | return; | 2865 | return; |
2864 | 2866 | ||
2865 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); | 2867 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); |
2866 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); | 2868 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); |
2867 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); | 2869 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); |
2868 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); | 2870 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); |
2869 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); | 2871 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); |
2870 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); | 2872 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); |
2871 | 2873 | ||
2872 | QString icon; | 2874 | QString icon; |
2873 | Category *cat= categories.find (category); | 2875 | Category *cat= categories.find (category); |
2874 | if (cat) | 2876 | if (cat) |
2875 | { | 2877 | { |
2876 | icon = cat->getIconName(); | 2878 | icon = cat->getIconName(); |
2877 | } | 2879 | } |
2880 | else | ||
2881 | icon = conf->readEntry(APP_KEY+category); | ||
2878 | 2882 | ||
2879 | #ifdef DESKTOP | 2883 | #ifdef DESKTOP |
2880 | QDir d(iconPath); | 2884 | QDir d(iconPath); |
2881 | #else | 2885 | #else |
2882 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2886 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2883 | #endif | 2887 | #endif |
2884 | d.setFilter( QDir::Files); | 2888 | d.setFilter( QDir::Files); |
2885 | 2889 | ||
2886 | const QFileInfoList *list = d.entryInfoList(); | 2890 | const QFileInfoList *list = d.entryInfoList(); |
2887 | int i=0; | 2891 | int i=0; |
2888 | QFileInfoListIterator it( *list ); // create list iterator | 2892 | QFileInfoListIterator it( *list ); // create list iterator |
2889 | QFileInfo *fi; // pointer for traversing | 2893 | QFileInfo *fi; // pointer for traversing |
2890 | if (icon.isEmpty() || icon.isNull()) | 2894 | if (icon.isEmpty() || icon.isNull()) |
2891 | { | 2895 | { |
2892 | dialog->IconField->setCurrentItem(0); | 2896 | dialog->IconField->setCurrentItem(0); |
2893 | } | 2897 | } |
2894 | else | 2898 | else |
2895 | { | 2899 | { |
2896 | while ( (fi=it.current()) ) | 2900 | while ( (fi=it.current()) ) |
2897 | { // for each file... | 2901 | { // for each file... |
2898 | QString fileName = fi->fileName(); | 2902 | QString fileName = fi->fileName(); |
2899 | if(fileName.right(4) == ".png") | 2903 | if(fileName.right(4) == ".png") |
2900 | { | 2904 | { |
2901 | fileName = fileName.mid(0,fileName.length()-4); | 2905 | fileName = fileName.mid(0,fileName.length()-4); |
2902 | 2906 | ||
2903 | if(fileName+".png"==icon) | 2907 | if(fileName+".png"==icon) |
2904 | { | 2908 | { |
2905 | dialog->IconField->setCurrentItem(i+1); | 2909 | dialog->IconField->setCurrentItem(i+1); |
2906 | break; | 2910 | break; |
2907 | } | 2911 | } |
2908 | ++i; | 2912 | ++i; |
2909 | } | 2913 | } |
2910 | ++it; | 2914 | ++it; |
2911 | } | 2915 | } |
2912 | } | 2916 | } |
2913 | } | 2917 | } |
2914 | 2918 | ||
2915 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) | 2919 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) |
2916 | { | 2920 | { |
2917 | QString app_key = APP_KEY; | 2921 | QString app_key = APP_KEY; |
2918 | #ifndef DESKTOP | 2922 | #ifndef DESKTOP |
2919 | conf->setGroup ("fieldDefs"); | 2923 | conf->setGroup ("fieldDefs"); |
2920 | #else | 2924 | #else |
2921 | #ifndef WIN32 | 2925 | #ifndef WIN32 |
2922 | app_key += "/fieldDefs/"; | 2926 | app_key += "/fieldDefs/"; |
2923 | #endif | 2927 | #endif |
2924 | #endif | 2928 | #endif |
2925 | QString category = dialog->CategoryField->currentText(); | 2929 | QString category = dialog->CategoryField->currentText(); |
2926 | // #ifndef WIN32 | 2930 | // #ifndef WIN32 |
2927 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); | 2931 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); |
2928 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); | 2932 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); |
2929 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); | 2933 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); |
2930 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); | 2934 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); |
2931 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); | 2935 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); |
2932 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); | 2936 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); |
2933 | // #endif | 2937 | // #endif |
2934 | saveConf(); | 2938 | saveConf(); |
2935 | #ifndef DESKTOP | 2939 | #ifndef DESKTOP |
2936 | conf->setGroup ("zsafe"); | 2940 | conf->setGroup ("zsafe"); |
2937 | #endif | 2941 | #endif |
2938 | } | 2942 | } |
2939 | 2943 | ||
2940 | void ZSafe::editCategory() | 2944 | void ZSafe::editCategory() |
2941 | { | 2945 | { |
2942 | if (!selectedItem) | 2946 | if (!selectedItem) |
2943 | return; | 2947 | return; |
2944 | if (isCategory(selectedItem)) | 2948 | if (isCategory(selectedItem)) |
2945 | { | 2949 | { |
2946 | QString category = selectedItem->text(0); | 2950 | QString category = selectedItem->text(0); |
2947 | bool initIcons = false; | 2951 | bool initIcons = false; |
2948 | // open the 'Category' dialog | 2952 | // open the 'Category' dialog |
2949 | CategoryDialog *dialog; | 2953 | CategoryDialog *dialog; |
2950 | if (categoryDialog) | 2954 | if (categoryDialog) |
2951 | { | 2955 | { |
2952 | dialog = categoryDialog; | 2956 | dialog = categoryDialog; |
2953 | } | 2957 | } |
2954 | else | 2958 | else |
2955 | { | 2959 | { |
2956 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); | 2960 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); |
2957 | #ifdef WIN32 | 2961 | #ifdef WIN32 |
2958 | categoryDialog->setCaption ("Qt " + tr("Category")); | 2962 | categoryDialog->setCaption ("Qt " + tr("Category")); |
2959 | #endif | 2963 | #endif |
2960 | dialog = categoryDialog; | 2964 | dialog = categoryDialog; |
2961 | connect( dialog->CategoryField, | 2965 | connect( dialog->CategoryField, |
2962 | SIGNAL( activated ( const QString &)), | 2966 | SIGNAL( activated ( const QString &)), |
2963 | this, SLOT( categoryFieldActivated( const QString & ) ) ); | 2967 | this, SLOT( categoryFieldActivated( const QString & ) ) ); |
2964 | initIcons = true; | 2968 | initIcons = true; |
2965 | } | 2969 | } |
2966 | setCategoryDialogFields(dialog); | 2970 | setCategoryDialogFields(dialog); |
2967 | 2971 | ||
2968 | #ifdef DESKTOP | 2972 | #ifdef DESKTOP |
2969 | #ifndef WIN32 | 2973 | #ifndef WIN32 |
2970 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); | 2974 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); |
2971 | #else | 2975 | #else |
2972 | // read all categories from the config file and store | 2976 | // read all categories from the config file and store |
2973 | // into a list | 2977 | // into a list |
2974 | QFile f (cfgFile); | 2978 | QFile f (cfgFile); |
2975 | QStringList list; | 2979 | QStringList list; |
2976 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2980 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2977 | QTextStream t( &f ); // use a text stream | 2981 | QTextStream t( &f ); // use a text stream |
2978 | QString s; | 2982 | QString s; |
2979 | int n = 1; | 2983 | int n = 1; |
2980 | while ( !t.eof() ) { // until end of file... | 2984 | while ( !t.eof() ) { // until end of file... |
2981 | s = t.readLine(); // line of text excluding '\n' | 2985 | s = t.readLine(); // line of text excluding '\n' |
2982 | list.append(s); | 2986 | list.append(s); |
2983 | } | 2987 | } |
2984 | f.close(); | 2988 | f.close(); |
2985 | } | 2989 | } |
2986 | #endif | 2990 | #endif |
2987 | #else | 2991 | #else |
2988 | // read all categories from the config file and store | 2992 | // read all categories from the config file and store |
2989 | // into a list | 2993 | // into a list |
2990 | QFile f (cfgFile); | 2994 | QFile f (cfgFile); |
2991 | QStringList list; | 2995 | QStringList list; |
2992 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2996 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2993 | QTextStream t( &f ); // use a text stream | 2997 | QTextStream t( &f ); // use a text stream |
2994 | QString s; | 2998 | QString s; |
2995 | while ( !t.eof() ) { // until end of file... | 2999 | while ( !t.eof() ) { // until end of file... |
2996 | s = t.readLine(); // line of text excluding '\n' | 3000 | s = t.readLine(); // line of text excluding '\n' |
2997 | list.append(s); | 3001 | list.append(s); |
2998 | } | 3002 | } |
2999 | f.close(); | 3003 | f.close(); |
3000 | } | 3004 | } |
3001 | #endif | 3005 | #endif |
3002 | QStringList::Iterator it = list.begin(); | 3006 | QStringList::Iterator it = list.begin(); |
3003 | QString categ; | 3007 | QString categ; |
3004 | dialog->CategoryField->clear(); // remove all items | 3008 | dialog->CategoryField->clear(); // remove all items |
3005 | int i=0; | 3009 | int i=0; |
3006 | bool foundCategory = false; | 3010 | bool foundCategory = false; |
3007 | while( it != list.end() ) | 3011 | while( it != list.end() ) |
3008 | { | 3012 | { |
3009 | QString *cat = new QString (*it); | 3013 | QString *cat = new QString (*it); |
3010 | if (cat->contains("-field1", FALSE)) | 3014 | if (cat->contains("-field1", FALSE)) |
3011 | { | 3015 | { |
3012 | #ifdef DESKTOP | 3016 | #ifdef DESKTOP |
3013 | #ifndef WIN32 | 3017 | #ifndef WIN32 |
3014 | categ = cat->section ("-field1", 0, 0); | 3018 | categ = cat->section ("-field1", 0, 0); |
3015 | #else | 3019 | #else |
3016 | int pos = cat->find ("-field1"); | 3020 | int pos = cat->find ("-field1"); |
3017 | categ = cat->left (pos); | 3021 | categ = cat->left (pos); |
3018 | #endif | 3022 | #endif |
3019 | #else | 3023 | #else |
3020 | int pos = cat->find ("-field1"); | 3024 | int pos = cat->find ("-field1"); |
3021 | cat->truncate(pos); | 3025 | cat->truncate(pos); |
3022 | categ = *cat; | 3026 | categ = *cat; |
3023 | #endif | 3027 | #endif |
3024 | if (!categ.isEmpty()) | 3028 | if (!categ.isEmpty()) |
3025 | { | 3029 | { |
3026 | dialog->CategoryField->insertItem (categ, i); | 3030 | dialog->CategoryField->insertItem (categ, i); |
3027 | if (category.compare(categ) == 0) | 3031 | if (category.compare(categ) == 0) |
3028 | { | 3032 | { |
3029 | dialog->CategoryField->setCurrentItem(i); | 3033 | dialog->CategoryField->setCurrentItem(i); |
3030 | foundCategory = true; | 3034 | foundCategory = true; |
3031 | } | 3035 | } |
3032 | i++; | 3036 | i++; |
3033 | } | 3037 | } |
3034 | } | 3038 | } |
3035 | ++it; | 3039 | ++it; |
3036 | } | 3040 | } |
3037 | if (!foundCategory) | 3041 | if (!foundCategory) |
3038 | { | 3042 | { |
3039 | dialog->CategoryField->insertItem (category, i); | 3043 | dialog->CategoryField->insertItem (category, i); |
3040 | dialog->CategoryField->setCurrentItem(i); | 3044 | dialog->CategoryField->setCurrentItem(i); |
3041 | } | 3045 | } |
3042 | 3046 | ||
3043 | QString icon; | 3047 | QString icon; |
3044 | Category *cat= categories.find (selectedItem->text(0)); | 3048 | Category *cat= categories.find (selectedItem->text(0)); |
3045 | if (cat) | 3049 | if (cat) |
3046 | { | 3050 | { |
3047 | icon = cat->getIconName(); | 3051 | icon = cat->getIconName(); |
3048 | } | 3052 | } |
3049 | 3053 | ||
3050 | if (initIcons) | 3054 | if (initIcons) |
3051 | { | 3055 | { |
3052 | 3056 | ||
3053 | Wait waitDialog(this, tr("Wait dialog")); | 3057 | Wait waitDialog(this, tr("Wait dialog")); |
3054 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 3058 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
3055 | waitDialog.show(); | 3059 | waitDialog.show(); |
3056 | qApp->processEvents(); | 3060 | qApp->processEvents(); |
3057 | 3061 | ||
3058 | #ifdef DESKTOP | 3062 | #ifdef DESKTOP |
3059 | QDir d(iconPath); | 3063 | QDir d(iconPath); |
3060 | #else | 3064 | #else |
3061 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3065 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
3062 | #endif | 3066 | #endif |
3063 | d.setFilter( QDir::Files); | 3067 | d.setFilter( QDir::Files); |
3064 | 3068 | ||
3065 | const QFileInfoList *list = d.entryInfoList(); | 3069 | const QFileInfoList *list = d.entryInfoList(); |
3066 | int i=0; | 3070 | int i=0; |
3067 | QFileInfoListIterator it( *list ); // create list iterator | 3071 | QFileInfoListIterator it( *list ); // create list iterator |
3068 | QFileInfo *fi; // pointer for traversing | 3072 | QFileInfo *fi; // pointer for traversing |
3069 | if (icon.isEmpty() || icon.isNull()) | 3073 | if (icon.isEmpty() || icon.isNull()) |
3070 | { | 3074 | { |
3071 | dialog->IconField->setCurrentItem(0); | 3075 | dialog->IconField->setCurrentItem(0); |
3072 | } | 3076 | } |
3073 | 3077 | ||
3074 | dialog->IconField->insertItem("predefined"); | 3078 | dialog->IconField->insertItem("predefined"); |
3075 | while ( (fi=it.current()) ) { // for each file... | 3079 | while ( (fi=it.current()) ) { // for each file... |
3076 | QString fileName = fi->fileName(); | 3080 | QString fileName = fi->fileName(); |
3077 | if(fileName.right(4) == ".png") | 3081 | if(fileName.right(4) == ".png") |
3078 | { | 3082 | { |
3079 | fileName = fileName.mid(0,fileName.length()-4); | 3083 | fileName = fileName.mid(0,fileName.length()-4); |
3080 | #ifdef DESKTOP | 3084 | #ifdef DESKTOP |
3081 | QPixmap imageOfFile; | 3085 | QPixmap imageOfFile; |
3082 | imageOfFile.load(iconPath + fi->fileName()); | 3086 | imageOfFile.load(iconPath + fi->fileName()); |
3083 | #else | 3087 | #else |
3084 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 3088 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
3085 | #endif | 3089 | #endif |
3086 | QImage foo = imageOfFile.convertToImage(); | 3090 | QImage foo = imageOfFile.convertToImage(); |
3087 | foo = foo.smoothScale(16,16); | 3091 | foo = foo.smoothScale(16,16); |
3088 | imageOfFile.convertFromImage(foo); | 3092 | imageOfFile.convertFromImage(foo); |
3089 | dialog->IconField->insertItem(imageOfFile,fileName); | 3093 | dialog->IconField->insertItem(imageOfFile,fileName); |
3090 | if(fileName+".png"==icon) | 3094 | if(fileName+".png"==icon) |
3091 | dialog->IconField->setCurrentItem(i+1); | 3095 | dialog->IconField->setCurrentItem(i+1); |
3092 | ++i; | 3096 | ++i; |
3093 | } | 3097 | } |
3094 | ++it; | 3098 | ++it; |
3095 | } | 3099 | } |
3096 | waitDialog.hide(); | 3100 | waitDialog.hide(); |
3097 | } | 3101 | } |
3098 | else | 3102 | else |
3099 | { | 3103 | { |
3100 | #ifdef DESKTOP | 3104 | #ifdef DESKTOP |
3101 | // QDir d(QDir::homeDirPath() + "/pics/"); | 3105 | // QDir d(QDir::homeDirPath() + "/pics/"); |
3102 | QDir d(iconPath); | 3106 | QDir d(iconPath); |
3103 | #else | 3107 | #else |
3104 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3108 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
3105 | #endif | 3109 | #endif |
3106 | d.setFilter( QDir::Files); | 3110 | d.setFilter( QDir::Files); |
3107 | 3111 | ||
3108 | const QFileInfoList *list = d.entryInfoList(); | 3112 | const QFileInfoList *list = d.entryInfoList(); |
3109 | int i=0; | 3113 | int i=0; |
3110 | QFileInfoListIterator it( *list ); // create list iterator | 3114 | QFileInfoListIterator it( *list ); // create list iterator |
3111 | QFileInfo *fi; // pointer for traversing | 3115 | QFileInfo *fi; // pointer for traversing |
3112 | if (icon.isEmpty() || icon.isNull()) | 3116 | if (icon.isEmpty() || icon.isNull()) |
3113 | { | 3117 | { |
3114 | dialog->IconField->setCurrentItem(0); | 3118 | dialog->IconField->setCurrentItem(0); |
3115 | } | 3119 | } |
3116 | else | 3120 | else |
3117 | { | 3121 | { |
3118 | 3122 | ||
3119 | while ( (fi=it.current()) ) | 3123 | while ( (fi=it.current()) ) |
3120 | { // for each file... | 3124 | { // for each file... |
3121 | QString fileName = fi->fileName(); | 3125 | QString fileName = fi->fileName(); |
3122 | if(fileName.right(4) == ".png") | 3126 | if(fileName.right(4) == ".png") |
3123 | { | 3127 | { |
3124 | fileName = fileName.mid(0,fileName.length()-4); | 3128 | fileName = fileName.mid(0,fileName.length()-4); |
3125 | 3129 | ||
3126 | 3130 | ||
3127 | if(fileName+".png"==icon) | 3131 | if(fileName+".png"==icon) |
3128 | { | 3132 | { |
3129 | dialog->IconField->setCurrentItem(i+1); | 3133 | dialog->IconField->setCurrentItem(i+1); |
3130 | break; | 3134 | break; |
3131 | } | 3135 | } |
3132 | ++i; | 3136 | ++i; |
3133 | } | 3137 | } |
3134 | ++it; | 3138 | ++it; |
3135 | } | 3139 | } |
3136 | } | 3140 | } |
3137 | } | 3141 | } |
3138 | 3142 | ||
3139 | // dialog->show(); | 3143 | // dialog->show(); |
3140 | #ifndef DESKTOP | 3144 | #ifndef DESKTOP |
3141 | // dialog->move (20, 100); | 3145 | // dialog->move (20, 100); |
3142 | #endif | 3146 | #endif |
3143 | DialogCode result = (DialogCode) dialog->exec(); | 3147 | DialogCode result = (DialogCode) dialog->exec(); |
3144 | #ifdef DESKTOP | 3148 | #ifdef DESKTOP |
3145 | result = Accepted; | 3149 | result = Accepted; |
3146 | #endif | 3150 | #endif |
3147 | 3151 | ||
3148 | QString fullIconPath; | 3152 | QString fullIconPath; |
3149 | QPixmap *pix; | 3153 | QPixmap *pix; |
3150 | if (result == Accepted) | 3154 | if (result == Accepted) |
3151 | { | 3155 | { |
3152 | modified = true; | 3156 | modified = true; |
3153 | if (category != dialog->CategoryField->currentText()) | 3157 | if (category != dialog->CategoryField->currentText()) |
3154 | { | 3158 | { |
3155 | categories.remove (category); | 3159 | categories.remove (category); |
3156 | // #ifndef WIN32 | 3160 | // #ifndef WIN32 |
3157 | conf->removeEntry(category); | 3161 | conf->removeEntry(category); |
3158 | // #endif | 3162 | // #endif |
3159 | saveConf(); | 3163 | saveConf(); |
3160 | } | 3164 | } |
3161 | 3165 | ||
3162 | category = dialog->CategoryField->currentText(); | 3166 | category = dialog->CategoryField->currentText(); |
3163 | icon = dialog->IconField->currentText()+".png"; | 3167 | icon = dialog->IconField->currentText()+".png"; |
3164 | 3168 | ||
3165 | if (cat) | 3169 | if (cat) |
3166 | { | 3170 | { |
3167 | qWarning("Category found"); | 3171 | qWarning("Category found"); |
3168 | 3172 | ||
3169 | // if (!icon.isEmpty() && !icon.isNull()) | 3173 | // if (!icon.isEmpty() && !icon.isNull()) |
3170 | if (icon != "predefined.png") | 3174 | if (icon != "predefined.png") |
3171 | { | 3175 | { |
3172 | // build the full path | 3176 | // build the full path |
3173 | fullIconPath = iconPath + icon; | 3177 | fullIconPath = iconPath + icon; |
3174 | pix = new QPixmap (fullIconPath); | 3178 | pix = new QPixmap (fullIconPath); |
3175 | if (pix) | 3179 | if (pix) |
3176 | { | 3180 | { |
3177 | // save the full pixmap name into the config file | 3181 | // save the full pixmap name into the config file |
3178 | // #ifndef WIN32 | 3182 | // #ifndef WIN32 |
3179 | conf->writeEntry(APP_KEY+category, icon); | 3183 | conf->writeEntry(APP_KEY+category, icon); |
3180 | // #endif | 3184 | // #endif |
3181 | saveConf(); | 3185 | saveConf(); |
3182 | QImage img = pix->convertToImage(); | 3186 | QImage img = pix->convertToImage(); |
3183 | pix->convertFromImage(img.smoothScale(14,14)); | 3187 | pix->convertFromImage(img.smoothScale(14,14)); |
3184 | cat->setIconName (icon); | 3188 | cat->setIconName (icon); |
3185 | cat->setIcon (*pix); | 3189 | cat->setIcon (*pix); |
3186 | } | 3190 | } |
3187 | } | 3191 | } |
3188 | else | 3192 | else |
3189 | { | 3193 | { |
3190 | // #ifndef WIN32 | 3194 | // #ifndef WIN32 |
3191 | conf->removeEntry (category); | 3195 | conf->removeEntry (category); |
3192 | // #endif | 3196 | // #endif |
3193 | saveConf(); | 3197 | saveConf(); |
3194 | cat->setIcon (*getPredefinedIcon(category)); | 3198 | cat->setIcon (*getPredefinedIcon(category)); |
3195 | } | 3199 | } |
3196 | 3200 | ||
3197 | // change the category name of the selected category | 3201 | // change the category name of the selected category |
3198 | QListViewItem *catItem = cat->getListItem(); | 3202 | QListViewItem *catItem = cat->getListItem(); |
3199 | if (catItem) | 3203 | if (catItem) |
3200 | { | 3204 | { |
3201 | qWarning (category); | 3205 | qWarning (category); |
3202 | catItem->setText( 0, tr( category ) ); | 3206 | catItem->setText( 0, tr( category ) ); |
3203 | cat->setCategoryName (tr(category)); | 3207 | cat->setCategoryName (tr(category)); |
3204 | cat->initListItem(); | 3208 | cat->initListItem(); |
3205 | categories.insert (category, cat); | 3209 | categories.insert (category, cat); |
3206 | } | 3210 | } |
3207 | } | 3211 | } |
3208 | saveCategoryDialogFields(dialog); | 3212 | saveCategoryDialogFields(dialog); |
3209 | } | 3213 | } |
3210 | else | 3214 | else |
3211 | { | 3215 | { |
3212 | // delete dialog; | 3216 | // delete dialog; |
3213 | dialog->hide(); | 3217 | dialog->hide(); |
3214 | return; | 3218 | return; |
3215 | } | 3219 | } |
3216 | 3220 | ||
3217 | } | 3221 | } |
3218 | } | 3222 | } |
3219 | 3223 | ||
3220 | void ZSafe::cutItem() | 3224 | void ZSafe::cutItem() |
3221 | { | 3225 | { |
3222 | if (!selectedItem) | 3226 | if (!selectedItem) |
3223 | return; | 3227 | return; |
3224 | if (!isCategory(selectedItem)) | 3228 | if (!isCategory(selectedItem)) |
3225 | { | 3229 | { |
3226 | IsCut = true; | 3230 | IsCut = true; |
3227 | copiedItem = selectedItem; | 3231 | copiedItem = selectedItem; |
3228 | } | 3232 | } |
3229 | } | 3233 | } |
3230 | 3234 | ||
3231 | void ZSafe::copyItem() | 3235 | void ZSafe::copyItem() |
3232 | { | 3236 | { |
3233 | if (!selectedItem) | 3237 | if (!selectedItem) |
3234 | return; | 3238 | return; |
3235 | if (!isCategory(selectedItem)) | 3239 | if (!isCategory(selectedItem)) |
3236 | { | 3240 | { |
3237 | IsCopy = true; | 3241 | IsCopy = true; |
3238 | copiedItem = selectedItem; | 3242 | copiedItem = selectedItem; |
3239 | } | 3243 | } |
3240 | } | 3244 | } |
3241 | 3245 | ||
3242 | // paste item into category | 3246 | // paste item into category |
3243 | void ZSafe::pasteItem() | 3247 | void ZSafe::pasteItem() |
3244 | { | 3248 | { |
3245 | if (!selectedItem) | 3249 | if (!selectedItem) |
3246 | return; | 3250 | return; |
3247 | if (isCategory(selectedItem)) | 3251 | if (isCategory(selectedItem)) |
3248 | { | 3252 | { |
3249 | modified = true; | 3253 | modified = true; |
3250 | if (IsCut) | 3254 | if (IsCut) |
3251 | { | 3255 | { |
3252 | if (copiedItem) | 3256 | if (copiedItem) |
3253 | { | 3257 | { |
3254 | // add the new item | 3258 | // add the new item |
3255 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3259 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3256 | // i->setOpen (TRUE); | 3260 | // i->setOpen (TRUE); |
3257 | i->setText (0, copiedItem->text(0)); | 3261 | i->setText (0, copiedItem->text(0)); |
3258 | i->setText (1, copiedItem->text(1)); | 3262 | i->setText (1, copiedItem->text(1)); |
3259 | i->setText (2, copiedItem->text(2)); | 3263 | i->setText (2, copiedItem->text(2)); |
3260 | i->setText (3, copiedItem->text(3)); | 3264 | i->setText (3, copiedItem->text(3)); |
3261 | i->setText (4, copiedItem->text(4)); | 3265 | i->setText (4, copiedItem->text(4)); |
3262 | i->setText (5, copiedItem->text(5)); | 3266 | i->setText (5, copiedItem->text(5)); |
3263 | selectedItem->setOpen( TRUE ); | 3267 | selectedItem->setOpen( TRUE ); |
3264 | 3268 | ||
3265 | // remove the cutted item | 3269 | // remove the cutted item |
3266 | copiedItem->parent()->takeItem(copiedItem); | 3270 | copiedItem->parent()->takeItem(copiedItem); |
3267 | selectedItem = NULL; | 3271 | selectedItem = NULL; |
3268 | } | 3272 | } |
3269 | } | 3273 | } |
3270 | else if (IsCopy) | 3274 | else if (IsCopy) |
3271 | { | 3275 | { |
3272 | if (copiedItem) | 3276 | if (copiedItem) |
3273 | { | 3277 | { |
3274 | // add the new item | 3278 | // add the new item |
3275 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3279 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3276 | // i->setOpen (TRUE); | 3280 | // i->setOpen (TRUE); |
3277 | i->setText (0, copiedItem->text(0)); | 3281 | i->setText (0, copiedItem->text(0)); |
3278 | i->setText (1, copiedItem->text(1)); | 3282 | i->setText (1, copiedItem->text(1)); |
3279 | i->setText (2, copiedItem->text(2)); | 3283 | i->setText (2, copiedItem->text(2)); |
3280 | i->setText (3, copiedItem->text(3)); | 3284 | i->setText (3, copiedItem->text(3)); |
3281 | i->setText (4, copiedItem->text(4)); | 3285 | i->setText (4, copiedItem->text(4)); |
3282 | i->setText (5, copiedItem->text(5)); | 3286 | i->setText (5, copiedItem->text(5)); |
3283 | selectedItem->setOpen( TRUE ); | 3287 | selectedItem->setOpen( TRUE ); |
3284 | } | 3288 | } |
3285 | } | 3289 | } |
3286 | } | 3290 | } |
3287 | IsCut = false; | 3291 | IsCut = false; |
3288 | IsCopy = false; | 3292 | IsCopy = false; |
3289 | } | 3293 | } |
3290 | 3294 | ||
3291 | void ZSafe::newDocument() | 3295 | void ZSafe::newDocument() |
3292 | { | 3296 | { |
3293 | 3297 | ||
3294 | // open the file dialog | 3298 | // open the file dialog |
3295 | #ifndef DESKTOP | 3299 | #ifndef DESKTOP |
3296 | #ifndef NO_OPIE | 3300 | #ifndef NO_OPIE |
3297 | QMap<QString, QStringList> mimeTypes; | 3301 | QMap<QString, QStringList> mimeTypes; |
3298 | mimeTypes.insert(tr("All"), QStringList() ); | 3302 | mimeTypes.insert(tr("All"), QStringList() ); |
3299 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | 3303 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); |
3300 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | 3304 | QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, |
3301 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3305 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3302 | QString::null, | 3306 | QString::null, |
3303 | mimeTypes, | 3307 | mimeTypes, |
3304 | this, | 3308 | this, |
3305 | tr ("Create new ZSafe document")); | 3309 | tr ("Create new ZSafe document")); |
3306 | #else | 3310 | #else |
3307 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, | 3311 | QString newFile = ScQtFileEdit::getSaveAsFileName(this, |
3308 | tr ("Create new ZSafe document"), | 3312 | tr ("Create new ZSafe document"), |
3309 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3313 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3310 | "*.zsf"); | 3314 | "*.zsf"); |
3311 | #endif | 3315 | #endif |
3312 | #else | 3316 | #else |
3313 | QString newFile = QFileDialog::getSaveFileName( | 3317 | QString newFile = QFileDialog::getSaveFileName( |
3314 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3318 | QDir::homeDirPath() + "/Documents/application/zsafe", |
3315 | "ZSafe (*.zsf)", | 3319 | "ZSafe (*.zsf)", |
3316 | this, | 3320 | this, |
3317 | "ZSafe File Dialog" | 3321 | "ZSafe File Dialog" |
3318 | "Choose a ZSafe file" ); | 3322 | "Choose a ZSafe file" ); |
3319 | #endif | 3323 | #endif |
3320 | 3324 | ||
3321 | // open the new document | 3325 | // open the new document |
3322 | if (newFile && newFile.length() > 0 ) | 3326 | if (newFile && newFile.length() > 0 ) |
3323 | { | 3327 | { |
3324 | // save the previous opened document | 3328 | // save the previous opened document |
3325 | if (!filename.isEmpty()) | 3329 | if (!filename.isEmpty()) |
3326 | saveDocument(filename, FALSE); | 3330 | saveDocument(filename, FALSE); |
3327 | 3331 | ||
3328 | modified = true; | 3332 | modified = true; |
3329 | 3333 | ||
3330 | // clear the password list | 3334 | // clear the password list |
3331 | QListViewItem *i; | 3335 | QListViewItem *i; |
3332 | QListViewItem *c = NULL; | 3336 | QListViewItem *c = NULL; |
3333 | // step through all categories | 3337 | // step through all categories |
3334 | for (i = ListView->firstChild(); | 3338 | for (i = ListView->firstChild(); |
3335 | i != NULL; | 3339 | i != NULL; |
3336 | i = i->nextSibling()) | 3340 | i = i->nextSibling()) |
3337 | { | 3341 | { |
3338 | if (c) delete c; // delete the previous category | 3342 | if (c) delete c; // delete the previous category |
3339 | 3343 | ||
3340 | c = i; | 3344 | c = i; |
3341 | // step through all subitems | 3345 | // step through all subitems |
3342 | QListViewItem *si; | 3346 | QListViewItem *si; |
3343 | for (si = i->firstChild(); | 3347 | for (si = i->firstChild(); |
3344 | si != NULL; ) | 3348 | si != NULL; ) |
3345 | { | 3349 | { |
3346 | QListViewItem *_si = si; | 3350 | QListViewItem *_si = si; |
3347 | si = si->nextSibling(); | 3351 | si = si->nextSibling(); |
3348 | i->takeItem(_si); // remove from view list | 3352 | i->takeItem(_si); // remove from view list |
3349 | if (_si) delete _si; | 3353 | if (_si) delete _si; |
3350 | } | 3354 | } |
3351 | } | 3355 | } |
3352 | if (c) delete c; // delete the previous category | 3356 | if (c) delete c; // delete the previous category |
3353 | categories.clear(); | 3357 | categories.clear(); |
3354 | 3358 | ||
3355 | // m_password = ""; | 3359 | // m_password = ""; |
3356 | selectedItem = NULL; | 3360 | selectedItem = NULL; |
3357 | 3361 | ||
3358 | filename = newFile; | 3362 | filename = newFile; |
3359 | 3363 | ||
3360 | // save the current filename to the config file | 3364 | // save the current filename to the config file |
3361 | conf->writeEntry(APP_KEY+"document", filename); | 3365 | conf->writeEntry(APP_KEY+"document", filename); |
3362 | saveConf(); | 3366 | saveConf(); |
3363 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 3367 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
3364 | #ifdef WIN32 | 3368 | #ifdef WIN32 |
3365 | this->setCaption("Qt ZSafe: " + ti); | 3369 | this->setCaption("Qt ZSafe: " + ti); |
3366 | #else | 3370 | #else |
3367 | this->setCaption("ZSafe: " + ti); | 3371 | this->setCaption("ZSafe: " + ti); |
3368 | #endif | 3372 | #endif |
3369 | 3373 | ||
3370 | // openDocument(filename); | 3374 | // openDocument(filename); |
3371 | 3375 | ||
3372 | QMessageBox::information( this, tr("ZSafe"), | 3376 | QMessageBox::information( this, tr("ZSafe"), |
3373 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); | 3377 | tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); |
3374 | 3378 | ||
3375 | saveDocumentWithPwd(); | 3379 | saveDocumentWithPwd(); |
3376 | } | 3380 | } |
3377 | } | 3381 | } |
3378 | 3382 | ||
3379 | void ZSafe::loadDocument() | 3383 | void ZSafe::loadDocument() |
3380 | { | 3384 | { |
3381 | 3385 | ||
3382 | // open the file dialog | 3386 | // open the file dialog |
3383 | #ifndef DESKTOP | 3387 | #ifndef DESKTOP |
3384 | #ifndef NO_OPIE | 3388 | #ifndef NO_OPIE |
3385 | QMap<QString, QStringList> mimeTypes; | 3389 | QMap<QString, QStringList> mimeTypes; |
3386 | mimeTypes.insert(tr("All"), QStringList() ); | 3390 | mimeTypes.insert(tr("All"), QStringList() ); |
3387 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); | 3391 | mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); |
3388 | QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 3392 | QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
3389 | QDir::homeDirPath() + "/Documents/application/zsafe", | 3393 | QDir::homeDirPath() + "/Documents/application/zsafe", |