author | zecke <zecke> | 2003-08-25 15:06:32 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-25 15:06:32 (UTC) |
commit | 44b9e62c1e5071fc6e5f8e80204b9974dbc704b6 (patch) (unidiff) | |
tree | 2ed47cff84f9b9cfb94fd38f6931ba69316f32aa /library | |
parent | bf3c4abb9dff716e098f05852d9a3d8ac8cbcb44 (diff) | |
download | opie-44b9e62c1e5071fc6e5f8e80204b9974dbc704b6.zip opie-44b9e62c1e5071fc6e5f8e80204b9974dbc704b6.tar.gz opie-44b9e62c1e5071fc6e5f8e80204b9974dbc704b6.tar.bz2 |
add a qtopia method we need for the new launcher
-rw-r--r-- | library/backend/categories.cpp | 8 | ||||
-rw-r--r-- | library/backend/categories.h | 3 |
2 files changed, 11 insertions, 0 deletions
diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp index cce9f38..34ff6fe 100644 --- a/library/backend/categories.cpp +++ b/library/backend/categories.cpp | |||
@@ -420,512 +420,520 @@ QStringList Categories::labels( const QString &app, | |||
420 | cats += (*appIt).labels(); | 420 | cats += (*appIt).labels(); |
421 | //else qDebug("Categories::labels didn't find app %s", app.latin1() ); | 421 | //else qDebug("Categories::labels didn't find app %s", app.latin1() ); |
422 | if ( includeGlobal ) | 422 | if ( includeGlobal ) |
423 | cats += mGlobalCats.labels(); | 423 | cats += mGlobalCats.labels(); |
424 | 424 | ||
425 | cats.sort(); | 425 | cats.sort(); |
426 | switch ( extra ) { | 426 | switch ( extra ) { |
427 | case NoExtra: break; | 427 | case NoExtra: break; |
428 | case AllUnfiled: | 428 | case AllUnfiled: |
429 | cats.append( tr("All") ); | 429 | cats.append( tr("All") ); |
430 | cats.append( tr("Unfiled") ); | 430 | cats.append( tr("Unfiled") ); |
431 | break; | 431 | break; |
432 | case AllLabel: | 432 | case AllLabel: |
433 | cats.append( tr("All") ); | 433 | cats.append( tr("All") ); |
434 | break; | 434 | break; |
435 | case UnfiledLabel: | 435 | case UnfiledLabel: |
436 | cats.append( tr("Unfiled") ); | 436 | cats.append( tr("Unfiled") ); |
437 | break; | 437 | break; |
438 | } | 438 | } |
439 | 439 | ||
440 | return cats; | 440 | return cats; |
441 | } | 441 | } |
442 | 442 | ||
443 | /*! | 443 | /*! |
444 | Returns the label associated with the id | 444 | Returns the label associated with the id |
445 | */ | 445 | */ |
446 | QString Categories::label( const QString &app, int id ) const | 446 | QString Categories::label( const QString &app, int id ) const |
447 | { | 447 | { |
448 | if ( mGlobalCats.contains( id ) ) | 448 | if ( mGlobalCats.contains( id ) ) |
449 | return mGlobalCats.label( id ); | 449 | return mGlobalCats.label( id ); |
450 | QMap< QString, CategoryGroup >::ConstIterator | 450 | QMap< QString, CategoryGroup >::ConstIterator |
451 | appIt = mAppCats.find( app ); | 451 | appIt = mAppCats.find( app ); |
452 | if ( appIt == mAppCats.end() ) | 452 | if ( appIt == mAppCats.end() ) |
453 | return QString::null; | 453 | return QString::null; |
454 | return (*appIt).label( id ); | 454 | return (*appIt).label( id ); |
455 | } | 455 | } |
456 | 456 | ||
457 | /*! | 457 | /*! |
458 | Returns a single string associated with \a catids for display in a | 458 | Returns a single string associated with \a catids for display in a |
459 | combobox or any area that requires one string. If \a catids are empty | 459 | combobox or any area that requires one string. If \a catids are empty |
460 | then "Unfiled" will be returned. If multiple categories are | 460 | then "Unfiled" will be returned. If multiple categories are |
461 | assigned then the behavior depends on the DisplaySingle type. | 461 | assigned then the behavior depends on the DisplaySingle type. |
462 | 462 | ||
463 | If \a display is set to ShowMulti then " (multi)" appended to the | 463 | If \a display is set to ShowMulti then " (multi)" appended to the |
464 | first string. If \a display is set to ShowAll, then a space | 464 | first string. If \a display is set to ShowAll, then a space |
465 | seperated string is returned with all categories. If ShowFirst is | 465 | seperated string is returned with all categories. If ShowFirst is |
466 | set, the just the first string is returned. | 466 | set, the just the first string is returned. |
467 | */ | 467 | */ |
468 | QString Categories::displaySingle( const QString &app, | 468 | QString Categories::displaySingle( const QString &app, |
469 | const QArray<int> &catids, | 469 | const QArray<int> &catids, |
470 | DisplaySingle display ) const | 470 | DisplaySingle display ) const |
471 | { | 471 | { |
472 | QStringList strs = labels( app, catids ); | 472 | QStringList strs = labels( app, catids ); |
473 | if ( !strs.count() ) | 473 | if ( !strs.count() ) |
474 | return tr("Unfiled"); | 474 | return tr("Unfiled"); |
475 | strs.sort(); | 475 | strs.sort(); |
476 | QString r; | 476 | QString r; |
477 | if ( strs.count() > 1 ) { | 477 | if ( strs.count() > 1 ) { |
478 | switch ( display ) { | 478 | switch ( display ) { |
479 | case ShowFirst: | 479 | case ShowFirst: |
480 | r = strs.first(); | 480 | r = strs.first(); |
481 | break; | 481 | break; |
482 | case ShowMulti: | 482 | case ShowMulti: |
483 | r = strs.first() + tr(" (multi.)"); | 483 | r = strs.first() + tr(" (multi.)"); |
484 | break; | 484 | break; |
485 | case ShowAll: | 485 | case ShowAll: |
486 | r = strs.join(" "); | 486 | r = strs.join(" "); |
487 | break; | 487 | break; |
488 | } | 488 | } |
489 | } | 489 | } |
490 | else r = strs.first(); | 490 | else r = strs.first(); |
491 | return r; | 491 | return r; |
492 | } | 492 | } |
493 | 493 | ||
494 | /*! | 494 | /*! |
495 | 495 | ||
496 | Returns all ids associated with the application CategoryGroup \a app | 496 | Returns all ids associated with the application CategoryGroup \a app |
497 | and the passed in \a labels in that group. | 497 | and the passed in \a labels in that group. |
498 | */ | 498 | */ |
499 | QArray<int> Categories::ids( const QString &app, const QStringList &labels) const | 499 | QArray<int> Categories::ids( const QString &app, const QStringList &labels) const |
500 | { | 500 | { |
501 | QArray<int> results; | 501 | QArray<int> results; |
502 | QStringList::ConstIterator it; | 502 | QStringList::ConstIterator it; |
503 | int i; | 503 | int i; |
504 | 504 | ||
505 | for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { | 505 | for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { |
506 | int value = id( app, *it ); | 506 | int value = id( app, *it ); |
507 | if ( value != 0 ) { | 507 | if ( value != 0 ) { |
508 | int tmp = results.size(); | 508 | int tmp = results.size(); |
509 | results.resize( tmp + 1 ); | 509 | results.resize( tmp + 1 ); |
510 | results[ tmp ] = value; | 510 | results[ tmp ] = value; |
511 | } | 511 | } |
512 | } | 512 | } |
513 | return results; | 513 | return results; |
514 | } | 514 | } |
515 | 515 | ||
516 | /*! | 516 | /*! |
517 | Returns the id associated with the app. If the id is not found in the | 517 | Returns the id associated with the app. If the id is not found in the |
518 | application CategoryGroup, then it searches the global CategoryGroup. | 518 | application CategoryGroup, then it searches the global CategoryGroup. |
519 | If it is not found it either, 0 is returned. | 519 | If it is not found it either, 0 is returned. |
520 | */ | 520 | */ |
521 | int Categories::id( const QString &app, const QString &cat ) const | 521 | int Categories::id( const QString &app, const QString &cat ) const |
522 | { | 522 | { |
523 | if ( cat == tr("Unfiled") || cat.contains( tr(" (multi.)") ) ) | 523 | if ( cat == tr("Unfiled") || cat.contains( tr(" (multi.)") ) ) |
524 | return 0; | 524 | return 0; |
525 | int uid = mGlobalCats.id( cat ); | 525 | int uid = mGlobalCats.id( cat ); |
526 | if ( uid != 0 ) | 526 | if ( uid != 0 ) |
527 | return uid; | 527 | return uid; |
528 | return mAppCats[app].id( cat ); | 528 | return mAppCats[app].id( cat ); |
529 | } | 529 | } |
530 | 530 | ||
531 | 531 | ||
532 | /*! | 532 | /*! |
533 | Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName | 533 | Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName |
534 | is not found, or if \a newName conflicts with an existing category | 534 | is not found, or if \a newName conflicts with an existing category |
535 | in the CategoryGroup. | 535 | in the CategoryGroup. |
536 | 536 | ||
537 | It will first search the CategoryGroup associated with \a appname | 537 | It will first search the CategoryGroup associated with \a appname |
538 | and if not found it will try to replace in global CategoryGroup. | 538 | and if not found it will try to replace in global CategoryGroup. |
539 | */ | 539 | */ |
540 | bool Categories::renameCategory( const QString &appname, | 540 | bool Categories::renameCategory( const QString &appname, |
541 | const QString &oldName, | 541 | const QString &oldName, |
542 | const QString &newName ) | 542 | const QString &newName ) |
543 | { | 543 | { |
544 | QMap< QString, CategoryGroup >::Iterator | 544 | QMap< QString, CategoryGroup >::Iterator |
545 | appIt = mAppCats.find( appname ); | 545 | appIt = mAppCats.find( appname ); |
546 | 546 | ||
547 | if ( appIt != mAppCats.end() ) { | 547 | if ( appIt != mAppCats.end() ) { |
548 | CategoryGroup &cats = *appIt; | 548 | CategoryGroup &cats = *appIt; |
549 | int id = cats.id( oldName ); | 549 | int id = cats.id( oldName ); |
550 | if ( id != 0 && cats.rename( id, newName ) ) { | 550 | if ( id != 0 && cats.rename( id, newName ) ) { |
551 | emit categoryRenamed( *this, appname, id ); | 551 | emit categoryRenamed( *this, appname, id ); |
552 | return TRUE; | 552 | return TRUE; |
553 | } | 553 | } |
554 | } | 554 | } |
555 | return renameGlobalCategory( oldName, newName ); | 555 | return renameGlobalCategory( oldName, newName ); |
556 | } | 556 | } |
557 | 557 | ||
558 | /*! | 558 | /*! |
559 | Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName | 559 | Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName |
560 | is not found, or if \a newName conflicts with an existing category | 560 | is not found, or if \a newName conflicts with an existing category |
561 | in the CategoryGroup. This function will only rename categories found | 561 | in the CategoryGroup. This function will only rename categories found |
562 | in the global CategoryGroup. | 562 | in the global CategoryGroup. |
563 | */ | 563 | */ |
564 | bool Categories::renameGlobalCategory( const QString &oldName, | 564 | bool Categories::renameGlobalCategory( const QString &oldName, |
565 | const QString &newName ) | 565 | const QString &newName ) |
566 | { | 566 | { |
567 | int uid = mGlobalCats.id( oldName ); | 567 | int uid = mGlobalCats.id( oldName ); |
568 | if ( uid != 0 && mGlobalCats.rename( uid, newName ) ) { | 568 | if ( uid != 0 && mGlobalCats.rename( uid, newName ) ) { |
569 | emit categoryRenamed( *this, QString::null, uid ); | 569 | emit categoryRenamed( *this, QString::null, uid ); |
570 | return TRUE; | 570 | return TRUE; |
571 | } | 571 | } |
572 | return FALSE; | 572 | return FALSE; |
573 | } | 573 | } |
574 | 574 | ||
575 | /*! | 575 | /*! |
576 | Changes the grouping of a category. If a category was global and \a global | 576 | Changes the grouping of a category. If a category was global and \a global |
577 | is set to TRUE, then the \a catname will be moved to the \a appname group. | 577 | is set to TRUE, then the \a catname will be moved to the \a appname group. |
578 | */ | 578 | */ |
579 | void Categories::setGlobal( const QString &appname, | 579 | void Categories::setGlobal( const QString &appname, |
580 | const QString &catname, | 580 | const QString &catname, |
581 | bool global ) | 581 | bool global ) |
582 | { | 582 | { |
583 | // if in global and should be in app; then move it | 583 | // if in global and should be in app; then move it |
584 | if ( mGlobalCats.contains( catname ) && !global ) { | 584 | if ( mGlobalCats.contains( catname ) && !global ) { |
585 | mGlobalCats.remove( catname ); | 585 | mGlobalCats.remove( catname ); |
586 | addCategory( appname, catname ); | 586 | addCategory( appname, catname ); |
587 | return ; | 587 | return ; |
588 | } | 588 | } |
589 | 589 | ||
590 | // if in app and should be in global, then move it | 590 | // if in app and should be in global, then move it |
591 | if ( !global ) | 591 | if ( !global ) |
592 | return; | 592 | return; |
593 | if ( removeCategory( appname, catname, FALSE ) ) | 593 | if ( removeCategory( appname, catname, FALSE ) ) |
594 | addGlobalCategory( catname ); | 594 | addGlobalCategory( catname ); |
595 | } | 595 | } |
596 | 596 | ||
597 | /*! | 597 | /*! |
598 | Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not. | 598 | Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not. |
599 | */ | 599 | */ |
600 | bool Categories::isGlobal( const QString &catname ) const | 600 | bool Categories::isGlobal( const QString &catname ) const |
601 | { | 601 | { |
602 | return mGlobalCats.contains( catname ); | 602 | return mGlobalCats.contains( catname ); |
603 | } | 603 | } |
604 | 604 | ||
605 | 605 | ||
606 | /*! | 606 | /*! |
607 | Returns true if the \a catname is associated with any CategoryGroup, | 607 | Returns true if the \a catname is associated with any CategoryGroup, |
608 | including global. | 608 | including global. |
609 | */ | 609 | */ |
610 | bool Categories::exists( const QString &catname ) const | 610 | bool Categories::exists( const QString &catname ) const |
611 | { | 611 | { |
612 | if ( isGlobal(catname) ) | 612 | if ( isGlobal(catname) ) |
613 | return TRUE; | 613 | return TRUE; |
614 | 614 | ||
615 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) | 615 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) |
616 | if ( exists( appsIt.key(), catname ) ) | 616 | if ( exists( appsIt.key(), catname ) ) |
617 | return TRUE; | 617 | return TRUE; |
618 | 618 | ||
619 | return FALSE; | 619 | return FALSE; |
620 | } | 620 | } |
621 | 621 | ||
622 | /*! | 622 | /*! |
623 | Returns TRUE if the \a catname is associated with the \a appname | 623 | Returns TRUE if the \a catname is associated with the \a appname |
624 | CategoryGroup, FALSE if not found. | 624 | CategoryGroup, FALSE if not found. |
625 | */ | 625 | */ |
626 | bool Categories::exists( const QString &appname, | 626 | bool Categories::exists( const QString &appname, |
627 | const QString &catname) const | 627 | const QString &catname) const |
628 | { | 628 | { |
629 | QMap< QString, CategoryGroup >::ConstIterator | 629 | QMap< QString, CategoryGroup >::ConstIterator |
630 | appIt = mAppCats.find( appname ); | 630 | appIt = mAppCats.find( appname ); |
631 | 631 | ||
632 | if ( appIt == mAppCats.end() ) | 632 | if ( appIt == mAppCats.end() ) |
633 | return FALSE; | 633 | return FALSE; |
634 | 634 | ||
635 | return (*appIt).contains( catname ); | 635 | return (*appIt).contains( catname ); |
636 | } | 636 | } |
637 | 637 | ||
638 | /*! | 638 | /*! |
639 | Saves the Categories database to the \a fname. See categoryFileName() | 639 | Saves the Categories database to the \a fname. See categoryFileName() |
640 | for the default file name string used for the shared category database. | 640 | for the default file name string used for the shared category database. |
641 | 641 | ||
642 | Returns FALSE if there is error writing the file or TRUE on success. | 642 | Returns FALSE if there is error writing the file or TRUE on success. |
643 | */ | 643 | */ |
644 | bool Categories::save( const QString &fname ) const | 644 | bool Categories::save( const QString &fname ) const |
645 | { | 645 | { |
646 | QString strNewFile = fname + ".new"; | 646 | QString strNewFile = fname + ".new"; |
647 | QFile f( strNewFile ); | 647 | QFile f( strNewFile ); |
648 | QString out; | 648 | QString out; |
649 | int total_written; | 649 | int total_written; |
650 | 650 | ||
651 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 651 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
652 | qWarning("Unable to write to %s", fname.latin1()); | 652 | qWarning("Unable to write to %s", fname.latin1()); |
653 | return FALSE; | 653 | return FALSE; |
654 | } | 654 | } |
655 | 655 | ||
656 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | 656 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
657 | out += "<!DOCTYPE CategoryList>\n"; | 657 | out += "<!DOCTYPE CategoryList>\n"; |
658 | 658 | ||
659 | out += "<Categories>\n"; | 659 | out += "<Categories>\n"; |
660 | 660 | ||
661 | for ( QMap<int, QString>::ConstIterator git = mGlobalCats.idMap().begin(); | 661 | for ( QMap<int, QString>::ConstIterator git = mGlobalCats.idMap().begin(); |
662 | git != mGlobalCats.idMap().end(); ++git ) | 662 | git != mGlobalCats.idMap().end(); ++git ) |
663 | out += "<Category id=\"" + QString::number(git.key()) + "\"" + | 663 | out += "<Category id=\"" + QString::number(git.key()) + "\"" + |
664 | " name=\"" + escapeString(*git) + "\" />\n"; | 664 | " name=\"" + escapeString(*git) + "\" />\n"; |
665 | 665 | ||
666 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt=mAppCats.begin(); | 666 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt=mAppCats.begin(); |
667 | appsIt != mAppCats.end(); ++appsIt ) { | 667 | appsIt != mAppCats.end(); ++appsIt ) { |
668 | const QString &app = appsIt.key(); | 668 | const QString &app = appsIt.key(); |
669 | const QMap<int, QString> &appcats = (*appsIt).idMap(); | 669 | const QMap<int, QString> &appcats = (*appsIt).idMap(); |
670 | for ( QMap<int, QString>::ConstIterator appcatit = appcats.begin(); | 670 | for ( QMap<int, QString>::ConstIterator appcatit = appcats.begin(); |
671 | appcatit != appcats.end(); ++appcatit ) | 671 | appcatit != appcats.end(); ++appcatit ) |
672 | out += "<Category id=\"" + QString::number(appcatit.key()) + "\"" + | 672 | out += "<Category id=\"" + QString::number(appcatit.key()) + "\"" + |
673 | " app=\"" + escapeString(app) + "\"" + | 673 | " app=\"" + escapeString(app) + "\"" + |
674 | " name=\"" + escapeString(*appcatit) + "\" />\n"; | 674 | " name=\"" + escapeString(*appcatit) + "\" />\n"; |
675 | } | 675 | } |
676 | out += "</Categories>\n"; | 676 | out += "</Categories>\n"; |
677 | 677 | ||
678 | QCString cstr = out.utf8(); | 678 | QCString cstr = out.utf8(); |
679 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 679 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
680 | if ( total_written != int(cstr.length()) ) { | 680 | if ( total_written != int(cstr.length()) ) { |
681 | f.close(); | 681 | f.close(); |
682 | QFile::remove( strNewFile ); | 682 | QFile::remove( strNewFile ); |
683 | return FALSE; | 683 | return FALSE; |
684 | } | 684 | } |
685 | f.close(); | 685 | f.close(); |
686 | 686 | ||
687 | #ifdef Q_OS_WIN32 | 687 | #ifdef Q_OS_WIN32 |
688 | QFile::remove( fname ); | 688 | QFile::remove( fname ); |
689 | #endif | 689 | #endif |
690 | if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) { | 690 | if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) { |
691 | qWarning( "problem renaming file %s to %s", | 691 | qWarning( "problem renaming file %s to %s", |
692 | strNewFile.latin1(), fname.latin1()); | 692 | strNewFile.latin1(), fname.latin1()); |
693 | // remove the tmp file... | 693 | // remove the tmp file... |
694 | QFile::remove( strNewFile ); | 694 | QFile::remove( strNewFile ); |
695 | } | 695 | } |
696 | 696 | ||
697 | return TRUE; | 697 | return TRUE; |
698 | } | 698 | } |
699 | 699 | ||
700 | /*! | 700 | /*! |
701 | Loads the Categories database using \a fname. See categoryFileName() | 701 | Loads the Categories database using \a fname. See categoryFileName() |
702 | for the default file name string used for the shared category database. | 702 | for the default file name string used for the shared category database. |
703 | 703 | ||
704 | Returns FALSE if there is error reading the file or TRUE on success. | 704 | Returns FALSE if there is error reading the file or TRUE on success. |
705 | */ | 705 | */ |
706 | bool Categories::load( const QString &fname ) | 706 | bool Categories::load( const QString &fname ) |
707 | { | 707 | { |
708 | QFile file( fname ); | 708 | QFile file( fname ); |
709 | if ( !file.open( IO_ReadOnly ) ) { | 709 | if ( !file.open( IO_ReadOnly ) ) { |
710 | qWarning("Unable to open %s", fname.latin1()); | 710 | qWarning("Unable to open %s", fname.latin1()); |
711 | 711 | ||
712 | addGlobalCategory(tr("Business")); | 712 | addGlobalCategory(tr("Business")); |
713 | addGlobalCategory(tr("Personal")); | 713 | addGlobalCategory(tr("Personal")); |
714 | save(fname); | 714 | save(fname); |
715 | 715 | ||
716 | return FALSE; | 716 | return FALSE; |
717 | } | 717 | } |
718 | 718 | ||
719 | clear(); | 719 | clear(); |
720 | QByteArray ba = file.readAll(); | 720 | QByteArray ba = file.readAll(); |
721 | QString data = QString::fromUtf8( ba.data(), ba.size() ); | 721 | QString data = QString::fromUtf8( ba.data(), ba.size() ); |
722 | QChar *uc = (QChar *)data.unicode(); | 722 | QChar *uc = (QChar *)data.unicode(); |
723 | int len = data.length(); | 723 | int len = data.length(); |
724 | 724 | ||
725 | // QTime t; | 725 | // QTime t; |
726 | // t.start(); | 726 | // t.start(); |
727 | QString name; | 727 | QString name; |
728 | QString id; | 728 | QString id; |
729 | QString app; | 729 | QString app; |
730 | int i = 0; | 730 | int i = 0; |
731 | while ( (i = data.find( "<Category ", i)) != -1 ) { | 731 | while ( (i = data.find( "<Category ", i)) != -1 ) { |
732 | 732 | ||
733 | i += 10; | 733 | i += 10; |
734 | name = QString::null; | 734 | name = QString::null; |
735 | app = QString::null; | 735 | app = QString::null; |
736 | while ( 1 ) { | 736 | while ( 1 ) { |
737 | // skip white space | 737 | // skip white space |
738 | while ( i < len && | 738 | while ( i < len && |
739 | (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) | 739 | (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) |
740 | i++; | 740 | i++; |
741 | // if at the end, then done | 741 | // if at the end, then done |
742 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) | 742 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) |
743 | break; | 743 | break; |
744 | // we have another attribute read it. | 744 | // we have another attribute read it. |
745 | int j = i; | 745 | int j = i; |
746 | while ( j < len && uc[j] != '=' ) | 746 | while ( j < len && uc[j] != '=' ) |
747 | j++; | 747 | j++; |
748 | QString attr = QConstString( uc+i, j-i ).string(); | 748 | QString attr = QConstString( uc+i, j-i ).string(); |
749 | i = ++j; // skip = | 749 | i = ++j; // skip = |
750 | while ( i < len && uc[i] != '"' ) | 750 | while ( i < len && uc[i] != '"' ) |
751 | i++; | 751 | i++; |
752 | j = ++i; | 752 | j = ++i; |
753 | while ( j < len && uc[j] != '"' ) | 753 | while ( j < len && uc[j] != '"' ) |
754 | j++; | 754 | j++; |
755 | QString value = Qtopia::plainString( QConstString( uc+i, j-i ).string() ); | 755 | QString value = Qtopia::plainString( QConstString( uc+i, j-i ).string() ); |
756 | i = j + 1; | 756 | i = j + 1; |
757 | 757 | ||
758 | // qDebug("attr='%s' value='%s'", attr.latin1(), value.latin1() ); | 758 | // qDebug("attr='%s' value='%s'", attr.latin1(), value.latin1() ); |
759 | if ( attr == "id" ) | 759 | if ( attr == "id" ) |
760 | id = value; | 760 | id = value; |
761 | else if ( attr == "app" ) | 761 | else if ( attr == "app" ) |
762 | app = value; | 762 | app = value; |
763 | 763 | ||
764 | else if ( attr == "name" ) | 764 | else if ( attr == "name" ) |
765 | name = value; | 765 | name = value; |
766 | } | 766 | } |
767 | 767 | ||
768 | if ( name.isNull() || id.isNull() ) { | 768 | if ( name.isNull() || id.isNull() ) { |
769 | qWarning("No name or id in the category"); | 769 | qWarning("No name or id in the category"); |
770 | continue; | 770 | continue; |
771 | } | 771 | } |
772 | if ( app.isNull() ) | 772 | if ( app.isNull() ) |
773 | mGlobalCats.add( id.toInt(), name ); | 773 | mGlobalCats.add( id.toInt(), name ); |
774 | else | 774 | else |
775 | mAppCats[ app ].add( id.toInt(), name ); | 775 | mAppCats[ app ].add( id.toInt(), name ); |
776 | } | 776 | } |
777 | 777 | ||
778 | return TRUE; | 778 | return TRUE; |
779 | } | 779 | } |
780 | 780 | ||
781 | /*! | 781 | /*! |
782 | Clear the categories in memory. Equivelent to creating an empty Categories | 782 | Clear the categories in memory. Equivelent to creating an empty Categories |
783 | object. | 783 | object. |
784 | */ | 784 | */ |
785 | void Categories::clear() | 785 | void Categories::clear() |
786 | { | 786 | { |
787 | mGlobalCats.clear(); | 787 | mGlobalCats.clear(); |
788 | mAppCats.clear(); | 788 | mAppCats.clear(); |
789 | } | 789 | } |
790 | 790 | ||
791 | /*! | 791 | /*! |
792 | Dump the contents to standard out. Used for debugging only. | 792 | Dump the contents to standard out. Used for debugging only. |
793 | */ | 793 | */ |
794 | void Categories::dump() const | 794 | void Categories::dump() const |
795 | { | 795 | { |
796 | qDebug("\tglobal categories = %s", mGlobalCats.labels().join(", ").latin1() ); | 796 | qDebug("\tglobal categories = %s", mGlobalCats.labels().join(", ").latin1() ); |
797 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) { | 797 | for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) { |
798 | const QString &app = appsIt.key(); | 798 | const QString &app = appsIt.key(); |
799 | QStringList appcats = (*appsIt).labels(); | 799 | QStringList appcats = (*appsIt).labels(); |
800 | qDebug("\tapp = %s\tcategories = %s", app.latin1(), | 800 | qDebug("\tapp = %s\tcategories = %s", app.latin1(), |
801 | appcats.join(", ").latin1() ); | 801 | appcats.join(", ").latin1() ); |
802 | 802 | ||
803 | } | 803 | } |
804 | } | 804 | } |
805 | 805 | ||
806 | QStringList CheckedListView::checked() const | 806 | QStringList CheckedListView::checked() const |
807 | { | 807 | { |
808 | QStringList strs; | 808 | QStringList strs; |
809 | for ( QCheckListItem *i = (QCheckListItem *) firstChild(); | 809 | for ( QCheckListItem *i = (QCheckListItem *) firstChild(); |
810 | i; i = (QCheckListItem *)i->nextSibling() ) | 810 | i; i = (QCheckListItem *)i->nextSibling() ) |
811 | if ( i->isOn() ) | 811 | if ( i->isOn() ) |
812 | strs += i->text( 0 ); | 812 | strs += i->text( 0 ); |
813 | return strs; | 813 | return strs; |
814 | } | 814 | } |
815 | 815 | ||
816 | void CheckedListView::addCheckableList( const QStringList &options ) | 816 | void CheckedListView::addCheckableList( const QStringList &options ) |
817 | { | 817 | { |
818 | for ( QStringList::ConstIterator it = options.begin(); | 818 | for ( QStringList::ConstIterator it = options.begin(); |
819 | it != options.end(); ++it ) { | 819 | it != options.end(); ++it ) { |
820 | (void) new QCheckListItem( this, *it, | 820 | (void) new QCheckListItem( this, *it, |
821 | QCheckListItem::CheckBox ); | 821 | QCheckListItem::CheckBox ); |
822 | } | 822 | } |
823 | } | 823 | } |
824 | 824 | ||
825 | void CheckedListView::setChecked( const QStringList &checked ) | 825 | void CheckedListView::setChecked( const QStringList &checked ) |
826 | { | 826 | { |
827 | // iterate over all items | 827 | // iterate over all items |
828 | bool showingChecked = FALSE; | 828 | bool showingChecked = FALSE; |
829 | for ( QCheckListItem *i = (QCheckListItem *) firstChild(); | 829 | for ( QCheckListItem *i = (QCheckListItem *) firstChild(); |
830 | i; i = (QCheckListItem *)i->nextSibling() ) | 830 | i; i = (QCheckListItem *)i->nextSibling() ) |
831 | // see if the item should be checked by searching the | 831 | // see if the item should be checked by searching the |
832 | // checked list | 832 | // checked list |
833 | if ( checked.find( i->text( 0 ) ) != checked.end() ) { | 833 | if ( checked.find( i->text( 0 ) ) != checked.end() ) { |
834 | i->setOn( TRUE ); | 834 | i->setOn( TRUE ); |
835 | // make sure it is showing at least one checked item | 835 | // make sure it is showing at least one checked item |
836 | if ( !showingChecked ) { | 836 | if ( !showingChecked ) { |
837 | ensureItemVisible( i ); | 837 | ensureItemVisible( i ); |
838 | showingChecked = TRUE; | 838 | showingChecked = TRUE; |
839 | } | 839 | } |
840 | } | 840 | } |
841 | else | 841 | else |
842 | i->setOn( FALSE ); | 842 | i->setOn( FALSE ); |
843 | } | 843 | } |
844 | 844 | ||
845 | /*! \fn Categories &Categories::operator= ( const Categories &c ) | 845 | /*! \fn Categories &Categories::operator= ( const Categories &c ) |
846 | 846 | ||
847 | Performs deep copy. | 847 | Performs deep copy. |
848 | */ | 848 | */ |
849 | 849 | ||
850 | 850 | ||
851 | /*! \fn QStringList Categories::globalCategories() const | 851 | /*! \fn QStringList Categories::globalCategories() const |
852 | 852 | ||
853 | Returns list of all global category labels | 853 | Returns list of all global category labels |
854 | */ | 854 | */ |
855 | 855 | ||
856 | /*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const | 856 | /*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const |
857 | 857 | ||
858 | Returns a map of application names to CategoryGroup. The CategoryGroup | 858 | Returns a map of application names to CategoryGroup. The CategoryGroup |
859 | class defines a map of ids to category labels and category labels to ids. | 859 | class defines a map of ids to category labels and category labels to ids. |
860 | */ | 860 | */ |
861 | 861 | ||
862 | /*! \fn const CategoryGroup &Categories::globalGroup() const | 862 | /*! \fn const CategoryGroup &Categories::globalGroup() const |
863 | 863 | ||
864 | Returns the global CategoryGroup. The CategoryGroup | 864 | Returns the global CategoryGroup. The CategoryGroup |
865 | class defines a map of ids to category labels and category labels to ids. | 865 | class defines a map of ids to category labels and category labels to ids. |
866 | */ | 866 | */ |
867 | 867 | ||
868 | /*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid) | 868 | /*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid) |
869 | 869 | ||
870 | Emitted if a category is added. | 870 | Emitted if a category is added. |
871 | 871 | ||
872 | \a cats is a const reference to this object | 872 | \a cats is a const reference to this object |
873 | \a appname is the CategoryGroup application name that the category was added to or QString::null if it was global | 873 | \a appname is the CategoryGroup application name that the category was added to or QString::null if it was global |
874 | \a uid is the unique identifier associated with the added category | 874 | \a uid is the unique identifier associated with the added category |
875 | */ | 875 | */ |
876 | 876 | ||
877 | /*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname, | 877 | /*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname, |
878 | int uid) | 878 | int uid) |
879 | 879 | ||
880 | Emitted if removed category is removed. | 880 | Emitted if removed category is removed. |
881 | 881 | ||
882 | \a cats is a const reference to this object | 882 | \a cats is a const reference to this object |
883 | \a appname is the CategoryGroup application name that the category was removed from or QString::null if it was the global CategoryGroup | 883 | \a appname is the CategoryGroup application name that the category was removed from or QString::null if it was the global CategoryGroup |
884 | \a uid is the unique identifier associated with the removed category | 884 | \a uid is the unique identifier associated with the removed category |
885 | */ | 885 | */ |
886 | 886 | ||
887 | 887 | ||
888 | /*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname, | 888 | /*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname, |
889 | int uid) | 889 | int uid) |
890 | 890 | ||
891 | Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats | 891 | Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats |
892 | object. | 892 | object. |
893 | 893 | ||
894 | \a cats is a const reference to this object | 894 | \a cats is a const reference to this object |
895 | \a appname is the CategoryGroup application name that the category was renamed in or QString::null if it was the global CategoryGroup | 895 | \a appname is the CategoryGroup application name that the category was renamed in or QString::null if it was the global CategoryGroup |
896 | \a uid is the unique identifier associated with the renamed category | 896 | \a uid is the unique identifier associated with the renamed category |
897 | */ | 897 | */ |
898 | 898 | ||
899 | /*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 ) | 899 | /*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 ) |
900 | 900 | ||
901 | Constructor for an empty Categories object. | 901 | Constructor for an empty Categories object. |
902 | */ | 902 | */ |
903 | 903 | ||
904 | /*! \fn Categories::Categories( const Categories ©From ) | 904 | /*! \fn Categories::Categories( const Categories ©From ) |
905 | 905 | ||
906 | Deep copy constructor | 906 | Deep copy constructor |
907 | */ | 907 | */ |
908 | 908 | ||
909 | /*! \fn Categories::~Categories() | 909 | /*! \fn Categories::~Categories() |
910 | 910 | ||
911 | Empty destructor. Call save() before destruction if there are changes | 911 | Empty destructor. Call save() before destruction if there are changes |
912 | that need to be saved. | 912 | that need to be saved. |
913 | */ | 913 | */ |
914 | 914 | ||
915 | /*! \fn CategoryGroup::clear() | 915 | /*! \fn CategoryGroup::clear() |
916 | \internal | 916 | \internal |
917 | */ | 917 | */ |
918 | 918 | ||
919 | /*! \fn const QMap<int, QString> &CategoryGroup::idMap() const | 919 | /*! \fn const QMap<int, QString> &CategoryGroup::idMap() const |
920 | 920 | ||
921 | Returns a const reference to the id to label QMap | 921 | Returns a const reference to the id to label QMap |
922 | */ | 922 | */ |
923 | 923 | ||
924 | /*! \fn CategoryGroup::CategoryGroup() | 924 | /*! \fn CategoryGroup::CategoryGroup() |
925 | \internal | 925 | \internal |
926 | */ | 926 | */ |
927 | 927 | ||
928 | /*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c) | 928 | /*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c) |
929 | \internal | 929 | \internal |
930 | */ | 930 | */ |
931 | 931 | ||
932 | |||
933 | /* ### FIXME properly merge */ | ||
934 | QStringList Categories::labels( const QString & app, const QArray<int> &catids ) const | ||
935 | { | ||
936 | QStringList strs = mGlobalCats.labels( catids ); | ||
937 | strs += mAppCats[app].labels( catids ); | ||
938 | return strs; | ||
939 | } | ||
diff --git a/library/backend/categories.h b/library/backend/categories.h index d5b3669..91c93e7 100644 --- a/library/backend/categories.h +++ b/library/backend/categories.h | |||
@@ -1,226 +1,229 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free | 7 | ** GNU General Public License version 2 as published by the Free |
8 | ** Software Foundation and appearing in the file LICENSE.GPL included | 8 | ** Software Foundation and appearing in the file LICENSE.GPL included |
9 | ** in the packaging of this file. | 9 | ** in the packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING |
12 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A | 12 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A |
13 | ** PARTICULAR PURPOSE. | 13 | ** PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef QTPALMTOP_CATEGORIES_H | 22 | #ifndef QTPALMTOP_CATEGORIES_H |
23 | #define QTPALMTOP_CATEGORIES_H | 23 | #define QTPALMTOP_CATEGORIES_H |
24 | 24 | ||
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qstringlist.h> | 26 | #include <qstringlist.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | #include <qlistview.h> | 28 | #include <qlistview.h> |
29 | #include <qarray.h> | 29 | #include <qarray.h> |
30 | #include "qpcglobal.h" | 30 | #include "qpcglobal.h" |
31 | #include "palmtopuidgen.h" | 31 | #include "palmtopuidgen.h" |
32 | 32 | ||
33 | class CategoryGroup; | 33 | class CategoryGroup; |
34 | 34 | ||
35 | #if defined(QPC_TEMPLATEDLL) | 35 | #if defined(QPC_TEMPLATEDLL) |
36 | // MOC_SKIP_BEGIN | 36 | // MOC_SKIP_BEGIN |
37 | template class QPC_EXPORT QMap<int, QString>; | 37 | template class QPC_EXPORT QMap<int, QString>; |
38 | template class QPC_EXPORT QMap<QString, int>; | 38 | template class QPC_EXPORT QMap<QString, int>; |
39 | template class QPC_EXPORT QMap< QString, CategoryGroup >; | 39 | template class QPC_EXPORT QMap< QString, CategoryGroup >; |
40 | // MOC_SKIP_END | 40 | // MOC_SKIP_END |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | class QPC_EXPORT CategoryGroup | 43 | class QPC_EXPORT CategoryGroup |
44 | { | 44 | { |
45 | friend class Categories; | 45 | friend class Categories; |
46 | public: | 46 | public: |
47 | CategoryGroup(): mIdLabelMap(), mLabelIdMap() { } | 47 | CategoryGroup(): mIdLabelMap(), mLabelIdMap() { } |
48 | CategoryGroup( const CategoryGroup &c ) : | 48 | CategoryGroup( const CategoryGroup &c ) : |
49 | mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { } | 49 | mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { } |
50 | 50 | ||
51 | void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); } | 51 | void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); } |
52 | 52 | ||
53 | int add( const QString &label ); | 53 | int add( const QString &label ); |
54 | bool add( int uid, const QString &label ); | 54 | bool add( int uid, const QString &label ); |
55 | 55 | ||
56 | bool remove( const QString &label ); | 56 | bool remove( const QString &label ); |
57 | bool remove( int uid ); | 57 | bool remove( int uid ); |
58 | 58 | ||
59 | bool rename( int uid, const QString &newLabel ); | 59 | bool rename( int uid, const QString &newLabel ); |
60 | bool rename( const QString &oldLabel, const QString &newLabel ); | 60 | bool rename( const QString &oldLabel, const QString &newLabel ); |
61 | 61 | ||
62 | bool contains(int id) const; | 62 | bool contains(int id) const; |
63 | bool contains(const QString &label) const; | 63 | bool contains(const QString &label) const; |
64 | 64 | ||
65 | /** Returns label associated with the uid or QString::null if | 65 | /** Returns label associated with the uid or QString::null if |
66 | * not found | 66 | * not found |
67 | */ | 67 | */ |
68 | const QString &label(int id) const; | 68 | const QString &label(int id) const; |
69 | /** Returns the uid associated with label or 0 if not found */ | 69 | /** Returns the uid associated with label or 0 if not found */ |
70 | int id(const QString &label) const; | 70 | int id(const QString &label) const; |
71 | 71 | ||
72 | /** Returns a sorted list of labels */ | 72 | /** Returns a sorted list of labels */ |
73 | QStringList labels() const; | 73 | QStringList labels() const; |
74 | 74 | ||
75 | QStringList labels( const QArray<int> &catids ) const; | 75 | QStringList labels( const QArray<int> &catids ) const; |
76 | 76 | ||
77 | const QMap<int, QString> &idMap() const { return mIdLabelMap; } | 77 | const QMap<int, QString> &idMap() const { return mIdLabelMap; } |
78 | 78 | ||
79 | private: | 79 | private: |
80 | void insert( int uid, const QString &label ); | 80 | void insert( int uid, const QString &label ); |
81 | QMap<int, QString> mIdLabelMap; | 81 | QMap<int, QString> mIdLabelMap; |
82 | QMap<QString, int> mLabelIdMap; | 82 | QMap<QString, int> mLabelIdMap; |
83 | 83 | ||
84 | static Qtopia::UidGen &uidGen() { return sUidGen; } | 84 | static Qtopia::UidGen &uidGen() { return sUidGen; } |
85 | static Qtopia::UidGen sUidGen; | 85 | static Qtopia::UidGen sUidGen; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | /* Map from application name to categories */ | 88 | /* Map from application name to categories */ |
89 | class QPC_EXPORT Categories : public QObject | 89 | class QPC_EXPORT Categories : public QObject |
90 | { | 90 | { |
91 | Q_OBJECT | 91 | Q_OBJECT |
92 | public: | 92 | public: |
93 | Categories( QObject *parent=0, const char *name = 0 ) | 93 | Categories( QObject *parent=0, const char *name = 0 ) |
94 | : QObject( parent, name ), mGlobalCats(), mAppCats() { } | 94 | : QObject( parent, name ), mGlobalCats(), mAppCats() { } |
95 | Categories( const Categories ©From ) : QObject( copyFrom.parent() ), | 95 | Categories( const Categories ©From ) : QObject( copyFrom.parent() ), |
96 | mGlobalCats( copyFrom.mGlobalCats ), | 96 | mGlobalCats( copyFrom.mGlobalCats ), |
97 | mAppCats( copyFrom.mAppCats ) { } | 97 | mAppCats( copyFrom.mAppCats ) { } |
98 | virtual ~Categories() { } | 98 | virtual ~Categories() { } |
99 | 99 | ||
100 | Categories &operator= ( const Categories &c ) | 100 | Categories &operator= ( const Categories &c ) |
101 | { mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; } | 101 | { mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; } |
102 | 102 | ||
103 | void clear(); | 103 | void clear(); |
104 | 104 | ||
105 | /** Add the category name as long as it doesn't already exist | 105 | /** Add the category name as long as it doesn't already exist |
106 | * locally or globally. Return UID if added, 0 if conflicts | 106 | * locally or globally. Return UID if added, 0 if conflicts |
107 | * (error). | 107 | * (error). |
108 | */ | 108 | */ |
109 | int addCategory( const QString &appname, const QString &catname); | 109 | int addCategory( const QString &appname, const QString &catname); |
110 | /** Add the category name as long as it doesn't already exist | 110 | /** Add the category name as long as it doesn't already exist |
111 | * locally or globally. Return UID if added, 0 if conflicts | 111 | * locally or globally. Return UID if added, 0 if conflicts |
112 | * (error). | 112 | * (error). |
113 | */ | 113 | */ |
114 | int addCategory( const QString &appname, const QString &catname, int uid); | 114 | int addCategory( const QString &appname, const QString &catname, int uid); |
115 | /** Add the global category just checking that it doesn't | 115 | /** Add the global category just checking that it doesn't |
116 | * already exist globally. Return UID if added, 0 if conflicts. | 116 | * already exist globally. Return UID if added, 0 if conflicts. |
117 | */ | 117 | */ |
118 | int addGlobalCategory( const QString &catname ); | 118 | int addGlobalCategory( const QString &catname ); |
119 | /** Add the global category just checking that it doesn't | 119 | /** Add the global category just checking that it doesn't |
120 | * already exist globally. Return UID if added, 0 if conflicts. | 120 | * already exist globally. Return UID if added, 0 if conflicts. |
121 | */ | 121 | */ |
122 | int addGlobalCategory( const QString &catname, int uid ); | 122 | int addGlobalCategory( const QString &catname, int uid ); |
123 | /** Removes the category from the application; if it is not found | 123 | /** Removes the category from the application; if it is not found |
124 | * in the application, then it removes it from the global list | 124 | * in the application, then it removes it from the global list |
125 | */ | 125 | */ |
126 | bool removeCategory( const QString &appName, const QString &catName, | 126 | bool removeCategory( const QString &appName, const QString &catName, |
127 | bool checkGlobal = TRUE); | 127 | bool checkGlobal = TRUE); |
128 | bool removeCategory( const QString &appName, int uid ); | 128 | bool removeCategory( const QString &appName, int uid ); |
129 | bool removeGlobalCategory( const QString &catName ); | 129 | bool removeGlobalCategory( const QString &catName ); |
130 | bool removeGlobalCategory( int uid ); | 130 | bool removeGlobalCategory( int uid ); |
131 | 131 | ||
132 | QArray<int> ids( const QString &app, const QStringList &labels) const; | 132 | QArray<int> ids( const QString &app, const QStringList &labels) const; |
133 | 133 | ||
134 | /** Returns the id associated with the app */ | 134 | /** Returns the id associated with the app */ |
135 | int id( const QString &app, const QString &cat ) const; | 135 | int id( const QString &app, const QString &cat ) const; |
136 | /** Returns the label associated with the id */ | 136 | /** Returns the label associated with the id */ |
137 | QString label( const QString &app, int id ) const; | 137 | QString label( const QString &app, int id ) const; |
138 | 138 | ||
139 | enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel }; | 139 | enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel }; |
140 | /** Returns the sorted list of all categories that are | 140 | /** Returns the sorted list of all categories that are |
141 | * associated with the app. | 141 | * associated with the app. |
142 | * If includeGlobal parameter is TRUE then the returned | 142 | * If includeGlobal parameter is TRUE then the returned |
143 | * categories will include the global category items. | 143 | * categories will include the global category items. |
144 | * If extra = NoExtra, then | 144 | * If extra = NoExtra, then |
145 | * If extra = AllUnfiled, then All and Unfiled will be prepended to | 145 | * If extra = AllUnfiled, then All and Unfiled will be prepended to |
146 | * the list | 146 | * the list |
147 | * If extra = AllLabel, then All is prepended | 147 | * If extra = AllLabel, then All is prepended |
148 | * If extra = UnfiledLabel, then Unfiled is prepended | 148 | * If extra = UnfiledLabel, then Unfiled is prepended |
149 | */ | 149 | */ |
150 | QStringList labels( const QString &app, | 150 | QStringList labels( const QString &app, |
151 | bool includeGlobal = TRUE, | 151 | bool includeGlobal = TRUE, |
152 | ExtraLabels extra = NoExtra ) const; | 152 | ExtraLabels extra = NoExtra ) const; |
153 | 153 | ||
154 | QStringList labels( const QString &app, | ||
155 | const QArray<int> &catids ) const; | ||
156 | |||
154 | enum DisplaySingle { ShowMulti, ShowAll, ShowFirst }; | 157 | enum DisplaySingle { ShowMulti, ShowAll, ShowFirst }; |
155 | 158 | ||
156 | /** Returns a single string associated with the cat ids for display in | 159 | /** Returns a single string associated with the cat ids for display in |
157 | * a combobox or any area that requires one string. If catids are empty | 160 | * a combobox or any area that requires one string. If catids are empty |
158 | * then "Unfiled" will be returned. If multiple categories are assigned | 161 | * then "Unfiled" will be returned. If multiple categories are assigned |
159 | * then the behavior depends on the DisplaySingle type. | 162 | * then the behavior depends on the DisplaySingle type. |
160 | * If /a display is set to ShowMulti then " (multi)" appended to the | 163 | * If /a display is set to ShowMulti then " (multi)" appended to the |
161 | * first string. If /a display is set to ShowAll, then a space seperated | 164 | * first string. If /a display is set to ShowAll, then a space seperated |
162 | * string is returned with all categories. If ShowFirst is returned, | 165 | * string is returned with all categories. If ShowFirst is returned, |
163 | * the just the first string is returned. | 166 | * the just the first string is returned. |
164 | */ | 167 | */ |
165 | QString displaySingle( const QString &app, | 168 | QString displaySingle( const QString &app, |
166 | const QArray<int> &catids, | 169 | const QArray<int> &catids, |
167 | DisplaySingle display ) const; | 170 | DisplaySingle display ) const; |
168 | 171 | ||
169 | QStringList globalCategories() const { return mGlobalCats.labels();} | 172 | QStringList globalCategories() const { return mGlobalCats.labels();} |
170 | 173 | ||
171 | bool renameCategory( const QString &appname, | 174 | bool renameCategory( const QString &appname, |
172 | const QString &oldName, | 175 | const QString &oldName, |
173 | const QString &newName ); | 176 | const QString &newName ); |
174 | bool renameGlobalCategory( const QString &oldName, | 177 | bool renameGlobalCategory( const QString &oldName, |
175 | const QString &newName ); | 178 | const QString &newName ); |
176 | 179 | ||
177 | void setGlobal( const QString &appname, const QString &catname, | 180 | void setGlobal( const QString &appname, const QString &catname, |
178 | bool value ); | 181 | bool value ); |
179 | bool isGlobal( const QString &catname ) const; | 182 | bool isGlobal( const QString &catname ) const; |
180 | 183 | ||
181 | 184 | ||
182 | /** Returns true if the catname is associated with any application | 185 | /** Returns true if the catname is associated with any application |
183 | */ | 186 | */ |
184 | bool exists( const QString &catname ) const; | 187 | bool exists( const QString &catname ) const; |
185 | bool exists( const QString &appname, const QString &catname) const; | 188 | bool exists( const QString &appname, const QString &catname) const; |
186 | 189 | ||
187 | bool save( const QString &fname ) const; | 190 | bool save( const QString &fname ) const; |
188 | bool load( const QString &fname ); | 191 | bool load( const QString &fname ); |
189 | 192 | ||
190 | // for debugging | 193 | // for debugging |
191 | void dump() const; | 194 | void dump() const; |
192 | 195 | ||
193 | const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; } | 196 | const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; } |
194 | const CategoryGroup &globalGroup() const { return mGlobalCats; } | 197 | const CategoryGroup &globalGroup() const { return mGlobalCats; } |
195 | 198 | ||
196 | signals: | 199 | signals: |
197 | /** emitted if added a category; | 200 | /** emitted if added a category; |
198 | * the second param is the application the category was added to | 201 | * the second param is the application the category was added to |
199 | * or null if global | 202 | * or null if global |
200 | * the third param is the uid of the newly added category | 203 | * the third param is the uid of the newly added category |
201 | */ | 204 | */ |
202 | void categoryAdded( const Categories &, const QString &, int ); | 205 | void categoryAdded( const Categories &, const QString &, int ); |
203 | /** emitted if removed a category | 206 | /** emitted if removed a category |
204 | * the second param is the application the category was removed from | 207 | * the second param is the application the category was removed from |
205 | * or null if global | 208 | * or null if global |
206 | * the third param is the uid of the removed category | 209 | * the third param is the uid of the removed category |
207 | */ | 210 | */ |
208 | void categoryRemoved( const Categories &, const QString &, int ); | 211 | void categoryRemoved( const Categories &, const QString &, int ); |
209 | /** emitted if a category is renamed; the second param is the uid of | 212 | /** emitted if a category is renamed; the second param is the uid of |
210 | * the removed category */ | 213 | * the removed category */ |
211 | void categoryRenamed( const Categories &, const QString &, int ); | 214 | void categoryRenamed( const Categories &, const QString &, int ); |
212 | 215 | ||
213 | private: | 216 | private: |
214 | CategoryGroup mGlobalCats; | 217 | CategoryGroup mGlobalCats; |
215 | QMap< QString, CategoryGroup > mAppCats; | 218 | QMap< QString, CategoryGroup > mAppCats; |
216 | }; | 219 | }; |
217 | 220 | ||
218 | class QPC_EXPORT CheckedListView : public QListView | 221 | class QPC_EXPORT CheckedListView : public QListView |
219 | { | 222 | { |
220 | public: | 223 | public: |
221 | void addCheckableList( const QStringList &options ); | 224 | void addCheckableList( const QStringList &options ); |
222 | void setChecked( const QStringList &checked ); | 225 | void setChecked( const QStringList &checked ); |
223 | QStringList checked() const; | 226 | QStringList checked() const; |
224 | }; | 227 | }; |
225 | 228 | ||
226 | #endif | 229 | #endif |