1/*
2 Copyright (c) 2006-2008 Tobias Koenig <tokoe@kde.org>
3 Copyright (c) 2012 Laurent Montel <montel@kde.org>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#ifndef AKONADI_AGENTINSTANCEWIDGET_H
22#define AKONADI_AGENTINSTANCEWIDGET_H
23
24#include "akonadi_export.h"
25
26#include <QWidget>
27
28class QAbstractItemView;
29namespace Akonadi {
30
31class AgentInstance;
32class AgentFilterProxyModel;
33
34/**
35 * @short Provides a widget that lists all available agent instances.
36 *
37 * The widget is listening on the dbus for changes, so the
38 * widget is updated automatically as soon as new agent instances
39 * are added to or removed from the system.
40 *
41 * @code
42 *
43 * MyWidget::MyWidget( QWidget *parent )
44 * : QWidget( parent )
45 * {
46 * QVBoxLayout *layout = new QVBoxLayout( this );
47 *
48 * mAgentInstanceWidget = new Akonadi::AgentInstanceWidget( this );
49 * layout->addWidget( mAgentInstanceWidget );
50 *
51 * connect( mAgentInstanceWidget, SIGNAL(doubleClicked(Akonadi::AgentInstance)),
52 * this, SLOT(slotInstanceSelected(Akonadi::AgentInstance)) );
53 * }
54 *
55 * ...
56 *
57 * MyWidget::slotInstanceSelected( Akonadi::AgentInstance &instance )
58 * {
59 * qDebug() << "Selected instance" << instance.name();
60 * }
61 *
62 * @endcode
63 *
64 * @author Tobias Koenig <tokoe@kde.org>
65 */
66class AKONADI_EXPORT AgentInstanceWidget : public QWidget
67{
68 Q_OBJECT
69
70public:
71 /**
72 * Creates a new agent instance widget.
73 *
74 * @param parent The parent widget.
75 */
76 explicit AgentInstanceWidget(QWidget *parent = 0);
77
78 /**
79 * Destroys the agent instance widget.
80 */
81 ~AgentInstanceWidget();
82
83 /**
84 * Returns the current agent instance or an invalid agent instance
85 * if no agent instance is selected.
86 */
87 AgentInstance currentAgentInstance() const;
88
89 /**
90 * Returns the selected agent instances.
91 * @since 4.5
92 */
93 QList<AgentInstance> selectedAgentInstances() const;
94
95 /**
96 * Returns the agent filter proxy model, use this to filter by
97 * agent mimetype or capabilities.
98 */
99 AgentFilterProxyModel *agentFilterProxyModel() const;
100
101 /**
102 * Returns the view used in the widget.
103 * @since 4.5
104 */
105 QAbstractItemView *view() const;
106
107Q_SIGNALS:
108 /**
109 * This signal is emitted whenever the current agent instance changes.
110 *
111 * @param current The current agent instance.
112 * @param previous The previous agent instance.
113 */
114 void currentChanged(const Akonadi::AgentInstance &current, const Akonadi::AgentInstance &previous);
115
116 /**
117 * This signal is emitted whenever there is a double click on an agent instance.
118 *
119 * @param current The current agent instance.
120 */
121 void doubleClicked(const Akonadi::AgentInstance &current);
122
123 /**
124 * This signal is emitted whenever there is a click on an agent instance.
125 *
126 * @param current The current agent instance.
127 * @since 4.9.1
128 */
129 void clicked(const Akonadi::AgentInstance &current);
130
131private:
132 //@cond PRIVATE
133 class Private;
134 Private *const d;
135
136 Q_PRIVATE_SLOT(d, void currentAgentInstanceChanged(const QModelIndex &, const QModelIndex &))
137 Q_PRIVATE_SLOT(d, void currentAgentInstanceDoubleClicked(const QModelIndex &))
138 Q_PRIVATE_SLOT(d, void currentAgentInstanceClicked(const QModelIndex &currentIndex))
139 //@endcond
140};
141
142}
143
144#endif
145