author | zcarsten <zcarsten> | 2003-08-06 20:15:19 (UTC) |
---|---|---|
committer | zcarsten <zcarsten> | 2003-08-06 20:15:19 (UTC) |
commit | e14f10f07d8477ee49cd487587732e27a3307878 (patch) (unidiff) | |
tree | e46ff1986ce5c0cbba2283d80a878df432f874d8 | |
parent | ba25812361114b7cf059a3a1fb3aed42f8a7ebde (diff) | |
download | opie-e14f10f07d8477ee49cd487587732e27a3307878.zip opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.gz opie-e14f10f07d8477ee49cd487587732e27a3307878.tar.bz2 |
addCategory corrected
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index ef16b46..e86b3d2 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -2344,753 +2344,777 @@ qWarning ("getDocPassword"); | |||
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 | dialog->CategoryField->clear(); // remove all items | 2601 | dialog->CategoryField->clear(); // remove all items |
2601 | while( it != list.end() ) | 2602 | while( it != list.end() ) |
2602 | { | 2603 | { |
2603 | QString *cat = new QString (*it); | 2604 | QString *cat = new QString (*it); |
2604 | if (cat->contains("-field1", FALSE)) | 2605 | if (cat->contains("-field1", FALSE)) |
2605 | { | 2606 | { |
2606 | #ifdef DESKTOP | 2607 | #ifdef DESKTOP |
2607 | #ifndef WIN32 | 2608 | #ifndef WIN32 |
2608 | categ = cat->section ("-field1", 0, 0); | 2609 | categ = cat->section ("-field1", 0, 0); |
2609 | #else | 2610 | #else |
2610 | int pos = cat->find ("-field1"); | 2611 | int pos = cat->find ("-field1"); |
2611 | categ = cat->left (pos); | 2612 | categ = cat->left (pos); |
2612 | #endif | 2613 | #endif |
2613 | #else | 2614 | #else |
2614 | int pos = cat->find ("-field1"); | 2615 | int pos = cat->find ("-field1"); |
2615 | cat->truncate(pos); | 2616 | cat->truncate(pos); |
2616 | categ = *cat; | 2617 | categ = *cat; |
2617 | #endif | 2618 | #endif |
2618 | if (!categ.isEmpty()) | 2619 | if (!categ.isEmpty()) |
2619 | { | 2620 | { |
2620 | dialog->CategoryField->insertItem (categ, -1); | 2621 | dialog->CategoryField->insertItem (categ, -1); |
2622 | if (firstCategory.isEmpty()) | ||
2623 | firstCategory = categ; | ||
2621 | } | 2624 | } |
2622 | } | 2625 | } |
2623 | ++it; | 2626 | ++it; |
2624 | } | 2627 | } |
2625 | 2628 | ||
2626 | 2629 | ||
2627 | setCategoryDialogFields(dialog); | 2630 | if (firstCategory.isEmpty()) |
2631 | setCategoryDialogFields(dialog); | ||
2632 | else | ||
2633 | setCategoryDialogFields(dialog, firstCategory); | ||
2628 | 2634 | ||
2629 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); | 2635 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); |
2630 | 2636 | ||
2631 | if (initIcons) | 2637 | if (initIcons) |
2632 | { | 2638 | { |
2633 | Wait waitDialog(this, tr("Wait dialog")); | 2639 | Wait waitDialog(this, tr("Wait dialog")); |
2634 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 2640 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2635 | waitDialog.show(); | 2641 | waitDialog.show(); |
2636 | qApp->processEvents(); | 2642 | qApp->processEvents(); |
2637 | 2643 | ||
2638 | #ifdef DESKTOP | 2644 | #ifdef DESKTOP |
2639 | QDir d(iconPath); | 2645 | QDir d(iconPath); |
2640 | #else | 2646 | #else |
2641 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2647 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2642 | #endif | 2648 | #endif |
2643 | d.setFilter( QDir::Files); | 2649 | d.setFilter( QDir::Files); |
2644 | 2650 | ||
2645 | const QFileInfoList *list = d.entryInfoList(); | 2651 | const QFileInfoList *list = d.entryInfoList(); |
2646 | QFileInfoListIterator it( *list ); // create list iterator | 2652 | QFileInfoListIterator it( *list ); // create list iterator |
2647 | QFileInfo *fi; // pointer for traversing | 2653 | QFileInfo *fi; // pointer for traversing |
2648 | 2654 | ||
2649 | dialog->IconField->insertItem("predefined"); | 2655 | dialog->IconField->insertItem("predefined"); |
2650 | while ( (fi=it.current()) ) { // for each file... | 2656 | while ( (fi=it.current()) ) { // for each file... |
2651 | QString fileName = fi->fileName(); | 2657 | QString fileName = fi->fileName(); |
2652 | if(fileName.right(4) == ".png"){ | 2658 | if(fileName.right(4) == ".png"){ |
2653 | fileName = fileName.mid(0,fileName.length()-4); | 2659 | fileName = fileName.mid(0,fileName.length()-4); |
2654 | #ifdef DESKTOP | 2660 | #ifdef DESKTOP |
2655 | QPixmap imageOfFile; | 2661 | QPixmap imageOfFile; |
2656 | imageOfFile.load(iconPath + fi->fileName()); | 2662 | imageOfFile.load(iconPath + fi->fileName()); |
2657 | #else | 2663 | #else |
2658 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 2664 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
2659 | #endif | 2665 | #endif |
2660 | QImage foo = imageOfFile.convertToImage(); | 2666 | QImage foo = imageOfFile.convertToImage(); |
2661 | foo = foo.smoothScale(16,16); | 2667 | foo = foo.smoothScale(16,16); |
2662 | imageOfFile.convertFromImage(foo); | 2668 | imageOfFile.convertFromImage(foo); |
2663 | dialog->IconField->insertItem(imageOfFile,fileName); | 2669 | dialog->IconField->insertItem(imageOfFile,fileName); |
2664 | } | 2670 | } |
2665 | ++it; | 2671 | ++it; |
2666 | } | 2672 | } |
2667 | waitDialog.hide(); | 2673 | waitDialog.hide(); |
2668 | } | 2674 | } |
2669 | 2675 | ||
2670 | #ifndef WIN32 | 2676 | #ifndef WIN32 |
2671 | dialog->show(); | 2677 | dialog->show(); |
2672 | #endif | 2678 | #endif |
2673 | #ifndef DESKTOP | 2679 | #ifndef DESKTOP |
2674 | // dialog->move (20, 100); | 2680 | // dialog->move (20, 100); |
2675 | #endif | 2681 | #endif |
2676 | DialogCode result = (DialogCode) dialog->exec(); | 2682 | DialogCode result = (DialogCode) dialog->exec(); |
2677 | #ifdef DESKTOP | 2683 | #ifdef DESKTOP |
2678 | result = Accepted; | 2684 | result = Accepted; |
2679 | #endif | 2685 | #endif |
2680 | 2686 | ||
2681 | QString category; | 2687 | QString category; |
2682 | QString icon; | 2688 | QString icon; |
2683 | QString fullIconPath; | 2689 | QString fullIconPath; |
2684 | QPixmap *pix; | 2690 | QPixmap *pix; |
2685 | if (result == Accepted) | 2691 | if (result == Accepted) |
2686 | { | 2692 | { |
2687 | modified = true; | 2693 | modified = true; |
2688 | category = dialog->CategoryField->currentText(); | 2694 | category = dialog->CategoryField->currentText(); |
2689 | icon = dialog->IconField->currentText()+".png"; | 2695 | icon = dialog->IconField->currentText()+".png"; |
2690 | 2696 | ||
2691 | qWarning (category); | 2697 | qWarning (category); |
2692 | 2698 | ||
2693 | QListViewItem *li = new ShadedListItem( 1, ListView ); | 2699 | QListViewItem *li = new ShadedListItem( 1, ListView ); |
2694 | Category *c1 = new Category(); | 2700 | Category *c1 = new Category(); |
2695 | c1->setCategoryName(category); | 2701 | c1->setCategoryName(category); |
2696 | 2702 | ||
2697 | // if (!icon.isEmpty() && !icon.isNull()) | 2703 | // if (!icon.isEmpty() && !icon.isNull()) |
2698 | if (icon != "predefined.png") | 2704 | if (icon != "predefined.png") |
2699 | { | 2705 | { |
2700 | // build the full path | 2706 | // build the full path |
2701 | fullIconPath = iconPath + icon; | 2707 | fullIconPath = iconPath + icon; |
2702 | pix = new QPixmap (fullIconPath); | 2708 | pix = new QPixmap (fullIconPath); |
2703 | // pix->resize(14, 14); | 2709 | // pix->resize(14, 14); |
2704 | if (pix) | 2710 | if (pix) |
2705 | { | 2711 | { |
2706 | // save the full pixmap name into the config file | 2712 | // save the full pixmap name into the config file |
2707 | // #ifndef WIN32 | 2713 | // #ifndef WIN32 |
2708 | conf->writeEntry(APP_KEY+category, icon); | 2714 | conf->writeEntry(APP_KEY+category, icon); |
2709 | // #endif | 2715 | // #endif |
2710 | saveConf(); | 2716 | saveConf(); |
2711 | QImage img = pix->convertToImage(); | 2717 | QImage img = pix->convertToImage(); |
2712 | pix->convertFromImage(img.smoothScale(14,14)); | 2718 | pix->convertFromImage(img.smoothScale(14,14)); |
2713 | c1->setIcon (*pix); | 2719 | c1->setIcon (*pix); |
2714 | c1->setIconName(icon); | 2720 | c1->setIconName(icon); |
2715 | } | 2721 | } |
2716 | else | 2722 | else |
2717 | { | 2723 | { |
2718 | QPixmap folder( ( const char** ) general_data ); | 2724 | QPixmap folder( ( const char** ) general_data ); |
2719 | c1->setIcon (folder); | 2725 | c1->setIcon (folder); |
2720 | } | 2726 | } |
2721 | } | 2727 | } |
2722 | else | 2728 | else |
2723 | { | 2729 | { |
2724 | c1->setIcon (*getPredefinedIcon(category)); | 2730 | c1->setIcon (*getPredefinedIcon(category)); |
2725 | } | 2731 | } |
2726 | 2732 | ||
2727 | c1->setListItem (li); | 2733 | c1->setListItem (li); |
2728 | c1->initListItem(); | 2734 | c1->initListItem(); |
2729 | categories.insert (c1->getCategoryName(), c1); | 2735 | categories.insert (c1->getCategoryName(), c1); |
2730 | 2736 | ||
2731 | saveCategoryDialogFields(dialog); | 2737 | saveCategoryDialogFields(dialog); |
2732 | } | 2738 | } |
2733 | else | 2739 | else |
2734 | { | 2740 | { |
2735 | // delete dialog; | 2741 | // delete dialog; |
2736 | dialog->hide(); | 2742 | dialog->hide(); |
2737 | return; | 2743 | return; |
2738 | } | 2744 | } |
2739 | 2745 | ||
2740 | } | 2746 | } |
2741 | 2747 | ||
2742 | } | 2748 | } |
2743 | 2749 | ||
2744 | void ZSafe::delCategory() | 2750 | void ZSafe::delCategory() |
2745 | { | 2751 | { |
2746 | if (!selectedItem) | 2752 | if (!selectedItem) |
2747 | return; | 2753 | return; |
2748 | if (isCategory(selectedItem)) | 2754 | if (isCategory(selectedItem)) |
2749 | { | 2755 | { |
2750 | switch( QMessageBox::information( this, tr("ZSafe"), | 2756 | switch( QMessageBox::information( this, tr("ZSafe"), |
2751 | tr("Do you want to delete?"), | 2757 | tr("Do you want to delete?"), |
2752 | tr("&Delete"), tr("D&on't Delete"), | 2758 | tr("&Delete"), tr("D&on't Delete"), |
2753 | 0 // Enter == button 0 | 2759 | 0 // Enter == button 0 |
2754 | ) ) { // Escape == button 2 | 2760 | ) ) { // Escape == button 2 |
2755 | case 0: // Delete clicked, Alt-S or Enter pressed. | 2761 | case 0: // Delete clicked, Alt-S or Enter pressed. |
2756 | // Delete from the category list | 2762 | // Delete from the category list |
2757 | modified = true; | 2763 | modified = true; |
2758 | categories.remove (selectedItem->text(0)); | 2764 | categories.remove (selectedItem->text(0)); |
2759 | // #ifndef WIN32 | 2765 | // #ifndef WIN32 |
2760 | conf->removeEntry (selectedItem->text(0)); | 2766 | conf->removeEntry (selectedItem->text(0)); |
2761 | // #endif | 2767 | // #endif |
2762 | saveConf(); | 2768 | saveConf(); |
2763 | 2769 | ||
2764 | // Delete the selected item and all subitems | 2770 | // Delete the selected item and all subitems |
2765 | // step through all subitems | 2771 | // step through all subitems |
2766 | QListViewItem *si; | 2772 | QListViewItem *si; |
2767 | for (si = selectedItem->firstChild(); | 2773 | for (si = selectedItem->firstChild(); |
2768 | si != NULL; ) | 2774 | si != NULL; ) |
2769 | { | 2775 | { |
2770 | QListViewItem *_si = si; | 2776 | QListViewItem *_si = si; |
2771 | si = si->nextSibling(); | 2777 | si = si->nextSibling(); |
2772 | selectedItem->takeItem(_si); // remove from view list | 2778 | selectedItem->takeItem(_si); // remove from view list |
2773 | if (_si) delete _si; | 2779 | if (_si) delete _si; |
2774 | } | 2780 | } |
2775 | ListView->takeItem(selectedItem); | 2781 | ListView->takeItem(selectedItem); |
2776 | delete selectedItem; | 2782 | delete selectedItem; |
2777 | 2783 | ||
2778 | selectedItem = NULL; | 2784 | selectedItem = NULL; |
2779 | break; | 2785 | break; |
2780 | case 1: // Don't delete | 2786 | case 1: // Don't delete |
2781 | break; | 2787 | break; |
2782 | } | 2788 | } |
2783 | 2789 | ||
2784 | } | 2790 | } |
2785 | } | 2791 | } |
2786 | 2792 | ||
2787 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) | 2793 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) |
2788 | { | 2794 | { |
2789 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 2795 | if (!dialog) |
2790 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 2796 | return; |
2791 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | ||
2792 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | ||
2793 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | ||
2794 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | ||
2795 | 2797 | ||
2796 | QString icon; | 2798 | QString icon; |
2797 | Category *cat= categories.find (selectedItem->text(0)); | 2799 | if (selectedItem) |
2798 | if (cat) | ||
2799 | { | 2800 | { |
2800 | icon = cat->getIconName(); | 2801 | dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
2802 | dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | ||
2803 | dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | ||
2804 | dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | ||
2805 | dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); | ||
2806 | dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); | ||
2807 | |||
2808 | Category *cat= categories.find (selectedItem->text(0)); | ||
2809 | if (cat) | ||
2810 | { | ||
2811 | icon = cat->getIconName(); | ||
2812 | } | ||
2813 | } | ||
2814 | else | ||
2815 | { | ||
2816 | dialog->Field1->setText(tr("Name")); | ||
2817 | dialog->Field2->setText(tr("Username")); | ||
2818 | dialog->Field3->setText(tr("Password")); | ||
2819 | dialog->Field4->setText(tr("Comment")); | ||
2820 | dialog->Field5->setText(tr("Field 4")); | ||
2821 | dialog->Field6->setText(tr("Field 5")); | ||
2801 | } | 2822 | } |
2802 | 2823 | ||
2803 | #ifdef DESKTOP | 2824 | #ifdef DESKTOP |
2804 | QDir d(iconPath); | 2825 | QDir d(iconPath); |
2805 | #else | 2826 | #else |
2806 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2827 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2807 | #endif | 2828 | #endif |
2808 | d.setFilter( QDir::Files); | 2829 | d.setFilter( QDir::Files); |
2809 | 2830 | ||
2810 | const QFileInfoList *list = d.entryInfoList(); | 2831 | const QFileInfoList *list = d.entryInfoList(); |
2811 | int i=0; | 2832 | int i=0; |
2812 | QFileInfoListIterator it( *list ); // create list iterator | 2833 | QFileInfoListIterator it( *list ); // create list iterator |
2813 | QFileInfo *fi; // pointer for traversing | 2834 | QFileInfo *fi; // pointer for traversing |
2814 | if (icon.isEmpty() || icon.isNull()) | 2835 | if (icon.isEmpty() || icon.isNull()) |
2815 | { | 2836 | { |
2816 | dialog->IconField->setCurrentItem(0); | 2837 | dialog->IconField->setCurrentItem(0); |
2817 | } | 2838 | } |
2818 | else | 2839 | else |
2819 | { | 2840 | { |
2820 | while ( (fi=it.current()) ) | 2841 | while ( (fi=it.current()) ) |
2821 | { // for each file... | 2842 | { // for each file... |
2822 | QString fileName = fi->fileName(); | 2843 | QString fileName = fi->fileName(); |
2823 | if(fileName.right(4) == ".png") | 2844 | if(fileName.right(4) == ".png") |
2824 | { | 2845 | { |
2825 | fileName = fileName.mid(0,fileName.length()-4); | 2846 | fileName = fileName.mid(0,fileName.length()-4); |
2826 | 2847 | ||
2827 | if(fileName+".png"==icon) | 2848 | if(fileName+".png"==icon) |
2828 | { | 2849 | { |
2829 | dialog->IconField->setCurrentItem(i+1); | 2850 | dialog->IconField->setCurrentItem(i+1); |
2830 | break; | 2851 | break; |
2831 | } | 2852 | } |
2832 | ++i; | 2853 | ++i; |
2833 | } | 2854 | } |
2834 | ++it; | 2855 | ++it; |
2835 | } | 2856 | } |
2836 | } | 2857 | } |
2837 | } | 2858 | } |
2838 | 2859 | ||
2839 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) | 2860 | void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) |
2840 | { | 2861 | { |
2862 | if (!dialog) | ||
2863 | return; | ||
2864 | |||
2841 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); | 2865 | dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); |
2842 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); | 2866 | dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); |
2843 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); | 2867 | dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); |
2844 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); | 2868 | dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); |
2845 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); | 2869 | dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); |
2846 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); | 2870 | dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); |
2847 | 2871 | ||
2848 | QString icon; | 2872 | QString icon; |
2849 | Category *cat= categories.find (category); | 2873 | Category *cat= categories.find (category); |
2850 | if (cat) | 2874 | if (cat) |
2851 | { | 2875 | { |
2852 | icon = cat->getIconName(); | 2876 | icon = cat->getIconName(); |
2853 | } | 2877 | } |
2854 | 2878 | ||
2855 | #ifdef DESKTOP | 2879 | #ifdef DESKTOP |
2856 | QDir d(iconPath); | 2880 | QDir d(iconPath); |
2857 | #else | 2881 | #else |
2858 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2882 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2859 | #endif | 2883 | #endif |
2860 | d.setFilter( QDir::Files); | 2884 | d.setFilter( QDir::Files); |
2861 | 2885 | ||
2862 | const QFileInfoList *list = d.entryInfoList(); | 2886 | const QFileInfoList *list = d.entryInfoList(); |
2863 | int i=0; | 2887 | int i=0; |
2864 | QFileInfoListIterator it( *list ); // create list iterator | 2888 | QFileInfoListIterator it( *list ); // create list iterator |
2865 | QFileInfo *fi; // pointer for traversing | 2889 | QFileInfo *fi; // pointer for traversing |
2866 | if (icon.isEmpty() || icon.isNull()) | 2890 | if (icon.isEmpty() || icon.isNull()) |
2867 | { | 2891 | { |
2868 | dialog->IconField->setCurrentItem(0); | 2892 | dialog->IconField->setCurrentItem(0); |
2869 | } | 2893 | } |
2870 | else | 2894 | else |
2871 | { | 2895 | { |
2872 | while ( (fi=it.current()) ) | 2896 | while ( (fi=it.current()) ) |
2873 | { // for each file... | 2897 | { // for each file... |
2874 | QString fileName = fi->fileName(); | 2898 | QString fileName = fi->fileName(); |
2875 | if(fileName.right(4) == ".png") | 2899 | if(fileName.right(4) == ".png") |
2876 | { | 2900 | { |
2877 | fileName = fileName.mid(0,fileName.length()-4); | 2901 | fileName = fileName.mid(0,fileName.length()-4); |
2878 | 2902 | ||
2879 | if(fileName+".png"==icon) | 2903 | if(fileName+".png"==icon) |
2880 | { | 2904 | { |
2881 | dialog->IconField->setCurrentItem(i+1); | 2905 | dialog->IconField->setCurrentItem(i+1); |
2882 | break; | 2906 | break; |
2883 | } | 2907 | } |
2884 | ++i; | 2908 | ++i; |
2885 | } | 2909 | } |
2886 | ++it; | 2910 | ++it; |
2887 | } | 2911 | } |
2888 | } | 2912 | } |
2889 | } | 2913 | } |
2890 | 2914 | ||
2891 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) | 2915 | void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) |
2892 | { | 2916 | { |
2893 | QString app_key = APP_KEY; | 2917 | QString app_key = APP_KEY; |
2894 | #ifndef DESKTOP | 2918 | #ifndef DESKTOP |
2895 | conf->setGroup ("fieldDefs"); | 2919 | conf->setGroup ("fieldDefs"); |
2896 | #else | 2920 | #else |
2897 | #ifndef WIN32 | 2921 | #ifndef WIN32 |
2898 | app_key += "/fieldDefs/"; | 2922 | app_key += "/fieldDefs/"; |
2899 | #endif | 2923 | #endif |
2900 | #endif | 2924 | #endif |
2901 | QString category = dialog->CategoryField->currentText(); | 2925 | QString category = dialog->CategoryField->currentText(); |
2902 | // #ifndef WIN32 | 2926 | // #ifndef WIN32 |
2903 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); | 2927 | conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); |
2904 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); | 2928 | conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); |
2905 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); | 2929 | conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); |
2906 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); | 2930 | conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); |
2907 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); | 2931 | conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); |
2908 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); | 2932 | conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); |
2909 | // #endif | 2933 | // #endif |
2910 | saveConf(); | 2934 | saveConf(); |
2911 | #ifndef DESKTOP | 2935 | #ifndef DESKTOP |
2912 | conf->setGroup ("zsafe"); | 2936 | conf->setGroup ("zsafe"); |
2913 | #endif | 2937 | #endif |
2914 | } | 2938 | } |
2915 | 2939 | ||
2916 | void ZSafe::editCategory() | 2940 | void ZSafe::editCategory() |
2917 | { | 2941 | { |
2918 | if (!selectedItem) | 2942 | if (!selectedItem) |
2919 | return; | 2943 | return; |
2920 | if (isCategory(selectedItem)) | 2944 | if (isCategory(selectedItem)) |
2921 | { | 2945 | { |
2922 | QString category = selectedItem->text(0); | 2946 | QString category = selectedItem->text(0); |
2923 | bool initIcons = false; | 2947 | bool initIcons = false; |
2924 | // open the 'Category' dialog | 2948 | // open the 'Category' dialog |
2925 | CategoryDialog *dialog; | 2949 | CategoryDialog *dialog; |
2926 | if (categoryDialog) | 2950 | if (categoryDialog) |
2927 | { | 2951 | { |
2928 | dialog = categoryDialog; | 2952 | dialog = categoryDialog; |
2929 | } | 2953 | } |
2930 | else | 2954 | else |
2931 | { | 2955 | { |
2932 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); | 2956 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); |
2933 | #ifdef WIN32 | 2957 | #ifdef WIN32 |
2934 | categoryDialog->setCaption ("Qt " + tr("Category")); | 2958 | categoryDialog->setCaption ("Qt " + tr("Category")); |
2935 | #endif | 2959 | #endif |
2936 | dialog = categoryDialog; | 2960 | dialog = categoryDialog; |
2937 | connect( dialog->CategoryField, | 2961 | connect( dialog->CategoryField, |
2938 | SIGNAL( activated ( const QString &)), | 2962 | SIGNAL( activated ( const QString &)), |
2939 | this, SLOT( categoryFieldActivated( const QString & ) ) ); | 2963 | this, SLOT( categoryFieldActivated( const QString & ) ) ); |
2940 | initIcons = true; | 2964 | initIcons = true; |
2941 | } | 2965 | } |
2942 | setCategoryDialogFields(dialog); | 2966 | setCategoryDialogFields(dialog); |
2943 | 2967 | ||
2944 | #ifdef DESKTOP | 2968 | #ifdef DESKTOP |
2945 | #ifndef WIN32 | 2969 | #ifndef WIN32 |
2946 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); | 2970 | QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); |
2947 | #else | 2971 | #else |
2948 | // read all categories from the config file and store | 2972 | // read all categories from the config file and store |
2949 | // into a list | 2973 | // into a list |
2950 | QFile f (cfgFile); | 2974 | QFile f (cfgFile); |
2951 | QStringList list; | 2975 | QStringList list; |
2952 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2976 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2953 | QTextStream t( &f ); // use a text stream | 2977 | QTextStream t( &f ); // use a text stream |
2954 | QString s; | 2978 | QString s; |
2955 | int n = 1; | 2979 | int n = 1; |
2956 | while ( !t.eof() ) { // until end of file... | 2980 | while ( !t.eof() ) { // until end of file... |
2957 | s = t.readLine(); // line of text excluding '\n' | 2981 | s = t.readLine(); // line of text excluding '\n' |
2958 | list.append(s); | 2982 | list.append(s); |
2959 | } | 2983 | } |
2960 | f.close(); | 2984 | f.close(); |
2961 | } | 2985 | } |
2962 | #endif | 2986 | #endif |
2963 | #else | 2987 | #else |
2964 | // read all categories from the config file and store | 2988 | // read all categories from the config file and store |
2965 | // into a list | 2989 | // into a list |
2966 | QFile f (cfgFile); | 2990 | QFile f (cfgFile); |
2967 | QStringList list; | 2991 | QStringList list; |
2968 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 2992 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
2969 | QTextStream t( &f ); // use a text stream | 2993 | QTextStream t( &f ); // use a text stream |
2970 | QString s; | 2994 | QString s; |
2971 | while ( !t.eof() ) { // until end of file... | 2995 | while ( !t.eof() ) { // until end of file... |
2972 | s = t.readLine(); // line of text excluding '\n' | 2996 | s = t.readLine(); // line of text excluding '\n' |
2973 | list.append(s); | 2997 | list.append(s); |
2974 | } | 2998 | } |
2975 | f.close(); | 2999 | f.close(); |
2976 | } | 3000 | } |
2977 | #endif | 3001 | #endif |
2978 | QStringList::Iterator it = list.begin(); | 3002 | QStringList::Iterator it = list.begin(); |
2979 | QString categ; | 3003 | QString categ; |
2980 | dialog->CategoryField->clear(); // remove all items | 3004 | dialog->CategoryField->clear(); // remove all items |
2981 | int i=0; | 3005 | int i=0; |
2982 | bool foundCategory = false; | 3006 | bool foundCategory = false; |
2983 | while( it != list.end() ) | 3007 | while( it != list.end() ) |
2984 | { | 3008 | { |
2985 | QString *cat = new QString (*it); | 3009 | QString *cat = new QString (*it); |
2986 | if (cat->contains("-field1", FALSE)) | 3010 | if (cat->contains("-field1", FALSE)) |
2987 | { | 3011 | { |
2988 | #ifdef DESKTOP | 3012 | #ifdef DESKTOP |
2989 | #ifndef WIN32 | 3013 | #ifndef WIN32 |
2990 | categ = cat->section ("-field1", 0, 0); | 3014 | categ = cat->section ("-field1", 0, 0); |
2991 | #else | 3015 | #else |
2992 | int pos = cat->find ("-field1"); | 3016 | int pos = cat->find ("-field1"); |
2993 | categ = cat->left (pos); | 3017 | categ = cat->left (pos); |
2994 | #endif | 3018 | #endif |
2995 | #else | 3019 | #else |
2996 | int pos = cat->find ("-field1"); | 3020 | int pos = cat->find ("-field1"); |
2997 | cat->truncate(pos); | 3021 | cat->truncate(pos); |
2998 | categ = *cat; | 3022 | categ = *cat; |
2999 | #endif | 3023 | #endif |
3000 | if (!categ.isEmpty()) | 3024 | if (!categ.isEmpty()) |
3001 | { | 3025 | { |
3002 | dialog->CategoryField->insertItem (categ, i); | 3026 | dialog->CategoryField->insertItem (categ, i); |
3003 | if (category.compare(categ) == 0) | 3027 | if (category.compare(categ) == 0) |
3004 | { | 3028 | { |
3005 | dialog->CategoryField->setCurrentItem(i); | 3029 | dialog->CategoryField->setCurrentItem(i); |
3006 | foundCategory = true; | 3030 | foundCategory = true; |
3007 | } | 3031 | } |
3008 | i++; | 3032 | i++; |
3009 | } | 3033 | } |
3010 | } | 3034 | } |
3011 | ++it; | 3035 | ++it; |
3012 | } | 3036 | } |
3013 | if (!foundCategory) | 3037 | if (!foundCategory) |
3014 | { | 3038 | { |
3015 | dialog->CategoryField->insertItem (category, i); | 3039 | dialog->CategoryField->insertItem (category, i); |
3016 | dialog->CategoryField->setCurrentItem(i); | 3040 | dialog->CategoryField->setCurrentItem(i); |
3017 | } | 3041 | } |
3018 | 3042 | ||
3019 | QString icon; | 3043 | QString icon; |
3020 | Category *cat= categories.find (selectedItem->text(0)); | 3044 | Category *cat= categories.find (selectedItem->text(0)); |
3021 | if (cat) | 3045 | if (cat) |
3022 | { | 3046 | { |
3023 | icon = cat->getIconName(); | 3047 | icon = cat->getIconName(); |
3024 | } | 3048 | } |
3025 | 3049 | ||
3026 | if (initIcons) | 3050 | if (initIcons) |
3027 | { | 3051 | { |
3028 | 3052 | ||
3029 | Wait waitDialog(this, tr("Wait dialog")); | 3053 | Wait waitDialog(this, tr("Wait dialog")); |
3030 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 3054 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
3031 | waitDialog.show(); | 3055 | waitDialog.show(); |
3032 | qApp->processEvents(); | 3056 | qApp->processEvents(); |
3033 | 3057 | ||
3034 | #ifdef DESKTOP | 3058 | #ifdef DESKTOP |
3035 | QDir d(iconPath); | 3059 | QDir d(iconPath); |
3036 | #else | 3060 | #else |
3037 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3061 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
3038 | #endif | 3062 | #endif |
3039 | d.setFilter( QDir::Files); | 3063 | d.setFilter( QDir::Files); |
3040 | 3064 | ||
3041 | const QFileInfoList *list = d.entryInfoList(); | 3065 | const QFileInfoList *list = d.entryInfoList(); |
3042 | int i=0; | 3066 | int i=0; |
3043 | QFileInfoListIterator it( *list ); // create list iterator | 3067 | QFileInfoListIterator it( *list ); // create list iterator |
3044 | QFileInfo *fi; // pointer for traversing | 3068 | QFileInfo *fi; // pointer for traversing |
3045 | if (icon.isEmpty() || icon.isNull()) | 3069 | if (icon.isEmpty() || icon.isNull()) |
3046 | { | 3070 | { |
3047 | dialog->IconField->setCurrentItem(0); | 3071 | dialog->IconField->setCurrentItem(0); |
3048 | } | 3072 | } |
3049 | 3073 | ||
3050 | dialog->IconField->insertItem("predefined"); | 3074 | dialog->IconField->insertItem("predefined"); |
3051 | while ( (fi=it.current()) ) { // for each file... | 3075 | while ( (fi=it.current()) ) { // for each file... |
3052 | QString fileName = fi->fileName(); | 3076 | QString fileName = fi->fileName(); |
3053 | if(fileName.right(4) == ".png") | 3077 | if(fileName.right(4) == ".png") |
3054 | { | 3078 | { |
3055 | fileName = fileName.mid(0,fileName.length()-4); | 3079 | fileName = fileName.mid(0,fileName.length()-4); |
3056 | #ifdef DESKTOP | 3080 | #ifdef DESKTOP |
3057 | QPixmap imageOfFile; | 3081 | QPixmap imageOfFile; |
3058 | imageOfFile.load(iconPath + fi->fileName()); | 3082 | imageOfFile.load(iconPath + fi->fileName()); |
3059 | #else | 3083 | #else |
3060 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 3084 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
3061 | #endif | 3085 | #endif |
3062 | QImage foo = imageOfFile.convertToImage(); | 3086 | QImage foo = imageOfFile.convertToImage(); |
3063 | foo = foo.smoothScale(16,16); | 3087 | foo = foo.smoothScale(16,16); |
3064 | imageOfFile.convertFromImage(foo); | 3088 | imageOfFile.convertFromImage(foo); |
3065 | dialog->IconField->insertItem(imageOfFile,fileName); | 3089 | dialog->IconField->insertItem(imageOfFile,fileName); |
3066 | if(fileName+".png"==icon) | 3090 | if(fileName+".png"==icon) |
3067 | dialog->IconField->setCurrentItem(i+1); | 3091 | dialog->IconField->setCurrentItem(i+1); |
3068 | ++i; | 3092 | ++i; |
3069 | } | 3093 | } |
3070 | ++it; | 3094 | ++it; |
3071 | } | 3095 | } |
3072 | waitDialog.hide(); | 3096 | waitDialog.hide(); |
3073 | } | 3097 | } |
3074 | else | 3098 | else |
3075 | { | 3099 | { |
3076 | #ifdef DESKTOP | 3100 | #ifdef DESKTOP |
3077 | // QDir d(QDir::homeDirPath() + "/pics/"); | 3101 | // QDir d(QDir::homeDirPath() + "/pics/"); |
3078 | QDir d(iconPath); | 3102 | QDir d(iconPath); |
3079 | #else | 3103 | #else |
3080 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 3104 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
3081 | #endif | 3105 | #endif |
3082 | d.setFilter( QDir::Files); | 3106 | d.setFilter( QDir::Files); |
3083 | 3107 | ||
3084 | const QFileInfoList *list = d.entryInfoList(); | 3108 | const QFileInfoList *list = d.entryInfoList(); |
3085 | int i=0; | 3109 | int i=0; |
3086 | QFileInfoListIterator it( *list ); // create list iterator | 3110 | QFileInfoListIterator it( *list ); // create list iterator |
3087 | QFileInfo *fi; // pointer for traversing | 3111 | QFileInfo *fi; // pointer for traversing |
3088 | if (icon.isEmpty() || icon.isNull()) | 3112 | if (icon.isEmpty() || icon.isNull()) |
3089 | { | 3113 | { |
3090 | dialog->IconField->setCurrentItem(0); | 3114 | dialog->IconField->setCurrentItem(0); |
3091 | } | 3115 | } |
3092 | else | 3116 | else |
3093 | { | 3117 | { |
3094 | 3118 | ||
3095 | while ( (fi=it.current()) ) | 3119 | while ( (fi=it.current()) ) |
3096 | { // for each file... | 3120 | { // for each file... |