Changeset View
Changeset View
Standalone View
Standalone View
src/akonadi/akonadiconfigdialog.cpp
Show All 18 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "akonadiconfigdialog.h" | 24 | #include "akonadiconfigdialog.h" | ||
25 | 25 | | |||
26 | #include <QAction> | 26 | #include <QAction> | ||
27 | #include <QApplication> | ||||
27 | #include <QDialogButtonBox> | 28 | #include <QDialogButtonBox> | ||
28 | #include <QLabel> | 29 | #include <QLabel> | ||
29 | #include <QLayout> | 30 | #include <QLayout> | ||
30 | #include <QMessageBox> | 31 | #include <QMessageBox> | ||
31 | #include <QPointer> | 32 | #include <QPointer> | ||
32 | #include <QToolBar> | 33 | #include <QToolBar> | ||
33 | 34 | | |||
34 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
35 | 36 | | |||
36 | #include <AkonadiCore/AgentFilterProxyModel> | 37 | #include <AkonadiCore/AgentFilterProxyModel> | ||
37 | #include <AkonadiCore/AgentInstance> | 38 | #include <AkonadiCore/AgentInstance> | ||
38 | #include <AkonadiWidgets/AgentInstanceWidget> | 39 | #include <AkonadiWidgets/AgentInstanceWidget> | ||
39 | #include <AkonadiCore/AgentInstanceCreateJob> | 40 | #include <AkonadiCore/AgentInstanceCreateJob> | ||
40 | #include <AkonadiCore/AgentManager> | 41 | #include <AkonadiCore/AgentManager> | ||
41 | #include <AkonadiWidgets/AgentTypeDialog> | 42 | #include <AkonadiWidgets/AgentTypeDialog> | ||
42 | 43 | | |||
44 | #include <KCalCore/Todo> | ||||
45 | #include <Akonadi/Notes/NoteUtils> | ||||
46 | | ||||
43 | using namespace Akonadi; | 47 | using namespace Akonadi; | ||
44 | 48 | | |||
45 | ConfigDialog::ConfigDialog(QWidget *parent) | 49 | ConfigDialog::ConfigDialog(StorageInterface::FetchContentTypes types, QWidget *parent) | ||
46 | : QDialog(parent) | 50 | : QDialog(parent), | ||
51 | m_agentInstanceWidget(new Akonadi::AgentInstanceWidget(this)), | ||||
52 | m_types(types) | ||||
47 | { | 53 | { | ||
48 | setWindowTitle(i18n("Configure")); | 54 | setWindowTitle(i18n("Configure")); | ||
49 | 55 | | |||
50 | auto description = new QLabel(this); | 56 | auto description = new QLabel(this); | ||
51 | description->setWordWrap(true); | 57 | description->setWordWrap(true); | ||
52 | description->setText(i18n("Please select or create a resource which will be used by the application to store and query its TODOs.")); | 58 | description->setText(i18n("Please select or create a resource which will be used by the application to store and query its TODOs.")); | ||
53 | 59 | | |||
54 | m_agentInstanceWidget = new Akonadi::AgentInstanceWidget(this); | 60 | applyContentTypes(m_agentInstanceWidget->agentFilterProxyModel()); | ||
55 | m_agentInstanceWidget->agentFilterProxyModel()->addMimeTypeFilter(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); | | |||
56 | 61 | | |||
57 | auto toolBar = new QToolBar(this); | 62 | auto toolBar = new QToolBar(this); | ||
58 | toolBar->setIconSize(QSize(16, 16)); | 63 | toolBar->setIconSize(QSize(16, 16)); | ||
59 | toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 64 | toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||
60 | 65 | | |||
61 | auto addAction = new QAction(this); | 66 | auto addAction = new QAction(this); | ||
62 | addAction->setObjectName(QStringLiteral("addAction")); | 67 | addAction->setObjectName(QStringLiteral("addAction")); | ||
63 | addAction->setText(i18n("Add resource")); | 68 | addAction->setText(i18n("Add resource")); | ||
Show All 32 Lines | |||||
96 | layout->addWidget(buttons); | 101 | layout->addWidget(buttons); | ||
97 | 102 | | |||
98 | setLayout(layout); | 103 | setLayout(layout); | ||
99 | } | 104 | } | ||
100 | 105 | | |||
101 | void ConfigDialog::onAddTriggered() | 106 | void ConfigDialog::onAddTriggered() | ||
102 | { | 107 | { | ||
103 | auto dlg = QPointer<AgentTypeDialog>(new AgentTypeDialog(this)); | 108 | auto dlg = QPointer<AgentTypeDialog>(new AgentTypeDialog(this)); | ||
104 | dlg->agentFilterProxyModel()->addMimeTypeFilter(QStringLiteral("application/x-vnd.akonadi.calendar.todo")); | 109 | applyContentTypes(dlg->agentFilterProxyModel()); | ||
105 | if (dlg->exec()) { | 110 | if (dlg->exec()) { | ||
106 | if (!dlg) | 111 | if (!dlg) | ||
107 | return; | 112 | return; | ||
108 | 113 | | |||
109 | const auto agentType = dlg->agentType(); | 114 | const auto agentType = dlg->agentType(); | ||
110 | 115 | | |||
111 | if (agentType.isValid()) { | 116 | if (agentType.isValid()) { | ||
112 | auto job = new Akonadi::AgentInstanceCreateJob(agentType, this); | 117 | auto job = new Akonadi::AgentInstanceCreateJob(agentType, this); | ||
Show All 23 Lines | |||||
136 | 141 | | |||
137 | void ConfigDialog::onConfigureTriggered() | 142 | void ConfigDialog::onConfigureTriggered() | ||
138 | { | 143 | { | ||
139 | auto agent = m_agentInstanceWidget->currentAgentInstance(); | 144 | auto agent = m_agentInstanceWidget->currentAgentInstance(); | ||
140 | if (agent.isValid()) | 145 | if (agent.isValid()) | ||
141 | agent.configure(this); | 146 | agent.configure(this); | ||
142 | } | 147 | } | ||
143 | 148 | | |||
149 | void ConfigDialog::applyContentTypes(AgentFilterProxyModel *model) | ||||
150 | { | ||||
151 | if (m_types & StorageInterface::Notes) | ||||
152 | model->addMimeTypeFilter(NoteUtils::noteMimeType()); | ||||
153 | if (m_types & StorageInterface::Tasks) | ||||
154 | model->addMimeTypeFilter(KCalCore::Todo::todoMimeType()); | ||||
155 | } | ||||
156 | |