Akonadi::CollectionPropertiesPage Class

A single page in a collection properties dialog. More...

Header: #include <Akonadi/CollectionPropertiesPage>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiWidgets)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiWidgets)
Inherited By:

Akonadi::CachePolicyPage and Akonadi::CollectionMaintenancePage

Public Functions

CollectionPropertiesPage(QWidget *parent = nullptr)
virtual ~CollectionPropertiesPage() override
virtual bool canHandle(const Akonadi::Collection &collection) const
virtual void load(const Akonadi::Collection &collection) = 0
QString pageTitle() const
virtual void save(Akonadi::Collection &collection) = 0
void setPageTitle(const QString &title)

Detailed Description

The collection properties dialog can be extended by custom collection properties pages, which provide gui elements for viewing and changing collection attributes.

The following example shows how to create a simple collection properties page for the secrecy attribute from the Akonadi::Attribute example.

 class SecrecyPage : public CollectionPropertiesPage
 {
    public:
      SecrecyPage( QWidget *parent = nullptr )
        : CollectionPropertiesPage( parent )
      {
        QVBoxLayout *layout = new QVBoxLayout( this );

        mSecrecy = new QComboBox( this );
        mSecrecy->addItem( "Public" );
        mSecrecy->addItem( "Private" );
        mSecrecy->addItem( "Confidential" );

        layout->addWidget( new QLabel( "Secrecy:" ) );
        layout->addWidget( mSecrecy );

        setPageTitle( i18n( "Secrecy" ) );
      }

      void load( const Collection &collection )
      {
        SecrecyAttribute *attr = collection.attribute( "secrecy" );

        switch ( attr->secrecy() ) {
          case SecrecyAttribute::Public: mSecrecy->setCurrentIndex( 0 ); break;
          case SecrecyAttribute::Private: mSecrecy->setCurrentIndex( 1 ); break;
          case SecrecyAttribute::Confidential: mSecrecy->setCurrentIndex( 2 ); break;
        }
      }

      void save( Collection &collection )
      {
        SecrecyAttribute *attr = collection.attribute( "secrecy" );

        switch ( mSecrecy->currentIndex() ) {
          case 0: attr->setSecrecy( SecrecyAttribute::Public ); break;
          case 1: attr->setSecrecy( SecrecyAttribute::Private ); break;
          case 2: attr->setSecrecy( SecrecyAttribute::Confidential ); break;
        }
      }

      bool canHandle( const Collection &collection ) const
      {
        return collection.hasAttribute( "secrecy" );
      }
 };

 AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY( SecrecyPageFactory, SecrecyPage )

Author: Volker Krause <vkrause@kde.org>

See also Akonadi::CollectionPropertiesDialog and Akonadi::CollectionPropertiesPageFactory.

Member Function Documentation

[explicit] CollectionPropertiesPage::CollectionPropertiesPage(QWidget *parent = nullptr)

Creates a new collection properties page.

parent The parent widget.

[override virtual noexcept] CollectionPropertiesPage::~CollectionPropertiesPage()

Destroys the collection properties page.

[virtual] bool CollectionPropertiesPage::canHandle(const Akonadi::Collection &collection) const

Checks if this page can actually handle the given collection.

Returns \ true if the collection can be handled, \ false otherwise The default implementation returns always \ true. When \ false is returned this page is not shown in the properties dialog. collection The collection to check.

[pure virtual] void CollectionPropertiesPage::load(const Akonadi::Collection &collection)

Loads the page content from the given collection.

collection The collection to load.

QString CollectionPropertiesPage::pageTitle() const

Returns the page title.

See also setPageTitle().

[pure virtual] void CollectionPropertiesPage::save(Akonadi::Collection &collection)

Saves page content to the given collection.

collection Reference to the collection to save to.

void CollectionPropertiesPage::setPageTitle(const QString &title)

Sets the page title.

title Translated, preferably short tab title.

See also pageTitle().