1 | /* |
2 | Copyright (c) 2006 Tobias Koenig <tokoe@kde.org> |
3 | Copyright (c) 2008 Omat Holding B.V. <info@omat.nl> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #include "agenttypedialog.h" |
20 | #include "agentfilterproxymodel.h" |
21 | |
22 | #include <QVBoxLayout> |
23 | #include <KGlobal> |
24 | #include <KConfig> |
25 | |
26 | #include <kfilterproxysearchline.h> |
27 | #include <klineedit.h> |
28 | |
29 | using namespace Akonadi; |
30 | |
31 | class AgentTypeDialog::Private |
32 | { |
33 | public: |
34 | Private(AgentTypeDialog *qq) |
35 | : q(qq) |
36 | { |
37 | |
38 | } |
39 | void readConfig(); |
40 | void writeConfig(); |
41 | AgentTypeWidget *Widget; |
42 | AgentType agentType; |
43 | AgentTypeDialog *q; |
44 | }; |
45 | |
46 | void AgentTypeDialog::Private::writeConfig() |
47 | { |
48 | KConfigGroup group(KGlobal::config(), "AgentTypeDialog" ); |
49 | group.writeEntry("Size" , q->size()); |
50 | } |
51 | |
52 | void AgentTypeDialog::Private::readConfig() |
53 | { |
54 | KConfigGroup group(KGlobal::config(), "AgentTypeDialog" ); |
55 | const QSize sizeDialog = group.readEntry("Size" , QSize(460, 320)); |
56 | if (sizeDialog.isValid()) { |
57 | q->resize(sizeDialog); |
58 | } |
59 | } |
60 | |
61 | AgentTypeDialog::AgentTypeDialog(QWidget *parent) |
62 | : KDialog(parent) |
63 | , d(new Private(this)) |
64 | { |
65 | setButtons(Ok | Cancel); |
66 | QVBoxLayout *layout = new QVBoxLayout(mainWidget()); |
67 | layout->setMargin(0); |
68 | |
69 | d->Widget = new Akonadi::AgentTypeWidget(mainWidget()); |
70 | connect(d->Widget, SIGNAL(activated()), this, SLOT(accept())); |
71 | |
72 | KFilterProxySearchLine *searchLine = new KFilterProxySearchLine(mainWidget()); |
73 | layout->addWidget(searchLine); |
74 | searchLine->setProxy(d->Widget->agentFilterProxyModel()); |
75 | |
76 | layout->addWidget(d->Widget); |
77 | |
78 | connect(this, SIGNAL(okClicked()), this, SLOT(accept())); |
79 | |
80 | d->readConfig(); |
81 | |
82 | searchLine->lineEdit()->setFocus(); |
83 | } |
84 | |
85 | AgentTypeDialog::~AgentTypeDialog() |
86 | { |
87 | d->writeConfig(); |
88 | delete d; |
89 | } |
90 | |
91 | void AgentTypeDialog::done(int result) |
92 | { |
93 | if (result == Accepted) { |
94 | d->agentType = d->Widget->currentAgentType(); |
95 | } else { |
96 | d->agentType = AgentType(); |
97 | } |
98 | |
99 | KDialog::done(result); |
100 | } |
101 | |
102 | AgentType AgentTypeDialog::agentType() const |
103 | { |
104 | return d->agentType; |
105 | } |
106 | |
107 | AgentFilterProxyModel *AgentTypeDialog::agentFilterProxyModel() const |
108 | { |
109 | return d->Widget->agentFilterProxyModel(); |
110 | } |
111 | |