File indexing completed on 2024-11-10 04:41:10
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "agenttypewidgettest.h" 0008 0009 #include "agentfilterproxymodel.h" 0010 #include "agenttype.h" 0011 0012 #include <KAboutData> 0013 #include <QComboBox> 0014 0015 #include <QApplication> 0016 #include <QCommandLineParser> 0017 #include <QDialogButtonBox> 0018 #include <QPushButton> 0019 #include <QVBoxLayout> 0020 0021 // krazy:excludeall=qclasses 0022 0023 Dialog::Dialog(QWidget *parent) 0024 : QDialog(parent) 0025 { 0026 auto layout = new QVBoxLayout(this); 0027 0028 mFilter = new QComboBox(this); 0029 mFilter->addItem(QStringLiteral("None")); 0030 mFilter->addItem(QStringLiteral("text/calendar")); 0031 mFilter->addItem(QStringLiteral("text/directory")); 0032 mFilter->addItem(QStringLiteral("message/rfc822")); 0033 connect(mFilter, &QComboBox::activated, this, &Dialog::filterChanged); 0034 0035 mWidget = new Akonadi::AgentTypeWidget(this); 0036 connect(mWidget, &Akonadi::AgentTypeWidget::currentChanged, this, &Dialog::currentChanged); 0037 0038 auto box = new QDialogButtonBox(this); 0039 0040 layout->addWidget(mFilter); 0041 layout->addWidget(mWidget); 0042 layout->addWidget(box); 0043 0044 QPushButton *ok = box->addButton(QDialogButtonBox::Ok); 0045 connect(ok, &QPushButton::clicked, this, &Dialog::accept); 0046 0047 QPushButton *cancel = box->addButton(QDialogButtonBox::Cancel); 0048 connect(cancel, &QPushButton::clicked, this, &Dialog::reject); 0049 0050 resize(450, 320); 0051 } 0052 0053 void Dialog::done(int r) 0054 { 0055 if (r == Accepted) { 0056 qDebug("'%s' selected", qPrintable(mWidget->currentAgentType().identifier())); 0057 } 0058 0059 QDialog::done(r); 0060 } 0061 0062 void Dialog::currentChanged(const Akonadi::AgentType ¤t, const Akonadi::AgentType &previous) 0063 { 0064 qDebug("current changed: %s -> %s", qPrintable(previous.identifier()), qPrintable(current.identifier())); 0065 } 0066 0067 void Dialog::filterChanged(int index) 0068 { 0069 mWidget->agentFilterProxyModel()->clearFilters(); 0070 if (index > 0) { 0071 mWidget->agentFilterProxyModel()->addMimeTypeFilter(mFilter->itemText(index)); 0072 } 0073 } 0074 0075 int main(int argc, char **argv) 0076 { 0077 QApplication app(argc, argv); 0078 KAboutData aboutData(QStringLiteral("agenttypeviewtest"), QStringLiteral("agenttypeviewtest"), QStringLiteral("0.10")); 0079 KAboutData::setApplicationData(aboutData); 0080 0081 QCommandLineParser parser; 0082 aboutData.setupCommandLine(&parser); 0083 parser.process(app); 0084 aboutData.processCommandLine(&parser); 0085 0086 Dialog dlg; 0087 dlg.exec(); 0088 0089 return 0; 0090 } 0091 0092 #include "moc_agenttypewidgettest.cpp"